Skip to content

Commit

Permalink
fix: spells always usable when spellactivation is active (#865)
Browse files Browse the repository at this point in the history
* chore(spellactivation): first iteration of spell activation glow tracking

* chore(spellactivation): rename module name
  • Loading branch information
Hemario committed Apr 18, 2021
1 parent 1c4d158 commit bb1be9c
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/ioc.ts
Expand Up @@ -57,6 +57,7 @@ import { Runeforge } from "./states/runeforge";
import { Conduit } from "./states/conduit";
import { Runner } from "./engine/runner";
import { Controls } from "./engine/controls";
import { SpellActivationGlow } from "./states/spellactivationglow";

/** Used to emulate IoC for integration tests */
export class IoC {
Expand Down Expand Up @@ -114,6 +115,7 @@ export class IoC {
public version: OvaleVersionClass;
public warlock: OvaleWarlockClass;
public runner: Runner;
public spellActivationGlow: SpellActivationGlow;

constructor() {
// TODO créer configuration avec la partie GUI et rajouter une méthode register à appeler ici comme pour les states
Expand Down Expand Up @@ -337,14 +339,19 @@ export class IoC {
this.power,
this.paperDoll
);
this.spellActivationGlow = new SpellActivationGlow(
this.ovale,
this.debug
);
this.spells = new OvaleSpellsClass(
this.spellBook,
this.ovale,
this.debug,
this.profiler,
this.data,
this.power,
this.runes
this.runes,
this.spellActivationGlow
);
this.bestAction = new OvaleBestActionClass(
this.equipment,
Expand Down Expand Up @@ -487,5 +494,6 @@ export class IoC {
this.azeriteArmor.registerConditions(this.condition);
this.stagger.registerConditions(this.condition);
this.stance.registerConditions(this.condition);
this.spellActivationGlow.registerConditions(this.condition);
}
}
1 change: 1 addition & 0 deletions src/scripts/ovale_paladin_spells.ts
Expand Up @@ -241,6 +241,7 @@ Define(divine_shield 642)
SpellRequire(divine_shield unusable set=1 enabled=(debuffpresent(forbearance_debuff)))
Define(forbearance_debuff 25771)
SpellInfo(forbearance_debuff duration=30)
#hammer_of_wrath
SpellRequire(hammer_of_wrath unusable set=1 enabled=(target.healthpercent() > 20 and (level()<58 or not buffpresent(avenging_wrath))))
Define(lay_on_hands 633)
SpellInfo(lay_on_hands cd=600)
Expand Down
15 changes: 14 additions & 1 deletion src/states/Spells.ts
Expand Up @@ -20,6 +20,7 @@ import { StateModule } from "../engine/state";
import { NamedParametersOf, AstActionNode } from "../engine/ast";
import { OvalePowerClass, PowerType } from "./Power";
import { OvaleRunesClass } from "./Runes";
import { SpellActivationGlow } from "./spellactivationglow";

const warriorInterceptSpellId = SpellId.intercept;
const warriorHeroicThrowSpellId = SpellId.heroic_throw;
Expand All @@ -36,7 +37,8 @@ export class OvaleSpellsClass implements StateModule {
ovaleProfiler: OvaleProfilerClass,
private ovaleData: OvaleDataClass,
private power: OvalePowerClass,
private runes: OvaleRunesClass
private runes: OvaleRunesClass,
private spellActivationGlow: SpellActivationGlow
) {
this.module = ovale.createModule(
"OvaleSpells",
Expand Down Expand Up @@ -186,6 +188,17 @@ export class OvaleSpellsClass implements StateModule {
[isUsable, noMana] = [true, false];
}
}
// if we have a spell activation glow we force the spell as being usable anyway.
if (
!isUsable &&
this.spellActivationGlow.hasSpellActivationGlow(spellId)
) {
this.tracer.log(
"Spell ID '%s' has spell activation glow. Force it as usable.",
spellId
);
isUsable = true;
}
} else {
[isUsable, noMana] = IsUsableSpell(spellId);
}
Expand Down
85 changes: 85 additions & 0 deletions src/states/spellactivationglow.ts
@@ -0,0 +1,85 @@
import { AceModule } from "@wowts/tsaddon";
import aceEvent, { AceEvent } from "@wowts/ace_event-3.0";
import { DebugTools, Tracer } from "../engine/debug";
import { OvaleClass } from "../Ovale";
import { LuaArray } from "@wowts/lua";
import {
ConditionFunction,
OvaleConditionClass,
returnBoolean,
} from "../engine/condition";
import { AstFunctionNode, NamedParametersOf } from "../engine/ast";
import { GetSpellInfo } from "@wowts/wow-mock";

export class SpellActivationGlow {
private module: AceModule & AceEvent;
private debug: Tracer;
private spellActivationSpellsShown: LuaArray<boolean> = {};

constructor(ovale: OvaleClass, ovaleDebug: DebugTools) {
this.module = ovale.createModule(
"SpellActivationGlow",
this.handleInitialize,
this.handleDisable,
aceEvent
);
this.debug = ovaleDebug.create("SpellActivationGlow");
}

private handleInitialize = () => {
this.module.RegisterEvent(
"SPELL_ACTIVATION_OVERLAY_GLOW_SHOW",
this.handleSpellActivationOverlayGlow
);
this.module.RegisterEvent(
"SPELL_ACTIVATION_OVERLAY_GLOW_HIDE",
this.handleSpellActivationOverlayGlow
);
};

private handleDisable = () => {
this.module.UnregisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_SHOW");
this.module.UnregisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_HIDE");
};

private handleSpellActivationOverlayGlow = (
event: string,
spellId: number
) => {
const spellName = GetSpellInfo(spellId);
this.debug.debug(
"Event %s with spellId %d (%s)",
event,
spellId,
spellName
);
this.spellActivationSpellsShown[spellId] =
event == "SPELL_ACTIVATION_OVERLAY_GLOW_SHOW" || false;
};

hasSpellActivationGlow(spellId: number) {
return this.spellActivationSpellsShown[spellId] || false;
}

public registerConditions(ovaleCondition: OvaleConditionClass) {
ovaleCondition.registerCondition(
"spellactivationglowactive",
false,
this.spellActivationGlowActive
);
ovaleCondition.registerAlias(
"spellactivationglowactive",
"spellactivationglowshown"
);
}

private spellActivationGlowActive: ConditionFunction = (
positionalParams: LuaArray<any>,
namedParams: NamedParametersOf<AstFunctionNode>,
atTime: number
) => {
const spellId = positionalParams[1];
const retValue = this.hasSpellActivationGlow(spellId) || false;
return returnBoolean(retValue);
};
}

0 comments on commit bb1be9c

Please sign in to comment.