Ensure that damage takes into effect stat bonuses from equipment

This commit is contained in:
Peter Stockings
2026-01-27 17:48:20 +11:00
parent 165cde6ca3
commit cdedf47e0d
4 changed files with 220 additions and 28 deletions

View File

@@ -1,4 +1,5 @@
import type { World, EntityId, Action, SimEvent, Actor, CombatantActor, CollectibleActor, ActorType } from "../../core/types";
import { calculateDamage } from "../gameplay/CombatLogic";
import { isBlocked, tryDestructTile } from "../world/world-logic";
import { isDestructibleByWalk } from "../../core/terrain";
@@ -119,11 +120,10 @@ function handleAttack(_w: World, actor: Actor, action: { targetId: EntityId }, a
if (target && target.category === "combatant" && actor.category === "combatant") {
const events: SimEvent[] = [{ type: "attacked", attackerId: actor.id, targetId: action.targetId }];
// 1. Accuracy vs Evasion Check
const hitChance = actor.stats.accuracy - target.stats.evasion;
const hitRoll = Math.random() * 100;
// 1. Calculate Damage
const result = calculateDamage(actor.stats, target.stats);
if (hitRoll > hitChance) {
if (!result.hit) {
events.push({
type: "dodged",
targetId: action.targetId,
@@ -133,23 +133,9 @@ function handleAttack(_w: World, actor: Actor, action: { targetId: EntityId }, a
return events;
}
// 2. Base Damage Calculation
let dmg = Math.max(1, actor.stats.attack - target.stats.defense);
// 3. Critical Strike Check
const critRoll = Math.random() * 100;
const isCrit = critRoll < actor.stats.critChance;
if (isCrit) {
dmg = Math.floor(dmg * (actor.stats.critMultiplier / 100));
}
// 4. Block Chance Check
const blockRoll = Math.random() * 100;
let isBlock = false;
if (blockRoll < target.stats.blockChance) {
dmg = Math.floor(dmg * 0.5);
isBlock = true;
}
const dmg = result.dmg;
const isCrit = result.isCrit;
const isBlock = result.isBlock;
target.stats.hp -= dmg;