Skip to content

Commit

Permalink
Merge pull request wowsims#3809 from wowsims/apl
Browse files Browse the repository at this point in the history
Implement Recast checkbox for Channel APL action
  • Loading branch information
jimmyt857 authored Oct 4, 2023
2 parents d6a01b7 + 39cf075 commit 17943a4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion proto/apl.proto
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ message APLActionChannelSpell {
UnitReference target = 2;

APLValue interrupt_if = 3;
APLValue max_ticks = 4;
bool allow_recast = 5;
}

message APLActionMultidot {
Expand Down
15 changes: 6 additions & 9 deletions sim/core/apl.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type APLRotation struct {
// Will be nil when there is no active channel.
interruptChannelIf APLValue

// Max ticks for the current channel, or 0 for no maximum.
channelMaxTicks int32
// If true, can recast channel when interrupted.
allowChannelRecastOnInterrupt bool

// Used inside of actions/value to determine whether they will occur during the prepull or regular rotation.
parsingPrepull bool
Expand Down Expand Up @@ -153,7 +153,7 @@ func (rot *APLRotation) reset(sim *Simulation) {
rot.controllingAction = nil
rot.inLoop = false
rot.interruptChannelIf = nil
rot.channelMaxTicks = 0
rot.allowChannelRecastOnInterrupt = false
for _, action := range rot.allAPLActions() {
action.impl.Reset(sim)
}
Expand Down Expand Up @@ -218,10 +218,6 @@ func (apl *APLRotation) shouldInterruptChannel(sim *Simulation) bool {
return false
}

if apl.channelMaxTicks != 0 && channeledDot.TickCount >= apl.channelMaxTicks {
return true
}

if apl.interruptChannelIf == nil || !apl.interruptChannelIf.GetBool(sim) {
// Continue the channel.
return false
Expand All @@ -232,9 +228,10 @@ func (apl *APLRotation) shouldInterruptChannel(sim *Simulation) bool {
if nextAction == nil {
return false
}

if channelAction, ok := nextAction.impl.(*APLActionChannelSpell); ok && channelAction.spell == channeledDot.Spell {
// Newly selected action is channeling the same spell, so continue the channel.
return false
// Newly selected action is channeling the same spell, so continue the channel unless recast is allowed.
return apl.allowChannelRecastOnInterrupt
}

return true
Expand Down
13 changes: 4 additions & 9 deletions sim/core/apl_actions_casting.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package core

import (
"fmt"

"github.com/wowsims/wotlk/sim/core/proto"
)

Expand Down Expand Up @@ -40,7 +41,7 @@ type APLActionChannelSpell struct {
spell *Spell
target UnitReference
interruptIf APLValue
maxTicks APLValue
allowRecast bool
}

func (rot *APLRotation) newActionChannelSpell(config *proto.APLActionChannelSpell) APLActionImpl {
Expand All @@ -52,8 +53,6 @@ func (rot *APLRotation) newActionChannelSpell(config *proto.APLActionChannelSpel
})
}

maxTicks := rot.coerceTo(rot.newAPLValue(config.MaxTicks), proto.APLValueType_ValueTypeInt)

spell := rot.GetAPLSpell(config.SpellId)
if spell == nil {
return nil
Expand All @@ -71,20 +70,16 @@ func (rot *APLRotation) newActionChannelSpell(config *proto.APLActionChannelSpel
spell: spell,
target: target,
interruptIf: interruptIf,
maxTicks: maxTicks,
allowRecast: config.AllowRecast,
}
}
func (action *APLActionChannelSpell) IsReady(sim *Simulation) bool {
return action.spell.CanCast(sim, action.target.Get())
}
func (action *APLActionChannelSpell) Execute(sim *Simulation) {
maxTicks := int32(0)
if action.maxTicks != nil {
maxTicks = action.maxTicks.GetInt(sim)
}
action.spell.Cast(sim, action.target.Get())
action.spell.Unit.Rotation.interruptChannelIf = action.interruptIf
action.spell.Unit.Rotation.channelMaxTicks = maxTicks
action.spell.Unit.Rotation.allowChannelRecastOnInterrupt = action.allowRecast
}
func (action *APLActionChannelSpell) String() string {
return fmt.Sprintf("Channel Spell(%s, interruptIf=%s)", action.spell.ActionID, action.interruptIf)
Expand Down
2 changes: 1 addition & 1 deletion sim/core/dot.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func newDot(config Dot) *Dot {
dot.Spell.Unit.ChanneledDot = nil
if dot.Spell.Unit.IsUsingAPL {
dot.Spell.Unit.Rotation.interruptChannelIf = nil
dot.Spell.Unit.Rotation.channelMaxTicks = 0
dot.Spell.Unit.Rotation.allowChannelRecastOnInterrupt = false
}
}
})
Expand Down
5 changes: 2 additions & 3 deletions ui/core/components/individual_sim_ui/apl_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,8 @@ const actionKindFactories: {[f in NonNullable<APLActionKind>]: ActionKindConfig<
label: 'Interrupt If',
labelTooltip: 'Condition which must be true to allow the channel to be interrupted.',
}),
AplValues.valueFieldConfig('maxTicks', {
label: 'Max Ticks',
labelTooltip: 'Maximum number of ticks to use for the channel, evaluated when casting begins. <b>None</b> or <b>0</b> will allow the full duration.',
AplHelpers.booleanFieldConfig('allowRecast', 'Recast', {
labelTooltip: 'If checked, interrupts of this channel will recast the spell.',
}),
],
}),
Expand Down
10 changes: 8 additions & 2 deletions ui/core/components/individual_sim_ui/apl_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,10 @@ export function booleanFieldConfig(field: string, label?:string, options?: Parti
return {
field: field,
newValue: () => false,
factory: (parent, player, config) => new BooleanPicker(parent, player, config),
factory: (parent, player, config) => {
config.extraCssClasses = ['input-inline'].concat(config.extraCssClasses || []);
return new BooleanPicker(parent, player, config);
},
...(options || {}),
label: label,
};
Expand All @@ -455,7 +458,10 @@ export function numberFieldConfig(field: string, options?: Partial<APLPickerBuil
return {
field: field,
newValue: () => 0,
factory: (parent, player, config) => new NumberPicker(parent, player, config),
factory: (parent, player, config) => {
config.extraCssClasses = ['input-inline'].concat(config.extraCssClasses || []);
return new NumberPicker(parent, player, config);
},
...(options || {}),
};
}
Expand Down

0 comments on commit 17943a4

Please sign in to comment.