aboutsummaryrefslogtreecommitdiff
path: root/internal/combat/formulas.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-07-01 22:30:31 -0400
committerhistoria <[not public]>2026-07-01 22:30:31 -0400
commitc14c2e403c75a913e1a6d962fb6fe64f013adae5 (patch)
tree75070293fe2535b594ac72e501cbf08a3f1146e0 /internal/combat/formulas.go
parent8eec7b75ff9c8c368b252373db45fb891732d2ca (diff)
downloadthehouseoficarus-c14c2e403c75a913e1a6d962fb6fe64f013adae5.tar.gz
fix: combat formulas and mob attack types (mobs switch attack styles if safespotting)
Diffstat (limited to 'internal/combat/formulas.go')
-rw-r--r--internal/combat/formulas.go44
1 files changed, 31 insertions, 13 deletions
diff --git a/internal/combat/formulas.go b/internal/combat/formulas.go
index f4e1ba2..f165923 100644
--- a/internal/combat/formulas.go
+++ b/internal/combat/formulas.go
@@ -2,8 +2,24 @@ package combat
import "math/rand"
-func EffectiveRoll(level int, styleBonus int, equipBonus int) int {
- effective := level + styleBonus + 8
+func PlayerEffective(level, styleBonus int) int {
+ return level + styleBonus + 8
+}
+
+func NPCEffective(level int) int {
+ return level + 9
+}
+
+// ScienceEffective is the effective-level formula for science attacks. It is
+// intentionally the same as NPCEffective (level + 9) and is applied to BOTH the
+// attacker and defender of a science-mod exchange (see scienceAttack), giving a
+// symmetric science-vs-science model with no attack styles. It is kept as a
+// distinct function to document that intent independently of NPCEffective.
+func ScienceEffective(level int) int {
+ return level + 9
+}
+
+func AttackRoll(effective, equipBonus int) int {
return effective * (equipBonus + 64)
}
@@ -17,13 +33,11 @@ func HitChance(attackRoll, defenseRoll int) float64 {
}
func HitCheck(attackRoll, defenseRoll int) bool {
- chance := HitChance(attackRoll, defenseRoll)
- return rand.Float64() < chance
+ return rand.Float64() < HitChance(attackRoll, defenseRoll)
}
-func MaxHit(level int, styleBonus int, equipBonus int) int {
- effective := level + styleBonus + 8
- hit := (effective * (equipBonus + 64)) / 512
+func MaxHit(effective, equipStrBonus int) int {
+ hit := (effective*(equipStrBonus+64) + 320) / 640
if hit < 1 {
hit = 1
}
@@ -34,7 +48,11 @@ func RollDamage(maxHit int) int {
if maxHit <= 0 {
return 0
}
- return 1 + rand.Intn(maxHit)
+ d := rand.Intn(maxHit + 1)
+ if d < 1 {
+ d = 1
+ }
+ return d
}
func AttackStyleBonus(style string) (attack, strength, defense int) {
@@ -69,15 +87,15 @@ func RangedStyleBonus(style string) (ranged, defense int) {
func SelectBonus(attackType string, stab, slash, crush, science, ranged int) int {
switch attackType {
- case "stab":
+ case AttackStab:
return stab
- case "slash":
+ case AttackSlash:
return slash
- case "crush":
+ case AttackCrush:
return crush
- case "science":
+ case AttackScience:
return science
- case "ranged":
+ case AttackRanged:
return ranged
default:
return crush