Gestion/assistance aventure/eclat

This commit is contained in:
sladecraven 2022-06-05 15:54:17 +02:00
parent 8a4efaad9a
commit c7a1133334
14 changed files with 280 additions and 61 deletions

BIN
assets/icons/adresse.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
assets/icons/eclat.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
assets/icons/presence.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
assets/icons/puissance.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
assets/icons/trempe.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

@ -43,6 +43,7 @@ export class MournbladeActorSheet extends ActorSheet {
skills: duplicate(this.actor.getSkills()), skills: duplicate(this.actor.getSkills()),
weapons: duplicate(this.actor.getWeapons()), weapons: duplicate(this.actor.getWeapons()),
armors: duplicate(this.actor.getArmors()), armors: duplicate(this.actor.getArmors()),
alignement: this.actor.getAlignement(),
//equipments: duplicate(this.actor.getEquipments()), //equipments: duplicate(this.actor.getEquipments()),
options: this.options, options: this.options,
owner: this.document.isOwner, owner: this.document.isOwner,

View File

@ -75,6 +75,11 @@ export class MournbladeActor extends Actor {
return comp return comp
} }
/* -------------------------------------------- */
getAlignement() {
return (this.data.data.balance.loi > this.data.data.balance.chaos) ? "loyal" : "chaotique"
}
/* -------------------------------------------- */ /* -------------------------------------------- */
prepareBaseData() { prepareBaseData() {
} }
@ -132,6 +137,35 @@ export class MournbladeActor extends Actor {
} }
} }
/* -------------------------------------------- */
getBonneAventure() {
return this.data.data.bonneaventure.actuelle
}
/* -------------------------------------------- */
changeBonneAventure(value) {
let newBA = this.data.data.bonneaventure.actuelle
newBA += value
this.update({ 'data.bonneaventure.actuelle': newBA })
}
/* -------------------------------------------- */
getEclat() {
return this.data.data.eclat.value
}
/* -------------------------------------------- */
changeEclat(value) {
let newE = this.data.data.eclat.value
newE += value
this.update({ 'data.eclat.value': newE })
}
/* -------------------------------------------- */
canEclatDoubleD20( ) {
return ( this.getAlignement() == "loyal" && this.data.data.eclat.value> 0)
}
/* -------------------------------------------- */ /* -------------------------------------------- */
compareName(a, b) { compareName(a, b) {
if (a.name < b.name) { if (a.name < b.name) {
@ -198,13 +232,17 @@ export class MournbladeActor extends Actor {
rollData.actorImg = this.img rollData.actorImg = this.img
rollData.actorId = this.id rollData.actorId = this.id
rollData.img = this.img rollData.img = this.img
rollData.canEclatDoubleD20 = this.canEclatDoubleD20()
rollData.doubleD20 = false
if (attrKey) { if (attrKey) {
rollData.attrKey = attrKey rollData.attrKey = attrKey
rollData.actionImg = "systems/fvtt-mournblade/assets/icons/" + this.data.data.attributs[attrKey].labelnorm + ".webp"
rollData.attr = duplicate(this.data.data.attributs[attrKey]) rollData.attr = duplicate(this.data.data.attributs[attrKey])
} }
if (compId) { if (compId) {
rollData.competence = duplicate(this.data.items.get(compId) || {}) rollData.competence = duplicate(this.data.items.get(compId) || {})
rollData.actionImg = rollData.competence.img
} }
return rollData return rollData
} }

View File

@ -63,6 +63,8 @@ export class MournbladeRollDialog extends Dialog {
html.find('#difficulte').change(async (event) => { html.find('#difficulte').change(async (event) => {
this.rollData.difficulte = Number(event.currentTarget.value) this.rollData.difficulte = Number(event.currentTarget.value)
}) })
html.find('#doubleD20').change(async (event) => {
this.rollData.doubleD20 = event.currentTarget.checked
})
} }
} }

View File

