Skip to content
Merged

5.6.5 #309

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
14 changes: 12 additions & 2 deletions src/module/actor/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ export class DemonlordActor extends Actor {
}
// And then round down
system.characteristics.health.healingrate = Math.floor(system.characteristics.health.healingrate)
// Insanity
if (!system.characteristics.insanity) {
system.characteristics.insanity = {
min: 0,
max: 0,
value: 0,
immune: 0
}
}
system.characteristics.insanity.max += system.attributes.will.value

// Final armor computation
system.characteristics.defense += system.bonuses.armor.defense
Expand Down Expand Up @@ -324,7 +334,7 @@ export class DemonlordActor extends Actor {

// Also, if any of the effects in the document contains an affliction, activate it
if (['character', 'creature'].includes(this.type)) {
const effects = doc.effects.filter(e => e.changes.some(c => c.key === 'system.maluses.affliction'))
const effects = doc.effects.filter(e => e.transfer && e.changes.some(c => c.key === 'system.maluses.affliction'))
for (const activeEffect of effects) {
const changes = activeEffect.changes
for (const affliction of changes.filter(c => c.key === 'system.maluses.affliction')) {
Expand Down Expand Up @@ -397,7 +407,7 @@ export class DemonlordActor extends Actor {
// Also, if any of the effects in the deleted documents contains an affliction (and it's the last instance of this affliction), remove it
if (['character', 'creature'].includes(this.type)) {
for (const doc of documents.filter(d => d.effects?.some(e => e.changes?.some(c => c.key === 'system.maluses.affliction')))) {
const effects = doc.effects.filter(e => e.changes?.some(c => c.key === 'system.maluses.affliction'))
const effects = doc.effects.filter(e => e.transfer && e.changes?.some(c => c.key === 'system.maluses.affliction'))
for (const activeEffect of effects) {
const changes = activeEffect.changes
for (const affliction of changes.filter(c => c.key === 'system.maluses.affliction')) {
Expand Down
75 changes: 41 additions & 34 deletions src/module/combat/combat-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,40 +238,31 @@ calculateEncounterDifficulty(combatants) {
}
}

const trackerHeader = html.querySelector(".combat-tracker-header")
if (this.initiativeMethod === 's') {
if (game.combat?.turn === null)
trackerHeader.innerHTML = trackerHeader.innerHTML + `<div class="encounter-controls combat"><strong class="encounter-difficulty" data-rating="challenging">${game.i18n.localize('DL.TurnChooseTurn')}</strong></div>`
else
trackerHeader.innerHTML = trackerHeader.innerHTML + `<div class="encounter-controls combat"><class="encounter-difficulty">&nbsp;</div>`
}

html.querySelectorAll('.combatant')?.forEach(el => {
// For each combatant in the tracker, change the initiative selector
const combId = el.getAttribute('data-combatant-id')
const combatant = combatants.get(combId)
if (!combatant) return

if (!game.modules.get('lancer-initiative')) {
const multipleCombatants = game.combat.getCombatantsByToken(combatant.token)

if (combatant.actor?.system.fastAndSlowTurn && multipleCombatants.length == 2) {
// The combatant has a double initiative, so we display "Fast" and "Slow"
init = combatant._id === multipleCombatants[0]._id
? game.i18n.localize('DL.TurnSlow')
: game.i18n.localize('DL.TurnFast')
// Display only
if (this.initiativeMethod === 's') el.getElementsByClassName('token-initiative')[0].innerHTML = `<span class="combatant-control dlturnorder">${init}</span>`
} else {
init = combatant.actor?.system.fastturn
? game.i18n.localize('DL.TurnFast')
: game.i18n.localize('DL.TurnSlow')

const multipleCombatants = game.combat.getCombatantsByToken(combatant.token)
const title = (game.user.isGM || combatant.actor.isOwner) && game.combat?.turn === null ? i18n('DL.TurnChangeTurn') : ''
const style = (game.user.isGM || combatant.actor.isOwner) && game.combat?.turn === null ? 'font-weight: bold; cursor: pointer;' : 'font-weight: normal; cursor: auto; opacity: 0.5;'

if (combatant.actor?.system.fastAndSlowTurn && multipleCombatants.length == 2) {
// The combatant has a double initiative, so we display "Fast" and "Slow"
init = combatant._id === multipleCombatants[0]._id
? game.i18n.localize('DL.TurnSlow')
: game.i18n.localize('DL.TurnFast')
// Display only
if (this.initiativeMethod === 's') el.getElementsByClassName('token-initiative')[0].innerHTML = `<span class="combatant-control dlturnorder">${init}</span>`
} else {
init = combatant.actor?.system.fastturn
? game.i18n.localize('DL.TurnFast')
: game.i18n.localize('DL.TurnSlow')

// Change initiative by clicking on the name
if (this.initiativeMethod === 's') el.getElementsByClassName('token-initiative')[0].innerHTML =
`<a class="combatant-control dlturnorder" style="${style}" title="${title}">${init}</a>`
// Change initiative by clicking on the name
if (this.initiativeMethod === 's') el.getElementsByClassName('token-initiative')[0].innerHTML =
`<a class="combatant-control dlturnorder" title="${i18n('DL.TurnChangeTurn')}">${init}</a>`
}
}

if (this.initiativeMethod === 'h' && game.user.isGM)
Expand Down Expand Up @@ -324,7 +315,18 @@ calculateEncounterDifficulty(combatants) {
if (game.user.isGM) {
const hasActedButton = document.createElement('button')
hasActedButton.type = 'button'
hasActedButton.className = 'inline-control combatant-control icon fa-solid fa-hourglass-start'
hasActedButton.className = 'inline-control combatant-control icon fa-solid'

const hasActed = combatant.getFlag('demonlord', 'hasActed')

if (hasActed) {
hasActedButton.classList.add('fa-hourglass-end')
el.classList.add('hide')
} else {
hasActedButton.classList.add('fa-hourglass-start')
el.classList.remove('hide')
}

hasActedButton.setAttribute('data-action', 'toggleActed')
hasActedButton.setAttribute('data-tooltip', '')
hasActedButton.setAttribute('aria-label', game.i18n.localize('DL.ToggleActed'))
Expand Down Expand Up @@ -356,7 +358,8 @@ calculateEncounterDifficulty(combatants) {
const combId = li.dataset.combatantId
const combatant = combatants.get(combId)
if (!combatant) return
if (game.user.isGM || (combatant.actor.isOwner && game.combat?.turn === null)) {

if (game.user.isGM || combatant.actor.isOwner) {
await combatant.actor.update({'system.fastturn': !combatant.actor.system.fastturn})
const initChatMessage = await createInitChatMessage(combatant, {})
if (initChatMessage) ChatMessage.create(initChatMessage)
Expand Down Expand Up @@ -405,12 +408,16 @@ calculateEncounterDifficulty(combatants) {
}

static async onToggleActed(event) {
const button = event.target.closest('.inline-control')
const combatant = event.target.closest('.combatant')
const buttonElement = event.target.closest('.inline-control')
const combatantElement = event.target.closest('.combatant')

buttonElement.classList.toggle('fa-hourglass-start')
buttonElement.classList.toggle('fa-hourglass-end')
combatantElement.classList.toggle('hide')

const combatant = game.combat.combatants.get(combatantElement.dataset.combatantId)

button.classList.toggle('fa-hourglass-start')
button.classList.toggle('fa-hourglass-end')
combatant.classList.toggle('hide')
await combatant.setFlag('demonlord', 'hasActed', buttonElement.classList.contains('fa-hourglass-end'))
}

async _onToggleHidden(combatant) {
Expand Down
9 changes: 5 additions & 4 deletions src/module/combat/combatant.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
export class DLCombatant extends foundry.documents.Combatant {
_onDelete(options, userId) {
super._onDelete(options, userId)

async _onDelete(options, userId) {

// If the combatant is deleted, we also delete its double if it exists
if (this.actor.system.fastAndSlowTurn) {
const doubleCombatants = game.combat.getCombatantsByToken(this.token).filter(c => c.id !== this.id)
for (const double of doubleCombatants) {
if (double) {
double.delete()
await double.delete()
}
}
}

await super._onDelete(options, userId)
}
}
Loading