From ef06a05d605f6d482f201cb062fd9b5b5dc07e2e Mon Sep 17 00:00:00 2001 From: MulliganStu <31667631+MulliganStu@users.noreply.github.com> Date: Thu, 17 Oct 2024 11:35:10 -0400 Subject: [PATCH] Implement recovery button, encumbrance, and automatic DR (#45) * Get defenderDR from target * Added, recovery roll function * Allow Recover to be clickable * Allow Recover to be clickable * Make Recover text highlight when cursor hover * Minor tweak for text highlight * Minor tweak to add highlight, plus a little icon! * Post test tweaks * Post test tweaks * Removed days without substance with slots * Removed slots * Set up encumberance * Sets DR automatically * minor tweak to auto-filling defender DR when attacking --- css/deathinspace.css | 9 +++- module/actor/actor.js | 66 ++++++++++++++++++++++++++-- module/actor/sheet/actor-sheet.js | 6 +++ module/dialog/attack-dialog.js | 13 +++++- template.json | 4 -- templates/actor/character-sheet.html | 5 ++- 6 files changed, 91 insertions(+), 12 deletions(-) diff --git a/css/deathinspace.css b/css/deathinspace.css index bb8b43e..248d2cd 100644 --- a/css/deathinspace.css +++ b/css/deathinspace.css @@ -455,6 +455,13 @@ .deathinspace.sheet.actor.character .personal-tab .hit-points-row .hit-points-text .help-text { font-size: 12px; } +.deathinspace.sheet.actor.character .personal-tab .hit-points-row .hit-points-text .help-text-recover { + font-size: 12px; +} +.deathinspace.sheet.actor.character .personal-tab .hit-points-row .hit-points-text .help-text-recover:hover { +cursor: pointer; + text-shadow: 0 0 10px red; +} .deathinspace.sheet.actor.character .personal-tab .hit-points-row .hit-points-current-col { border-right: 1px dotted black; display: flex; @@ -1751,4 +1758,4 @@ } .deathinspace.sheet.actor .belongings-tab .holo-row .debt { flex: 1; -} \ No newline at end of file +} diff --git a/module/actor/actor.js b/module/actor/actor.js index d3a8bd7..d6579a5 100644 --- a/module/actor/actor.js +++ b/module/actor/actor.js @@ -41,6 +41,28 @@ export class DISActor extends Actor { }); return super.create(data, options); } + //This and the function below it calculate slot max number automatically and puts it in as a variable under actor.system.maxSlots + prepareDerivedData(){ + const actorData = this; + const systemData = actorData.system; + + this._prepareData(actorData); + } + + _prepareData(actorData){ + const systemData = actorData.system; + systemData.maxSlots = systemData.abilities.body.value + 12; + //this next part makes the DR automatically + const itemArray = Array.from(actorData.items); + let totalDefense = 0; + + for(let i=0;ithis.system.maxSlots){return true;} + else{return false;} + } + get hasVoidPoints() { return this.system.voidPoints && this.system.voidPoints.value; } @@ -130,6 +166,28 @@ export class DISActor extends Actor { async techCheck() { return this.showAbilityCheckDialog("tech"); } + + async rollRecovery(){ + //get BDY + const body = this.system.abilities.body.value; + //roll 1d8+BDY + const roll = new Roll(`1d8 + ${body}`); + await roll.evaluate(); + //if outcome was positive + if(roll.total > 0){ + //do not exceed max health + const newValue = Math.min(this.system.hitPoints.value + roll.total, this.system.hitPoints.max); + //set value + await this.update({ ["system.hitPoints.value"]: newValue}); + } + //chat message + roll.toMessage({ + user: game.user.id, + sound: diceSound(), + speaker: ChatMessage.getSpeaker({actor: this}), + flavor: `Recovered ${roll.total} hit points` + }); + } async showAddItemDialog() { const dialog = new AddItemDialog(); @@ -146,10 +204,10 @@ export class DISActor extends Actor { formulaForRollType(rollType) { let d20Formula = "1d20"; - if (rollType === "advantage") { - d20Formula = "2d20kh"; - } else if (rollType === "disadvantage") { + if (rollType === "disadvantage" || this.isEncumbered) { d20Formula = "2d20kl"; + } else if (rollType === "advantage" && !this.isEncumbered) { + d20Formula = "2d20kh"; } return d20Formula; } diff --git a/module/actor/sheet/actor-sheet.js b/module/actor/sheet/actor-sheet.js index 83ed2a8..27d3a12 100644 --- a/module/actor/sheet/actor-sheet.js +++ b/module/actor/sheet/actor-sheet.js @@ -11,6 +11,7 @@ export default class DISActorSheet extends ActorSheet { html.find(".inline-edit").change(this._onInlineEdit.bind(this)); html.find(".ability-name").click(this._onAbilityRoll.bind(this)); html.find("a.regenerate").click(this._onRegenerate.bind(this)); + html.find(".help-text-recover").click(this._onRecover.bind(this)); } _onItemCreate(event) { @@ -132,4 +133,9 @@ export default class DISActorSheet extends ActorSheet { d.render(true); } } + + _onRecover(event){ + event.preventDefault(); + this.actor.rollRecovery(); + } } diff --git a/module/dialog/attack-dialog.js b/module/dialog/attack-dialog.js index 484c978..02efab7 100644 --- a/module/dialog/attack-dialog.js +++ b/module/dialog/attack-dialog.js @@ -23,10 +23,21 @@ export default class AttackDialog extends Application { /** @override */ async getData() { - let defenderDR = await this.actor.getFlag( + let target = Array.from(game.user.targets)[0]; + + //Checks if target is selected, if not throws a message + if(target == null || target == undefined){ + ui.notifications.error("Please select a target.") + } + + let targetActorId = target.document.actorId; + let actor = game.actors.get(targetActorId); + let defenderDR = await this.actor.getFlag( CONFIG.DIS.flagScope, CONFIG.DIS.flags.DEFENDER_DR ); + defenderDR = actor.system.defenseRating; + if (!defenderDR) { defenderDR = 12; // default } diff --git a/template.json b/template.json index ea5abdb..4c9c985 100644 --- a/template.json +++ b/template.json @@ -22,10 +22,6 @@ "character": { "templates": ["abilities"], "background": "", - "daysWithoutSubstance": { - "max": 7, - "value": 0 - }, "debt": 0, "defenseRating": 12, "drive": "", diff --git a/templates/actor/character-sheet.html b/templates/actor/character-sheet.html index 030fbdb..ed3dd5e 100644 --- a/templates/actor/character-sheet.html +++ b/templates/actor/character-sheet.html @@ -105,7 +105,8 @@
-
{{localize "DIS.HitPointsHelp1"}}
{{localize "DIS.HitPointsHelp2"}}
+
{{localize "DIS.HitPointsHelp1"}}
+
{{localize "DIS.HitPointsHelp2"}}
@@ -361,4 +362,4 @@ {{editor data.system.notes target="system.notes" button=true owner=owner editable=true}}
- \ No newline at end of file +