This commit is contained in:
@ -138,7 +138,6 @@ export class LethalFantasyCombat extends Combat {
|
||||
}
|
||||
|
||||
async nextRound() {
|
||||
console.log('NEXT ROUND')
|
||||
this.turnsDone = false
|
||||
|
||||
let turn = this.turn === null ? null : 0; // Preserve the fact that it's no-one's turn currently.
|
||||
@ -162,13 +161,12 @@ export class LethalFantasyCombat extends Combat {
|
||||
|
||||
for (let c of this.combatants) {
|
||||
if ( nextRound >= c.initiative) {
|
||||
c.update({ 'system.progressionCount': c.system.progressionCount + 1 });
|
||||
let user = game.users.find(u => u.active && u.character && u.character.id === c.actor.id);
|
||||
if (user?.hasPlayerOwner) {
|
||||
game.socket.emit(`system.${SYSTEM.id}`, { type: "rollProgressionDice", progressionCount: c.system.progressionCount+1, actorId: c.actor.id, combatId: this.id, combatantId: c.id });
|
||||
} else {
|
||||
user = game.users.find(u => u.active && u.isGM);
|
||||
c.actor.system.rollProgressionDice(this.id, c.id, c.system.progressionCount+1);
|
||||
c.actor.system.rollProgressionDice(this.id, c.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -166,71 +166,8 @@ export default class LethalFantasyMonsterSheet extends LethalFantasyActorSheet {
|
||||
async _onRoll(event, target) {
|
||||
if (this.isEditMode) return
|
||||
const rollType = event.target.dataset.rollType
|
||||
let rollTarget
|
||||
let rollKey = event.target.dataset.rollKey
|
||||
switch (rollType) {
|
||||
case "monster-attack":
|
||||
case "monster-defense":
|
||||
case "monster-damage":
|
||||
rollTarget = foundry.utils.duplicate(this.document.system.attacks[rollKey])
|
||||
rollTarget.rollKey = rollKey
|
||||
break
|
||||
case "monster-skill":
|
||||
rollTarget = foundry.utils.duplicate(this.document.system.resists[rollKey])
|
||||
rollTarget.rollKey = rollKey
|
||||
break
|
||||
case "save":
|
||||
rollTarget = foundry.utils.duplicate(this.document.system.saves[rollKey])
|
||||
rollTarget.rollKey = rollKey
|
||||
rollTarget.rollDice = event.target.dataset?.rollDice
|
||||
break
|
||||
case "weapon-damage-small":
|
||||
case "weapon-damage-medium":
|
||||
case "weapon-attack":
|
||||
case "weapon-defense":
|
||||
let weapon = this.actor.items.find((i) => i.type === "weapon" && i.id === rollKey)
|
||||
let skill
|
||||
let skills = this.actor.items.filter((i) => i.type === "skill" && i.name.toLowerCase() === weapon.name.toLowerCase())
|
||||
if (skills.length > 0) {
|
||||
skill = this.getBestWeaponClassSkill(skills, rollType, 1.0)
|
||||
} else {
|
||||
skills = this.actor.items.filter((i) => i.type === "skill" && i.name.toLowerCase().replace(" skill", "") === weapon.name.toLowerCase())
|
||||
if (skills.length > 0) {
|
||||
skill = this.getBestWeaponClassSkill(skills, rollType, 1.0)
|
||||
} else {
|
||||
skills = this.actor.items.filter((i) => i.type === "skill" && i.system.weaponClass === weapon.system.weaponClass)
|
||||
if (skills.length > 0) {
|
||||
skill = this.getBestWeaponClassSkill(skills, rollType, 0.5)
|
||||
} else {
|
||||
skills = this.actor.items.filter((i) => i.type === "skill" && i.system.weaponClass.includes(SYSTEM.WEAPON_CATEGORIES[weapon.system.weaponClass]))
|
||||
if (skills.length > 0) {
|
||||
skill = this.getBestWeaponClassSkill(skills, rollType, 0.25)
|
||||
} else {
|
||||
ui.notifications.warn(game.i18n.localize("LETHALFANTASY.Notifications.skillNotFound"))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!weapon || !skill) {
|
||||
console.error("Weapon or skill not found", weapon, skill)
|
||||
ui.notifications.warn(game.i18n.localize("LETHALFANTASY.Notifications.skillNotFound"))
|
||||
return
|
||||
}
|
||||
rollTarget = skill
|
||||
rollTarget.weapon = weapon
|
||||
rollTarget.weaponSkillModifier = skill.weaponSkillModifier
|
||||
rollTarget.rollKey = rollKey
|
||||
rollTarget.combat = foundry.utils.duplicate(this.actor.system.combat)
|
||||
break
|
||||
default:
|
||||
ui.notifications.error(game.i18n.localize("LETHALFANTASY.Notifications.rollTypeNotFound") + String(rollType))
|
||||
break
|
||||
}
|
||||
|
||||
// In all cases
|
||||
console.log(rollTarget)
|
||||
await this.document.system.roll(rollType, rollTarget)
|
||||
let rollDice = event.target.dataset?.rollDice || "0"
|
||||
this.actor.system.prepareMonsterRoll(rollType, rollKey, rollDice)
|
||||
}
|
||||
// #endregion
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ export default class LethalFantasyActor extends Actor {
|
||||
}
|
||||
}
|
||||
|
||||
/* *************************************************/
|
||||
getBestWeaponClassSkill(skills, rollType, multiplier = 1.0) {
|
||||
let maxValue = 0
|
||||
let goodSkill = skills[0]
|
||||
@ -68,6 +69,7 @@ export default class LethalFantasyActor extends Actor {
|
||||
return goodSkill
|
||||
}
|
||||
|
||||
/* *************************************************/
|
||||
async prepareRoll(rollType, rollKey, rollDice ) {
|
||||
console.log("Preparing roll", rollType, rollKey, rollDice)
|
||||
let rollTarget
|
||||
|
@ -221,8 +221,8 @@ export default class LethalFantasyRoll extends Roll {
|
||||
hasChangeDice = false
|
||||
options.rollTarget.value = options.rollTarget.actorModifiers.levelSpellModifier + options.rollTarget.actorModifiers.intSpellModifier
|
||||
options.rollTarget.charModifier = options.rollTarget.actorModifiers.intSpellModifier
|
||||
hasStaticModifier = true // options.rollType === "spell-power"
|
||||
hasModifier = true //options.rollType !== "spell-attack"
|
||||
hasStaticModifier = options.rollType === "spell-power"
|
||||
hasModifier = options.rollType !== "spell-attack"
|
||||
options.rollTarget.staticModifier = options.rollTarget.actorLevel
|
||||
|
||||
} else if (options.rollType === "miracle" || options.rollType === "miracle-attack" || options.rollType === "miracle-power") {
|
||||
@ -234,8 +234,8 @@ export default class LethalFantasyRoll extends Roll {
|
||||
hasChangeDice = false
|
||||
options.rollTarget.value = options.rollTarget.actorModifiers.levelMiracleModifier + options.rollTarget.actorModifiers.chaMiracleModifier
|
||||
options.rollTarget.charModifier = options.rollTarget.actorModifiers.chaMiracleModifier
|
||||
hasStaticModifier = true // options.rollType === "spell-power"
|
||||
hasModifier = true // options.rollType !== "miracle-attack"
|
||||
hasStaticModifier = options.rollType === "spell-power"
|
||||
hasModifier = options.rollType !== "miracle-attack"
|
||||
options.rollTarget.staticModifier = options.rollTarget.actorLevel
|
||||
|
||||
} else if (options.rollType === "shield-roll") {
|
||||
@ -302,6 +302,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
rollType: options.rollType,
|
||||
rollTarget: options.rollTarget,
|
||||
rollName: options.rollName,
|
||||
actorName: options.actorName,
|
||||
rollModes,
|
||||
hasModifier,
|
||||
hasFavor,
|
||||
@ -373,7 +374,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
if (hasStaticModifier) {
|
||||
modifierFormula += ` + ${options.rollTarget.staticModifier}`
|
||||
}
|
||||
modifierFormula += ` + ${options.rollTarget.charModifier}`
|
||||
// modifierFormula += ` + ${options.rollTarget.charModifier}`
|
||||
let sign = fullModifier < 0 ? "-" : "+"
|
||||
if (hasExplode) {
|
||||
titleFormula = `${dice}E ${sign} ${modifierFormula}`
|
||||
@ -543,6 +544,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
return rollBase
|
||||
}
|
||||
|
||||
/* ***********************************************************/
|
||||
static async promptInitiative(options = {}) {
|
||||
const rollModes = Object.fromEntries(Object.entries(CONFIG.Dice.rollModes).map(([key, value]) => [key, game.i18n.localize(value)]))
|
||||
const fieldRollMode = new foundry.data.fields.StringField({
|
||||
@ -603,6 +605,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
|
||||
}
|
||||
|
||||
/* ***********************************************************/
|
||||
static async promptCombatAction(options = {}) {
|
||||
|
||||
const rollModes = Object.fromEntries(Object.entries(CONFIG.Dice.rollModes).map(([key, value]) => [key, game.i18n.localize(value)]))
|
||||
@ -641,22 +644,22 @@ export default class LethalFantasyRoll extends Roll {
|
||||
})
|
||||
} else if (currentAction.type === "spell" || currentAction.type === "miracle") {
|
||||
let label = ""
|
||||
if ( currentAction.spellStatus === "castingTime") {
|
||||
if (currentAction.spellStatus === "castingTime") {
|
||||
label = "Wait casting time"
|
||||
}
|
||||
if ( currentAction.spellStatus === "toBeCasted") {
|
||||
if (currentAction.spellStatus === "toBeCasted") {
|
||||
label = "Cast spell/miracle"
|
||||
}
|
||||
if ( currentAction.spellStatus === "lethargy") {
|
||||
if (currentAction.spellStatus === "lethargy") {
|
||||
label = "Roll lethargy dice"
|
||||
}
|
||||
buttons.push({
|
||||
action: "roll",
|
||||
label: label,
|
||||
callback: (event, button, dialog) => {
|
||||
return "rollLethargyDice"
|
||||
},
|
||||
})
|
||||
action: "roll",
|
||||
label: label,
|
||||
callback: (event, button, dialog) => {
|
||||
return "rollLethargyDice"
|
||||
},
|
||||
})
|
||||
}
|
||||
} else {
|
||||
buttons.push({
|
||||
@ -731,8 +734,8 @@ export default class LethalFantasyRoll extends Roll {
|
||||
|
||||
if (currentAction) {
|
||||
if (rollContext === "rollLethargyDice") {
|
||||
if ( currentAction.spellStatus === "castingTime") {
|
||||
if ( currentAction.castingTime < currentAction.system.castingTime) {
|
||||
if (currentAction.spellStatus === "castingTime") {
|
||||
if (currentAction.castingTime < currentAction.system.castingTime) {
|
||||
let message = `Casting time : ${currentAction.name}, count : ${currentAction.castingTime}/${currentAction.system.castingTime}`
|
||||
ChatMessage.create({ content: message, speaker: ChatMessage.getSpeaker({ actor: combatant.actor }) })
|
||||
currentAction.castingTime += 1
|
||||
@ -747,8 +750,8 @@ export default class LethalFantasyRoll extends Roll {
|
||||
return
|
||||
}
|
||||
}
|
||||
if ( currentAction.spellStatus === "toBeCasted") {
|
||||
combatant.actor.prepareRoll( (currentAction.type === "spell") ? "spell-attack" : "miracle-attack" , currentAction._id)
|
||||
if (currentAction.spellStatus === "toBeCasted") {
|
||||
combatant.actor.prepareRoll((currentAction.type === "spell") ? "spell-attack" : "miracle-attack", currentAction._id)
|
||||
if (currentAction.type === "spell") {
|
||||
currentAction.spellStatus = "lethargy"
|
||||
await combatant.setFlag(SYSTEM.id, "currentAction", foundry.utils.duplicate(currentAction))
|
||||
@ -758,7 +761,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
}
|
||||
return
|
||||
}
|
||||
if ( currentAction.spellStatus === "lethargy") {
|
||||
if (currentAction.spellStatus === "lethargy") {
|
||||
// Roll lethargy dice
|
||||
let dice = LethalFantasyUtils.getLethargyDice(currentAction.system.level)
|
||||
let roll = new Roll(dice)
|
||||
@ -772,7 +775,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
// Update the combatant progression count
|
||||
await combatant.setFlag(SYSTEM.id, "currentAction", "")
|
||||
// Display the action selection window again
|
||||
combatant.actor.system.rollProgressionDice(options.combatId, options.combatantId )
|
||||
combatant.actor.system.rollProgressionDice(options.combatId, options.combatantId)
|
||||
} else {
|
||||
// Notify that the player cannot act now with a chat message
|
||||
currentAction.progressionCount += 1
|
||||
@ -839,7 +842,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ***********************************************************/
|
||||
static async promptProgressionDice(options = {}) {
|
||||
|
||||
const rollModes = Object.fromEntries(Object.entries(CONFIG.Dice.rollModes).map(([key, value]) => [key, game.i18n.localize(value)]))
|
||||
@ -1011,6 +1014,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
}
|
||||
}
|
||||
|
||||
/* ***********************************************************/
|
||||
static async promptRangedDefense(rollTarget) {
|
||||
|
||||
const rollModes = Object.fromEntries(Object.entries(CONFIG.Dice.rollModes).map(([key, value]) => [key, game.i18n.localize(value)]))
|
||||
|
@ -76,7 +76,7 @@ export default class LethalFantasyMonster extends foundry.abstract.TypeDataModel
|
||||
}
|
||||
return new fields.SchemaField(schema, { label })
|
||||
}
|
||||
// Add 4 attackFields in an attack schema
|
||||
// Add 4 attackFields in an attack schema
|
||||
schema.attacks = new fields.SchemaField({
|
||||
attack1: attackField("1"),
|
||||
attack2: attackField("2"),
|
||||
@ -145,6 +145,73 @@ export default class LethalFantasyMonster extends foundry.abstract.TypeDataModel
|
||||
await roll.toMessage({}, { rollMode: roll.options.rollMode })
|
||||
}
|
||||
|
||||
async prepareMonsterRoll(rollType, rollKey, rollDice) {
|
||||
let rollTarget
|
||||
switch (rollType) {
|
||||
case "monster-attack":
|
||||
case "monster-defense":
|
||||
case "monster-damage":
|
||||
rollTarget = foundry.utils.duplicate(this.attacks[rollKey])
|
||||
rollTarget.rollKey = rollKey
|
||||
break
|
||||
case "monster-skill":
|
||||
rollTarget = foundry.utils.duplicate(this.resists[rollKey])
|
||||
rollTarget.rollKey = rollKey
|
||||
break
|
||||
case "save":
|
||||
rollTarget = foundry.utils.duplicate(this.saves[rollKey])
|
||||
rollTarget.rollKey = rollKey
|
||||
rollTarget.rollDice = rollDice
|
||||
break
|
||||
case "weapon-damage-small":
|
||||
case "weapon-damage-medium":
|
||||
case "weapon-attack":
|
||||
case "weapon-defense":
|
||||
let weapon = this.actor.items.find((i) => i.type === "weapon" && i.id === rollKey)
|
||||
let skill
|
||||
let skills = this.actor.items.filter((i) => i.type === "skill" && i.name.toLowerCase() === weapon.name.toLowerCase())
|
||||
if (skills.length > 0) {
|
||||
skill = this.getBestWeaponClassSkill(skills, rollType, 1.0)
|
||||
} else {
|
||||
skills = this.actor.items.filter((i) => i.type === "skill" && i.name.toLowerCase().replace(" skill", "") === weapon.name.toLowerCase())
|
||||
if (skills.length > 0) {
|
||||
skill = this.getBestWeaponClassSkill(skills, rollType, 1.0)
|
||||
} else {
|
||||
skills = this.actor.items.filter((i) => i.type === "skill" && i.system.weaponClass === weapon.system.weaponClass)
|
||||
if (skills.length > 0) {
|
||||
skill = this.getBestWeaponClassSkill(skills, rollType, 0.5)
|
||||
} else {
|
||||
skills = this.actor.items.filter((i) => i.type === "skill" && i.system.weaponClass.includes(SYSTEM.WEAPON_CATEGORIES[weapon.system.weaponClass]))
|
||||
if (skills.length > 0) {
|
||||
skill = this.getBestWeaponClassSkill(skills, rollType, 0.25)
|
||||
} else {
|
||||
ui.notifications.warn(game.i18n.localize("LETHALFANTASY.Notifications.skillNotFound"))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!weapon || !skill) {
|
||||
console.error("Weapon or skill not found", weapon, skill)
|
||||
ui.notifications.warn(game.i18n.localize("LETHALFANTASY.Notifications.skillNotFound"))
|
||||
return
|
||||
}
|
||||
rollTarget = skill
|
||||
rollTarget.weapon = weapon
|
||||
rollTarget.weaponSkillModifier = skill.weaponSkillModifier
|
||||
rollTarget.rollKey = rollKey
|
||||
rollTarget.combat = foundry.utils.duplicate(this.combat)
|
||||
break
|
||||
default:
|
||||
ui.notifications.error(game.i18n.localize("LETHALFANTASY.Notifications.rollTypeNotFound") + String(rollType))
|
||||
break
|
||||
}
|
||||
|
||||
// In all cases
|
||||
console.log(rollTarget)
|
||||
await this.roll(rollType, rollTarget)
|
||||
}
|
||||
|
||||
async rollInitiative(combatId = undefined, combatantId = undefined) {
|
||||
const hasTarget = false
|
||||
|
||||
@ -164,7 +231,7 @@ export default class LethalFantasyMonster extends foundry.abstract.TypeDataModel
|
||||
await roll.toMessage({}, { rollMode: roll.options.rollMode })
|
||||
}
|
||||
|
||||
async rollProgressionDice(combatId, combatantId, rollProgressionCount) {
|
||||
async rollProgressionDice(combatId, combatantId) {
|
||||
|
||||
const rollModes = Object.fromEntries(Object.entries(CONFIG.Dice.rollModes).map(([key, value]) => [key, game.i18n.localize(value)]))
|
||||
const fieldRollMode = new foundry.data.fields.StringField({
|
||||
@ -175,7 +242,8 @@ export default class LethalFantasyMonster extends foundry.abstract.TypeDataModel
|
||||
|
||||
let roll = new Roll("1D8")
|
||||
await roll.evaluate()
|
||||
let max = rollProgressionCount
|
||||
let combatant = game.combats.get(combatId)?.combatants?.get(combatantId)
|
||||
|
||||
let msg = await roll.toMessage({ flavor: `Progression Roll for ${this.parent.name}` } )
|
||||
if (game?.dice3d) {
|
||||
await game.dice3d.waitFor3DAnimationByMessageID(msg.id)
|
||||
@ -188,14 +256,14 @@ export default class LethalFantasyMonster extends foundry.abstract.TypeDataModel
|
||||
hasAttack = true
|
||||
let message = game.i18n.format("LETHALFANTASY.Notifications.messageProgressionOKMonster", { isMonster: true, name: this.parent.name, weapon: attack.name, roll: roll.total })
|
||||
ChatMessage.create({ content: message, speaker: ChatMessage.getSpeaker({ actor: this.parent }) })
|
||||
this.prepareMonsterRoll("monster-attack", key)
|
||||
}
|
||||
}
|
||||
if (!hasAttack) {
|
||||
let message = game.i18n.format("LETHALFANTASY.Notifications.messageProgressionKOMonster", { isMonster: true, name: this.parent.name, roll: roll.total })
|
||||
ChatMessage.create({ content: message, speaker: ChatMessage.getSpeaker({ actor: this.parent }) })
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user