Improve confrontation management

This commit is contained in:
LeRatierBretonnien 2023-06-01 22:13:04 +02:00
parent b3cbe7b31a
commit 88385d2307
11 changed files with 289 additions and 110 deletions

View File

@ -24,6 +24,9 @@
"bonusmalustraits": "Traits Bonus/Malus", "bonusmalustraits": "Traits Bonus/Malus",
"spectranscend": "Self-Transcend : " "spectranscend": "Self-Transcend : "
}, },
"warn": {
"notenoughdice": "Execution and Preservation must have 2 dices allocated"
},
"ui": { "ui": {
"traitType": "Trait type", "traitType": "Trait type",
"niveauTrait": "Trait level", "niveauTrait": "Trait level",
@ -97,7 +100,13 @@
"impactsocial": "Social", "impactsocial": "Social",
"impactmalus": "Impact Malus", "impactmalus": "Impact Malus",
"ongoingconfront": "Ongoing confrontation", "ongoingconfront": "Ongoing confrontation",
"confront":"Confrontation" "confront":"Confrontation",
"launchconfront": "Launch confrontation",
"execution": "Execution",
"preservation": "Preservation",
"dicepool": "Available dices",
"selectconfront": "Select for confrontation",
"transcendapply": "Apply la Transcend to "
} }
} }
} }

View File

@ -24,6 +24,9 @@
"bonusmalustraits": "Bonus/Malus des Traits", "bonusmalustraits": "Bonus/Malus des Traits",
"spectranscend": "Dépassement de soi : " "spectranscend": "Dépassement de soi : "
}, },
"warn": {
"notenoughdice": "L'Accomplissement et la Préservation doivent avoir 2 dés chacun"
},
"ui": { "ui": {
"traitType": "Type de trait", "traitType": "Type de trait",
"niveauTrait": "Niveau du trait", "niveauTrait": "Niveau du trait",
@ -97,7 +100,13 @@
"impactsocial": "Social", "impactsocial": "Social",
"impactmalus": "Malus d'Impact", "impactmalus": "Malus d'Impact",
"ongoingconfront": "Confrontations en cours", "ongoingconfront": "Confrontations en cours",
"confront":"Confrontation" "confront":"Confrontation",
"launchconfront": "Lancer la confrontation",
"execution": "Accomplissement",
"preservation": "Préservation",
"dicepool": "Dés disponibles",
"selectconfront": "Sélectionner pour la Confrontation",
"transcendapply": "Appliquer la Transcendence à "
} }
} }
} }

View File

@ -314,7 +314,7 @@ export class EcrymeActor extends Actor {
rollData.actorId = this.id rollData.actorId = this.id
rollData.img = this.img rollData.img = this.img
rollData.isReroll = false rollData.isReroll = false
rollData.traits = this.getRollTraits() rollData.traits = duplicate(this.getRollTraits())
rollData.spleen = this.getSpleen() rollData.spleen = this.getSpleen()
rollData.ideal = this.getIdeal() rollData.ideal = this.getIdeal()
@ -351,8 +351,9 @@ export class EcrymeActor extends Actor {
let rollData = this.getCommonSkill(categKey, skillKey) let rollData = this.getCommonSkill(categKey, skillKey)
rollData.mode = "skill" rollData.mode = "skill"
rollData.title = game.i18n.localize("ECRY.ui.confrontation") + " : " + game.i18n.localize(rollData.skill.name) rollData.title = game.i18n.localize("ECRY.ui.confrontation") + " : " + game.i18n.localize(rollData.skill.name)
rollData.executionDices = [] rollData.executionTotal = rollData.skill.value
rollData.preservationDices = [] rollData.preservationTotal = rollData.skill.value
rollData.applyTranscendence = "execution"
let confrontStartDialog = await EcrymeConfrontStartDialog.create(this, rollData) let confrontStartDialog = await EcrymeConfrontStartDialog.create(this, rollData)
confrontStartDialog.render(true) confrontStartDialog.render(true)
} }

View File

