Skip to content

Commit

Permalink
fix(power): fix semantics of {max,set,refund}_XXX in SpellInfo() (#835)
Browse files Browse the repository at this point in the history
When `set_<powerType>` is given in SpellInfo(), use that as the
value to which the power should be set after the spell is
successfully cast.  Ensure that the cost of the spell given by
`<powerType>` is met even if `set_<powerType>` is given.

If `max_<powerType>` is given in SpellInfo(), use that as the max
cost of the spell.  Use `getProperty()` instead of directly
accessing the value so that any spell requirements are handled at
runtime.  Note that power cost from `set_<powerType>` has
precedence over the cost from `max_<powerType>`.

Lastly, always evaluate `refund_<powerType>` to determine the
amount of power refunded after the spell is successfully cast.

With this change, a combo-point finisher spell can be defined in
two different ways:
    SpellInfo(finisher combopoints=1 set_combopoints=0)
or
    SpellInfo(finisher combopoints=1 max_combopoints=5)
  • Loading branch information
johnnylam88 committed Feb 4, 2021
1 parent 2ea9e4e commit eaf9cf2
Showing 1 changed file with 37 additions and 31 deletions.
68 changes: 37 additions & 31 deletions src/states/Power.ts
Expand Up @@ -693,52 +693,58 @@ export class OvalePowerClass extends States<PowerState> implements StateModule {
let spellRefund = 0;
const si = this.ovaleData.spellInfo[spellId];
if (si && si[powerType]) {
const setPowerValue = this.ovaleData.getSpellInfoProperty(
spellId,
atTime,
`set_${powerType}` as `set_${PowerType}`,
targetGUID
);
if (setPowerValue !== undefined) {
const power = this.getPowerAt(state, powerType, atTime);
return [power - setPowerValue, 0];
}

let [cost, ratio] = this.ovaleData.getSpellInfoPropertyNumber(
spellId,
atTime,
powerType,
targetGUID,
true
);
if (ratio && ratio != 0) {
const maxCostParam = `max_${powerType}` as `max_${PowerType}`;
const maxCost = si[maxCostParam];
if (maxCost) {
const setPowerValue = this.ovaleData.getProperty(
si,
atTime,
`set_${powerType}` as `set_${PowerType}`
);
if (isNumber(setPowerValue)) {
const power = this.getPowerAt(state, powerType, atTime);
spellCost = power - setPowerValue;
if (spellCost < cost) {
spellCost = cost;
}
} else {
const maxCost = this.ovaleData.getProperty(
si,
atTime,
`max_${powerType}` as `max_${PowerType}`
);
if (isNumber(maxCost)) {
const power = this.getPowerAt(state, powerType, atTime);
if (power > maxCost || maximumCost) {
cost = maxCost;
if (cost < maxCost) {
cost = maxCost;
}
} else if (power > cost) {
cost = power;
}
}

spellCost =
(cost > 0 && floor(cost * ratio)) || ceil(cost * ratio);

const parameter = `refund_${powerType}` as `refund_${PowerType}`;
const refund = this.ovaleData.getProperty(
si,
atTime,
parameter
);

if (refund == "cost") {
spellRefund = spellCost;
} else if (isNumber(refund)) {
spellRefund = refund;
if (ratio && ratio != 0) {
if (cost > 0) {
spellCost = floor(cost * ratio);
} else {
spellCost = ceil(cost * ratio);
}
}
}
const refund = this.ovaleData.getProperty(
si,
atTime,
`refund_${powerType}` as `refund_${PowerType}`
);
if (refund == "cost") {
spellRefund = spellCost;
} else if (isNumber(refund)) {
spellRefund = refund;
}
} else {
const [cost] = this.getSpellCost(spellId, powerType);
if (cost) {
Expand Down

0 comments on commit eaf9cf2

Please sign in to comment.