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

Check for time to Runes when computing Time to Power. #752

Merged
merged 6 commits into from
Dec 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions src/engine/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,8 @@ export interface AstActionNode
| "usable"
| "target"
| "offgcd"
| "extra_amount"
| "extra_energy"
| "extra_focus"
| "texture"
> {
name: ActionType;
Expand All @@ -875,7 +876,8 @@ const checkActionParameters: NamedParametersCheck<AstActionNode> = {
target: true,
usable: true,
offgcd: true,
extra_amount: true,
extra_energy: true,
extra_focus: true,
texture: true,
};

Expand Down
25 changes: 2 additions & 23 deletions src/engine/best-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ import {
setResultType,
} from "./ast";
import { OvaleCooldownClass } from "../states/Cooldown";
import { OvaleRunesClass } from "../states/Runes";
import { OvaleSpellsClass } from "../states/Spells";
import { isNumber, isString } from "../tools/tools";
import { OvaleClass } from "../Ovale";
import { AceModule } from "@wowts/tsaddon";
import { OvaleGUIDClass } from "./guid";
import { OvalePowerClass } from "../states/Power";
import { OvaleFutureClass } from "../states/Future";
import { OvaleSpellBookClass } from "../states/SpellBook";
import { Profiler, OvaleProfilerClass } from "./profiler";
Expand Down Expand Up @@ -58,13 +56,11 @@ export class OvaleBestActionClass {
private ovaleCooldown: OvaleCooldownClass,
Ovale: OvaleClass,
private OvaleGUID: OvaleGUIDClass,
private OvalePower: OvalePowerClass,
private OvaleFuture: OvaleFutureClass,
private OvaleSpellBook: OvaleSpellBookClass,
ovaleProfiler: OvaleProfilerClass,
ovaleDebug: OvaleDebugClass,
private variables: Variables,
private ovaleRunes: OvaleRunesClass,
private OvaleSpells: OvaleSpellsClass,
private runner: Runner
) {
Expand Down Expand Up @@ -292,37 +288,20 @@ export class OvaleBestActionClass {
result.actionTexture = `Interface\\Icons\\${si.texture}`;
}
if (result.actionCooldownStart && result.actionCooldownDuration) {
const extraPower =
<number>element.cachedParams.named.extra_amount || 0;
// let seconds = OvaleSpells.GetTimeToSpell(spellId, atTime, targetGUID, extraPower);
const timeToCd =
(result.actionCooldownDuration > 0 &&
result.actionCooldownStart +
result.actionCooldownDuration -
atTime) ||
0;
let timeToPower = this.OvalePower.TimeToPower(
const timeToPower = this.OvaleSpells.TimeToPowerForSpell(
spellId,
atTime,
targetGUID,
undefined,
extraPower
element.cachedParams.named
);
const runes = this.ovaleData.GetSpellInfoProperty(
spellId,
atTime,
"runes",
targetGUID
);
if (runes) {
const timeToRunes = this.ovaleRunes.GetRunesCooldown(
atTime,
<number>runes
);
if (timeToPower < timeToRunes) {
timeToPower = timeToRunes;
}
}
if (timeToPower > timeToCd) {
result.actionResourceExtend = timeToPower - timeToCd;
this.tracer.Log(
Expand Down
5 changes: 2 additions & 3 deletions src/ioc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ export class IoC {
this.debug,
this.profiler,
this.data,
this.power
this.power,
this.runes,
);
this.bestAction = new OvaleBestActionClass(
this.equipment,
Expand All @@ -351,13 +352,11 @@ export class IoC {
this.cooldown,
this.ovale,
this.guid,
this.power,
this.future,
this.spellBook,
this.profiler,
this.debug,
this.variables,
this.runes,
this.spells,
runner
);
Expand Down
127 changes: 22 additions & 105 deletions src/states/Power.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,23 +465,6 @@ export class OvalePowerClass extends States<PowerState> implements StateModule {
}
};

TimeToPower(
spellId: number,
atTime: number,
targetGUID: string | undefined,
powerType: PowerType | undefined,
extraPower?: number
) {
return this.getTimeToPowerStateAt(
this.GetState(atTime),
spellId,
atTime,
targetGUID,
powerType,
extraPower
);
}

InitializeState() {
for (const [powerType] of kpairs(this.POWER_INFO)) {
this.next.power[powerType] = 0;
Expand Down Expand Up @@ -587,7 +570,7 @@ export class OvalePowerClass extends States<PowerState> implements StateModule {
spellId: number,
powerType: PowerType,
atTime: number,
targetGUID: string,
targetGUID: string | undefined,
maximumCost?: boolean
) {
return this.getPowerCostAt(
Expand Down Expand Up @@ -624,6 +607,7 @@ export class OvalePowerClass extends States<PowerState> implements StateModule {
}
return rate;
}

/**
* Power atTime for the given powerType.
* @param powerType
Expand All @@ -642,19 +626,27 @@ export class OvalePowerClass extends States<PowerState> implements StateModule {
return power;
}

hasPowerFor(
spellId: number,
/**
* Number of seconds until powrLevel is reached atTime for the powerType.
* @param powerLevel
* @param powerType
* @param atTime
*/
getTimeToPowerAt(
state: PowerState,
powerLevel: number,
powerType: PowerType,
atTime: number,
targetGUID?: string
): boolean {
const seconds = this.getTimeToPowerStateAt(
this.GetState(atTime),
spellId,
atTime,
targetGUID,
undefined
);
return (seconds === 0);
): number {
let seconds = INFINITY;
const power = this.getPowerAt(state, powerType, atTime)
if (power < powerLevel) {
const powerRate = this.getPowerRateAt(state, powerType, atTime);
if (powerRate > 0) {
seconds = (powerLevel - power) / powerRate;
}
}
return seconds;
}

/**
Expand Down Expand Up @@ -734,79 +726,4 @@ export class OvalePowerClass extends States<PowerState> implements StateModule {
this.profiler.StopProfiling("OvalePower_PowerCost");
return [spellCost, spellRefund];
}

/**
* How many seconds until there is enough power to use the ability.
* @param spellId
* @param atTime
* @param targetGUID
* @param powerType
* @param extraPower If true, will add this to the cost
*/
private getTimeToPowerStateAt(
state: PowerState,
spellId: number,
atTime: number,
targetGUID: string | undefined,
powerType: PowerType | undefined,
extraPower?: number
): number {
let timeToPower = 0;
const si = this.ovaleData.spellInfo[spellId];
if (si) {
for (const [, powerInfo] of kpairs(this.POWER_INFO)) {
const pType = powerInfo.type;
if (powerType === undefined || powerType == pType) {
let [cost] = this.getPowerCostAt(
state,
spellId,
pType,
atTime,
targetGUID
);
if (cost > 0) {
this.tracer.Log(" Spell ID '%d' has cost of %d %s",
spellId,
cost,
pType
);
if (powerType == pType && extraPower) {
this.tracer.Log(
" Including extra power %d for %s",
extraPower,
pType
);
cost = cost + extraPower;
}
const power = this.getPowerAt(state, pType, atTime);
if (power < cost) {
const powerRate =
this.getPowerRateAt(state, pType, atTime);
if (powerRate > 0) {
const seconds = (cost - power) / powerRate;
this.tracer.Log(
" Requires %f seconds to %d %s",
seconds,
cost,
pType
);
if (timeToPower < seconds) {
timeToPower = seconds;
}
} else {
timeToPower = INFINITY;
break;
}
}
}
}
}
}
this.tracer.Log(
"Spell ID '%d' requires %f seconds for power requirements.",
spellId,
timeToPower
);
return timeToPower;
}
}
Loading