Skip to content

Commit

Permalink
Monsters: hide description
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPrimate committed Dec 10, 2020
1 parent 733fe59 commit feefd58
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v 0.1.10

* Generic loot item images from dndbeyond are here! (Thanks to @CaptainYoshi )
* First pass of option to hide monster action/attack description from players

# v 0.1.9

* Resolved bug with duplicate items when using SRD items
Expand Down
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"author": "MrPrimate",
"title": "D&D Beyond Importer",
"description": "Import your dndbeyond.com characters, spells and monsters at super speed!",
"version": "0.1.9",
"download": "https://github.com/mrprimate/ddb-importer/releases/download/0.1.9/ddb-importer.zip",
"version": "0.1.10",
"download": "https://github.com/mrprimate/ddb-importer/releases/download/0.1.10/ddb-importer.zip",
"manifest": "https://github.com/mrprimate/ddb-importer/releases/download/latest/module.json",
"url": "https://github.com/mrprimate/ddb-importer",
"minimumCoreVersion": "0.7.5",
Expand Down
8 changes: 8 additions & 0 deletions src/hooks/ready/registerGameSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,14 @@ export default function () {
default: true,
});

game.settings.register("ddb-importer", "munching-policy-hide-description", {
name: "ddb-importer.munching-policy-hide-description.name",
hint: "ddb-importer.munching-policy-hide-description.hint",
scope: "player",
config: false,
type: Boolean,
default: false,
});

// sets the current tutorial step the user has completed
// game.settings.register("ddb-importer", "tutorial-step", {
Expand Down
9 changes: 8 additions & 1 deletion src/muncher/ddb.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,14 @@ export default class DDBMuncher extends Application {
},
];

const monsterConfig = [];
const monsterConfig = [
{
name: "hide-description",
isChecked: game.settings.get("ddb-importer", "munching-policy-hide-description"),
description: "Hide description from players?",
enabled: true,
},
];

