Physical and arcane damage

This commit is contained in:
2026-09-30 09:56:53 -03:00
parent 88659bb7af
commit 9e580f175e
9 changed files with 54 additions and 75 deletions
+5 -14
View File
@@ -129,27 +129,18 @@ Deno.test("hurting: a weaker hit right after does nothing, a harder one only the
assert(mob.hurt(1, DAMAGE.generic), "hurt normally again after the cooldown");
assertEquals(mob.health, 4);
ticks(11);
mob.absorption = 0;
mob.add_effect(new EffectInstance(EFFECTS.absorption, 100));
assertEquals(mob.absorption, 4);
mob.hurt(3, DAMAGE.generic);
assertEquals([mob.absorption, mob.health], [1, 4], "absorption goes first");
ticks(11);
mob.invulnerable = true;
assertEquals(mob.hurt(3, DAMAGE.generic), false);
assert(mob.hurt(1, DAMAGE.void), "falling out of the world hurts anyway");
});
Deno.test("armor takes some of the damage, and hits push away from the attacker", async () => {
Deno.test("hits push away from the attacker", async () => {
const { spawn, ticks } = await floor_game();
const mob = spawn(0.5, 100, 2.5);
ticks(2);
mob.attributes.get(ATTRIBUTES.armor)!.base = 10;
// minecraft: 10 armor against 5 damage takes 7.5 / 25 of it off
mob.hurt(5, { cause: "mob_attack", attacker: { id: "x", x: 0.5, y: 100, z: 0.5 } });
assertAlmostEquals(mob.health, 10 - 5 * (1 - 7.5 / 25));
mob.hurt(5, { type: "physical", cause: "mob_attack", attacker: { id: "x", x: 0.5, y: 100, z: 0.5 } });
assertEquals(mob.health, 5);
assert(mob.vz > 0 && mob.vy > 0, "knocked back, away from the attacker at a smaller z");
});
@@ -336,7 +327,7 @@ Deno.test("entities are saved with everything about them, riders on what they ri
mob.health = 6;
mob.add_effect(new EffectInstance(EFFECTS.speed, 100));
mob.add_effect(new EffectInstance(EFFECTS.speed, 10, { amplifier: 1 }));
mob.attributes.get(ATTRIBUTES.armor)!.base = 4;
mob.attributes.get(ATTRIBUTES.physical_shielding)!.base = 4;
mob.set_item_slot("mainhand", new ItemStack("bworld:stick"));
mob.restrict_to(1, 2, 3, 8);
assert(rider.start_riding(mob));
@@ -360,7 +351,7 @@ Deno.test("entities are saved with everything about them, riders on what they ri
const speed = horse.get_effect(EFFECTS.speed)!;
assertEquals([speed.amplifier, speed.duration, speed.hidden?.amplifier, speed.hidden?.duration], [1, 9, 0, 99]);
assertAlmostEquals(horse.attribute(ATTRIBUTES.movement_speed), 0.25 * 1.4);
assertEquals(horse.attribute(ATTRIBUTES.armor), 4);
assertEquals(horse.attribute(ATTRIBUTES.physical_shielding), 4);
assertEquals(horse.main_hand_item?.type_id, "bworld:stick");
assertEquals([horse.home, horse.home_radius], [{ x: 1, y: 2, z: 3 }, 8]);
assertEquals(loaded_rider.vehicle, horse);