Add custom Die class for handling the ripping and crypting dice
This commit is contained in:
parent
b10535eceb
commit
fe4ebcdb5c
2 changed files with 63 additions and 0 deletions
56
module/dice/CryptDie.mjs
Normal file
56
module/dice/CryptDie.mjs
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
import { Logger } from "../utils/Logger.mjs";
|
||||||
|
|
||||||
|
const { Die } = foundry.dice.terms;
|
||||||
|
|
||||||
|
export class CryptDie extends Die {
|
||||||
|
static get MODIFIERS() {
|
||||||
|
return {
|
||||||
|
...super.MODIFIERS,
|
||||||
|
"rc": `ripOrCrypt`,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
ripCryptState = undefined;
|
||||||
|
async ripOrCrypt(modifier) {
|
||||||
|
|
||||||
|
const rgx = /rc([0-9]+)/i;
|
||||||
|
const match = modifier.match(rgx);
|
||||||
|
if (!match) { return false };
|
||||||
|
let [ target ] = match.slice(1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Handle "Ripping" rolls, which is equivalent to re-rolling 8's and counting
|
||||||
|
it as a success.
|
||||||
|
*/
|
||||||
|
await this.explode(`x=8`, { recursive: true });
|
||||||
|
if(this.results.some(result => result.exploded)) {
|
||||||
|
this.ripCryptState = `ripping`;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Handles "Crypting" rolls, which is a single explosion that allows
|
||||||
|
*/
|
||||||
|
if (!this.ripCryptState) {
|
||||||
|
await this.explode(`xo=1`, { recursive: false });
|
||||||
|
|
||||||
|
let almostCrypted = false;
|
||||||
|
for (const result of this.results) {
|
||||||
|
if (result.result !== 1) { continue };
|
||||||
|
if (almostCrypted) {
|
||||||
|
this.ripCryptState = `crypted`;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
almostCrypted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Count successes and deduct failures from total
|
||||||
|
await this.countSuccess(`cs>=${target}`);
|
||||||
|
await this.deductFailures(`df<${target}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
get total() {
|
||||||
|
return Math.max(super.total, 0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -5,6 +5,9 @@ import { HeroSummaryCardV1 } from "../Apps/ActorSheets/HeroSummaryCardV1.mjs";
|
||||||
import { HeroData } from "../data/Actor/Hero.mjs";
|
import { HeroData } from "../data/Actor/Hero.mjs";
|
||||||
import { registerDevSettings } from "../settings/devSettings.mjs";
|
import { registerDevSettings } from "../settings/devSettings.mjs";
|
||||||
|
|
||||||
|
// Class Overrides
|
||||||
|
import { CryptDie } from "../dice/CryptDie.mjs";
|
||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
import { Logger } from "../utils/Logger.mjs";
|
import { Logger } from "../utils/Logger.mjs";
|
||||||
|
|
||||||
|
|
@ -19,6 +22,10 @@ Hooks.once(`init`, () => {
|
||||||
CONFIG.Actor.dataModels.hero = HeroData;
|
CONFIG.Actor.dataModels.hero = HeroData;
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
|
// #region Class Changes
|
||||||
|
CONFIG.Dice.terms.d = CryptDie;
|
||||||
|
// #endregion
|
||||||
|
|
||||||
// #region Sheets
|
// #region Sheets
|
||||||
// #region Actors
|
// #region Actors
|
||||||
Actors.registerSheet(game.system.id, HeroSummaryCardV1, {
|
Actors.registerSheet(game.system.id, HeroSummaryCardV1, {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue