Skip to content

Commit

Permalink
Merge pull request #1265 from hillerstorm/apl_values
Browse files Browse the repository at this point in the history
Add useful APL values for Energy and Focus
  • Loading branch information
hillerstorm authored Dec 16, 2024
2 parents 319b70d + accf399 commit f1ad747
Show file tree
Hide file tree
Showing 7 changed files with 338 additions and 21 deletions.
18 changes: 17 additions & 1 deletion proto/apl.proto
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ message APLAction {
}
}

// NextIndex: 88
// NextIndex: 94
message APLValue {
UUID uuid = 87;

Expand Down Expand Up @@ -122,7 +122,13 @@ message APLValue {
APLValueCurrentSolarEnergy current_solar_energy = 68;
APLValueCurrentLunarEnergy current_lunar_energy = 69;
APLValueCurrentHolyPower current_holy_power = 75;
APLValueMaxEnergy max_energy = 88;
APLValueMaxFocus max_focus = 89;
APLValueMaxRunicPower max_runic_power = 86;
APLValueEnergyRegenPerSecond energy_regen_per_second = 90;
APLValueFocusRegenPerSecond focus_regen_per_second = 91;
APLValueEnergyTimeToTarget energy_time_to_target = 92;
APLValueFocusTimeToTarget focus_time_to_target = 93;

// Unit values
APLValueUnitIsMoving unit_is_moving = 72;
Expand Down Expand Up @@ -439,7 +445,17 @@ message APLValueCurrentRunicPower {}
message APLValueCurrentSolarEnergy {}
message APLValueCurrentLunarEnergy {}
message APLValueCurrentHolyPower {}
message APLValueMaxEnergy {}
message APLValueMaxFocus {}
message APLValueMaxRunicPower {}
message APLValueEnergyRegenPerSecond {}
message APLValueFocusRegenPerSecond {}
message APLValueEnergyTimeToTarget {
APLValue target_energy = 1;
}
message APLValueFocusTimeToTarget {
APLValue target_focus = 1;
}

enum APLValueRuneType {
RuneUnknown = 0;
Expand Down
12 changes: 12 additions & 0 deletions sim/core/apl_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,20 @@ func (rot *APLRotation) newAPLValue(config *proto.APLValue) APLValue {
value = rot.newValueCurrentComboPoints(config.GetCurrentComboPoints(), config.Uuid)
case *proto.APLValue_CurrentRunicPower:
value = rot.newValueCurrentRunicPower(config.GetCurrentRunicPower(), config.Uuid)
case *proto.APLValue_MaxEnergy:
value = rot.newValueMaxEnergy(config.GetMaxEnergy(), config.Uuid)
case *proto.APLValue_MaxFocus:
value = rot.newValueMaxFocus(config.GetMaxFocus(), config.Uuid)
case *proto.APLValue_MaxRunicPower:
value = rot.newValueMaxRunicPower(config.GetMaxRunicPower(), config.Uuid)
case *proto.APLValue_EnergyRegenPerSecond:
value = rot.newValueEnergyRegenPerSecond(config.GetEnergyRegenPerSecond(), config.Uuid)
case *proto.APLValue_FocusRegenPerSecond:
value = rot.newValueFocusRegenPerSecond(config.GetFocusRegenPerSecond(), config.Uuid)
case *proto.APLValue_EnergyTimeToTarget:
value = rot.newValueEnergyTimeToTarget(config.GetEnergyTimeToTarget(), config.Uuid)
case *proto.APLValue_FocusTimeToTarget:
value = rot.newValueFocusTimeToTarget(config.GetFocusTimeToTarget(), config.Uuid)

// Resources Runes
case *proto.APLValue_CurrentRuneCount:
Expand Down
169 changes: 168 additions & 1 deletion sim/core/apl_values_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package core

import (
"fmt"
"time"

"github.com/wowsims/cata/sim/core/proto"
)
Expand Down Expand Up @@ -171,6 +172,89 @@ func (value *APLValueCurrentFocus) String() string {
return "Current Focus"
}

type APLValueMaxFocus struct {
DefaultAPLValueImpl
maxFocus float64
}

func (rot *APLRotation) newValueMaxFocus(_ *proto.APLValueMaxFocus, uuid *proto.UUID) APLValue {
unit := rot.unit
if !unit.HasFocusBar() {
rot.ValidationMessageByUUID(uuid, proto.LogLevel_Error, "%s does not use Focus", unit.Label)
return nil
}
return &APLValueMaxFocus{
maxFocus: unit.MaximumFocus(),
}
}
func (value *APLValueMaxFocus) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeFloat
}
func (value *APLValueMaxFocus) GetFloat(sim *Simulation) float64 {
return value.maxFocus
}
func (value *APLValueMaxFocus) String() string {
return fmt.Sprintf("Max Focus(%f)", value.maxFocus)
}

type APLValueFocusRegenPerSecond struct {
DefaultAPLValueImpl
unit *Unit
}

func (rot *APLRotation) newValueFocusRegenPerSecond(_ *proto.APLValueFocusRegenPerSecond, uuid *proto.UUID) APLValue {
unit := rot.unit
if !unit.HasFocusBar() {
rot.ValidationMessageByUUID(uuid, proto.LogLevel_Warning, "%s does not use Focus", unit.Label)
return nil
}
return &APLValueFocusRegenPerSecond{
unit: unit,
}
}
func (value *APLValueFocusRegenPerSecond) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeFloat
}
func (value *APLValueFocusRegenPerSecond) GetFloat(sim *Simulation) float64 {
return value.unit.FocusRegenPerSecond()
}
func (value *APLValueFocusRegenPerSecond) String() string {
return "Focus Regen Per Second"
}

type APLValueFocusTimeToTarget struct {
DefaultAPLValueImpl
unit *Unit
targetFocus APLValue
}

func (rot *APLRotation) newValueFocusTimeToTarget(config *proto.APLValueFocusTimeToTarget, uuid *proto.UUID) APLValue {
unit := rot.unit
if !unit.HasFocusBar() {
rot.ValidationMessageByUUID(uuid, proto.LogLevel_Warning, "%s does not use Focus", unit.Label)
return nil
}

targetFocus := rot.coerceTo(rot.newAPLValue(config.TargetFocus), proto.APLValueType_ValueTypeFloat)
if targetFocus == nil {
return nil
}

return &APLValueFocusTimeToTarget{
unit: unit,
targetFocus: targetFocus,
}
}
func (value *APLValueFocusTimeToTarget) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeDuration
}
func (value *APLValueFocusTimeToTarget) GetDuration(sim *Simulation) time.Duration {
return value.unit.TimeToTargetFocus(value.targetFocus.GetFloat(sim))
}
func (value *APLValueFocusTimeToTarget) String() string {
return "Estimated Time To Target Focus"
}

type APLValueCurrentEnergy struct {
DefaultAPLValueImpl
unit *Unit
Expand All @@ -196,6 +280,89 @@ func (value *APLValueCurrentEnergy) String() string {
return "Current Energy"
}

type APLValueMaxEnergy struct {
DefaultAPLValueImpl
unit *Unit
}

func (rot *APLRotation) newValueMaxEnergy(_ *proto.APLValueMaxEnergy, uuid *proto.UUID) APLValue {
unit := rot.unit
if !unit.HasEnergyBar() {
rot.ValidationMessageByUUID(uuid, proto.LogLevel_Error, "%s does not use Energy", unit.Label)
return nil
}
return &APLValueMaxEnergy{
unit: unit,
}
}
func (value *APLValueMaxEnergy) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeFloat
}
func (value *APLValueMaxEnergy) GetFloat(sim *Simulation) float64 {
return value.unit.MaximumEnergy()
}
func (value *APLValueMaxEnergy) String() string {
return "Max Energy"
}

type APLValueEnergyRegenPerSecond struct {
DefaultAPLValueImpl
unit *Unit
}

func (rot *APLRotation) newValueEnergyRegenPerSecond(_ *proto.APLValueEnergyRegenPerSecond, uuid *proto.UUID) APLValue {
unit := rot.unit
if !unit.HasEnergyBar() {
rot.ValidationMessageByUUID(uuid, proto.LogLevel_Warning, "%s does not use Energy", unit.Label)
return nil
}
return &APLValueEnergyRegenPerSecond{
unit: unit,
}
}
func (value *APLValueEnergyRegenPerSecond) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeFloat
}
func (value *APLValueEnergyRegenPerSecond) GetFloat(sim *Simulation) float64 {
return value.unit.EnergyRegenPerSecond()
}
func (value *APLValueEnergyRegenPerSecond) String() string {
return "Energy Regen Per Second"
}

