Skip to content

Commit

Permalink
Handle dual gate kineticist
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPrimate committed Jun 3, 2024
1 parent 288bbf1 commit 7cde814
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.2.1

- Some small tweaks to handle higher level dual gate kineticists correctly.

# 1.2.0

- Remove deprecation messags when running in v12.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pathmuncher",
"version": "1.2.0",
"version": "1.2.1",
"author": "MrPrimate",
"description": "Foundry VTT module for integrating Pathfinder 2e Pathbuilder characters",
"private": true,
Expand Down
59 changes: 36 additions & 23 deletions src/app/Pathmuncher.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ export class Pathmuncher {
includeGrants: false,
includeFlagsOnly: true,
processedRules,
excludeAddedGrants: true,
});

const cleansedChoiceSet = foundry.utils.deepClone(choiceSet);
Expand Down Expand Up @@ -1004,9 +1005,11 @@ export class Pathmuncher {
const tempActor = await this.#generateTempActor({
documents: [document],
includePassedDocumentsRules: true,
// includeGrants: false,
includeGrants: false,
// includeFlagsOnly: true,
otherDocs: otherDocuments,
// include otherDOcs and grants?
excludeAddedGrants: true,
});
const cleansedRule = foundry.utils.deepClone(rule);
try {
Expand Down Expand Up @@ -2523,7 +2526,7 @@ export class Pathmuncher {
}

async #generateTempActor({ documents = [], includePassedDocumentsRules = false, includeGrants = false,
includeFlagsOnly = false, processedRules = [], otherDocs = [] } = {}
includeFlagsOnly = false, processedRules = [], otherDocs = [], excludeAddedGrants = false } = {}
) {
const actorData = foundry.utils.mergeObject({ type: "character", flags: { pathmuncher: { temp: true } } }, this.result.character);
actorData.name = `Mr Temp (${this.result.character.name})`;
Expand All @@ -2534,16 +2537,17 @@ export class Pathmuncher {
const actor = await Actor.create(actorData, { renderSheet: false });
const currentState = foundry.utils.duplicate(this.result);

// console.warn("Initial temp actor", {
// initialTempActor: foundry.utils.deepClone(actor),
// documents,
// includePassedDocumentsRules,
// includeGrants,
// includeFlagsOnly,
// processedRules,
// otherDocs,
// this: this,
// });
console.warn("Initial temp actor", {

Check warning on line 2540 in src/app/Pathmuncher.js

View workflow job for this annotation

GitHub Actions / test (18.x)

Unexpected console statement
initialTempActor: foundry.utils.deepClone(actor),
documents,
includePassedDocumentsRules,
includeGrants,
includeFlagsOnly,
processedRules,
otherDocs,
excludeAddedGrants,
this: this,
});

const currentItems = [
...currentState.deity,
Expand All @@ -2560,8 +2564,8 @@ export class Pathmuncher {
// ...currentState.armor,
// ...currentState.treasure,
// ...currentState.money,
];
currentItems.push(...otherDocs.filter((d) => !currentItems.some((i) => i._id === d._id)));
].filter((i) => !otherDocs.some((o) => i._id === o._id));
currentItems.push(...otherDocs);
for (const doc of documents) {
if (!currentItems.some((d) => d._id === doc._id)) {
currentItems.push(foundry.utils.deepClone(doc));
Expand All @@ -2583,8 +2587,7 @@ export class Pathmuncher {
const objectSelectionRules = i.system.rules
.filter((r) => {
const evaluateRules = ["RollOption", "ChoiceSet"].includes(r.key) && (r.selection || r.domain === "all");
return !includeFlagsOnly || evaluateRules; // && ["RollOption", "GrantItem", "ChoiceSet", "ActiveEffectLike"].includes(r.key);
// || (["ChoiceSet"].includes(r.key) && r.selection);
return !includeFlagsOnly || evaluateRules || ["ActiveEffectLike"].includes(r.key);
})
.map((r) => {
r.ignored = false;
Expand All @@ -2607,30 +2610,36 @@ export class Pathmuncher {
if (i.system.items) i.system.items = [];
if (i.system.rules) {
i.system.rules = i.system.rules
// eslint-disable-next-line complexity
.filter((r) => {
const allowedMiscKeys = ["RollOption", "ActiveEffectLike"].includes(r.key);
if (allowedMiscKeys) return true;
const isOtherDocument = otherDocs.some((d) => d._id === i._id);
const excludeAddedGrant = excludeAddedGrants && ["GrantItem"].includes(r.key) && this.grantItemLookUp.has(r.uuid);
const otherDocumentGrantRules = isOtherDocument && excludeAddedGrant;
if (otherDocumentGrantRules) return false;
if (isOtherDocument) return true;

const isPassedDocument = documents.some((d) => d._id === i._id);
const isChoiceSetSelection = ["ChoiceSet"].includes(r.key) && r.selection;
// const choiceSetSelectionNotObject = isChoiceSetSelection && !utils.isObject(r.selection);
const grantRuleWithoutFlag = includeGrants && ["GrantItem"].includes(r.key) && !r.flag;
// if (excludeAddedGrant && grantRuleWithoutFlag) return false;
const genericDiscardRule = ["ChoiceSet", "GrantItem"].includes(r.key);
const grantRuleFromItemFlag = ["GrantItem"].includes(r.key) && r.uuid.includes("{item|flags");
const includeGrantRuleFromItemFlag = includeGrants && grantRuleFromItemFlag;
const allowedMiscKeys = ["RollOption", "ActiveEffectLike"].includes(r.key);
const grantRuleFromItemFlag = includeGrants && ["GrantItem"].includes(r.key) && r.uuid.includes("{item|flags");

const notPassedDocumentRules
= !isPassedDocument
// && !excludeAddedGrant
&& (grantRuleWithoutFlag
// || choiceSetSelectionNotObject
|| !genericDiscardRule
|| includeGrantRuleFromItemFlag
|| allowedMiscKeys);
|| grantRuleFromItemFlag);

const passedDocumentRules
= isPassedDocument
&& includePassedDocumentsRules
&& (isChoiceSetSelection || grantRuleWithoutFlag || includeGrantRuleFromItemFlag || allowedMiscKeys);
// && !excludeAddedGrant
&& (isChoiceSetSelection || grantRuleWithoutFlag || grantRuleFromItemFlag);

return notPassedDocumentRules || passedDocumentRules;
})
Expand All @@ -2644,6 +2653,10 @@ export class Pathmuncher {
});
if (documents.some((d) => d._id === i._id) && processedRules.length > 0 && includeFlagsOnly) {
i.system.rules = foundry.utils.deepClone(processedRules).filter((r) => {
const excludeAddedGrant = excludeAddedGrants && ["GrantItem"].includes(r.key) && this.grantItemLookUp.has(r.uuid);
if (excludeAddedGrant) return false;
const noGrants = !includeGrants && !["GrantItem"].includes(r.key);
if (noGrants) return false;
const grantRuleFromItemFlag = ["GrantItem"].includes(r.key) && r.uuid.includes("{item|flags");
if (!grantRuleFromItemFlag) return true;
if (grantRuleFromItemFlag && r.alterations) return true;
Expand Down
6 changes: 4 additions & 2 deletions src/data/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const POSTFIX_PB_REMOVALS = [
/(.*) (Impulse Junction)$/,
/(.*) (Gate Junction:).*$/,
/(.*) (Patron)$/,
// /(Fork) the Path/,
// /(Expand) the Portal/,
];

const PREFIX_PB_REMOVALS = [
Expand All @@ -42,8 +44,8 @@ const PREFIX_PB_REMOVALS = [
];

const POSTFIX_PB_SPLIT_AND_KEEP = [
/(.*) (Impulse Junction)$/,
/(.*) Gate Junction: (.*)$/,
/(\w+) (Impulse) Junction/,
/(\w+) Gate Junction: (\w+) /,
];

const PARENTHESIS = [
Expand Down

0 comments on commit 7cde814

Please sign in to comment.