Skip to content

Commit

Permalink
play
Browse files Browse the repository at this point in the history
  • Loading branch information
ToxicKevinFerm committed May 1, 2024
1 parent de64776 commit e75fe42
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 8 deletions.
94 changes: 94 additions & 0 deletions sim/core/dbc/dbc.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ var spellEffectDataJson string
//go:embed generated/data/spell_data.json
var spellDataJson string

//go:embed generated/data/spell_power_data.json
var spellPowerDataJson string

//go:embed generated/GameTables/SpellScaling.txt
var spellScalingFile string

Expand Down Expand Up @@ -318,6 +321,8 @@ func (dbc *DBC) loadSpellData() error {
spell.PowerID = uint(raw[38].(float64))
spell.EssenceID = uint(raw[39].(float64))
spell.Effects = make([]*SpellEffectData, 0)
spell.Power = make([]*SpellPowerData, 0)
spell.PowerCount = 0
spell.EffectsCount = 0

// Cache the spell
Expand All @@ -333,10 +338,69 @@ func (dbc *DBC) loadSpellData() error {
if spell.Category != 0 {
dbc.categoryMapping.AddSpell(spell.Category, spell)
}
var rawJson [][]interface{} // To accommodate the large array of arrays
if err := json.Unmarshal([]byte(spellPowerDataJson), &rawJson); err != nil {
log.Fatal(err)
}

// Assuming the first item in rawJson is the large array of SpellPowerData arrays
for _, item := range rawJson[0] {
entry := item.([]interface{}) // Each item is an array representing one SpellPowerData
spellPowerData := SpellPowerData{
ID: uint(entry[0].(float64)),
SpellID: uint(entry[1].(float64)),
AuraID: uint(entry[2].(float64)),
PowerType: int(entry[3].(float64)),
Cost: int(entry[4].(float64)),
CostMax: int(entry[5].(float64)),
CostPerTick: int(entry[6].(float64)),
PctCost: entry[7].(float64),
PctCostMax: entry[8].(float64),
PctCostPerTick: entry[9].(float64),
}
if dbc.spellIndex[spellPowerData.SpellID] != nil {
dbc.spellIndex[spellPowerData.SpellID].Power = append(dbc.spellIndex[spellPowerData.SpellID].Power, &spellPowerData)
dbc.spellIndex[spellPowerData.SpellID].PowerCount += 1
}
}
}

return nil
}
func (sd *SpellPowerData) GetMaxCost() float64 {
if sd.CostMax != 0 {
return float64(sd.CostMax) / sd.costDivisor(!(sd.Cost != 0))
}
return float64(sd.PctCostMax) / sd.costDivisor(!(sd.Cost != 0))
}

func (sd *SpellPowerData) GetCostPerTick() float64 {
return float64(sd.CostPerTick) / sd.costDivisor(!(sd.Cost != 0))
}

func (sd *SpellPowerData) GetCost() float64 {
cost := 0.0
if sd.Cost != 0 {
cost = float64(sd.Cost)
} else {
cost = sd.PctCost
}
return cost / sd.costDivisor(!(sd.Cost != 0))
}
func (sd *SpellPowerData) costDivisor(percentage bool) float64 {
switch sd.PowerType {
case POWER_MANA:
if percentage {
return 100.0
}
return 1.0
case POWER_RAGE, POWER_RUNIC_POWER, POWER_ASTRAL_POWER, POWER_SOUL_SHARDS:
return 10.0
default:
return 1.0
}

}