type APLValueEnergyTimeToTarget struct {
DefaultAPLValueImpl
unit *Unit
targetEnergy APLValue
}

func (rot *APLRotation) newValueEnergyTimeToTarget(config *proto.APLValueEnergyTimeToTarget, uuid *proto.UUID) APLValue {
unit := rot.unit
if !unit.HasEnergyBar() {
rot.ValidationMessageByUUID(uuid, proto.LogLevel_Warning, "%s does not use Energy", unit.Label)
return nil
}

targetEnergy := rot.coerceTo(rot.newAPLValue(config.TargetEnergy), proto.APLValueType_ValueTypeFloat)
if targetEnergy == nil {
return nil
}

return &APLValueEnergyTimeToTarget{
unit: unit,
targetEnergy: targetEnergy,
}
}
func (value *APLValueEnergyTimeToTarget) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeDuration
}
func (value *APLValueEnergyTimeToTarget) GetDuration(sim *Simulation) time.Duration {
return value.unit.TimeToTargetEnergy(value.targetEnergy.GetFloat(sim))
}
func (value *APLValueEnergyTimeToTarget) String() string {
return "Estimated Time To Target Energy"
}

type APLValueCurrentComboPoints struct {
DefaultAPLValueImpl
unit *Unit
Expand Down Expand Up @@ -258,7 +425,7 @@ func (rot *APLRotation) newValueMaxRunicPower(_ *proto.APLValueMaxRunicPower, uu
return nil
}
return &APLValueMaxRunicPower{
maxRunicPower: int32(unit.MaxRunicPower()),
maxRunicPower: int32(unit.MaximumRunicPower()),
}
}
func (value *APLValueMaxRunicPower) Type() proto.APLValueType {
Expand Down
8 changes: 8 additions & 0 deletions sim/core/energy.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ func (eb *energyBar) EnergyRegenPerSecond() float64 {
return 10.0 * eb.hasteRatingMultiplier * eb.energyRegenMultiplier
}

func (eb *energyBar) TimeToTargetEnergy(targetEnergy float64) time.Duration {
if eb.currentEnergy >= targetEnergy {
return time.Duration(0)
}

return DurationFromSeconds((targetEnergy - eb.currentEnergy) / eb.EnergyRegenPerSecond())
}

func (eb *energyBar) AddEnergy(sim *Simulation, amount float64, metrics *ResourceMetrics) {
if amount < 0 {
panic("Trying to add negative energy!")
Expand Down
12 changes: 12 additions & 0 deletions sim/core/focus.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func (fb *focusBar) CurrentFocus() float64 {
return fb.currentFocus
}

func (fb *focusBar) MaximumFocus() float64 {
return fb.maxFocus
}

func (fb *focusBar) NextFocusTickAt() time.Duration {
return fb.nextFocusTick
}
Expand All @@ -77,6 +81,14 @@ func (fb *focusBar) FocusRegenPerSecond() float64 {
}
}

func (fb *focusBar) TimeToTargetFocus(targetFocus float64) time.Duration {
if fb.currentFocus >= targetFocus {
return time.Duration(0)
}

return DurationFromSeconds((targetFocus - fb.currentFocus) / fb.FocusRegenPerSecond())
}

func (fb *focusBar) getTotalRegenMultiplier() float64 {
return fb.hasteRatingMultiplier * fb.focusRegenMultiplier
}
Expand Down
2 changes: 1 addition & 1 deletion sim/core/runic_power.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (rp *runicPowerBar) CurrentRunicPower() float64 {
return rp.currentRunicPower
}

func (rp *runicPowerBar) MaxRunicPower() float64 {
func (rp *runicPowerBar) MaximumRunicPower() float64 {
return rp.maxRunicPower
}

Expand Down
Loading

0 comments on commit f1ad747

Please sign in to comment.