diff --git a/Axolotl-with-a-Gun/guns/gunsword/inertia-and-pause-buffer.mjs b/Axolotl-with-a-Gun/guns/gunsword/inertia-and-pause-buffer.mjs new file mode 100644 index 0000000..3995962 --- /dev/null +++ b/Axolotl-with-a-Gun/guns/gunsword/inertia-and-pause-buffer.mjs @@ -0,0 +1,145 @@ +const notifStyle = ` + font-size: 1.5rem; + margin: 0.5rem 0; + padding: 6px 8px; + box-shadow: 0 0 10px var(--color-shadow-dark); + color: var(--color-text-light-1); + border-radius: 5px; + text-align: center;`; + +const greenNotif = ` + background: var(--color-level-success-bg); + border: 1px solid var(--color-level-success-border);`; + +const redNotif = ` + background: var(--color-level-error-bg); + border: 1px solid var(--color-level-error);`; + +async function rollDice() { + const sidesOnDice = 6; + + let comboCount = game.user.getFlag(`world`, `comboCount`) ?? 0; + + const answers = await DialogManager.ask({ + id: `gunsword-dice-pool`, + question: `Set up your dice pool:`, + inputs: [ + { + key: `statBase`, + inputType: `number`, + label: `Stat Base`, + autofocus: true, + }, + { + key: `extraDice`, + inputType: `number`, + label: `Extra Dice`, + defaultValue: 0, + }, + { + key: `comboCount`, + inputType: `hidden`, + label: `Combo`, + details: `Your current C-C-C-Combo Meter is at: ${comboCount}`, + }, + ], + }); + const { statBase, extraDice } = answers; + let rollMode = game.settings.get(`core`, `rollMode`); + + let diceCount = statBase ?? 1; + diceCount += extraDice ?? 0; + + let discardedAdded = false; + let successes = 0; + let critsOnly = 0; + const results = []; + const resultValues = []; + for (let i = diceCount; i > 0; i--) { + let r = new Roll(`1d${sidesOnDice}`); + await r.evaluate(); + let classes = `roll die d${sidesOnDice}`; + + let total = r.total; + + if (total === statBase && critsOnly === 0) { + successes += comboCount; + critsOnly += 1; + classes += ` success`; + comboCount = Math.ceil(comboCount / 2); + } + else if (total <= statBase) { + successes += 1; + comboCount += 1; + } + else { + if (!discardedAdded) { + comboCount += 1; + total += `*`; + discardedAdded = true; + }; + classes += ` discarded`; + }; + + resultValues.push(total); + results.push(`
  • ${total}
  • `); + } + + game.user.setFlag(`world`, `comboCount`, comboCount); + + let content = `Rolls:
      ${results.join(`\n`)}
    *Added to combo count.
    Gain 1 Momentum
    Successes: ${successes}
    Crits: ${critsOnly}
    Combo Count After Roll: ${comboCount}`; + + let successType = `Normal`; + if (successes >= 8) { + content += `
    POP OFF
    Add one to your Axolotl stat and gain 1 additional Momentum!`; + successType = `Popped Off`; + } + else if (successes === 0) { + content += `
    Pinned Down
    Roll a d6, rescuing you becomes a new objective`; + successType = `Downed`; + }; + + if (rollMode === CONST.DICE_ROLL_MODES.BLIND) { + ui.notifications.info(`Cannot make a blind roll from the macro, rolling with mode "Private GM Roll" instead`); + rollMode = CONST.DICE_ROLL_MODES.PRIVATE; + }; + + const privacy = stats.utils.determinePrivacyFromRollMode(rollMode); + await CONFIG.stats.db.createRows( + `Dice/d6`, + game.user.id, + resultValues.map(value => ({ value, privacy })), + { rerender: false }, + ); + await CONFIG.stats.db.createRow( + `AwaG/Type of Success`, + game.user.id, + { value: successType, privacy }, + { rerender: false }, + ); + await CONFIG.stats.db.createRow( + `AwaG/Count of Successes`, + game.user.id, + { value: successes, privacy }, + { rerender: false }, + ); + await CONFIG.stats.db.createRow( + `AwaG/Amount of Dice Rolled`, + game.user.id, + { value: diceCount, privacy }, + { rerender: false }, + ); + CONFIG.stats.db.render(); + + const chatData = ChatMessage.applyRollMode( + { + flavor: `(Gun: Gunsword)`, + content, + }, + rollMode, + ); + + await ChatMessage.implementation.create(chatData); +} + +rollDice();