server/scripts/tests/e2/horses.lua
2019-09-10 06:40:42 +02:00

118 lines
3.6 KiB
Lua

require "lunit"
module("tests.e2.capacity", package.seeall, lunit.testcase)
function setup()
eressea.free_game()
eressea.settings.set("rules.food.flags", "4")
eressea.settings.set("nmr.timeout", "0")
eressea.settings.set("NewbieImmunity", "0")
end
function test_walk()
local r1 = region.create(0, 0, "plain")
local r2 = region.create(1, 0, "plain")
local f = faction.create("human", "pirate@eressea.de", "de")
local u1 = unit.create(f, r1, 1)
local u2 = unit.create(f, r1, 2)
local u3 = unit.create(f, r1, 1)
u1:add_item("money", 540)
u1:add_order("NACH O")
u2:add_item("money", 1080)
u2:add_order("NACH O")
u3:add_item("money", 541)
u3:add_order("NACH O")
process_orders()
assert_equal(r2, u1.region)
assert_equal(r2, u2.region)
assert_equal(r1, u3.region)
end
function test_lead_horses()
local r1 = region.create(0, 0, "plain")
local r2 = region.create(1, 0, "plain")
local r3 = region.create(2, 0, "plain")
local f = faction.create("human")
-- walk (don't ride) a horse to the next region:
local u1 = unit.create(f, r1, 1)
u1:add_item("horse", 1)
u1:add_item("money", 2540)
u1:add_order("NACH O O")
-- too heavy to move:
local u2 = unit.create(f, r1, 1)
u2:add_item("horse", 1)
u2:add_item("money", 2541)
u2:add_order("NACH O O")
-- too many horses:
local u3 = unit.create(f, r1, 1)
u3:add_item("horse", 2)
u3:add_item("money", 2540)
u3:add_order("NACH O O")
-- riders can lead 4 extra horses per level:
local u4 = unit.create(f, r1, 1)
u4:set_skill("riding", 1)
u4:add_item("horse", 5)
u4:add_item("money", 540+2000*5)
u4:add_order("NACH O O")
process_orders()
assert_equal(r2, u1.region)
assert_equal(r1, u2.region)
assert_equal(r1, u3.region)
assert_equal(r2, u4.region)
end
function test_ride_horses()
local r0 = region.create(0, 0, "plain")
local r1 = region.create(1, 0, "plain")
local r2 = region.create(2, 0, "plain")
local r3 = region.create(3, 0, "plain")
local f = faction.create("human")
-- ride a horse two regions:
local u1 = unit.create(f, r0, 1)
u1:set_skill("riding", 1)
u1:add_item("horse", 1)
u1:add_item("money", 1000)
u1:add_order("NACH O O O")
-- too heavy to ride, walk the horse:
local u2 = unit.create(f, r0, 1)
u2:set_skill("riding", 1)
u2:add_item("horse", 1)
u2:add_item("money", 2001)
u2:add_order("NACH O O O")
process_orders()
-- mit 20 GE beladenes Pferd kommt 2 Regionen weit:
assert_equal(r2, u1.region)
-- überladenes Pferd kommt nur eine Region weit, zu Fuss:
assert_equal(r1, u2.region)
end
function test_rider_leads_horses()
local r0 = region.create(0, 0, "plain")
local r1 = region.create(1, 0, "plain")
local r2 = region.create(2, 0, "plain")
local r3 = region.create(3, 0, "plain")
local f = faction.create("human")
-- lead 1 extra horse per level while riding:
local u1 = unit.create(f, r0, 1)
u1:set_skill("riding", 1)
u1:add_item("horse", 2)
u1:add_order("NACH O O O")
-- too heavy to ride, walk the horses:
local u2 = unit.create(f, r0, 1)
u2:set_skill("riding", 1)
u2:add_item("horse", 2)
u2:add_item("money", 2000 * 2)
u2:add_order("NACH O O")
-- too many horses, but can walk:
local u3 = unit.create(f, r0, 1)
u3:set_skill("riding", 1)
u3:add_item("horse", 5)
u3:add_order("NACH O O")
process_orders()
assert_equal(r2, u1.region)
assert_equal(r1, u2.region)
assert_equal(r1, u3.region)
end