Review fight automation

This commit is contained in:
sladecraven 2022-06-11 10:21:18 +02:00
parent ef5cf6f393
commit 7259d3dc21
4 changed files with 59 additions and 44 deletions

View File

@ -363,6 +363,7 @@ export class BoLActor extends Actor {
} }
} }
/*-------------------------------------------- */
getAlchemistBonus() { getAlchemistBonus() {
let sorcerer = this.careers.find(item => item.data.properties.alchemist == true) let sorcerer = this.careers.find(item => item.data.properties.alchemist == true)
if (sorcerer) { if (sorcerer) {
@ -370,6 +371,7 @@ export class BoLActor extends Actor {
} }
return 0; return 0;
} }
/*-------------------------------------------- */
getSorcererBonus() { getSorcererBonus() {
let sorcerer = this.careers.find(item => item.data.properties.sorcerer == true) let sorcerer = this.careers.find(item => item.data.properties.sorcerer == true)
if (sorcerer) { if (sorcerer) {
@ -378,6 +380,7 @@ export class BoLActor extends Actor {
return 0; return 0;
} }
/*-------------------------------------------- */
heroReroll() { heroReroll() {
if (this.type == 'character') { if (this.type == 'character') {
return this.data.data.resources.hero.value > 0; return this.data.data.resources.hero.value > 0;
@ -550,7 +553,7 @@ export class BoLActor extends Actor {
async manageHealthState() { async manageHealthState() {
let hpID = "lastHP" + this.id let hpID = "lastHP" + this.id
let lastHP = await this.getFlag("world", hpID) let lastHP = await this.getFlag("world", hpID)
if (lastHP != this.data.data.resources.hp.value && this.isOwner ) { if (lastHP != this.data.data.resources.hp.value && game.user.isGM ) { // Only GM sends this
await this.setFlag("world", hpID, this.data.data.resources.hp.value) await this.setFlag("world", hpID, this.data.data.resources.hp.value)
if (this.data.data.resources.hp.value <= 0) { if (this.data.data.resources.hp.value <= 0) {
ChatMessage.create({ ChatMessage.create({
@ -614,9 +617,9 @@ export class BoLActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
rollProtection(itemId) { rollProtection(itemId) {
let armor = this.data.items.get(itemId) let armor = duplicate(this.data.items.get(itemId))
if (armor) { if (armor) {
let armorFormula = "max("+armor.data.data.properties.soak.formula + ", 0)" let armorFormula = "max("+armor.data.properties.soak.formula + ", 0)"
let rollArmor = new Roll(armorFormula) let rollArmor = new Roll(armorFormula)
rollArmor.roll({ async: false }).toMessage() rollArmor.roll({ async: false }).toMessage()
} }
@ -624,7 +627,7 @@ export class BoLActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
rollWeaponDamage(itemId) { rollWeaponDamage(itemId) {
let weapon = this.data.items.get(itemId) let weapon = duplicate(this.data.items.get(itemId))
if (weapon) { if (weapon) {
let r = new BoLDefaultRoll({ id: randomID(16), isSuccess: true, mode: "weapon", weapon: weapon, actorId: this.id, actor: this }) let r = new BoLDefaultRoll({ id: randomID(16), isSuccess: true, mode: "weapon", weapon: weapon, actorId: this.id, actor: this })
r.setSuccess(true) r.setSuccess(true)

View File

@ -72,7 +72,7 @@ export class BoLRoll {
let target = BoLUtility.getTarget() let target = BoLUtility.getTarget()
let weaponData = weapon.data.data let weaponData = weapon.data
let attribute = eval(`actor.data.data.attributes.${weaponData.properties.attackAttribute}`) let attribute = eval(`actor.data.data.attributes.${weaponData.properties.attackAttribute}`)
let aptitude = eval(`actor.data.data.aptitudes.${weaponData.properties.attackAptitude}`) let aptitude = eval(`actor.data.data.aptitudes.${weaponData.properties.attackAptitude}`)
@ -109,23 +109,25 @@ export class BoLRoll {
/* -------------------------------------------- */ /* -------------------------------------------- */
static weaponCheck(actor, event) { static weaponCheck(actor, event) {
const li = $(event.currentTarget).parents(".item") const li = $(event.currentTarget).parents(".item")
const weapon = actor.items.get(li.data("item-id")) let weapon = actor.items.get(li.data("item-id"))
if (!weapon) { if (!weapon) {
ui.notifications.warn("Unable to find weapon !") ui.notifications.warn("Unable to find weapon !")
return return
} }
weapon = duplicate(weapon)
return this.weaponCheckWithWeapon(actor, weapon) return this.weaponCheckWithWeapon(actor, weapon)
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static alchemyCheck(actor, event) { static alchemyCheck(actor, event) {
const li = $(event.currentTarget).parents(".item"); const li = $(event.currentTarget).parents(".item");
const alchemy = actor.items.get(li.data("item-id")); let alchemy = actor.items.get(li.data("item-id"));
if (!alchemy) { if (!alchemy) {
ui.notifications.warn("Unable to find Alchemy !"); ui.notifications.warn("Unable to find Alchemy !");
return; return;
} }
let alchemyData = alchemy.data.data alchemy = dupicate(alchemy)
let alchemyData = alchemy.data
if (alchemyData.properties.pccurrent < alchemyData.properties.pccost) { if (alchemyData.properties.pccurrent < alchemyData.properties.pccost) {
ui.notifications.warn("Pas assez de Points de Cration investis dans la Préparation !") ui.notifications.warn("Pas assez de Points de Cration investis dans la Préparation !")
return return
@ -154,7 +156,7 @@ export class BoLRoll {
/* -------------------------------------------- */ /* -------------------------------------------- */
static spellCheckWithSpell( actor, spell ) { static spellCheckWithSpell( actor, spell ) {
let spellData = spell.data.data let spellData = spell.data
let spellDef = { let spellDef = {
mode: "spell", mode: "spell",
actorId: actor.id, actorId: actor.id,
@ -184,11 +186,12 @@ export class BoLRoll {
return return
} }
const li = $(event.currentTarget).parents(".item") const li = $(event.currentTarget).parents(".item")
const spell = actor.items.get(li.data("item-id")) let spell = actor.items.get(li.data("item-id"))
if (!spell) { if (!spell) {
ui.notifications.warn("Impossible de trouver ce sort !") ui.notifications.warn("Impossible de trouver ce sort !")
return return
} }
spell = duplicate(spell)
return this.spellCheckWithSpell( actor, spell) return this.spellCheckWithSpell( actor, spell)
} }
@ -207,7 +210,7 @@ export class BoLRoll {
$('#roll-nbdice').val("2 + " + String(Math.abs(this.rollData.bmDice)) + letter) $('#roll-nbdice').val("2 + " + String(Math.abs(this.rollData.bmDice)) + letter)
} }
let rollbase = this.rollData.attrValue + "+" + this.rollData.aptValue let rollbase = this.rollData.attrValue + "+" + this.rollData.aptValue
if ( this.rollData.weapon && this.rollData.weapon.data.data.properties.onlymodifier ) { if ( this.rollData.weapon && this.rollData.weapon.data.properties.onlymodifier ) {
rollbase = "" rollbase = ""
} }
$('#roll-modifier').val(rollbase + "+" + this.rollData.careerBonus + "+" + this.rollData.mod + "+" + $('#roll-modifier').val(rollbase + "+" + this.rollData.careerBonus + "+" + this.rollData.mod + "+" +
@ -337,8 +340,8 @@ export class BoLRoll {
/* -------------------------------------------- */ /* -------------------------------------------- */
static preProcessWeapon(rollData, defender) { static preProcessWeapon(rollData, defender) {
if (rollData.mode == "weapon") { if (rollData.mode == "weapon") {
rollData.weaponModifier = rollData.weapon.data.data.properties.attackModifiers ?? 0; rollData.weaponModifier = rollData.weapon.data.properties.attackModifiers ?? 0;
rollData.attackBonusDice = rollData.weapon.data.data.properties.attackBonusDice rollData.attackBonusDice = rollData.weapon.data.properties.attackBonusDice
if (defender) { // If target is selected if (defender) { // If target is selected
rollData.defence = defender.defenseValue rollData.defence = defender.defenseValue
rollData.armorMalus = defender.armorMalusValue rollData.armorMalus = defender.armorMalusValue
@ -429,7 +432,7 @@ export class BoLRoll {
rollData.nbDice += (rollData.attackBonusDice) ? 1 : 0 rollData.nbDice += (rollData.attackBonusDice) ? 1 : 0
let rollbase = rollData.attrValue + rollData.aptValue let rollbase = rollData.attrValue + rollData.aptValue
if ( rollData.weapon && rollData.weapon.data.data.properties.onlymodifier ) { if ( rollData.weapon && rollData.weapon.data.properties.onlymodifier ) {
rollbase = 0 rollbase = 0
} }
const modifiers = rollbase + rollData.careerBonus + rollData.mod + rollData.weaponModifier - rollData.defence - rollData.modArmorMalus + rollData.shieldMalus + rollData.attackModifier + rollData.appliedArmorMalus const modifiers = rollbase + rollData.careerBonus + rollData.mod + rollData.weaponModifier - rollData.defence - rollData.modArmorMalus + rollData.shieldMalus + rollData.attackModifier + rollData.appliedArmorMalus
@ -454,7 +457,6 @@ export class BoLRoll {
export class BoLDefaultRoll { export class BoLDefaultRoll {
constructor(rollData) { constructor(rollData) {
BoLUtility.storeRoll(rollData)
this.rollData = rollData this.rollData = rollData
if (this.rollData.isSuccess == undefined) { // First init if (this.rollData.isSuccess == undefined) { // First init
this.rollData.isSuccess = false; this.rollData.isSuccess = false;
@ -500,7 +502,7 @@ export class BoLDefaultRoll {
actor.spendPowerPoint(this.rollData.ppCost + this.rollData.ppCostArmor) actor.spendPowerPoint(this.rollData.ppCost + this.rollData.ppCostArmor)
} }
if (this.rollData.mode == "alchemy") { // PP cost management if (this.rollData.mode == "alchemy") { // PP cost management
actor.resetAlchemyStatus(this.rollData.alchemy.id) actor.resetAlchemyStatus(this.rollData.alchemy._id)
} }
await this.sendChatMessage() await this.sendChatMessage()
@ -509,14 +511,15 @@ export class BoLDefaultRoll {
/* -------------------------------------------- */ /* -------------------------------------------- */
async sendChatMessage() { async sendChatMessage() {
let actor = game.actors.get( this.rollData.actorId) let actor = game.actors.get( this.rollData.actorId)
this._buildChatMessage(this.rollData).then(msgFlavor => { this._buildChatMessage(this.rollData).then( async msgFlavor => {
this.rollData.roll.toMessage({ let msg = await this.rollData.roll.toMessage({
user: game.user.id, user: game.user.id,
rollMode: game.settings.get("core", "rollMode"), rollMode: game.settings.get("core", "rollMode"),
//whisper: BoLUtility.getWhisperRecipientsAndGMs(this.rollData.actor.name), //whisper: BoLUtility.getWhisperRecipientsAndGMs(this.rollData.actor.name),
flavor: msgFlavor, flavor: msgFlavor,
speaker: ChatMessage.getSpeaker({ actor: actor }), speaker: ChatMessage.getSpeaker({ actor: actor }),
}) })
msg.setFlag("world", "bol-roll-data", this.rollData)
}) })
} }
@ -555,14 +558,15 @@ export class BoLDefaultRoll {
/* -------------------------------------------- */ /* -------------------------------------------- */
async sendDamageMessage() { async sendDamageMessage() {
let actor = game.actors.get( this.rollData.actorId) let actor = game.actors.get( this.rollData.actorId)
this._buildDamageChatMessage(this.rollData).then(msgFlavor => { this._buildDamageChatMessage(this.rollData).then(async msgFlavor => {
this.rollData.damageRoll.toMessage({ let msg = await this.rollData.damageRoll.toMessage({
user: game.user.id, user: game.user.id,
flavor: msgFlavor, flavor: msgFlavor,
speaker: ChatMessage.getSpeaker({ actor: actor }), speaker: ChatMessage.getSpeaker({ actor: actor }),
flags: { msgType: "default" } flags: { msgType: "default" }
}) })
}); msg.setFlag("world", "bol-roll-data", this.rollData)
})
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -582,7 +586,7 @@ export class BoLDefaultRoll {
/* -------------------------------------------- */ /* -------------------------------------------- */
async rollDamage() { async rollDamage() {
if (this.rollData.mode != "weapon") { // Only specific process in Weapon mode if (this.rollData.mode != "weapon") { // Only specific process in Weapon mode
return; return
} }
if (this.rollData.isSuccess) { if (this.rollData.isSuccess) {
@ -594,8 +598,9 @@ export class BoLDefaultRoll {
if (this.rollData.damageMode == 'damage-plus-12') { if (this.rollData.damageMode == 'damage-plus-12') {
bonusDmg = 12 bonusDmg = 12
} }
let attrDamageValue = this.getDamageAttributeValue(this.rollData.weapon.data.data.properties.damageAttribute) console.log("ROLLWEAPON: ", this.rollData)
let weaponFormula = BoLUtility.getDamageFormula(this.rollData.weapon.data.data, this.rollData.fightOption) let attrDamageValue = this.getDamageAttributeValue(this.rollData.weapon.data.properties.damageAttribute)
let weaponFormula = BoLUtility.getDamageFormula(this.rollData.weapon.data, this.rollData.fightOption)
let damageFormula = weaponFormula + "+" + bonusDmg + "+" + attrDamageValue let damageFormula = weaponFormula + "+" + bonusDmg + "+" + attrDamageValue
console.log("DAMAGE !!!", damageFormula, attrDamageValue, this.rollData) console.log("DAMAGE !!!", damageFormula, attrDamageValue, this.rollData)

View File

@ -31,7 +31,7 @@ export class BoLTokenHud {
let actionIndex = Number(event.currentTarget.attributes['data-action-index'].value) let actionIndex = Number(event.currentTarget.attributes['data-action-index'].value)
let action = hudData.actionsList[actionIndex] let action = hudData.actionsList[actionIndex]
const weapon = actor.items.get( action._id ) const weapon = actor.items.get( action._id )
BoLRoll.weaponCheckWithWeapon(hudData.actor, weapon) BoLRoll.weaponCheckWithWeapon(hudData.actor, duplicate(weapon))
//console.log("Clicked", action) //console.log("Clicked", action)
} ) } )

View File

@ -63,12 +63,12 @@ export class BoLUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static storeRoll(roll) { static storeRoll(roll) {
this.lastRoll = roll this.rollTab[roll.id] = roll
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static getLastRoll() { static getRoll(rollId) {
return this.lastRoll return this.rollTab[roll.id]
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -180,27 +180,34 @@ export class BoLUtility {
} }
} }
/* -------------------------------------------- */
static getRollDataFromMessage( event ) {
let messageId = BoLUtility.findChatMessageId(event.currentTarget)
let message = game.messages.get(messageId)
return message.getFlag("world", "bol-roll-data")
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static async chatListeners(html) { static async chatListeners(html) {
// Damage handling // Damage handling
html.on("click", '.chat-damage-apply', event => { html.on("click", '.chat-damage-apply', event => {
let rollData = BoLUtility.getLastRoll() let rollData = BoLUtility.getRollDataFromMessage(event)
console.log("DATA !!!", rollData)
$(`#${rollData.applyId}`).hide() $(`#${rollData.applyId}`).hide()
BoLUtility.sendAttackSuccess(rollData) BoLUtility.sendAttackSuccess(rollData)
}); });
html.on("click", '.chat-damage-roll', event => { html.on("click", '.chat-damage-roll', event => {
event.preventDefault(); event.preventDefault();
let rollData = BoLUtility.getLastRoll() let rollData = BoLUtility.getRollDataFromMessage(event)
rollData.damageMode = event.currentTarget.attributes['data-damage-mode'].value;
let bolRoll = new BoLDefaultRoll(rollData) let bolRoll = new BoLDefaultRoll(rollData)
bolRoll.rollDamage() bolRoll.rollDamage()
}); });
html.on("click", '.transform-legendary-roll', event => { html.on("click", '.transform-legendary-roll', event => {
event.preventDefault(); event.preventDefault();
let rollData = BoLUtility.getLastRoll() let rollData = BoLUtility.getRollDataFromMessage(event)
let actor = game.actors.get( rollData.actorId) let actor = game.actors.get( rollData.actorId)
actor.subHeroPoints(1) actor.subHeroPoints(1)
let r = new BoLDefaultRoll(rollData) let r = new BoLDefaultRoll(rollData)
@ -209,7 +216,7 @@ export class BoLUtility {
html.on("click", '.transform-heroic-roll', event => { html.on("click", '.transform-heroic-roll', event => {
event.preventDefault(); event.preventDefault();
let rollData = BoLUtility.getLastRoll() let rollData = BoLUtility.getRollDataFromMessage(event)
let actor = game.actors.get( rollData.actorId) let actor = game.actors.get( rollData.actorId)
actor.subHeroPoints(1) actor.subHeroPoints(1)
let r = new BoLDefaultRoll(rollData) let r = new BoLDefaultRoll(rollData)
@ -218,7 +225,7 @@ export class BoLUtility {
html.on("click", '.hero-reroll', event => { html.on("click", '.hero-reroll', event => {
event.preventDefault(); event.preventDefault();
let rollData = BoLUtility.getLastRoll() let rollData = BoLUtility.getRollDataFromMessage(event)
let actor = game.actors.get( rollData.actorId) let actor = game.actors.get( rollData.actorId)
actor.subHeroPoints(1) actor.subHeroPoints(1)
rollData.reroll = false // Disable reroll option for second roll rollData.reroll = false // Disable reroll option for second roll
@ -264,15 +271,15 @@ export class BoLUtility {
let armorFormula = defender.getArmorFormula() let armorFormula = defender.getArmorFormula()
attackDef.rollArmor = new Roll(armorFormula) attackDef.rollArmor = new Roll(armorFormula)
attackDef.rollArmor.roll( { async: false } ) attackDef.rollArmor.roll( { async: false } )
console.log("Armor roll ", attackDef.rollArmor) attackDef.armorProtect = (attackDef.rollArmor.total < 0) ? 0 : attackDef.rollArmor.total
attackDef.armorProtect = (attackDef.rollArmor.total < 0) ? 0 : attackDef.rollArmor.total; attackDef.finalDamage = attackDef.damageTotal - attackDef.armorProtect
attackDef.finalDamage = attackDef.damageRoll.total - attackDef.armorProtect; attackDef.finalDamage = (attackDef.finalDamage < 0) ? 0 : attackDef.finalDamage
attackDef.finalDamage = (attackDef.finalDamage < 0) ? 0 : attackDef.finalDamage; defender.sufferDamage(attackDef.finalDamage)
defender.sufferDamage(attackDef.finalDamage); console.log("Armor roll -> result ", attackDef)
} }
if (defenseMode == 'damage-without-armor') { if (defenseMode == 'damage-without-armor') {
attackDef.finalDamage = attackDef.damageRoll.total; attackDef.finalDamage = attackDef.damageTotal
defender.sufferDamage(attackDef.finalDamage); defender.sufferDamage(attackDef.finalDamage)
} }
if (defenseMode == 'hero-reduce-damage') { if (defenseMode == 'hero-reduce-damage') {
let armorFormula = defender.getArmorFormula() let armorFormula = defender.getArmorFormula()
@ -281,7 +288,7 @@ export class BoLUtility {
attackDef.armorProtect = (attackDef.rollArmor.total < 0) ? 0 : attackDef.rollArmor.total attackDef.armorProtect = (attackDef.rollArmor.total < 0) ? 0 : attackDef.rollArmor.total
attackDef.rollHero = new Roll("1d6") attackDef.rollHero = new Roll("1d6")
attackDef.rollHero.roll({ async: false }) attackDef.rollHero.roll({ async: false })
attackDef.finalDamage = attackDef.damageRoll.total - attackDef.rollHero.total - attackDef.armorProtect attackDef.finalDamage = attackDef.damageTotal - attackDef.rollHero.total - attackDef.armorProtect
attackDef.finalDamage = (attackDef.finalDamage < 0) ? 0 : attackDef.finalDamage attackDef.finalDamage = (attackDef.finalDamage < 0) ? 0 : attackDef.finalDamage
defender.sufferDamage(attackDef.finalDamage) defender.sufferDamage(attackDef.finalDamage)
defender.subHeroPoints(1) defender.subHeroPoints(1)
@ -417,8 +424,8 @@ export class BoLUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static computeSpellCost(spell, nbOptCond = 0) { static computeSpellCost(spell, nbOptCond = 0) {
let pp = spell.data.data.properties.ppcost let pp = spell.data.properties.ppcost
let minpp = __circle2minpp[spell.data.data.properties.circle] let minpp = __circle2minpp[spell.data.properties.circle]
pp = (pp - nbOptCond < minpp) ? minpp : pp - nbOptCond pp = (pp - nbOptCond < minpp) ? minpp : pp - nbOptCond
return pp return pp
} }