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",
"spectranscend": "Self-Transcend : "
},
"warn": {
"notenoughdice": "Execution and Preservation must have 2 dices allocated"
},
"ui": {
"traitType": "Trait type",
"niveauTrait": "Trait level",
@ -97,7 +100,13 @@
"impactsocial": "Social",
"impactmalus": "Impact Malus",
"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",
"spectranscend": "Dépassement de soi : "
},
"warn": {
"notenoughdice": "L'Accomplissement et la Préservation doivent avoir 2 dés chacun"
},
"ui": {
"traitType": "Type de trait",
"niveauTrait": "Niveau du trait",
@ -97,7 +100,13 @@
"impactsocial": "Social",
"impactmalus": "Malus d'Impact",
"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.img = this.img
rollData.isReroll = false
rollData.traits = this.getRollTraits()
rollData.traits = duplicate(this.getRollTraits())
rollData.spleen = this.getSpleen()
rollData.ideal = this.getIdeal()
@ -351,8 +351,9 @@ export class EcrymeActor extends Actor {
let rollData = this.getCommonSkill(categKey, skillKey)
rollData.mode = "skill"
rollData.title = game.i18n.localize("ECRY.ui.confrontation") + " : " + game.i18n.localize(rollData.skill.name)
rollData.executionDices = []
rollData.preservationDices = []
rollData.executionTotal = rollData.skill.value
rollData.preservationTotal = rollData.skill.value
rollData.applyTranscendence = "execution"
let confrontStartDialog = await EcrymeConfrontStartDialog.create(this, rollData)
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-description.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);
}
@ -386,10 +387,7 @@ export class EcrymeUtility {
let msg = await this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-ecryme/templates/chat/chat-generic-result.hbs`, rollData)
})
msg.setFlag("world", "rolldata", rollData)
if (rollData.mode == "initiative") {
actor.setFlag("world", "initiative", myRoll.total)
}
msg.setFlag("world", "ecryme-rolldata", rollData)
console.log("Rolldata result", rollData)
}
@ -407,7 +405,7 @@ export class EcrymeUtility {
let msg = await this.createChatWithRollMode(rollData.alias, {
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"),
content: html,
buttons: {
rollNormal: {
launchConfront: {
icon: '<i class="fas fa-check"></i>',
label: game.i18n.localize("ECRY.ui.rollnormal"),
callback: () => { this.rollConfront("4d6") }
label: game.i18n.localize("ECRY.ui.launchconfront"),
callback: () => { this.launchConfront().catch("Error when launching Confrontation") }
},
cancel: {
icon: '<i class="fas fa-times"></i>',
@ -40,51 +40,159 @@ export class EcrymeConfrontDialog extends Dialog {
this.actor = actor;
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) {
super._onDragStart(event)
console.log("DRAG", event)
const diceData = {
diceIndex : $(event.srcElement).data("dice-idx"),
diceValue : $(event.srcElement).data("dice-value"),
}
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)
diceIndex: $(event.srcElement).data("dice-idx"),
diceValue: $(event.srcElement).data("dice-value"),
}
event.dataTransfer.setData("text/plain", JSON.stringify(diceData));
}
/* -------------------------------------------- */
_onDrop(event) {
let dataJSON = event.dataTransfer.getData('text/plain')
console.log("DICEDATA", dataJSON)
let data = JSON.parse(dataJSON)
let idx = Number(data.diceIndex)
//console.log("DATA", data, event, event.srcElement.className)
if ( event.srcElement.className.includes("execution")) {
this.rollData.availableDices[idx].location = "execution"
if (event.srcElement.className.includes("execution")) {
this.rollData.availableDices[idx].location = "execution"
}
if ( event.srcElement.className.includes("preservation")) {
this.rollData.availableDices[idx].location = "preservation"
if (event.srcElement.className.includes("preservation")) {
this.rollData.availableDices[idx].location = "preservation"
}
if ( event.srcElement.className.includes("dice-list")) {
this.rollData.availableDices[idx].location = "mainpool"
if (event.srcElement.className.includes("dice-list")) {
this.rollData.availableDices[idx].location = "mainpool"
}
this.refreshDialog()
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()
}
/* -------------------------------------------- */
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%);
}
.confront-area {
min-height: 96px;
margin: 2px;
padding: 4px;
min-height: 64px;
border-width: 2px;
border-color: #000000;
border-radius: 4px;
border-radius: 6px;
border: 2px ridge #443307;
}

View File

@ -1347,9 +1347,11 @@ ul, li {
transform: translate(-50%, -80%);
}
.confront-area {
margin: 2px;
padding: 4px;
min-height: 96px;
border-width: 2px;
border-color: #000000;
border-radius: 4px;
border-radius: 6px;
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}}
<img class="actor-icon" src="{{img}}" data-edit="img" title="{{name}}" />
{{/if}}
<h1 class="dialog-roll-title roll-dialog-header">{{title}}</h1>
<h1 class="dialog-roll-title roll-dialog-header">{{title}} ({{skill.value}})</h1>
</header>
<div class="flexcol">
<div class="flexrow">
<div class="flexrow confront-area confront-execution-area" >
{{#each availableDices as |dice idx|}}
{{#if (eq dice.location "execution")}}
<div class="confront-dice-container" >
<span draggable="true" data-dice-idx={{idx}} data-dice-value="{{dice.result}}">
<img class="confront-dice" src="icons/svg/d6-grey.svg">
<label class="confront-dice-centered">{{dice.result}}</label>
</span>
</div>
{{/if}}
{{/each}}
<div>
<h3>{{localize "ECRY.ui.execution"}} : <span id="execution-total">{{executionTotal}}</span> </h3>
<div id="confront-execution" class="flexrow confront-area confront-execution-area">
{{> systems/fvtt-ecryme/templates/dialogs/partial-confront-dice-area.hbs filter="execution"}}
</div>
</div>
<div class="flexrow confront-area confront-preservation-area" >
{{#each availableDices as |dice idx|}}
{{#if (eq dice.location "preservation")}}
<div class="confront-dice-container" >
<span draggable="true" data-dice-idx={{idx}} data-dice-value="{{dice.result}}">
<img class="confront-dice" src="icons/svg/d6-grey.svg">
<label class="confront-dice-centered">{{dice.result}}</label>
</span>
</div>
{{/if}}
{{/each}}
<div>
<h3>{{localize "ECRY.ui.preservation"}} : <span id="preservation-total">{{preservationTotal}}</span></h3>
<div id="confront-preservation" class="flexrow confront-area confront-preservation-area">
{{> systems/fvtt-ecryme/templates/dialogs/partial-confront-dice-area.hbs filter="preservation"}}
</div>
</div>
</div>
<div class="flexrow confront-area confrontation-dice-list">
{{#each availableDices as |dice idx|}}
{{#if (eq dice.location "mainpool")}}
<div class="confront-dice-container" >
<span draggable="true" data-dice-idx={{idx}} data-dice-value="{{dice.result}}">
<img class="confront-dice" src="icons/svg/d6-grey.svg">
<label class="confront-dice-centered">{{dice.result}}</label>
</span>
</div>
{{/if}}
{{/each}}
<h4>{{localize "ECRY.ui.dicepool"}}</h4>
<div id="confront-dice-pool" class="flexrow confront-area confrontation-dice-list">
{{> systems/fvtt-ecryme/templates/dialogs/partial-confront-dice-area.hbs filter="mainpool"}}
</div>
{{#if impactMalus}}
<div class="flexrow">
<span class="roll-dialog-label">{{localize "ECRY.ui.impactmalus"}} : </span>
<span class="roll-dialog-label">{{impactMalus}}</span>
</div>
{{/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>
{{> systems/fvtt-ecryme/templates/dialogs/partial-common-roll-dialog.hbs}}
</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}}