Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for COF and COC systems #97

Merged
merged 5 commits into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add capacities and consumable spells
  • Loading branch information
Qaw committed Oct 6, 2021
commit 1fcb12b481187412978be7ad3dda8618ceebe8df
3 changes: 2 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,5 +344,6 @@

"tokenactionhud.co.combat": "Combat",
"tokenactionhud.co.attacks": "Attacks",
"tokenactionhud.co.protections": "Protections"
"tokenactionhud.co.protections": "Protections",
"tokenactionhud.co.capacities": "Capacities"
}
3 changes: 2 additions & 1 deletion lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,5 +344,6 @@

"tokenactionhud.co.combat": "Combat",
"tokenactionhud.co.attacks": "Attaques",
"tokenactionhud.co.protections": "Protections"
"tokenactionhud.co.protections": "Protections",
"tokenactionhud.co.capacities": "Capacités"
}
40 changes: 37 additions & 3 deletions scripts/actions/co/co-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ export class ActionHandlerCo extends ActionHandler {
let characteristics = this._getCharacteristics(actor, tokenId);
let combat = this._getCombat(actor,tokenId);
let items = this._getItemsList(actor, tokenId);
let capacities = this._getCapacities(actor, tokenId);

this._combineCategoryWithList(result, this.i18n("tokenactionhud.characteristics"), characteristics);
this._combineCategoryWithList(result, this.i18n("tokenactionhud.co.combat"), combat);
this._combineCategoryWithList(result, this.i18n("tokenactionhud.inventory"), items);
this._combineCategoryWithList(result, this.i18n("tokenactionhud.co.capacities"), capacities);

if (settings.get("showHudTitle")) result.hudTitle = token.data?.name;

Expand Down Expand Up @@ -92,7 +94,7 @@ export class ActionHandlerCo extends ActionHandler {
// Spells
let spellsCategory = this.initializeEmptySubcategory();

let spells = actor.items.filter(item => item.data.type === "item" && item.data.data.subtype === "spell" && item.data.data.properties.weapon);
let spells = actor.items.filter(item => item.data.type === "item" && item.data.data.subtype === "spell" && (item.data.data.properties.weapon || item.data.data.properties.activable));

spellsCategory.actions = spells.map((w) =>
this._buildEquipmentItem(tokenId, actor, "spell", w)
Expand Down Expand Up @@ -128,7 +130,7 @@ export class ActionHandlerCo extends ActionHandler {
this._combineSubcategoryWithCategory(result, this.i18n("tokenactionhud.co.protections"), protectionsCat);

// Consumables
let consumables = actor.items.filter((item) => item.data?.type === "item" && item.data.data.properties.consumable);
let consumables = actor.items.filter((item) => item.data?.type === "item" && item.data.data.subtype !== "spell" && item.data.data.properties.consumable && item.data.data.qty > 0);

let consumablesActions = consumables.map((p) =>
this._buildEquipmentItem(tokenId, actor, "item", p)
Expand All @@ -138,8 +140,19 @@ export class ActionHandlerCo extends ActionHandler {

this._combineSubcategoryWithCategory(result, this.i18n("tokenactionhud.consumables"), consumablesCat);

// Spells
let spells = actor.items.filter((item) => item.data?.type === "item" && item.data.data.subtype === "spell");

let spellsActions = spells.map((s) =>
this._buildEquipmentItem(tokenId, actor, "item", s)
);
let spellsCat = this.initializeEmptySubcategory();
spellsCat.actions = spellsActions;

this._combineSubcategoryWithCategory(result, this.i18n("tokenactionhud.spells"), spellsCat);

// Other equipment
let others = actor.items.filter((item) => item.data?.type === "item" && (item.data.data.subtype !== "armor" && item.data.data.subtype !== "shield" && item.data.data.subtype !== "melee" && item.data.data.subtype !== "ranged" && !item.data.data.properties.consumable));
let others = actor.items.filter((item) => item.data?.type === "item" && (item.data.data.subtype !== "armor" && item.data.data.subtype !== "shield" && item.data.data.subtype !== "melee" && item.data.data.subtype !== "ranged" && item.data.data.subtype !== "spell" && !item.data.data.properties.consumable));
let othersActions = others.map((i) =>
this._buildEquipmentItem(tokenId, actor, "item", i)
);
Expand All @@ -151,6 +164,22 @@ export class ActionHandlerCo extends ActionHandler {
return result;
}

/** @private */
_getCapacities(actor, tokenId) {
let result = this.initializeEmptyCategory("capacities");

// Capacities
let capacities = actor.items.filter(item => item.data?.type === "capacity");
let capacitiesActions = capacities.map((w) =>
this._buildItem(tokenId, actor, "capacity", w)
);
let capacitiesCat = this.initializeEmptySubcategory();
capacitiesCat.actions = capacitiesActions;

this._combineSubcategoryWithCategory(result, this.i18n("tokenactionhud.co.capacities"), capacitiesCat);
return result;
}

/** @private */
_buildEquipmentItem(tokenId, actor, macroType, item) {
let action = this._buildItem(tokenId, actor, macroType, item);
Expand Down Expand Up @@ -213,4 +242,9 @@ export class ActionHandlerCo extends ActionHandler {
return result;
}

/** @private */
_buildCapacityItem(tokenId, actor, macroType, item) {
let action = this._buildItem(tokenId, actor, macroType, item);
return action;
}
}
23 changes: 20 additions & 3 deletions scripts/rollHandlers/co/co-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export class RollHandlerBaseCo extends RollHandler {
if (this.isRenderItem()) this.doRenderItem(tokenId, itemId);
else this._handleItem(macroType, event, actor, itemId);
break;
case "capacity":
this.doRenderItem(tokenId, itemId);
break;
}
}

Expand All @@ -47,19 +50,33 @@ export class RollHandlerBaseCo extends RollHandler {

_handleWeapon(macroType, event, actor, actionId) {
let item = actor.items.get(actionId);
actor.rollWeapon(item);
// Only Dommage
if (this.isShift(event)) {
actor.rollWeapon(item, {dmgOnly: true})
}
else actor.rollWeapon(item);
}

_handleSpell(macroType, event, actor, actionId) {
let item = actor.items.get(actionId);
// TODO

// Consumable spell
if (item.data.data.properties.consumable) actor.consumeItem(item);
else {
// Only Dommage
if (this.isShift(event)) {
actor.rollWeapon(item, {dmgOnly: true})
}
else actor.rollWeapon(item);
}

}

_handleItem(macroType, event, actor, actionId) {
let item = actor.items.get(actionId);

// Equipable item
if (item.data.data.properties.equipable) actor.toggleEquipItem(item, false);
if (item.data.data.properties.equipable) actor.toggleEquipItem(item, this.isShift(event));

// Consumable item
if (item.data.data.properties.consumable) actor.consumeItem(item);
Expand Down