Skip to content

Commit

Permalink
Merge pull request dmdorman#821 from phBalance/phBalance/loading-issu…
Browse files Browse the repository at this point in the history
…es-4

Skill enhancer improvements
  • Loading branch information
phBalance authored Mar 9, 2024
2 parents 46974df + af1a134 commit c6b415b
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 145 deletions.
19 changes: 0 additions & 19 deletions module/handlebars-helpers.mjs
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
export function initializeHandlebarsHelpers() {
Handlebars.registerHelper("filterItem", filterItem);
Handlebars.registerHelper("indexOf", indexOf);
Handlebars.registerHelper("abs", abs);
Handlebars.registerHelper("increment", increment);
Handlebars.registerHelper("gameConfigValue", gameConfigValue);
}

function filterItem(item, filterString) {
if (!filterString) return item;

if (
item.name.toLowerCase().includes(filterString.toLowerCase()) ||
(item.system.description &&
item.system.description
.toLowerCase()
.includes(filterString.toLowerCase())) ||
(item.system.XMLID &&
item.system.XMLID.toLowerCase().includes(
filterString.toLowerCase(),
))
) {
return item;
}
}

function indexOf(str, searchTerm) {
return str.indexOf(searchTerm);
}
Expand Down
83 changes: 57 additions & 26 deletions module/item/item.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export function initializeItemHandlebarsHelpers() {
Handlebars.registerHelper("itemName", itemName);
Handlebars.registerHelper("itemIsManeuver", itemIsManeuver);
Handlebars.registerHelper("itemIsOptionalManeuver", itemIsOptionalManeuver);
Handlebars.registerHelper("filterItem", filterItem);
Handlebars.registerHelper("parentItem", parentItem);
Handlebars.registerHelper("parentItemType", parentItemType);
}

// Returns HTML so expects to not escaped in handlebars (i.e. triple braces)
Expand Down Expand Up @@ -62,6 +65,34 @@ function itemIsOptionalManeuver(item) {
);
}

function filterItem(item, filterString) {
if (!filterString) return item;

if (
item.name.toLowerCase().includes(filterString.toLowerCase()) ||
(item.system.description &&
item.system.description
.toLowerCase()
.includes(filterString.toLowerCase())) ||
(item.system.XMLID &&
item.system.XMLID.toLowerCase().includes(
filterString.toLowerCase(),
))
) {
return item;
}
}

function parentItem(item) {
return item.getHdcParent();
}

function parentItemType(item, type) {
const parent = parentItem(item);

return parent?.system.type === type;
}

