Commit 5351cbe6 authored by DailyShana's avatar DailyShana

update AddCounter

parent c77efc27
...@@ -1515,8 +1515,8 @@ int32 card::destination_redirect(uint8 destination, uint32 reason) { ...@@ -1515,8 +1515,8 @@ int32 card::destination_redirect(uint8 destination, uint32 reason) {
} }
return 0; return 0;
} }
int32 card::add_counter(uint8 playerid, uint16 countertype, uint16 count) { int32 card::add_counter(uint8 playerid, uint16 countertype, uint16 count, uint8 singly) {
if(!is_can_add_counter(playerid, countertype, count)) if(!is_can_add_counter(playerid, countertype, count, singly))
return FALSE; return FALSE;
uint16 cttype = countertype; uint16 cttype = countertype;
if((countertype & COUNTER_NEED_ENABLE) && !(countertype & COUNTER_NEED_PERMIT)) if((countertype & COUNTER_NEED_ENABLE) && !(countertype & COUNTER_NEED_PERMIT))
...@@ -1527,16 +1527,29 @@ int32 card::add_counter(uint8 playerid, uint16 countertype, uint16 count) { ...@@ -1527,16 +1527,29 @@ int32 card::add_counter(uint8 playerid, uint16 countertype, uint16 count) {
cmit->second[0] = 0; cmit->second[0] = 0;
cmit->second[1] = 0; cmit->second[1] = 0;
} }
uint16 pcount = count;
if(singly) {
effect_set eset;
uint16 limit = 0;
filter_effect(EFFECT_COUNTER_LIMIT + cttype, &eset);
for(int32 i = 0; i < eset.size(); ++i)
limit = eset[i]->get_value();
if(limit) {
uint16 mcount = limit - get_counter(cttype);
if(pcount > mcount)
pcount = mcount;
}
}
if(!(countertype & COUNTER_NEED_ENABLE)) if(!(countertype & COUNTER_NEED_ENABLE))
cmit->second[0] += count; cmit->second[0] += pcount;
else else
cmit->second[1] += count; cmit->second[1] += pcount;
pduel->write_buffer8(MSG_ADD_COUNTER); pduel->write_buffer8(MSG_ADD_COUNTER);
pduel->write_buffer16(cttype); pduel->write_buffer16(cttype);
pduel->write_buffer8(current.controler); pduel->write_buffer8(current.controler);
pduel->write_buffer8(current.location); pduel->write_buffer8(current.location);
pduel->write_buffer8(current.sequence); pduel->write_buffer8(current.sequence);
pduel->write_buffer16(count); pduel->write_buffer16(pcount);
return TRUE; return TRUE;
} }
int32 card::remove_counter(uint16 countertype, uint16 count) { int32 card::remove_counter(uint16 countertype, uint16 count) {
...@@ -1561,7 +1574,7 @@ int32 card::remove_counter(uint16 countertype, uint16 count) { ...@@ -1561,7 +1574,7 @@ int32 card::remove_counter(uint16 countertype, uint16 count) {
pduel->write_buffer16(count); pduel->write_buffer16(count);
return TRUE; return TRUE;
} }
int32 card::is_can_add_counter(uint8 playerid, uint16 countertype, uint16 count) { int32 card::is_can_add_counter(uint8 playerid, uint16 countertype, uint16 count, uint8 singly) {
effect_set eset; effect_set eset;
if(!pduel->game_field->is_player_can_place_counter(playerid, this, countertype, count)) if(!pduel->game_field->is_player_can_place_counter(playerid, this, countertype, count))
return FALSE; return FALSE;
...@@ -1582,7 +1595,7 @@ int32 card::is_can_add_counter(uint8 playerid, uint16 countertype, uint16 count) ...@@ -1582,7 +1595,7 @@ int32 card::is_can_add_counter(uint8 playerid, uint16 countertype, uint16 count)
filter_effect(EFFECT_COUNTER_LIMIT + cttype, &eset); filter_effect(EFFECT_COUNTER_LIMIT + cttype, &eset);
for(int32 i = 0; i < eset.size(); ++i) for(int32 i = 0; i < eset.size(); ++i)
limit = eset[i]->get_value(); limit = eset[i]->get_value();
if(limit > 0 && (cur + count > limit)) if(limit > 0 && (cur + (singly ? 1 : count) > limit))
return FALSE; return FALSE;
return TRUE; return TRUE;
} }
......
...@@ -211,9 +211,9 @@ public: ...@@ -211,9 +211,9 @@ public:
void release_relation(effect* peffect); void release_relation(effect* peffect);
int32 leave_field_redirect(uint32 reason); int32 leave_field_redirect(uint32 reason);
int32 destination_redirect(uint8 destination, uint32 reason); int32 destination_redirect(uint8 destination, uint32 reason);
int32 add_counter(uint8 playerid, uint16 countertype, uint16 count); int32 add_counter(uint8 playerid, uint16 countertype, uint16 count, uint8 singly);
int32 remove_counter(uint16 countertype, uint16 count); int32 remove_counter(uint16 countertype, uint16 count);
int32 is_can_add_counter(uint8 playerid, uint16 countertype, uint16 count); int32 is_can_add_counter(uint8 playerid, uint16 countertype, uint16 count, uint8 singly);
int32 get_counter(uint16 countertype); int32 get_counter(uint16 countertype);
void set_material(card_set* materials); void set_material(card_set* materials);
void add_card_target(card* pcard); void add_card_target(card* pcard);
......
...@@ -1840,8 +1840,11 @@ int32 scriptlib::card_add_counter(lua_State *L) { ...@@ -1840,8 +1840,11 @@ int32 scriptlib::card_add_counter(lua_State *L) {
card* pcard = *(card**) lua_touserdata(L, 1); card* pcard = *(card**) lua_touserdata(L, 1);
uint32 countertype = lua_tointeger(L, 2); uint32 countertype = lua_tointeger(L, 2);
uint32 count = lua_tointeger(L, 3); uint32 count = lua_tointeger(L, 3);
uint8 singly = FALSE;
if(lua_gettop(L) > 3)
singly = lua_toboolean(L, 4);
if(pcard->is_affect_by_effect(pcard->pduel->game_field->core.reason_effect)) if(pcard->is_affect_by_effect(pcard->pduel->game_field->core.reason_effect))
lua_pushboolean(L, pcard->add_counter(pcard->pduel->game_field->core.reason_player, countertype, count)); lua_pushboolean(L, pcard->add_counter(pcard->pduel->game_field->core.reason_player, countertype, count, singly));
else lua_pushboolean(L, 0); else lua_pushboolean(L, 0);
return 1; return 1;
} }
...@@ -1927,7 +1930,10 @@ int32 scriptlib::card_is_can_add_counter(lua_State *L) { ...@@ -1927,7 +1930,10 @@ int32 scriptlib::card_is_can_add_counter(lua_State *L) {
card* pcard = *(card**) lua_touserdata(L, 1); card* pcard = *(card**) lua_touserdata(L, 1);
uint32 countertype = lua_tointeger(L, 2); uint32 countertype = lua_tointeger(L, 2);
uint32 count = lua_tointeger(L, 3); uint32 count = lua_tointeger(L, 3);
lua_pushboolean(L, pcard->is_can_add_counter(pcard->pduel->game_field->core.reason_player, countertype, count)); uint8 singly = FALSE;
if(lua_gettop(L) > 3)
singly = lua_toboolean(L, 4);
lua_pushboolean(L, pcard->is_can_add_counter(pcard->pduel->game_field->core.reason_player, countertype, count, singly));
return 1; return 1;
} }
int32 scriptlib::card_is_can_remove_counter(lua_State *L) { int32 scriptlib::card_is_can_remove_counter(lua_State *L) {
......
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