Skip to content

Commit

Permalink
Set shield when equipped, bring back settings for custom bulk, implem…
Browse files Browse the repository at this point in the history
…ent hefty hauler and lifting belt
  • Loading branch information
BernhardPosselt authored and Hooking committed Jun 1, 2020
1 parent 0322f4d commit 0e7da89
Show file tree
Hide file tree
Showing 15 changed files with 567 additions and 371 deletions.
7 changes: 5 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ root = true

[*]
indent_style = space
indent_size = 2
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
insert_final_newline = false

[{*.json,*.html}]
indent_size = 2
540 changes: 263 additions & 277 deletions dist/packs/equipment.db

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@
"Biography": "Biography",
"BonusBulk": "Bonus Bulk Maximum",
"BonusBulkTitle": "Add or subtract from your bulk limit",
"BonusEncumbranceBulkLabel": "Additional Encumbrance Bulk",
"BonusLimitBulkLabel": "Additional Limit Bulk",
"BonusHPLabel": "Bonus HP",
"BonusHPperLevel": "Bonus HP per Level",
"BonusHPperLevelTitle": "Applies once for every level (CON mod is added separately)",
Expand Down Expand Up @@ -516,6 +518,7 @@
"MaxHitPointsShortLabel": "Max HP",
"MaxStaminaPointsShortLabel": "Max SP",
"MaxStaminaTitle": "Your maximum stamina points",
"MaxHitPointsHeader": "Maximum Hit Points",
"ModifierTitle": "Modifier",
"ModifiersTitle": "Modifiers",
"ModifierType": {
Expand Down Expand Up @@ -546,7 +549,7 @@
"PerceptionHeader": "Perception",
"PerceptionLabel": "Perception",
"PotencyRuneLabel": "Potency Rune",
"PreciousMaterialAdamantite": "Adamantite",
"PreciousMaterialAdamantine": "Adamantine",
"PreciousMaterialColdIron": "Cold Iron",
"PreciousMaterialDarkwood": "Darkwood",
"PreciousMaterialDragonhide": "Dragonhide",
Expand Down Expand Up @@ -633,6 +636,7 @@
"SettingsQuickRollsNotes": "If enabled, when you roll dice from a sheet, you only get a pop-up to modify the roll ad-hoc when you hold the SHIFT button.",
"ShieldACBonusTitle": "The AC bonus of your shield (when you use the raise shield action)",
"ShieldBTLabel": "Broken",
"ShieldBrokenThresholdLabel": "Broken Threshold",
"ShieldBTShortLabel": "BT",
"ShieldBTTitle": "Your shields Broken Threshold",
"ShieldCurrentLabel": "Shield HP",
Expand Down
9 changes: 1 addition & 8 deletions src/module/actor/sheet/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,7 @@ class ActorSheetPF2e extends ActorSheet {
skl.label = CONFIG.PF2E.martialSkills[s];
skl.value = skl.rank ? (skl.rank * 2) + sheetData.data.details.level.value : 0;
}

//set Broken Threshold of the characters shield
const shield = sheetData.data.attributes.shield;
shield.brokenThreshold = Math.floor(shield.max/2);

sheetData.data.attributes.shield.brokenThreshold = shield.brokenThreshold;
sheetData.brokenShield = shield.value < shield.brokenThreshold ? true : false;


// Update save labels
for (const [s, save] of Object.entries(sheetData.data.saves)) {
save.icon = this._getProficiencyIcon(save.rank);
Expand Down
66 changes: 64 additions & 2 deletions src/module/actor/sheet/character.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,19 @@ class ActorSheetPF2eCharacter extends ActorSheetPF2e {
return `${path}actor-sheet.html`;
}

/* -------------------------------------------- */
async _updateObject(event, formData) {
// update shield hp
const equippedShieldId = this.getEquippedShield(this.actor.data.items)?._id
if (equippedShieldId !== undefined) {
const shieldEntity = this.actor.getOwnedItem(equippedShieldId);
await shieldEntity.update({
'data.hp.value': formData['data.attributes.shield.hp.value']
})
}
await super._updateObject(event, formData);
}

/* -------------------------------------------- */

/**
* Add some extra data when rendering the sheet to reduce the amount of logic required within the template.
Expand Down Expand Up @@ -411,15 +423,65 @@ class ActorSheetPF2eCharacter extends ActorSheetPF2e {

actorData.spellcastingEntries = spellcastingEntries;

// shield
const equippedShield = this.getEquippedShield(actorData.items);
if (equippedShield === undefined) {
actorData.data.attributes.shield = {
hp: {
value: 0,
},
maxHp: {
value: 0,
},
armor: {
value: 0,
},
hardness: {
value: 0,
},
brokenThreshold: {
value: 0,
},
}
actorData.data.attributes.shieldBroken = false;
} else {
actorData.data.attributes.shield = duplicate(equippedShield.data)
actorData.data.attributes.shieldBroken = equippedShield.data.hp.value < equippedShield.data.brokenThreshold.value;
}

// Inventory encumbrance
// FIXME: this is hard coded for now
const featNames = new Set(actorData.items
.filter(item => item.type === 'feat')
.map(item => item.name));

let bonusEncumbranceBulk = actorData.data.attributes.bonusEncumbranceBulk ?? 0;
let bonusLimitBulk = actorData.data.attributes.bonusLimitBulk ?? 0;
if (featNames.has('Hefty Hauler')) {
bonusEncumbranceBulk += 2;
bonusLimitBulk += 2;
}
const equippedLiftingBelt = actorData.items
.find(item => item.name === 'Lifting Belt' && item.data.equipped.value) !== undefined;
if (equippedLiftingBelt) {
bonusEncumbranceBulk += 1;
bonusLimitBulk += 1;
}
const [bulk] = calculateBulk(bulkItems, stacks, false, bulkConfig);
actorData.data.attributes.encumbrance = calculateEncumbrance(
actorData.data.abilities.str.mod,
actorData.data.attributes.bonusbulk,
bonusEncumbranceBulk,
bonusLimitBulk,
bulk
);
}

getEquippedShield(items) {
return items
.find(item => item.type === 'armor'
&& item.data.equipped.value
&& item.data.armorType.value === 'shield')
}

/* -------------------------------------------- */
/* Event Listeners and Handlers
Expand Down
10 changes: 5 additions & 5 deletions src/module/item/encumbrance.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export class InventoryWeight {

/**
* @param strengthModifier
* @param bonusBulkLimit in bulk
* @param bonusBulkLimit increased maximum bulk
* @param bonusBulkEncumbrance increased bulk until you are encumbered
* @param combinedBulk
*/
export function calculateEncumbrance(strengthModifier, bonusBulkLimit, combinedBulk) {
const modifier = strengthModifier + bonusBulkLimit;
const encumberedAt = modifier + 5;
const limit = modifier + 10;
export function calculateEncumbrance(strengthModifier, bonusBulkEncumbrance, bonusBulkLimit, combinedBulk) {
const encumberedAt = strengthModifier + bonusBulkEncumbrance + 5;
const limit = strengthModifier + bonusBulkLimit + 10;
return new InventoryWeight(combinedBulk, encumberedAt, limit);
}
60 changes: 37 additions & 23 deletions src/module/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@ export const migrateActorData = function (actor, worldSchemaVersion) {
if (worldSchemaVersion < 0.582) {
migrateActorItems(actor, updateData, addWeaponPotencyRune);
}


if (worldSchemaVersion < 0.583) {
migrateActorBonusBulk(actor, updateData);
migrateActorItems(actor, updateData, addHpThresholdHardness);
}

}
return updateData;
};
Expand All @@ -183,7 +188,7 @@ function addWeaponPotencyRune(item, itemData) {
function addItemRarityAndLevel(item, itemData) {
itemData['data.rarity.value'] = 'common';
if (['treasure', 'backpack'].includes(item.type)) {
itemData['data.level.value'] = '0';
itemData['data.level.value'] = '0';
}
return itemData;
}
Expand Down Expand Up @@ -262,6 +267,16 @@ function addContainerAttributes(item, itemData) {
return itemData;
}

function addHpThresholdHardness(item, updateData) {
if (['weapon', 'melee', 'armor', 'equipment', 'consumable', 'backpack'].includes(item.type)) {
updateData['data.brokenThreshold.value'] = 0;
updateData['data.hp.value'] = 0;
updateData['data.maxHp.value'] = 0;
updateData['data.hardness.value'] = 0;
}
return updateData;
}

async function addCoin(actorEntity, treasureId, denomination, quantity) {
if (quantity !== null && (`${quantity}`).trim() !== '0') {
console.log(`Adding ${quantity} of ${denomination} to actors ${actorEntity.data.name}'s inventory`);
Expand Down Expand Up @@ -351,14 +366,18 @@ export const migrateItemData = function (item, worldSchemaVersion) {
if (worldSchemaVersion < 0.579) {
addContainerAttributes(item, updateData);
}

if (worldSchemaVersion < 0.580) {
addItemRarityAndLevel(item, updateData);
}

if (worldSchemaVersion < 0.582) {
addWeaponPotencyRune(item, updateData);
}

if (worldSchemaVersion < 0.583) {
addHpThresholdHardness(item, updateData);
}
// Return the migrated update data
return updateData;
};
Expand Down Expand Up @@ -426,6 +445,11 @@ function _migrateActorOtherSpeeds(actor, updateData) {
}
}

function migrateActorBonusBulk(actor, updateData) {
updateData['data.attributes.bonusLimitBulk'] = actor.data.attributes.bonusbulk || 0;
updateData['data.attributes.bonusEncumbranceBulk'] = actor.data.attributes.bonusbulk || 0;
}

function _migrateHitPointData(actor, updateData) {
updateData['data.attributes.flatbonushp'] = parseInt((actor.data.attributes.flatbonushp || {}).value) || 0;
updateData['data.attributes.levelbonushp'] = parseInt((actor.data.attributes.levelbonushp || {}).value) || 0;
Expand Down Expand Up @@ -584,40 +608,30 @@ function migrateImage(item, updateData) {
// consumables subfolder
else if (itemImage?.includes('systems/pf2e/icons/equipment/consumables/') && !itemImage?.includes('systems/pf2e/icons/equipment/consumables/potions/') && itemImage?.includes('potion')) {
updateData['img'] = itemImage.replace('systems/pf2e/icons/equipment/consumables/', 'systems/pf2e/icons/equipment/consumables/potions/');
}
else if (itemImage?.includes('systems/pf2e/icons/equipment/alchemical-items/') && !itemImage?.includes('systems/pf2e/icons/equipment/alchemical-items/alchemical-elixirs/') && itemImage?.includes('elixir')) {
} else if (itemImage?.includes('systems/pf2e/icons/equipment/alchemical-items/') && !itemImage?.includes('systems/pf2e/icons/equipment/alchemical-items/alchemical-elixirs/') && itemImage?.includes('elixir')) {
updateData['img'] = itemImage.replace('systems/pf2e/icons/equipment/alchemical-items/', 'systems/pf2e/icons/equipment/alchemical-items/alchemical-elixirs/');
}

// specific icon changes
else if (itemImage?.includes('systems/pf2e/icons/equipment/alchemical-items/acid-flask.jpg')) {
updateData['img'] = itemImage.replace('systems/pf2e/icons/equipment/alchemical-items/acid-flask.jpg', 'systems/pf2e/icons/equipment/alchemical-items/alchemical-bombs/acid-flask.jpg');
}
else if (itemImage?.includes('systems/pf2e/icons/equipment/alchemical-items/alchemists-fire.jpg')) {
} else if (itemImage?.includes('systems/pf2e/icons/equipment/alchemical-items/alchemists-fire.jpg')) {
updateData['img'] = itemImage.replace('systems/pf2e/icons/equipment/alchemical-items/alchemists-fire.jpg', 'systems/pf2e/icons/equipment/alchemical-items/alchemical-bombs/alchemists-fire.jpg');
}
else if (itemImage?.includes('systems/pf2e/icons/equipment/alchemical-items/frost-vial.jpg')) {
} else if (itemImage?.includes('systems/pf2e/icons/equipment/alchemical-items/frost-vial.jpg')) {
updateData['img'] = itemImage.replace('systems/pf2e/icons/equipment/alchemical-items/frost-vial.jpg', 'systems/pf2e/icons/equipment/alchemical-items/alchemical-bombs/frost-vial.jpg');
}
else if (itemImage?.includes('systems/pf2e/icons/equipment/alchemical-items/bombers-eye-elixir.jpg')) {
} else if (itemImage?.includes('systems/pf2e/icons/equipment/alchemical-items/bombers-eye-elixir.jpg')) {
updateData['img'] = itemImage.replace('systems/pf2e/icons/equipment/alchemical-items/bombers-eye-elixir.jpg', 'systems/pf2e/icons/equipment/alchemical-items/alchemical-elixirs/bombers-eye-elixir.jpg');
}
else if (itemImage?.includes('systems/pf2e/icons/equipment/alchemical-items/antidote.jpg')) {
} else if (itemImage?.includes('systems/pf2e/icons/equipment/alchemical-items/antidote.jpg')) {
updateData['img'] = itemImage.replace('systems/pf2e/icons/equipment/alchemical-items/antidote.jpg', 'systems/pf2e/icons/equipment/alchemical-items/alchemical-elixirs/antidote.jpg');
}
else if (itemImage?.includes('systems/pf2e/icons/equipment/alchemical-items/bottled-lightning.jpg')) {
} else if (itemImage?.includes('systems/pf2e/icons/equipment/alchemical-items/bottled-lightning.jpg')) {
updateData['img'] = itemImage.replace('systems/pf2e/icons/equipment/alchemical-items/bottled-lightning.jpg', 'systems/pf2e/icons/equipment/alchemical-items/alchemical-bombs/bottled-lightning.jpg');
}
else if (itemImage?.includes('systems/pf2e/icons/equipment/held-items/platinum-pieces.jpg')) {
} else if (itemImage?.includes('systems/pf2e/icons/equipment/held-items/platinum-pieces.jpg')) {
updateData['img'] = itemImage.replace('systems/pf2e/icons/equipment/held-items/platinum-pieces.jpg', 'systems/pf2e/icons/equipment/treasure/currency/platinum-pieces.jpg');
}
else if (itemImage?.includes('systems/pf2e/icons/equipment/held-items/gold-pieces.jpg')) {
} else if (itemImage?.includes('systems/pf2e/icons/equipment/held-items/gold-pieces.jpg')) {
updateData['img'] = itemImage.replace('systems/pf2e/icons/equipment/held-items/gold-pieces.jpg', 'systems/pf2e/icons/equipment/treasure/currency/gold-pieces.jpg');
}
else if (itemImage?.includes('systems/pf2e/icons/equipment/held-items/silver-pieces.jpg')) {
} else if (itemImage?.includes('systems/pf2e/icons/equipment/held-items/silver-pieces.jpg')) {
updateData['img'] = itemImage.replace('systems/pf2e/icons/equipment/held-items/silver-pieces.jpg', 'systems/pf2e/icons/equipment/treasure/currency/silver-pieces.jpg');
}
else if (itemImage?.includes('systems/pf2e/icons/equipment/held-items/copper-pieces.jpg')) {
} else if (itemImage?.includes('systems/pf2e/icons/equipment/held-items/copper-pieces.jpg')) {
updateData['img'] = itemImage.replace('systems/pf2e/icons/equipment/held-items/copper-pieces.jpg', 'systems/pf2e/icons/equipment/treasure/currency/copper-pieces.jpg');
}

Expand Down
2 changes: 1 addition & 1 deletion src/scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ CONFIG.preciousMaterials = {
coldIron: "PF2E.PreciousMaterialColdIron",
silver: "PF2E.PreciousMaterialSilver",
mithral: "PF2E.PreciousMaterialMithral",
adamantine: "PF2E.PreciousMaterialAdamantite",
adamantine: "PF2E.PreciousMaterialAdamantine",
darkwood: "PF2E.PreciousMaterialDarkwood",
dragonhide: "PF2E.PreciousMaterialDragonhide",
orichalcum: "PF2E.PreciousMaterialOrichalcum",
Expand Down
4 changes: 3 additions & 1 deletion src/styles/actor/character/_character.scss
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@
flex: 100%;
margin-bottom: 0;
}

&_bonus-bulk {
flex: 50%;
}
label,
h4 {
margin: 0;
Expand Down
Loading

0 comments on commit 0e7da89

Please sign in to comment.