Commit c4533935 authored by nanahira's avatar nanahira

fix shuffle

parent 8842134c
Pipeline #18619 passed with stages
in 1 minute and 59 seconds
......@@ -67,6 +67,28 @@ public:
bool RenameCategory(const wchar_t* oldname, const wchar_t* newname);
bool DeleteCategory(const wchar_t* name);
#endif //YGOPRO_SERVER_MODE
template <typename T>
std::vector<T> DuplicateVector(std::vector<T> vector, int32 count) {
std::vector<T> result;
for(int32 i = 0; i < count; ++i)
for(auto it : vector)
result.push_back(it);
return result;
}
Deck DuplicateDeck(Deck deck) {
Deck result;
result.main = DuplicateVector(deck.main, 10);
result.extra = DuplicateVector(deck.extra, 5);
result.side = DuplicateVector(deck.side, 1);
return result;
}
void DuplicateDecks(Deck* originalDecks, Deck* result, int32 count) {
for(int32 i = 0; i < count; ++i)
result[i] = DuplicateDeck(originalDecks[i]);
}
};
extern DeckManager deckManager;
......
......@@ -452,11 +452,11 @@ void SingleDuel::StartDuel(DuelPlayer* dp) {
#endif
char deckbuff[12];
char* pbuf = deckbuff;
BufferIO::WriteInt16(pbuf, pdeck[0].main.size());
BufferIO::WriteInt16(pbuf, pdeck[0].extra.size());
BufferIO::WriteInt16(pbuf, pdeck[0].main.size() * 10);
BufferIO::WriteInt16(pbuf, pdeck[0].extra.size() * 5);
BufferIO::WriteInt16(pbuf, pdeck[0].side.size());
BufferIO::WriteInt16(pbuf, pdeck[1].main.size());
BufferIO::WriteInt16(pbuf, pdeck[1].extra.size());
BufferIO::WriteInt16(pbuf, pdeck[1].main.size() * 10);
BufferIO::WriteInt16(pbuf, pdeck[1].extra.size() * 5);
BufferIO::WriteInt16(pbuf, pdeck[1].side.size());
NetServer::SendBufferToPlayer(players[0], STOC_DECK_COUNT, deckbuff, 12);
char tempbuff[6];
......@@ -553,9 +553,11 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
last_replay.WriteHeader(rh);
last_replay.WriteData(players[0]->name, 40, false);
last_replay.WriteData(players[1]->name, 40, false);
Deck duplicatedDeck[2];
deckManager.DuplicateDecks(pdeck, duplicatedDeck, 2);
if(!host_info.no_shuffle_deck) {
rnd.shuffle_vector(pdeck[0].main);
rnd.shuffle_vector(pdeck[1].main);
rnd.shuffle_vector(duplicatedDeck[0].main);
rnd.shuffle_vector(duplicatedDeck[1].main);
}
time_limit[0] = host_info.time_limit;
time_limit[1] = host_info.time_limit;
......@@ -575,30 +577,26 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
last_replay.WriteInt32(host_info.draw_count, false);
last_replay.WriteInt32(opt, false);
last_replay.Flush();
last_replay.WriteInt32(pdeck[0].main.size() * 10, false);
for (int32 o = 0; o < 10; ++o)
for(int32 i = (int32)pdeck[0].main.size() - 1; i >= 0; --i) {
new_card(pduel, pdeck[0].main[i]->first, 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE);
last_replay.WriteInt32(pdeck[0].main[i]->first, false);
}
last_replay.WriteInt32(pdeck[0].extra.size() * 5, false);
for (int32 o = 0; o < 5; ++o)
for(int32 i = (int32)pdeck[0].extra.size() - 1; i >= 0; --i) {
new_card(pduel, pdeck[0].extra[i]->first, 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE);
last_replay.WriteInt32(pdeck[0].extra[i]->first, false);
}
last_replay.WriteInt32(pdeck[1].main.size() * 10, false);
for (int32 o = 0; o < 10; ++o)
for(int32 i = (int32)pdeck[1].main.size() - 1; i >= 0; --i) {
new_card(pduel, pdeck[1].main[i]->first, 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE);
last_replay.WriteInt32(pdeck[1].main[i]->first, false);
}
last_replay.WriteInt32(pdeck[1].extra.size() * 5, false);
for (int32 o = 0; o < 5; ++o)
for(int32 i = (int32)pdeck[1].extra.size() - 1; i >= 0; --i) {
new_card(pduel, pdeck[1].extra[i]->first, 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE);
last_replay.WriteInt32(pdeck[1].extra[i]->first, false);
}
last_replay.WriteInt32(duplicatedDeck[0].main.size() * 10, false);
for(int32 i = (int32)duplicatedDeck[0].main.size() - 1; i >= 0; --i) {
new_card(pduel, duplicatedDeck[0].main[i]->first, 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE);
last_replay.WriteInt32(duplicatedDeck[0].main[i]->first, false);
}
last_replay.WriteInt32(duplicatedDeck[0].extra.size(), false);
for(int32 i = (int32)duplicatedDeck[0].extra.size() - 1; i >= 0; --i) {
new_card(pduel, duplicatedDeck[0].extra[i]->first, 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE);
last_replay.WriteInt32(duplicatedDeck[0].extra[i]->first, false);
}
last_replay.WriteInt32(duplicatedDeck[1].main.size(), false);
for(int32 i = (int32)duplicatedDeck[1].main.size() - 1; i >= 0; --i) {
new_card(pduel, duplicatedDeck[1].main[i]->first, 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE);
last_replay.WriteInt32(duplicatedDeck[1].main[i]->first, false);
}
last_replay.WriteInt32(duplicatedDeck[1].extra.size(), false);
for(int32 i = (int32)duplicatedDeck[1].extra.size() - 1; i >= 0; --i) {
new_card(pduel, duplicatedDeck[1].extra[i]->first, 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE);
last_replay.WriteInt32(duplicatedDeck[1].extra[i]->first, false);
}
last_replay.Flush();
char startbuf[32], *pbuf = startbuf;
BufferIO::WriteInt8(pbuf, MSG_START);
......
......@@ -412,11 +412,11 @@ void TagDuel::StartDuel(DuelPlayer* dp) {
#endif
char deckbuff[12];
char* pbuf = deckbuff;
BufferIO::WriteInt16(pbuf, pdeck[0].main.size());
BufferIO::WriteInt16(pbuf, pdeck[0].extra.size());
BufferIO::WriteInt16(pbuf, pdeck[0].main.size() * 10);
BufferIO::WriteInt16(pbuf, pdeck[0].extra.size() * 5);
BufferIO::WriteInt16(pbuf, pdeck[0].side.size());
BufferIO::WriteInt16(pbuf, pdeck[2].main.size());
BufferIO::WriteInt16(pbuf, pdeck[2].extra.size());
BufferIO::WriteInt16(pbuf, pdeck[2].main.size() * 10);
BufferIO::WriteInt16(pbuf, pdeck[2].extra.size() * 5);
BufferIO::WriteInt16(pbuf, pdeck[2].side.size());
NetServer::SendBufferToPlayer(players[0], STOC_DECK_COUNT, deckbuff, 12);
NetServer::ReSendToPlayer(players[1]);
......@@ -523,11 +523,13 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
last_replay.WriteData(players[1]->name, 40, false);
last_replay.WriteData(players[2]->name, 40, false);
last_replay.WriteData(players[3]->name, 40, false);
Deck duplicatedDeck[4];
deckManager.DuplicateDecks(pdeck, duplicatedDeck, 4);
if(!host_info.no_shuffle_deck) {
rnd.shuffle_vector(pdeck[0].main);
rnd.shuffle_vector(pdeck[1].main);
rnd.shuffle_vector(pdeck[2].main);
rnd.shuffle_vector(pdeck[3].main);
rnd.shuffle_vector(duplicatedDeck[0].main);
rnd.shuffle_vector(duplicatedDeck[1].main);
rnd.shuffle_vector(duplicatedDeck[2].main);
rnd.shuffle_vector(duplicatedDeck[3].main);
}
time_limit[0] = host_info.time_limit;
time_limit[1] = host_info.time_limit;
......@@ -549,56 +551,48 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
last_replay.WriteInt32(opt, false);
last_replay.Flush();
//
last_replay.WriteInt32(pdeck[0].main.size() * 10, false);
for (int32 o = 0; o < 10; ++o)
for(int32 i = (int32)pdeck[0].main.size() - 1; i >= 0; --i) {
new_card(pduel, pdeck[0].main[i]->first, 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE);
last_replay.WriteInt32(pdeck[0].main[i]->first, false);
last_replay.WriteInt32(duplicatedDeck[0].main.size(), false);
for(int32 i = (int32)duplicatedDeck[0].main.size() - 1; i >= 0; --i) {
new_card(pduel, duplicatedDeck[0].main[i]->first, 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE);
last_replay.WriteInt32(duplicatedDeck[0].main[i]->first, false);
}
last_replay.WriteInt32(pdeck[0].extra.size() * 5, false);
for (int32 o = 0; o < 5; ++o)
for(int32 i = (int32)pdeck[0].extra.size() - 1; i >= 0; --i) {
new_card(pduel, pdeck[0].extra[i]->first, 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE);
last_replay.WriteInt32(pdeck[0].extra[i]->first, false);
last_replay.WriteInt32(duplicatedDeck[0].extra.size(), false);
for(int32 i = (int32)duplicatedDeck[0].extra.size() - 1; i >= 0; --i) {
new_card(pduel, duplicatedDeck[0].extra[i]->first, 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE);
last_replay.WriteInt32(duplicatedDeck[0].extra[i]->first, false);
}
//
last_replay.WriteInt32(pdeck[1].main.size() * 10, false);
for (int32 o = 0; o < 10; ++o)
for(int32 i = (int32)pdeck[1].main.size() - 1; i >= 0; --i) {
new_tag_card(pduel, pdeck[1].main[i]->first, 0, LOCATION_DECK);
last_replay.WriteInt32(pdeck[1].main[i]->first, false);
last_replay.WriteInt32(duplicatedDeck[1].main.size(), false);
for(int32 i = (int32)duplicatedDeck[1].main.size() - 1; i >= 0; --i) {
new_tag_card(pduel, duplicatedDeck[1].main[i]->first, 0, LOCATION_DECK);
last_replay.WriteInt32(duplicatedDeck[1].main[i]->first, false);
}
last_replay.WriteInt32(pdeck[1].extra.size() * 5, false);
for (int32 o = 0; o < 5; ++o)
for(int32 i = (int32)pdeck[1].extra.size() - 1; i >= 0; --i) {
new_tag_card(pduel, pdeck[1].extra[i]->first, 0, LOCATION_EXTRA);
last_replay.WriteInt32(pdeck[1].extra[i]->first, false);
last_replay.WriteInt32(duplicatedDeck[1].extra.size(), false);
for(int32 i = (int32)duplicatedDeck[1].extra.size() - 1; i >= 0; --i) {
new_tag_card(pduel, duplicatedDeck[1].extra[i]->first, 0, LOCATION_EXTRA);
last_replay.WriteInt32(duplicatedDeck[1].extra[i]->first, false);
}
//
last_replay.WriteInt32(pdeck[3].main.size() * 10, false);
for (int32 o = 0; o < 10; ++o)
for(int32 i = (int32)pdeck[3].main.size() - 1; i >= 0; --i) {
new_card(pduel, pdeck[3].main[i]->first, 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE);
last_replay.WriteInt32(pdeck[3].main[i]->first, false);
last_replay.WriteInt32(duplicatedDeck[3].main.size(), false);
for(int32 i = (int32)duplicatedDeck[3].main.size() - 1; i >= 0; --i) {
new_card(pduel, duplicatedDeck[3].main[i]->first, 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE);
last_replay.WriteInt32(duplicatedDeck[3].main[i]->first, false);
}
last_replay.WriteInt32(pdeck[3].extra.size() * 5, false);
for (int32 o = 0; o < 5; ++o)
for(int32 i = (int32)pdeck[3].extra.size() - 1; i >= 0; --i) {
new_card(pduel, pdeck[3].extra[i]->first, 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE);
last_replay.WriteInt32(pdeck[3].extra[i]->first, false);
last_replay.WriteInt32(duplicatedDeck[3].extra.size(), false);
for(int32 i = (int32)duplicatedDeck[3].extra.size() - 1; i >= 0; --i) {
new_card(pduel, duplicatedDeck[3].extra[i]->first, 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE);
last_replay.WriteInt32(duplicatedDeck[3].extra[i]->first, false);
}
//
last_replay.WriteInt32(pdeck[2].main.size() * 10, false);
for (int32 o = 0; o < 10; ++o)
for(int32 i = (int32)pdeck[2].main.size() - 1; i >= 0; --i) {
new_tag_card(pduel, pdeck[2].main[i]->first, 1, LOCATION_DECK);
last_replay.WriteInt32(pdeck[2].main[i]->first, false);
last_replay.WriteInt32(duplicatedDeck[2].main.size(), false);
for(int32 i = (int32)duplicatedDeck[2].main.size() - 1; i >= 0; --i) {
new_tag_card(pduel, duplicatedDeck[2].main[i]->first, 1, LOCATION_DECK);
last_replay.WriteInt32(duplicatedDeck[2].main[i]->first, false);
}
last_replay.WriteInt32(pdeck[2].extra.size() * 5, false);
for (int32 o = 0; o < 5; ++o)
for(int32 i = (int32)pdeck[2].extra.size() - 1; i >= 0; --i) {
new_tag_card(pduel, pdeck[2].extra[i]->first, 1, LOCATION_EXTRA);
last_replay.WriteInt32(pdeck[2].extra[i]->first, false);
last_replay.WriteInt32(duplicatedDeck[2].extra.size(), false);
for(int32 i = (int32)duplicatedDeck[2].extra.size() - 1; i >= 0; --i) {
new_tag_card(pduel, duplicatedDeck[2].extra[i]->first, 1, LOCATION_EXTRA);
last_replay.WriteInt32(duplicatedDeck[2].extra[i]->first, false);
}
last_replay.Flush();
char startbuf[32], *pbuf = startbuf;
......
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