Commit 16be11ad authored by mercury233's avatar mercury233 Committed by GitHub

update Duel.CheckLPCost, Duel.PayLPCost (#410)

parent 60484c53
...@@ -2271,7 +2271,7 @@ int32 field::check_spsummon_counter(uint8 playerid, uint8 ct) { ...@@ -2271,7 +2271,7 @@ int32 field::check_spsummon_counter(uint8 playerid, uint8 ct) {
} }
return TRUE; return TRUE;
} }
int32 field::check_lp_cost(uint8 playerid, uint32 lp) { int32 field::check_lp_cost(uint8 playerid, uint32 lp, uint32 must_pay) {
effect_set eset; effect_set eset;
int32 val = lp; int32 val = lp;
filter_player_effect(playerid, EFFECT_LPCOST_CHANGE, &eset); filter_player_effect(playerid, EFFECT_LPCOST_CHANGE, &eset);
...@@ -2281,17 +2281,22 @@ int32 field::check_lp_cost(uint8 playerid, uint32 lp) { ...@@ -2281,17 +2281,22 @@ int32 field::check_lp_cost(uint8 playerid, uint32 lp) {
pduel->lua->add_param(val, PARAM_TYPE_INT); pduel->lua->add_param(val, PARAM_TYPE_INT);
val = eset[i]->get_value(3); val = eset[i]->get_value(3);
} }
if(val <= 0) if(val <= 0) {
return TRUE; if(must_pay)
tevent e; return FALSE;
e.event_cards = 0;
e.event_player = playerid;
e.event_value = lp;
e.reason = 0;
e.reason_effect = core.reason_effect;
e.reason_player = playerid;
if(effect_replace_check(EFFECT_LPCOST_REPLACE, e))
return TRUE; return TRUE;
}
if(!must_pay) {
tevent e;
e.event_cards = 0;
e.event_player = playerid;
e.event_value = lp;
e.reason = 0;
e.reason_effect = core.reason_effect;
e.reason_player = playerid;
if(effect_replace_check(EFFECT_LPCOST_REPLACE, e))
return TRUE;
}
//cost[playerid].amount += val; //cost[playerid].amount += val;
if(val <= player[playerid].lp) if(val <= player[playerid].lp)
return TRUE; return TRUE;
......
...@@ -468,10 +468,10 @@ public: ...@@ -468,10 +468,10 @@ public:
void set_spsummon_counter(uint8 playerid); void set_spsummon_counter(uint8 playerid);
int32 check_spsummon_counter(uint8 playerid, uint8 ct = 1); int32 check_spsummon_counter(uint8 playerid, uint8 ct = 1);
int32 check_lp_cost(uint8 playerid, uint32 cost); int32 check_lp_cost(uint8 playerid, uint32 cost, uint32 must_pay);
void save_lp_cost() {} void save_lp_cost() {}
void restore_lp_cost() {} void restore_lp_cost() {}
int32 pay_lp_cost(uint32 step, uint8 playerid, uint32 cost); int32 pay_lp_cost(uint32 step, uint8 playerid, uint32 cost, uint32 must_pay);
uint32 get_field_counter(uint8 self, uint8 s, uint8 o, uint16 countertype); uint32 get_field_counter(uint8 self, uint8 s, uint8 o, uint16 countertype);
int32 effect_replace_check(uint32 code, const tevent& e); int32 effect_replace_check(uint32 code, const tevent& e);
......
...@@ -1433,7 +1433,10 @@ int32 scriptlib::duel_check_lp_cost(lua_State *L) { ...@@ -1433,7 +1433,10 @@ int32 scriptlib::duel_check_lp_cost(lua_State *L) {
return 0; return 0;
uint32 cost = (uint32)lua_tointeger(L, 2); uint32 cost = (uint32)lua_tointeger(L, 2);
duel* pduel = interpreter::get_duel_info(L); duel* pduel = interpreter::get_duel_info(L);
lua_pushboolean(L, pduel->game_field->check_lp_cost(playerid, cost)); uint32 must_pay = FALSE;
if(lua_gettop(L) > 2)
must_pay = lua_toboolean(L, 3);
lua_pushboolean(L, pduel->game_field->check_lp_cost(playerid, cost, must_pay));
return 1; return 1;
} }
int32 scriptlib::duel_pay_lp_cost(lua_State *L) { int32 scriptlib::duel_pay_lp_cost(lua_State *L) {
...@@ -1444,7 +1447,10 @@ int32 scriptlib::duel_pay_lp_cost(lua_State *L) { ...@@ -1444,7 +1447,10 @@ int32 scriptlib::duel_pay_lp_cost(lua_State *L) {
return 0; return 0;
uint32 cost = (uint32)lua_tointeger(L, 2); uint32 cost = (uint32)lua_tointeger(L, 2);
duel* pduel = interpreter::get_duel_info(L); duel* pduel = interpreter::get_duel_info(L);
pduel->game_field->add_process(PROCESSOR_PAY_LPCOST, 0, 0, 0, playerid, cost); uint32 must_pay = FALSE;
if(lua_gettop(L) > 2)
must_pay = lua_toboolean(L, 3);
pduel->game_field->add_process(PROCESSOR_PAY_LPCOST, 0, 0, 0, playerid, cost, must_pay);
return lua_yield(L, 0); return lua_yield(L, 0);
} }
int32 scriptlib::duel_discard_deck(lua_State *L) { int32 scriptlib::duel_discard_deck(lua_State *L) {
......
...@@ -594,7 +594,7 @@ int32 field::recover(uint16 step, effect* reason_effect, uint32 reason, uint8 re ...@@ -594,7 +594,7 @@ int32 field::recover(uint16 step, effect* reason_effect, uint32 reason, uint8 re
} }
return TRUE; return TRUE;
} }
int32 field::pay_lp_cost(uint32 step, uint8 playerid, uint32 cost) { int32 field::pay_lp_cost(uint32 step, uint8 playerid, uint32 cost, uint32 must_pay) {
switch(step) { switch(step) {
case 0: { case 0: {
effect_set eset; effect_set eset;
...@@ -609,6 +609,18 @@ int32 field::pay_lp_cost(uint32 step, uint8 playerid, uint32 cost) { ...@@ -609,6 +609,18 @@ int32 field::pay_lp_cost(uint32 step, uint8 playerid, uint32 cost) {
if(val <= 0) if(val <= 0)
return TRUE; return TRUE;
core.units.begin()->arg2 = val; core.units.begin()->arg2 = val;
core.select_options.clear();
core.select_effects.clear();
if(val <= player[playerid].lp) {
core.select_options.push_back(11);
core.select_effects.push_back(0);
}
if(must_pay) {
if(core.select_options.size() == 0)
return TRUE;
returns.ivalue[0] = 0;
return FALSE;
}
tevent e; tevent e;
e.event_cards = 0; e.event_cards = 0;
e.event_player = playerid; e.event_player = playerid;
...@@ -616,12 +628,6 @@ int32 field::pay_lp_cost(uint32 step, uint8 playerid, uint32 cost) { ...@@ -616,12 +628,6 @@ int32 field::pay_lp_cost(uint32 step, uint8 playerid, uint32 cost) {
e.reason = 0; e.reason = 0;
e.reason_effect = core.reason_effect; e.reason_effect = core.reason_effect;
e.reason_player = playerid; e.reason_player = playerid;
core.select_options.clear();
core.select_effects.clear();
if(val <= player[playerid].lp) {
core.select_options.push_back(11);
core.select_effects.push_back(0);
}
auto pr = effects.continuous_effect.equal_range(EFFECT_LPCOST_REPLACE); auto pr = effects.continuous_effect.equal_range(EFFECT_LPCOST_REPLACE);
for(auto eit = pr.first; eit != pr.second;) { for(auto eit = pr.first; eit != pr.second;) {
effect* peffect = eit->second; effect* peffect = eit->second;
......
...@@ -491,7 +491,7 @@ int32 field::process() { ...@@ -491,7 +491,7 @@ int32 field::process() {
return pduel->bufferlen; return pduel->bufferlen;
} }
case PROCESSOR_PAY_LPCOST: { case PROCESSOR_PAY_LPCOST: {
if (pay_lp_cost(it->step, it->arg1, it->arg2)) if (pay_lp_cost(it->step, it->arg1, it->arg2, it->arg3))
core.units.pop_front(); core.units.pop_front();
else else
it->step++; it->step++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment