Sign in
mod

Sparring

by Potluck · version 1 · Checked for all ages

Where a world's rules let players hurt each other (a server's pvp, or Players can hurt each other on the world's Change page), a hit from another player hurts: a fist a little, a sword by how good it is, a weapon another creation made by its power and a Keen one harder, less what armor keeps off. After a hit there's a moment's grace. Where the rules don't let them, a hit only says so.

1--!strict
2-- Sparring's own tests: `potluck-server --test=sparring`.
3
4local test = require("@potluck/test@0.9")
5local world = require("@potluck/world@0.28")
6
7local function two()
8 local a = test.player("Ada", { survival = true })
9 local b = test.player("Bo", { survival = true, at = a.position + vector.create(1.5, 0, 0) })
10 return a, b
11end
12
13test.case("where the rules don't let players hurt each other, a hit only says so", function()
14 local a, b = two()
15 test.same(world.rule("pvp"), false, "players can't hurt each other unless the rules say")
16 test.hit(a, b)
17 test.same(test.health(b), 20, "unhurt")
18 test.same(test.shown(a, "sparring"), "Players can't hurt each other in this world.")
19end)
20
21test.case("where they do, a fist hurts a little and a sword more", function()
22 test.rule("pvp", true)
23 local a, b = two()
24 test.hit(a, b)
25 test.same(test.health(b), 19, "a fist")
26 test.wait(1)
27 test.hold(a, "Iron sword")
28 test.hit(a, b)
29 test.same(test.health(b), 15, "an iron sword")
30end)
31
32test.case("a moment's grace after each hit", function()
33 test.rule("pvp", true)
34 local a, b = two()
35 test.hold(a, "Stone sword")
36 test.hit(a, b)
37 test.hit(a, b)
38 test.same(test.health(b), 17, "only the first of two quick hits")
39 test.wait(1)
40 test.hit(a, b)
41 test.same(test.health(b), 14, "then another")
42end)
43
44test.case("nobody in creative is hurt", function()
45 test.rule("pvp", true)
46 local a = test.player("Ada", { survival = true })
47 local b = test.player("Bo", { at = a.position + vector.create(1.5, 0, 0) })
48 test.hit(a, b)
49 test.same(test.health(b) or 20, 20, "creative")
50end)