From 1eaa1e6d84d42ffeaf7ed868ed3df61eb8133fdd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Jan 2018 18:07:49 +0100 Subject: [PATCH] BUG 2405: use mistletoe to create effect, use effect to flee from battle. --- res/core/messages.xml | 15 +++------------ scripts/tests/items.lua | 8 ++++---- src/battle.c | 20 ++++++-------------- src/items.c | 28 +++++++++++----------------- src/modules/museum.c | 4 ++-- 5 files changed, 26 insertions(+), 49 deletions(-) diff --git a/res/core/messages.xml b/res/core/messages.xml index 8c5db1b4d..00f2da5fd 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -6815,19 +6815,10 @@ + - "$unit($unit) benutzt ein $resource($item,1)." - "$unit($unit) uses a $resource($item,1)." - - - - - - - - - "$unit($unit) in $region($region): '$order($command)' - $resource($item,0) können nur von Ein-Personen Einheiten benutzt werden." - "$unit($unit) in $region($region): '$order($command)' - $resource($item,0) can only be used by single-person units." + "$unit($unit) benutzt $amount $resource($item,$amount)." + "$unit($unit) uses $amount $resource($item,$amount)." diff --git a/scripts/tests/items.lua b/scripts/tests/items.lua index b66316737..fb6a754f5 100644 --- a/scripts/tests/items.lua +++ b/scripts/tests/items.lua @@ -11,15 +11,15 @@ function setup() eressea.settings.set("magic.regeneration.enable", "0") end -function disable_test_use_mistletoe() +function test_use_mistletoe() local r = region.create(0, 0, "plain") local f = faction.create("human") local u = unit.create(f, r, 1) u.name = 'Miraculix' - u:add_item('mistletoe', 2) - u:add_order("BENUTZEN 1 Mistelzweig") + u:add_item('mistletoe', 3) + u:add_order("BENUTZEN 2 Mistelzweig") process_orders() - assert_equal(1, u:effect('mistletoe')) + assert_equal(2, u:effect('mistletoe')) assert_equal(1, u:get_item('mistletoe')) assert_equal(1, f:count_msg_type('use_item')) end diff --git a/src/battle.c b/src/battle.c index 580bb045c..b0e931214 100644 --- a/src/battle.c +++ b/src/battle.c @@ -2340,13 +2340,6 @@ double fleechance(unit * u) p = 0.9; } } -#if 0 - /* TODO: mistletoe */ - c = get_curse(u->attribs, &ct_fleechance); - if (c) { - p += c->effect; - } -#endif return p; } @@ -3360,17 +3353,16 @@ static int join_battle(battle * b, unit * u, bool attack, fighter ** cp) side *s; fighter *fc = NULL; - if (!attack) { -#if 0 - /* TODO: mistletoe */ - attrib *a = a_find(u->attribs, &at_fleechance); - if (a != NULL) { - if (rng_double() <= a->data.flt) { + if (!attack && u->attribs) { + const item_type *itype = it_find("mistletoe"); + if (itype) { + int effect = get_effect(u, itype); + if (effect >= u->number) { + change_effect(u, itype, -u->number); *cp = NULL; return false; } } -#endif } for (s = b->sides; s != b->sides + b->nsides; ++s) { diff --git a/src/items.c b/src/items.c index 2a2248279..ba9f35388 100644 --- a/src/items.c +++ b/src/items.c @@ -374,24 +374,18 @@ static int use_mistletoe(struct unit *user, const struct item_type *itype, int amount, struct order *ord) { - int mtoes = - get_pooled(user, itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, - user->number); - - if (user->number > mtoes) { - ADDMSG(&user->faction->msgs, msg_message("use_singleperson", - "unit item region command", user, itype->rtype, user->region, ord)); - return -1; + int mtoes = get_pooled(user, itype->rtype, + GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, amount); + if (mtoes < amount) { + amount = mtoes; + } + if (amount > 0) { + use_pooled(user, itype->rtype, + GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, amount); + change_effect(user, itype, amount); + ADDMSG(&user->faction->msgs, + msg_message("use_item", "unit amount item", user, amount, itype->rtype)); } - use_pooled(user, itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, - user->number); -#if 0 - /* TODO: mistletoe */ - a_add(&user->attribs, make_fleechance((float)1.0)); -#endif - ADDMSG(&user->faction->msgs, - msg_message("use_item", "unit item", user, itype->rtype)); - return 0; } diff --git a/src/modules/museum.c b/src/modules/museum.c index 4420603ad..0f9fe9923 100644 --- a/src/modules/museum.c +++ b/src/modules/museum.c @@ -460,7 +460,7 @@ static void use_key1(connection *b, void *data) { if (b->type == &bt_questportal) { const struct item_type *itype = it_find("questkey1"); ADDMSG(&u->faction->msgs, - msg_message("use_item", "unit item", u, itype->rtype)); + msg_message("use_item", "unit amount item", u, 1, itype->rtype)); b->data.i &= 0xFE; } } @@ -470,7 +470,7 @@ static void use_key2(connection *b, void *data) { if (b->type == &bt_questportal) { const struct item_type *itype = it_find("questkey2"); ADDMSG(&u->faction->msgs, - msg_message("use_item", "unit item", u, itype->rtype)); + msg_message("use_item", "unit amount item", u, 1, itype->rtype)); b->data.i &= 0xFD; } }