Skip to content

Commit

Permalink
Update for dnd5e 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dev7355608 committed Sep 7, 2024
1 parent 4ae6bf2 commit 968fa8c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 16 deletions.
8 changes: 4 additions & 4 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"email": "[email protected]"
}
],
"version": "2.4.0",
"version": "2.4.1",
"compatibility": {
"minimum": "12",
"verified": "12"
Expand Down Expand Up @@ -53,15 +53,15 @@
"type": "system",
"compatibility": {
"minimum": "3.2.0",
"verified": "3.3.1"
"verified": "4.0.0"
}
}
]
},
"url": "https://github.com/dev7355608/vision-5e",
"manifest": "https://github.com/dev7355608/vision-5e/releases/latest/download/module.json",
"download": "https://github.com/dev7355608/vision-5e/releases/download/v2.4.0/module.zip",
"changelog": "https://github.com/dev7355608/vision-5e/releases/tag/v2.4.0",
"download": "https://github.com/dev7355608/vision-5e/releases/download/v2.4.1/module.zip",
"changelog": "https://github.com/dev7355608/vision-5e/releases/tag/v2.4.1",
"bugs": "https://github.com/dev7355608/vision-5e/issues",
"readme": "https://raw.githubusercontent.com/dev7355608/vision-5e/main/README.md",
"license": "https://raw.githubusercontent.com/dev7355608/vision-5e/main/LICENSE"
Expand Down
67 changes: 55 additions & 12 deletions scripts/actor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,34 @@ function isMagical(actor) {
return actor.items.some(isMagicItem) || actor.appliedEffects.some(isMagicEffect)
}

/**
* @param {DamageData} damage
* @returns {boolean}
*/
function isPoisonDamage(damage) {
return damage.types.has("poison") || damage.custom.enabled && /\[\s*poison\s*\]/i.test(damage.custom.formula);
}

/**
* @param {Activity} activity
* @returns {boolean}
*/
function isPoisonousAttack(activity) {
return activity.type === "attack" && (activity.damage.parts.some(isPoisonDamage)
|| /\[\s*poison\s*\]/i.test(activity.damage.critical));
}

/**
* @param {Item} item
* @returns {boolean}
*/
function isPoisonousNaturalWeapon(item) {
return item.type === "weapon" && item.system.type.value === "natural"
&& (isPoisonDamage(item.system.damage.base)
|| item.system.properties.has("ver") && isPoisonDamage(item.system.damage.versatile)
|| item.system.activities.some(isPoisonousAttack));
}

/**
* A poisonous creature is a creature that has a poisonous natural weapon attack.
* @param {Actor} actor
Expand All @@ -205,20 +233,35 @@ function isPoisonous(actor) {
return false;
}

for (const item of actor.items) {
if (item.type === "weapon" && item.system.type.value === "natural"
&& (item.system.damage.parts.some(part => part[1] === "poison")
|| [
item.system.critical.damage,
item.system.damage.versatile,
item.system.formula
].some(formula => /\[poison\]/i.test(formula)))) {
return true;
}
return actor.items.some(isPoisonousNaturalWeapon);
}

Hooks.once("init", () => {
if (!foundry.utils.isNewerVersion("4.0.0", game.system.version)) {
return;
}

return false;
}
isPoisonous = function (actor) {
if (actor.statuses.has(CONFIG.specialStatusEffects.OBJECT)
|| actor.statuses.has(CONFIG.specialStatusEffects.PETRIFIED)) {
return false;
}

for (const item of actor.items) {
if (item.type === "weapon" && item.system.type.value === "natural"
&& (item.system.damage.parts.some(part => part[1] === "poison")
|| [
item.system.critical.damage,
item.system.damage.versatile,
item.system.formula
].some(formula => /\[poison\]/i.test(formula)))) {
return true;
}
}

return false;
}
});

/**
* A thinking creature is a creature that has an Intelligence of 4 or higher and speaks at least one language.
Expand Down

0 comments on commit 968fa8c

Please sign in to comment.