2020-04-22 03:03:44 +02:00
|
|
|
local tcname = 'tests.e3.items'
|
2020-05-03 16:52:40 +02:00
|
|
|
local lunit = require('lunit')
|
2020-04-22 03:03:44 +02:00
|
|
|
if _VERSION >= 'Lua 5.2' then
|
|
|
|
_ENV = module(tcname, 'seeall')
|
|
|
|
else
|
2020-05-03 16:52:40 +02:00
|
|
|
module(tcname, lunit.testcase, package.seeall)
|
2020-04-22 03:03:44 +02:00
|
|
|
end
|
2017-02-28 10:48:27 +01:00
|
|
|
|
|
|
|
function setup()
|
|
|
|
eressea.game.reset()
|
|
|
|
eressea.settings.set("rules.food.flags", "4") -- food is free
|
|
|
|
eressea.settings.set("NewbieImmunity", "0")
|
2017-03-03 16:50:43 +01:00
|
|
|
end
|
|
|
|
|
2017-12-26 13:23:14 +01:00
|
|
|
function test_water_of_life()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2017-12-26 15:57:59 +01:00
|
|
|
r:set_flag(1, false) -- no mallorn
|
2017-12-26 13:23:14 +01:00
|
|
|
local f = faction.create("human")
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
local trees = r:get_resource('tree')
|
2017-12-27 07:11:21 +01:00
|
|
|
u:add_item('p2', 1)
|
2017-12-26 13:23:14 +01:00
|
|
|
u:add_item('log', 10)
|
|
|
|
u:add_order("BENUTZE 1 'Wasser des Lebens'")
|
2017-12-26 16:09:15 +01:00
|
|
|
u:add_order("ZEIGE 'Wasser des Lebens'")
|
2017-12-26 13:23:14 +01:00
|
|
|
process_orders()
|
2017-12-27 07:11:21 +01:00
|
|
|
assert_equal(0, u:get_item('p2'))
|
2017-12-26 13:23:14 +01:00
|
|
|
assert_equal(5, u:get_item('log'))
|
2017-12-27 07:11:21 +01:00
|
|
|
trees = r:get_resource('tree')-trees
|
|
|
|
if trees~=5 then
|
|
|
|
init_reports()
|
|
|
|
write_report(f)
|
|
|
|
print(f, get_turn())
|
|
|
|
end
|
|
|
|
assert_equal(5, trees)
|
2017-12-26 13:23:14 +01:00
|
|
|
end
|
|
|
|
|
2017-03-03 16:50:43 +01:00
|
|
|
function test_give_horses()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "noreply@eressea.de", "de")
|
2017-03-03 16:50:43 +01:00
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
|
|
|
|
r:set_resource("horse", 0)
|
|
|
|
u:add_item("charger", 20)
|
|
|
|
u:add_order("GIB 0 10 Streitross")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(10, r:get_resource("horse"))
|
|
|
|
assert_equal(10, u:get_item("charger"))
|
2017-02-28 10:48:27 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function test_goblins()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f1 = faction.create("goblin", "goblin@eressea.de", "de")
|
|
|
|
local f2 = faction.create("dwarf", "dwarf@eressea.de", "de")
|
|
|
|
local f3 = faction.create("elf", "elf@eressea.de", "de")
|
2017-02-28 11:07:32 +01:00
|
|
|
local ud = unit.create(f1, r, 1)
|
|
|
|
local uh = unit.create(f1, r, 1)
|
|
|
|
uh.race = "halfling"
|
2017-02-28 10:48:27 +01:00
|
|
|
local u2 = unit.create(f2, r, 1)
|
|
|
|
local u3 = unit.create(f3, r, 1)
|
|
|
|
|
|
|
|
local restricted = {
|
|
|
|
"towershield", "rep_crossbow", "plate", "lance",
|
2017-03-03 09:56:27 +01:00
|
|
|
"mallornlance", "greatbow", "greataxe", "axe", "scale",
|
|
|
|
"plate", "halberd", "greatsword", "rustyhalberd"
|
2017-02-28 10:48:27 +01:00
|
|
|
}
|
|
|
|
for k, v in ipairs(restricted) do
|
2017-02-28 11:07:32 +01:00
|
|
|
ud:add_item(v, 1)
|
|
|
|
uh:add_item(v, 1)
|
2017-02-28 10:48:27 +01:00
|
|
|
u2:add_item(v, 1)
|
2017-02-28 10:58:09 +01:00
|
|
|
u3:add_item(v, 1)
|
2017-02-28 10:48:27 +01:00
|
|
|
end
|
|
|
|
|
2017-02-28 11:07:32 +01:00
|
|
|
uh:add_order("ATTACKIERE " .. itoa36(u2.id))
|
|
|
|
uh:add_order("ATTACKIERE " .. itoa36(u3.id))
|
|
|
|
ud:add_order("ATTACKIERE " .. itoa36(u2.id))
|
|
|
|
ud:add_order("ATTACKIERE " .. itoa36(u3.id))
|
2017-02-28 10:48:27 +01:00
|
|
|
process_orders()
|
|
|
|
end
|
2017-03-03 18:02:43 +01:00
|
|
|
|
|
|
|
function test_make_horse()
|
|
|
|
eressea.settings.set("rules.horses.growth", "0")
|
|
|
|
local r = region.create(0, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "horses@eressea.de", "de")
|
2017-03-03 18:02:43 +01:00
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
u:set_skill("training", 4)
|
|
|
|
r:set_resource("horse", 100)
|
|
|
|
u:add_order("MACHE 1 PFERD")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(1, u:get_item("horse"))
|
|
|
|
assert_equal(99, r:get_resource("horse"))
|
|
|
|
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("MACHE 1 STREITROSS")
|
|
|
|
u:add_item("money", 200)
|
|
|
|
u:add_item("iron", 1)
|
|
|
|
process_orders()
|
|
|
|
assert_equal(1, u:get_item("charger"))
|
|
|
|
assert_equal(0, u:get_item("horse"))
|
|
|
|
assert_equal(0, u:get_item("iron"))
|
|
|
|
assert_equal(0, u:get_item("money"))
|
|
|
|
assert_equal(99, r:get_resource("horse"))
|
|
|
|
end
|