Skip to content

Commit

Permalink
fix #483
Browse files Browse the repository at this point in the history
  • Loading branch information
QckSilverDragon committed Dec 15, 2024
1 parent 36751b0 commit da4b4a0
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 41 deletions.
69 changes: 36 additions & 33 deletions system/src/documents/FalloutActor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default class FalloutActor extends Actor {

isSleeping = false;

constructor(object, options={}) {
constructor(object, options = {}) {
super(object, options);
}

Expand All @@ -26,7 +26,7 @@ export default class FalloutActor extends Actor {
const settlement = await fromUuid(settlementUuid);
if (settlement) {
if (settlement.system.leader === actor.uuid) {
await settlement.update({"system.leader": ""});
await settlement.update({ "system.leader": "" });
settlement.sheet.render(false);
}
}
Expand Down Expand Up @@ -135,7 +135,7 @@ export default class FalloutActor extends Actor {

incrementJunk() {
const newJunk = this.system.materials.junk + 1;
this.update({"system.materials.junk": newJunk});
this.update({ "system.materials.junk": newJunk });
}

isFieldOverridden(fieldName) {
Expand Down Expand Up @@ -175,8 +175,11 @@ export default class FalloutActor extends Actor {
prepareDerivedData() {
// Make separate methods for each Actor type (character, npc, etc.) to keep
// things organized.
const disableAutoDerivedStats = game.settings.get(
SYSTEM_ID, "disableAutoDerivedStats"
);

if (this.type === "character" || this.type === "robot") {
if (!disableAutoDerivedStats && (this.type === "character" || this.type === "robot")) {
this._calculateDefense();
this._calculateInitiative();
this._calculateMaxHp();
Expand Down Expand Up @@ -295,8 +298,8 @@ export default class FalloutActor extends Actor {
let outfit = this.items.find(
i =>
i.type === "apparel"
&& i.system.apparelType === "outfit"
&& i.system.equipped
&& i.system.apparelType === "outfit"
&& i.system.equipped
);
if (outfit) {
for (let [k, v] of Object.entries(outfit.system.location)) {
Expand All @@ -323,8 +326,8 @@ export default class FalloutActor extends Actor {
let clothing = this.items.find(
i =>
i.type === "apparel"
&& i.system.apparelType === "clothing"
&& i.system.equipped
&& i.system.apparelType === "clothing"
&& i.system.equipped
);

if (clothing) {
Expand Down Expand Up @@ -354,14 +357,14 @@ export default class FalloutActor extends Actor {
for (let [k, bodyPart] of Object.entries(this.system.body_parts)) {
if (outfittedLocations[k]) {
bodyPart.resistance.physical =
parseInt(outfittedLocations[k].system.resistance.physical)
+ parseInt(this.system.resistance.physical);
parseInt(outfittedLocations[k].system.resistance.physical)
+ parseInt(this.system.resistance.physical);
bodyPart.resistance.energy =
parseInt(outfittedLocations[k].system.resistance.energy)
+ parseInt(this.system.resistance.energy);
parseInt(outfittedLocations[k].system.resistance.energy)
+ parseInt(this.system.resistance.energy);
bodyPart.resistance.radiation =
parseInt(outfittedLocations[k].system.resistance.radiation)
+ parseInt(this.system.resistance.radiation);
parseInt(outfittedLocations[k].system.resistance.radiation)
+ parseInt(this.system.resistance.radiation);
}
else {
bodyPart.resistance.physical = parseInt(this.system.resistance.physical);
Expand Down Expand Up @@ -541,23 +544,23 @@ export default class FalloutActor extends Actor {
}
// ADD PLATING AND RESISTANCE BONUSES
let plating = this.items.find(i => i.type === "robot_armor"
&& i.system.apparelType === "plating"
&& i.system.equipped
&& i.system.apparelType === "plating"
&& i.system.equipped
);

if (plating) {
for (let [k, v] of Object.entries(plating.system.location)) {
if (outfittedLocations[k] && v) {
outfittedLocations[k].name += ` over ${plating.name}`;
outfittedLocations[k].system.resistance.physical =
parseInt(outfittedLocations[k].system.resistance.physical)
+ parseInt(plating.system.resistance.physical);
parseInt(outfittedLocations[k].system.resistance.physical)
+ parseInt(plating.system.resistance.physical);
outfittedLocations[k].system.resistance.energy =
parseInt(outfittedLocations[k].system.resistance.energy)
+ parseInt(plating.system.resistance.energy);
parseInt(outfittedLocations[k].system.resistance.energy)
+ parseInt(plating.system.resistance.energy);
outfittedLocations[k].system.resistance.radiation =
parseInt(outfittedLocations[k].system.resistance.radiation)
+ parseInt(plating.system.resistance.radiation);
parseInt(outfittedLocations[k].system.resistance.radiation)
+ parseInt(plating.system.resistance.radiation);
}
else if (!outfittedLocations[k] && v) {
outfittedLocations[k] = foundry.utils.duplicate(plating.toObject());
Expand All @@ -569,14 +572,14 @@ export default class FalloutActor extends Actor {
for (let [k, bodyPart] of Object.entries(this.system.body_parts)) {
if (outfittedLocations[k]) {
bodyPart.resistance.physical =
parseInt(outfittedLocations[k].system.resistance.physical)
+ parseInt(this.system.resistance.physical);
parseInt(outfittedLocations[k].system.resistance.physical)
+ parseInt(this.system.resistance.physical);
bodyPart.resistance.energy =
parseInt(outfittedLocations[k].system.resistance.energy)
+ parseInt(this.system.resistance.energy);
parseInt(outfittedLocations[k].system.resistance.energy)
+ parseInt(this.system.resistance.energy);
bodyPart.resistance.radiation =
parseInt(outfittedLocations[k].system.resistance.radiation)
+ parseInt(this.system.resistance.radiation);
parseInt(outfittedLocations[k].system.resistance.radiation)
+ parseInt(this.system.resistance.radiation);
}
else {
bodyPart.resistance.physical = parseInt(this.system.resistance.physical);
Expand Down Expand Up @@ -779,7 +782,7 @@ export default class FalloutActor extends Actor {
/**
* Prepare NPC roll data.
*/
_getNpcRollData(data) {}
_getNpcRollData(data) { }

async _preCreate(data, options, user) {
await super._preCreate(data, options, user);
Expand Down Expand Up @@ -866,7 +869,7 @@ export default class FalloutActor extends Actor {

for (const category of Object.keys(categoryTableDefaults)) {
const key = `system.item_types.${category}.table`;
scavengingLocationUpdate[key] = categoryTableDefaults[category];
scavengingLocationUpdate[key] = categoryTableDefaults[category];
}

await this.updateSource(scavengingLocationUpdate);
Expand Down Expand Up @@ -1394,7 +1397,7 @@ export default class FalloutActor extends Actor {

let scenes = item.system.duration === "lasting" ? 2 : 1;

let newDosage = this.system.chemDoses[chemId]?.doses ?? 0;
let newDosage = this.system.chemDoses[chemId]?.doses ?? 0;
newDosage = alreadyAddicted ? 1 : newDosage + 1;

const addictionNumberExceeded =
Expand Down Expand Up @@ -1623,7 +1626,7 @@ export default class FalloutActor extends Actor {


// Reduce Ammo
async reduceAmmo(ammoName="", roundsToUse=0) {
async reduceAmmo(ammoName = "", roundsToUse = 0) {
const [ammoItems, shotsAvailable] = this._getAvailableAmmoType(ammoName);

if (shotsAvailable <= 0) return;
Expand Down Expand Up @@ -1730,7 +1733,7 @@ export default class FalloutActor extends Actor {
this,
{
title: game.i18n.localize("FALLOUT.AvailabilityRoll.result.title"),
body: game.i18n.format("FALLOUT.AvailabilityRoll.result.body", {rarity}),
body: game.i18n.format("FALLOUT.AvailabilityRoll.result.body", { rarity }),
},
CONST.DICE_ROLL_MODES.PRIVATE
);
Expand Down
10 changes: 10 additions & 0 deletions system/src/settings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@ export default function registerSettings() {
requiresReload: true,
});

game.settings.register(SYSTEM_ID, "disableAutoDerivedStats", {
name: "Disable Auto-calculated Player Derived Stats",
hint: "By default the system will auto-calculate derived stats for player characters based on the core rulebook. Check this if would prefer to populate these values manually.",
scope: "world",
type: Boolean,
config: true,
default: false,
requiresReload: true,
});

game.settings.register(SYSTEM_ID, "disableAutoXpReward", {
name: "Disable Auto-calculated NPC XP Reward",
hint: "By default the system will auto-calculate the XP reward level of an NPC based on the core rulebook. Check this if would prefer to populate these values manually.",
Expand Down
4 changes: 4 additions & 0 deletions system/src/sheets/FalloutPcSheet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ export default class FalloutPcSheet extends FalloutBaseActorSheet {
SYSTEM_ID, "disableAutoXpTarget"
);

context.disableAutoDerivedStats = game.settings.get(
SYSTEM_ID, "disableAutoDerivedStats"
);

this._updateChemDoseManager();

// ADD FAVOURITE ITEMS
Expand Down
8 changes: 5 additions & 3 deletions system/templates/actor/_shared-partials/header.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,11 @@
name="system.level.nextLevelXP"
type="text"
value="{{system.level.nextLevelXP}}"
{{#unless disableAutoXpTarget}}
data-tooltip="{{localize 'FALLOUT.Actor.Warnings.DerivedValue'}}"
disabled
{{#unless disableAutoDerivedStats}}
{{#unless disableAutoXpTarget}}
data-tooltip="{{localize 'FALLOUT.Actor.Warnings.DerivedValue'}}"
disabled
{{/unless}}
{{/unless}}
/>
</div>
Expand Down
12 changes: 9 additions & 3 deletions system/templates/actor/pc/partials/derived.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
</label>
<input
class="num-short-2"
data-tooltip="{{localize 'FALLOUT.Actor.Warnings.DerivedValue'}}"
name="system.meleeDamage.value"
type="number"
value="{{system.meleeDamage.value}}"
{{#unless disableAutoDerivedStats}}
data-tooltip="{{localize 'FALLOUT.Actor.Warnings.DerivedValue'}}"
disabled
{{/unless}}
>
</div>
<div class="flexrow resource-row align-mid">
Expand All @@ -21,11 +23,13 @@
</label>
<input
class="num-short-2"
data-tooltip="{{localize 'FALLOUT.Actor.Warnings.DerivedValue'}}"
type="number"
name="system.defense.value"
value="{{system.defense.value}}"
{{#unless disableAutoDerivedStats}}
data-tooltip="{{localize 'FALLOUT.Actor.Warnings.DerivedValue'}}"
disabled
{{/unless}}
>
</div>
<div class="flexrow resource-row align-mid">
Expand All @@ -34,11 +38,13 @@
</label>
<input
class="num-short-2"
data-tooltip="{{localize 'FALLOUT.Actor.Warnings.DerivedValue'}}"
type="number"
name="system.initiative.value"
value="{{system.initiative.value}}"
{{#unless disableAutoDerivedStats}}
data-tooltip="{{localize 'FALLOUT.Actor.Warnings.DerivedValue'}}"
disabled
{{/unless}}
>
</div>
</div>
7 changes: 5 additions & 2 deletions system/templates/actor/pc/partials/health.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
<span class="text-center">/</span>
<input
class="num-short-3"
data-tooltip="{{localize 'FALLOUT.Actor.Warnings.DerivedValue'}}"
style="font-size:18px; background-color: beige; color: black;"
type="number"
name="system.health.max"
value="{{system.health.max}}"
min="0" disabled
min="0"
{{#unless disableAutoDerivedStats}}
disabled
data-tooltip="{{localize 'FALLOUT.Actor.Warnings.DerivedValue'}}"
{{/unless}}
>
</div>
</div>

0 comments on commit da4b4a0

Please sign in to comment.