test the birthday amulet

This commit is contained in:
Enno Rehling 2017-02-27 14:01:41 +01:00
parent 604b574d0f
commit 60c2f1e807
5 changed files with 36 additions and 5 deletions

View File

@ -62,9 +62,7 @@
</resource>
<resource name="aoc" appearance="amulet">
<item weight="100">
<function name="use" value="use_birthdayamulet"/>
</item>
<item weight="100" use="yes" />
</resource>
<resource name="dreameye">

View File

@ -230,12 +230,24 @@ function test_no_uruk()
assert_equal(f1.race, "orc")
end
function test_meow()
local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r, 1)
u:add_item("aoc", 1)
u:clear_orders()
u:add_order("BENUTZEN 1 Katzenamulett")
process_orders()
assert_equal(1, u:get_item("aoc"))
assert_equal(1, r:count_msg_type('meow'))
end
function test_ointment()
local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r, 1)
local hp = u.hp
u.hp = 0
u.hp = 1
u:add_item("ointment", 1)
u:clear_orders()
u:add_order("BENUTZEN 1 Wundsalbe")

View File

@ -29,6 +29,7 @@ without prior permission by the authors of Eressea.
#include <kernel/ship.h>
#include <kernel/plane.h>
#include <kernel/terrain.h>
#include <kernel/messages.h>
#include <modules/autoseed.h>
#include <attributes/key.h>
#include <attributes/racename.h>
@ -46,6 +47,23 @@ without prior permission by the authors of Eressea.
#include <string.h>
#include <stdlib.h>
static int tolua_region_count_msg_type(lua_State *L) {
region *self = (region *)tolua_tousertype(L, 1, 0);
const char *str = tolua_tostring(L, 2, 0);
int n = 0;
if (self->msgs) {
mlist * ml = self->msgs->begin;
while (ml) {
if (strcmp(str, ml->msg->type->name) == 0) {
++n;
}
ml = ml->next;
}
}
lua_pushinteger(L, n);
return 1;
}
int tolua_regionlist_next(lua_State * L)
{
region **region_ptr = (region **)lua_touserdata(L, lua_upvalueindex(1));
@ -671,6 +689,8 @@ void tolua_region_open(lua_State * L)
tolua_function(L, TOLUA_CAST "destroy", tolua_region_destroy);
tolua_function(L, TOLUA_CAST "__tostring", tolua_region_tostring);
tolua_function(L, TOLUA_CAST "count_msg_type", tolua_region_count_msg_type);
/* flags */
tolua_variable(L, TOLUA_CAST "blocked", tolua_region_get_blocked, tolua_region_set_blocked);

View File

@ -1289,7 +1289,7 @@ void register_resources(void)
register_item_use(use_potion_delayed, "use_p2");
register_item_use(use_tacticcrystal, "use_tacticcrystal");
register_item_use(use_birthdayamulet, "use_birthdayamulet");
register_item_use(use_birthdayamulet, "use_aoc");
register_item_use(use_warmthpotion, "use_nestwarmth");
register_item_use(use_bloodpotion, "use_peasantblood");
register_item_use(use_healingpotion, "use_ointment");

View File

@ -855,6 +855,7 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
struct order *))fun;
}
else if (strcmp((const char *)propValue, "use") == 0) {
log_error("%s has a use function", rtype->_name);
itype->flags |= ITF_CANUSE;
itype->use =
(int(*)(struct unit *, const struct item_type *, int,