v0.5 fixes

This commit is contained in:
2022-07-19 00:18:46 +02:00
parent bf52b61a0d
commit 2ab1cbe24c
12 changed files with 255 additions and 52 deletions

View File

@ -60,9 +60,9 @@ export class PegasusUtility {
/* -------------------------------------------- */
static getDiceList() {
return [{ key: "d4", img: "systems/fvtt-pegasus-rpg/images/dice/d4.webp" }, { key: "d6", img: "systems/fvtt-pegasus-rpg/images/dice/d6.webp" },
{ key: "d8", img: "systems/fvtt-pegasus-rpg/images/dice/d8.webp" }, { key: "d10", img: "systems/fvtt-pegasus-rpg/images/dice/d10.webp" },
{ key: "d12", img: "systems/fvtt-pegasus-rpg/images/dice/d12.webp" }]
return [{ key: "d4", level: 1, img: "systems/fvtt-pegasus-rpg/images/dice/d4.webp" }, { key: "d6", level: 2, img: "systems/fvtt-pegasus-rpg/images/dice/d6.webp" },
{ key: "d8", level: 3, img: "systems/fvtt-pegasus-rpg/images/dice/d8.webp" }, { key: "d10", level: 4, img: "systems/fvtt-pegasus-rpg/images/dice/d10.webp" },
{ key: "d12", level: 5, img: "systems/fvtt-pegasus-rpg/images/dice/d12.webp" }]
}
/* -------------------------------------------- */
@ -72,7 +72,7 @@ export class PegasusUtility {
if (effect && effect.applied && effect.effect.data.bonusdice) {
let diceKey = PegasusUtility.getDiceFromLevel(effect.effect.data.effectlevel)
let newDice = {
name: "effect-bonus-dice", key: diceKey, effect: effect.effect.name,
name: "effect-bonus-dice", key: diceKey, level: effect.effect.data.effectlevel, effect: effect.effect.name,
img: `systems/fvtt-pegasus-rpg/images/dice/${diceKey}.webp`
}
newDicePool.push(newDice)
@ -90,7 +90,7 @@ export class PegasusUtility {
let diceList = diceKey.split(" ")
for(let myDice of diceList) {
let newDice = {
name: "damage", key: myDice,
name: "damage", key: myDice, level: rollData.damageDiceLevel,
img: `systems/fvtt-pegasus-rpg/images/dice/${myDice}.webp`
}
newDicePool.push(newDice)
@ -108,7 +108,7 @@ export class PegasusUtility {
let diceList = diceKey.split(" ")
for(let myDice of diceList) {
let newDice = {
name: "spec", key: myDice,
name: "spec", key: myDice, level: rollData.specDicesLevel,
img: `systems/fvtt-pegasus-rpg/images/dice/${myDice}.webp`
}
newDicePool.push(newDice)
@ -118,9 +118,9 @@ export class PegasusUtility {
}
/* -------------------------------------------- */
static addDicePool(rollData, diceKey) {
static addDicePool(rollData, diceKey, level) {
let newDice = {
name: "dice-click", key: diceKey,
name: "dice-click", key: diceKey, level: level,
img: `systems/fvtt-pegasus-rpg/images/dice/${diceKey}.webp`
}
rollData.dicePool.push(newDice)
@ -451,22 +451,22 @@ export class PegasusUtility {
/* -------------------------------------------- */
static updateRollData(rollData) {
let id = rollData.rollId;
let oldRollData = this.rollDataStore[id] || {};
let newRollData = mergeObject(oldRollData, rollData);
this.rollDataStore[id] = newRollData;
let id = rollData.rollId
let oldRollData = this.rollDataStore[id] || {}
let newRollData = mergeObject(oldRollData, rollData)
this.rollDataStore[id] = newRollData
}
/* -------------------------------------------- */
static saveRollData(rollData) {
game.socket.emit("system.pegasus-rpg", {
name: "msg_update_roll", data: rollData
}); // Notify all other clients of the roll
this.updateRollData(rollData);
this.updateRollData(rollData)
}
/* -------------------------------------------- */
static getRollData(id) {
return this.rollDataStore[id];
return this.rollDataStore[id]
}
/* -------------------------------------------- */
@ -570,15 +570,51 @@ export class PegasusUtility {
for (let effect of rollData.effectsList) {
if (effect.effect.data.isUsed && effect.effect.data.oneuse) {
toRem.push(effect.effect._id)
ChatMessage.create({content: `One used effect ${effect.effect.name} has been auto-deleted.`})
}
}
if (toRem.length > 0) {
console.log("Going to remove one use effects", toRem)
//console.log("Going to remove one use effects", toRem)
let actor = game.actors.get(rollData.actorId)
actor.deleteEmbeddedDocuments('Item', toRem)
}
}
/* -------------------------------------------- */
static async momentumReroll(actorId) {
let actor = game.actors.get(actorId)
let rollData = actor.lastRoll
if (rollData) {
rollData.rerollMomentum = true
PegasusUtility.rollPegasus(rollData)
this.actor.lastRoll = undefined
} else {
ui.notifications.warn("No last roll registered....")
}
}
/* -------------------------------------------- */
static async showMomentumDialog( actorId) {
let d = new Dialog({
title: "Momentum reroll",
content: "<p>Do you want to re-roll your last roll ?</p>",
buttons: {
one: {
icon: '<i class="fas fa-check"></i>',
label: "Cancel",
callback: () => this.close()
},
two: {
icon: '<i class="fas fa-times"></i>',
label: "Reroll",
callback: () => PegasusUtility.momentumReroll(actorId)
}
},
default: "Reroll",
})
d.render(true)
}
/* -------------------------------------------- */
static async rollPegasus(rollData) {
@ -626,13 +662,17 @@ export class PegasusUtility {
let diceFormulaTab = []
for (let dice of rollData.dicePool) {
diceFormulaTab.push(dice.key)
let level = dice.level
if (dice.name == "stat" ) {
level += rollData.statLevelBonus
}
diceFormulaTab.push( this.getFoundryDiceFromLevel(level) )
}
let diceFormula = '{' + diceFormulaTab.join(', ') + '}kh + ' + (rollData.stat?.mod || 0)
// Performs roll
let myRoll = rollData.roll
if (!myRoll || rollData.reroll) { // New rolls only of no rerolls
if (!myRoll || rollData.reroll || rollData.rerollMomentum) { // New rolls only of no rerolls
myRoll = new Roll(diceFormula).roll({ async: false })
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
rollData.roll = myRoll
@ -669,7 +709,8 @@ export class PegasusUtility {
this.removeOneUseEffects(rollData) // Unused for now
// And save the roll
this.saveRollData(rollData);
this.saveRollData(rollData)
actor.lastRoll = rollData
}
/* -------------------------------------------- */
@ -812,6 +853,10 @@ export class PegasusUtility {
rollId: randomID(16),
rollMode: game.settings.get("core", "rollMode"),
bonusDicesLevel: 0,
statLevelBonus: 0,
damageLevelBonus: 0,
specLevelBonus: 0,
hindranceLevelBonus: 0,
hindranceDicesLevel: 0,
otherDicesLevel: 0,
statDicesLevel: 0,