Skip to content

Commit

Permalink
Merge pull request #3255 from wowsims/apl
Browse files Browse the repository at this point in the history
Add lots of common APL values
  • Loading branch information
jimmyt857 authored Jul 6, 2023
2 parents b9913fb + 1e4a927 commit 47d6395
Show file tree
Hide file tree
Showing 7 changed files with 346 additions and 1 deletion.
28 changes: 28 additions & 0 deletions proto/apl.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,22 @@ message APLValue {
APLValueNot not = 4;
APLValueCompare cmp = 5;

// Encounter values
APLValueCurrentTime current_time = 7;
APLValueCurrentTimePercent current_time_percent = 8;
APLValueRemainingTime remaining_time = 9;
APLValueRemainingTimePercent remaining_time_percent = 10;

// Resource values
APLValueCurrentMana current_mana = 11;
APLValueCurrentManaPercent current_mana_percent = 12;
APLValueCurrentRage current_rage = 14;
APLValueCurrentEnergy current_energy = 15;
APLValueCurrentComboPoints current_combo_points = 16;

// Dot values
APLValueDotIsActive dot_is_active = 6;
APLValueDotRemainingTime dot_remaining_time = 13;
}
}

Expand Down Expand Up @@ -119,6 +133,20 @@ message APLValueCompare {
APLValue rhs = 3;
}

message APLValueCurrentTime {}
message APLValueCurrentTimePercent {}
message APLValueRemainingTime {}
message APLValueRemainingTimePercent {}

message APLValueCurrentMana {}
message APLValueCurrentManaPercent {}
message APLValueCurrentRage {}
message APLValueCurrentEnergy {}
message APLValueCurrentComboPoints {}

message APLValueDotIsActive {
ActionID spell_id = 1;
}
message APLValueDotRemainingTime {
ActionID spell_id = 1;
}
24 changes: 24 additions & 0 deletions sim/core/apl_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,33 @@ func (unit *Unit) newAPLValue(config *proto.APLValue) APLValue {
case *proto.APLValue_Cmp:
return unit.newValueCompare(config.GetCmp())

// Encounter
case *proto.APLValue_CurrentTime:
return unit.newValueCurrentTime(config.GetCurrentTime())
case *proto.APLValue_CurrentTimePercent:
return unit.newValueCurrentTimePercent(config.GetCurrentTimePercent())
case *proto.APLValue_RemainingTime:
return unit.newValueRemainingTime(config.GetRemainingTime())
case *proto.APLValue_RemainingTimePercent:
return unit.newValueRemainingTimePercent(config.GetRemainingTimePercent())

// Resources
case *proto.APLValue_CurrentMana:
return unit.newValueCurrentMana(config.GetCurrentMana())
case *proto.APLValue_CurrentManaPercent:
return unit.newValueCurrentManaPercent(config.GetCurrentManaPercent())
case *proto.APLValue_CurrentRage:
return unit.newValueCurrentRage(config.GetCurrentRage())
case *proto.APLValue_CurrentEnergy:
return unit.newValueCurrentEnergy(config.GetCurrentEnergy())
case *proto.APLValue_CurrentComboPoints:
return unit.newValueCurrentComboPoints(config.GetCurrentComboPoints())

// Dots
case *proto.APLValue_DotIsActive:
return unit.newValueDotIsActive(config.GetDotIsActive())
case *proto.APLValue_DotRemainingTime:
return unit.newValueDotRemainingTime(config.GetDotRemainingTime())

default:
validationError("Unimplemented value type")
Expand Down
29 changes: 28 additions & 1 deletion sim/core/apl_values_core.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package core

import (
"time"

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

Expand All @@ -23,8 +25,12 @@ type APLValueDotIsActive struct {
}

func (unit *Unit) newValueDotIsActive(config *proto.APLValueDotIsActive) APLValue {
dot := unit.aplGetDot(config.SpellId)
if dot == nil {
return nil
}
return &APLValueDotIsActive{
dot: unit.aplGetDot(config.SpellId),
dot: dot,
}
}
func (value *APLValueDotIsActive) Type() proto.APLValueType {
Expand All @@ -33,3 +39,24 @@ func (value *APLValueDotIsActive) Type() proto.APLValueType {
func (value *APLValueDotIsActive) GetBool(sim *Simulation) bool {
return value.dot.IsActive()
}

type APLValueDotRemainingTime struct {
defaultAPLValueImpl
dot *Dot
}

func (unit *Unit) newValueDotRemainingTime(config *proto.APLValueDotRemainingTime) APLValue {
dot := unit.aplGetDot(config.SpellId)
if dot == nil {
return nil
}
return &APLValueDotRemainingTime{
dot: dot,
}
}
func (value *APLValueDotRemainingTime) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeDuration
}
func (value *APLValueDotRemainingTime) GetDuration(sim *Simulation) time.Duration {
return value.dot.RemainingDuration(sim)
}
63 changes: 63 additions & 0 deletions sim/core/apl_values_encounter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package core

import (
"time"

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

type APLValueCurrentTime struct {
defaultAPLValueImpl
}

func (unit *Unit) newValueCurrentTime(config *proto.APLValueCurrentTime) APLValue {
return &APLValueCurrentTime{}
}
func (value *APLValueCurrentTime) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeDuration
}
func (value *APLValueCurrentTime) GetDuration(sim *Simulation) time.Duration {
return sim.CurrentTime
}

type APLValueCurrentTimePercent struct {
defaultAPLValueImpl
}

func (unit *Unit) newValueCurrentTimePercent(config *proto.APLValueCurrentTimePercent) APLValue {
return &APLValueCurrentTimePercent{}
}
func (value *APLValueCurrentTimePercent) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeFloat
}
func (value *APLValueCurrentTimePercent) GetFloat(sim *Simulation) float64 {
return sim.CurrentTime.Seconds() / sim.Duration.Seconds()
}

type APLValueRemainingTime struct {
defaultAPLValueImpl
}

func (unit *Unit) newValueRemainingTime(config *proto.APLValueRemainingTime) APLValue {
return &APLValueRemainingTime{}
}
func (value *APLValueRemainingTime) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeDuration
}
func (value *APLValueRemainingTime) GetDuration(sim *Simulation) time.Duration {
return sim.GetRemainingDuration()
}

type APLValueRemainingTimePercent struct {
defaultAPLValueImpl
}

func (unit *Unit) newValueRemainingTimePercent(config *proto.APLValueRemainingTimePercent) APLValue {
return &APLValueRemainingTimePercent{}
}
func (value *APLValueRemainingTimePercent) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeFloat
}
func (value *APLValueRemainingTimePercent) GetFloat(sim *Simulation) float64 {
return sim.GetRemainingDurationPercent()
}
9 changes: 9 additions & 0 deletions sim/core/apl_values_operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ func (unit *Unit) newValueConst(config *proto.APLValueConst) APLValue {
return result
}

