2020-04-19 21:35:48 +02:00
|
|
|
local tcname = 'tests.shared.items'
|
|
|
|
local lunit = require("lunit")
|
|
|
|
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-19 21:35:48 +02:00
|
|
|
end
|
2017-02-27 18:21:41 +01:00
|
|
|
|
|
|
|
function setup()
|
|
|
|
eressea.free_game()
|
|
|
|
eressea.settings.set("nmr.timeout", "0")
|
2018-01-22 19:30:56 +01:00
|
|
|
eressea.settings.set("NewbieImmunity", "0")
|
2017-02-27 18:21:41 +01:00
|
|
|
eressea.settings.set("rules.food.flags", "4")
|
|
|
|
eressea.settings.set("rules.ship.storms", "0")
|
|
|
|
eressea.settings.set("magic.regeneration.enable", "0")
|
|
|
|
end
|
|
|
|
|
2018-01-21 18:07:49 +01:00
|
|
|
function test_use_mistletoe()
|
2017-02-27 19:35:14 +01:00
|
|
|
local r = region.create(0, 0, "plain")
|
2018-01-19 17:17:32 +01:00
|
|
|
local f = faction.create("human")
|
2017-02-27 19:35:14 +01:00
|
|
|
local u = unit.create(f, r, 1)
|
2018-01-21 18:07:49 +01:00
|
|
|
u:add_item('mistletoe', 3)
|
|
|
|
u:add_order("BENUTZEN 2 Mistelzweig")
|
2018-01-21 11:18:06 +01:00
|
|
|
process_orders()
|
2018-01-21 18:07:49 +01:00
|
|
|
assert_equal(2, u:effect('mistletoe'))
|
2017-02-27 19:35:14 +01:00
|
|
|
assert_equal(1, u:get_item('mistletoe'))
|
|
|
|
assert_equal(1, f:count_msg_type('use_item'))
|
|
|
|
end
|
|
|
|
|
2018-01-21 18:13:42 +01:00
|
|
|
function test_mistletoe_survive()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local u = unit.create(faction.create("human"), r, 1)
|
|
|
|
local u2 = unit.create(faction.create("human"), r, 1)
|
|
|
|
local uno = u.id
|
|
|
|
u:add_item('mistletoe', 2)
|
|
|
|
u:add_order("BENUTZEN 2 Mistelzweig")
|
|
|
|
u2:add_order('ATTACKIERE ' .. itoa36(uno))
|
|
|
|
process_orders()
|
|
|
|
u = get_unit(uno)
|
|
|
|
assert_not_nil(u)
|
|
|
|
assert_equal(1, u:effect('mistletoe'))
|
|
|
|
end
|
|
|
|
|
2017-02-27 18:50:48 +01:00
|
|
|
function test_dreameye()
|
2017-02-27 18:21:41 +01:00
|
|
|
local r = region.create(0, 0, "plain")
|
2018-01-19 17:17:32 +01:00
|
|
|
local f = faction.create("human")
|
2017-02-27 18:21:41 +01:00
|
|
|
local u = unit.create(f, r, 1)
|
2017-02-27 18:50:48 +01:00
|
|
|
u:add_item("dreameye", 2)
|
2017-02-27 18:21:41 +01:00
|
|
|
u:clear_orders()
|
2017-02-27 18:50:48 +01:00
|
|
|
u:add_order("BENUTZEN 1 Traumauge")
|
2017-02-27 20:16:50 +01:00
|
|
|
assert_nil(u:get_curse('skillmod'))
|
2017-02-27 19:35:14 +01:00
|
|
|
turn_begin()
|
|
|
|
turn_process()
|
2017-02-27 20:16:50 +01:00
|
|
|
assert_not_nil(u:get_curse('skillmod'))
|
2017-02-27 18:50:48 +01:00
|
|
|
assert_equal(1, u:get_item("dreameye"))
|
|
|
|
assert_equal(1, f:count_msg_type('use_tacticcrystal'))
|
2017-02-27 19:35:14 +01:00
|
|
|
turn_end()
|
2017-02-27 20:26:48 +01:00
|
|
|
assert_nil(u:get_curse('skillmod'))
|
2017-02-27 18:21:41 +01:00
|
|
|
end
|
|
|
|
|
2017-02-27 18:50:48 +01:00
|
|
|
function test_manacrystal()
|
2017-02-27 18:21:41 +01:00
|
|
|
local r = region.create(0, 0, "plain")
|
2018-01-19 17:17:32 +01:00
|
|
|
local f = faction.create("human")
|
2017-02-27 18:21:41 +01:00
|
|
|
local u = unit.create(f, r, 1)
|
2017-02-27 18:50:48 +01:00
|
|
|
u:add_item("manacrystal", 2)
|
2017-02-27 18:21:41 +01:00
|
|
|
u:clear_orders()
|
2017-02-27 18:50:48 +01:00
|
|
|
u.magic = "gwyrrd"
|
|
|
|
u:set_skill('magic', 1)
|
|
|
|
u.aura = 0
|
|
|
|
u:add_order("BENUTZEN 1 Astralkristall")
|
2017-02-27 19:35:14 +01:00
|
|
|
turn_begin()
|
|
|
|
turn_process()
|
2017-02-27 18:50:48 +01:00
|
|
|
assert_equal(1, u:get_item("manacrystal"))
|
|
|
|
assert_equal(25, u.aura)
|
|
|
|
assert_equal(1, f:count_msg_type('manacrystal_use'))
|
2017-02-27 19:35:14 +01:00
|
|
|
turn_end()
|
2017-02-27 18:21:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function test_skillpotion()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2018-01-19 17:17:32 +01:00
|
|
|
local f = faction.create("human")
|
2017-02-27 18:21:41 +01:00
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
u:add_item("skillpotion", 2)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("BENUTZEN 1 Talenttrunk")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(1, u:get_item("skillpotion"))
|
|
|
|
assert_equal(1, f:count_msg_type('skillpotion_use'))
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_studypotion()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2018-01-19 17:17:32 +01:00
|
|
|
local f = faction.create("human")
|
2017-02-27 18:21:41 +01:00
|
|
|
local u = unit.create(f, r, 1)
|
2017-02-27 20:16:50 +01:00
|
|
|
turn_begin()
|
2017-02-27 18:21:41 +01:00
|
|
|
u:add_item("studypotion", 2)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("LERNE Unterhaltung")
|
|
|
|
u:add_order("BENUTZEN 1 Lerntrank")
|
2017-02-27 20:16:50 +01:00
|
|
|
turn_process()
|
|
|
|
-- cannot sense the "learning" attribute, because study_cmd
|
|
|
|
-- removes it during processing :(
|
2017-02-27 18:21:41 +01:00
|
|
|
assert_equal(1, u:get_item("studypotion"))
|
2017-02-27 20:16:50 +01:00
|
|
|
turn_end()
|
2017-02-27 18:21:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function test_antimagic()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2018-01-19 17:17:32 +01:00
|
|
|
local f = faction.create("human")
|
2017-02-27 18:21:41 +01:00
|
|
|
local u = unit.create(f, r, 1)
|
2017-02-27 20:16:50 +01:00
|
|
|
|
|
|
|
turn_begin()
|
2017-02-27 18:21:41 +01:00
|
|
|
u:add_item("antimagic", 2)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("BENUTZEN 1 Antimagiekristall")
|
2017-02-27 20:16:50 +01:00
|
|
|
assert_equal(nil, r:get_curse('antimagiczone'))
|
|
|
|
turn_process()
|
|
|
|
assert_equal(5, r:get_curse('antimagiczone'))
|
2017-02-27 18:21:41 +01:00
|
|
|
assert_equal(1, r:count_msg_type('use_antimagiccrystal'))
|
|
|
|
assert_equal(1, u:get_item("antimagic"))
|
2017-02-27 20:16:50 +01:00
|
|
|
turn_end()
|
|
|
|
assert_equal(5, r:get_curse('antimagiczone')) -- haelt zwei wochen
|
|
|
|
turn_end() -- hack: age the curse again
|
|
|
|
assert_equal(nil, r:get_curse('antimagiczone'))
|
2017-02-27 18:21:41 +01:00
|
|
|
end
|
|
|
|
|
2018-02-17 15:22:44 +01:00
|
|
|
function test_use_healing_potion()
|
|
|
|
-- Heiltrank kann (auch) mit BENUTZE eingesetzt werden
|
2017-02-27 18:21:41 +01:00
|
|
|
local r = region.create(0, 0, "plain")
|
2018-01-19 17:17:32 +01:00
|
|
|
local f = faction.create("human")
|
2018-02-17 15:22:44 +01:00
|
|
|
local u = unit.create(f, r, 30)
|
|
|
|
assert_equal(600, u.hp)
|
|
|
|
u.hp = 100
|
|
|
|
turn_begin()
|
2018-02-17 20:35:00 +01:00
|
|
|
u:add_item("healing", 1)
|
2018-02-17 15:22:44 +01:00
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("BENUTZEN 1 Heiltrank")
|
|
|
|
turn_process()
|
|
|
|
assert_equal(530, u.hp)
|
2018-02-17 20:35:00 +01:00
|
|
|
assert_equal(0, u:get_item("healing"))
|
2018-02-17 15:30:38 +01:00
|
|
|
assert_equal(1, f:count_msg_type('use_item'))
|
2018-02-17 15:22:44 +01:00
|
|
|
turn_end()
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_use_healing_potion_multi_units()
|
|
|
|
-- Heiltrank kann mehrere Einheiten heilen
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("human")
|
|
|
|
local u1 = unit.create(f, r, 30)
|
|
|
|
local u = unit.create(f, r, 30)
|
|
|
|
assert_equal(600, u1.hp)
|
|
|
|
assert_equal(600, u.hp)
|
|
|
|
u.hp = 400
|
|
|
|
u1.hp = 400
|
|
|
|
turn_begin()
|
2018-02-17 20:35:00 +01:00
|
|
|
u:add_item("healing", 1)
|
2018-02-17 15:22:44 +01:00
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("BENUTZEN 1 Heiltrank")
|
|
|
|
turn_process()
|
|
|
|
assert_equal(600, u.hp)
|
|
|
|
assert_equal(600, u1.hp)
|
2018-02-17 20:35:00 +01:00
|
|
|
assert_equal(0, u:get_item("healing"))
|
2018-02-17 15:22:44 +01:00
|
|
|
turn_end()
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_use_multiple_healing_potions()
|
|
|
|
-- Einheit kann mehr als einen Heiltrank benutzen
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("human")
|
|
|
|
local u = unit.create(f, r, 60)
|
|
|
|
assert_equal(1200, u.hp)
|
|
|
|
u.hp = 400
|
|
|
|
turn_begin()
|
2018-02-17 20:35:00 +01:00
|
|
|
u:add_item("healing", 2)
|
2018-02-17 15:22:44 +01:00
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("BENUTZEN 2 Heiltrank")
|
|
|
|
turn_process()
|
|
|
|
assert_equal(1200, u.hp)
|
2018-02-17 20:35:00 +01:00
|
|
|
assert_equal(0, u:get_item("healing"))
|
2018-02-17 15:22:44 +01:00
|
|
|
turn_end()
|
|
|
|
end
|
|
|
|
|
2018-02-17 18:59:43 +01:00
|
|
|
function test_use_elixir()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("human")
|
|
|
|
local u = unit.create(f, r, 10)
|
|
|
|
assert_equal(200, u.hp)
|
|
|
|
u:add_item("p13", 1)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("BENUTZEN 1 Elixier~der~Macht")
|
|
|
|
process_orders()
|
|
|
|
-- potion makes hp 1000, monthly_healing takes away 400:
|
|
|
|
assert_equal(600, u.hp)
|
|
|
|
assert_equal(0, u:get_item("p13"))
|
|
|
|
assert_equal(1, f:count_msg_type('use_item'))
|
|
|
|
end
|
|
|
|
|
2018-02-17 15:22:44 +01:00
|
|
|
function test_use_ointment()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("human")
|
|
|
|
local u = unit.create(f, r, 30)
|
|
|
|
assert_equal(600, u.hp)
|
|
|
|
u.hp = 100
|
2017-02-27 18:21:41 +01:00
|
|
|
u:add_item("ointment", 1)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("BENUTZEN 1 Wundsalbe")
|
|
|
|
process_orders()
|
2018-02-17 15:22:44 +01:00
|
|
|
assert_equal(530, u.hp)
|
2017-02-27 18:21:41 +01:00
|
|
|
assert_equal(0, u:get_item("ointment"))
|
2018-02-17 15:30:38 +01:00
|
|
|
assert_equal(1, f:count_msg_type('use_item'))
|
2017-02-27 18:21:41 +01:00
|
|
|
end
|
|
|
|
|
2018-01-19 17:17:32 +01:00
|
|
|
function test_use_domore()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("human")
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
u:add_item("p3", 1)
|
|
|
|
u:add_order("BENUTZEN 1 Schaffenstrunk")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(10, u:effect("p3"))
|
|
|
|
assert_equal(0, u:get_item("p3"))
|
2018-02-17 15:30:38 +01:00
|
|
|
assert_equal(1, f:count_msg_type('use_item'))
|
2018-01-19 17:17:32 +01:00
|
|
|
u:clear_orders()
|
|
|
|
u:set_skill('weaponsmithing', 3)
|
|
|
|
u:add_item("iron", 2)
|
|
|
|
u:add_order("MACHEN Schwert")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(9, u:effect("p3"))
|
|
|
|
assert_equal(0, u:get_item("iron"))
|
|
|
|
assert_equal(2, u:get_item("sword"))
|
|
|
|
end
|
|
|
|
|
2017-02-27 18:21:41 +01:00
|
|
|
function test_bloodpotion_demon()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2018-01-19 17:17:32 +01:00
|
|
|
local f = faction.create("demon")
|
2017-02-27 18:21:41 +01:00
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
u:add_item("peasantblood", 1)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("BENUTZEN 1 Bauernblut")
|
|
|
|
process_orders()
|
2018-01-19 17:17:32 +01:00
|
|
|
assert_equal(100, u:effect('peasantblood'))
|
2017-02-27 18:21:41 +01:00
|
|
|
assert_equal(0, u:get_item("peasantblood"))
|
2018-02-17 15:30:38 +01:00
|
|
|
assert_equal(1, f:count_msg_type('use_item'))
|
2017-02-27 18:21:41 +01:00
|
|
|
assert_equal("demon", u.race)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_bloodpotion_other()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2018-01-19 17:17:32 +01:00
|
|
|
local f = faction.create("human")
|
2017-02-27 18:21:41 +01:00
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
u:add_item("peasantblood", 1)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("BENUTZEN 1 Bauernblut")
|
|
|
|
process_orders()
|
2018-01-19 17:17:32 +01:00
|
|
|
assert_equal(0, u:effect('peasantblood'))
|
2017-02-27 18:21:41 +01:00
|
|
|
assert_equal(0, u:get_item("peasantblood"))
|
2018-02-17 15:30:38 +01:00
|
|
|
assert_equal(1, f:count_msg_type('use_item'))
|
2017-02-27 18:21:41 +01:00
|
|
|
assert_equal("smurf", u.race)
|
|
|
|
end
|