diff --git a/scripts/tests/spells.lua b/scripts/tests/spells.lua index 1538b4249..2d23d2efe 100644 --- a/scripts/tests/spells.lua +++ b/scripts/tests/spells.lua @@ -6,7 +6,49 @@ function setup() free_game() settings.set("magic.fumble.enable", "0") settings.set("magic.regeneration.enable", "0") - settings.set("rules.economy.food", "0") + settings.set("rules.economy.food", "4") +end + +function test_spell_payment() + local r = region.create(0,0, "plain") + local f = faction.create("spell_payment@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:set_skill("magic", 12) + u.magic = "gwyrrd" -- calls create_mage + u:add_spell("create_roi") + + local permaura = u:get_pooled("permaura") + u:add_item("money", 3000) + u.aura = 50 + u:clear_orders() + u:add_order("ZAUBERE 'Erschaffe einen Ring der Unsichtbarkeit' ") + process_orders() + + assert_equal(1, u:get_item("roi")) + assert_equal(0, u:get_item("money")) + assert_equal(0, u.aura) + assert_equal(permaura-1, u:get_pooled("permaura")) +end + +function test_spell_not_found_no_payment() + local r = region.create(0,0, "plain") + local f = faction.create("spell_fails_no_payment@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:set_skill("magic", 12) + u.magic = "gwyrrd" -- calls create_mage + + local permaura = u:get_pooled("permaura") + u:add_item("money", 3000) + u.aura = 50 + + u:clear_orders() + u:add_order("ZAUBERE 'Erschaffe einen Ring der Unsichtbarkeit' ") + process_orders() + + assert_equal(0, u:get_item("roi")) + assert_equal(3000, u:get_item("money")) + assert_equal(50, u.aura) + assert_equal(permaura, u:get_pooled("permaura")) end function test_create_firesword() diff --git a/src/kernel/magic.c b/src/kernel/magic.c index 581ef4988..f6b8360b9 100644 --- a/src/kernel/magic.c +++ b/src/kernel/magic.c @@ -889,6 +889,7 @@ void pay_spell(unit * u, const spell * sp, int cast_level, int range) int k; int resuse; + assert(cast_level>0); for (k = 0; sp->components[k].type; k++) { if (sp->components[k].type == r_aura) { resuse = spellcost(u, sp) * range; @@ -1394,7 +1395,7 @@ static void do_fumble(castorder * co) case 5: case 6: /* Spruch gelingt, aber alle Magiepunkte weg */ - sp->cast(co); + co->level = sp->cast(co); set_spellpoints(u, 0); ADDMSG(&u->faction->msgs, msg_message("patzer4", "unit region spell", u, r, sp)); @@ -1405,7 +1406,7 @@ static void do_fumble(castorder * co) case 9: default: /* Spruch gelingt, alle nachfolgenden Sprüche werden 2^4 so teuer */ - sp->cast(co); + co->level = sp->cast(co); ADDMSG(&u->faction->msgs, msg_message("patzer5", "unit region spell", u, r, sp)); countspells(u, 3); @@ -2839,10 +2840,13 @@ void magic(void) } } } - pay_spell(u, sp, co->level, co->distance); /* erst bezahlen, dann Kostenzähler erhöhen */ - if (fumbled) + if (fumbled) { do_fumble(co); + } + if (co->level>0) { + pay_spell(u, sp, co->level, co->distance); + } countspells(u, 1); } }