(Underdepths) Prepare for final pass
This commit is contained in:
1 parent
b6d2a058e3
commit
9c1d8d8270
53 files changed
-5020
No files matched your search
@@ -1,27 +0,0 @@
|
||||
"""Combat resolution: hit chance, armor reduction, critical hits."""
|
||||
from __future__ import annotations
|
||||
|
||||
import random
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
|
||||
@dataclass
|
||||
class AttackRoll:
|
||||
hit: bool
|
||||
crit: bool
|
||||
damage: int
|
||||
|
||||
|
||||
def roll_attack(attacker: Any, defender: Any, rng: random.Random = random) -> AttackRoll:
|
||||
hit_chance = 0.7 + (attacker.accuracy - defender.evasion) * 0.05
|
||||
hit_chance = max(0.1, min(0.95, hit_chance))
|
||||
base = attacker.power + getattr(attacker, "weapon_power", 0)
|
||||
# Player exposes effective armor via total_armor(); plain objects/enemies use .armor.
|
||||
total_armor = getattr(defender, "total_armor", None)
|
||||
armor = total_armor() if callable(total_armor) else getattr(defender, "armor", 0)
|
||||
reduced = max(0, base - armor)
|
||||
if rng.random() >= hit_chance:
|
||||
return AttackRoll(hit=False, crit=False, damage=0)
|
||||
crit = rng.random() < attacker.crit_chance
|
||||
return AttackRoll(hit=True, crit=crit, damage=reduced * (2 if crit else 1))
|
||||
Reference in new issue
Block a user