const itemTypeToIcon = {
attack: "icons/svg/sword.svg",
movement: "icons/svg/pawprint.svg",
Expand Down Expand Up @@ -1467,11 +1498,13 @@ export class HeroSystem6eItem extends Item {
...HeroSystem6eItem.ItemXmlTags,
...powerList
.filter(
(o) =>
o.type?.includes("characteristic") ||
o.type?.includes("framework"),
(power) =>
power.type.includes("characteristic") ||
power.type.includes("framework") ||
(power.type.includes("skill") &&
power.type.includes("enhancer")),
)
.map((o) => o.key),
.map((power) => power.key),
]) {
const itemSubTag = itemTag
.replace(/S$/, "")
Expand Down Expand Up @@ -1542,16 +1575,6 @@ export class HeroSystem6eItem extends Item {
// Base Cost is typically extracted directly from HDC
let baseCost = system.baseCost;

// Power Framework might be important
let parentItem = this.getHdcParent();
let configPowerInfoParent = null;
if (parentItem) {
configPowerInfoParent = getPowerInfo({
item: parentItem,
actor: actor,
});
}

// Cost per level is NOT included in the HDC file.
// We will try to get cost per level via config.js
// Default cost per level will be BASECOST, or 3/2 for skill, or 1 for everything else
Expand Down Expand Up @@ -1683,14 +1706,6 @@ export class HeroSystem6eItem extends Item {
}
}

// Skill Enhancer discount (a hidden discount; not shown in item description)
if (
configPowerInfoParent &&
configPowerInfoParent.type?.includes("enhancer")
) {
cost = Math.max(1, cost - 1);
}

cost += adderCost;

// INDEPENDENT ADVANTAGE (aka Naked Advantage)
Expand All @@ -1700,7 +1715,7 @@ export class HeroSystem6eItem extends Item {
for (let modifier of (system.MODIFIER || []).filter(
(o) => !o.PRIVATE,
)) {
advantages += modifier.baseCost; //parseFloat(modifier.BASECOST)
advantages += modifier.baseCost;
}
cost = cost * advantages;
}
Expand Down Expand Up @@ -1796,7 +1811,8 @@ export class HeroSystem6eItem extends Item {
}

calcRealCost() {
let system = this.system;
const system = this.system;

// Real Cost = Active Cost / (1 + total value of all Limitations)

// This may be a slot in a framework if so get parent
Expand Down Expand Up @@ -1829,7 +1845,7 @@ export class HeroSystem6eItem extends Item {
if (adder.XMLID == "JAMMED" && _myLimitation == 0.25) {
system.title =
(system.title || "") +
"Limitations are below the minumum of -1/4; \nConsider removing unnecessary limitations. ";
"Limitations are below the minimum of -1/4; \nConsider removing unnecessary limitations.";
adderBaseCost = 0;
}

Expand All @@ -1849,7 +1865,7 @@ export class HeroSystem6eItem extends Item {
_myLimitation = 0.25;
system.title =
(system.title || "") +
"Limitations are below the minimum of -1/4; \nConsider removing unnecessary limitations. ";
"Limitations are below the minimum of -1/4; \nConsider removing unnecessary limitations.";
}

//console.log("limitation", modifier.ALIAS, _myLimitation)
Expand All @@ -1860,6 +1876,20 @@ export class HeroSystem6eItem extends Item {

let _realCost = system.activePoints;

// Skill Enhancer discount
if (parent) {
const configPowerInfoParent = getPowerInfo({
item: parent,
});

if (
configPowerInfoParent &&
configPowerInfoParent.type?.includes("enhancer")
) {
_realCost = Math.max(1, _realCost - 1);
}
}

// Power cost in Power Framework is applied before limitations
let costSuffix = "";
if (parent) {
Expand Down Expand Up @@ -2778,6 +2808,7 @@ export class HeroSystem6eItem extends Item {
.replace(";,", ";")
.replace("; ,", ";")
.replace("; ;", ";")
.replace(/;$/, "") // Remove ";" at the end of the description string
.trim();

// Endurance
Expand Down
89 changes: 85 additions & 4 deletions module/testing/testing-upload.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4926,10 +4926,10 @@ export function registerUploadTests(quench) {

describe("CONTACT 11-", async function () {
const contents = `
<PERK XMLID="CONTACT" ID="1709783993407" BASECOST="0.0" LEVELS="2" ALIAS="Contact" POSITION="2" MULTIPLIER="1.0" GRAPHIC="Burst" COLOR="255 255 255" SFX="Default" SHOW_ACTIVE_COST="Yes" INCLUDE_NOTES_IN_PRINTOUT="Yes" NAME="">
<NOTES />
</PERK>
`;
<PERK XMLID="CONTACT" ID="1709783993407" BASECOST="0.0" LEVELS="2" ALIAS="Contact" POSITION="2" MULTIPLIER="1.0" GRAPHIC="Burst" COLOR="255 255 255" SFX="Default" SHOW_ACTIVE_COST="Yes" INCLUDE_NOTES_IN_PRINTOUT="Yes" NAME="">
<NOTES />
</PERK>
`;
let item;

before(async () => {
Expand Down Expand Up @@ -4967,6 +4967,87 @@ export function registerUploadTests(quench) {
});
});
});

describe("Skill enhancers", async function () {
const skillEnhancerContents = `
<SCIENTIST XMLID="SCIENTIST" ID="1236046710927" BASECOST="3.0" LEVELS="0" ALIAS="Scientist" POSITION="19" MULTIPLIER="1.0" GRAPHIC="Burst" COLOR="255 255 255" SFX="Default" SHOW_ACTIVE_COST="Yes" INCLUDE_NOTES_IN_PRINTOUT="Yes" NAME="" INTBASED="NO">
<NOTES />
</SCIENTIST>
`;
const contents = `
<SKILL XMLID="SCIENCE_SKILL" ID="1042169893315" BASECOST="3.0" LEVELS="0" ALIAS="SS" POSITION="20" MULTIPLIER="1.0" GRAPHIC="Burst" COLOR="255 255 255" SFX="Default" SHOW_ACTIVE_COST="Yes" INCLUDE_NOTES_IN_PRINTOUT="Yes" PARENTID="1236046710927" NAME="" INPUT="Astronomy" CHARACTERISTIC="INT" FAMILIARITY="No" LEVELSONLY="No">
<NOTES />
</SKILL>
`;
let skillItem;
let skillEnhancerItem;

before(async () => {
const actor = new HeroSystem6eActor(
{
name: "Quench Actor",
type: "pc",
},
{ temporary: true },
);

skillEnhancerItem = await new HeroSystem6eItem(
HeroSystem6eItem.itemDataFromXml(skillEnhancerContents),
{ temporary: true, parent: actor },
);
await skillEnhancerItem._postUpload();
actor.items.set(
skillEnhancerItem.system.XMLID,
skillEnhancerItem,
);

skillItem = await new HeroSystem6eItem(
HeroSystem6eItem.itemDataFromXml(contents),
{ temporary: true, parent: actor },
);
await skillItem._postUpload();
actor.items.set(skillItem.system.XMLID, skillItem);
skillItem.skillRollUpdateValue();
});

it("skill enhancer description", function () {
assert.equal(
skillEnhancerItem.system.description,
"Scientist",
);
});

it("skill enhancer realCost", function () {
assert.equal(skillEnhancerItem.system.realCost, 3);
});

it("skill enhancer activePoints", function () {
assert.equal(skillEnhancerItem.system.activePoints, 3);
});

it("skill enhancer levels", function () {
assert.equal(skillEnhancerItem.system.value, 0);
});

it("skill description", function () {
assert.equal(
skillItem.system.description,
"SS: Astronomy 11- (3 Active Points)",
);
});

it("skill realCost", function () {
assert.equal(skillItem.system.realCost, 2);
});

it("skill activePoints", function () {
assert.equal(skillItem.system.activePoints, 3);
});

it("skill levels", function () {
assert.equal(skillItem.system.value, 0);
});
});
},
{ displayName: "HERO: Upload" },
);
Expand Down
95 changes: 47 additions & 48 deletions templates/actor/actor-savuori-sheet.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -512,58 +512,57 @@
<th></th>
</tr>
{{#each items as |item id|}}
{{#if (and (eq item.type "power") (filterItem item ../options.itemFilters.power))}}
{{#if (eq item.system.XMLID "LIST")}}
<tr class="item">
<td height="24"></td>
<td></td>
<td class="left">{{item.system.ALIAS}}</td>
<td></td>
<td></td>
<td></td>
</tr>
{{else}}
<tr class="item {{#if (gt item.system.value item.system.max)}} overMax{{/if}}{{#if (lt item.system.value item.system.max)}} underMax{{/if}}"
data-item-id="{{item._id}}">
<td>
<div class="item-image"><img src="{{item.img}}" title="{{item.name}}" width="24"
height="24" /></div>
</td>
<td>{{item.system.realCost}}</td>
<td class="left{{#if item.system.PARENTID}} item-framework-child-name{{/if}}">
{{#if item.system.childIdx}}
{{item.system.childIdx}})
{{/if}}
{{{itemFullDescription item}}}
</td>
<td>{{item.system.endEstimate}}</td>

<td>
{{#if (ne item.system.subType "attack")}}
{{#if item.system.showToggle}}
<input class="item-toggle" type="checkbox"
Xname="item.system.active" {{checked item.system.active}} data-dtype="Boolean"
data-action="toggle" />
{{!-- Show powers and things in a framework or compound power --}}
{{#if (and (or (eq item.type "power") (parentItemType item "framework") (parentItemType item "compound")) (filterItem item ../options.itemFilters.power))}}
{{#if (eq item.system.XMLID "LIST")}}
<tr class="item">
<td height="24"></td>
<td></td>
<td class="left">{{item.system.ALIAS}}</td>
<td></td>
<td></td>
<td></td>
</tr>
{{else}}
<tr class="item {{#if (gt item.system.value item.system.max)}} overMax{{/if}}{{#if (lt item.system.value item.system.max)}} underMax{{/if}}"
data-item-id="{{item._id}}">
<td>
<div class="item-image"><img src="{{item.img}}" title="{{item.name}}" width="24"
height="24" /></div>
</td>
<td>{{item.system.realCost}}</td>
<td class="left{{#if item.system.PARENTID}} item-framework-child-name{{/if}}">
{{#if item.system.childIdx}}
{{item.system.childIdx}})
{{/if}}
{{else}}
<a class="item-image item-rollable"><i class="fas fa-dice" title="{{item.name}}" width="24" height="24"></i></a>
{{/if}}
</td>
<td>
<a class="item-control item-chat" title="Send to chat"><i
class="fas fa-comment-alt"></i></a>
<a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Delete Item">
<i class="fas fa-trash"></i>
</a>
</td>
</tr>
{{{itemFullDescription item}}}
</td>
<td>{{item.system.endEstimate}}</td>

<td>
{{#if (ne item.system.subType "attack")}}
{{#if item.system.showToggle}}
<input class="item-toggle" type="checkbox"
Xname="item.system.active" {{checked item.system.active}} data-dtype="Boolean"
data-action="toggle" />
{{/if}}
{{else}}
<a class="item-image item-rollable"><i class="fas fa-dice" title="{{item.name}}" width="24" height="24"></i></a>
{{/if}}
</td>
<td>
<a class="item-control item-chat" title="Send to chat"><i
class="fas fa-comment-alt"></i></a>
<a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Delete Item">
<i class="fas fa-trash"></i>
</a>
</td>
</tr>
{{/if}}
{{/if}}
{{/if}}
{{/each}}

</table>

</div> {{!-- Powers Tab --}}


Expand Down
Loading

0 comments on commit c6b415b

Please sign in to comment.