2014-08-07 13:19:19 +02:00
|
|
|
require "lunit"
|
|
|
|
|
|
|
|
module("tests.eressea.study", package.seeall, lunit.testcase)
|
|
|
|
|
|
|
|
function setup()
|
|
|
|
conf = [[{
|
|
|
|
"races" : { "human" : {} },
|
|
|
|
"terrains" : { "plain" : { "flags" : [ "land" ] } },
|
2015-07-11 12:48:03 +02:00
|
|
|
"keywords" : { "de" : { "study": "LERNEN", "teach": "LEHREN" } },
|
|
|
|
"skills" : { "de": {
|
|
|
|
"tactics" : "Taktik",
|
|
|
|
"alchemy" : "Alchemie",
|
|
|
|
"crossbow" : "Armbrust"
|
|
|
|
} },
|
2015-05-05 17:44:58 +02:00
|
|
|
"spells" : { "fireball" : { "syntax" : "u+" } }
|
2014-08-07 13:19:19 +02:00
|
|
|
}]]
|
|
|
|
eressea.game.reset()
|
|
|
|
eressea.config.reset();
|
|
|
|
eressea.settings.set('rules.magic.playerschools', '')
|
2015-09-11 10:04:08 +02:00
|
|
|
eressea.settings.set("rules.food.flags", "4")
|
2015-07-11 12:48:03 +02:00
|
|
|
eressea.settings.set('study.random_progress', '0')
|
2014-08-07 13:19:19 +02:00
|
|
|
eressea.config.parse(conf)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_study()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "test@example.com", "de")
|
2014-08-07 13:19:19 +02:00
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
u:add_order("LERNEN Armbrust")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(1, u:get_skill("crossbow"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_study_expensive()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "test@example.com", "de")
|
2014-08-07 13:19:19 +02:00
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
eressea.settings.set("skills.cost.alchemy", "50")
|
|
|
|
u:add_order("LERNEN Alchemie")
|
|
|
|
u:add_item("money", 50)
|
|
|
|
process_orders()
|
|
|
|
assert_equal(1, u:get_skill("alchemy"))
|
|
|
|
assert_equal(0, u:get_item("money"))
|
|
|
|
end
|
2015-05-05 17:44:58 +02:00
|
|
|
|
|
|
|
function test_unit_spells()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "test@example.com", "de")
|
2015-05-05 17:44:58 +02:00
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
u.magic = "gray"
|
|
|
|
u:set_skill("magic", 1)
|
|
|
|
u:add_spell("toast")
|
|
|
|
assert_equal(nil, u.spells)
|
|
|
|
u:add_spell("fireball", 2)
|
|
|
|
local sp = u.spells()
|
|
|
|
assert_equal("fireball", sp.name)
|
|
|
|
assert_equal(2, sp.level)
|
|
|
|
end
|
2015-07-11 12:48:03 +02:00
|
|
|
|
|
|
|
local function make_teacher(student, f, skill)
|
|
|
|
f = f or student.faction
|
|
|
|
local u = unit.create(f, student.region, 1)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("LEHRE " .. itoa36(student.id))
|
|
|
|
u:set_skill(skill or "crossbow", 10)
|
|
|
|
return u
|
|
|
|
end
|
|
|
|
|
|
|
|
local function make_student(f, r, num, skill)
|
|
|
|
local u = unit.create(f, r, num or 1)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("LERNE " .. (skill or "Armbrust"))
|
|
|
|
return u
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_study_no_teacher()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "test@example.com", "de")
|
2015-07-11 12:48:03 +02:00
|
|
|
local u1 = make_student(f, r, 1)
|
|
|
|
u1:set_skill("crossbow", 1)
|
|
|
|
process_orders()
|
|
|
|
assert_equal(1, u1:get_skill("crossbow"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_study_with_teacher()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "test@example.com", "de")
|
2015-07-11 12:48:03 +02:00
|
|
|
local u1 = make_student(f, r, 1)
|
|
|
|
|
|
|
|
make_teacher(u1)
|
|
|
|
u1:set_skill("crossbow", 1)
|
|
|
|
process_orders()
|
|
|
|
assert_equal(2, u1:get_skill("crossbow"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_study_too_many_students()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "test@example.com", "de")
|
2015-07-11 12:48:03 +02:00
|
|
|
local u1 = make_student(f, r, 20, "Taktik")
|
|
|
|
u1.name = "Student"
|
|
|
|
u1:add_item("money", 201*u1.number)
|
|
|
|
make_teacher(u1, f, "tactics")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(u1.number, u1:get_item("money"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_study_multiple_teachers()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "test@example.com", "de")
|
2015-07-11 12:48:03 +02:00
|
|
|
local u1 = make_student(f, r, 20, "Taktik")
|
|
|
|
u1.name = "Student"
|
|
|
|
u1:add_item("money", 201*u1.number)
|
|
|
|
make_teacher(u1, f, "tactics")
|
|
|
|
make_teacher(u1, f, "tactics")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(u1.number, u1:get_item("money"))
|
|
|
|
end
|