Update with minor fixes/updates

This commit is contained in:
sladecraven 2022-07-19 21:56:59 +02:00
parent cd41d2d9b6
commit 8b6bfeb36c
3 changed files with 37 additions and 51 deletions

View File

@ -952,6 +952,7 @@ export class PegasusActor extends Actor {
let biodata = duplicate(this.data.data.biodata) let biodata = duplicate(this.data.data.biodata)
biodata.currentlevelremaining = Math.max(biodata.currentlevelremaining + incDec, 0) biodata.currentlevelremaining = Math.max(biodata.currentlevelremaining + incDec, 0)
this.update({ "data.biodata": biodata }) this.update({ "data.biodata": biodata })
ChatMessage.create({ content: `${this.name} has used a Hero Level to reroll !` })
return biodata.currentlevelremaining return biodata.currentlevelremaining
} }

View File

@ -100,9 +100,9 @@ export class PegasusUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static updateArmorDicePool(rollData) { static updateArmorDicePool(rollData) {
let newDicePool = rollData.dicePool.filter(dice => dice.name != "armor-shield" ) let newDicePool = rollData.dicePool.filter(dice => dice.name != "armor-shield")
for (let armor of rollData.armorsList) { for (let armor of rollData.armorsList) {
if (armor.applied ) { if (armor.applied) {
let diceKey = PegasusUtility.getDiceFromLevel(armor.value) let diceKey = PegasusUtility.getDiceFromLevel(armor.value)
let diceList = diceKey.split(" ") let diceList = diceKey.split(" ")
for (let myDice of diceList) { for (let myDice of diceList) {
@ -314,6 +314,31 @@ export class PegasusUtility {
defender.processNoDefense(attackRollData); defender.processNoDefense(attackRollData);
} }
/* -------------------------------------------- */
static rerollHeroRemaining(userId, rollId) {
if (game.user.isGM) {
let user = game.users.get(userId)
let character = user.character
if (!character) {
ui.notifications.warn(`No character linked to the player : reroll not allowed.`)
return
}
let rollData = this.getRollData(rollId)
if (character.getLevelRemaining() > 0) {
rollData.rerollHero = true
this.rollPegasus(rollData)
character.modifyHeroLevelRemaining(-1)
} else {
ui.notifications.warn(`No more Hero Level for ${actor.name} ! Unable to reroll.`)
}
}
}
/* -------------------------------------------- */
static sendRerollHeroRemaining(userId, rollId) {
game.socket.emit("system.fvtt-pegasus-rpg", { name: "msg_reroll_hero", data: { userId: userId, rollId: rollId } })
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static async chatListeners(html) { static async chatListeners(html) {
@ -325,9 +350,11 @@ export class PegasusUtility {
}) })
html.on("click", '.reroll-level-remaining', event => { html.on("click", '.reroll-level-remaining', event => {
let rollId = $(event.currentTarget).data("roll-id") let rollId = $(event.currentTarget).data("roll-id")
let rollData = this.getRollData(rollId) if (game.user.isGM) {
rollData.reroll = true PegasusUtility.rerollHeroRemaining(game.user.id, rollId)
this.rollPegasus(rollData) } else {
PegasusUtility.sendRerollHeroRemaining(game.user.id, rollId)
}
}) })
} }
@ -527,6 +554,9 @@ export class PegasusUtility {
} }
this.addItemDropToActor(actor, item) this.addItemDropToActor(actor, item)
} }
if (msg.name == "msg_reroll_hero") {
this.rerollHeroRemaining(msg.data.userId, msg.data.rollId)
}
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -657,46 +687,6 @@ export class PegasusUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static async rollPegasus(rollData) { static async rollPegasus(rollData) {
/*
let dicePool = [{ name: "stat", level: 0, statmod: 0 }, { name: "spec", level: 0 }, { name: "bonus", level: 0 }, { name: "hindrance", level: 0 }, { name: "other", level: 0 }];
if (rollData.stat) {
dicePool[0].level += Number(rollData.stat.value)
dicePool[0].statmod = Number(rollData.stat.mod)
}
if (rollData.statDicesLevel) {
dicePool[0].level = rollData.statDicesLevel
}
if (rollData.selectedSpec && rollData.selectedSpec != "0") {
rollData.spec = rollData.specList.find(item => item._id == rollData.selectedSpec)
rollData.spec.data.dice = PegasusUtility.getDiceFromLevel(rollData.spec.data.level)
}
if (rollData.spec) {
dicePool[1].level += Number(rollData.spec.data.level)
}
if (rollData.specDicesLevel) {
dicePool[1].level = rollData.specDicesLevel
}
if (rollData.traumaState == "none") {
if (rollData.bonusDicesLevel) {
dicePool[2].level += Number(rollData.bonusDicesLevel)
}
}
if (!rollData.isInit) { // No Hindrance dice for Init
if (rollData.hindranceDicesLevel) {
dicePool[3].level += Number(rollData.hindranceDicesLevel)
}
}
if (rollData.otherDicesLevel) {
dicePool[4].level += Number(rollData.otherDicesLevel)
}
let diceFormulaTab = [];
for (let diceGroup of dicePool) {
diceFormulaTab.push(this.getFoundryDiceFromLevel(diceGroup.level))
}
let diceFormula = '{' + diceFormulaTab.join(', ') + '}kh';
*/
let actor = game.actors.get(rollData.actorId) let actor = game.actors.get(rollData.actorId)
let diceFormulaTab = [] let diceFormulaTab = []
@ -711,14 +701,11 @@ export class PegasusUtility {
// Performs roll // Performs roll
let myRoll = rollData.roll let myRoll = rollData.roll
if (!myRoll || rollData.reroll || rollData.rerollMomentum) { // New rolls only of no rerolls if (!myRoll || rollData.rerollHero || rollData.rerollMomentum) { // New rolls only of no rerolls
myRoll = new Roll(diceFormula).roll({ async: false }) myRoll = new Roll(diceFormula).roll({ async: false })
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode")) await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
rollData.roll = myRoll rollData.roll = myRoll
} }
if (rollData.reroll) {
rollData.levelRemaining = actor.modifyHeroLevelRemaining(-1)
}
// Final score and keep data // Final score and keep data
rollData.finalScore = myRoll.total rollData.finalScore = myRoll.total

View File

@ -48,9 +48,7 @@
{{/if}} {{/if}}
{{/if}} {{/if}}
{{#if levelRemaining}}
<button class="chat-card-button reroll-level-remaining" data-roll-id="{{rollId}}">Reroll</button> <button class="chat-card-button reroll-level-remaining" data-roll-id="{{rollId}}">Reroll</button>
{{/if}}
</ul> </ul>
</div> </div>