Commit f33afa5d authored by VanillaSalt's avatar VanillaSalt

fix

parent 2c3800be
......@@ -551,14 +551,14 @@ int32 field::get_useable_count(card* pcard, uint8 playerid, uint8 location, uint
else
return get_useable_count(playerid, location, uplayer, reason, zone, list);
}
int32 field::get_spsummonable_count(card* pcard, uint8 playerid, uint8 uplayer, uint32 zone, uint32* list) {
int32 field::get_spsummonable_count(card* pcard, uint8 playerid, uint32 zone, uint32* list) {
if(core.duel_rule >= 4 && pcard->current.location == LOCATION_EXTRA)
return get_spsummonable_count_fromex(pcard, playerid, uplayer, zone, list);
return get_spsummonable_count_fromex(pcard, playerid, zone, list);
else
return get_tofield_count(playerid, LOCATION_MZONE, uplayer, zone, list);
return get_tofield_count(playerid, LOCATION_MZONE, zone, list);
}
int32 field::get_useable_count(uint8 playerid, uint8 location, uint8 uplayer, uint32 reason, uint32 zone, uint32* list) {
int32 count = get_tofield_count(playerid, location, uplayer, zone, list);
int32 count = get_tofield_count(playerid, location, zone, list);
int32 limit;
if(location == LOCATION_MZONE)
limit = get_mzone_limit(playerid, uplayer, LOCATION_REASON_TOFIELD);
......@@ -568,7 +568,7 @@ int32 field::get_useable_count(uint8 playerid, uint8 location, uint8 uplayer, ui
count = limit;
return count;
}
int32 field::get_tofield_count(uint8 playerid, uint8 location, uint8 uplayer, uint32 zone, uint32* list) {
int32 field::get_tofield_count(uint8 playerid, uint8 location, uint32 zone, uint32* list) {
if (location != LOCATION_MZONE && location != LOCATION_SZONE)
return 0;
uint32 flag = player[playerid].disabled_location | player[playerid].used_location;
......@@ -584,13 +584,13 @@ int32 field::get_tofield_count(uint8 playerid, uint8 location, uint8 uplayer, ui
return count;
}
int32 field::get_useable_count_fromex(card* pcard, uint8 playerid, uint8 uplayer, uint32 zone, uint32* list) {
int32 count = get_spsummonable_count_fromex(pcard, playerid, uplayer, zone, list);
int32 count = get_spsummonable_count_fromex(pcard, playerid, zone, list);
int32 limit = get_mzone_limit(playerid, uplayer, LOCATION_REASON_TOFIELD);
if(count > limit)
count = limit;
return count;
}
int32 field::get_spsummonable_count_fromex(card* pcard, uint8 playerid, uint8 uplayer, uint32 zone, uint32* list) {
int32 field::get_spsummonable_count_fromex(card* pcard, uint8 playerid, uint32 zone, uint32* list) {
uint32 flag = player[playerid].disabled_location | player[playerid].used_location;
uint32 linked_zone = get_linked_zone(playerid);
flag = (flag | ~zone | ~linked_zone) & 0x1f;
......@@ -2017,7 +2017,7 @@ int32 field::check_lp_cost(uint8 playerid, uint32 lp) {
e.reason_effect = core.reason_effect;
e.reason_player = playerid;
if(effect_replace_check(EFFECT_LPCOST_REPLACE, e))
return true;
return TRUE;
cost[playerid].amount += val;
if(cost[playerid].amount <= player[playerid].lp)
return TRUE;
......
......@@ -343,11 +343,11 @@ public:
card* get_field_card(uint32 playerid, uint32 location, uint32 sequence);
int32 is_location_useable(uint32 playerid, uint32 location, uint32 sequence);
int32 get_useable_count(card* pcard, uint8 playerid, uint8 location, uint8 uplayer, uint32 reason, uint32 zone = 0xff, uint32* list = 0);
int32 get_spsummonable_count(card* pcard, uint8 playerid, uint8 uplayer, uint32 zone = 0xff, uint32* list = 0);
int32 get_spsummonable_count(card* pcard, uint8 playerid, uint32 zone = 0xff, uint32* list = 0);
int32 get_useable_count(uint8 playerid, uint8 location, uint8 uplayer, uint32 reason, uint32 zone = 0xff, uint32* list = 0);
int32 get_tofield_count(uint8 playerid, uint8 location, uint8 uplayer, uint32 zone = 0xff, uint32* list = 0);
int32 get_tofield_count(uint8 playerid, uint8 location, uint32 zone = 0xff, uint32* list = 0);
int32 get_useable_count_fromex(card* pcard, uint8 playerid, uint8 uplayer, uint32 zone = 0xff, uint32* list = 0);
int32 get_spsummonable_count_fromex(card* pcard, uint8 playerid, uint8 uplayer, uint32 zone = 0xff, uint32* list = 0);
int32 get_spsummonable_count_fromex(card* pcard, uint8 playerid, uint32 zone = 0xff, uint32* list = 0);
int32 get_mzone_limit(uint8 playerid, uint8 uplayer, uint32 reason);
int32 get_szone_limit(uint8 playerid, uint8 uplayer, uint32 reason);
uint32 get_linked_zone(int32 playerid);
......
......@@ -1525,8 +1525,8 @@ int32 scriptlib::duel_get_usable_mzone_count(lua_State *L) {
uint32 zone = 0xff;
if(pduel->game_field->core.duel_rule >= 4) {
uint32 flag1, flag2;
int32 ct1 = pduel->game_field->get_tofield_count(playerid, LOCATION_MZONE, uplayer, zone, &flag1);
int32 ct2 = pduel->game_field->get_spsummonable_count_fromex(0, playerid, uplayer, zone, &flag2);
int32 ct1 = pduel->game_field->get_tofield_count(playerid, LOCATION_MZONE, zone, &flag1);
int32 ct2 = pduel->game_field->get_spsummonable_count_fromex(0, playerid, zone, &flag2);
int32 ct3 = field::field_used_count[~(flag1 | flag2) & 0x1f];
int32 count = ct1 + ct2 - ct3;
int32 limit = pduel->game_field->get_mzone_limit(playerid, uplayer, LOCATION_REASON_TOFIELD);
......
......@@ -625,6 +625,7 @@ int32 field::pay_lp_cost(uint32 step, uint8 playerid, uint32 cost) {
effect* peffect = core.select_effects[returns.ivalue[0]];
if(!peffect) {
player[playerid].lp -= cost;
this->cost[playerid].amount -= cost;
pduel->write_buffer8(MSG_PAY_LPCOST);
pduel->write_buffer8(playerid);
pduel->write_buffer32(cost);
......@@ -3968,6 +3969,8 @@ int32 field::move_to_field(uint16 step, card* target, uint32 enable, uint32 ret,
flag |= 0x1u << (core.duel_rule >= 4 ? 8 : 14);
if(is_location_useable(playerid, LOCATION_PZONE, 1))
flag |= 0x1u << (core.duel_rule >= 4 ? 12 : 15);
if(!flag)
return TRUE;
if(move_player != playerid)
flag = flag << 16;
flag = ~flag;
......@@ -4615,7 +4618,8 @@ int32 field::select_synchro_material(int16 step, uint8 playerid, card* pcard, in
core.must_select_cards.push_back(smat);
smat->sum_param = smat->get_synchro_level(pcard);
}
core.select_cards.clear();
card_vector nsyn(core.must_select_cards);
int32 mcount = nsyn.size();
if(mg) {
for(auto cit = mg->container.begin(); cit != mg->container.end(); ++cit) {
card* pm = *cit;
......@@ -4633,7 +4637,7 @@ int32 field::select_synchro_material(int16 step, uint8 playerid, card* pcard, in
continue;
if(!pduel->lua->check_matching(pm, -1, 0))
continue;
core.select_cards.push_back(pm);
nsyn.push_back(pm);
pm->sum_param = pm->get_synchro_level(pcard);
}
} else {
......@@ -4660,52 +4664,57 @@ int32 field::select_synchro_material(int16 step, uint8 playerid, card* pcard, in
continue;
if(!pduel->lua->check_matching(pm, -1, 0))
continue;
core.select_cards.push_back(pm);
nsyn.push_back(pm);
pm->sum_param = pm->get_synchro_level(pcard);
}
}
int32 playerid = pcard->current.controler;
int32 ct = get_spsummonable_count(pcard, playerid, playerid);
if(ct <= 0) {
card_set linked_cards;
uint32 linked_zone = core.duel_rule >= 4 ? get_linked_zone(playerid) | (1u << 5) | (1u << 6) : 0x1f;
get_cards_in_zone(&linked_cards, linked_zone, playerid);
if(linked_cards.find(tuner) != linked_cards.end())
ct++;
if(smat) {
if(linked_cards.find(smat) != linked_cards.end())
ct++;
}
int32 lv = pcard->get_level();
core.select_cards.clear();
auto start = nsyn.begin() + mcount;
for(auto cit = start; cit != nsyn.end(); ++cit) {
card* pm = *cit;
if(start != cit)
std::iter_swap(start, cit);
if(check_other_synchro_material(nsyn, lv, min - 1, max - 1, mcount + 1))
core.select_cards.push_back(pm);
if(start != cit)
std::iter_swap(start, cit);
}
if(ct > 0)
core.units.begin()->step = 6;
return FALSE;
}
case 5: {
int32 lv = pcard->get_level();
card* tuner = core.limit_tuner;
int32 playerid = pcard->current.controler;
int32 ct = get_spsummonable_count(pcard, playerid);
if(ct > 0) {
core.units.begin()->step = 6;
return FALSE;
}
card_set linked_cards;
uint32 linked_zone = core.duel_rule >= 4 ? get_linked_zone(playerid) | (1u << 5) | (1u << 6) : 0x1f;
get_cards_in_zone(&linked_cards, linked_zone, playerid);
if(linked_cards.find(tuner) != linked_cards.end())
ct++;
if(smat && linked_cards.find(smat) != linked_cards.end())
ct++;
if(ct > 0) {
core.units.begin()->step = 6;
return FALSE;
}
card_vector* select_cards = new card_vector;
for(auto cit = core.select_cards.begin(); cit != core.select_cards.end(); ++cit) {
card* pm = *cit;
if(linked_cards.find(pm) != linked_cards.end())
select_cards->push_back(pm);
}
if(select_cards->size() == core.select_cards.size()) {
delete select_cards;
core.units.begin()->step = 6;
return FALSE;
}
select_cards->swap(core.select_cards);
card_vector* must_select_cards = new card_vector;
must_select_cards->swap(core.must_select_cards);
int32 mcount = must_select_cards->size();
card_vector nsyn(*must_select_cards);
nsyn.insert(nsyn.end(), select_cards->begin(), select_cards->end());
auto start = nsyn.begin() + mcount;
for(auto cit = start; cit != nsyn.end(); ++cit) {
card* pm = *cit;
if(linked_cards.find(pm) == linked_cards.end())
continue;
if(start != cit)
std::iter_swap(start, cit);
if(check_other_synchro_material(nsyn, lv, min - 1, max - 1, mcount + 1))
core.select_cards.push_back(pm);
if(start != cit)
std::iter_swap(start, cit);
}
core.units.begin()->ptr1 = select_cards;
core.units.begin()->ptr2 = must_select_cards;
pduel->write_buffer8(MSG_HINT);
......
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