Skip to content

Commit

Permalink
- apply changes to player mechs
Browse files Browse the repository at this point in the history
  • Loading branch information
ScyllPoesis committed May 6, 2021
1 parent 9a1ff5e commit 69bad8b
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 102 deletions.
95 changes: 44 additions & 51 deletions scripts/actions/lancer/lancer-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export class ActionHandlerLancer extends ActionHandler {

switch (actor.data.type) {
case "pilot":
this._combineCategoryWithList(result, this.i18n("tokenactionhud.pilot"), this._pilotCategory(actor, tokenId));
// TODO: figure out new pilot data and owned item paths.
break;
case "mech":
this._combineCategoryWithList(result, this.i18n("tokenactionhud.mech"), this._mechCategory(actor, tokenId));
this._combineCategoryWithList(
result,
Expand Down Expand Up @@ -60,6 +62,7 @@ export class ActionHandlerLancer extends ActionHandler {
if (option) {
option.max && (action.name += ` [${option.uses}/${option.max}]`);
option.charged && (action.icon = `<i class="mdi mdi-flash"></i>`);
option.loading && (action.icon = `<i class="mdi mdi-ammunition"></i>`);
}

action.encodedValue = [macroType, tokenId, actionId, JSON.stringify(option ? option : {})].join(this.delimiter);
Expand All @@ -76,27 +79,7 @@ export class ActionHandlerLancer extends ActionHandler {
return item.type === itemType;
})
.map((item) => {
let isCharged = false;
let currentUses = 0;
let maxUses = 0;

let chargeTag = item.data.tags.find((tag) => tag.tag.fallback_lid === "tg_recharge");
if (chargeTag) {
isCharged = true;
currentUses = item.data.charged ? 1 : 0;
maxUses = 1;
}
let limitedTag = item.data.tags.find((tag) => tag.tag.fallback_lid === "tg_limited");
if (limitedTag) {
currentUses = item.data.uses;
maxUses = limitedTag.val;
}

return this._makeAction(item.name, macro, tokenId, item._id, {
uses: currentUses,
max: maxUses,
charged: isCharged,
});
return this._makeAction(item.name, macro, tokenId, item._id, this._getUseData(item));
});

return result;
Expand All @@ -115,27 +98,7 @@ export class ActionHandlerLancer extends ActionHandler {
return item.data.type === itemType;
})
.map((item) => {
let isCharged = false;
let currentUses = 0;
let maxUses = 0;

let chargeTag = item.data.tags.find((tag) => tag.tag.fallback_lid === "tg_recharge");
if (chargeTag) {
isCharged = true;
currentUses = item.data.charged ? 1 : 0;
maxUses = 1;
}
let limitedTag = item.data.tags.find((tag) => tag.tag.fallback_lid === "tg_limited");
if (limitedTag) {
currentUses = item.data.uses;
maxUses = limitedTag.val;
}

return this._makeAction(item.name, macro, tokenId, item._id, {
uses: currentUses,
max: maxUses,
charged: isCharged,
});
return this._makeAction(item.name, macro, tokenId, item._id, this._getUseData(item));
});

return result;
Expand Down Expand Up @@ -279,10 +242,10 @@ export class ActionHandlerLancer extends ActionHandler {
let engineering = this.i18n("tokenactionhud.engineering");

let haseActionData = [
{ name: hull, id: "hull" },
{ name: agility, id: "agility" },
{ name: systems, id: "systems" },
{ name: engineering, id: "engineering" },
{ name: hull, id: "mm.ent.Hull" },
{ name: agility, id: "mm.ent.Agility" },
{ name: systems, id: "mm.ent.Systems" },
{ name: engineering, id: "mm.ent.Engineering" },
];

let haseActions = haseActionData.map((actionData) => {
Expand All @@ -301,12 +264,12 @@ export class ActionHandlerLancer extends ActionHandler {
result.id = "stat";
result.name = this.i18n("tokenactionhud.stat");

let grit = this.i18n("tokenactionhud.grit");
// let grit = this.i18n("tokenactionhud.grit");
let techAttack = this.i18n("tokenactionhud.techattack");

let statActionData = [
{ name: grit, data: "pilot.grit" },
{ name: techAttack, data: "mech.tech_attack" },
// { name: grit, data: "pilot.grit" },
{ name: techAttack, data: "mm.ent.TechAttack" },
];

let statActions = statActionData.map((actionData) => {
Expand Down Expand Up @@ -357,7 +320,17 @@ export class ActionHandlerLancer extends ActionHandler {
let subcat = this.initializeEmptySubcategory(weapon.id);
subcat.name = weapon.name;

let attack = this._makeAction(this.i18n("tokenactionhud.attack"), macro, tokenId, weapon._id);
let loadingTag = weapon.data.profiles[weapon.data.selected_profile].tags.find(
(tag) => tag.tag.fallback_lid === "tg_loading"
);
let loadData = {};
if (loadingTag) {
loadData.uses = weapon.data.loaded ? 1 : 0;
loadData.max = 1;
loadData.loading = true;
}

let attack = this._makeAction(this.i18n("tokenactionhud.attack"), macro, tokenId, weapon._id, loadData);

subcat.actions = [attack];

Expand Down Expand Up @@ -399,4 +372,24 @@ export class ActionHandlerLancer extends ActionHandler {

return result;
}

_getUseData(item) {
let isCharged = false;
let currentUses = 0;
let maxUses = 0;

let chargeTag = item.data.tags.find((tag) => tag.tag.fallback_lid === "tg_recharge");
if (chargeTag) {
isCharged = true;
currentUses = item.data.charged ? 1 : 0;
maxUses = 1;
}
let limitedTag = item.data.tags.find((tag) => tag.tag.fallback_lid === "tg_limited");
if (limitedTag) {
currentUses = item.data.uses;
maxUses = limitedTag.val;
}

return { uses: currentUses, max: maxUses, charged: isCharged };
}
}
101 changes: 50 additions & 51 deletions scripts/rollHandlers/lancer/lancer-base.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,64 @@
import { RollHandler } from "../rollHandler.js";

export class RollHandlerBaseLancer extends RollHandler {
constructor() {
super();
constructor() {
super();
}

/** @override */
doHandleActionEvent(event, encodedValue) {
let payload = encodedValue.split("|");

if (payload.length != 3 && payload.length != 4) {
super.throwInvalidValueErr();
}

/** @override */
doHandleActionEvent(event, encodedValue) {
let payload = encodedValue.split('|');

if (payload.length != 3 && payload.length != 4) {
super.throwInvalidValueErr();
}

let macroType = payload[0];
let tokenId = payload[1];
let actionId = payload[2];
let option = JSON.parse(payload[3]);
let macroType = payload[0];
let tokenId = payload[1];
let actionId = payload[2];
let option = JSON.parse(payload[3]);

let actor = super.getActor(tokenId);
let actor = super.getActor(tokenId);

let hasSheet = ['item']
if (this.isRenderItem() && hasSheet.includes(macroType))
return this.doRenderItem(tokenId, actionId);
let hasSheet = ["item"];
if (this.isRenderItem() && hasSheet.includes(macroType)) return this.doRenderItem(tokenId, actionId);

switch (macroType) {
case "hase":
this._rollHaseMacro(actor, actionId);
break;
case "stat":
this._rollStatMacro(actor, actionId);
break;
case "item":
this._rollWeaponOrFeatureMacro(actor, actionId, option);
break;
case "coreActive":
this._rollCoreActiveMacro(actor);
break;
case "corePassive":
this._rollCorePassiveMacro(actor);
break;
}
switch (macroType) {
case "hase":
this._rollHaseMacro(actor, actionId);
break;
case "stat":
this._rollStatMacro(actor, actionId);
break;
case "item":
this._rollWeaponOrFeatureMacro(actor, actionId, option);
break;
case "coreActive":
this._rollCoreActiveMacro(actor);
break;
case "corePassive":
this._rollCorePassiveMacro(actor);
break;
}
}

_rollHaseMacro(actor, action) {
game.lancer.prepareStatMacro(actor._id, `data.mech.${action}`);
}
_rollHaseMacro(actor, action) {
game.lancer.prepareStatMacro(actor._id, `${action}`);
}

_rollStatMacro(actor, action) {
game.lancer.prepareStatMacro(actor._id, `data.${action}`);
}
_rollStatMacro(actor, action) {
game.lancer.prepareStatMacro(actor._id, `${action}`);
}

_rollWeaponOrFeatureMacro(actor, itemId, option) {
game.lancer.prepareItemMacro(actor._id, itemId, option);
}
_rollWeaponOrFeatureMacro(actor, itemId, option) {
game.lancer.prepareItemMacro(actor._id, itemId, option);
}

_rollCoreActiveMacro(actor) {
game.lancer.prepareCoreActiveMacro(actor._id);
}
_rollCoreActiveMacro(actor) {
game.lancer.prepareCoreActiveMacro(actor._id);
}

_rollCorePassiveMacro(actor) {
game.lancer.prepareCorePassiveMacro(actor._id);
}
}
_rollCorePassiveMacro(actor) {
game.lancer.prepareCorePassiveMacro(actor._id);
}
}

0 comments on commit 69bad8b

Please sign in to comment.