Add charmes/tours management

This commit is contained in:
2023-11-29 22:04:17 +01:00
parent 06d0d9b24d
commit 3e394734ce
63 changed files with 334 additions and 252 deletions

View File

@@ -115,6 +115,12 @@ export class WastelandActorSheet extends ActorSheet {
let compId = li.data("item-id")
this.actor.rollCompetence(attrKey, compId)
})
html.find('.roll-charme').click((event) => {
const li = $(event.currentTarget).parents(".item")
let charmeId = li.data("item-id")
this.actor.rollCharme(charmeId)
})
html.find('.roll-pouvoir').click((event) => {
const li = $(event.currentTarget).parents(".item")
let pouvoirId = li.data("item-id")

View File

@@ -393,6 +393,7 @@ export class WastelandActor extends Actor {
rollData.canEclatDoubleD20 = true // Always true in Wastelan
rollData.doubleD20 = false
rollData.attributs = WastelandUtility.getAttributs()
rollData.config = duplicate(game.system.wasteland.config)
if (attrKey) {
rollData.attrKey = attrKey
@@ -427,6 +428,16 @@ export class WastelandActor extends Actor {
rollDialog.render(true)
}
/* -------------------------------------------- */
async rollCharme(charmeId) {
let rollData = this.getCommonRollData("cla")
rollData.charme = duplicate(this.items.get(charmeId) || {})
rollData.charmeDice = "1d4"
console.log("RollDatra", rollData)
let rollDialog = await WastelandRollDialog.create(this, rollData)
rollDialog.render(true)
}
/* -------------------------------------------- */
async rollPouvoir(pouvoirId) {
let comp = this.items.find(comp => comp.type == "competence" && comp.name.toLowerCase() == "savoir : runes")

View File

@@ -11,5 +11,13 @@ export const WASTELAND_CONFIG = {
charmetype: {
tour: "Tour",
charme: "Charme",
}
},
dices: {
"1d4": "1d4",
"1d6": "1d6",
"1d8": "1d8",
"1d10": "1d10",
"1d12": "1d12",
"1d20": "1d20",
},
}

View File

@@ -3,35 +3,51 @@ import { WastelandUtility } from "./wasteland-utility.js";
export class WastelandRollDialog extends Dialog {
/* -------------------------------------------- */
static async create(actor, rollData ) {
static async create(actor, rollData) {
let options = { classes: ["WastelandDialog"], width: 340, height: 'fit-content', 'z-index': 99999 };
let html = await renderTemplate('systems/fvtt-wasteland/templates/roll-dialog-generic.html', rollData);
return new WastelandRollDialog(actor, rollData, html, options );
return new WastelandRollDialog(actor, rollData, html, options);
}
/* -------------------------------------------- */
constructor(actor, rollData, html, options, close = undefined) {
let buttons = {
rolld10: {
icon: '<i class="fas fa-check"></i>',
label: "Lancer 1d10",
callback: () => { this.roll("1d10") }
},
rolld20: {
icon: '<i class="fas fa-check"></i>',
label: "Lancer 1d20",
callback: () => { this.roll("1d20") }
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Annuler",
callback: () => { this.close() }
}
}
if (rollData.charme) {
buttons = {
roll: {
icon: '<i class="fas fa-check"></i>',
label: "Lancer",
callback: () => { this.roll() }
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Annuler",
callback: () => { this.close() }
}
}
}
let conf = {
title: "Test de Capacité",
content: html,
buttons: {
rolld10: {
icon: '<i class="fas fa-check"></i>',
label: "Lancer 1d10",
callback: () => { this.roll("1d10") }
},
rolld20: {
icon: '<i class="fas fa-check"></i>',
label: "Lancer 1d20",
callback: () => { this.roll("1d20") }
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Annuler",
callback: () => { this.close() }
} },
buttons: buttons,
close: close
}
@@ -42,9 +58,9 @@ export class WastelandRollDialog extends Dialog {
}
/* -------------------------------------------- */
roll ( dice) {
roll(dice) {
this.rollData.mainDice = dice
WastelandUtility.rollWasteland( this.rollData )
WastelandUtility.rollWasteland(this.rollData)
}
@@ -56,24 +72,28 @@ export class WastelandRollDialog extends Dialog {
function onLoad() {
}
$(function () { onLoad(); });
html.find('#modificateur').change(async (event) => {
html.find('#modificateur').change(async (event) => {
this.rollData.modificateur = Number(event.currentTarget.value)
})
html.find('#difficulte').change(async (event) => {
html.find('#difficulte').change(async (event) => {
this.rollData.difficulte = Number(event.currentTarget.value)
})
html.find('#attrKey').change(async (event) => {
html.find('#attrKey').change(async (event) => {
this.rollData.attrKey = String(event.currentTarget.value)
})
html.find('#runemode').change(async (event) => {
})
html.find('#runemode').change(async (event) => {
this.rollData.runemode = String(event.currentTarget.value)
})
html.find('#runeame').change(async (event) => {
})
html.find('#runeame').change(async (event) => {
this.rollData.runeame = Number(event.currentTarget.value)
})
html.find('#doubleD20').change(async (event) => {
})
html.find('#doubleD20').change(async (event) => {
this.rollData.doubleD20 = event.currentTarget.checked
})
})
html.find('#charmeDice').change(async (event) => {
this.rollData.charmeDice = String(event.currentTarget.value)
})
}
}

View File

@@ -2,6 +2,20 @@
import { WastelandCombat } from "./wasteland-combat.js";
import { WastelandCommands } from "./wasteland-commands.js";
/* -------------------------------------------- */
const __contrecouptCharme = {
1 : {name: "Effet chromatique", description: "" },
3 : {name: "Enivrement Kobold", description: "" },
5 : {name: "Mutisme superstitieux", description: "" },
7 : {name: "Agité!", description: "" },
9 : {name: "Somnolence", description: "" },
11 : {name: "Manie incontrôlable", description: "" },
13 : {name: "Malédiction des Ternes", description: "" },
15 : {name: "La petite Mort", description: "" },
17 : {name: "Angoisse cauchemardesque", description: "" },
19 : {name: "Anémie Kobold", description: "" }
}
/* -------------------------------------------- */
export class WastelandUtility {
@@ -279,25 +293,44 @@ export class WastelandUtility {
/* -------------------------------------------- */
static computeResult(rollData) {
if (rollData.mainDice == "1d20") {
let diceValue = rollData.roll.terms[0].results[0].result
diceValue *= (rollData.doubleD20) ? 2 : 1
//console.log("PAIR/IMP", diceValue)
if (diceValue % 2 == 1) {
//console.log("PAIR/IMP2", diceValue)
rollData.finalResult -= rollData.roll.terms[0].results[0].result // Substract value
if (diceValue == 1 || diceValue == 11) {
rollData.isDramatique = true
rollData.isSuccess = false
if (rollData.charme) {
let resultIndex = false
let resTab = duplicate(rollData.charme.system.resultats)
for(let id in resTab) {
let res = resTab[id]
if (!resultIndex && rollData.finalResult >= res.value) {
resultIndex = id;
}
}
}
//console.log("Result : ", rollData)
if (rollData.difficulte > 0 && !rollData.isDramatique) {
rollData.isSuccess = (rollData.finalResult >= rollData.difficulte)
rollData.isHeroique = ((rollData.finalResult - rollData.difficulte) >= 10)
rollData.isDramatique = ((rollData.finalResult - rollData.difficulte) <= -10)
if (resultIndex) {
rollData.charmeDuree = rollData.charme.system.resultats[resultIndex].description
}
let effectRoll = new Roll(rollData.charmeDice).roll({ async: false })
rollData.contrecoupResult = effectRoll.total
if (rollData.contrecoupResult % 2 == 1) {
rollData.contrecoup = __contrecouptCharme[rollData.contrecoupResult]
}
} else {
if (rollData.mainDice == "1d20") {
let diceValue = rollData.roll.terms[0].results[0].result
diceValue *= (rollData.doubleD20) ? 2 : 1
//console.log("PAIR/IMP", diceValue)
if (diceValue % 2 == 1) {
//console.log("PAIR/IMP2", diceValue)
rollData.finalResult -= rollData.roll.terms[0].results[0].result // Substract value
if (diceValue == 1 || diceValue == 11) {
rollData.isDramatique = true
rollData.isSuccess = false
}
}
}
//console.log("Result : ", rollData)
if (rollData.difficulte > 0 && !rollData.isDramatique) {
rollData.isSuccess = (rollData.finalResult >= rollData.difficulte)
rollData.isHeroique = ((rollData.finalResult - rollData.difficulte) >= 10)
rollData.isDramatique = ((rollData.finalResult - rollData.difficulte) <= -10)
}
}
}
@@ -313,13 +346,18 @@ export class WastelandUtility {
rollData.attr = duplicate(actor.system.attributs[rollData.attrKey])
}
rollData.diceFormula = rollData.mainDice
if (rollData.doubleD20) { // Multiply result !
rollData.diceFormula += "*2"
if (!rollData.isReroll) {
actor.changeEclat(-1)
}
if (rollData.charme) {
rollData.diceFormula = rollData.charmeDice
} else {
rollData.diceFormula = rollData.mainDice
if (rollData.doubleD20) { // Multiply result !
rollData.diceFormula += "*2"
if (!rollData.isReroll) {
actor.changeEclat(-1)
}
}
}
//console.log("BEFORE COMP", rollData)
if (rollData.competence) {
rollData.predilections = duplicate(rollData.competence.system.predilections.filter(pred => !pred.used) || [])
@@ -328,21 +366,10 @@ export class WastelandUtility {
} else {
rollData.diceFormula += `+${rollData.attr.value}*2+${rollData.modificateur}`
}
if (rollData.arme && rollData.arme.type == "arme") {
rollData.diceFormula += `+${rollData.arme.system.bonusmaniementoff}`
}
if (rollData.rune) {
rollData.runeduree = Math.ceil((rollData.runeame + 3) / 3)
if (rollData.runemode == "inscrire") {
rollData.runeduree *= 2
}
if (rollData.runemode == "prononcer") {
rollData.runeduree = 1
}
}
let myRoll = new Roll(rollData.diceFormula).roll({ async: false })
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
rollData.roll = duplicate(myRoll)
@@ -352,14 +379,6 @@ export class WastelandUtility {
rollData.finalResult = myRoll.total
this.computeResult(rollData)
if (rollData.rune) {
let subAme = rollData.runeame
if (rollData.isEchec && !rollData.isDramatique) {
subAme = Math.ceil((subAme + 1) / 2)
}
actor.subPointsAme(rollData.runemode, subAme)
}
this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-wasteland/templates/chat-generic-result.html`, rollData)
}, rollData)