diff --git a/module/config.mjs b/module/config.mjs index 95150f6..76844f0 100644 --- a/module/config.mjs +++ b/module/config.mjs @@ -1,37 +1,47 @@ -const statDice = [ `d4`, `d6`, `d8`, `d10`, `d12`, `d20` ]; +export const statDice = [ `d4`, `d6`, `d8`, `d10`, `d12`, `d20` ]; -const trainingLevels = [``, `locked`, `+2`, `+4`]; +export const trainingLevels = [``, `locked`, `+2`, `+4`]; -const damageTypes = [ `slashing`, `piercing`, `smashing`, `gun`, `neon`, `shadow`, `solar` ]; +export const damageTypes = [ `slashing`, `piercing`, `smashing`, `gun`, `neon`, `shadow`, `solar` ]; -const ammoTypes = [`quivers`, `mags`, `cells`]; +export const ammoTypes = [`quivers`, `mags`, `cells`]; -const stats = [ `build`, `meta`, `presence`, `hands`, `tilt`, `rng` ]; +export const stats = [ `build`, `meta`, `presence`, `hands`, `tilt`, `rng` ]; -const buildSkills = [ `defense`, `magic`, `melee`, `platforming`, `strength`, ]; -const metaSkills = [ `alchemy`, `arcanum`, `dreams`, `lore`, `navigation`, ]; -const presenceSkills = [ `animal_handling`, `perception`, `sneak`, `speech`, `vibes`, ]; -const handsSkills = [ `accuracy`, `crafting`, `engineering`, `explosives`, `piloting`, ]; +export const buildSkills = [ `defense`, `magic`, `melee`, `platforming`, `strength`, ]; +export const metaSkills = [ `alchemy`, `arcanum`, `dreams`, `lore`, `navigation`, ]; +export const presenceSkills = [ `animal_handling`, `perception`, `sneak`, `speech`, `vibes`, ]; +export const handsSkills = [ `accuracy`, `crafting`, `engineering`, `explosives`, `piloting`, ]; -const allSkills = [ +export const allSkills = [ ...buildSkills, ...metaSkills, ...presenceSkills, ...handsSkills, ]; -const skills = { +export const skills = { build: buildSkills, meta: metaSkills, presence: presenceSkills, hands: handsSkills, }; -const itemTiers = [ +export const itemTiers = [ `simple`, `greater`, `rare`, `legendary` ]; +export const syncMilestones = [ + { value: 20, andReturn: true }, + { value: 40, andReturn: false }, + { value: 60, andReturn: true }, + { value: 80, andReturn: false }, + { value: 100, andReturn: true }, +]; + +export const syncDice = "1d20"; + export default { stats, statDice, @@ -45,4 +55,6 @@ export default { allSkills, skills, itemTiers, -}; \ No newline at end of file + syncMilestones, + syncDice, +}; diff --git a/module/documents/Actor/Handler.mjs b/module/documents/Actor/Handler.mjs index 02ae92d..557f569 100644 --- a/module/documents/Actor/Handler.mjs +++ b/module/documents/Actor/Handler.mjs @@ -1,11 +1,13 @@ import PlayerActor from "./Player.mjs"; import MobActor from "./Mob.mjs"; +import SyncActor from "./Sync.mjs"; /** @extends {Actor} */ export class ActorHandler extends Actor { proxyTargets = { player: PlayerActor, mob: MobActor, + sync: SyncActor, }; constructor(data, ctx) { @@ -89,4 +91,10 @@ export class ActorHandler extends Actor { }; return true; }; + + _preUpdate(...args) { + return this.proxyFunction("_preUpdate", ...args); + }; + + useRestDie() { return this.proxyFunction("useRestDie"); }; }; diff --git a/module/documents/Actor/Sync.mjs b/module/documents/Actor/Sync.mjs new file mode 100644 index 0000000..caa5a5d --- /dev/null +++ b/module/documents/Actor/Sync.mjs @@ -0,0 +1,60 @@ +import { syncMilestones, syncDice } from "../../config.mjs"; + +/** @this {Actor} */ +async function useRestDie() { + let addToSync = await (new Roll(syncDice)).evaluate(); + await addToSync.toMessage({ + speaker: ChatMessage.getSpeaker({ actor: this.actor }), + flavor: `Sync Restoration`, + }); + this.update({ + "system.rest_dice": this.system.rest_dice - 1, + "system.value": this.system.value + addToSync.total, + }); +}; + +/** @this {Actor} */ +async function _preUpdate(data, options) { + if (options.diff) { + if (data.system?.value != null) { + let currentSync = this.system.value; + let newSync = data.system.value; + + let minSync = Math.min(currentSync, newSync); + let maxSync = Math.max(currentSync, newSync); + let milestones = syncMilestones.filter( + m => minSync < m.value && m.value <= maxSync + ); + + if (milestones.length > 0) data.system.rest_dice ??= this.system.rest_dice; + + for (const milestone of milestones) { + // Damage + if (newSync < currentSync) { + if (!this.system.milestones_hit.has(milestone.value)) { + data.system.rest_dice += 1; + this.system.milestones_hit.add(milestone.value); + }; + } + + // Healing + else if (newSync > currentSync) { + if ( + this.system.milestones_hit.has(milestone.value) + && milestone.andReturn + && milestone.value <= newSync + ) { + this.system.milestones_hit.delete(milestone.value); + }; + }; + }; + + data.system.milestones_hit = [ ...this.system.milestones_hit ]; + }; + }; +}; + +export default { + _preUpdate, + useRestDie, +}; diff --git a/module/models/Actor/Sync.mjs b/module/models/Actor/Sync.mjs index 64bf260..9d8082e 100644 --- a/module/models/Actor/Sync.mjs +++ b/module/models/Actor/Sync.mjs @@ -3,10 +3,18 @@ export class SyncData extends foundry.abstract.TypeDataModel { const fields = foundry.data.fields; return { value: new fields.NumberField({ - required: true, integer: true, initial: 100, }), + rest_dice: new fields.NumberField({ + integer: true, + initial: 0, + min: 0, + }), + milestones_hit: new fields.SetField( + new fields.NumberField({ integer: true, }), + { initial: [] }, + ), }; }; -}; \ No newline at end of file +}; diff --git a/module/sheets/SyncVariations/AbstractSyncSheet.mjs b/module/sheets/SyncVariations/AbstractSyncSheet.mjs index 7af1899..3ec588e 100644 --- a/module/sheets/SyncVariations/AbstractSyncSheet.mjs +++ b/module/sheets/SyncVariations/AbstractSyncSheet.mjs @@ -6,7 +6,7 @@ export class AbstractSyncSheet extends GenericActorSheet { super.defaultOptions, { width: 200, - height: 200, + height: 275, } ); opts.classes.push( @@ -22,11 +22,12 @@ export class AbstractSyncSheet extends GenericActorSheet { ctx.system = actor.system; ctx.flags = actor.flags; - - console.groupCollapsed(`SyncSheet.getData`); - console.log(`ctx`, ctx); - console.log(`actor`, actor); - console.groupEnd(); return ctx; }; + + activateListeners(html) { + super.activateListeners(html); + html.find(`.use-rest-die`) + .on(`click`, this.actor.useRestDie.bind(this.actor)); + }; }; \ No newline at end of file diff --git a/styles/global/buttons.scss b/styles/global/buttons.scss index 6364e93..ced06f9 100644 --- a/styles/global/buttons.scss +++ b/styles/global/buttons.scss @@ -1,5 +1,7 @@ @use "../vars.scss" as *; +@use "sass:color" as color; + .dotdungeon.dotdungeon.dotdungeon.dotdungeon > .window-content { button { border-radius: 4px; @@ -21,31 +23,52 @@ &.confirm { background: $colour-confirm; color: $text-on-confirm; - &:hover, &:focus-visible { + + &:hover:not(:disabled), + &:focus-visible { background: transparent; color: $colour-confirm; border-color: $colour-confirm; } + + &:disabled { + background: color.adjust($colour-confirm, $lightness: -10%); + color: color.adjust($text-on-confirm, $lightness: -15%); + } } &.neutral { background: $colour-neutral; color: $text-on-neutral; - &:hover, &:focus-visible { + + &:hover:not(:disabled), + &:focus-visible { background: transparent; color: $colour-neutral; border-color: $colour-neutral; } + + &:disabled { + background: color.adjust($colour-neutral, $lightness: -10%); + color: color.adjust($text-on-neutral, $lightness: -15%); + } } &.danger { background: $colour-danger; color: $text-on-danger; - &:hover, &:focus-visible { + + &:hover:not(:disabled), + &:focus-visible { background: transparent; color: $colour-danger; border-color: $colour-danger; } + + &:disabled { + background: color.adjust($colour-danger, $lightness: -10%); + color: color.adjust($text-on-danger, $lightness: -15%); + } } &.reduced-padding { diff --git a/styles/sheets/actor/sync/basic.scss b/styles/sheets/actor/sync/basic.scss index 5914f07..6f412be 100644 --- a/styles/sheets/actor/sync/basic.scss +++ b/styles/sheets/actor/sync/basic.scss @@ -23,6 +23,22 @@ width: 60%; text-align: center; } + + .rest-container { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + gap: 4px; + + .button-row { + display: grid; + grid-template-columns: repeat(3, 1fr); + gap: 4px; + align-items: center; + text-align: center; + } + } } &--sync-sheet { diff --git a/templates/actors/sync/basic.hbs b/templates/actors/sync/basic.hbs index 942ba30..93a0e84 100644 --- a/templates/actors/sync/basic.hbs +++ b/templates/actors/sync/basic.hbs @@ -17,4 +17,38 @@ value="{{system.value}}" > +
+ Rest Dice: +
+ + + {{system.rest_dice}} + + +
+ +
\ No newline at end of file