Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix card::card_operation_sort #712

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,19 @@ bool card::card_operation_sort(card* c1, card* c2) {
}
if(c1->current.location != c2->current.location)
return c1->current.location < c2->current.location;
if(c1->current.location & LOCATION_OVERLAY) {
if(cp1 == PLAYER_NONE)
return c1->current.sequence < c2->current.sequence;
if(c1->current.location == LOCATION_OVERLAY) {
if(c1->overlay_target && c2->overlay_target && c1->overlay_target->current.sequence != c2->overlay_target->current.sequence)
return c1->overlay_target->current.sequence < c2->overlay_target->current.sequence;
else
return c1->current.sequence < c2->current.sequence;
} else if (c1->current.location & LOCATION_DECK && pduel->game_field->is_select_hide_deck_sequence(cp1)) {
} else if (c1->current.location == LOCATION_DECK && pduel->game_field->is_select_hide_deck_sequence(cp1)) {
// if deck reversed and the card being at the top, it should go first
if(pduel->game_field->core.deck_reversed) {
if(c1->current.sequence == pduel->game_field->player[cp1].list_main.size() - 1)
if(c1 == pduel->game_field->player[cp1].list_main.back())
return false;
if(c2->current.sequence == pduel->game_field->player[cp2].list_main.size() - 1)
if(c2 == pduel->game_field->player[cp2].list_main.back())
return true;
}
// faceup deck cards should go at the very first
Expand All @@ -105,8 +107,8 @@ bool card::card_operation_sort(card* c1, card* c2) {
return c2_faceup;
}
// sort deck as card property
auto c1_type = c1->data.type & 0x7;
auto c2_type = c2->data.type & 0x7;
auto c1_type = c1->data.type & (TYPE_MONSTER | TYPE_SPELL | TYPE_TRAP);
auto c2_type = c2->data.type & (TYPE_MONSTER | TYPE_SPELL | TYPE_TRAP);
// monster should go before spell, and then trap
if(c1_type != c2_type)
return c1_type > c2_type;
Expand Down
24 changes: 12 additions & 12 deletions playerop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@ int32_t field::select_card(uint16_t step, uint8_t playerid, uint8_t cancelable,
pduel->write_buffer8(min);
pduel->write_buffer8(max);
pduel->write_buffer8((uint8_t)core.select_cards.size());
uint8_t deck_seq_pointer = 0;
uint8_t deck_seq = 0;
for(auto& pcard : core.select_cards) {
pduel->write_buffer32(pcard->data.code);
pduel->write_buffer32(pcard->get_select_info_location(&deck_seq_pointer));
pduel->write_buffer32(pcard->get_select_info_location(&deck_seq));
}
return FALSE;
} else {
Expand Down Expand Up @@ -305,15 +305,15 @@ int32_t field::select_unselect_card(uint16_t step, uint8_t playerid, uint8_t can
pduel->write_buffer8(min);
pduel->write_buffer8(max);
pduel->write_buffer8((uint8_t)core.select_cards.size());
uint8_t deck_seq_pointer = 0;
uint8_t deck_seq = 0;
for(auto& pcard : core.select_cards) {
pduel->write_buffer32(pcard->data.code);
pduel->write_buffer32(pcard->get_select_info_location(&deck_seq_pointer));
pduel->write_buffer32(pcard->get_select_info_location(&deck_seq));
}
pduel->write_buffer8((uint8_t)core.unselect_cards.size());
for(auto& pcard : core.unselect_cards) {
pduel->write_buffer32(pcard->data.code);
pduel->write_buffer32(pcard->get_select_info_location(&deck_seq_pointer));
pduel->write_buffer32(pcard->get_select_info_location(&deck_seq));
}
return FALSE;
} else {
Expand Down Expand Up @@ -530,12 +530,12 @@ int32_t field::select_tribute(uint16_t step, uint8_t playerid, uint8_t cancelabl
pduel->write_buffer8(min);
pduel->write_buffer8(max);
pduel->write_buffer8((uint8_t)core.select_cards.size());
uint8_t deck_seq_pointer = 0;
uint8_t deck_seq = 0;
for(auto& pcard : core.select_cards) {
pduel->write_buffer32(pcard->data.code);
pduel->write_buffer8(pcard->current.controler);
pduel->write_buffer8(pcard->current.location);
pduel->write_buffer8(pcard->get_select_sequence(&deck_seq_pointer));
pduel->write_buffer8(pcard->get_select_sequence(&deck_seq));
pduel->write_buffer8(pcard->release_param);
}
return FALSE;
Expand Down Expand Up @@ -605,12 +605,12 @@ int32_t field::select_counter(uint16_t step, uint8_t playerid, uint16_t countert
pduel->write_buffer8((uint8_t)core.select_cards.size());
core.selecting_player = playerid;
std::sort(core.select_cards.begin(), core.select_cards.end(), card::card_operation_sort);
uint8_t deck_seq_pointer = 0;
uint8_t deck_seq = 0;
for(auto& pcard : core.select_cards) {
pduel->write_buffer32(pcard->data.code);
pduel->write_buffer8(pcard->current.controler);
pduel->write_buffer8(pcard->current.location);
pduel->write_buffer8(pcard->get_select_sequence(&deck_seq_pointer));
pduel->write_buffer8(pcard->get_select_sequence(&deck_seq));
pduel->write_buffer16(pcard->get_counter(countertype));
}
return FALSE;
Expand Down Expand Up @@ -663,20 +663,20 @@ int32_t field::select_with_sum_limit(int16_t step, uint8_t playerid, int32_t acc
pduel->write_buffer8(min);
pduel->write_buffer8(max);
pduel->write_buffer8((uint8_t)core.must_select_cards.size());
uint8_t deck_seq_pointer = 0;
uint8_t deck_seq = 0;
for(auto& pcard : core.must_select_cards) {
pduel->write_buffer32(pcard->data.code);
pduel->write_buffer8(pcard->current.controler);
pduel->write_buffer8(pcard->current.location);
pduel->write_buffer8(pcard->get_select_sequence(&deck_seq_pointer));
pduel->write_buffer8(pcard->get_select_sequence(&deck_seq));
pduel->write_buffer32(pcard->sum_param);
}
pduel->write_buffer8((uint8_t)core.select_cards.size());
for(auto& pcard : core.select_cards) {
pduel->write_buffer32(pcard->data.code);
pduel->write_buffer8(pcard->current.controler);
pduel->write_buffer8(pcard->current.location);
pduel->write_buffer8(pcard->get_select_sequence(&deck_seq_pointer));
pduel->write_buffer8(pcard->get_select_sequence(&deck_seq));
pduel->write_buffer32(pcard->sum_param);
}
return FALSE;
Expand Down