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

Strict Sequences now only check that all subaction spells are off CD #3606

Merged
merged 1 commit into from
Sep 3, 2023
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
14 changes: 14 additions & 0 deletions sim/core/apl_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
68 changes: 37 additions & 31 deletions sim/core/apl_actions_sequences.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,47 @@ 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)
}
}
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 {
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
Expand All @@ -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) }), "+") + ")"
}
6 changes: 3 additions & 3 deletions sim/core/apl_values_sequences.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Loading