Skip to content

Commit

Permalink
fix(runeforge): ovale should check for bonus id instead of power id (#…
Browse files Browse the repository at this point in the history
…838)

fixes #805
  • Loading branch information
Hemario committed Mar 9, 2021
1 parent eaf9cf2 commit 968078a
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/ioc.ts
Expand Up @@ -424,7 +424,7 @@ export class IoC {
);
this.recount = new OvaleRecountClass(this.ovale, this.score);
const covenant = new Covenant(this.ovale, this.debug);
const runeforge = new Runeforge(this.debug);
const runeforge = new Runeforge(this.ovale, this.debug);
const conduit = new Conduit(this.debug);
this.conditions = new OvaleConditions(
this.condition,
Expand Down
99 changes: 87 additions & 12 deletions src/states/runeforge.ts
@@ -1,6 +1,12 @@
import { ipairs, LuaArray, tonumber, unpack } from "@wowts/lua";
import { pairs, ipairs, LuaArray, tonumber, unpack } from "@wowts/lua";
import { concat, insert } from "@wowts/table";
import { C_LegendaryCrafting, RuneforgePowerState } from "@wowts/wow-mock";
import {
C_LegendaryCrafting,
GetInventoryItemQuality,
GetInventoryItemLink,
INVSLOT_FIRST_EQUIPPED,
INVSLOT_LAST_EQUIPPED,
} from "@wowts/wow-mock";
import { OptionUiGroup } from "../ui/acegui-helpers";
import {
ConditionFunction,
Expand All @@ -9,9 +15,16 @@ import {
} 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 { match } from "@wowts/string";

export class Runeforge {
private debugOptions: OptionUiGroup = {
private module: AceModule & AceEvent;
private equippedLegendaryById: LuaArray<number> = {};

private debugRuneforges: OptionUiGroup = {
type: "group",
name: "Runeforges",
args: {
Expand Down Expand Up @@ -39,10 +52,73 @@ export class Runeforge {
},
};

constructor(debug: DebugTools) {
debug.defaultOptions.args["runeforge"] = this.debugOptions;
private debugLegendaries: OptionUiGroup = {
type: "group",
name: "Legendaries",
args: {
legendaries: {
type: "input",
name: "Legendaries",
multiline: 25,
width: "full",
get: () => {
const output: LuaArray<string> = {};
for (const [id, v] of pairs(this.equippedLegendaryById)) {
insert(output, `${id}: ${v}`);
}
return concat(output, "\n");
},
},
},
};

constructor(ovale: OvaleClass, debug: DebugTools) {
debug.defaultOptions.args["runeforge"] = this.debugRuneforges;
debug.defaultOptions.args["legendaries"] = this.debugLegendaries;

this.module = ovale.createModule(
"OvaleRuneforge",
this.handleInitialize,
this.handleDisable,
aceEvent
);
}

private handleInitialize = () => {
this.module.RegisterMessage(
"Ovale_EquipmentChanged",
this.updateEquippedItems
);
};
private handleDisable = () => {
this.module.UnregisterMessage("Ovale_EquipmentChanged");
};
private updateEquippedItems = () => {
this.equippedLegendaryById = {};
// we need to scan for legendaries now
for (
let slotId = INVSLOT_FIRST_EQUIPPED;
slotId <= INVSLOT_LAST_EQUIPPED;
slotId += 1
) {
if (GetInventoryItemQuality("player", slotId) == 5) {
const [newItemLink] = match(
GetInventoryItemLink("player", slotId),
"item:([%-?%d:]+)"
);
if (newItemLink) {
const [newLegendaryId] = match(
newItemLink,
"%d*:%d*:%d*:%d*:%d*:%d*:%d*:%d*:%d*:%d*:%d*:%d*:%d*:(%d*):"
);
this.equippedLegendaryById[
tonumber(newLegendaryId)
] = tonumber(slotId);
}
}
}
};

registerConditions(condition: OvaleConditionClass) {
condition.registerCondition(
"equippedruneforge",
Expand All @@ -53,16 +129,15 @@ export class Runeforge {
}

private equippedRuneforge: ConditionFunction = (positionalParameters) => {
const [powerId] = unpack(positionalParameters);
if (!isNumber(powerId)) {
oneTimeMessage(`${powerId} is not defined in EquippedRuneforge`);
const [bonusItemId] = unpack(positionalParameters);
if (!isNumber(bonusItemId)) {
oneTimeMessage(
`${bonusItemId} is not defined in EquippedRuneforge`
);
return [];
}
const runeforgePower = C_LegendaryCrafting.GetRuneforgePowerInfo(
tonumber(powerId)
);
return returnBoolean(
runeforgePower.state === RuneforgePowerState.Available
this.equippedLegendaryById[bonusItemId] !== undefined
);
};
}

0 comments on commit 968078a

Please sign in to comment.