Skip to content

Commit

Permalink
Implement recovery button, encumbrance, and automatic DR (#45)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
MulliganStu authored Oct 17, 2024
1 parent c30426b commit ef06a05
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 12 deletions.
9 changes: 8 additions & 1 deletion css/deathinspace.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1751,4 +1758,4 @@
}
.deathinspace.sheet.actor .belongings-tab .holo-row .debt {
flex: 1;
}
}
66 changes: 62 additions & 4 deletions module/actor/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;i<itemArray.length;i++){
if(!itemArray[i].system.defenseRatingBonus){}
else{ totalDefense += itemArray[i].system.defenseRatingBonus;}
}

systemData.defenseRating = systemData.abilities.dexterity.value + totalDefense + 12;
}

_onCreate(data, options, userId) {
super._onCreate(data, options, userId);
Expand All @@ -49,7 +71,21 @@ export class DISActor extends Actor {
this._addCoreFunctionItems();
}
}

//determines if encumbered or not
get isEncumbered(){
const itemArray = Array.from(this.items);
let slotsUsed = 0;

for(let i=0;i<itemArray.length;i++){
if(!itemArray[i].system.slots){}
else if((itemArray[i].name == "EVA Suit - Light" || itemArray[i].name == "EVA Suit - Heavy") && itemArray[i].system.equipped){}
else {slotsUsed += itemArray[i].system.slots;}
}

if(slotsUsed>this.system.maxSlots){return true;}
else{return false;}
}

get hasVoidPoints() {
return this.system.voidPoints && this.system.voidPoints.value;
}
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions module/actor/sheet/actor-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -132,4 +133,9 @@ export default class DISActorSheet extends ActorSheet {
d.render(true);
}
}

_onRecover(event){
event.preventDefault();
this.actor.rollRecovery();
}
}
13 changes: 12 additions & 1 deletion module/dialog/attack-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 0 additions & 4 deletions template.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
"character": {
"templates": ["abilities"],
"background": "",
"daysWithoutSubstance": {
"max": 7,
"value": 0
},
"debt": 0,
"defenseRating": 12,
"drive": "",
Expand Down
5 changes: 3 additions & 2 deletions templates/actor/character-sheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@
<div class="hit-points-row">
<div class="hit-points-text">
<label>{{localize "DIS.HitPoints"}}</label>
<div class="help-text">{{localize "DIS.HitPointsHelp1"}}<br/>{{localize "DIS.HitPointsHelp2"}}</div>
<div class="help-text">{{localize "DIS.HitPointsHelp1"}}</div>
<div class="help-text-recover"><i class="fa-solid fa-suitcase-medical"></i>{{localize "DIS.HitPointsHelp2"}}</div>
</div>
<div class="hit-points-current-col">
<label>{{localize "DIS.Current"}}</label>
Expand Down Expand Up @@ -361,4 +362,4 @@
{{editor data.system.notes target="system.notes" button=true owner=owner editable=true}}</div>
</div>
</section>
</form>
</form>

0 comments on commit ef06a05

Please sign in to comment.