Skip to content

Commit

Permalink
feat(dps): correct sweepFire calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
wezzle committed Oct 24, 2024
1 parent 5e5ab44 commit 3d913d5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
17 changes: 16 additions & 1 deletion gamedata/parser/lua.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func ParseWeaponDefs(data *lua.LTable) map[string]types.WeaponDef {
Name: IgnoreError("name", p.String),
WeaponType: IgnoreError("weapontype", p.String),
Id: IgnoreError("id", p.Int64),
CustomParams: map[string]string{},
CustomParams: make(map[string]interface{}),
AvoidFriendly: IgnoreError("avoidfriendly", p.Bool),
AvoidFeature: IgnoreError("avoidfeature", p.Bool),
AvoidNeutral: IgnoreError("avoidneutral", p.Bool),
Expand Down Expand Up @@ -518,6 +518,21 @@ func ParseWeaponDefs(data *lua.LTable) map[string]types.WeaponDef {
SoundHitDryVolume: IgnoreError("soundhitdryvolume", p.Float64),
SoundHitWetVolume: IgnoreError("soundhitwetvolume", p.Float64),
}

customParams := IgnoreError("customparams", p.Table)
if customParams != nil {
customParams.data.ForEach(func(k lua.LValue, v lua.LValue) {
if v.Type() != lua.LTNumber && v.Type() != lua.LTString {
return
}
customParamValue, err := strconv.ParseFloat(v.String(), 64)
if err != nil {
return
}
def.CustomParams[k.String()] = customParamValue
})
}

damage := IgnoreError("damage", p.Table)
damage.data.ForEach(func(k lua.LValue, v lua.LValue) {
if v.Type() != lua.LTNumber && v.Type() != lua.LTString {
Expand Down
2 changes: 1 addition & 1 deletion gamedata/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type (
Name string
WeaponType WeaponType
Id int64
CustomParams map[string]string
CustomParams map[string]interface{}
AvoidFriendly bool
AvoidFeature bool
AvoidNeutral bool
Expand Down
23 changes: 22 additions & 1 deletion gamedata/types/unitproperties.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ func (p *UnitProperties) DPS() float64 {
// LaserCannon
//
//
// TODO check beamlaser calculation for legbastion, leginc seems to work fine
// Sweepfire (Legion heatguns)
// unitDefInfo[unitDefID].maxdps = (weaponDef.damages[0] * weaponDef.customParams.sweepfire) / math.max(weaponDef.minIntensity, 0.5)
// unitDefInfo[unitDefID].mindps = weaponDef.damages[0] * weaponDef.customParams.sweepfire
dps := 0.0

for _, weapon := range p.Weapons {
Expand All @@ -75,6 +77,25 @@ func (p *UnitProperties) DPS() float64 {
continue
}

if sweepFire, exists := wd.CustomParams["sweepfire"]; exists {
var sweepFireValue float64
switch v := sweepFire.(type) {
case float64:
sweepFireValue = v
case float32:
sweepFireValue = float64(v)
case int64:
sweepFireValue = float64(v)
case int:
sweepFireValue = float64(v)
}

if sweepFireValue != 0 {
dps = dps + (damage * sweepFireValue)
continue
}
}

damage = damage / wd.ReloadTime
if wd.Burst != 0 {
damage = damage * float64(wd.Burst)
Expand Down

0 comments on commit 3d913d5

Please sign in to comment.