Skip to content

Commit

Permalink
Merge pull request #4003 from vigo2/vigo/dk-rune-costs
Browse files Browse the repository at this point in the history
dk-rune-costs
  • Loading branch information
vigo2 authored Nov 5, 2023
2 parents 147e77d + 75c3c70 commit 10ac32b
Show file tree
Hide file tree
Showing 4 changed files with 604 additions and 591 deletions.
27 changes: 18 additions & 9 deletions sim/core/runic_power.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,17 @@ func (rp *runicPowerBar) spendRuneCost(sim *Simulation, spell *Spell, cost RuneC
for i := int8(0); i < u; i++ {
slots = append(slots, rp.spendRune(sim, 4, spell.UnholyRuneMetrics()))
}
for i := int8(0); i < d; i++ {
slots = append(slots, rp.spendDeathRune(sim, spell.DeathRuneMetrics()))
if d > 0 {
defaultCost := RuneCost(spell.DefaultCast.Cost)
for i, mu := int8(0), defaultCost.Unholy()-u; i < mu; i++ {
slots = append(slots, rp.spendDeathRune(sim, []int8{4, 5, 2, 3, 0, 1}, spell.DeathRuneMetrics()))
}
for i, mf := int8(0), defaultCost.Frost()-f; i < mf; i++ {
slots = append(slots, rp.spendDeathRune(sim, []int8{2, 3, 4, 5, 0, 1}, spell.DeathRuneMetrics()))
}
for i, mb := int8(0), defaultCost.Blood()-b; i < mb; i++ {
slots = append(slots, rp.spendDeathRune(sim, []int8{0, 1, 4, 5, 2, 3}, spell.DeathRuneMetrics()))
}
}

if rpc := cost.RunicPower(); rpc > 0 {
Expand Down Expand Up @@ -748,8 +757,8 @@ func (rp *runicPowerBar) findReadyRune(slot int8) int8 {
panic(fmt.Sprintf("findReadyRune(%d) - no slot found (runeStates = %12b)", slot, rp.runeStates))
}

func (rp *runicPowerBar) spendDeathRune(sim *Simulation, metrics *ResourceMetrics) int8 {
slot := rp.findReadyDeathRune()
func (rp *runicPowerBar) spendDeathRune(sim *Simulation, order []int8, metrics *ResourceMetrics) int8 {
slot := rp.findReadyDeathRune(order)
if rp.btSlot != slot {
rp.runeMeta[slot].revertAt = NeverExpires // disable revert at
rp.runeStates ^= isDeaths[slot] // clear death bit to revert.
Expand All @@ -763,9 +772,9 @@ func (rp *runicPowerBar) spendDeathRune(sim *Simulation, metrics *ResourceMetric
return slot
}

// findReadyDeathRune returns the slot of first available death rune.
func (rp *runicPowerBar) findReadyDeathRune() int8 {
for _, slot := range []int8{4, 5, 2, 3, 0, 1} { // Death runes are spent in the order Unholy -> Frost -> Blood in-game...
// findReadyDeathRune returns the slot of first available death rune in the order given.
func (rp *runicPowerBar) findReadyDeathRune(order []int8) int8 {
for _, slot := range order {
if rp.runeStates&isSpentDeath[slot] == isDeaths[slot] {
return slot
}
Expand Down Expand Up @@ -802,7 +811,7 @@ type RuneCostImpl struct {
}

func newRuneCost(spell *Spell, options RuneCostOptions) *RuneCostImpl {
baseCost := float64(NewRuneCost(int8(options.RunicPowerCost), options.BloodRuneCost, options.FrostRuneCost, options.UnholyRuneCost, 0))
baseCost := float64(NewRuneCost(int16(options.RunicPowerCost), options.BloodRuneCost, options.FrostRuneCost, options.UnholyRuneCost, 0))
spell.DefaultCast.Cost = baseCost
spell.CurCast.Cost = baseCost

Expand Down Expand Up @@ -844,7 +853,7 @@ func (rc *RuneCostImpl) MeetsRequirement(spell *Spell) bool {
return true
}

func (rc *RuneCostImpl) CostFailureReason(sim *Simulation, spell *Spell) string {
func (rc *RuneCostImpl) CostFailureReason(_ *Simulation, _ *Spell) string {
return "not enough RP or runes"
}

Expand Down
26 changes: 15 additions & 11 deletions sim/core/runic_power_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import (
"time"
)

// RuneCost's bit layout is: <rrrr_rrrr_dduu_ffbb>. Each part is just a count now (0..3 for runes).
type RuneCost uint16
// RuneCost's bit layout is: <16r.4d.4u.4f.4b>. Each part is just a count now (0..15 for runes).
type RuneCost int32

func NewRuneCost(rp, blood, frost, unholy, death int8) RuneCost {
return RuneCost(rp)<<8 | RuneCost((death&0b11)<<6|(unholy&0b11)<<4|(frost&0b11)<<2|blood&0b11)
func NewRuneCost(rp int16, blood, frost, unholy, death int8) RuneCost {
return RuneCost(rp)<<16 |
RuneCost(death&0xf)<<12 |
RuneCost(unholy&0xf)<<8 |
RuneCost(frost&0xf)<<4 |
RuneCost(blood&0xf)
}

func (rc RuneCost) String() string {
Expand All @@ -18,27 +22,27 @@ func (rc RuneCost) String() string {

// HasRune returns if this cost includes a rune portion.
func (rc RuneCost) HasRune() bool {
return rc&0b1111_1111 > 0
return rc&0xffff > 0
}

func (rc RuneCost) RunicPower() int8 {
return int8(rc >> 8)
func (rc RuneCost) RunicPower() int16 {
return int16(rc >> 16)
}

func (rc RuneCost) Blood() int8 {
return int8(rc & 0b11)
return int8(rc & 0xf)
}

func (rc RuneCost) Frost() int8 {
return int8((rc >> 2) & 0b11)
return int8((rc >> 4) & 0xf)
}

func (rc RuneCost) Unholy() int8 {
return int8((rc >> 4) & 0b11)
return int8((rc >> 8) & 0xf)
}

func (rc RuneCost) Death() int8 {
return int8((rc >> 6) & 0b11)
return int8((rc >> 12) & 0xf)
}

type Predictor struct {
Expand Down
Loading

0 comments on commit 10ac32b

Please sign in to comment.