2020-04-19 21:35:48 +02:00
local tcname = ' tests.e2.spells '
2020-05-03 16:52:40 +02:00
local lunit = require ( ' lunit ' )
2020-04-19 21:35:48 +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-19 21:35:48 +02:00
end
2015-04-30 15:59:52 +02:00
function setup ( )
2020-02-08 21:49:42 +01:00
eressea.game . reset ( )
2015-04-30 15:59:52 +02:00
eressea.settings . set ( " nmr.removenewbie " , " 0 " )
eressea.settings . set ( " nmr.timeout " , " 0 " )
eressea.settings . set ( " NewbieImmunity " , " 0 " )
2015-09-11 10:04:08 +02:00
eressea.settings . set ( " rules.food.flags " , " 4 " )
2017-05-06 10:56:44 +02:00
eressea.settings . set ( " rules.peasants.growth.factor " , " 0 " )
2019-10-05 20:59:55 +02:00
eressea.settings . set ( " magic.resist.enable " , " 0 " )
2017-12-09 10:24:31 +01:00
eressea.settings . set ( " magic.fumble.enable " , " 0 " )
2018-11-15 20:51:42 +01:00
eressea.settings . set ( " magic.regeneration.enable " , " 0 " )
2015-04-30 15:59:52 +02:00
end
2019-12-29 14:28:55 +01:00
function test_undead_cannot_enter_holyground ( )
local r1 = region.create ( 0 , 0 , ' plain ' )
local r2 = region.create ( 1 , 0 , ' plain ' )
local f = faction.create ( ' human ' )
local u1 = unit.create ( f , r1 , 1 )
local u2 = unit.create ( f , r2 , 1 )
u2.magic = ' gwyrrd '
u2 : set_skill ( ' magic ' , 100 )
u2.aura = 200
u2 : add_spell ( ' holyground ' )
u2 : add_order ( ' ZAUBERE STUFE 10 "Heiliger Boden" ' )
u1.race = " skeleton "
u1 : add_order ( " NACH Osten " )
process_orders ( )
assert_not_nil ( r2 : get_curse ( ' holyground ' ) )
assert_equal ( r1 , u1.region )
end
2015-04-30 15:59:52 +02:00
function test_shapeshift ( )
local r = region.create ( 42 , 0 , " plain " )
2017-03-17 22:31:59 +01:00
local f = faction.create ( " demon " , " noreply@eressea.de " , " de " )
2015-04-30 15:59:52 +02:00
local u1 = unit.create ( f , r , 1 )
local u2 = unit.create ( f , r , 1 )
u1 : clear_orders ( )
u1.magic = " gray "
u1 : set_skill ( " magic " , 2 )
u1.aura = 1
u1 : add_spell ( " shapeshift " )
u1 : add_order ( " ZAUBERE STUFE 1 Gestaltwandlung " .. itoa36 ( u2.id ) .. " Goblin " )
process_orders ( )
assert_equal ( f.race , u2.race )
s = u2 : show ( )
assert_equal ( " 1 Goblin " , string.sub ( s , string.find ( s , " 1 Goblin " ) ) )
end
2017-04-30 17:25:24 +02:00
2017-04-30 21:38:30 +02:00
function test_raindance ( )
local r = region.create ( 0 , 0 , " plain " )
local f = faction.create ( " halfling " , " noreply@eressea.de " , " de " )
local u = unit.create ( f , r )
local err = 0
r : set_resource ( " peasant " , 100 )
r : set_resource ( " money " , 0 )
u.magic = " gwyrrd "
u.race = " dwarf "
u : set_skill ( " magic " , 20 )
u.aura = 200
err = err + u : add_spell ( " raindance " )
assert_equal ( 0 , err )
u : clear_orders ( )
u : add_order ( " ZAUBERE STUFE 1 Regentanz " )
assert_equal ( 0 , r : get_resource ( " money " ) )
2017-05-06 10:56:44 +02:00
2017-04-30 21:38:30 +02:00
process_orders ( )
assert_equal ( 200 , r : get_resource ( " money " ) )
assert_equal ( 0 , u : get_item ( " money " ) )
u : clear_orders ( )
u : add_order ( " ARBEITEN " )
process_orders ( )
assert_equal ( 10 , u : get_item ( " money " ) ) -- only peasants benefit
assert_equal ( 400 , r : get_resource ( " money " ) )
-- this is where the spell ends
process_orders ( )
process_orders ( )
assert_equal ( 600 , r : get_resource ( " money " ) )
end
2017-04-30 17:42:16 +02:00
function test_earn_silver ( )
local r = region.create ( 0 , 0 , " mountain " )
2017-04-30 17:25:24 +02:00
local f = faction.create ( " human " )
local u = unit.create ( f , r )
eressea.settings . set ( " rules.food.flags " , " 4 " )
eressea.settings . set ( " magic.fumble.enable " , " 0 " )
eressea.settings . set ( " rules.peasants.growth " , " 0 " )
eressea.settings . set ( " rules.economy.repopulate_maximum " , " 0 " )
u.magic = " gwyrrd "
u.race = " elf "
u : set_skill ( " magic " , 10 )
u.aura = 100
local err = u : add_spell ( " earn_silver#gwyrrd " )
assert_equal ( 0 , err )
u : clear_orders ( )
u : add_order ( " ZAUBERE STUFE 1 Viehheilung " )
r : set_resource ( " money " , 350 )
r : set_resource ( " peasant " , 0 )
process_orders ( ) -- get 50 silver
assert_equal ( 50 , u : get_item ( " money " ) )
assert_equal ( 300 , r : get_resource ( " money " ) )
u : clear_orders ( ) -- get 100 silver
u : add_order ( " ZAUBERE STUFE 2 Viehheilung " )
process_orders ( )
assert_equal ( 150 , u : get_item ( " money " ) )
assert_equal ( 200 , r : get_resource ( " money " ) )
u : clear_orders ( ) -- get 150 silver
u : add_order ( " ZAUBERE STUFE 3 Viehheilung " )
process_orders ( )
assert_equal ( 300 , u : get_item ( " money " ) )
assert_equal ( 50 , r : get_resource ( " money " ) )
process_orders ( ) -- not enough
assert_equal ( 350 , u : get_item ( " money " ) )
assert_equal ( 0 , r : get_resource ( " money " ) )
end
2018-01-26 17:45:40 +01:00
2018-11-15 20:51:42 +01:00
function test_familiar_cast ( )
local r = region.create ( 0 , 0 , " plain " )
r : set_resource ( " money " , 350 )
r : set_resource ( " peasant " , 0 )
local f = faction.create ( " human " )
local u = unit.create ( f , r )
u.magic = " gwyrrd "
u : set_skill ( " magic " , 10 )
u.aura = 200
u : add_spell ( " earn_silver#gwyrrd " )
u : add_order ( ' ARBEITE ' )
local uf = unit.create ( f , r )
uf.race = " lynx "
uf : set_skill ( " magic " , 5 )
uf : add_order ( ' ZAUBER STUFE 1 Viehheilung ' )
u.familiar = uf
process_orders ( )
assert_equal ( 198 , u.aura ) -- Fremdzauber, Kosten verdoppelt
assert_equal ( 10 , u : get_item ( ' money ' ) ) -- von ARBEITE
assert_equal ( 50 , uf : get_item ( ' money ' ) ) -- von Zauber
assert_equal ( 300 , uf.region : get_resource ( " money " ) )
end
function test_familiar_mage_actions ( )
local r = region.create ( 0 , 0 , " plain " )
r : set_resource ( " money " , 350 )
r : set_resource ( " peasant " , 0 )
local f = faction.create ( " human " )
local u = unit.create ( f , r )
u.magic = " gwyrrd "
u : set_skill ( " magic " , 10 )
u.aura = 200
u : add_spell ( " earn_silver#gwyrrd " )
u : add_order ( ' ZAUBER STUFE 1 Viehheilung ' )
local uf = unit.create ( f , r )
uf.race = " lynx "
uf : set_skill ( " magic " , 5 )
uf : add_order ( ' ZAUBER STUFE 1 Viehheilung ' )
u.familiar = uf
process_orders ( )
assert_equal ( 50 , u : get_item ( ' money ' ) )
assert_equal ( 50 , uf : get_item ( ' money ' ) )
assert_equal ( 250 , uf.region : get_resource ( " money " ) )
assert_equal ( 197 , u.aura )
end
2018-01-26 17:45:40 +01:00
function test_familiar ( )
local r = region.create ( 0 , 0 , " mountain " )
local f = faction.create ( " human " )
local u = unit.create ( f , r )
local uid = u.id
u.name = ' Hodor '
u.magic = " gwyrrd "
u.race = " elf "
u : set_skill ( " magic " , 10 )
u.aura = 200
local err = u : add_spell ( " summon_familiar " )
assert_equal ( 0 , err )
u : add_order ( " ZAUBERE Vertrauten~rufen " )
process_orders ( )
for u in r.units do
if u.id ~= uid then
assert_equal ( ' Vertrauter von Hodor ( ' .. itoa36 ( uid ) .. ' ) ' , u.name )
end
end
end
2018-05-15 06:58:07 +02:00
function test_familiar_lynx ( )
local r = region.create ( 0 , 0 , ' plain ' )
local f = faction.create ( ' human ' )
local u = unit.create ( f , r )
u.race = ' lynx '
u : equip ( ' fam_lynx ' )
assert_equal ( 1 , u : get_skill ( ' stealth ' ) )
assert_equal ( 1 , u : get_skill ( ' espionage ' ) )
assert_equal ( 1 , u : get_skill ( ' magic ' ) )
assert_equal ( 1 , u : get_skill ( ' perception ' ) )
end
2018-09-04 16:41:46 +02:00
function test_bug_2480 ( )
local r = region.create ( 0 , 0 , " plain " )
2018-09-11 17:17:47 +02:00
local f = faction.create ( " human " , " 2480@eressea.de " , " de " )
2018-09-04 16:41:46 +02:00
local u1 = unit.create ( f , r , 1 )
local monster = unit.create ( get_monsters ( ) , r , 1 , " wyrm " )
u1.number = 30
u1.hp = u1.hp_max * u1.number
monster : add_order ( " ATTACK " .. itoa36 ( u1.id ) )
process_orders ( )
assert_equal ( 0 , u1.number ) ;
end
2018-11-17 21:24:59 +01:00
function test_bug_2517 ( )
local r = region.create ( 0 , 0 , " plain " )
local f = faction.create ( " elf " )
local um = unit.create ( f , r , 1 )
local uf = nil
eressea.settings . set ( " magic.familiar.race " , " lynx " )
f.magic = ' gwyrrd '
um.magic = ' gwyrrd '
um.race = ' elf '
um : set_skill ( ' magic ' , 10 )
um : add_spell ( ' summon_familiar ' )
um : add_spell ( ' earn_silver#gwyrrd ' )
um : add_order ( ' ZAUBERE Vertrauten~rufen ' )
um.aura = 200
process_orders ( )
uf = um.familiar
assert_not_nil ( uf )
assert_equal ( ' lynx ' , uf.race )
2018-11-22 22:22:40 +01:00
assert_equal ( ' gray ' , uf.magic )
2018-11-17 21:24:59 +01:00
uf : add_order ( ' LERNE Magie ' )
um : clear_orders ( )
um : add_order ( ' ARBEITEN ' )
process_orders ( )
2018-11-22 22:22:40 +01:00
assert_equal ( ' gray ' , uf.magic )
2018-11-17 21:24:59 +01:00
uf : add_order ( ' ZAUBERE STUFE 1 Viehheilung ' )
process_orders ( )
assert_equal ( 50 , uf : get_item ( ' money ' ) )
end
function test_familiar_school ( )
local r = region.create ( 0 , 0 , " plain " )
r : set_resource ( " money " , 350 )
r : set_resource ( " peasant " , 0 )
local f = faction.create ( " human " )
local u = unit.create ( f , r )
u.magic = " draig "
u : set_skill ( " magic " , 10 )
local uf = unit.create ( f , r )
uf.race = " lynx "
u.familiar = uf
assert_nil ( uf.magic )
uf : set_skill ( " magic " , 5 )
assert_nil ( uf.magic )
uf.aura = 10
assert_equal ( 0 , uf.aura )
assert_nil ( uf.magic )
end
2019-09-29 17:56:56 +02:00
function test_astral_disruption ( )
local r = region.create ( 0 , 0 , " plain " )
local r2 = r : get_astral ( ' fog ' )
2020-12-06 19:08:23 +01:00
local r3 = region.create ( r2.x + 1 , r2.y , ' fog ' )
2019-09-29 17:56:56 +02:00
local f = faction.create ( " human " )
local u = unit.create ( f , r )
local uh = unit.create ( get_monsters ( ) , r2 , 1 , " braineater " )
2020-12-06 19:08:23 +01:00
u.magic = " tybied "
2019-09-29 17:56:56 +02:00
u : set_skill ( " magic " , 100 ) -- level 100 should beat magic resistance
u.aura = 200
2020-12-06 19:08:23 +01:00
u : add_spell ( " astral_disruption " , 14 )
2019-09-29 17:56:56 +02:00
u : add_order ( ' ZAUBERE STUFE 1 "Stoere Astrale Integritaet" ' )
process_orders ( )
2020-12-06 19:08:23 +01:00
assert_equal ( 60 , u.aura )
assert_equal ( 100 , r2 : get_curse ( " astralblock " ) )
assert_nil ( r3 : get_curse ( " astralblock " ) )
assert_equal ( r , uh.region )
end
function test_astral_disruption_levels ( )
local r = region.create ( 0 , 0 , " plain " )
local r2 = r : get_astral ( ' fog ' )
local r3 = region.create ( r2.x + 1 , r2.y , ' fog ' )
local r4 = region.create ( r2.x + 2 , r2.y , ' fog ' )
local f = faction.create ( " human " )
local u = unit.create ( f , r )
local uh = unit.create ( get_monsters ( ) , r2 , 1 , " braineater " )
u.magic = " tybied "
u : set_skill ( " magic " , 100 ) -- level 100 should beat magic resistance
u.aura = 200
u : add_spell ( " astral_disruption " , 14 )
-- at level 5, range +1:
u : add_order ( ' ZAUBERE STUFE 5 "Stoere Astrale Integritaet" ' )
process_orders ( )
assert_equal ( 60 , u.aura )
assert_equal ( 100 , r2 : get_curse ( " astralblock " ) )
assert_equal ( 100 , r3 : get_curse ( " astralblock " ) )
assert_nil ( r4 : get_curse ( " astralblock " ) )
assert_equal ( r , uh.region )
end
function test_astral_disruption_default_level ( )
local r = region.create ( 0 , 0 , " plain " )
local r2 = r : get_astral ( ' fog ' )
local r3 = region.create ( r2.x + 1 , r2.y , ' fog ' )
local r4 = region.create ( r3.x + 1 , r2.y , ' fog ' )
local r5 = region.create ( r4.x + 1 , r2.y , ' fog ' )
local f = faction.create ( " human " )
local u = unit.create ( f , r )
local uh = unit.create ( get_monsters ( ) , r2 , 1 , " braineater " )
u.magic = " tybied "
u : set_skill ( " magic " , 100 ) -- level 100 should beat magic resistance
u.aura = 200
u : add_spell ( " astral_disruption " , 14 )
-- no level means cast at the spell's level (14)
u : add_order ( ' ZAUBERE "Stoere Astrale Integritaet" ' )
process_orders ( )
assert_equal ( 60 , u.aura )
assert_equal ( 100 , r2 : get_curse ( " astralblock " ) )
assert_equal ( 100 , r3 : get_curse ( " astralblock " ) )
assert_equal ( 100 , r4 : get_curse ( " astralblock " ) )
assert_nil ( r5 : get_curse ( " astralblock " ) )
2019-09-29 17:56:56 +02:00
assert_equal ( r , uh.region )
end
2021-03-21 17:50:06 +01:00
function test_dream_magician_dies ( )
local u1 , u2 , r , f , f2
r = region.create ( 0 , 0 , ' plain ' )
f = faction.create ( ' human ' , " dreamer@eressea.de " , " de " )
u1 = unit.create ( f , r , 1 )
u1 : set_skill ( " melee " , 1 )
u2 = unit.create ( f , r , 1 )
u2.magic = ' illaun '
u2 : set_skill ( ' magic ' , 20 )
u2.aura = 100
u2 : add_spell ( ' gooddreams ' )
u2 : add_order ( ' ZAUBERE STUFE 10 "Schöne Träume" ' )
f2 = faction.create ( ' human ' )
u3 = unit.create ( f2 , r , 1000 )
assert_equal ( 1 , u1 : eff_skill ( " melee " ) )
process_orders ( )
u2 : clear_orders ( )
-- how to kill a mage ...
u3 : add_order ( " ATTACKIERE " .. itoa36 ( u2.id ) )
u1 : add_order ( " KÄMPFE NICHT " )
u2 : add_order ( " KÄMPFE AGGRESSIV " )
init_reports ( )
write_reports ( )
assert_equal ( 2 , u1 : eff_skill ( " melee " ) )
process_orders ( )
-- u2 is dead
-- in a perfect world, this would be a test that the curse has no effect. However, with rng == 0, the duration of the dream curse is only 1 week, so it would have faded anyway. But we should at least not crash.
assert_equal ( 0 , u2.number )
assert_equal ( 1 , u1 : eff_skill ( " melee " ) )
end