@ -8,10 +8,12 @@ export class MournbladeUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static async init() { static async init() {
Hooks.on('renderChatLog', (log, html, data) => MournbladeUtility.chatListeners(html)); Hooks.on('renderChatLog', (log, html, data) => MournbladeUtility.chatListeners(html))
Hooks.on("getChatLogEntryContext", (html, options) => MournbladeUtility.chatRollMenu(html, options))
Hooks.on("getCombatTrackerEntryContext", (html, options) => { Hooks.on("getCombatTrackerEntryContext", (html, options) => {
MournbladeUtility.pushInitiativeOptions(html, options); MournbladeUtility.pushInitiativeOptions(html, options);
}); })
Hooks.on("dropCanvasData", (canvas, data) => { Hooks.on("dropCanvasData", (canvas, data) => {
MournbladeUtility.dropItemOnToken(canvas, data) MournbladeUtility.dropItemOnToken(canvas, data)
}); });
@ -193,7 +195,7 @@ export class MournbladeUtility {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static saveRollData(rollData) { static saveRollData(rollData) {
game.socket.emit("system.Mournblade-rpg", { game.socket.emit("system.fvtt-mournblade", {
name: "msg_update_roll", data: rollData name: "msg_update_roll", data: rollData
}); // Notify all other clients of the roll }); // Notify all other clients of the roll
this.updateRollData(rollData); this.updateRollData(rollData);
@ -261,32 +263,14 @@ export class MournbladeUtility {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static async rollMournblade(rollData) { static computeResult(rollData) {
rollData.diceFormula = rollData.mainDice
if (rollData.competence) {
let compmod = (rollData.competence.data.niveau == 0) ? -3 : 0
rollData.diceFormula += `+${rollData.attr.value}+${rollData.competence.data.niveau}+${rollData.modificateur}+${compmod}`
} else {
rollData.diceFormula += `+${rollData.attr.value}*2+${rollData.modificateur}`
}
let myRoll = rollData.roll
if (!myRoll) { // New rolls only of no rerolls
myRoll = new Roll(rollData.diceFormula).roll({ async: false });
console.log("ROLL : ", rollData.diceFormula)
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"));
rollData.roll = myRoll
}
console.log(">>>> ", myRoll)
rollData.finalResult = myRoll.total
if (rollData.mainDice == "1d20") { if (rollData.mainDice == "1d20") {
let diceValue = myRoll.terms[0].results[0].result let diceValue = rollData.roll.terms[0].results[0].result
console.log("PAIR/IMP", diceValue) diceValue *= (rollData.doubleD20) ? 2 : 1
//console.log("PAIR/IMP", diceValue)
if (diceValue % 2 == 1) { if (diceValue % 2 == 1) {
console.log("PAIR/IMP2", diceValue) //console.log("PAIR/IMP2", diceValue)
rollData.finalResult -= myRoll.terms[0].results[0].result // Substract value rollData.finalResult -= rollData.roll.terms[0].results[0].result // Substract value
if (diceValue == 1 || diceValue == 11) { if (diceValue == 1 || diceValue == 11) {
rollData.isDramatique = true rollData.isDramatique = true
rollData.isSuccess = false rollData.isSuccess = false
@ -295,16 +279,60 @@ export class MournbladeUtility {
} }
if (rollData.difficulte > 0 && !rollData.isDramatique) { if (rollData.difficulte > 0 && !rollData.isDramatique) {
rollData.isSuccess = (myRoll.finalResult >= rollData.difficulte) rollData.isSuccess = (rollData.roll.finalResult >= rollData.difficulte)
rollData.isHeroique = ((myRoll.finalResult - rollData.difficulte) >= 10) rollData.isHeroique = ((rollData.roll.finalResult - rollData.difficulte) >= 10)
rollData.isDramatique = ((myRoll.finalResult - rollData.difficulte) <= -10) rollData.isDramatique = ((rollData.roll.finalResult - rollData.difficulte) <= -10)
} }
}
/* -------------------------------------------- */
static async rollMournblade(rollData) {
rollData.diceFormula = rollData.mainDice
if ( rollData.doubleD20) { // Multiply result !
rollData.diceFormula += "*2"
if (!rollData.isReroll) {
let actor = game.actors.get(rollData.actorId)
actor.changeEclat(-1)
}
}
if (rollData.competence) {
let compmod = (rollData.competence.data.niveau == 0) ? -3 : 0
rollData.diceFormula += `+${rollData.attr.value}+${rollData.competence.data.niveau}+${rollData.modificateur}+${compmod}`
} else {
rollData.diceFormula += `+${rollData.attr.value}*2+${rollData.modificateur}`
}
let myRoll = new Roll(rollData.diceFormula).roll({ async: false })
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"));
rollData.roll = myRoll
console.log(">>>> ", myRoll)
rollData.finalResult = myRoll.total
this.computeResult( rollData)
this.createChatWithRollMode(rollData.alias, { this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-mournblade/templates/chat-generic-result.html`, rollData) content: await renderTemplate(`systems/fvtt-mournblade/templates/chat-generic-result.html`, rollData)
}); }, rollData)
}
/* -------------------------------------------- */
static async bonusRollMournblade(rollData) {
rollData.bonusFormula = rollData.addedBonus
let bonusRoll = new Roll(rollData.bonusFormula).roll({async: false})
await this.showDiceSoNice(bonusRoll, game.settings.get("core", "rollMode"));
rollData.bonusRoll = bonusRoll
rollData.finalResult += rollData.bonusRoll.total
this.computeResult( rollData)
this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-mournblade/templates/chat-generic-result.html`, rollData)
}, rollData)
// And save the roll
this.saveRollData(rollData);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -364,7 +392,7 @@ export class MournbladeUtility {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static createChatMessage(name, rollMode, chatOptions) { static async createChatMessage(name, rollMode, chatOptions, rollData = undefined) {
switch (rollMode) { switch (rollMode) {
case "blindroll": // GM only case "blindroll": // GM only
if (!game.user.isGM) { if (!game.user.isGM) {
@ -381,8 +409,10 @@ export class MournbladeUtility {
chatOptions.whisper = this.getWhisperRecipients(rollMode, name); chatOptions.whisper = this.getWhisperRecipients(rollMode, name);
break; break;
} }
chatOptions.alias = chatOptions.alias || name; chatOptions.alias = chatOptions.alias || name
ChatMessage.create(chatOptions); let msg = await ChatMessage.create(chatOptions)
console.log("=======>", rollData)
msg.setFlag("world", "mournblade-roll", rollData)
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -413,8 +443,119 @@ export class MournbladeUtility {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static createChatWithRollMode(name, chatOptions) { static createChatWithRollMode(name, chatOptions, rollData = undefined) {
this.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions); this.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions, rollData)
}
/* -------------------------------------------- */
static applyBonneAventureRoll(li, changed, addedBonus) {
let msgId = li.data("message-id")
let msg = game.messages.get(msgId)
if (msg) {
let rollData = msg.getFlag("world", "mournblade-roll")
let actor = game.actors.get(rollData.actorId)
actor.changeBonneAventure( changed )
rollData.isReroll = true
rollData.textBonus = "Bonus de Points d'Aventure"
if (addedBonus == "reroll") {
MournbladeUtility.rollMournblade(rollData)
} else {
rollData.addedBonus = addedBonus
MournbladeUtility.bonusRollMournblade(rollData)
}
}
}
/* -------------------------------------------- */
static applyEclatRoll(li, changed, addedBonus) {
let msgId = li.data("message-id")
let msg = game.messages.get(msgId)
if (msg) {
let rollData = msg.getFlag("world", "mournblade-roll")
let actor = game.actors.get(rollData.actorId)
actor.changeEclat( changed )
rollData.isReroll = true
rollData.textBonus = "Bonus d'Eclat"
rollData.addedBonus = addedBonus
MournbladeUtility.bonusRollMournblade(rollData)
}
}
/* -------------------------------------------- */
static chatRollMenu(html, options) {
let canApply = li => canvas.tokens.controlled.length && li.find(".mournblade-roll").length
let canApplyBALoyal = function (li) {
let message = game.messages.get(li.attr("data-message-id"))
let rollData = message.getFlag("world", "mournblade-roll")
let actor = game.actors.get(rollData.actorId)
return ( !rollData.isReroll && actor.getBonneAventure() > 0 && actor.getAlignement() == "loyal")
}
let canApplyPELoyal = function (li) {
let message = game.messages.get(li.attr("data-message-id"))
let rollData = message.getFlag("world", "mournblade-roll")
let actor = game.actors.get(rollData.actorId)
return ( !rollData.isReroll && actor.getEclat() > 0 && actor.getAlignement() == "loyal")
}
let canApplyBAChaotique = function (li) {
let message = game.messages.get(li.attr("data-message-id"))
let rollData = message.getFlag("world", "mournblade-roll")
let actor = game.actors.get(rollData.actorId)
return ( !rollData.isReroll && actor.getBonneAventure() > 0 && actor.getAlignement() == "chaotique")
}
let canApplyBAChaotique3 = function (li) {
let message = game.messages.get(li.attr("data-message-id"))
let rollData = message.getFlag("world", "mournblade-roll")
let actor = game.actors.get(rollData.actorId)
return ( !rollData.isReroll && actor.getBonneAventure() > 2 && actor.getAlignement() == "chaotique")
}
let canApplyPEChaotique = function (li) {
let message = game.messages.get(li.attr("data-message-id"))
let rollData = message.getFlag("world", "mournblade-roll")
let actor = game.actors.get(rollData.actorId)
return ( !rollData.isReroll && actor.getEclat() > 0 && actor.getAlignement() == "chaotique")
}
options.push(
{
name: "Ajouer +3 (1 point de Bonne Aventure)",
icon: "<i class='fas fa-user-plus'></i>",
condition: canApply && canApplyBALoyal,
callback: li => MournbladeUtility.applyBonneAventureRoll(li, -1, "+3")
}
)
options.push(
{
name: "Ajouer +1d6 (1 point de Bonne Aventure)",
icon: "<i class='fas fa-user-plus'></i>",
condition: canApply && canApplyBAChaotique,
callback: li => MournbladeUtility.applyBonneAventureRoll(li, -1, "+1d6")
}
)
options.push(
{
name: "Relancer le dé (3 points de Bonne Aventure)",
icon: "<i class='fas fa-user-plus'></i>",
condition: canApply && canApplyBAChaotique3,
callback: li => MournbladeUtility.applyBonneAventureRoll(li, -3, "reroll")
}
)
options.push(
{
name: "Ajouter +10 (1 Point d'Eclat)",
icon: "<i class='fas fa-user-plus'></i>",
condition: canApply && canApplyPELoyal,
callback: li => MournbladeUtility.applyEclatRoll(li, -1, "+10")
}
)
options.push(
{
name: "Ajouter +1d20(1 Point d'Eclat)",
icon: "<i class='fas fa-user-plus'></i>",
condition: canApply && canApplyPEChaotique,
callback: li => MournbladeUtility.applyEclatRoll(li, -1, "+1d20")
}
)
return options
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -48,13 +48,37 @@
</ul> </ul>
</div> </div>
<div class="sheet-box color-bg-ame color-text-ame">
<span class="flexrow">
<h4 class="ame-margin title-font">Alignement : {{upperFirst alignement}}</h4>
</span>
<span class="flexrow">
<label class="item-name-label competence-name">Loi</label>
<select class="status-small-label color-class-common" type="text" name="data.balance.loi"
value="{{data.balance.loi}}" data-dtype="Number">
{{#select data.balance.loi}}
{{> systems/fvtt-mournblade/templates/partial-list-niveau.html}}
{{/select}}
</select>
<label class="item-name-label competence-name">Chaos</label>
<select class="status-small-label color-class-common" type="text" name="data.balance.chaos"
value="{{data.balance.chaos}}" data-dtype="Number">
{{#select data.balance.chaos}}
{{> systems/fvtt-mournblade/templates/partial-list-niveau.html}}
{{/select}}
</select>
</span>
</div>
<div class="sheet-box color-bg-ame color-text-ame"> <div class="sheet-box color-bg-ame color-text-ame">
<span class="flexrow"> <span class="flexrow">
<h4 class="ame-margin title-font">Bonne Aventure</h4> <h4 class="ame-margin title-font">Bonne Aventure</h4>
</span> </span>
<span class="flexrow"> <span class="flexrow">
<label>Base</label><label>{{data.bonneaventure.base}}</label> <label>Base</label>
<label>Actuelle</label><label>{{data.bonneaventure.actuelle}}</label> <input type="text" class="padd-right status-small-label color-class-common" name="data.bonneaventure.base" value="{{data.bonneaventure.base}}" data-dtype="Number" />
<label>Actuelle</label>
<input type="text" class="padd-right status-small-label color-class-common" name="data.bonneaventure.actuelle" value="{{data.bonneaventure.actuelle}}" data-dtype="Number" />
</span> </span>
</div> </div>
@ -63,7 +87,8 @@
<h4 class="ame-margin title-font">Eclat</h4> <h4 class="ame-margin title-font">Eclat</h4>
</span> </span>
<span class="flexrow"> <span class="flexrow">
<label>Valeur</label><label>{{data.eclat.value}}</label> <label>Valeur</label>
<input type="text" class="padd-right status-small-label color-class-common" name="data.eclat.value" value="{{data.eclat.value}}" data-dtype="Number" />
</span> </span>
</div> </div>
@ -72,7 +97,8 @@
<h4 class="ame-margin title-font">Expérience</h4> <h4 class="ame-margin title-font">Expérience</h4>
</span> </span>
<span class="flexrow"> <span class="flexrow">
<label>Valeur</label><label>{{data.experience.value}}</label> <label>Valeur</label>
<input type="text" class="padd-right status-small-label color-class-common" name="data.experience.value" value="{{data.experience.value}}" data-dtype="Number" />
</span> </span>
</div> </div>

View File

@ -9,7 +9,7 @@
{{#if img}} {{#if img}}
<div> <div>
<img class="chat-icon" src="{{img}}" alt="{{name}}" /> <img class="chat-icon" src="{{actionImg}}" alt="{{name}}" />
</div> </div>
{{/if}} {{/if}}
@ -18,12 +18,16 @@
<div> <div>
<ul> <ul>
<li>Attribut : {{attr.label}}</li> <li class="mournblade-roll">Attribut : {{attr.label}}</li>
{{#if competence}} {{#if competence}}
<li>Compétence : {{competence.name}}</li> <li>Compétence : {{competence.name}}</li>
{{/if}} {{/if}}
{{#if bonusRoll}}
<li>{{textBonus}} : {{bonusRoll.total}}</li>
{{/if}}
{{#if weaponName}} {{#if weaponName}}
<li>Weapon : {{weaponName}}</li> <li>Weapon : {{weaponName}}</li>
{{/if}} {{/if}}
@ -43,7 +47,7 @@
<li>Succés Héroïque!!!</li> <li>Succés Héroïque!!!</li>
{{/if}} {{/if}}
{{#if isDramatique}} {{#if isDramatique}}
<li>Succés Dramatique!!!</li> <li>Echec Dramatique!!!</li>
{{/if}} {{/if}}
</ul> </ul>

View File

@ -46,6 +46,13 @@
</select> </select>
</div> </div>
{{#if canEclatDoubleD20}}
<div class="flexrow">
<span class="roll-dialog-label">Doubler le d20 (1 Point d'Eclat)</span>
<input class="" id="doubleD20" type="checkbox" name="doubleD20" value="{{doubleD20}}" {{checked doubleD20}}/>
</div>
{{/if}}
</div> </div>