Skip to content

Commit

Permalink
feat(runeforge): allow using runeforge power IDs in scripts (#920)
Browse files Browse the repository at this point in the history
* fix(runeforge): sort imports

* feat(runeforge): allow using runeforge power IDs in conditions
  • Loading branch information
johnnylam88 committed Jul 8, 2021
1 parent 0196a8a commit 4cbed9a
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions src/states/runeforge.ts
@@ -1,30 +1,31 @@
import aceEvent, { AceEvent } from "@wowts/ace_event-3.0";
import {
LuaArray,
ipairs,
kpairs,
lualength,
pairs,
tonumber,
unpack,
wipe,
} from "@wowts/lua";
import { concat, insert } from "@wowts/table";
import { AceModule } from "@wowts/tsaddon";
import { C_LegendaryCrafting, Enum } from "@wowts/wow-mock";
import { OptionUiGroup } from "../ui/acegui-helpers";
import { OvaleClass } from "../Ovale";
import {
ConditionFunction,
OvaleConditionClass,
returnBoolean,
} from "../engine/condition";
import { DebugTools } from "../engine/debug";
import { isNumber, oneTimeMessage } from "../tools/tools";
import { OvaleClass } from "../Ovale";
import { AceModule } from "@wowts/tsaddon";
import aceEvent, { AceEvent } from "@wowts/ace_event-3.0";
import { OptionUiGroup } from "../ui/acegui-helpers";
import { OvaleEquipmentClass, inventorySlotNames } from "./Equipment";

export class Runeforge {
private module: AceModule & AceEvent;
private equippedLegendaryById: LuaArray<boolean> = {};
private equippedRuneforgeById: LuaArray<boolean> = {};

private debugRuneforges: OptionUiGroup = {
type: "group",
Expand All @@ -39,13 +40,18 @@ export class Runeforge {
const ids =
C_LegendaryCrafting.GetRuneforgePowers(undefined);
const output: LuaArray<string> = {};
for (const [, v] of ipairs(ids)) {
for (const [, id] of ipairs(ids)) {
const runeforgePower =
C_LegendaryCrafting.GetRuneforgePowerInfo(v);
if (runeforgePower) {
insert(output, `${v}: ${runeforgePower.name}`);
C_LegendaryCrafting.GetRuneforgePowerInfo(id);
if (runeforgePower != undefined) {
insert(output, `${id}: ${runeforgePower.name}`);
}
}
insert(output, "");
insert(output, "Equipped:");
for (const [id] of kpairs(this.equippedRuneforgeById)) {
insert(output, ` ${id}`);
}
return concat(output, "\n");
},
},
Expand All @@ -64,7 +70,7 @@ export class Runeforge {
get: () => {
const output: LuaArray<string> = {};
insert(output, "Legendary bonus IDs:");
for (const [id] of pairs(this.equippedLegendaryById)) {
for (const [id] of kpairs(this.equippedLegendaryById)) {
insert(output, ` ${id}`);
}
return concat(output, "\n");
Expand Down Expand Up @@ -102,6 +108,7 @@ export class Runeforge {

private handleOvaleEquipmentChanged = (event: string) => {
wipe(this.equippedLegendaryById);
wipe(this.equippedRuneforgeById);
for (const [slot] of kpairs(inventorySlotNames)) {
// Update bonus IDs list in equippedLegendaryById.
const quality = this.equipment.getEquippedItemQuality(slot);
Expand All @@ -113,6 +120,18 @@ export class Runeforge {
this.equippedLegendaryById[id] = true;
}
}
// Update power IDs list in equippedRuneforgeById.
const location = this.equipment.getEquippedItemLocation(slot);
if (location != undefined) {
if (C_LegendaryCrafting.IsRuneforgeLegendary(location)) {
const componentInfo =
C_LegendaryCrafting.GetRuneforgeLegendaryComponentInfo(
location
);
const id = tonumber(componentInfo.powerID);
this.equippedRuneforgeById[id] = true;
}
}
}
};

Expand All @@ -131,6 +150,11 @@ export class Runeforge {
oneTimeMessage(`${id} is not defined in EquippedRuneforge`);
return [];
}
return returnBoolean(this.equippedLegendaryById[id]);
/* Check both lists and return true if the ID is in either of them.
* Technically could be incorrect, but chance of collision is very low.
*/
return returnBoolean(
this.equippedLegendaryById[id] || this.equippedRuneforgeById[id]
);
};
}

0 comments on commit 4cbed9a

Please sign in to comment.