const genericConfig = [
{
Expand Down
40 changes: 36 additions & 4 deletions src/muncher/monster/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,27 @@ import { FEAT_TEMPLATE } from "./templates/feat.js";

// "actionsDescription": "<p><em><strong>Multiattack.</strong></em> The dragon can use its Frightful Presence. It then makes three attacks: one with its bite and two with its claws.</p>\r\n<p><em><strong>Bite.</strong></em> <em>Melee Weapon Attack:</em> +15 to hit, reach 15 ft., one target. <em>Hit:</em> 19 (2d10 + 8) piercing damage plus 9 (2d8) acid damage.</p>\r\n<p><em><strong>Claw.</strong></em> <em>Melee Weapon Attack:</em> +15 to hit, reach 10 ft., one target. <em>Hit:</em> 15 (2d6 + 8) slashing damage.</p>\r\n<p><em><strong>Tail.</strong></em> <em>Melee Weapon Attack:</em> +15 to hit, reach 20 ft., one target. <em>Hit:</em> 17 (2d8 + 8) bludgeoning damage.</p>\r\n<p><em><strong>Frightful Presence.</strong></em> Each creature of the dragon's choice that is within 120 feet of the dragon and aware of it must succeed on a DC 19 Wisdom saving throw or become frightened for 1 minute. A creature can repeat the saving throw at the end of each of its turns, ending the effect on itself on a success. If a creature's saving throw is successful or the effect ends for it, the creature is immune to the dragon's Frightful Presence for the next 24 hours.</p>\r\n<p><em><strong>Acid Breath (Recharge 5&ndash;6).</strong></em> The dragon exhales acid in a 90-foot line that is 10 feet wide. Each creature in that line must make a DC 22 Dexterity saving throw, taking 67 (15d8) acid damage on a failed save, or half as much damage on a successful one.</p>",

function addPlayerDescription(monster, action) {
let playerDescription = "";
if (["rwak", "mwak"].includes(action.data.actionType)) {
playerDescription = `</section>\nThe ${monster.name} performs a ${action.name} attack!`;
} else if (["rsak", "msak"].includes(action.data.actionType)) {
playerDescription = `</section>\nThe ${monster.name} casts ${action.name}!`;
} else if (["save"].includes(action.data.actionType)) {
playerDescription = `</section>\nThe ${monster.name} uses ${action.name} and a save is required!`;
} else {
playerDescription = `</section>\nThe ${monster.name} performs the ${action.name} action`;
}
return playerDescription;
}


export function getActions(monster, DDB_CONFIG, type = "action") {
if (monster.actionsDescription == "") {
return [];
}

const hideDescription = game.settings.get("ddb-importer", "munching-policy-hide-description");
let actions = null;

switch (type) {
Expand Down Expand Up @@ -49,7 +65,9 @@ export function getActions(monster, DDB_CONFIG, type = "action") {
if (!query) return;
action.name = query.textContent.trim().replace(/\.$/, '').trim();
action.data.source = getSource(monster, DDB_CONFIG);
action.flags.monsterMunch = {};
action.flags.monsterMunch = {
titleHTML: query.outerHTML,
};
dynamicActions.push(action);
});

Expand All @@ -67,7 +85,9 @@ export function getActions(monster, DDB_CONFIG, type = "action") {
if (!query) return;
action.name = query.textContent.trim().replace(/\.$/, '').trim();
action.data.source = getSource(monster, DDB_CONFIG);
action.flags.monsterMunch = {};
action.flags.monsterMunch = {
titleHTML: query.outerHTML,
};
dynamicActions.push(action);
});
action = dynamicActions[0];
Expand All @@ -85,7 +105,9 @@ export function getActions(monster, DDB_CONFIG, type = "action") {
const title = pDom.textContent.split('.')[0];
action.name = title.trim();
action.data.source = getSource(monster, DDB_CONFIG);
action.flags.monsterMunch = {};
action.flags.monsterMunch = {
titleHTML: pDom.outerHTML.split('.')[0],
};
dynamicActions.push(action);
});
action = dynamicActions[0];
Expand All @@ -96,9 +118,15 @@ export function getActions(monster, DDB_CONFIG, type = "action") {
// console.log(node.textContent);
const switchAction = dynamicActions.find((act) => node.textContent.startsWith(act.name));
if (switchAction) {
if (action.data.description.value !== "" && hideDescription) {
action.data.description.value += addPlayerDescription(monster, action);
}
action = switchAction;
if (action.data.description.value === "" && hideDescription) {
action.data.description.value = "<section class=\"secret\">\n";
}
}
action.data.description.value += node.outerHTML;
if (node.outerHTML) action.data.description.value += node.outerHTML;

const actionInfo = getActionInfo(monster, DDB_CONFIG, action.name, node.textContent);
// console.log("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
Expand Down Expand Up @@ -182,6 +210,10 @@ export function getActions(monster, DDB_CONFIG, type = "action") {
// console.log("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
});

if (action && action.data.description.value !== "" && hideDescription) {
action.data.description.value += addPlayerDescription(monster, action);
}

// console.log(dynamicActions);
// console.log(JSON.stringify(dynamicActions, null, 4));

Expand Down
21 changes: 20 additions & 1 deletion src/muncher/monster/lair.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { FEAT_TEMPLATE } from "./templates/feat.js";

// "lairDescription": "<p>Black dragons dwell in swamps on the frayed edges of civilization. A black dragon&rsquo;s lair is a dismal cave, grotto, or ruin that is at least partially flooded, providing pools where the dragon rests, and where its victims can ferment. The lair is littered with the acid-pitted bones of previous victims and the fly-ridden carcasses of fresh kills, watched over by crumbling statues. Centipedes, scorpions, and snakes infest the lair, which is filled with the stench of death and decay.</p>\r\n<h4>Lair Actions</h4>\r\n<p>On initiative count 20 (losing initiative ties), the dragon takes a lair action to cause one of the following effects; the dragon can&rsquo;t use the same effect two rounds in a row:</p>\r\n<ul>\r\n<li>Pools of water that the dragon can see within 120 feet of it surge outward in a grasping tide. Any creature on the ground within 20 feet of such a pool must succeed on a DC 15 Strength saving throw or be pulled up to 20 feet into the water and knocked prone.</li>\r\n<li>A cloud of swarming insects fills a 20-foot-radius sphere centered on a point the dragon chooses within 120 feet of it. The cloud spreads around corners and remains until the dragon dismisses it as an action, uses this lair action again, or dies. The cloud is lightly obscured. Any creature in the cloud when it appears must make on a DC 15 Constitution saving throw, taking 10 (3d6) piercing damage on a failed save, or half as much damage on a successful one. A creature that ends its turn in the cloud takes 10 (3d6) piercing damage.</li>\r\n<li>Magical darkness spreads from a point the dragon chooses within 60 feet of it, filling a 15-foot-radius sphere until the dragon dismisses it as an action, uses this lair action again, or dies. The darkness spreads around corners. A creature with darkvision can&rsquo;t see through this darkness, and nonmagical light can&rsquo;t illuminate it. If any of the effect&rsquo;s area overlaps with an area of light created by a spell of 2nd level or lower, the spell that created the light is dispelled.</li>\r\n</ul>\r\n<h4>Regional Effects</h4>\r\n<p>The region containing a legendary black dragon&rsquo;s lair is warped by the dragon&rsquo;s magic, which creates one or more of the following effects:</p>\r\n<ul>\r\n<li>The land within 6 miles of the lair takes twice as long as normal to traverse, since the plants grow thick and twisted, and the swamps are thick with reeking mud.</li>\r\n<li>Water sources within 1 mile of the lair are supernaturally fouled. Enemies of the dragon that drink such water regurgitate it within minutes.<br />Fog lightly obscures the land within 6 miles of the lair.</li>\r\n</ul>\r\n<p>If the dragon dies, vegetation remains as it has grown, but other effects fade over 1d10 days.</p>",

function addPlayerDescription(monster, action) {
let playerDescription = `</section>\nThe ${monster.name} uses a ${action.name}!`;
return playerDescription;
}

export function getLairActions(monster, DDB_CONFIG) {
let resource = {
value: false,
Expand All @@ -16,6 +21,8 @@ export function getLairActions(monster, DDB_CONFIG) {
};
}

const hideDescription = game.settings.get("ddb-importer", "munching-policy-hide-description");

let dom = new DocumentFragment();
$.parseHTML(monster.lairDescription).forEach((element) => {
dom.appendChild(element);
Expand Down Expand Up @@ -60,15 +67,23 @@ export function getLairActions(monster, DDB_CONFIG) {

if (!action) {
action = dynamicActions[0];
} else if (hideDescription) {
action.data.description.value = "<section class=\"secret\">\n";
}

dom.childNodes.forEach((node) => {
const switchAction = dynamicActions.find((act) => act.name == node.textContent);
if (switchAction) {
actionType = node.textContent;
if (action.data.description.value !== "" && hideDescription) {
action.data.description.value += addPlayerDescription(monster, action);
}
action = switchAction;
if ((action.data.description.value === "" || action.name === "Lair Actions") && hideDescription) {
action.data.description.value += "<section class=\"secret\">\n";
}
}
action.data.description.value += node.outerHTML;
if (node.outerHTML) action.data.description.value += node.outerHTML;

const initiativeMatch = node.textContent.match(/initiative count (\d+)/);
if (initiativeMatch) {
Expand All @@ -79,6 +94,10 @@ export function getLairActions(monster, DDB_CONFIG) {
}
});

if (action && action.data.description.value !== "" && hideDescription) {
action.data.description.value += addPlayerDescription(monster, action);
}

return {
resource: resource,
lairActions: dynamicActions,
Expand Down
22 changes: 19 additions & 3 deletions src/muncher/monster/legendary.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { getSource } from "./source.js";
import { getRecharge, getActivation, getFeatSave, getDamage } from "./utils.js";
import { FEAT_TEMPLATE } from "./templates/feat.js";

function addPlayerDescription(monster, action) {
let playerDescription = `</section>\nThe ${monster.name} performs a Legendary Action! Prepare for ${action.name}!`;
return playerDescription;
}


export function getLegendaryActions(monster, DDB_CONFIG, monsterActions) {
if (monster.legendaryActionsDescription == "") {
return {
Expand All @@ -13,6 +19,8 @@ export function getLegendaryActions(monster, DDB_CONFIG, monsterActions) {
};
}

const hideDescription = game.settings.get("ddb-importer", "munching-policy-hide-description");

let actionResource = {
value: 3,
max: 3
Expand Down Expand Up @@ -81,11 +89,17 @@ export function getLegendaryActions(monster, DDB_CONFIG, monsterActions) {

const switchAction = dynamicActions.find((act) => node.textContent.startsWith(act.name));
if (switchAction) {
if (action.data.description.value !== "" && hideDescription) {
action.data.description.value += addPlayerDescription(monster, action);
}
action = switchAction;
if (action.data.description.value === "" && hideDescription) {
action.data.description.value = "<section class=\"secret\">\n";
}
}
// console.log(action)
if (action.flags && action.flags.monstersMunch && action.flags.monsterMunch.actionCopy) return;
action.data.description.value += node.outerHTML;
if (node.outerHTML) action.data.description.value += node.outerHTML;

const activationCost = getActivation(node.textContent);
if (activationCost) {
Expand All @@ -106,10 +120,12 @@ export function getLegendaryActions(monster, DDB_CONFIG, monsterActions) {
}
action.data.damage = getDamage(node.textContent);
}


});

if (action && action.data.description.value !== "" && hideDescription) {
action.data.description.value += addPlayerDescription(monster, action);
}

// console.log(dynamicActions);

return {
Expand Down
20 changes: 19 additions & 1 deletion src/muncher/monster/specialtraits.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import { getSource } from "./source.js";
import { getRecharge, getActivation, getFeatSave, getDamage, getAction, getUses } from "./utils.js";
import { FEAT_TEMPLATE } from "./templates/feat.js";


function addPlayerDescription(monster, action) {
let playerDescription = `</section>\nThe ${monster.name} uses ${action.name}!`;
return playerDescription;
}

export function getSpecialTraits(monster, DDB_CONFIG) {
if (monster.specialTraitsDescription == "") {
return {
Expand All @@ -16,6 +22,8 @@ export function getSpecialTraits(monster, DDB_CONFIG) {
};
}

const hideDescription = game.settings.get("ddb-importer", "munching-policy-hide-description");

let resistanceResource = {
value: 0,
max: 0
Expand Down Expand Up @@ -54,9 +62,15 @@ export function getSpecialTraits(monster, DDB_CONFIG) {
dom.childNodes.forEach((node) => {
const switchAction = dynamicActions.find((act) => node.textContent.startsWith(act.name));
if (switchAction) {
if (action.data.description.value !== "" && hideDescription) {
action.data.description.value += addPlayerDescription(monster, action);
}
action = switchAction;
if (action.data.description.value === "" && hideDescription) {
action.data.description.value = "<section class=\"secret\">\n";
}
}
action.data.description.value += node.outerHTML;
if (node.outerHTML) action.data.description.value += node.outerHTML;

const activationCost = getActivation(node.textContent);
if (activationCost) {
Expand Down Expand Up @@ -92,6 +106,10 @@ export function getSpecialTraits(monster, DDB_CONFIG) {

});

if (action && action.data.description.value !== "" && hideDescription) {
action.data.description.value += addPlayerDescription(monster, action);
}

// console.log(dynamicActions);

return {
Expand Down

0 comments on commit feefd58

Please sign in to comment.