repair magic item: stardust

https://bugs.eressea.de/view.php?id=2226
This commit is contained in:
Enno Rehling 2016-08-06 18:16:50 +02:00
parent 257ae38749
commit 3ea33c6895
3 changed files with 35 additions and 3 deletions

View file

@ -15,6 +15,23 @@ local function error_message(msg, u, ord)
return -1
end
local function usepotion_message(u, type)
msg = message.create("usepotion")
msg:set_unit("unit", u)
msg:set_resource("potion", type)
return msg
end
function use_stardust(u, amount)
local p = u.region:get_resource("peasant")
p = math.ceil(1.5 * p)
u.region:set_resource("peasant", p)
local msg = usepotion_message(u, "stardust")
msg:send_region(u.region)
return 1
end
function use_snowglobe(u, amount, token, ord)
local transform = {
ocean = "glacier",
@ -59,9 +76,7 @@ function use_xmastree(u, amount)
local trees = u.region:get_resource("tree")
u.region:set_key("xm06", true)
u.region:set_resource("tree", 10+trees)
local msg = message.create("usepotion")
msg:set_unit("unit", u)
msg:set_resource("potion", "xmastree")
local msg = usepotion_message(u, "xmastree")
msg:send_region(u.region)
return amount
end

View file

@ -82,3 +82,18 @@ function test_xmastree()
r = use_tree("plain")
assert_equal(10, r:get_resource("tree"))
end
function test_stardust()
-- fix random peasant changes:
eressea.settings.set("rules.economy.repopulate_maximum", 0)
local r = region.create(0, 0, "plain")
r:set_resource("peasant", 10)
local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r, 5)
u:add_item("stardust", 1)
u:clear_orders()
u:add_order("BENUTZEN 1 Sternenstaub")
process_orders()
assert_equal(15, r:get_resource("peasant"))
assert_equal(0, u:get_item('stardust'))
end

View file

@ -458,6 +458,7 @@ static int tolua_region_create(lua_State * L)
const terrain_type *terrain = get_terrain(tname);
region *r, *result;
if (!terrain) {
log_error("lua: region.create with invalid terrain %s", tname);
return 0;
}
@ -481,6 +482,7 @@ static int tolua_region_create(lua_State * L)
tolua_pushusertype(L, result, TOLUA_CAST "region");
return 1;
}
log_error("lua: region.create with invalid terrain %s", tname);
return 0;
}