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

@ -162,6 +162,7 @@ export class BoLRoll {
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,85 +178,116 @@ 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
if ( this.rollData.isSuccess == undefined ) { // First init
this.rollData.isSuccess = false; this.rollData.isSuccess = false;
this.rollData.isCritical = false; this.rollData.isCritical = false;
this.rollData.isFumble = 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
if (this.rollData.reroll == undefined) {
this.rollData.reroll = this.rollData.actor.heroReroll() this.rollData.reroll = this.rollData.actor.heroReroll()
}
if (this.rollData.registerInit) { if (this.rollData.registerInit) {
this.rollData.actor.registerInit(r.total, this.rollData.isCritical); 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
return;
}
if (this.rollData.isSuccess) {
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 + ((attrDamage) ? "+" + this.rollData.actor.data.data.attributes[attrDamage].value : "+0");
//console.log("Formula", weaponFormula, damageFormula, this.rollData.weapon.data.data.properties.damage)
this.rollData.damageRoll = new Roll(damageFormula);
await this.rollData.damageRoll.roll({ "async": false });
await BoLUtility.showDiceSoNice(this.rollData.damageRoll);
// Update rollData object
this.rollData.damageFormula = damageFormula;
this._buildDamageChatMessage(this.rollData).then(msgFlavor => { this._buildDamageChatMessage(this.rollData).then(msgFlavor => {
this.rollData.damageRoll.toMessage({ this.rollData.damageRoll.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.processDefense()); })
}); });
} }
async rollDamage() {
if (this.rollData.mode != "weapon") { // Only specific process in Weapon mode
return;
}
if (this.rollData.isSuccess) {
if ( !this.rollData.damageRoll) {
let bonusDmg = 0
if ( this.rollData.damageMode == 'damage-plus-6') {
bonusDmg = 6
}
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)
this.rollData.damageFormula = damageFormula
this.rollData.damageRoll = new Roll(damageFormula)
this.rollData.damageTotal = this.rollData.damageRoll.total
await this.rollData.damageRoll.roll({ "async": false })
}
$(`#${this.rollData.optionsId}`).hide() // Hide the options roll buttons
this.sendDamageMessage()
}
} }
_buildDamageChatMessage(rollData) { _buildDamageChatMessage(rollData) {

View File

@ -119,23 +119,35 @@ export class BoLUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
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 => {
let rollData = BoLUtility.getLastRoll()
$(`#${rollData.applyId}`).hide()
BoLUtility.sendAttackSuccess(rollData)
});
html.on("click", '.chat-damage-roll', event => {
event.preventDefault(); event.preventDefault();
let attackId = event.currentTarget.attributes['data-attack-id'].value; let rollData = BoLUtility.getLastRoll()
let damageMode = event.currentTarget.attributes['data-damage-mode'].value; rollData.damageMode = event.currentTarget.attributes['data-damage-mode'].value;
if ( game.user.isGM) { let bolRoll = new BoLDefaultRoll(rollData)
BoLUtility.processDamageIncrease(event, attackId, damageMode) bolRoll.rollDamage()
} else { });
game.socket.emit("system.bol", { msg: "msg_damage_increase", data: {event: event, attackId: attackId, damageMode: damageMode} });
} html.on("click", '.transform-heroic-roll', event => {
event.preventDefault();
let rollData = BoLUtility.getLastRoll()
rollData.actor.subHeroPoints(1)
let r = new BoLDefaultRoll( rollData )
r.upgradeToCritical();
} ); } );
html.on("click", '.hero-reroll', event => { html.on("click", '.hero-reroll', event => {
event.preventDefault(); event.preventDefault();
let rollData = BoLUtility.getLastRoll() let rollData = BoLUtility.getLastRoll()
rollData.actor.subHeroPoints(1) rollData.actor.subHeroPoints(1)
rollData.reroll = false // Disable reroll option for second roll
let r = new BoLDefaultRoll( rollData ) 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)}}
{{> "systems/bol/templates/chat/rolls/attack-damage-card.hbs"}}
{{/if}} {{/if}}
{{!#if hasDescription}}
<!--<h4>--> {{#if reroll}}
<!-- <pre class="rollDescr-line">{{!description}}</pre>--> <button class="chat-button button hero-reroll" data-roll-id=="{{rollId}}" data-actor-id="{{actor.id}}">Relancer (1 P. Heroisme)</button>
<!--</h4>--> {{/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>