@ -157,7 +157,8 @@ export class EcrymeUtility {
'systems/fvtt-ecryme/templates/items/partial-item-equipment.hbs', 'systems/fvtt-ecryme/templates/items/partial-item-equipment.hbs',
'systems/fvtt-ecryme/templates/items/partial-item-description.hbs', 'systems/fvtt-ecryme/templates/items/partial-item-description.hbs',
'systems/fvtt-ecryme/templates/dialogs/partial-common-roll-dialog.hbs', 'systems/fvtt-ecryme/templates/dialogs/partial-common-roll-dialog.hbs',
'systems/fvtt-ecryme/templates/actors/partial-impacts.hbs' 'systems/fvtt-ecryme/templates/dialogs/partial-confront-dice-area.hbs',
'systems/fvtt-ecryme/templates/actors/partial-impacts.hbs',
] ]
return loadTemplates(templatePaths); return loadTemplates(templatePaths);
} }
@ -386,10 +387,7 @@ export class EcrymeUtility {
let msg = await this.createChatWithRollMode(rollData.alias, { let msg = await this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-ecryme/templates/chat/chat-generic-result.hbs`, rollData) content: await renderTemplate(`systems/fvtt-ecryme/templates/chat/chat-generic-result.hbs`, rollData)
}) })
msg.setFlag("world", "rolldata", rollData) msg.setFlag("world", "ecryme-rolldata", rollData)
if (rollData.mode == "initiative") {
actor.setFlag("world", "initiative", myRoll.total)
}
console.log("Rolldata result", rollData) console.log("Rolldata result", rollData)
} }
@ -407,7 +405,7 @@ export class EcrymeUtility {
let msg = await this.createChatWithRollMode(rollData.alias, { let msg = await this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-ecryme/templates/chat/chat-generic-result.hbs`, rollData) content: await renderTemplate(`systems/fvtt-ecryme/templates/chat/chat-generic-result.hbs`, rollData)
}) })
msg.setFlag("world", "rolldata", rollData) msg.setFlag("world", "ecryme-rolldata", rollData)
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -22,10 +22,10 @@ export class EcrymeConfrontDialog extends Dialog {
title: game.i18n.localize("ECRY.ui.confront"), title: game.i18n.localize("ECRY.ui.confront"),
content: html, content: html,
buttons: { buttons: {
rollNormal: { launchConfront: {
icon: '<i class="fas fa-check"></i>', icon: '<i class="fas fa-check"></i>',
label: game.i18n.localize("ECRY.ui.rollnormal"), label: game.i18n.localize("ECRY.ui.launchconfront"),
callback: () => { this.rollConfront("4d6") } callback: () => { this.launchConfront().catch("Error when launching Confrontation") }
}, },
cancel: { cancel: {
icon: '<i class="fas fa-times"></i>', icon: '<i class="fas fa-times"></i>',
@ -40,45 +40,127 @@ export class EcrymeConfrontDialog extends Dialog {
this.actor = actor; this.actor = actor;
this.rollData = rollData; this.rollData = rollData;
// Ensure button is disabled
setTimeout(function () { $(".launchConfront").attr("disabled", true) }, 180)
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async roll() { async launchConfront() {
let msg = await EcrymeUtility.createChatMessage(this.rollData.alias, "blindroll", {
content: await renderTemplate(`systems/fvtt-ecryme/templates/chat/chat-confrontation-pending.hbs`, this.rollData)
})
msg.setFlag("world", "ecryme-rolldata", this.rollData)
}
/* -------------------------------------------- */
async refreshDialog() {
const content = await renderTemplate("systems/fvtt-ecryme/templates/dialogs/confront-dialog.hbs", this.rollData)
this.data.content = content
this.render(true)
let button = this.buttonDisabled
setTimeout(function () { $(".launchConfront").attr("disabled", button) }, 180)
} }
/* ------------------ -------------------------- */ /* ------------------ -------------------------- */
_onDragStart(event) { _onDragStart(event) {
super._onDragStart(event) super._onDragStart(event)
console.log("DRAG", event)
const diceData = { const diceData = {
diceIndex : $(event.srcElement).data("dice-idx"), diceIndex: $(event.srcElement).data("dice-idx"),
diceValue : $(event.srcElement).data("dice-value"), diceValue: $(event.srcElement).data("dice-value"),
} }
event.dataTransfer.setData("text/plain", JSON.stringify( diceData )); event.dataTransfer.setData("text/plain", JSON.stringify(diceData));
console.log(">>>>> DRAG START!!!!", event)
}
/* ------------------ -------------------------- */
async refreshDialog() {
const content = await renderTemplate("systems/fvtt-ecryme/templates/dialogs/confront-dialog.hbs", this.rollData)
this.data.content = content
this.render(true)
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_onDrop(event) { _onDrop(event) {
let dataJSON = event.dataTransfer.getData('text/plain') let dataJSON = event.dataTransfer.getData('text/plain')
console.log("DICEDATA", dataJSON)
let data = JSON.parse(dataJSON) let data = JSON.parse(dataJSON)
let idx = Number(data.diceIndex) let idx = Number(data.diceIndex)
//console.log("DATA", data, event, event.srcElement.className) //console.log("DATA", data, event, event.srcElement.className)
if ( event.srcElement.className.includes("execution")) { if (event.srcElement.className.includes("execution")) {
this.rollData.availableDices[idx].location = "execution" this.rollData.availableDices[idx].location = "execution"
} }
if ( event.srcElement.className.includes("preservation")) { if (event.srcElement.className.includes("preservation")) {
this.rollData.availableDices[idx].location = "preservation" this.rollData.availableDices[idx].location = "preservation"
} }
if ( event.srcElement.className.includes("dice-list")) { if (event.srcElement.className.includes("dice-list")) {
this.rollData.availableDices[idx].location = "mainpool" this.rollData.availableDices[idx].location = "mainpool"
} }
if (this.rollData.availableDices.filter(d => d.location == "execution").length == 2 && this.rollData.availableDices.filter(d => d.location == "preservation").length == 2) {
this.buttonDisabled = false
} else {
this.buttonDisabled = true
}
// Manage total values
this.computeTotals().catch("Error on dice pools")
}
/* -------------------------------------------- */
processTranscendence() {
// Apply Transcend if needed
if (this.rollData.skillTranscendence > 0) {
if (this.rollData.applyTranscendence == "execution") {
this.rollData.executionTotal += this.rollData.skillTranscendence
} else {
this.rollData.preservationTotal += this.rollData.skillTranscendence
}
}
}
/* -------------------------------------------- */
async computeTotals() {
let rollData = this.rollData
let actor = game.actors.get(rollData.actorId)
rollData.executionTotal = rollData.availableDices.filter(d => d.location == "execution").reduce((previous, current) => {
return previous + current.result
}, rollData.skill.value)
rollData.preservationTotal = rollData.availableDices.filter(d => d.location == "preservation").reduce((previous, current) => {
return previous + current.result
}, rollData.skill.value)
this.processTranscendence()
if (rollData.selectedSpecs && rollData.selectedSpecs.length > 0) {
rollData.spec = actor.getSpecialization(rollData.selectedSpecs[0])
this.rollData.executionTotal += "+2"
this.rollData.preservationTotal += "+2"
}
rollData.bonusMalusTraits = 0
for (let t of rollData.traits) {
t.isBonus = false
t.isMalus = false
}
if (rollData.traitsBonus && rollData.traitsBonus.length > 0) {
rollData.traitsBonusList = []
for (let id of rollData.traitsBonus) {
let trait = rollData.traits.find(t => t._id == id)
trait.isBonus = true
rollData.traitsBonusList.push(trait)
rollData.bonusMalusTraits += trait.system.level
}
}
if (rollData.traitsMalus && rollData.traitsMalus.length > 0) {
rollData.traitsMalusList = []
for (let id of rollData.traitsMalus) {
let trait = rollData.traits.find(t => t._id == id)
trait.isMalus = true
rollData.traitsMalusList.push(trait)
rollData.bonusMalusTraits -= trait.system.level
}
}
rollData.executionTotal += rollData.bonusMalusTraits
rollData.executionTotal += rollData.bonusMalusPerso
rollData.preservationTotal += rollData.bonusMalusTraits
rollData.preservationTotal += rollData.bonusMalusPerso
this.refreshDialog() this.refreshDialog()
} }
@ -86,5 +168,31 @@ export class EcrymeConfrontDialog extends Dialog {
activateListeners(html) { activateListeners(html) {
super.activateListeners(html); super.activateListeners(html);
html.find('#bonusMalusPerso').change((event) => {
this.rollData.bonusMalusPerso = Number(event.currentTarget.value)
this.computeTotals()
})
html.find('#roll-specialization').change((event) => {
this.rollData.selectedSpecs = $('#roll-specialization').val()
this.computeTotals()
})
html.find('#roll-trait-bonus').change((event) => {
this.rollData.traitsBonus = $('#roll-trait-bonus').val()
this.computeTotals()
})
html.find('#roll-trait-malus').change((event) => {
this.rollData.traitsMalus = $('#roll-trait-malus').val()
this.computeTotals()
})
html.find('#roll-select-transcendence').change((event) => {
this.rollData.skillTranscendence = Number($('#roll-select-transcendence').val())
this.computeTotals()
})
html.find('#roll-apply-transcendence').change((event) => {
this.rollData.applyTranscendence = $('#roll-apply-transcendence').val()
this.computeTotals()
})
} }
} }

View File

@ -1367,9 +1367,11 @@ ul, li {
transform: translate(-50%, -80%); transform: translate(-50%, -80%);
} }
.confront-area { .confront-area {
min-height: 96px; margin: 2px;
padding: 4px;
min-height: 64px;
border-width: 2px; border-width: 2px;
border-color: #000000; border-color: #000000;
border-radius: 4px; border-radius: 6px;
border: 2px ridge #443307; border: 2px ridge #443307;
} }

View File

@ -1347,9 +1347,11 @@ ul, li {
transform: translate(-50%, -80%); transform: translate(-50%, -80%);
} }
.confront-area { .confront-area {
margin: 2px;
padding: 4px;
min-height: 96px; min-height: 96px;
border-width: 2px; border-width: 2px;
border-color: #000000; border-color: #000000;
border-radius: 4px; border-radius: 6px;
border: 2px ridge #443307; border: 2px ridge #443307;
} }

View File

@ -0,0 +1,27 @@
<div class="chat-message-header">
{{#if actorImg}}
<img class="actor-icon" src="{{actorImg}}" alt="{{alias}}" />
{{/if}}
<h4 class="chat-actor-name">{{alias}}</h4>
</div>
<hr>
{{#if img}}
<div>
<img class="chat-icon" src="{{img}}" alt="{{alias}}" />
</div>
{{/if}}
<div>
<ul>
<li>Confrontation : {{alias}} </li>
<li>{{localize skill.name}}: {{skill.value}} </li>
{{#if spec}}
<li>{{localize "ECRY.chat.specialization"}} {{spec.name}} (+2) </li>
{{/if}}
</ul>
<button class="button-select-confront">{{localize "ECRY.ui.selectconfront"}}</button>
</div>
</div>

View File

@ -1,37 +0,0 @@
<div class="chat-message-header">
{{#if actorImg}}
<img class="actor-icon" src="{{actorImg}}" alt="{{alias}}" />
{{/if}}
<h4 class="chat-actor-name">{{alias}}</h4>
</div>
<hr>
{{#if img}}
<div >
<img class="chat-icon" src="{{img}}" alt="{{name}}" />
</div>
{{/if}}
<div class="flexcol">
</div>
<div>
<ul>
<li>Confrontation de {{attr.label}} : {{attr.value}}
</li>
<li>Degré de la confrontation: {{confrontationDegre}} </li>
<li>Ajustement spécial : {{confrontationModif}} </li>
<li>Seuil final : {{target}} </li>
<li>Valeur de la carte : {{total}} </li>
{{#if isSuccess}}
<li><label class="chat-result-text chat-result-success ">Réussite !</label> Votre {{attr.label}} augmente de {{gainAttr}} points.</li>
{{else}}
<li><label class="chat-result-text chat-result-success ">Echec !</label> Votre {{attr.label}} diminue de {{gainAttr}} points.</li>
{{/if}}
</ul>
</div>
</div>

View File

@ -3,55 +3,104 @@
{{#if img}} {{#if img}}
<img class="actor-icon" src="{{img}}" data-edit="img" title="{{name}}" /> <img class="actor-icon" src="{{img}}" data-edit="img" title="{{name}}" />
{{/if}} {{/if}}
<h1 class="dialog-roll-title roll-dialog-header">{{title}}</h1> <h1 class="dialog-roll-title roll-dialog-header">{{title}} ({{skill.value}})</h1>
</header> </header>
<div class="flexcol"> <div class="flexcol">
<div class="flexrow"> <div class="flexrow">
<div class="flexrow confront-area confront-execution-area" > <div>
{{#each availableDices as |dice idx|}} <h3>{{localize "ECRY.ui.execution"}} : <span id="execution-total">{{executionTotal}}</span> </h3>
{{#if (eq dice.location "execution")}} <div id="confront-execution" class="flexrow confront-area confront-execution-area">
<div class="confront-dice-container" > {{> systems/fvtt-ecryme/templates/dialogs/partial-confront-dice-area.hbs filter="execution"}}
<span draggable="true" data-dice-idx={{idx}} data-dice-value="{{dice.result}}"> </div>
<img class="confront-dice" src="icons/svg/d6-grey.svg">
<label class="confront-dice-centered">{{dice.result}}</label>
</span>
</div>
{{/if}}
{{/each}}
</div> </div>
<div class="flexrow confront-area confront-preservation-area" > <div>
{{#each availableDices as |dice idx|}} <h3>{{localize "ECRY.ui.preservation"}} : <span id="preservation-total">{{preservationTotal}}</span></h3>
{{#if (eq dice.location "preservation")}} <div id="confront-preservation" class="flexrow confront-area confront-preservation-area">
<div class="confront-dice-container" > {{> systems/fvtt-ecryme/templates/dialogs/partial-confront-dice-area.hbs filter="preservation"}}
<span draggable="true" data-dice-idx={{idx}} data-dice-value="{{dice.result}}"> </div>
<img class="confront-dice" src="icons/svg/d6-grey.svg">
<label class="confront-dice-centered">{{dice.result}}</label>
</span>
</div>
{{/if}}
{{/each}}
</div> </div>
</div> </div>
<div class="flexrow confront-area confrontation-dice-list"> <h4>{{localize "ECRY.ui.dicepool"}}</h4>
{{#each availableDices as |dice idx|}} <div id="confront-dice-pool" class="flexrow confront-area confrontation-dice-list">
{{#if (eq dice.location "mainpool")}} {{> systems/fvtt-ecryme/templates/dialogs/partial-confront-dice-area.hbs filter="mainpool"}}
<div class="confront-dice-container" > </div>
<span draggable="true" data-dice-idx={{idx}} data-dice-value="{{dice.result}}">
<img class="confront-dice" src="icons/svg/d6-grey.svg"> {{#if impactMalus}}
<label class="confront-dice-centered">{{dice.result}}</label> <div class="flexrow">
</span> <span class="roll-dialog-label">{{localize "ECRY.ui.impactmalus"}} : </span>
</div> <span class="roll-dialog-label">{{impactMalus}}</span>
{{/if}} </div>
{{/each}} {{/if}}
<div class="flexrow">
<span class="roll-dialog-label">{{localize "ECRY.ui.skilltranscendence"}} : </span>
<select class="" id="roll-select-transcendence" data-type="Number">
{{#select skillTranscendence}}
{{#for 0 skill.value 1}}
<option value="{{this}}">{{this}}</option>
{{/for}}
{{/select}}
</select>
</div>
<div class="flexrow">
<span class="roll-dialog-label">{{localize "ECRY.ui.transcendapply"}} : </span>
<select class="" id="roll-apply-transcendence" data-type="String">
{{#select applyTranscendence}}
<option value="execution">{{localize "ECRY.ui.execution"}}</option>
<option value="preservation">{{localize "ECRY.ui.preservation"}}</option>
{{/select}}
</select>
</div>
<div class="flexrow">
<span class="roll-dialog-label">{{localize "ECRY.ui.spec"}} : </span>
<select class="" id="roll-specialization" data-type="String" multiple>
{{#each skill.spec as |spec idx|}}
<option value="{{spec.id}}">{{spec.name}}</option>
{{/each}}
</select>
</div>
<div class="flexrow">
<span class="roll-dialog-label">{{localize "ECRY.ui.traitbonus"}} : </span>
<select class="" id="roll-trait-bonus" data-type="String" multiple>
{{#each traits as | trait idx|}}
<option value="{{trait._id}}" {{#if trait.isBonus}}selected{{/if}}>{{trait.name}} ({{trait.system.level}})</option>
{{/each}}
</select>
</div>
<div class="flexrow">
<span class="roll-dialog-label">{{localize "ECRY.ui.traitmalus"}} : </span>
<select class="" id="roll-trait-malus" data-type="String" multiple>
{{#each traits as | trait idx|}}
<option value="{{trait._id}}" {{#if trait.isMalus}}selected{{/if}}">{{trait.name}} ({{trait.system.level}})</option>
{{/each}}
</select>
</div>
<div class="flexrow">
<span class="roll-dialog-label">Bonus/Malus : </span>
<select id="bonusMalusPerso" name="bonusMalusPerso">
{{#select bonusMalusPerso}}
<option value="-3">-3</option>
<option value="-2">-2</option>
<option value="-1">-1</option>
<option value="0">0</option>
<option value="1">+1</option>
<option value="2">+2</option>
<option value="3">+3</option>
{{/select}}
</select>
</div> </div>
{{> systems/fvtt-ecryme/templates/dialogs/partial-common-roll-dialog.hbs}}
</div> </div>

View File

@ -0,0 +1,11 @@
{{#each availableDices as |dice idx|}}
{{#if (eq dice.location ../filter)}}
<div class="confront-dice-container" data-dice-idx={{idx}} data-dice-value="{{dice.result}}">
<span draggable="true" data-dice-idx={{idx}} data-dice-value="{{dice.result}}">
<img class="confront-dice" src="icons/svg/d6-grey.svg" data-dice-idx={{idx}} data-dice-value="{{dice.result}}">
<label class="confront-dice-centered" data-dice-idx={{idx}}
data-dice-value="{{dice.result}}">{{dice.result}}</label>
</span>
</div>
{{/if}}
{{/each}}