Added ability to apply the strife to the actor
This commit is contained in:
@@ -632,7 +632,7 @@ export class DicePickerDialog extends FormApplication {
|
||||
let targetToken;
|
||||
if (isMin === null) {
|
||||
// only one target, get the first element
|
||||
targetToken = Array.from(game.user.targets).values().next()?.value.document.actor;
|
||||
targetToken = Array.from(game.user.targets).values().next()?.value.document;
|
||||
} else {
|
||||
// Group (Min/Max)
|
||||
const targetGrp = Array.from(game.user.targets).reduce(
|
||||
|
||||
@@ -32,6 +32,7 @@ export class RollnKeepDialog extends FormApplication {
|
||||
*/
|
||||
object = {
|
||||
currentStep: 0,
|
||||
strifeApplied: 0,
|
||||
submitDisabled: false,
|
||||
swapDiceFaces: {
|
||||
rings: [],
|
||||
@@ -225,7 +226,7 @@ export class RollnKeepDialog extends FormApplication {
|
||||
const kept = this._getKeepCount(this.object.currentStep);
|
||||
this.object.submitDisabled = kept < 1 || kept > this.roll.l5r5e.keepLimit;
|
||||
} else if (!this.object.dicesList[this.object.currentStep]) {
|
||||
this.options.editable = false;
|
||||
this.options.editable = this.roll.l5r5e.summary.strife > 0;
|
||||
this.options.classes.push("finalized");
|
||||
}
|
||||
|
||||
@@ -675,6 +676,28 @@ export class RollnKeepDialog extends FormApplication {
|
||||
return;
|
||||
}
|
||||
|
||||
// Last step strife choice
|
||||
if (this.roll?.l5r5e?.rnkEnded && formData.strifeApplied !== undefined) {
|
||||
// Apply strife to actor
|
||||
const strifeApplied = Math.min(this.roll.l5r5e.summary.strife, Math.max(0, formData.strifeApplied));
|
||||
const actorMod = strifeApplied - this.roll.l5r5e.strifeApplied;
|
||||
if (actorMod !== 0) {
|
||||
await this.roll.l5r5e.actor.update({
|
||||
data: {
|
||||
strife: {
|
||||
value: Math.max(0, this.roll.l5r5e.actor.data.data.strife.value + actorMod),
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Update the roll & send to chat
|
||||
this.roll.l5r5e.strifeApplied = strifeApplied;
|
||||
await this._rebuildRoll(false);
|
||||
await this._toChatMessage();
|
||||
return this.close();
|
||||
}
|
||||
|
||||
// Discard all dices without a choice for the current step
|
||||
this._forceChoiceForDiceWithoutOne(RollnKeepDialog.CHOICES.discard);
|
||||
|
||||
@@ -690,8 +713,8 @@ export class RollnKeepDialog extends FormApplication {
|
||||
// Send the new roll in chat and delete the old message
|
||||
await this._toChatMessage();
|
||||
|
||||
// If a next step exist, rerender, else close
|
||||
if (this.object.dicesList[this.object.currentStep]) {
|
||||
// If a next step exist or strife, rerender, else close
|
||||
if (this.object.dicesList[this.object.currentStep] || this.roll.l5r5e.summary.strife > 0) {
|
||||
return this.render(false);
|
||||
}
|
||||
return this.close();
|
||||
|
||||
@@ -9,22 +9,23 @@ export class RollL5r5e extends Roll {
|
||||
super(formula, data, options);
|
||||
|
||||
this.l5r5e = {
|
||||
stance: "",
|
||||
skillId: "",
|
||||
skillCatId: "",
|
||||
actor: null,
|
||||
targetTokenId: null,
|
||||
difficulty: 2,
|
||||
difficultyHidden: false,
|
||||
voidPointUsed: false,
|
||||
keepLimit: null,
|
||||
isInitiativeRoll: false,
|
||||
skillAssistance: 0,
|
||||
initialFormula: null,
|
||||
dicesTypes: {
|
||||
std: false,
|
||||
l5r: false,
|
||||
},
|
||||
difficulty: 2,
|
||||
difficultyHidden: false,
|
||||
history: null,
|
||||
initialFormula: null,
|
||||
isInitiativeRoll: false,
|
||||
keepLimit: null,
|
||||
rnkEnded: false,
|
||||
skillAssistance: 0,
|
||||
skillCatId: "",
|
||||
skillId: "",
|
||||
stance: "",
|
||||
strifeApplied: 0,
|
||||
summary: {
|
||||
totalSuccess: 0,
|
||||
totalBonus: 0,
|
||||
@@ -33,12 +34,12 @@ export class RollL5r5e extends Roll {
|
||||
opportunity: 0,
|
||||
strife: 0,
|
||||
},
|
||||
history: null,
|
||||
rnkEnded: false,
|
||||
targetTokenId: null,
|
||||
voidPointUsed: false,
|
||||
};
|
||||
|
||||
// Parse flavor for stance and skillId
|
||||
const flavors = Array.from(formula.matchAll(/\d+d(s|r)\[([^\]]+)\]/gmu));
|
||||
const flavors = Array.from(formula.matchAll(/\d+d([sr])\[([^\]]+)\]/gmu));
|
||||
flavors.forEach((res) => {
|
||||
if (res[1] === "r" && !!res[2] && this.l5r5e.stance === "") {
|
||||
this.l5r5e.stance = res[2];
|
||||
|
||||
Reference in New Issue
Block a user