Make server control knockback
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
import { test_game } from "../helpers.ts";
|
||||
Deno.test("kb", async () => {
|
||||
const t = await test_game("mods");
|
||||
t.join(1, "alice");
|
||||
t.join(2, "bob");
|
||||
for (let x = -8; x <= 8; x++) for (let z = -8; z <= 8; z++) t.game.set_block(x, 99, z, "bworld:stone");
|
||||
t.send(1, { type: "move", x: 0.5, y: 100, z: 0.5, yaw: 0, pitch: 0 });
|
||||
t.send(2, { type: "move", x: 0.5, y: 100, z: 2.5, yaw: 0, pitch: 0 });
|
||||
t.game.tick();
|
||||
t.take(2);
|
||||
const bob = t.game.players()[1];
|
||||
console.log("on_ground", bob.on_ground);
|
||||
t.send(1, { type: "attack_entity", id: bob.id });
|
||||
console.log("v after hurt", bob.vx, bob.vy, bob.vz, "health", bob.health);
|
||||
t.game.tick();
|
||||
console.log(t.take(2).filter((m) => m.type === "set_motion"));
|
||||
});
|
||||
+19
-3
@@ -172,11 +172,27 @@ Deno.test("players hit each other, knocking them back and flashing red for every
|
||||
|
||||
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"));
|
||||
|
||||
// bob's client sends nothing, like in a background tab, and the server knocks him back anyway
|
||||
ticks(1);
|
||||
assert(bob.z > 2.5 && bob.y > 100, "up and away from alice");
|
||||
const teleport = take(2).find((m) => m.type === "teleport");
|
||||
assert(teleport.motion[2] > 0, "his client keeps him going between updates");
|
||||
assert(take(1).some((m) => m.type === "player_move" && m.id === bob.id), "alice sees him move");
|
||||
const knocked_to = bob.z;
|
||||
send(2, { type: "move", x: 0.5, y: 100, z: 2.5, yaw: 0, pitch: 0, teleport: teleport.id });
|
||||
assertEquals(bob.z, knocked_to, "his own moves wait until he lands");
|
||||
|
||||
ticks(20);
|
||||
assertEquals(bob.knockback_ticks, undefined, "landed");
|
||||
assert(bob.on_ground && bob.z > knocked_to);
|
||||
const last = take(2).filter((m) => m.type === "teleport").at(-1);
|
||||
send(2, { type: "move", x: 0.5, y: 100, z: 2.5, yaw: 0, pitch: 0, teleport: last.id - 1 });
|
||||
assert(bob.z > knocked_to, "a move sent before hearing of the last one is ignored");
|
||||
send(2, { type: "move", x: 0.5, y: 100, z: 5, yaw: 0, pitch: 0, teleport: last.id });
|
||||
assertEquals(bob.z, 5, "his client moves him again");
|
||||
|
||||
send(1, { type: "attack_entity", id: alice.id });
|
||||
assertEquals(alice.health, 20, "not yourself");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user