if len(config.Val) > 1 && config.Val[len(config.Val)-1] == '%' {
if floatVal, err := strconv.ParseFloat(config.Val[0:len(config.Val)-1], 64); err == nil {
result.floatVal = floatVal / 100.0
result.durationVal = DurationFromSeconds(floatVal / 100.0)
result.valType = proto.APLValueType_ValueTypeFloat
return result
}
}

if floatVal, err := strconv.ParseFloat(config.Val, 64); err == nil {
result.floatVal = floatVal
result.durationVal = DurationFromSeconds(floatVal)
Expand Down
105 changes: 105 additions & 0 deletions sim/core/apl_values_resources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package core

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

type APLValueCurrentMana struct {
defaultAPLValueImpl
unit *Unit
}

func (unit *Unit) newValueCurrentMana(config *proto.APLValueCurrentMana) APLValue {
if !unit.HasManaBar() {
return nil
}
return &APLValueCurrentMana{
unit: unit,
}
}
func (value *APLValueCurrentMana) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeFloat
}
func (value *APLValueCurrentMana) GetFloat(sim *Simulation) float64 {
return value.unit.CurrentMana()
}

type APLValueCurrentManaPercent struct {
defaultAPLValueImpl
unit *Unit
}

func (unit *Unit) newValueCurrentManaPercent(config *proto.APLValueCurrentManaPercent) APLValue {
if !unit.HasManaBar() {
return nil
}
return &APLValueCurrentManaPercent{
unit: unit,
}
}
func (value *APLValueCurrentManaPercent) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeFloat
}
func (value *APLValueCurrentManaPercent) GetFloat(sim *Simulation) float64 {
return value.unit.CurrentManaPercent()
}

type APLValueCurrentRage struct {
defaultAPLValueImpl
unit *Unit
}

func (unit *Unit) newValueCurrentRage(config *proto.APLValueCurrentRage) APLValue {
if !unit.HasRageBar() {
return nil
}
return &APLValueCurrentRage{
unit: unit,
}
}
func (value *APLValueCurrentRage) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeFloat
}
func (value *APLValueCurrentRage) GetFloat(sim *Simulation) float64 {
return value.unit.CurrentRage()
}

type APLValueCurrentEnergy struct {
defaultAPLValueImpl
unit *Unit
}

func (unit *Unit) newValueCurrentEnergy(config *proto.APLValueCurrentEnergy) APLValue {
if !unit.HasEnergyBar() {
return nil
}
return &APLValueCurrentEnergy{
unit: unit,
}
}
func (value *APLValueCurrentEnergy) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeFloat
}
func (value *APLValueCurrentEnergy) GetFloat(sim *Simulation) float64 {
return value.unit.CurrentEnergy()
}

type APLValueCurrentComboPoints struct {
defaultAPLValueImpl
unit *Unit
}

func (unit *Unit) newValueCurrentComboPoints(config *proto.APLValueCurrentComboPoints) APLValue {
if !unit.HasEnergyBar() {
return nil
}
return &APLValueCurrentComboPoints{
unit: unit,
}
}
func (value *APLValueCurrentComboPoints) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeInt
}
func (value *APLValueCurrentComboPoints) GetInt(sim *Simulation) int32 {
return value.unit.ComboPoints()
}
Loading

0 comments on commit 47d6395

Please sign in to comment.