Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New special duration: RestComplete, NextD20Roll deletion fixes, Effect name fix #208

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@
"DL.SpecialDurationTurnStart": "Turn Start: Expires at the start of the targets's next turn (in combat)",
"DL.SpecialDurationTurnStartSource": "Turn Start: Expires at the start of the source actor's next turn (in combat)",
"DL.SpecialDurationNextD20Roll": "Next d20 Roll: Expires at the targets's next Challenge/Attack Roll",
"DL.SpecialDurationRestComplete": "Rest Complete: Expires when the targets complete rest",
"DL.SpellAftereffect": "Aftereffect",
"DL.SpellArea": "Area",
"DL.SpellAttribute": "Attribute",
Expand Down
2 changes: 1 addition & 1 deletion src/module/active-effects/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Hooks.on('renderActiveEffectConfig', (app, html) => {

dropDownConfig({
specialDuration: 'specialDuration',
values: ['None', 'TurnStart', 'TurnEnd', 'TurnStartSource', 'TurnEndSource','NextD20Roll'],
values: ['None', 'TurnStart', 'TurnEnd', 'TurnStartSource', 'TurnEndSource','NextD20Roll','RestComplete'],
default_value: 'None',
})

Expand Down
56 changes: 49 additions & 7 deletions src/module/actor/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,15 @@ export class DemonlordActor extends Actor {
for (let effect of this.appliedEffects) {
const specialDuration = foundry.utils.getProperty(effect, 'flags.specialDuration')
if (!(specialDuration?.length > 0)) continue
if (specialDuration === 'NextD20Roll' && effect.changes.find((e) => e.key.includes('system.bonuses.attack.boons'))) await effect?.delete()
if (specialDuration === 'NextD20Roll') {
let nAttackAttribute = attackAttribute.length ? attackAttribute : 'None'
if (
effect.changes.find(e => e.key.includes('system.bonuses.attack.boons.all')) || !effect.changes.length ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably best to move the end !effect.changes.length === 0 to the top or the bottom. Same for lines 515, 598, 697 and 802.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code checks the same bonuses what each function rollItem/Talent/Weapon/Spell uses, so If you set a bonus to system.bonuses.attack.boons.spell effect will be removed when spell casted.
Same as weapon attack checks only for system.bonuses.attack.boons.${AttackAttribute}, system.bonuses.attack.boons.all and system.bonuses.attack.boons.all and not for system.bonuses.attack.boons.spell.
That is the logic.

effect.changes.find(e => e.key.includes(`system.bonuses.attack.boons.${nAttackAttribute}`)) ||
effect.changes.find(e => e.key.includes(`system.bonuses.attack.boons.weapon`))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe needs to be added for spells as well?

)
await effect?.delete()
}
}

Hooks.call('DL.RollAttack', {
Expand Down Expand Up @@ -502,7 +510,13 @@ export class DemonlordActor extends Actor {
for (let effect of this.appliedEffects) {
const specialDuration = foundry.utils.getProperty(effect, 'flags.specialDuration')
if (!(specialDuration?.length > 0)) continue
if (specialDuration === 'NextD20Roll' && effect.changes.find((e) => e.key.includes('system.bonuses.challenge.boons'))) await effect?.delete()
if (specialDuration === 'NextD20Roll') {
if (
effect.changes.find(e => e.key.includes('system.bonuses.challenge.boons.all')) || !effect.changes.length ||
effect.changes.find(e => e.key.includes(`system.bonuses.challenge.boons.${attribute.key}`))
)
await effect?.delete()
}
}

return challengeRoll
Expand Down Expand Up @@ -578,7 +592,14 @@ export class DemonlordActor extends Actor {
for (let effect of this.appliedEffects) {
const specialDuration = foundry.utils.getProperty(effect, 'flags.specialDuration')
if (!(specialDuration?.length > 0)) continue
if (specialDuration === 'NextD20Roll' && attackAttribute !== '' && effect.changes.find((e) => e.key.includes('system.bonuses.attack.boons'))) await effect?.delete()
if (specialDuration === 'NextD20Roll') {
let nAttackAttribute = attackAttribute.length ? attackAttribute : 'None'
if (
effect.changes.find(e => e.key.includes('system.bonuses.attack.boons.all')) || !effect.changes.length ||
effect.changes.find(e => e.key.includes(`system.bonuses.attack.boons.${nAttackAttribute}`))
)
await effect?.delete()
}
}

}
Expand Down Expand Up @@ -670,7 +691,15 @@ export class DemonlordActor extends Actor {
for (let effect of this.appliedEffects) {
const specialDuration = foundry.utils.getProperty(effect, 'flags.specialDuration')
if (!(specialDuration?.length > 0)) continue
if (specialDuration === 'NextD20Roll' && attackAttribute !== '' && effect.changes.find((e) => e.key.includes('system.bonuses.attack.boons'))) await effect?.delete()
if (specialDuration === 'NextD20Roll') {
let nAttackAttribute = attackAttribute.length ? attackAttribute : 'None'
if (
effect.changes.find(e => e.key.includes('system.bonuses.attack.boons.all')) || !effect.changes.length ||
effect.changes.find(e => e.key.includes(`system.bonuses.attack.boons.${nAttackAttribute}`)) ||
effect.changes.find(e => e.key.includes(`system.bonuses.attack.boons.spell`))
)
await effect?.delete()
}
}

// Add concentration if it's in the spell duration
Expand Down Expand Up @@ -748,7 +777,7 @@ export class DemonlordActor extends Actor {

let boons =
(parseInt(inputBoons) || 0) +
(this.system.bonuses.attack[attackAttribute] || 0) +
(this.system.bonuses.attack.boons[attackAttribute] || 0) +
(this.system.bonuses.attack.boons.all || 0) +
parseInt(itemData.action?.boonsbanes || 0)

Expand All @@ -767,8 +796,15 @@ export class DemonlordActor extends Actor {
for (let effect of this.appliedEffects) {
const specialDuration = foundry.utils.getProperty(effect, 'flags.specialDuration')
if (!(specialDuration?.length > 0)) continue
if (specialDuration === 'NextD20Roll' && attackAttribute !== '' && effect.changes.find((e) => e.key.includes('system.bonuses.attack.boons'))) await effect?.delete()
}
if (specialDuration === 'NextD20Roll') {
let nAttackAttribute = attackAttribute.length ? attackAttribute : 'None'
if (
effect.changes.find(e => e.key.includes('system.bonuses.attack.boons.all')) || !effect.changes.length ||
effect.changes.find(e => e.key.includes(`system.bonuses.attack.boons.${nAttackAttribute}`))
)
await effect?.delete()
}
}
}
postItemToChat(this, item, attackRoll, target?.actor, parseInt(inputBoons) || 0)
return attackRoll
Expand Down Expand Up @@ -911,6 +947,12 @@ export class DemonlordActor extends Actor {
if (restTime === 24) this.applyHealing(true)
}

for (let effect of this.appliedEffects) {
const specialDuration = foundry.utils.getProperty(effect, "flags.specialDuration")
if (!(specialDuration?.length > 0)) continue
if (specialDuration === 'RestComplete') await effect?.delete()
}

var templateData = { actor: this, restTime, magicRecovery, talentRecovery, healing }

const chatData = {
Expand Down
23 changes: 11 additions & 12 deletions src/module/chat/chat-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,17 @@ async function _onChatApplyEffect(event) {
}

const effectData = activeEffect.toObject()
//Repace origin with Item UUID, otherwise effect cannot be removed
//specialDuration: TurnStartSource, TurnEndSource

let aeUuid = activeEffect.uuid
let effectOrigin = aeUuid.substr(0, aeUuid.search('.ActiveEffect.'))
let effectOriginName = fromUuidSync(effectOrigin).name
if (activeEffect.origin.startsWith('Compendium')) {
effectData.origin = effectOrigin
}
if (effectData.name !== effectOriginName) effectData.name = `${effectData.name} [${effectOriginName}]`

for await (const target of selected) {
// First check if the actor already has this effect
const matchingEffects = target.actor.effects.filter(e => e.name === effectData.name && changesMatch(e.changes, effectData.changes))
Expand All @@ -236,18 +247,6 @@ async function _onChatApplyEffect(event) {
}
}


//Repace origin with Item UUID, otherwise effect cannot be removed
//specialDuration: TurnStartSource, TurnEndSource

let aeUuid = activeEffect.uuid
let effectOrigin = aeUuid.substr(0, aeUuid.search('.ActiveEffect.'))
let effectOriginName = fromUuidSync(effectOrigin).name
if (activeEffect.origin.startsWith('Compendium')) {
effectData.origin = effectOrigin
}
if (effectData.name !== effectOriginName) effectData.name = `${effectData.name} [${effectOriginName}]`

await ActiveEffect.create(effectData, {parent: target.actor}).then(e => ui.notifications.info(`Added "${e.name}" to "${target.actor.name}"`))
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/module/combat/combat.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ async function deleteSpecialdurationEffects(combatant) {
for (let effect of actor.appliedEffects) {
const specialDuration = foundry.utils.getProperty(effect, "flags.specialDuration")
if (!(specialDuration?.length > 0)) continue
if (specialDuration !== "None" && specialDuration !== undefined) await effect?.delete()
if (specialDuration !== "None" && specialDuration !== undefined && specialDuration !== 'RestComplete') await effect?.delete()
}
}

Expand All @@ -510,7 +510,7 @@ Hooks.on('deleteCombat', async (combat) => {
for (let effect of testActor.appliedEffects) {
const specialDuration = foundry.utils.getProperty(effect, "flags.specialDuration")
if (!(specialDuration?.length > 0)) continue
if (specialDuration !== "None" && specialDuration !== undefined) await effect?.delete()
if (specialDuration !== "None" && specialDuration !== undefined && specialDuration !== 'RestComplete') await effect?.delete()
}
}
})
Expand Down