Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add avoidance calculation methods #37

Merged
merged 2 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sim/core/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ type Hand bool

const MainHand Hand = true
const OffHand Hand = false

const CombatTableCoverageCap = 1.024 // 102.4% chance to avoid an attack
18 changes: 4 additions & 14 deletions sim/core/spell_outcome.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ func (result *SpellResult) applyAttackTableHit(spell *Spell) {
}

func (result *SpellResult) applyEnemyAttackTableMiss(spell *Spell, attackTable *AttackTable, roll float64, chance *float64) bool {
missChance := attackTable.BaseMissChance + spell.Unit.PseudoStats.IncreasedMissChance + result.Target.GetDiminishedMissChance() + result.Target.PseudoStats.ReducedPhysicalHitTakenChance
missChance := result.Target.GetTotalChanceToBeMissedAsDefender(attackTable) + spell.Unit.PseudoStats.IncreasedMissChance
if spell.Unit.AutoAttacks.IsDualWielding && !spell.Unit.PseudoStats.DisableDWMissPenalty {
missChance += 0.19
}
Expand All @@ -524,10 +524,7 @@ func (result *SpellResult) applyEnemyAttackTableBlock(spell *Spell, attackTable
return false
}

blockChance := attackTable.BaseBlockChance +
result.Target.stats[stats.Block]/BlockRatingPerBlockChance/100 +
result.Target.stats[stats.Defense]*DefenseRatingToChanceReduction
*chance += max(0, blockChance)
*chance = result.Target.GetTotalBlockChanceAsDefender(attackTable)

if roll < *chance {
result.Outcome |= OutcomeBlock
Expand All @@ -543,11 +540,7 @@ func (result *SpellResult) applyEnemyAttackTableDodge(spell *Spell, attackTable
return false
}

dodgeChance := attackTable.BaseDodgeChance +
result.Target.PseudoStats.BaseDodge +
result.Target.GetDiminishedDodgeChance() -
spell.Unit.PseudoStats.DodgeReduction
*chance += max(0, dodgeChance)
*chance = max(result.Target.GetTotalDodgeChanceAsDefender(attackTable)-spell.Unit.PseudoStats.DodgeReduction, 0.0)

if roll < *chance {
result.Outcome = OutcomeDodge
Expand All @@ -563,10 +556,7 @@ func (result *SpellResult) applyEnemyAttackTableParry(spell *Spell, attackTable
return false
}

parryChance := attackTable.BaseParryChance +
result.Target.PseudoStats.BaseParry +
result.Target.GetDiminishedParryChance()
*chance += max(0, parryChance)
*chance = result.Target.GetTotalParryChanceAsDefender(attackTable)

if roll < *chance {
result.Outcome = OutcomeParry
Expand Down
37 changes: 37 additions & 0 deletions sim/core/unit.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package core

import (
"math"
"time"

"github.com/wowsims/cata/sim/core/proto"
Expand Down Expand Up @@ -556,3 +557,39 @@ func (unit *Unit) GetMetadata() *proto.UnitMetadata {
func (unit *Unit) ExecuteCustomRotation(sim *Simulation) {
panic("Unimplemented ExecuteCustomRotation")
}

func (unit *Unit) GetTotalDodgeChanceAsDefender(atkTable *AttackTable) float64 {
chance := unit.PseudoStats.BaseDodge +
atkTable.BaseDodgeChance +
unit.GetDiminishedDodgeChance()
return math.Max(chance, 0.0)
}

func (unit *Unit) GetTotalParryChanceAsDefender(atkTable *AttackTable) float64 {
chance := unit.PseudoStats.BaseParry +
atkTable.BaseParryChance +
unit.GetDiminishedParryChance()
return math.Max(chance, 0.0)
}

func (unit *Unit) GetTotalChanceToBeMissedAsDefender(atkTable *AttackTable) float64 {
chance := atkTable.BaseMissChance +
unit.GetDiminishedMissChance() +
unit.PseudoStats.ReducedPhysicalHitTakenChance
return math.Max(chance, 0.0)
}

func (unit *Unit) GetTotalBlockChanceAsDefender(atkTable *AttackTable) float64 {
chance := atkTable.BaseBlockChance +
unit.GetStat(stats.Block)/BlockRatingPerBlockChance/100 +
unit.GetStat(stats.Defense)*DefenseRatingToChanceReduction
return math.Max(chance, 0.0)
}

func (unit *Unit) GetTotalAvoidanceChance(atkTable *AttackTable) float64 {
miss := unit.GetTotalChanceToBeMissedAsDefender(atkTable)
dodge := unit.GetTotalDodgeChanceAsDefender(atkTable)
parry := unit.GetTotalParryChanceAsDefender(atkTable)
block := unit.GetTotalBlockChanceAsDefender(atkTable)
return miss + dodge + parry + block
}
Loading