Merge pull request #8 from sladecraven/master

Review/fix combat mode
This commit is contained in:
ZigmundKreud 2022-01-17 23:56:36 +01:00 committed by GitHub
commit 87a5b36b0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 149 additions and 123 deletions

View File

@ -267,6 +267,10 @@ a:hover {
.bol button { .bol button {
background: rgba(0, 0, 0, 0.1); background: rgba(0, 0, 0, 0.1);
} }
.chat-button {
font-size: 0.8rem;
}
.bol select { .bol select {
box-shadow: none; box-shadow: none;
font-size: 14px; font-size: 14px;

View File

@ -1,18 +1,18 @@
import { BoLUtility } from "../system/bol-utility.js"; import { BoLUtility } from "../system/bol-utility.js";
const __adv2dice = { ["1B"]: 3, ["2B"]: 4, ["2"]: 2, ["1M"]: 3, ["2M"]: 4} const __adv2dice = { ["1B"]: 3, ["2B"]: 4, ["2"]: 2, ["1M"]: 3, ["2M"]: 4 }
const _apt2attr = {init: "mind", melee: "agility", ranged: "agility", def: "vigor"} const _apt2attr = { init: "mind", melee: "agility", ranged: "agility", def: "vigor" }
export class BoLRoll { export class BoLRoll {
static options() { static options() {
return { classes: ["bol", "dialog"] }; return { classes: ["bol", "dialog"] };
} }
static convertToAdv( adv) { static convertToAdv(adv) {
if (adv == 0) return "2" if (adv == 0) return "2"
return Math.abs(adv) + (adv < 0)?'M':'B'; return Math.abs(adv) + (adv < 0) ? 'M' : 'B';
} }
static getDefaultAttribute( key ) { static getDefaultAttribute(key) {
return _apt2attr[key] return _apt2attr[key]
} }
static attributeCheck(actor, actorData, dataset, event) { static attributeCheck(actor, actorData, dataset, event) {
@ -25,7 +25,7 @@ export class BoLRoll {
let description = actor.name + " - " + game.i18n.localize('BOL.ui.attributeCheck') + " - " + game.i18n.localize(attribute.label); let description = actor.name + " - " + game.i18n.localize('BOL.ui.attributeCheck') + " - " + game.i18n.localize(attribute.label);
return this.displayRollDialog( return this.displayRollDialog(
{ {
mode: "attribute", mode: "attribute",
actor: actor, actor: actor,
actorData: actorData, actorData: actorData,
attribute: attribute, attribute: attribute,
@ -50,7 +50,7 @@ export class BoLRoll {
let description = actor.name + " - " + game.i18n.localize('BOL.ui.aptitudeCheck') + " - " + game.i18n.localize(aptitude.label); let description = actor.name + " - " + game.i18n.localize('BOL.ui.aptitudeCheck') + " - " + game.i18n.localize(aptitude.label);
return this.displayRollDialog( return this.displayRollDialog(
{ {
mode: "aptitude", mode: "aptitude",
actor: actor, actor: actor,
actorData: actorData, actorData: actorData,
attribute: attribute, attribute: attribute,
@ -108,7 +108,7 @@ export class BoLRoll {
if (rollData.mode == "weapon") { if (rollData.mode == "weapon") {
if (rollData.defender) { // If target is selected if (rollData.defender) { // If target is selected
rollData.defence = rollData.defender.defenseValue, rollData.defence = rollData.defender.defenseValue,
rollData.shieldBlock = 'none' rollData.shieldBlock = 'none'
let shields = rollData.defender.shields let shields = rollData.defender.shields
for (let shield of shields) { for (let shield of shields) {
rollData.shieldBlock = (shield.data.properties.blocking.blockingAll) ? 'blockall' : 'blockone'; rollData.shieldBlock = (shield.data.properties.blocking.blockingAll) ? 'blockall' : 'blockone';
@ -143,10 +143,10 @@ export class BoLRoll {
rollData.mod = html.find('#mod').val() || 0; rollData.mod = html.find('#mod').val() || 0;
let careers = html.find('#career').val(); let careers = html.find('#career').val();
rollData.career = (!careers || careers.length == 0) ? 0 : Math.max(...careers.map(i => parseInt(i))); rollData.career = (!careers || careers.length == 0) ? 0 : Math.max(...careers.map(i => parseInt(i)));
rollData.registerInit = (rollData.aptKey == 'init') ? $('#register-init').is(":checked") : false; rollData.registerInit = (rollData.aptKey == 'init') ? $('#register-init').is(":checked") : false;
let shieldMalus = 0; let shieldMalus = 0;
if ( rollData.mode == "weapon") { if (rollData.mode == "weapon") {
const applyShieldMalus = html.find('#applyShieldMalus').val() || false; const applyShieldMalus = html.find('#applyShieldMalus').val() || false;
if (applyShieldMalus || rollData.shieldBlock == 'blockall') { if (applyShieldMalus || rollData.shieldBlock == 'blockall') {
shieldMalus = rollData.shieldAttackMalus; shieldMalus = rollData.shieldAttackMalus;
@ -158,10 +158,11 @@ export class BoLRoll {
//// const dicePool = (isMalus) ? 2 - parseInt(rollData.adv) : 2 + parseInt(rollData.adv); //// const dicePool = (isMalus) ? 2 - parseInt(rollData.adv) : 2 + parseInt(rollData.adv);
const attrValue = (rollData.attrKey) && eval(`rollData.actor.data.data.attributes.${rollData.attrKey}.value`) || 0; const attrValue = (rollData.attrKey) && eval(`rollData.actor.data.data.attributes.${rollData.attrKey}.value`) || 0;
const aptValue = (rollData.aptKey) && eval(`rollData.actor.data.data.aptitudes.${rollData.aptKey}.value`) || 0 const aptValue = (rollData.aptKey) && eval(`rollData.actor.data.data.aptitudes.${rollData.aptKey}.value`) || 0
const modifiers = parseInt(attrValue) + parseInt(aptValue) + parseInt(rollData.mod) + parseInt(rollData.career) - rollData.defence - shieldMalus; const modifiers = parseInt(attrValue) + parseInt(aptValue) + parseInt(rollData.mod) + parseInt(rollData.career) - rollData.defence - shieldMalus;
const formula = (isMalus) ? dicePool + "d6kl2 + " + modifiers : dicePool + "d6kh2 + " + modifiers; const formula = (isMalus) ? dicePool + "d6kl2 + " + modifiers : dicePool + "d6kh2 + " + modifiers;
rollData.formula = formula; rollData.formula = formula;
rollData.modifiers = modifiers
let r = new BoLDefaultRoll(rollData); let r = new BoLDefaultRoll(rollData);
r.roll(); r.roll();
@ -177,84 +178,115 @@ export class BoLRoll {
export class BoLDefaultRoll { export class BoLDefaultRoll {
constructor(rollData) { constructor(rollData) {
BoLUtility.storeRoll(rollData); BoLUtility.storeRoll(rollData)
this.rollData = rollData this.rollData = rollData
this.rollData.isSuccess = false; if ( this.rollData.isSuccess == undefined ) { // First init
this.rollData.isCritical = false; this.rollData.isSuccess = false;
this.rollData.isFumble = false; this.rollData.isCritical = false;
this.rollData.isFumble = false;
}
if ( this.rollData.optionsId) {
$(`#${this.rollData.optionsId}`).hide() // Hide the options roll buttons
}
if ( this.rollData.applyId) {
$(`#${this.rollData.applyId}`).hide() // Hide the options roll buttons
}
this.rollData.optionsId = randomID(16)
this.rollData.applyId = randomID(16)
} }
async roll() { async roll() {
console.log("ROLL", this.rollData)
const r = new Roll(this.rollData.formula); const r = new Roll(this.rollData.formula);
await r.roll({ "async": false }); await r.roll({ "async": false });
//await BoLUtility.showDiceSoNice(r);
const activeDice = r.terms[0].results.filter(r => r.active); const activeDice = r.terms[0].results.filter(r => r.active);
const diceTotal = activeDice.map(r => r.result).reduce((a, b) => a + b); const diceTotal = activeDice.map(r => r.result).reduce((a, b) => a + b);
this.rollData.roll = r
this.rollData.isSuccess = (r.total >= 9); this.rollData.isSuccess = (r.total >= 9);
this.rollData.isCritical = (diceTotal === 12); this.rollData.isCritical = (diceTotal === 12)
this.rollData.isRealCritical = (diceTotal === 12)
this.rollData.isFumble = (diceTotal === 2); this.rollData.isFumble = (diceTotal === 2);
this.rollData.isFailure = !this.rollData.isSuccess this.rollData.isFailure = !this.rollData.isSuccess
this.rollData.reroll = this.rollData.actor.heroReroll() if (this.rollData.reroll == undefined) {
this.rollData.reroll = this.rollData.actor.heroReroll()
if (this.rollData.registerInit) {
this.rollData.actor.registerInit( r.total, this.rollData.isCritical);
} }
if (this.rollData.registerInit) {
this.rollData.actor.registerInit(r.total, this.rollData.isCritical);
}
console.log("ROLL", this.rollData)
await this.sendChatMessage()
}
async sendChatMessage() {
this._buildChatMessage(this.rollData).then(msgFlavor => { this._buildChatMessage(this.rollData).then(msgFlavor => {
r.toMessage({ this.rollData.roll.toMessage({
user: game.user.id, user: game.user.id,
flavor: msgFlavor, flavor: msgFlavor,
speaker: ChatMessage.getSpeaker({ actor: this.rollData.actor }), speaker: ChatMessage.getSpeaker({ actor: this.rollData.actor }),
flags: { msgType: "default" } flags: { msgType: "default" }
}).then(this.processResult()); })
}); });
} }
async processDefense() { upgradeToCritical() {
if (this.rollData.isCritical) { // Force to Critical roll
ChatMessage.create({ this.rollData.isCritical = true
alias: this.rollData.actor.name, this.rollData.isRealCritical = false
whisper: BoLUtility.getWhisperRecipientsAndGMs(this.rollData.actor.name), this.rollData.isSuccess = true
content: await renderTemplate('systems/bol/templates/chat/rolls/attack-heroic-card.hbs', this.rollData ) this.rollData.isFailure = false
}) this.rollData.reroll = false
} else { this.rollData.roll = new Roll("12+" + this.rollData.modifiers)
BoLUtility.sendAttackSuccess(this.rollData); this.rollData.reroll = false
} this.sendChatMessage()
} }
setSuccess( flag) { setSuccess(flag) {
this.rollData.isSuccess = flag this.rollData.isSuccess = flag
} }
async processResult() { async sendDamageMessage() {
if ( this.rollData.mode != "weapon") { // Only specific process in Weapon mode this._buildDamageChatMessage(this.rollData).then(msgFlavor => {
this.rollData.damageRoll.toMessage({
user: game.user.id,
flavor: msgFlavor,
speaker: ChatMessage.getSpeaker({ actor: this.rollData.actor }),
flags: { msgType: "default" }
})
});
}
async rollDamage() {
if (this.rollData.mode != "weapon") { // Only specific process in Weapon mode
return; return;
} }
if (this.rollData.isSuccess) { if (this.rollData.isSuccess) {
let attrDamage = this.rollData.weapon.data.data.properties.damageAttribute; if ( !this.rollData.damageRoll) {
let weaponFormula = BoLUtility.getDamageFormula(this.rollData.weapon.data.data.properties.damage, let bonusDmg = 0
this.rollData.weapon.data.data.properties.damageModifiers, if ( this.rollData.damageMode == 'damage-plus-6') {
this.rollData.weapon.data.data.properties.damageMultiplier) bonusDmg = 6
let damageFormula = weaponFormula + ((attrDamage) ? "+" + this.rollData.actor.data.data.attributes[attrDamage].value : "+0"); }
if ( this.rollData.damageMode == 'damage-plus-12') {
bonusDmg = 12
}
console.log("DAMAGE !!!")
let attrDamage = this.rollData.weapon.data.data.properties.damageAttribute;
let weaponFormula = BoLUtility.getDamageFormula(this.rollData.weapon.data.data.properties.damage,
this.rollData.weapon.data.data.properties.damageModifiers,
this.rollData.weapon.data.data.properties.damageMultiplier)
let damageFormula = weaponFormula + "+" + bonusDmg + ((attrDamage) ? "+" + this.rollData.actor.data.data.attributes[attrDamage].value : "+0");
//console.log("Formula", weaponFormula, damageFormula, this.rollData.weapon.data.data.properties.damage) //console.log("Formula", weaponFormula, damageFormula, this.rollData.weapon.data.data.properties.damage)
this.rollData.damageRoll = new Roll(damageFormula); this.rollData.damageFormula = damageFormula
await this.rollData.damageRoll.roll({ "async": false }); this.rollData.damageRoll = new Roll(damageFormula)
await BoLUtility.showDiceSoNice(this.rollData.damageRoll); this.rollData.damageTotal = this.rollData.damageRoll.total
// Update rollData object await this.rollData.damageRoll.roll({ "async": false })
this.rollData.damageFormula = damageFormula; }
$(`#${this.rollData.optionsId}`).hide() // Hide the options roll buttons
this._buildDamageChatMessage( this.rollData ).then(msgFlavor => { this.sendDamageMessage()
this.rollData.damageRoll.toMessage({
user: game.user.id,
flavor: msgFlavor,
speaker: ChatMessage.getSpeaker({ actor: this.rollData.actor }),
flags: { msgType: "default" }
}).then(this.processDefense());
});
} }
} }

View File

@ -114,29 +114,41 @@ export class BoLUtility {
} else { } else {
BoLUtility.processAttackSuccess(attackDef); BoLUtility.processAttackSuccess(attackDef);
} }
} }
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static async chatListeners(html) { static async chatListeners(html) {
// Damage handling // Damage handling
html.on("click", '.damage-increase', event => { html.on("click", '.chat-damage-apply', event => {
event.preventDefault(); let rollData = BoLUtility.getLastRoll()
let attackId = event.currentTarget.attributes['data-attack-id'].value; $(`#${rollData.applyId}`).hide()
let damageMode = event.currentTarget.attributes['data-damage-mode'].value; BoLUtility.sendAttackSuccess(rollData)
if ( game.user.isGM) {
BoLUtility.processDamageIncrease(event, attackId, damageMode)
} else {
game.socket.emit("system.bol", { msg: "msg_damage_increase", data: {event: event, attackId: attackId, damageMode: damageMode} });
}
}); });
html.on("click", '.hero-reroll', event => { html.on("click", '.chat-damage-roll', event => {
event.preventDefault();
let rollData = BoLUtility.getLastRoll()
rollData.damageMode = event.currentTarget.attributes['data-damage-mode'].value;
let bolRoll = new BoLDefaultRoll(rollData)
bolRoll.rollDamage()
});
html.on("click", '.transform-heroic-roll', event => {
event.preventDefault(); event.preventDefault();
let rollData = BoLUtility.getLastRoll() let rollData = BoLUtility.getLastRoll()
rollData.actor.subHeroPoints(1) rollData.actor.subHeroPoints(1)
let r = new BoLDefaultRoll( rollData ) let r = new BoLDefaultRoll( rollData )
r.upgradeToCritical();
} );
html.on("click", '.hero-reroll', event => {
event.preventDefault();
let rollData = BoLUtility.getLastRoll()
rollData.actor.subHeroPoints(1)
rollData.reroll = false // Disable reroll option for second roll
let r = new BoLDefaultRoll( rollData )
r.roll(); r.roll();
} ); } );
@ -145,7 +157,6 @@ export class BoLUtility {
let attackId = event.currentTarget.attributes['data-attack-id'].value; let attackId = event.currentTarget.attributes['data-attack-id'].value;
let defenseMode = event.currentTarget.attributes['data-defense-mode'].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 let weaponId = (event.currentTarget.attributes['data-weapon-id']) ? event.currentTarget.attributes['data-weapon-id'].value : -1
console.log("DEFENSE1", event.currentTarget, attackId, defenseMode, weaponId);
if ( game.user.isGM) { if ( game.user.isGM) {
BoLUtility.processDamageHandling(event, attackId, defenseMode, weaponId) BoLUtility.processDamageHandling(event, attackId, defenseMode, weaponId)
} else { } else {
@ -154,31 +165,6 @@ export class BoLUtility {
}); });
} }
/* -------------------------------------------- */
static async processDamageIncrease(event, attackId, damageMode ) {
if ( !game.user.isGM) {
return;
}
BoLUtility.removeChatMessageId(BoLUtility.findChatMessageId(event.currentTarget));
// Only GM process this
let attackDef = this.attackStore[attackId];
if (attackDef) {
attackDef.damageMode = damageMode;
if (defenseMode == 'damage-plus-6') {
attackDef.damageRoll.total += 6;
}
if (defenseMode == 'damage-plus-12') {
attackDef.damageRoll.total += 12;
attackDef.defender.subHeroPoints(1);
}
if (defenseMode == 'damage-normal') {
// Do nothing !
}
BoLUtility.sendAttackSuccess( this.attackDef);
}
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static async processDamageHandling(event, attackId, defenseMode, weaponId=-1) { static async processDamageHandling(event, attackId, defenseMode, weaponId=-1) {
if ( !game.user.isGM) { if ( !game.user.isGM) {
@ -188,7 +174,7 @@ export class BoLUtility {
//console.log("Damage Handling", event, attackId, defenseMode, weaponId) //console.log("Damage Handling", event, attackId, defenseMode, weaponId)
// Only GM process this // Only GM process this
let attackDef = this.attackStore[attackId]; let attackDef = this.attackStore[attackId]
if (attackDef) { if (attackDef) {
if (attackDef.defenseDone) return; // ?? Why ??? if (attackDef.defenseDone) return; // ?? Why ???
attackDef.defenseDone = true attackDef.defenseDone = true
@ -389,9 +375,6 @@ export class BoLUtility {
if (sockmsg.name == "msg_damage_handling") { if (sockmsg.name == "msg_damage_handling") {
BoLUtility.processDamageHandling(sockmsg.data.event, sockmsg.data.attackId, sockmsg.data.defenseMode) BoLUtility.processDamageHandling(sockmsg.data.event, sockmsg.data.attackId, sockmsg.data.defenseMode)
} }
if (sockmsg.name == "msg_damage_increase") {
BoLUtility.processDamageIncrease(sockmsg.data.event, sockmsg.data.attackId, sockmsg.data.damageMode)
}
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -32,6 +32,7 @@ export const preloadHandlebarsTemplates = async function () {
"systems/bol/templates/item/parts/properties/feature/race-properties.hbs", "systems/bol/templates/item/parts/properties/feature/race-properties.hbs",
// DIALOGS // DIALOGS
"systems/bol/templates/chat/rolls/attack-damage-card.hbs",
"systems/bol/templates/roll/parts/roll-dialog-modifiers.hbs", "systems/bol/templates/roll/parts/roll-dialog-modifiers.hbs",
"systems/bol/templates/roll/parts/roll-dialog-attribute.hbs", "systems/bol/templates/roll/parts/roll-dialog-attribute.hbs",
"systems/bol/templates/dialogs/aptitude-roll-part.hbs", "systems/bol/templates/dialogs/aptitude-roll-part.hbs",

View File

@ -7,7 +7,7 @@
"url": "https://github.com/ZigmundKreud/bol", "url": "https://github.com/ZigmundKreud/bol",
"license": "LICENSE.txt", "license": "LICENSE.txt",
"flags": {}, "flags": {},
"version": "0.8.9.9", "version": "0.9.0.0",
"templateVersion": 16, "templateVersion": 16,
"minimumCoreVersion": "0.8.6", "minimumCoreVersion": "0.8.6",
"compatibleCoreVersion": "9", "compatibleCoreVersion": "9",

View File

@ -0,0 +1,7 @@
<button class="chat-damage-roll" data-damage-mode="normal-damage" data-attack-id="{{id}}">Lancer les dommages</button>
{{#if isCritical}}
<button class="chat-damage-roll" data-damage-mode="damage-plus-6" data-attack-id="{{id}}">Lancer les dommages +6</button>
<button class="chat-damage-roll" data-damage-mode="damage-plus-12" data-attack-id="{{id}}">Dommages +12 (1 Pt. d'Heroisme)</button>
{{/if}}

View File

@ -1,6 +0,0 @@
<img class="chat-icon" src="{{actor.img}}" alt="{{actor.name}}"/>
Jet Héroïque !
<button class="damage-increase" data-damage-mode="damage-plus-6" data-attack-id="{{id}}">Augmenter les dommages de 6</button>
<button class="damage-increase" data-damage-mode="damage-plus-12" data-attack-id="{{id}}">Augmenter les dommages de 12 (1 point d'Heroisme)</button>
<button class="damage-increase" data-damage-mode="damage-normal" data-attack-id="{{id}}">Laisser les dommages inchangés</button>

View File

@ -1,7 +1,8 @@
<img class="chat-icon" src="{{weapon.img}}" alt="{{weapon.name}}"/> <img class="chat-icon" src="{{weapon.img}}" alt="{{weapon.name}}"/>
<h3><strong>Dommages de l'arme : {{damage}}</strong> <h3><strong>Dommages de {{weapon.name}} : {{damageRoll.total}}</strong>
{{!#if hasDescription}}
<!--<h4>--> {{#if target}}
<!-- <pre class="rollDescr-line">{{!description}}</pre>--> <div id="{{applyId}}">
<!--</h4>--> <button class="chat-damage-apply" data-attack-id="{{id}}">Appliquer les dommages à la cible</button>
{{!/if}} </div>
{{/if}}

View File

@ -16,11 +16,15 @@
<h3><strong>{{description}}</strong></h3> <h3><strong>{{description}}</strong></h3>
{{#if reroll}} <div id="{{optionsId}}">
<a class="button hero-reroll" data-roll-id=="{{rollId}}"" data-actor-id="{{actor.id}}">Relancer!</a> {{#if (and isSuccess weapon)}}
{{/if}} {{> "systems/bol/templates/chat/rolls/attack-damage-card.hbs"}}
{{!#if hasDescription}} {{/if}}
<!--<h4>-->
<!-- <pre class="rollDescr-line">{{!description}}</pre>--> {{#if reroll}}
<!--</h4>--> <button class="chat-button button hero-reroll" data-roll-id=="{{rollId}}" data-actor-id="{{actor.id}}">Relancer (1 P. Heroisme)</button>
{{!/if}} {{/if}}
{{#if isRealCritical}}
<button class="chat-button button transform-heroic-roll" data-roll-id=="{{rollId}}" data-actor-id="{{actor.id}}">Transformer en succes héroique (1 P. Heroisme)</button>
{{/if}}
</div>