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

Rotation timing improvements for Fire Mage APL #851

Merged
merged 9 commits into from
Jul 19, 2024
7 changes: 6 additions & 1 deletion proto/apl.proto
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ message APLAction {
}
}

// NextIndex: 75
// NextIndex: 77
message APLValue {
oneof value {
// Operators
Expand Down Expand Up @@ -155,6 +155,7 @@ message APLValue {
APLValueAuraIsKnown aura_is_known = 73;
APLValueAuraIsActive aura_is_active = 22;
APLValueAuraIsActiveWithReactionTime aura_is_active_with_reaction_time = 50;
APLValueAuraIsInactiveWithReactionTime aura_is_inactive_with_reaction_time = 76;
APLValueAuraRemainingTime aura_remaining_time = 23;
APLValueAuraNumStacks aura_num_stacks = 24;
APLValueAuraInternalCooldown aura_internal_cooldown = 39;
Expand Down Expand Up @@ -522,6 +523,10 @@ message APLValueAuraIsActiveWithReactionTime {
UnitReference source_unit = 2;
ActionID aura_id = 1;
}
message APLValueAuraIsInactiveWithReactionTime {
UnitReference source_unit = 2;
ActionID aura_id = 1;
}
message APLValueAuraRemainingTime {
UnitReference source_unit = 2;
ActionID aura_id = 1;
Expand Down
8 changes: 1 addition & 7 deletions sim/core/apl_actions_timing.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ func (action *APLActionWait) IsReady(sim *Simulation) bool {
func (action *APLActionWait) Execute(sim *Simulation) {
action.unit.Rotation.pushControllingAction(action)
action.curWaitTime = sim.CurrentTime + action.duration.GetDuration(sim)

pa := &PendingAction{
Priority: ActionPriorityLow,
OnAction: action.unit.rotationAction.OnAction,
NextActionAt: action.curWaitTime,
}
sim.AddPendingAction(pa)
action.unit.WaitUntil(sim, action.curWaitTime)
}

func (action *APLActionWait) GetNextAction(sim *Simulation) *APLAction {
Expand Down
2 changes: 2 additions & 0 deletions sim/core/apl_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ func (rot *APLRotation) newAPLValue(config *proto.APLValue) APLValue {
return rot.newValueAuraIsActive(config.GetAuraIsActive())
case *proto.APLValue_AuraIsActiveWithReactionTime:
return rot.newValueAuraIsActiveWithReactionTime(config.GetAuraIsActiveWithReactionTime())
case *proto.APLValue_AuraIsInactiveWithReactionTime:
return rot.newValueAuraIsInactiveWithReactionTime(config.GetAuraIsInactiveWithReactionTime())
case *proto.APLValue_AuraRemainingTime:
return rot.newValueAuraRemainingTime(config.GetAuraRemainingTime())
case *proto.APLValue_AuraNumStacks:
Expand Down
33 changes: 32 additions & 1 deletion sim/core/apl_values_aura.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,36 @@ func (value *APLValueAuraIsActiveWithReactionTime) String() string {
return fmt.Sprintf("Aura Active With Reaction Time(%s)", value.aura.String())
}

type APLValueAuraIsInactiveWithReactionTime struct {
DefaultAPLValueImpl
aura AuraReference
reactionTime time.Duration
}

func (rot *APLRotation) newValueAuraIsInactiveWithReactionTime(config *proto.APLValueAuraIsInactiveWithReactionTime) APLValue {
if config.AuraId == nil {
return nil
}
aura := rot.GetAPLAura(rot.GetSourceUnit(config.SourceUnit), config.AuraId)
if aura.Get() == nil {
return nil
}
return &APLValueAuraIsInactiveWithReactionTime{
aura: aura,
reactionTime: rot.unit.ReactionTime,
}
}
func (value *APLValueAuraIsInactiveWithReactionTime) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeBool
}
func (value *APLValueAuraIsInactiveWithReactionTime) GetBool(sim *Simulation) bool {
aura := value.aura.Get()
return !aura.IsActive() && aura.TimeInactive(sim) >= value.reactionTime
}
func (value *APLValueAuraIsInactiveWithReactionTime) String() string {
return fmt.Sprintf("Aura Inactive With Reaction Time(%s)", value.aura.String())
}

type APLValueAuraRemainingTime struct {
DefaultAPLValueImpl
aura AuraReference
Expand All @@ -106,7 +136,8 @@ func (value *APLValueAuraRemainingTime) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeDuration
}
func (value *APLValueAuraRemainingTime) GetDuration(sim *Simulation) time.Duration {
return value.aura.Get().RemainingDuration(sim)
aura := value.aura.Get()
return TernaryDuration(aura.IsActive(), aura.RemainingDuration(sim), 0)
}
func (value *APLValueAuraRemainingTime) String() string {
return fmt.Sprintf("Aura Remaining Time(%s)", value.aura.String())
Expand Down
2 changes: 1 addition & 1 deletion sim/core/apl_values_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (value *APLValueDotRemainingTime) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeDuration
}
func (value *APLValueDotRemainingTime) GetDuration(sim *Simulation) time.Duration {
return value.dot.RemainingDuration(sim)
return TernaryDuration(value.dot.IsActive(), value.dot.RemainingDuration(sim), 0)
}
func (value *APLValueDotRemainingTime) String() string {
return fmt.Sprintf("Dot Remaining Time(%s)", value.dot.Spell.ActionID)
Expand Down
14 changes: 14 additions & 0 deletions sim/core/aura.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Aura struct {

startTime time.Duration // Time at which the aura was applied.
expires time.Duration // Time at which aura will be removed.
fadeTime time.Duration // Time at which the aura was actually removed.

// The unit this aura is attached to.
Unit *Unit
Expand Down Expand Up @@ -128,6 +129,7 @@ func (aura *Aura) reset(sim *Simulation) {
panic("Aura nonzero stacks during reset: " + aura.Label)
}
aura.metrics.reset()
aura.fadeTime = -NeverExpires

if aura.OnReset != nil {
aura.OnReset(aura, sim)
Expand Down Expand Up @@ -224,6 +226,17 @@ func (aura *Aura) TimeActive(sim *Simulation) time.Duration {
}
}

// The amount of elapsed time since this aura was last active.
func (aura *Aura) TimeInactive(sim *Simulation) time.Duration {
if aura.IsActive() {
return 0
} else if (aura == nil) || (aura.fadeTime < 0) {
return NeverExpires
} else {
return sim.CurrentTime - aura.fadeTime
}
}

func (aura *Aura) RemainingDuration(sim *Simulation) time.Duration {
if aura.expires == NeverExpires {
return NeverExpires
Expand Down Expand Up @@ -659,6 +672,7 @@ func (aura *Aura) Deactivate(sim *Simulation) {
}

aura.expires = 0
aura.fadeTime = sim.CurrentTime
if aura.activeIndex != Inactive {
removeActiveIndex := aura.activeIndex
aura.Unit.activeAuras = removeBySwappingToBack(aura.Unit.activeAuras, removeActiveIndex)
Expand Down
Loading
Loading