Review fight automation + alchimie
This commit is contained in:
@ -127,16 +127,16 @@ export class BoLUtility {
|
||||
return undefined;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
static getOtherWhisperRecipients( name) {
|
||||
static getOtherWhisperRecipients(name) {
|
||||
let users = []
|
||||
for( let user of game.users) {
|
||||
if ( !user.isGM && user.name != name) {
|
||||
users.push( user.data._id)
|
||||
for (let user of game.users) {
|
||||
if (!user.isGM && user.name != name) {
|
||||
users.push(user.data._id)
|
||||
}
|
||||
}
|
||||
return users
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getWhisperRecipientsAndGMs(name) {
|
||||
let recep1 = ChatMessage.getWhisperRecipients(name) || [];
|
||||
@ -173,34 +173,39 @@ export class BoLUtility {
|
||||
//console.log("FOUND 1!!! ", actor)
|
||||
if (actor && actor.isOwner) return
|
||||
else if (game.user.isGM || data.author.id === game.user.id) return
|
||||
|
||||
|
||||
const divButtons = chatCard.find('.actions-section')
|
||||
console.log("FOUND 2!! ", divButtons)
|
||||
divButtons.hide()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getRollDataFromMessage( event ) {
|
||||
static getRollDataFromMessage(event) {
|
||||
let messageId = BoLUtility.findChatMessageId(event.currentTarget)
|
||||
let message = game.messages.get(messageId)
|
||||
return message.getFlag("world", "bol-roll-data")
|
||||
return message.getFlag("world", "bol-roll-data")
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static cleanupButtons(id) {
|
||||
$(`#${id}`).hide() // Hide the options roll buttons
|
||||
game.socket.emit("system.bol", { name: "msg_cleanup_buttons", data: { id: id } })
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async chatListeners(html) {
|
||||
|
||||
|
||||
// Damage handling
|
||||
html.on("click", '.chat-damage-apply', event => {
|
||||
let rollData = BoLUtility.getRollDataFromMessage(event)
|
||||
console.log("DATA !!!", rollData)
|
||||
$(`#${rollData.applyId}`).hide()
|
||||
BoLUtility.cleanupButtons(rollData.applyId)
|
||||
BoLUtility.sendAttackSuccess(rollData)
|
||||
});
|
||||
|
||||
html.on("click", '.chat-damage-roll', event => {
|
||||
event.preventDefault();
|
||||
event.preventDefault()
|
||||
let rollData = BoLUtility.getRollDataFromMessage(event)
|
||||
rollData.damageMode = event.currentTarget.attributes['data-damage-mode'].value
|
||||
let bolRoll = new BoLDefaultRoll(rollData)
|
||||
bolRoll.rollDamage()
|
||||
});
|
||||
@ -208,7 +213,7 @@ export class BoLUtility {
|
||||
html.on("click", '.transform-legendary-roll', event => {
|
||||
event.preventDefault();
|
||||
let rollData = BoLUtility.getRollDataFromMessage(event)
|
||||
let actor = game.actors.get( rollData.actorId)
|
||||
let actor = game.actors.get(rollData.actorId)
|
||||
actor.subHeroPoints(1)
|
||||
let r = new BoLDefaultRoll(rollData)
|
||||
r.upgradeToLegendary()
|
||||
@ -217,7 +222,7 @@ export class BoLUtility {
|
||||
html.on("click", '.transform-heroic-roll', event => {
|
||||
event.preventDefault();
|
||||
let rollData = BoLUtility.getRollDataFromMessage(event)
|
||||
let actor = game.actors.get( rollData.actorId)
|
||||
let actor = game.actors.get(rollData.actorId)
|
||||
actor.subHeroPoints(1)
|
||||
let r = new BoLDefaultRoll(rollData)
|
||||
r.upgradeToHeroic()
|
||||
@ -226,7 +231,7 @@ export class BoLUtility {
|
||||
html.on("click", '.hero-reroll', event => {
|
||||
event.preventDefault();
|
||||
let rollData = BoLUtility.getRollDataFromMessage(event)
|
||||
let actor = game.actors.get( rollData.actorId)
|
||||
let actor = game.actors.get(rollData.actorId)
|
||||
actor.subHeroPoints(1)
|
||||
rollData.reroll = false // Disable reroll option for second roll
|
||||
let r = new BoLDefaultRoll(rollData)
|
||||
@ -238,24 +243,24 @@ export class BoLUtility {
|
||||
let attackId = event.currentTarget.attributes['data-attack-id'].value
|
||||
let defenseMode = event.currentTarget.attributes['data-defense-mode'].value
|
||||
let weaponId = (event.currentTarget.attributes['data-weapon-id']) ? event.currentTarget.attributes['data-weapon-id'].value : -1
|
||||
|
||||
// Remove message for all
|
||||
let msgId = BoLUtility.findChatMessageId(event.currentTarget)
|
||||
if (game.user.isGM) {
|
||||
console.log("Process handling !!! -> GM direct damage handling")
|
||||
BoLUtility.processDamageHandling(event, attackId, defenseMode, weaponId)
|
||||
BoLUtility.processDamageHandling(attackId, defenseMode, weaponId, msgId)
|
||||
} else {
|
||||
console.log("Process handling !!! -> socket emit")
|
||||
game.socket.emit("system.bol", { name: "msg_damage_handling", data: { event: event, attackId: attackId, defenseMode: defenseMode, weaponId: weaponId } });
|
||||
game.socket.emit("system.bol", { name: "msg_damage_handling", data: { msgId: msgId, attackId: attackId, defenseMode: defenseMode, weaponId: weaponId } })
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async processDamageHandling(event, attackId, defenseMode, weaponId = -1) {
|
||||
static async processDamageHandling(attackId, defenseMode, weaponId = -1, msgId) {
|
||||
if (!game.user.isGM) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
BoLUtility.removeChatMessageId(BoLUtility.findChatMessageId(event.currentTarget));
|
||||
|
||||
console.log("Damage Handling", event, attackId, defenseMode, weaponId)
|
||||
BoLUtility.removeChatMessageId( msgId )
|
||||
console.log("Damage Handling", attackId, defenseMode, weaponId)
|
||||
// Only GM process this
|
||||
let attackDef = this.attackStore[attackId]
|
||||
if (attackDef && attackDef.defenderId) {
|
||||
@ -270,7 +275,7 @@ export class BoLUtility {
|
||||
if (defenseMode == 'damage-with-armor') {
|
||||
let armorFormula = defender.getArmorFormula()
|
||||
attackDef.rollArmor = new Roll(armorFormula)
|
||||
attackDef.rollArmor.roll( { async: false } )
|
||||
attackDef.rollArmor.roll({ async: false })
|
||||
attackDef.armorProtect = (attackDef.rollArmor.total < 0) ? 0 : attackDef.rollArmor.total
|
||||
attackDef.finalDamage = attackDef.damageTotal - attackDef.armorProtect
|
||||
attackDef.finalDamage = (attackDef.finalDamage < 0) ? 0 : attackDef.finalDamage
|
||||
@ -298,21 +303,35 @@ export class BoLUtility {
|
||||
attackDef.weaponHero = defender.weapons.find(item => item._id == weaponId);
|
||||
defender.deleteEmbeddedDocuments("Item", [weaponId]);
|
||||
}
|
||||
|
||||
let defenderUser
|
||||
for (let user of game.users) {
|
||||
if ( user.character && user.character.id == defender.id ) {
|
||||
defenderUser = user
|
||||
}
|
||||
}
|
||||
let damageResults = {
|
||||
attackId: attackDef.id,
|
||||
attacker: attackDef.attacker,
|
||||
rollArmor: attackDef.rollArmor,
|
||||
rollHero: attackDef.rollHero,
|
||||
weaponHero: attackDef.weaponHero,
|
||||
armorProtect: attackDef.armorProtect,
|
||||
name: defender.name,
|
||||
defender: defender,
|
||||
defenseMode: attackDef.defenseMode,
|
||||
finalDamage: attackDef.finalDamage
|
||||
}
|
||||
ChatMessage.create({
|
||||
alias: defender.name,
|
||||
whisper: BoLUtility.getWhisperRecipientsAndGMs(defender.name),
|
||||
content: await renderTemplate('systems/bol/templates/chat/rolls/defense-result-card.hbs', {
|
||||
attackId: attackDef.id,
|
||||
attacker: attackDef.attacker,
|
||||
rollArmor: attackDef.rollArmor,
|
||||
rollHero: attackDef.rollHero,
|
||||
weaponHero: attackDef.weaponHero,
|
||||
armorProtect: attackDef.armorProtect,
|
||||
name: defender.name,
|
||||
defender: defender,
|
||||
defenseMode: attackDef.defenseMode,
|
||||
finalDamage: attackDef.finalDamage
|
||||
})
|
||||
content: await renderTemplate('systems/bol/templates/chat/rolls/defense-result-card.hbs', damageResults)
|
||||
})
|
||||
console.log("Defender data : ", defenderUser)
|
||||
ChatMessage.create({
|
||||
alias: defender.name,
|
||||
whisper: BoLUtility.getOtherWhisperRecipients(defenderUser?.name),
|
||||
content: await renderTemplate('systems/bol/templates/chat/rolls/defense-summary-card.hbs', damageResults)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -417,8 +436,11 @@ export class BoLUtility {
|
||||
if (sockmsg.name == "msg_attack_success") {
|
||||
BoLUtility.processAttackSuccess(sockmsg.data)
|
||||
}
|
||||
if (sockmsg.name == "msg_cleanup_buttons") {
|
||||
$(`#${sockmsg.data.id}`).hide() // Hide the options roll buttons
|
||||
}
|
||||
if (sockmsg.name == "msg_damage_handling") {
|
||||
BoLUtility.processDamageHandling(sockmsg.data.event, sockmsg.data.attackId, sockmsg.data.defenseMode)
|
||||
BoLUtility.processDamageHandling(sockmsg.data.attackId, sockmsg.data.defenseMode, sockmsg.data.weaponId, sockmsg.data.msgId)
|
||||
}
|
||||
}
|
||||
|
||||
@ -450,11 +472,11 @@ export class BoLUtility {
|
||||
let postForm = 'kh' + nbDice
|
||||
let modIndex = 3
|
||||
// Upgrade damage if needed
|
||||
if ( upgradeDamage && ( !res[3] || res[3]=="") ) {
|
||||
if (upgradeDamage && (!res[3] || res[3] == "")) {
|
||||
res[3] = "B" // Upgrade to bonus
|
||||
}
|
||||
if (res[3]) {
|
||||
if ( upgradeDamage && res[3] == 'M') {
|
||||
if (upgradeDamage && res[3] == 'M') {
|
||||
res[3] = "" // Disable lamlus for upgradeDamage
|
||||
}
|
||||
if (res[3] == 'M') {
|
||||
|
Reference in New Issue
Block a user