From 7bfab6838ee51030b620de97d1461e543a1df20e Mon Sep 17 00:00:00 2001 From: James Tanner Date: Sun, 3 Sep 2023 15:23:58 -0700 Subject: [PATCH] Strict Sequences now only check that all subaction spells are off CD --- sim/core/apl_action.go | 14 +++++++ sim/core/apl_actions_sequences.go | 68 +++++++++++++++++-------------- sim/core/apl_values_sequences.go | 6 +-- 3 files changed, 54 insertions(+), 34 deletions(-) diff --git a/sim/core/apl_action.go b/sim/core/apl_action.go index d491162128..99220e26ac 100644 --- a/sim/core/apl_action.go +++ b/sim/core/apl_action.go @@ -46,6 +46,20 @@ func (action *APLAction) GetAllAPLValues() []APLValue { return FilterSlice(values, func(val APLValue) bool { return val != nil }) } +func (action *APLAction) GetAllSpells() []*Spell { + var spells []*Spell + for _, a := range action.GetAllActions() { + if impl, ok := a.impl.(*APLActionCastSpell); ok { + spells = append(spells, impl.spell) + } else if impl, ok := a.impl.(*APLActionMultidot); ok { + spells = append(spells, impl.spell) + } else if impl, ok := a.impl.(*APLActionMultishield); ok { + spells = append(spells, impl.spell) + } + } + return spells +} + func (action *APLAction) String() string { if action.condition == nil { return fmt.Sprintf("ACTION = %s", action.impl) diff --git a/sim/core/apl_actions_sequences.go b/sim/core/apl_actions_sequences.go index d0bd71fb8d..88e3dd2998 100644 --- a/sim/core/apl_actions_sequences.go +++ b/sim/core/apl_actions_sequences.go @@ -9,32 +9,32 @@ import ( type APLActionSequence struct { defaultAPLActionImpl - unit *Unit - name string - actions []*APLAction - curIdx int + unit *Unit + name string + subactions []*APLAction + curIdx int } func (rot *APLRotation) newActionSequence(config *proto.APLActionSequence) APLActionImpl { - actions := MapSlice(config.Actions, func(action *proto.APLAction) *APLAction { + subactions := MapSlice(config.Actions, func(action *proto.APLAction) *APLAction { return rot.newAPLAction(action) }) - actions = FilterSlice(actions, func(action *APLAction) bool { return action != nil }) - if len(actions) == 0 { + subactions = FilterSlice(subactions, func(action *APLAction) bool { return action != nil }) + if len(subactions) == 0 { return nil } return &APLActionSequence{ - unit: rot.unit, - name: config.Name, - actions: actions, + unit: rot.unit, + name: config.Name, + subactions: subactions, } } func (action *APLActionSequence) GetInnerActions() []*APLAction { - return Flatten(MapSlice(action.actions, func(action *APLAction) []*APLAction { return action.GetAllActions() })) + return Flatten(MapSlice(action.subactions, func(action *APLAction) []*APLAction { return action.GetAllActions() })) } func (action *APLActionSequence) Finalize(rot *APLRotation) { - for _, subaction := range action.actions { + for _, subaction := range action.subactions { subaction.impl.Finalize(rot) } } @@ -42,14 +42,14 @@ func (action *APLActionSequence) Reset(*Simulation) { action.curIdx = 0 } func (action *APLActionSequence) IsReady(sim *Simulation) bool { - return action.curIdx < len(action.actions) && action.actions[action.curIdx].IsReady(sim) + return action.curIdx < len(action.subactions) && action.subactions[action.curIdx].IsReady(sim) } func (action *APLActionSequence) Execute(sim *Simulation) { - action.actions[action.curIdx].Execute(sim) + action.subactions[action.curIdx].Execute(sim) action.curIdx++ } func (action *APLActionSequence) String() string { - return "Sequence(" + strings.Join(MapSlice(action.actions, func(subaction *APLAction) string { return fmt.Sprintf("(%s)", subaction) }), "+") + ")" + return "Sequence(" + strings.Join(MapSlice(action.subactions, func(subaction *APLAction) string { return fmt.Sprintf("(%s)", subaction) }), "+") + ")" } type APLActionResetSequence struct { @@ -88,39 +88,45 @@ func (action *APLActionResetSequence) String() string { type APLActionStrictSequence struct { defaultAPLActionImpl - unit *Unit - actions []*APLAction - curIdx int + unit *Unit + subactions []*APLAction + curIdx int + + subactionSpells []*Spell } func (rot *APLRotation) newActionStrictSequence(config *proto.APLActionStrictSequence) APLActionImpl { - actions := MapSlice(config.Actions, func(action *proto.APLAction) *APLAction { + subactions := MapSlice(config.Actions, func(action *proto.APLAction) *APLAction { return rot.newAPLAction(action) }) - actions = FilterSlice(actions, func(action *APLAction) bool { return action != nil }) - if len(actions) == 0 { + subactions = FilterSlice(subactions, func(action *APLAction) bool { return action != nil }) + if len(subactions) == 0 { return nil } return &APLActionStrictSequence{ - unit: rot.unit, - actions: actions, + unit: rot.unit, + subactions: subactions, } } func (action *APLActionStrictSequence) GetInnerActions() []*APLAction { - return Flatten(MapSlice(action.actions, func(action *APLAction) []*APLAction { return action.GetAllActions() })) + return Flatten(MapSlice(action.subactions, func(action *APLAction) []*APLAction { return action.GetAllActions() })) } func (action *APLActionStrictSequence) Finalize(rot *APLRotation) { - for _, subaction := range action.actions { + for _, subaction := range action.subactions { subaction.impl.Finalize(rot) + action.subactionSpells = append(action.subactionSpells, subaction.GetAllSpells()...) } } func (action *APLActionStrictSequence) Reset(*Simulation) { action.curIdx = 0 } func (action *APLActionStrictSequence) IsReady(sim *Simulation) bool { - for _, subaction := range action.actions { - if !subaction.IsReady(sim) { + if !action.unit.GCD.IsReady(sim) { + return false + } + for _, spell := range action.subactionSpells { + if !spell.IsReady(sim) { return false } } @@ -130,11 +136,11 @@ func (action *APLActionStrictSequence) Execute(sim *Simulation) { action.unit.Rotation.controllingAction = action } func (action *APLActionStrictSequence) GetNextAction(sim *Simulation) *APLAction { - if action.actions[action.curIdx].IsReady(sim) { - nextAction := action.actions[action.curIdx] + if action.subactions[action.curIdx].IsReady(sim) { + nextAction := action.subactions[action.curIdx] action.curIdx++ - if action.curIdx == len(action.actions) { + if action.curIdx == len(action.subactions) { action.curIdx = 0 action.unit.Rotation.controllingAction = nil } @@ -152,5 +158,5 @@ func (action *APLActionStrictSequence) GetNextAction(sim *Simulation) *APLAction } } func (action *APLActionStrictSequence) String() string { - return "Strict Sequence(" + strings.Join(MapSlice(action.actions, func(subaction *APLAction) string { return fmt.Sprintf("(%s)", subaction) }), "+") + ")" + return "Strict Sequence(" + strings.Join(MapSlice(action.subactions, func(subaction *APLAction) string { return fmt.Sprintf("(%s)", subaction) }), "+") + ")" } diff --git a/sim/core/apl_values_sequences.go b/sim/core/apl_values_sequences.go index a01393e79f..9292fa35ff 100644 --- a/sim/core/apl_values_sequences.go +++ b/sim/core/apl_values_sequences.go @@ -35,7 +35,7 @@ func (value *APLValueSequenceIsComplete) Type() proto.APLValueType { return proto.APLValueType_ValueTypeBool } func (value *APLValueSequenceIsComplete) GetBool(sim *Simulation) bool { - return value.sequence.curIdx >= len(value.sequence.actions) + return value.sequence.curIdx >= len(value.sequence.subactions) } func (value *APLValueSequenceIsComplete) String() string { return fmt.Sprintf("Sequence Is Complete(%s)", value.name) @@ -103,9 +103,9 @@ func (value *APLValueSequenceTimeToReady) Type() proto.APLValueType { return proto.APLValueType_ValueTypeDuration } func (value *APLValueSequenceTimeToReady) GetDuration(sim *Simulation) time.Duration { - if value.sequence.curIdx >= len(value.sequence.actions) { + if value.sequence.curIdx >= len(value.sequence.subactions) { return NeverExpires - } else if subaction, ok := value.sequence.actions[value.sequence.curIdx].impl.(*APLActionCastSpell); ok { + } else if subaction, ok := value.sequence.subactions[value.sequence.curIdx].impl.(*APLActionCastSpell); ok { return subaction.spell.TimeToReady(sim) } else if value.sequence.IsReady(sim) { return 0