Commit 76e26b16 authored by VanillaSalt's avatar VanillaSalt

counter

parent ca04a9a0
...@@ -166,7 +166,7 @@ uint32 card::get_infos(byte* buf, int32 query_flag, int32 use_cache) { ...@@ -166,7 +166,7 @@ uint32 card::get_infos(byte* buf, int32 query_flag, int32 use_cache) {
if(query_flag & QUERY_COUNTERS) { if(query_flag & QUERY_COUNTERS) {
*p++ = counters.size(); *p++ = counters.size();
for(auto cmit = counters.begin(); cmit != counters.end(); ++cmit) for(auto cmit = counters.begin(); cmit != counters.end(); ++cmit)
*p++ = cmit->first + (cmit->second << 16); *p++ = cmit->first + ((cmit->second[0] + cmit->second[1]) << 16);
} }
if(query_flag & QUERY_OWNER) if(query_flag & QUERY_OWNER)
*p++ = owner; *p++ = owner;
...@@ -1155,7 +1155,7 @@ void card::remove_effect(effect* peffect, effect_container::iterator it) { ...@@ -1155,7 +1155,7 @@ void card::remove_effect(effect* peffect, effect_container::iterator it) {
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_buffer8(cmit->second); pduel->write_buffer8(cmit->second[0] + cmit->second[1]);
counters.erase(cmit); counters.erase(cmit);
} }
} }
...@@ -1249,14 +1249,16 @@ void card::reset(uint32 id, uint32 reset_type) { ...@@ -1249,14 +1249,16 @@ void card::reset(uint32 id, uint32 reset_type) {
if(id & RESET_DISABLE) { if(id & RESET_DISABLE) {
for(auto cmit = counters.begin(); cmit != counters.end();) { for(auto cmit = counters.begin(); cmit != counters.end();) {
auto rm = cmit++; auto rm = cmit++;
if(rm->first & COUNTER_NEED_ENABLE) { if(rm->second[1] > 0) {
pduel->write_buffer8(MSG_REMOVE_COUNTER); pduel->write_buffer8(MSG_REMOVE_COUNTER);
pduel->write_buffer16(rm->first); pduel->write_buffer16(rm->first);
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_buffer8(rm->second); pduel->write_buffer8(rm->second[1]);
counters.erase(rm); rm->second[1] = 0;
if(rm->second[0] == 0)
counters.erase(rm);
} }
} }
} }
...@@ -1397,9 +1399,21 @@ int32 card::destination_redirect(uint8 destination, uint32 reason) { ...@@ -1397,9 +1399,21 @@ int32 card::destination_redirect(uint8 destination, uint32 reason) {
int32 card::add_counter(uint8 playerid, uint16 countertype, uint16 count) { int32 card::add_counter(uint8 playerid, uint16 countertype, uint16 count) {
if(!is_can_add_counter(playerid, countertype, count)) if(!is_can_add_counter(playerid, countertype, count))
return FALSE; return FALSE;
counters[countertype] += count; uint16 cttype = countertype;
if((countertype & COUNTER_NEED_ENABLE) && !(countertype & COUNTER_NEED_PERMIT))
cttype &= 0xfff;
auto pr = counters.insert(std::make_pair(cttype, counter_map::mapped_type()));
auto cmit = pr.first;
if(pr.second) {
cmit->second[0] = 0;
cmit->second[1] = 0;
}
if(!(countertype & COUNTER_NEED_ENABLE))
cmit->second[0] += count;
else
cmit->second[1] += count;
pduel->write_buffer8(MSG_ADD_COUNTER); pduel->write_buffer8(MSG_ADD_COUNTER);
pduel->write_buffer16(countertype); 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);
...@@ -1410,9 +1424,16 @@ int32 card::remove_counter(uint16 countertype, uint16 count) { ...@@ -1410,9 +1424,16 @@ int32 card::remove_counter(uint16 countertype, uint16 count) {
auto cmit = counters.find(countertype); auto cmit = counters.find(countertype);
if(cmit == counters.end()) if(cmit == counters.end())
return FALSE; return FALSE;
if(cmit->second <= count) if(cmit->second[1] <= count) {
counters.erase(cmit); uint16 remains = count;
else cmit->second -= count; remains -= cmit->second[1];
cmit->second[1] = 0;
if(cmit->second[0] <= remains)
counters.erase(cmit);
else cmit->second[0] -= remains;
} else {
cmit->second[1] -= count;
}
pduel->write_buffer8(MSG_REMOVE_COUNTER); pduel->write_buffer8(MSG_REMOVE_COUNTER);
pduel->write_buffer16(countertype); pduel->write_buffer16(countertype);
pduel->write_buffer8(current.controler); pduel->write_buffer8(current.controler);
...@@ -1431,12 +1452,15 @@ int32 card::is_can_add_counter(uint8 playerid, uint16 countertype, uint16 count) ...@@ -1431,12 +1452,15 @@ int32 card::is_can_add_counter(uint8 playerid, uint16 countertype, uint16 count)
return FALSE; return FALSE;
if((countertype & COUNTER_NEED_PERMIT) && !is_affected_by_effect(EFFECT_COUNTER_PERMIT + (countertype & 0xffff))) if((countertype & COUNTER_NEED_PERMIT) && !is_affected_by_effect(EFFECT_COUNTER_PERMIT + (countertype & 0xffff)))
return FALSE; return FALSE;
uint16 cttype = countertype;
if((countertype & COUNTER_NEED_ENABLE) && !(countertype & COUNTER_NEED_PERMIT))
cttype &= 0xfff;
int32 limit = -1; int32 limit = -1;
int32 cur = 0; int32 cur = 0;
auto cmit = counters.find(countertype); auto cmit = counters.find(cttype);
if(cmit != counters.end()) if(cmit != counters.end())
cur = cmit->second; cur = cmit->second[0] + cmit->second[1];
filter_effect(EFFECT_COUNTER_LIMIT + countertype, &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 + count > limit))
...@@ -1447,7 +1471,7 @@ int32 card::get_counter(uint16 countertype) { ...@@ -1447,7 +1471,7 @@ int32 card::get_counter(uint16 countertype) {
auto cmit = counters.find(countertype); auto cmit = counters.find(countertype);
if(cmit == counters.end()) if(cmit == counters.end())
return 0; return 0;
return cmit->second; return cmit->second[0] + cmit->second[1];
} }
void card::set_material(card_set* materials) { void card::set_material(card_set* materials) {
if(!materials) { if(!materials) {
......
...@@ -84,7 +84,7 @@ public: ...@@ -84,7 +84,7 @@ public:
typedef std::unordered_map<effect*, effect_container::iterator> effect_indexer; typedef std::unordered_map<effect*, effect_container::iterator> effect_indexer;
typedef std::unordered_map<effect*, uint32> effect_relation; typedef std::unordered_map<effect*, uint32> effect_relation;
typedef std::unordered_map<card*, uint32> relation_map; typedef std::unordered_map<card*, uint32> relation_map;
typedef std::map<uint16, uint16> counter_map; typedef std::map<uint16, std::array<uint16, 2> > counter_map;
typedef std::unordered_map<uint16, card*> attacker_map; typedef std::unordered_map<uint16, card*> attacker_map;
int32 scrtype; int32 scrtype;
int32 ref_handle; int32 ref_handle;
......
...@@ -1771,7 +1771,7 @@ int32 scriptlib::card_remove_counter(lua_State *L) { ...@@ -1771,7 +1771,7 @@ int32 scriptlib::card_remove_counter(lua_State *L) {
pcard->pduel->write_buffer8(pcard->current.controler); pcard->pduel->write_buffer8(pcard->current.controler);
pcard->pduel->write_buffer8(pcard->current.location); pcard->pduel->write_buffer8(pcard->current.location);
pcard->pduel->write_buffer8(pcard->current.sequence); pcard->pduel->write_buffer8(pcard->current.sequence);
pcard->pduel->write_buffer8(cmit->second); pcard->pduel->write_buffer8(cmit->second[0] + cmit->second[1]);
} }
pcard->counters.clear(); pcard->counters.clear();
return 0; return 0;
......
...@@ -109,9 +109,21 @@ int32 scriptlib::debug_pre_add_counter(lua_State *L) { ...@@ -109,9 +109,21 @@ int32 scriptlib::debug_pre_add_counter(lua_State *L) {
check_param_count(L, 2); check_param_count(L, 2);
check_param(L, PARAM_TYPE_CARD, 1); check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1); card* pcard = *(card**) lua_touserdata(L, 1);
uint32 ctype = lua_tointeger(L, 2); uint32 countertype = lua_tointeger(L, 2);
uint32 ccount = lua_tointeger(L, 3); uint32 count = lua_tointeger(L, 3);
pcard->counters[ctype] += ccount; uint16 cttype = countertype;
if((countertype & COUNTER_NEED_ENABLE) && !(countertype & COUNTER_NEED_PERMIT))
cttype &= 0xfff;
auto pr = pcard->counters.insert(std::make_pair(cttype, card::counter_map::mapped_type()));
auto cmit = pr.first;
if(pr.second) {
cmit->second[0] = 0;
cmit->second[1] = 0;
}
if(!(countertype & COUNTER_NEED_ENABLE))
cmit->second[0] += count;
else
cmit->second[1] += count;
return 0; return 0;
} }
int32 scriptlib::debug_reload_field_begin(lua_State *L) { int32 scriptlib::debug_reload_field_begin(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