Added ability to apply the strife to the actor

This commit is contained in:
Vlyan
2022-02-13 13:34:24 +01:00
parent 64b436627f
commit 8c4072d8af
11 changed files with 83 additions and 22 deletions

View File

@@ -10,8 +10,10 @@
- Compendiums : - Compendiums :
- Techniques : Added difficulty and skill values (not all techniques). - Techniques : Added difficulty and skill values (not all techniques).
- DicePicker : - DicePicker :
- Added TN hidden difficulty visibility for GM. - Added TN hidden difficulty visibility for GM (ex: ?2?).
- Added a selection for techniques with skill list. - Added a selection for techniques with skill list.
- RnK :
- Added ability to apply the strife to the actor on final step. The chat message show the value taken in gray aside the total strife.
Syntaxe quick explanation : Syntaxe quick explanation :
- Difficulty can be : - Difficulty can be :

View File

@@ -132,6 +132,7 @@
"swap_drop_here": "Swap", "swap_drop_here": "Swap",
"keep_drop_here": "Keep", "keep_drop_here": "Keep",
"bt_validate": "Finalize this step", "bt_validate": "Finalize this step",
"bt_strife": "Apply strife",
"undo": "[GM] Undo the last step choices" "undo": "[GM] Undo the last step choices"
}, },
"gm_toolbox": { "gm_toolbox": {

View File

@@ -132,6 +132,7 @@
"swap_drop_here": "Cambiar cara", "swap_drop_here": "Cambiar cara",
"keep_drop_here": "Guardar", "keep_drop_here": "Guardar",
"bt_validate": "Terminar este paso", "bt_validate": "Terminar este paso",
"bt_strife": "Apply strife",
"undo": "[GM] Deshacer los últimos cambios" "undo": "[GM] Deshacer los últimos cambios"
}, },
"gm_toolbox": { "gm_toolbox": {

View File

@@ -132,6 +132,7 @@
"swap_drop_here": "Modifier", "swap_drop_here": "Modifier",
"keep_drop_here": "Garder", "keep_drop_here": "Garder",
"bt_validate": "Finaliser cette étape", "bt_validate": "Finaliser cette étape",
"bt_strife": "Appliquer le conflit",
"undo": "[GM] Annuler les choix de la dernière étape" "undo": "[GM] Annuler les choix de la dernière étape"
}, },
"gm_toolbox": { "gm_toolbox": {

View File

@@ -632,7 +632,7 @@ export class DicePickerDialog extends FormApplication {
let targetToken; let targetToken;
if (isMin === null) { if (isMin === null) {
// only one target, get the first element // 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 { } else {
// Group (Min/Max) // Group (Min/Max)
const targetGrp = Array.from(game.user.targets).reduce( const targetGrp = Array.from(game.user.targets).reduce(

View File

@@ -32,6 +32,7 @@ export class RollnKeepDialog extends FormApplication {
*/ */
object = { object = {
currentStep: 0, currentStep: 0,
strifeApplied: 0,
submitDisabled: false, submitDisabled: false,
swapDiceFaces: { swapDiceFaces: {
rings: [], rings: [],
@@ -225,7 +226,7 @@ export class RollnKeepDialog extends FormApplication {
const kept = this._getKeepCount(this.object.currentStep); const kept = this._getKeepCount(this.object.currentStep);
this.object.submitDisabled = kept < 1 || kept > this.roll.l5r5e.keepLimit; this.object.submitDisabled = kept < 1 || kept > this.roll.l5r5e.keepLimit;
} else if (!this.object.dicesList[this.object.currentStep]) { } 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"); this.options.classes.push("finalized");
} }
@@ -675,6 +676,28 @@ export class RollnKeepDialog extends FormApplication {
return; 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 // Discard all dices without a choice for the current step
this._forceChoiceForDiceWithoutOne(RollnKeepDialog.CHOICES.discard); 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 // Send the new roll in chat and delete the old message
await this._toChatMessage(); await this._toChatMessage();
// If a next step exist, rerender, else close // If a next step exist or strife, rerender, else close
if (this.object.dicesList[this.object.currentStep]) { if (this.object.dicesList[this.object.currentStep] || this.roll.l5r5e.summary.strife > 0) {
return this.render(false); return this.render(false);
} }
return this.close(); return this.close();

View File

@@ -9,22 +9,23 @@ export class RollL5r5e extends Roll {
super(formula, data, options); super(formula, data, options);
this.l5r5e = { this.l5r5e = {
stance: "",
skillId: "",
skillCatId: "",
actor: null, actor: null,
targetTokenId: null,
difficulty: 2,
difficultyHidden: false,
voidPointUsed: false,
keepLimit: null,
isInitiativeRoll: false,
skillAssistance: 0,
initialFormula: null,
dicesTypes: { dicesTypes: {
std: false, std: false,
l5r: 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: { summary: {
totalSuccess: 0, totalSuccess: 0,
totalBonus: 0, totalBonus: 0,
@@ -33,12 +34,12 @@ export class RollL5r5e extends Roll {
opportunity: 0, opportunity: 0,
strife: 0, strife: 0,
}, },
history: null, targetTokenId: null,
rnkEnded: false, voidPointUsed: false,
}; };
// Parse flavor for stance and skillId // 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) => { flavors.forEach((res) => {
if (res[1] === "r" && !!res[2] && this.l5r5e.stance === "") { if (res[1] === "r" && !!res[2] && this.l5r5e.stance === "") {
this.l5r5e.stance = res[2]; this.l5r5e.stance = res[2];

File diff suppressed because one or more lines are too long

View File

@@ -237,6 +237,24 @@
flex-wrap: wrap; flex-wrap: wrap;
display: flex; display: flex;
} }
.form-group {
width: 100%;
.form-fields {
flex: 1;
&:nth-child(2) {
flex: 3;
input {
flex: 3;
}
i {
flex: unset;
}
}
}
.range-value {
width: 2rem;
}
}
} }
.profil { .profil {

View File

@@ -73,7 +73,7 @@
{{/if}} {{/if}}
{{#if strife}} {{#if strife}}
<i class="i_strife" title="{{localize 'l5r5e.chatdices.strife'}}"></i>x{{strife}} <i class="i_strife" title="{{localize 'l5r5e.chatdices.strife'}}"></i>x{{strife}} {{#if ../l5r5e.strifeApplied}}<sup>{{../l5r5e.strifeApplied}}</sup>{{/if}}
{{/if}} {{/if}}
</div> </div>

View File

@@ -38,7 +38,7 @@
</header> </header>
<section class="rnk-ct"> <section class="rnk-ct">
{{!-- Body --}} {{!-- Body --}}
{{#if options.editable}} {{^if l5r5e.rnkEnded}}
{{!-- Face Rings --}} {{!-- Face Rings --}}
<fieldset class="dropbox swap"> <fieldset class="dropbox swap">
<legend class="section-header"> <legend class="section-header">
@@ -137,6 +137,20 @@
</tr> </tr>
{{/each}} {{/each}}
</table> </table>
{{!-- Strife selection --}}
{{#if l5r5e.summary.strife}}
<div class="form-group" style="width: 100%;">
<div class="form-fields"></div>
<div class="form-fields">
<input type="range" name="strifeApplied" data-dtype="Number" value="{{l5r5e.strifeApplied}}" min="0" max="{{l5r5e.summary.strife}}" step="1">
<span class="range-value">{{l5r5e.strifeApplied}}</span> <i class="i_strife"></i>
</div>
<div class="form-fields"></div>
</div>
<button id="finalize" name="finalize" type="button" {{#if data.submitDisabled}}disabled{{/if}}>
{{ localize 'l5r5e.roll_n_keep.bt_strife' }} <i class="fas fa-arrow-circle-right"></i>
</button>
{{/if}}
{{/if}} {{/if}}
</section> </section>
</form> </form>