// FetchSpellEffect retrieves a spell effect based on an ID.
func (dbc *DBC) FetchSpellEffect(effectID uint) *SpellEffectData {
Expand Down Expand Up @@ -550,3 +614,33 @@ func (data *SpellData) classFlag(index uint) uint32 {
// Ensure the operation is performed within uint32 context
return uint32(data.ClassFlags[index/32]) & (1 << (index % 32))
}

type Power int

const (
POWER_HEALTH Power = -2
POWER_MANA = 0
POWER_RAGE = 1
POWER_FOCUS = 2
POWER_ENERGY = 3
POWER_HAPPINESS = 4
POWER_RUNE = 5
POWER_RUNIC_POWER = 6
POWER_SOUL_SHARDS = 7
POWER_ASTRAL_POWER = 8
POWER_HOLY_POWER = 9
POWER_MAELSTROM = 11
POWER_CHI = 12
POWER_INSANITY = 13
POWER_COMBO_POINT = 14
POWER_DEMONIC_FURY = 15
POWER_FURY = 17
POWER_PAIN = 18
POWER_ESSENSE = 19
POWER_BLOOD_RUNE = 20
POWER_FROST_RUNE = 21
POWER_UNHOLY_RUNE = 22
POWER_MAX = 23
POWER_NONE Power = 0xFFFFFFFF // To handle the 0xFFFFFFFF value
POWER_OFFSET = 2
)
4 changes: 0 additions & 4 deletions sim/core/dbc/spell_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ type Character interface {
const (
NUM_SPELL_FLAGS = 15
NUM_CLASS_FAMILY_FLAGS = 4
POWER_MANA = 0
POWER_INSANITY = 1
POWER_RAGE = 2
// Additional power types...
)

// Struct Definitions
Expand Down
56 changes: 54 additions & 2 deletions sim/core/spell_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package core

import (
"sync"
"time"

"github.com/wowsims/cata/sim/core/dbc"
)
Expand All @@ -21,6 +22,49 @@ func GetInstance() *SpellGen {
})
return instance
}
func (sc *SpellConfig) SetResourceCost(spell *dbc.SpellData) {
if spell.PowerCount != 0 {
for i := 0; i < int(spell.PowerCount); i++ {
power := spell.Power[i]
cost := power.GetCost()
switch power.PowerType {
case dbc.POWER_MANA:
sc.ManaCost = ManaCostOptions{
BaseCost: cost,
}
case dbc.POWER_RAGE:
sc.RageCost = RageCostOptions{
Cost: cost,
}
case dbc.POWER_FOCUS:
sc.FocusCost = FocusCostOptions{
Cost: cost,
}
case dbc.POWER_ENERGY:
sc.EnergyCost = EnergyCostOptions{
Cost: cost,
}
case dbc.POWER_COMBO_POINT:
// Combo points are set where?
case dbc.POWER_RUNIC_POWER:
// todo: probably need to instantiate this? but cant check if null
sc.RuneCost.RunicPowerCost = cost
case dbc.POWER_BLOOD_RUNE:
sc.RuneCost.BloodRuneCost = int8(cost)
case dbc.POWER_FROST_RUNE:
sc.RuneCost.BloodRuneCost = int8(cost)
case dbc.POWER_UNHOLY_RUNE:
sc.RuneCost.BloodRuneCost = int8(cost)
case dbc.POWER_SOUL_SHARDS:
// Where is this set?
case dbc.POWER_HOLY_POWER:
// Same here
default:
}
}

}
}

func (s *SpellGen) GetDBC() *dbc.DBC {
if s.dbc == nil {
Expand All @@ -40,6 +84,7 @@ func (sg *SpellGen) ParseSpellData(spellId uint, unit *Unit) *SpellConfig {
s.MissileSpeed = dbcSpell.PrjSpeed
s.SpellSchool = SpellSchool(dbcSpell.School) // Todo? Does this match 1 to 1?
//s.TicksCanCrit = dbcSpell.Flags()

s.Cast = CastConfig{
DefaultCast: Cast{
GCD: dbcSpell.GCD,
Expand All @@ -54,19 +99,24 @@ func (sg *SpellGen) ParseSpellData(spellId uint, unit *Unit) *SpellConfig {
//
}
if dbcSpell.HasPeriodicDamageEffect() {
s.Dot = DotConfig{}
s.Dot = DotConfig{
HasteAffectsDuration: dbcSpell.Flags(SX_DURATION_HASTED), // or SX_DOT_HASTED
AffectedByCastSpeed: dbcSpell.Flags(SX_DOT_HASTED), // POssible, need verification

}
}
return &s
}
func (sg *SpellGen) ParseEffects(dbcSpell *dbc.SpellData, spellConfig *SpellConfig, unit *Unit) {
effects := dbcSpell.Effects
for i := 0; i < int(dbcSpell.EffectsCount); i++ {
effect := effects[i]

switch effect.Type {
case dbc.E_SCHOOL_DAMAGE:
case dbc.E_HEALTH_LEECH:
//parse direct dmg mod
break
continue
case dbc.E_NORMALIZED_WEAPON_DMG:
//set normalised wpn dmg
case dbc.E_WEAPON_DAMAGE:
Expand All @@ -82,6 +132,8 @@ func (sg *SpellGen) ParseEffects(dbcSpell *dbc.SpellData, spellConfig *SpellConf
case dbc.A_PERIODIC_LEECH:
//parse effect periodic mods
//keep going
spellConfig.Dot.TickLength = time.Duration(effect.Amplitude) * time.Millisecond
spellConfig.BonusCoefficient = effect.SPCoeff
}

}
Expand Down
6 changes: 4 additions & 2 deletions sim/hunter/talents.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,10 @@ func (hunter *Hunter) applyPiercingShots() {
Label: "PiercingShots",
Duration: time.Second * 8,
},
NumberOfTicks: 8,
TickLength: time.Second * 1,
NumberOfTicks: 8,
HasteAffectsDuration: false,
AffectedByCastSpeed: false,
TickLength: time.Second * 1,
OnTick: func(sim *core.Simulation, target *core.Unit, dot *core.Dot) {
// Specifically account for bleed modifiers, since it still affects the spell, but we're ignoring all modifiers.
dot.SnapshotAttackerMultiplier = target.PseudoStats.PeriodicPhysicalDamageTakenMultiplier
Expand Down

0 comments on commit e75fe42

Please sign in to comment.