Commit e1f77651 authored by fallenstardust's avatar fallenstardust

sync ocgcore

parent 1322fb7a
...@@ -1923,6 +1923,9 @@ void card::reset(uint32 id, uint32 reset_type) { ...@@ -1923,6 +1923,9 @@ void card::reset(uint32 id, uint32 reset_type) {
for(; pr.first != pr.second; ++pr.first) for(; pr.first != pr.second; ++pr.first)
pr.first->second->value = pr.first->second->value & 0xffff; pr.first->second->value = pr.first->second->value & 0xffff;
} }
if(id & RESET_TOFIELD) {
pre_equip_target = 0;
}
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++;
...@@ -2126,7 +2129,7 @@ int32 card::destination_redirect(uint8 destination, uint32 reason) { ...@@ -2126,7 +2129,7 @@ int32 card::destination_redirect(uint8 destination, uint32 reason) {
int32 card::add_counter(uint8 playerid, uint16 countertype, uint16 count, uint8 singly) { int32 card::add_counter(uint8 playerid, uint16 countertype, uint16 count, uint8 singly) {
if(!is_can_add_counter(playerid, countertype, count, singly, 0)) if(!is_can_add_counter(playerid, countertype, count, singly, 0))
return FALSE; return FALSE;
uint16 cttype = countertype & ~COUNTER_NEED_ENABLE; uint16 cttype = countertype;
auto pr = counters.emplace(cttype, counter_map::mapped_type()); auto pr = counters.emplace(cttype, counter_map::mapped_type());
auto cmit = pr.first; auto cmit = pr.first;
if(pr.second) { if(pr.second) {
...@@ -2146,7 +2149,7 @@ int32 card::add_counter(uint8 playerid, uint16 countertype, uint16 count, uint8 ...@@ -2146,7 +2149,7 @@ int32 card::add_counter(uint8 playerid, uint16 countertype, uint16 count, uint8
pcount = mcount; pcount = mcount;
} }
} }
if((countertype & COUNTER_WITHOUT_PERMIT) && !(countertype & COUNTER_NEED_ENABLE)) if(countertype & COUNTER_WITHOUT_PERMIT)
cmit->second[0] += pcount; cmit->second[0] += pcount;
else else
cmit->second[1] += pcount; cmit->second[1] += pcount;
...@@ -2189,8 +2192,6 @@ int32 card::is_can_add_counter(uint8 playerid, uint16 countertype, uint16 count, ...@@ -2189,8 +2192,6 @@ int32 card::is_can_add_counter(uint8 playerid, uint16 countertype, uint16 count,
return FALSE; return FALSE;
if(!loc && (!(current.location & LOCATION_ONFIELD) || !is_position(POS_FACEUP))) if(!loc && (!(current.location & LOCATION_ONFIELD) || !is_position(POS_FACEUP)))
return FALSE; return FALSE;
if((countertype & COUNTER_NEED_ENABLE) && is_status(STATUS_DISABLED))
return FALSE;
} }
uint32 check = countertype & COUNTER_WITHOUT_PERMIT; uint32 check = countertype & COUNTER_WITHOUT_PERMIT;
if(!check) { if(!check) {
...@@ -2216,7 +2217,7 @@ int32 card::is_can_add_counter(uint8 playerid, uint16 countertype, uint16 count, ...@@ -2216,7 +2217,7 @@ int32 card::is_can_add_counter(uint8 playerid, uint16 countertype, uint16 count,
} }
if(!check) if(!check)
return FALSE; return FALSE;
uint16 cttype = countertype & ~COUNTER_NEED_ENABLE; uint16 cttype = countertype;
int32 limit = -1; int32 limit = -1;
int32 cur = 0; int32 cur = 0;
auto cmit = counters.find(cttype); auto cmit = counters.find(cttype);
...@@ -3048,7 +3049,6 @@ int32 card::is_can_be_summoned(uint8 playerid, uint8 ignore_count, effect* peffe ...@@ -3048,7 +3049,6 @@ int32 card::is_can_be_summoned(uint8 playerid, uint8 ignore_count, effect* peffe
} }
int32 card::get_summon_tribute_count() { int32 card::get_summon_tribute_count() {
int32 min = 0, max = 0; int32 min = 0, max = 0;
int32 minul = 0, maxul = 0;
int32 level = get_level(); int32 level = get_level();
if(level < 5) if(level < 5)
return 0; return 0;
...@@ -3056,22 +3056,26 @@ int32 card::get_summon_tribute_count() { ...@@ -3056,22 +3056,26 @@ int32 card::get_summon_tribute_count() {
min = max = 1; min = max = 1;
else else
min = max = 2; min = max = 2;
std::vector<int32> duplicate;
effect_set eset; effect_set eset;
filter_effect(EFFECT_DECREASE_TRIBUTE, &eset); filter_effect(EFFECT_DECREASE_TRIBUTE, &eset);
for(int32 i = 0; i < eset.size(); ++i) { for(int32 i = 0; i < eset.size(); ++i) {
int32 dec = eset[i]->get_value(this); if(eset[i]->is_flag(EFFECT_FLAG_COUNT_LIMIT) && eset[i]->count_limit == 0)
if(!eset[i]->is_flag(EFFECT_FLAG_COUNT_LIMIT)) { continue;
if(minul < (dec & 0xffff)) std::vector<int32> retval;
minul = dec & 0xffff; eset[i]->get_value(this, 0, &retval);
if(maxul < (dec >> 16)) int32 dec = retval.size() > 0 ? retval[0] : 0;
maxul = dec >> 16; int32 effect_code = retval.size() > 1 ? retval[1] : 0;
} else if(eset[i]->count_limit > 0) { if(effect_code > 0) {
auto it = std::find(duplicate.begin(), duplicate.end(), effect_code);
if(it == duplicate.end())
duplicate.push_back(effect_code);
else
continue;
}
min -= dec & 0xffff; min -= dec & 0xffff;
max -= dec >> 16; max -= dec >> 16;
} }
}
min -= minul;
max -= maxul;
if(min < 0) min = 0; if(min < 0) min = 0;
if(max < min) max = min; if(max < min) max = min;
return min + (max << 16); return min + (max << 16);
...@@ -3085,10 +3089,23 @@ int32 card::get_set_tribute_count() { ...@@ -3085,10 +3089,23 @@ int32 card::get_set_tribute_count() {
min = max = 1; min = max = 1;
else else
min = max = 2; min = max = 2;
std::vector<int32> duplicate;
effect_set eset; effect_set eset;
filter_effect(EFFECT_DECREASE_TRIBUTE_SET, &eset); filter_effect(EFFECT_DECREASE_TRIBUTE_SET, &eset);
if(eset.size()) { for(int32 i = 0; i < eset.size(); ++i) {
int32 dec = eset.get_last()->get_value(this); if(eset[i]->is_flag(EFFECT_FLAG_COUNT_LIMIT) && eset[i]->count_limit == 0)
continue;
std::vector<int32> retval;
eset[i]->get_value(this, 0, &retval);
int32 dec = retval.size() > 0 ? retval[0] : 0;
int32 effect_code = retval.size() > 1 ? retval[1] : 0;
if(effect_code > 0) {
auto it = std::find(duplicate.begin(), duplicate.end(), effect_code);
if(it == duplicate.end())
duplicate.push_back(effect_code);
else
continue;
}
min -= dec & 0xffff; min -= dec & 0xffff;
max -= dec >> 16; max -= dec >> 16;
} }
......
...@@ -366,7 +366,7 @@ public: ...@@ -366,7 +366,7 @@ public:
#define SUMMON_TYPE_LINK 0x4c000000 #define SUMMON_TYPE_LINK 0x4c000000
//Counter //Counter
#define COUNTER_WITHOUT_PERMIT 0x1000 #define COUNTER_WITHOUT_PERMIT 0x1000
#define COUNTER_NEED_ENABLE 0x2000 //#define COUNTER_NEED_ENABLE 0x2000
#define ASSUME_CODE 1 #define ASSUME_CODE 1
#define ASSUME_TYPE 2 #define ASSUME_TYPE 2
......
...@@ -196,7 +196,7 @@ enum effect_flag : uint32 { ...@@ -196,7 +196,7 @@ enum effect_flag : uint32 {
EFFECT_FLAG_IMMEDIATELY_APPLY = 0x80000000, EFFECT_FLAG_IMMEDIATELY_APPLY = 0x80000000,
}; };
enum effect_flag2 : uint32 { enum effect_flag2 : uint32 {
// EFFECT_FLAG2_NAGA = 0x0001, EFFECT_FLAG2_MILLENNIUM_RESTRICT = 0x0001,
EFFECT_FLAG2_COF = 0x0002, EFFECT_FLAG2_COF = 0x0002,
}; };
inline effect_flag operator|(effect_flag flag1, effect_flag flag2) inline effect_flag operator|(effect_flag flag1, effect_flag flag2)
......
...@@ -383,6 +383,16 @@ int32 scriptlib::card_get_origin_rscale(lua_State *L) { ...@@ -383,6 +383,16 @@ int32 scriptlib::card_get_origin_rscale(lua_State *L) {
lua_pushinteger(L, pcard->data.rscale); lua_pushinteger(L, pcard->data.rscale);
return 1; return 1;
} }
int32 scriptlib::card_get_current_scale(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**)lua_touserdata(L, 1);
if(pcard->current.pzone && pcard->current.sequence == (pcard->pduel->game_field->core.duel_rule >= 4 ? 0 : 6))
lua_pushinteger(L, pcard->get_lscale());
else
lua_pushinteger(L, pcard->get_rscale());
return 1;
}
int32 scriptlib::card_is_link_marker(lua_State *L) { int32 scriptlib::card_is_link_marker(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);
...@@ -3204,6 +3214,7 @@ static const struct luaL_Reg cardlib[] = { ...@@ -3204,6 +3214,7 @@ static const struct luaL_Reg cardlib[] = {
{ "GetOriginalLeftScale", scriptlib::card_get_origin_lscale }, { "GetOriginalLeftScale", scriptlib::card_get_origin_lscale },
{ "GetRightScale", scriptlib::card_get_rscale }, { "GetRightScale", scriptlib::card_get_rscale },
{ "GetOriginalRightScale", scriptlib::card_get_origin_rscale }, { "GetOriginalRightScale", scriptlib::card_get_origin_rscale },
{ "GetCurrentScale", scriptlib::card_get_current_scale },
{ "IsLinkMarker", scriptlib::card_is_link_marker }, { "IsLinkMarker", scriptlib::card_is_link_marker },
{ "GetLinkedGroup", scriptlib::card_get_linked_group }, { "GetLinkedGroup", scriptlib::card_get_linked_group },
{ "GetLinkedGroupCount", scriptlib::card_get_linked_group_count }, { "GetLinkedGroupCount", scriptlib::card_get_linked_group_count },
......
...@@ -127,14 +127,14 @@ int32 scriptlib::debug_pre_add_counter(lua_State *L) { ...@@ -127,14 +127,14 @@ int32 scriptlib::debug_pre_add_counter(lua_State *L) {
card* pcard = *(card**) lua_touserdata(L, 1); card* pcard = *(card**) lua_touserdata(L, 1);
uint32 countertype = (uint32)lua_tointeger(L, 2); uint32 countertype = (uint32)lua_tointeger(L, 2);
uint32 count = (uint32)lua_tointeger(L, 3); uint32 count = (uint32)lua_tointeger(L, 3);
uint16 cttype = countertype & ~COUNTER_NEED_ENABLE; uint16 cttype = countertype;
auto pr = pcard->counters.emplace(cttype, card::counter_map::mapped_type()); auto pr = pcard->counters.emplace(cttype, card::counter_map::mapped_type());
auto cmit = pr.first; auto cmit = pr.first;
if(pr.second) { if(pr.second) {
cmit->second[0] = 0; cmit->second[0] = 0;
cmit->second[1] = 0; cmit->second[1] = 0;
} }
if((countertype & COUNTER_WITHOUT_PERMIT) && !(countertype & COUNTER_NEED_ENABLE)) if(countertype & COUNTER_WITHOUT_PERMIT)
cmit->second[0] += count; cmit->second[0] += count;
else else
cmit->second[1] += count; cmit->second[1] += count;
......
...@@ -1766,29 +1766,43 @@ int32 field::summon(uint16 step, uint8 sumplayer, card* target, effect* proc, ui ...@@ -1766,29 +1766,43 @@ int32 field::summon(uint16 step, uint8 sumplayer, card* target, effect* proc, ui
if(tributes) if(tributes)
min -= (int32)tributes->size(); min -= (int32)tributes->size();
if(min > 0) { if(min > 0) {
std::vector<int32> duplicate;
effect_set eset; effect_set eset;
target->filter_effect(EFFECT_DECREASE_TRIBUTE, &eset); target->filter_effect(EFFECT_DECREASE_TRIBUTE, &eset);
int32 minul = 0;
effect* pdec = 0;
for(int32 i = 0; i < eset.size(); ++i) { for(int32 i = 0; i < eset.size(); ++i) {
if(!eset[i]->is_flag(EFFECT_FLAG_COUNT_LIMIT)) { if(eset[i]->is_flag(EFFECT_FLAG_COUNT_LIMIT))
int32 dec = eset[i]->get_value(target); continue;
if(minul < (dec & 0xffff)) { std::vector<int32> retval;
minul = dec & 0xffff; eset[i]->get_value(target, 0, &retval);
pdec = eset[i]; int32 dec = retval.size() > 0 ? retval[0] : 0;
} int32 effect_code = retval.size() > 1 ? retval[1] : 0;
} if(effect_code > 0) {
auto it = std::find(duplicate.begin(), duplicate.end(), effect_code);
if(it == duplicate.end())
duplicate.push_back(effect_code);
else
continue;
} }
if(pdec) { min -= dec & 0xffff;
min -= minul;
pduel->write_buffer8(MSG_HINT); pduel->write_buffer8(MSG_HINT);
pduel->write_buffer8(HINT_CARD); pduel->write_buffer8(HINT_CARD);
pduel->write_buffer8(0); pduel->write_buffer8(0);
pduel->write_buffer32(pdec->handler->data.code); pduel->write_buffer32(eset[i]->handler->data.code);
} }
for(int32 i = 0; i < eset.size() && min > 0; ++i) { for(int32 i = 0; i < eset.size() && min > 0; ++i) {
if(eset[i]->is_flag(EFFECT_FLAG_COUNT_LIMIT) && eset[i]->count_limit > 0 && eset[i]->target) { if(!eset[i]->is_flag(EFFECT_FLAG_COUNT_LIMIT) || eset[i]->count_limit == 0 || !eset[i]->target)
int32 dec = eset[i]->get_value(target); continue;
std::vector<int32> retval;
eset[i]->get_value(target, 0, &retval);
int32 dec = retval.size() > 0 ? retval[0] : 0;
int32 effect_code = retval.size() > 1 ? retval[1] : 0;
if(effect_code > 0) {
auto it = std::find(duplicate.begin(), duplicate.end(), effect_code);
if(it == duplicate.end())
duplicate.push_back(effect_code);
else
continue;
}
min -= dec & 0xffff; min -= dec & 0xffff;
eset[i]->dec_count(); eset[i]->dec_count();
pduel->write_buffer8(MSG_HINT); pduel->write_buffer8(MSG_HINT);
...@@ -1796,10 +1810,20 @@ int32 field::summon(uint16 step, uint8 sumplayer, card* target, effect* proc, ui ...@@ -1796,10 +1810,20 @@ int32 field::summon(uint16 step, uint8 sumplayer, card* target, effect* proc, ui
pduel->write_buffer8(0); pduel->write_buffer8(0);
pduel->write_buffer32(eset[i]->handler->data.code); pduel->write_buffer32(eset[i]->handler->data.code);
} }
}
for(int32 i = 0; i < eset.size() && min > 0; ++i) { for(int32 i = 0; i < eset.size() && min > 0; ++i) {
if(eset[i]->is_flag(EFFECT_FLAG_COUNT_LIMIT) && eset[i]->count_limit > 0 && !eset[i]->target) { if(!eset[i]->is_flag(EFFECT_FLAG_COUNT_LIMIT) || eset[i]->count_limit == 0 || eset[i]->target)
int32 dec = eset[i]->get_value(target); continue;
std::vector<int32> retval;
eset[i]->get_value(target, 0, &retval);
int32 dec = retval.size() > 0 ? retval[0] : 0;
int32 effect_code = retval.size() > 1 ? retval[1] : 0;
if(effect_code > 0) {
auto it = std::find(duplicate.begin(), duplicate.end(), effect_code);
if(it == duplicate.end())
duplicate.push_back(effect_code);
else
continue;
}
min -= dec & 0xffff; min -= dec & 0xffff;
eset[i]->dec_count(); eset[i]->dec_count();
pduel->write_buffer8(MSG_HINT); pduel->write_buffer8(MSG_HINT);
...@@ -1808,7 +1832,6 @@ int32 field::summon(uint16 step, uint8 sumplayer, card* target, effect* proc, ui ...@@ -1808,7 +1832,6 @@ int32 field::summon(uint16 step, uint8 sumplayer, card* target, effect* proc, ui
pduel->write_buffer32(eset[i]->handler->data.code); pduel->write_buffer32(eset[i]->handler->data.code);
} }
} }
}
if(tributes) { if(tributes) {
for(auto& pcard : *tributes) for(auto& pcard : *tributes)
pcard->current.reason_card = target; pcard->current.reason_card = target;
...@@ -2302,6 +2325,83 @@ int32 field::mset(uint16 step, uint8 setplayer, card* target, effect* proc, uint ...@@ -2302,6 +2325,83 @@ int32 field::mset(uint16 step, uint8 setplayer, card* target, effect* proc, uint
} }
case 5: { case 5: {
card_set* tributes = (card_set*)proc; card_set* tributes = (card_set*)proc;
int32 min = 0;
int32 level = target->get_level();
if(level < 5)
min = 0;
else if(level < 7)
min = 1;
else
min = 2;
if(tributes)
min -= (int32)tributes->size();
if(min > 0) {
std::vector<int32> duplicate;
effect_set eset;
target->filter_effect(EFFECT_DECREASE_TRIBUTE_SET, &eset);
for(int32 i = 0; i < eset.size(); ++i) {
if(eset[i]->is_flag(EFFECT_FLAG_COUNT_LIMIT))
continue;
std::vector<int32> retval;
eset[i]->get_value(target, 0, &retval);
int32 dec = retval.size() > 0 ? retval[0] : 0;
int32 effect_code = retval.size() > 1 ? retval[1] : 0;
if(effect_code > 0) {
auto it = std::find(duplicate.begin(), duplicate.end(), effect_code);
if(it == duplicate.end())
duplicate.push_back(effect_code);
else
continue;
}
min -= dec & 0xffff;
pduel->write_buffer8(MSG_HINT);
pduel->write_buffer8(HINT_CARD);
pduel->write_buffer8(0);
pduel->write_buffer32(eset[i]->handler->data.code);
}
for(int32 i = 0; i < eset.size() && min > 0; ++i) {
if(!eset[i]->is_flag(EFFECT_FLAG_COUNT_LIMIT) || eset[i]->count_limit == 0 || !eset[i]->target)
continue;
std::vector<int32> retval;
eset[i]->get_value(target, 0, &retval);
int32 dec = retval.size() > 0 ? retval[0] : 0;
int32 effect_code = retval.size() > 1 ? retval[1] : 0;
if(effect_code > 0) {
auto it = std::find(duplicate.begin(), duplicate.end(), effect_code);
if(it == duplicate.end())
duplicate.push_back(effect_code);
else
continue;
}
min -= dec & 0xffff;
eset[i]->dec_count();
pduel->write_buffer8(MSG_HINT);
pduel->write_buffer8(HINT_CARD);
pduel->write_buffer8(0);
pduel->write_buffer32(eset[i]->handler->data.code);
}
for(int32 i = 0; i < eset.size() && min > 0; ++i) {
if(!eset[i]->is_flag(EFFECT_FLAG_COUNT_LIMIT) || eset[i]->count_limit == 0 || eset[i]->target)
continue;
std::vector<int32> retval;
eset[i]->get_value(target, 0, &retval);
int32 dec = retval.size() > 0 ? retval[0] : 0;
int32 effect_code = retval.size() > 1 ? retval[1] : 0;
if(effect_code > 0) {
auto it = std::find(duplicate.begin(), duplicate.end(), effect_code);
if(it == duplicate.end())
duplicate.push_back(effect_code);
else
continue;
}
min -= dec & 0xffff;
eset[i]->dec_count();
pduel->write_buffer8(MSG_HINT);
pduel->write_buffer8(HINT_CARD);
pduel->write_buffer8(0);
pduel->write_buffer32(eset[i]->handler->data.code);
}
}
if(tributes) { if(tributes) {
for(auto& pcard : *tributes) for(auto& pcard : *tributes)
pcard->current.reason_card = target; pcard->current.reason_card = target;
......
...@@ -4007,6 +4007,7 @@ int32 field::add_chain(uint16 step) { ...@@ -4007,6 +4007,7 @@ int32 field::add_chain(uint16 step) {
auto& clit = core.new_chains.front(); auto& clit = core.new_chains.front();
effect* peffect = clit.triggering_effect; effect* peffect = clit.triggering_effect;
card* phandler = peffect->get_handler(); card* phandler = peffect->get_handler();
phandler->refresh_disable_status();
if(peffect->type & EFFECT_TYPE_ACTIVATE) { if(peffect->type & EFFECT_TYPE_ACTIVATE) {
clit.set_triggering_state(phandler); clit.set_triggering_state(phandler);
} }
......
...@@ -48,6 +48,7 @@ public: ...@@ -48,6 +48,7 @@ public:
static int32 card_get_origin_lscale(lua_State *L); static int32 card_get_origin_lscale(lua_State *L);
static int32 card_get_rscale(lua_State *L); static int32 card_get_rscale(lua_State *L);
static int32 card_get_origin_rscale(lua_State *L); static int32 card_get_origin_rscale(lua_State *L);
static int32 card_get_current_scale(lua_State *L);
static int32 card_is_link_marker(lua_State *L); static int32 card_is_link_marker(lua_State *L);
static int32 card_get_linked_group(lua_State *L); static int32 card_get_linked_group(lua_State *L);
static int32 card_get_linked_group_count(lua_State *L); static int32 card_get_linked_group_count(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