Make players mobs too !
This commit is contained in:
@@ -161,6 +161,53 @@ Deno.test("players hit entities they can reach, pushing them away", async () =>
|
||||
send(1, { type: "attack_entity", id: "nothing" });
|
||||
});
|
||||
|
||||
Deno.test("players hit each other, knocking them back and flashing red for everyone else", async () => {
|
||||
const { game, ticks, send, join, take } = await floor_game();
|
||||
join(2, "bob");
|
||||
send(2, { type: "move", x: 0.5, y: 100, z: 2.5, yaw: 0, pitch: 0 });
|
||||
const [alice, bob] = game.players();
|
||||
ticks(1);
|
||||
take(1);
|
||||
take(2);
|
||||
|
||||
send(1, { type: "attack_entity", id: bob.id });
|
||||
assertEquals(bob.health, 19);
|
||||
ticks(1);
|
||||
const motion = take(2).find((m) => m.type === "set_motion");
|
||||
assert(motion && motion.vz > 0, "bob's client is told he's knocked back, away from alice");
|
||||
assert(take(1).some((m) => m.type === "entity_event" && m.id === bob.id && m.event === "hurt"));
|
||||
|
||||
send(1, { type: "attack_entity", id: alice.id });
|
||||
assertEquals(alice.health, 20, "not yourself");
|
||||
|
||||
// past the hurt cooldown, and whatever full hunger healed back
|
||||
ticks(20);
|
||||
bob.health = 1;
|
||||
send(1, { type: "attack_entity", id: bob.id });
|
||||
assert(take(1).some((m) => m.type === "chat" && m.text === "bob was slain by alice"));
|
||||
assertEquals(bob.health, 20, "respawned");
|
||||
send(1, { type: "attack_entity", id: bob.id });
|
||||
assertEquals(bob.health, 20, "too far away now, back at spawn");
|
||||
});
|
||||
|
||||
Deno.test("mobs hurt players like anything else, and mods still get a say", async () => {
|
||||
const { game, spawn, ticks } = await floor_game();
|
||||
const alice = game.players()[0];
|
||||
const causes: string[] = [];
|
||||
game.mods.before.player_damage.for_mod("test").subscribe((event) => causes.push(event.cause));
|
||||
const mob = spawn(0.5, 100, 1.5);
|
||||
ticks(1);
|
||||
|
||||
assert(mob.do_hurt_target(alice));
|
||||
assertEquals(alice.health, 18);
|
||||
assertEquals(causes, ["mob_attack"]);
|
||||
assertEquals(alice.last_hurt_by_mob, mob.id);
|
||||
assertEquals(mob.do_hurt_target(alice), false, "not again straight away");
|
||||
|
||||
game.on_disconnect(1);
|
||||
assertEquals(alice.alive, false, "gone, so mobs after her give up");
|
||||
});
|
||||
|
||||
Deno.test("dying: it drops what it had, falls over for a second and is gone", async () => {
|
||||
const { game, spawn, take, ticks } = await floor_game();
|
||||
const mob = spawn(0.5, 100, 2.5);
|
||||
|
||||
Reference in New Issue
Block a user