bool Replay::OpenReplay(const wchar_t* name) { wchar_t fname[256]; myswprintf(fname, L"./replay/%ls", name); #ifdef WIN32 fp = _wfopen(fname, L"rb"); #else char fname2[256]; BufferIO::EncodeUTF8(fname, fname2); fp = fopen(fname2, "rb"); #endif if(!fp) return false; fread(&pheader, sizeof(pheader), 1, fp); if(pheader.flag & REPLAY_COMPRESSED) { comp_size = fread(comp_data, 1, 0x1000, fp); fclose(fp); replay_size = pheader.datasize; if(LzmaUncompress(replay_data, &replay_size, comp_data, &comp_size, pheader.props, 5) != SZ_OK) return false; } else { comp_size = fread(replay_data, 1, 0x20000, fp); fclose(fp); replay_size = comp_size; } pdata = replay_data; is_replaying = true; return true; }
bool Replay::OpenReplay(const wchar_t* name) { wchar_t fname[256]; myswprintf(fname, mainGame->fileManager->GetRealPath(L"./replay/%ls").ToWString().c_str(), name); #ifdef WIN32 fp = _wfopen(fname, L"rb"); #else char fname2[256]; BufferIO::EncodeUTF8(fname, fname2); fp = fopen(fname2, "rb"); #endif if(!fp) return false; fseek(fp, 0, SEEK_END); comp_size = ftell(fp) - sizeof(pheader); fseek(fp, 0, SEEK_SET); fread(&pheader, sizeof(pheader), 1, fp); if(pheader.flag & REPLAY_COMPRESSED) { fread(comp_data, 0x1000, 1, fp); fclose(fp); replay_size = pheader.datasize; if(LzmaUncompress(replay_data, &replay_size, comp_data, &comp_size, pheader.props, 5) != SZ_OK) return false; } else { fread(replay_data, 0x20000, 1, fp); fclose(fp); replay_size = comp_size; } pdata = replay_data; is_replaying = true; return true; }
int NetManager::BroadcastClient(void* np) { NetManager* net = (NetManager*)np; SOCKADDR_IN sockTo; sockTo.sin_addr.s_addr = htonl(INADDR_BROADCAST); sockTo.sin_family = AF_INET; sockTo.sin_port = htons(7913); fd_set fds; timeval tv; tv.tv_sec = 0; tv.tv_usec = 500000; FD_ZERO(&fds); FD_SET(net->sBClient, &fds); sendto(net->sBClient, (const char*)&net->hReq, sizeof(HostRequest), 0, (sockaddr*)&sockTo, sizeof(sockaddr)); mainGame->lstServerList->clear(); mainGame->is_refreshing = true; int result = select(net->sBClient + 1, &fds, 0, 0, &tv); std::set<int> addrset; net->hosts.clear(); while(result != 0 && result != SOCKET_ERROR) { int recvLen = recvfrom(net->sBClient, (char*)&net->hInfo, sizeof(HostInfo), 0, 0, 0); if(recvLen == sizeof(HostInfo) && net->hInfo.identifier == NETWORK_SERVER_ID && net->hInfo.version == PROTO_VERSION && addrset.find(net->hInfo.address) == addrset.end()) { net->hosts.push_back(net->hInfo); } result = select(net->sBClient, &fds, 0, 0, &tv); } if(mainGame->is_closing) return 0; wchar_t tbuf[256]; const wchar_t* mode; std::vector<HostInfo>::iterator it; mainGame->gMutex.Lock(); tracking.clearHost(); mainGame->lstServerList->clear(); for(it = net->hosts.begin(); it != net->hosts.end(); ++it) { if(!it->no_check_deck && !it->no_shuffle_deck && !it->no_shuffle_deck && !it->attack_ft && !it->no_chain_hint && it->start_lp == 8000 && it->start_hand == 5 && it->draw_count == 1) mode = L"标准设定"; else mode = L"自定义设定"; myswprintf(tbuf, L"[L] [%ls] [%ls] %ls", mode, it->lflist, it->name); mainGame->lstServerList->addItem(tbuf); } mainGame->btnLanStartServer->setEnabled(true); mainGame->btnLanConnect->setEnabled(true); mainGame->btnRefreshList->setEnabled(true); mainGame->btnLoadReplay->setEnabled(true); mainGame->btnDeckEdit->setEnabled(true); mainGame->gMutex.Unlock(); mainGame->is_refreshing = false; closesocket(net->sBClient); tracking.queryList(); return 0; }
bool DataManager::LoadStrings(const char* file) { FILE* fp = fopen(file, "r"); if(!fp) return false; for(int i = 0; i < 2048; ++i) _sysStrings[i] = 0; char linebuf[256]; char strbuf[256]; int value; fseek(fp, 0, SEEK_END); int fsize = ftell(fp); fseek(fp, 0, SEEK_SET); fgets(linebuf, 256, fp); while(ftell(fp) < fsize) { fgets(linebuf, 256, fp); if(linebuf[0] != '!') continue; sscanf(linebuf, "!%s", strbuf); if(!strcmp(strbuf, "system")) { sscanf(&linebuf[7], "%d %99[^\n]", &value, strbuf); int len = BufferIO::DecodeUTF8(strbuf, strBuffer); wchar_t* pbuf = new wchar_t[len + 1]; wcscpy(pbuf, strBuffer); _sysStrings[value] = pbuf; } else if(!strcmp(strbuf, "victory")) { sscanf(&linebuf[8], "%x %99[^\n]", &value, strbuf); int len = BufferIO::DecodeUTF8(strbuf, strBuffer); wchar_t* pbuf = new wchar_t[len + 1]; wcscpy(pbuf, strBuffer); _victoryStrings[value] = pbuf; } else if(!strcmp(strbuf, "counter")) { sscanf(&linebuf[8], "%x %99[^\n]", &value, strbuf); int len = BufferIO::DecodeUTF8(strbuf, strBuffer); wchar_t* pbuf = new wchar_t[len + 1]; wcscpy(pbuf, strBuffer); _counterStrings[value] = pbuf; } else if (!strcmp(strbuf, "setcode")) { sscanf(&linebuf[8], "%x %99[^\n]", &value, strbuf); int len = BufferIO::DecodeUTF8(strbuf, strBuffer); wchar_t* pbuf = new wchar_t[len + 1]; wcscpy(pbuf, strBuffer); _setcodeStrings[pbuf] = value; } } fclose(fp); for(int i = 0; i < 255; ++i) myswprintf(numStrings[i], L"%d", i); return true; }
void DeckBuilder::ClearSearch() { mainGame->cbCardType->setSelected(0); mainGame->cbCardType2->setSelected(0); mainGame->cbCardType2->setEnabled(false); mainGame->cbRace->setEnabled(false); mainGame->cbAttribute->setEnabled(false); mainGame->ebAttack->setEnabled(false); mainGame->ebDefense->setEnabled(false); mainGame->ebStar->setEnabled(false); mainGame->ebScale->setEnabled(false); mainGame->ebCardName->setText(L""); ClearFilter(); results.clear(); myswprintf(result_string, L"%d", 0); }
void Replay::SaveReplay(const wchar_t* name) { wchar_t fname[256]; myswprintf(fname, L"./replay/%ls.yrp", name); #ifdef WIN32 fp = _wfopen(fname, L"wb"); #else char fname2[256]; BufferIO::EncodeUTF8(fname, fname2); fp = fopen(fname2, "wb"); #endif if(!fp) return; fwrite(&pheader, sizeof(pheader), 1, fp); fwrite(comp_data, comp_size, 1, fp); fclose(fp); }
void Replay::SaveReplay(const wchar_t* name) { wchar_t fname[64]; myswprintf(fname, mainGame->fileManager->GetRealPath( L"./replay/%ls.yrp").ToWString().c_str(), name); #ifdef WIN32 fp = _wfopen(fname, L"wb"); #else char fname2[256]; BufferIO::EncodeUTF8(fname, fname2); fp = fopen(fname2, "wb"); #endif if(!fp) return; fwrite(&pheader, sizeof(pheader), 1, fp); fwrite(comp_data, comp_size, 1, fp); fclose(fp); }
bool Replay::CheckReplay(const wchar_t* name) { wchar_t fname[256]; myswprintf(fname, L"./replay/%ls", name); #ifdef WIN32 FILE* rfp = _wfopen(fname, L"rb"); #else char fname2[256]; BufferIO::EncodeUTF8(fname, fname2); FILE* rfp = fopen(fname2, "rb"); #endif if(!rfp) return false; ReplayHeader rheader; fread(&rheader, sizeof(ReplayHeader), 1, rfp); fclose(rfp); return rheader.id == 0x31707279 && rheader.version >= 0x12d0; }
bool DeckManager::LoadDeck(const wchar_t* file) { int sp = 0, ct = 0, mainc = 0, sidec = 0, code; wchar_t deck[64]; myswprintf(deck, L"./deck/%ls.ydk", file); int cardlist[128]; bool is_side = false; #ifdef WIN32 FILE* fp = _wfopen(deck, L"r"); #else char deckfn[256]; BufferIO::EncodeUTF8(deck, deckfn); FILE* fp = fopen(deckfn, "r"); #endif if(!fp) return false; char linebuf[256]; fseek(fp, 0, SEEK_END); int fsize = ftell(fp); fseek(fp, 0, SEEK_SET); fgets(linebuf, 256, fp); while(ftell(fp) < fsize && ct < 128) { fgets(linebuf, 256, fp); if(linebuf[0] == '!') { is_side = true; continue; } if(linebuf[0] < '0' || linebuf[0] > '9') continue; sp = 0; while(linebuf[sp] >= '0' && linebuf[sp] <= '9') sp++; linebuf[sp] = 0; code = atoi(linebuf); cardlist[ct++] = code; if(is_side) sidec++; else mainc++; } fclose(fp); LoadDeck(current_deck, cardlist, mainc, sidec); return true; }
void DeckManager::SaveDeck(Deck& deck, const wchar_t* name) { wchar_t file[64]; myswprintf(file, L"./deck/%ls.ydk", name); #ifdef WIN32 FILE* fp = _wfopen(file, L"w"); #else char filefn[256]; BufferIO::EncodeUTF8(file, filefn); FILE* fp = fopen(filefn, "w"); #endif if(!fp) return; fprintf(fp, "#created by ...\n#main\n"); for(int i = 0; i < deck.main.size(); ++i) fprintf(fp, "%d\n", deck.main[i]->first); fprintf(fp, "#extra\n"); for(int i = 0; i < deck.extra.size(); ++i) fprintf(fp, "%d\n", deck.extra[i]->first); fprintf(fp, "!side\n"); for(int i = 0; i < deck.side.size(); ++i) fprintf(fp, "%d\n", deck.side[i]->first); fclose(fp); }
int SingleMode::SinglePlayThread(void* param) { const wchar_t* name = mainGame->lstSinglePlayList->getListItem(mainGame->lstSinglePlayList->getSelected()); wchar_t fname[256]; myswprintf(fname, L"./single/%ls", name); char fname2[256]; size_t slen = BufferIO::EncodeUTF8(fname, fname2); mtrandom rnd; time_t seed = time(0); rnd.reset(seed); set_card_reader((card_reader)DataManager::CardReader); set_message_handler((message_handler)MessageHandler); pduel = create_duel(rnd.rand()); set_player_info(pduel, 0, 8000, 5, 1); set_player_info(pduel, 1, 8000, 5, 1); mainGame->dInfo.lp[0] = 8000; mainGame->dInfo.lp[1] = 8000; myswprintf(mainGame->dInfo.strLP[0], L"%d", mainGame->dInfo.lp[0]); myswprintf(mainGame->dInfo.strLP[1], L"%d", mainGame->dInfo.lp[1]); BufferIO::CopyWStr(mainGame->ebNickName->getText(), mainGame->dInfo.hostname, 20); mainGame->dInfo.clientname[0] = 0; mainGame->dInfo.turn = 0; mainGame->dInfo.strTurn[0] = 0; if(!preload_script(pduel, fname2, slen)) { end_duel(pduel); return 0; } mainGame->gMutex.Lock(); mainGame->HideElement(mainGame->wSinglePlay); mainGame->wCardImg->setVisible(true); mainGame->wInfos->setVisible(true); mainGame->btnLeaveGame->setVisible(true); mainGame->btnLeaveGame->setText(dataManager.GetSysString(1210)); mainGame->stName->setText(L""); mainGame->stInfo->setText(L""); mainGame->stDataInfo->setText(L""); mainGame->stText->setText(L""); mainGame->scrCardText->setVisible(false); mainGame->wPhase->setVisible(true); mainGame->dField.panel = 0; mainGame->dField.hovered_card = 0; mainGame->dField.clicked_card = 0; mainGame->dField.Clear(); mainGame->dInfo.isFirst = true; mainGame->dInfo.isStarted = true; mainGame->dInfo.isSingleMode = true; mainGame->device->setEventReceiver(&mainGame->dField); mainGame->gMutex.Unlock(); start_duel(pduel, 0); char engineBuffer[0x1000]; is_closing = false; is_continuing = true; int len = 0; while (is_continuing) { int result = process(pduel); len = result & 0xffff; /* int flag = result >> 16; */ if (len > 0) { get_message(pduel, (byte*)engineBuffer); is_continuing = SinglePlayAnalyze(engineBuffer, len); } } end_duel(pduel); if(!is_closing) { mainGame->gMutex.Lock(); mainGame->dInfo.isStarted = false; mainGame->dInfo.isSingleMode = false; mainGame->gMutex.Unlock(); mainGame->closeDoneSignal.Reset(); mainGame->closeSignal.Set(); mainGame->closeDoneSignal.Wait(); mainGame->gMutex.Lock(); mainGame->ShowElement(mainGame->wSinglePlay); mainGame->device->setEventReceiver(&mainGame->menuHandler); mainGame->gMutex.Unlock(); } return 0; }
bool SingleMode::SinglePlayAnalyze(char* msg, unsigned int len) { char* offset, *pbuf = msg; int player, count; while (pbuf - msg < (int)len) { if(is_closing || !is_continuing) return false; offset = pbuf; mainGame->dInfo.curMsg = BufferIO::ReadUInt8(pbuf); switch (mainGame->dInfo.curMsg) { case MSG_RETRY: { mainGame->gMutex.Lock(); mainGame->stMessage->setText(L"Error occurs."); mainGame->PopupElement(mainGame->wMessage); mainGame->gMutex.Unlock(); mainGame->actionSignal.Reset(); mainGame->actionSignal.Wait(); return false; } case MSG_HINT: { /*int type = */BufferIO::ReadInt8(pbuf); int player = BufferIO::ReadInt8(pbuf); /*int data = */BufferIO::ReadInt32(pbuf); if(player == 0) DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_WIN: { pbuf += 2; DuelClient::ClientAnalyze(offset, pbuf - offset); return false; } case MSG_SELECT_BATTLECMD: { player = BufferIO::ReadInt8(pbuf); count = BufferIO::ReadInt8(pbuf); pbuf += count * 11; count = BufferIO::ReadInt8(pbuf); pbuf += count * 8 + 2; SinglePlayRefresh(); if(!DuelClient::ClientAnalyze(offset, pbuf - offset)) { mainGame->singleSignal.Reset(); mainGame->singleSignal.Wait(); } break; } case MSG_SELECT_IDLECMD: { player = BufferIO::ReadInt8(pbuf); count = BufferIO::ReadInt8(pbuf); pbuf += count * 7; count = BufferIO::ReadInt8(pbuf); pbuf += count * 7; count = BufferIO::ReadInt8(pbuf); pbuf += count * 7; count = BufferIO::ReadInt8(pbuf); pbuf += count * 7; count = BufferIO::ReadInt8(pbuf); pbuf += count * 7; count = BufferIO::ReadInt8(pbuf); pbuf += count * 11 + 3; SinglePlayRefresh(); if(!DuelClient::ClientAnalyze(offset, pbuf - offset)) { mainGame->singleSignal.Reset(); mainGame->singleSignal.Wait(); } break; } case MSG_SELECT_EFFECTYN: { player = BufferIO::ReadInt8(pbuf); pbuf += 8; DuelClient::ClientAnalyze(offset, pbuf - offset); if(!DuelClient::ClientAnalyze(offset, pbuf - offset)) { mainGame->singleSignal.Reset(); mainGame->singleSignal.Wait(); } break; } case MSG_SELECT_YESNO: { player = BufferIO::ReadInt8(pbuf); pbuf += 4; if(!DuelClient::ClientAnalyze(offset, pbuf - offset)) { mainGame->singleSignal.Reset(); mainGame->singleSignal.Wait(); } break; } case MSG_SELECT_OPTION: { player = BufferIO::ReadInt8(pbuf); count = BufferIO::ReadInt8(pbuf); pbuf += count * 4; if(!DuelClient::ClientAnalyze(offset, pbuf - offset)) { mainGame->singleSignal.Reset(); mainGame->singleSignal.Wait(); } break; } case MSG_SELECT_CARD: case MSG_SELECT_TRIBUTE: { player = BufferIO::ReadInt8(pbuf); pbuf += 3; count = BufferIO::ReadInt8(pbuf); pbuf += count * 8; if(!DuelClient::ClientAnalyze(offset, pbuf - offset)) { mainGame->singleSignal.Reset(); mainGame->singleSignal.Wait(); } break; } case MSG_SELECT_CHAIN: { player = BufferIO::ReadInt8(pbuf); count = BufferIO::ReadInt8(pbuf); pbuf += 10 + count * 12; if(!DuelClient::ClientAnalyze(offset, pbuf - offset)) { mainGame->singleSignal.Reset(); mainGame->singleSignal.Wait(); } break; } case MSG_SELECT_PLACE: case MSG_SELECT_DISFIELD: { player = BufferIO::ReadInt8(pbuf); pbuf += 5; if(!DuelClient::ClientAnalyze(offset, pbuf - offset)) { mainGame->singleSignal.Reset(); mainGame->singleSignal.Wait(); } break; } case MSG_SELECT_POSITION: { player = BufferIO::ReadInt8(pbuf); pbuf += 5; if(!DuelClient::ClientAnalyze(offset, pbuf - offset)) { mainGame->singleSignal.Reset(); mainGame->singleSignal.Wait(); } break; } case MSG_SELECT_COUNTER: { player = BufferIO::ReadInt8(pbuf); pbuf += 3; count = BufferIO::ReadInt8(pbuf); pbuf += count * 8; if(!DuelClient::ClientAnalyze(offset, pbuf - offset)) { mainGame->singleSignal.Reset(); mainGame->singleSignal.Wait(); } break; } case MSG_SELECT_SUM: { pbuf++; player = BufferIO::ReadInt8(pbuf); pbuf += 6; count = BufferIO::ReadInt8(pbuf); pbuf += count * 11; if(!DuelClient::ClientAnalyze(offset, pbuf - offset)) { mainGame->singleSignal.Reset(); mainGame->singleSignal.Wait(); } break; } case MSG_SORT_CARD: case MSG_SORT_CHAIN: { player = BufferIO::ReadInt8(pbuf); count = BufferIO::ReadInt8(pbuf); pbuf += count * 7; if(!DuelClient::ClientAnalyze(offset, pbuf - offset)) { mainGame->singleSignal.Reset(); mainGame->singleSignal.Wait(); } break; } case MSG_CONFIRM_DECKTOP: { player = BufferIO::ReadInt8(pbuf); count = BufferIO::ReadInt8(pbuf); pbuf += count * 7; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_CONFIRM_CARDS: { player = BufferIO::ReadInt8(pbuf); count = BufferIO::ReadInt8(pbuf); pbuf += count * 7; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_SHUFFLE_DECK: { player = BufferIO::ReadInt8(pbuf); DuelClient::ClientAnalyze(offset, pbuf - offset); SinglePlayRefreshDeck(player); break; } case MSG_SHUFFLE_HAND: { /*int oplayer = */BufferIO::ReadInt8(pbuf); int count = BufferIO::ReadInt8(pbuf); pbuf += count * 4; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_REFRESH_DECK: { pbuf++; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_SWAP_GRAVE_DECK: { player = BufferIO::ReadInt8(pbuf); DuelClient::ClientAnalyze(offset, pbuf - offset); SinglePlayRefreshGrave(player); break; } case MSG_REVERSE_DECK: { DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_DECK_TOP: { pbuf += 6; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_SHUFFLE_SET_CARD: { count = BufferIO::ReadInt8(pbuf); pbuf += count * 8; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_NEW_TURN: { player = BufferIO::ReadInt8(pbuf); DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_NEW_PHASE: { pbuf++; DuelClient::ClientAnalyze(offset, pbuf - offset); SinglePlayRefresh(); break; } case MSG_MOVE: { int pc = pbuf[4]; int pl = pbuf[5]; /*int ps = pbuf[6];*/ /*int pp = pbuf[7];*/ int cc = pbuf[8]; int cl = pbuf[9]; int cs = pbuf[10]; /*int cp = pbuf[11];*/ pbuf += 16; DuelClient::ClientAnalyze(offset, pbuf - offset); if(cl && !(cl & 0x80) && (pl != cl || pc != cc)) SinglePlayRefreshSingle(cc, cl, cs); break; } case MSG_POS_CHANGE: { pbuf += 9; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_SET: { pbuf += 8; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_SWAP: { pbuf += 16; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_FIELD_DISABLED: { pbuf += 4; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_SUMMONING: { pbuf += 8; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_SUMMONED: { DuelClient::ClientAnalyze(offset, pbuf - offset); SinglePlayRefresh(); break; } case MSG_SPSUMMONING: { pbuf += 8; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_SPSUMMONED: { DuelClient::ClientAnalyze(offset, pbuf - offset); SinglePlayRefresh(); break; } case MSG_FLIPSUMMONING: { pbuf += 8; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_FLIPSUMMONED: { DuelClient::ClientAnalyze(offset, pbuf - offset); SinglePlayRefresh(); break; } case MSG_CHAINING: { pbuf += 16; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_CHAINED: { pbuf++; DuelClient::ClientAnalyze(offset, pbuf - offset); SinglePlayRefresh(); break; } case MSG_CHAIN_SOLVING: { pbuf++; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_CHAIN_SOLVED: { pbuf++; DuelClient::ClientAnalyze(offset, pbuf - offset); SinglePlayRefresh(); break; } case MSG_CHAIN_END: { DuelClient::ClientAnalyze(offset, pbuf - offset); SinglePlayRefresh(); SinglePlayRefreshDeck(0); SinglePlayRefreshDeck(1); break; } case MSG_CHAIN_NEGATED: { pbuf++; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_CHAIN_DISABLED: { pbuf++; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_CARD_SELECTED: case MSG_RANDOM_SELECTED: { player = BufferIO::ReadInt8(pbuf); count = BufferIO::ReadInt8(pbuf); pbuf += count * 4; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_BECOME_TARGET: { count = BufferIO::ReadInt8(pbuf); pbuf += count * 4; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_DRAW: { player = BufferIO::ReadInt8(pbuf); count = BufferIO::ReadInt8(pbuf); pbuf += count * 4; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_DAMAGE: { pbuf += 5; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_RECOVER: { pbuf += 5; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_EQUIP: { pbuf += 8; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_LPUPDATE: { pbuf += 5; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_UNEQUIP: { pbuf += 4; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_CARD_TARGET: { pbuf += 8; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_CANCEL_TARGET: { pbuf += 8; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_PAY_LPCOST: { pbuf += 5; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_ADD_COUNTER: { pbuf += 6; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_REMOVE_COUNTER: { pbuf += 6; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_ATTACK: { pbuf += 8; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_BATTLE: { pbuf += 26; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_ATTACK_DISABLED: { DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_DAMAGE_STEP_START: { DuelClient::ClientAnalyze(offset, pbuf - offset); SinglePlayRefresh(); break; } case MSG_DAMAGE_STEP_END: { DuelClient::ClientAnalyze(offset, pbuf - offset); SinglePlayRefresh(); break; } case MSG_MISSED_EFFECT: { pbuf += 8; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_TOSS_COIN: { player = BufferIO::ReadInt8(pbuf); count = BufferIO::ReadInt8(pbuf); pbuf += count; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_TOSS_DICE: { player = BufferIO::ReadInt8(pbuf); count = BufferIO::ReadInt8(pbuf); pbuf += count; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_ANNOUNCE_RACE: { player = BufferIO::ReadInt8(pbuf); pbuf += 5; if(!DuelClient::ClientAnalyze(offset, pbuf - offset)) { mainGame->singleSignal.Reset(); mainGame->singleSignal.Wait(); } break; } case MSG_ANNOUNCE_ATTRIB: { player = BufferIO::ReadInt8(pbuf); pbuf += 5; if(!DuelClient::ClientAnalyze(offset, pbuf - offset)) { mainGame->singleSignal.Reset(); mainGame->singleSignal.Wait(); } break; } case MSG_ANNOUNCE_CARD: { player = BufferIO::ReadInt8(pbuf); if(!DuelClient::ClientAnalyze(offset, pbuf - offset)) { mainGame->singleSignal.Reset(); mainGame->singleSignal.Wait(); } break; } case MSG_ANNOUNCE_NUMBER: { player = BufferIO::ReadInt8(pbuf); count = BufferIO::ReadInt8(pbuf); pbuf += 4 * count; if(!DuelClient::ClientAnalyze(offset, pbuf - offset)) { mainGame->singleSignal.Reset(); mainGame->singleSignal.Wait(); } break; } case MSG_CARD_HINT: { pbuf += 9; DuelClient::ClientAnalyze(offset, pbuf - offset); break; } case MSG_TAG_SWAP: { player = pbuf[0]; pbuf += pbuf[2] * 4 + pbuf[4] * 4 + 9; DuelClient::ClientAnalyze(offset, pbuf - offset); SinglePlayRefreshDeck(player); SinglePlayRefreshExtra(player); break; } case MSG_MATCH_KILL: { pbuf += 4; break; } case MSG_RELOAD_FIELD: { mainGame->gMutex.Lock(); mainGame->dField.Clear(); int val = 0; for(int p = 0; p < 2; ++p) { mainGame->dInfo.lp[p] = BufferIO::ReadInt32(pbuf); myswprintf(mainGame->dInfo.strLP[p], L"%d", mainGame->dInfo.lp[p]); for(int seq = 0; seq < 5; ++seq) { val = BufferIO::ReadInt8(pbuf); if(val) { ClientCard* ccard = new ClientCard; mainGame->dField.AddCard(ccard, p, LOCATION_MZONE, seq); ccard->position = BufferIO::ReadInt8(pbuf); val = BufferIO::ReadInt8(pbuf); if(val) { for(int xyz = 0; xyz < val; ++xyz) { ClientCard* xcard = new ClientCard; ccard->overlayed.push_back(xcard); mainGame->dField.overlay_cards.insert(xcard); xcard->overlayTarget = ccard; xcard->location = 0x80; xcard->sequence = ccard->overlayed.size() - 1; } } } } for(int seq = 0; seq < 8; ++seq) { val = BufferIO::ReadInt8(pbuf); if(val) { ClientCard* ccard = new ClientCard; mainGame->dField.AddCard(ccard, p, LOCATION_SZONE, seq); ccard->position = BufferIO::ReadInt8(pbuf); } } val = BufferIO::ReadInt8(pbuf); for(int seq = 0; seq < val; ++seq) { ClientCard* ccard = new ClientCard; mainGame->dField.AddCard(ccard, p, LOCATION_DECK, seq); } val = BufferIO::ReadInt8(pbuf); for(int seq = 0; seq < val; ++seq) { ClientCard* ccard = new ClientCard; mainGame->dField.AddCard(ccard, p, LOCATION_HAND, seq); } val = BufferIO::ReadInt8(pbuf); for(int seq = 0; seq < val; ++seq) { ClientCard* ccard = new ClientCard; mainGame->dField.AddCard(ccard, p, LOCATION_GRAVE, seq); } val = BufferIO::ReadInt8(pbuf); for(int seq = 0; seq < val; ++seq) { ClientCard* ccard = new ClientCard; mainGame->dField.AddCard(ccard, p, LOCATION_REMOVED, seq); } val = BufferIO::ReadInt8(pbuf); for(int seq = 0; seq < val; ++seq) { ClientCard* ccard = new ClientCard; mainGame->dField.AddCard(ccard, p, LOCATION_EXTRA, seq); } val = BufferIO::ReadInt8(pbuf); mainGame->dField.extra_p_count[p] = val; } BufferIO::ReadInt8(pbuf); //chain count, always 0 SinglePlayReload(); mainGame->dField.RefreshAllCards(); mainGame->gMutex.Unlock(); break; } case MSG_AI_NAME: { char namebuf[128]; wchar_t wname[128]; int len = BufferIO::ReadInt16(pbuf); char* begin = pbuf; pbuf += len + 1; memcpy(namebuf, begin, len + 1); BufferIO::DecodeUTF8(namebuf, wname); BufferIO::CopyWStr(wname, mainGame->dInfo.clientname, 20); break; } case MSG_SHOW_HINT: { char msgbuf[1024]; wchar_t msg[1024]; int len = BufferIO::ReadInt16(pbuf); char* begin = pbuf; pbuf += len + 1; memcpy(msgbuf, begin, len + 1); BufferIO::DecodeUTF8(msgbuf, msg); mainGame->gMutex.Lock(); mainGame->SetStaticText(mainGame->stMessage, 310, mainGame->textFont, msg); mainGame->PopupElement(mainGame->wMessage); mainGame->gMutex.Unlock(); mainGame->actionSignal.Reset(); mainGame->actionSignal.Wait(); break; } } } return is_continuing; }
int ReplayMode::ReplayThread(void* param) { ReplayHeader rh = cur_replay.pheader; mainGame->dInfo.isFirst = true; mtrandom rnd; int seed = rh.seed; rnd.reset(seed); cur_replay.ReadData(mainGame->dInfo.hostname, 40); cur_replay.ReadData(mainGame->dInfo.clientname, 40); set_card_reader((card_reader)DataManager::CardReader); set_message_handler((message_handler)MessageHandler); pduel = create_duel(rnd.rand()); int start_lp = cur_replay.ReadInt32(); int start_hand = cur_replay.ReadInt32(); int draw_count = cur_replay.ReadInt32(); int opt = cur_replay.ReadInt32(); set_player_info(pduel, 0, start_lp, start_hand, draw_count); set_player_info(pduel, 1, start_lp, start_hand, draw_count); mainGame->dInfo.lp[0] = start_lp; mainGame->dInfo.lp[1] = start_lp; myswprintf(mainGame->dInfo.strLP[0], L"%d", mainGame->dInfo.lp[0]); myswprintf(mainGame->dInfo.strLP[1], L"%d", mainGame->dInfo.lp[1]); mainGame->dInfo.turn = 0; mainGame->dInfo.strTurn[0] = 0; int main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_DECK, 0, 0); int extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_EXTRA, 0, 0); mainGame->dField.Initial(0, main, extra); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_DECK, 0, 0); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_EXTRA, 0, 0); mainGame->dField.Initial(1, main, extra); start_duel(pduel, opt); mainGame->dInfo.isStarted = true; mainGame->dInfo.isReplay = true; char engineBuffer[0x1000]; is_continuing = true; exit_pending = false; int len = 0, flag = 0; while (is_continuing && !exit_pending) { int result = process(pduel); len = result & 0xffff; flag = result >> 16; if (len > 0) { get_message(pduel, (byte*)engineBuffer); is_continuing = ReplayAnalyze(engineBuffer, len); } } end_duel(pduel); if(!is_closing) { mainGame->stMessage->setText(dataManager.GetSysString(1501)); mainGame->actionSignal.Reset(); mainGame->PopupElement(mainGame->wMessage); mainGame->actionSignal.Wait(); mainGame->dInfo.isStarted = false; mainGame->dInfo.isReplay = false; mainGame->CloseDuelWindow(); mainGame->ClearTextures(); mainGame->ShowElement(mainGame->wReplay); mainGame->device->setEventReceiver(&mainGame->menuHandler); } return 0; }
void DeckBuilder::FilterCards() { results.clear(); const wchar_t* pstr = mainGame->ebCardName->getText(); int trycode = BufferIO::GetVal(pstr); if(dataManager.GetData(trycode, 0)) { auto ptr = dataManager.GetCodePointer(trycode); results.push_back(ptr); mainGame->scrFilter->setVisible(false); mainGame->scrFilter->setPos(0); myswprintf(result_string, L"%d", results.size()); return; } unsigned int set_code = 0; if(pstr[0] == L'@') set_code = dataManager.GetSetCode(&pstr[1]); if(pstr[0] == 0 || (pstr[0] == L'$' && pstr[1] == 0) || (pstr[0] == L'@' && pstr[1] == 0)) pstr = 0; auto strpointer = dataManager._strings.begin(); for(code_pointer ptr = dataManager._datas.begin(); ptr != dataManager._datas.end(); ++ptr, ++strpointer) { const CardDataC& data = ptr->second; const CardString& text = strpointer->second; if(data.type & TYPE_TOKEN) continue; switch(filter_type) { case 1: { if(!(data.type & TYPE_MONSTER) || (data.type & filter_type2) != filter_type2) continue; if(filter_race && data.race != filter_race) continue; if(filter_attrib && data.attribute != filter_attrib) continue; if(filter_atktype) { if((filter_atktype == 1 && data.attack != filter_atk) || (filter_atktype == 2 && data.attack < filter_atk) || (filter_atktype == 3 && data.attack <= filter_atk) || (filter_atktype == 4 && (data.attack > filter_atk || data.attack < 0)) || (filter_atktype == 5 && (data.attack >= filter_atk || data.attack < 0)) || (filter_atktype == 6 && data.attack != -2)) continue; } if(filter_deftype) { if((filter_deftype == 1 && data.defence != filter_def) || (filter_deftype == 2 && data.defence < filter_def) || (filter_deftype == 3 && data.defence <= filter_def) || (filter_deftype == 4 && (data.defence > filter_def || data.defence < 0)) || (filter_deftype == 5 && (data.defence >= filter_def || data.defence < 0)) || (filter_deftype == 6 && data.defence != -2)) continue; } if(filter_lvtype) { if((filter_lvtype == 1 && data.level != filter_lv) || (filter_lvtype == 2 && data.level < filter_lv) || (filter_lvtype == 3 && data.level <= filter_lv) || (filter_lvtype == 4 && data.level > filter_lv) || (filter_lvtype == 5 && data.level >= filter_lv)) continue; } break; } case 2: { if(!(data.type & TYPE_SPELL)) continue; if(filter_type2 && data.type != filter_type2) continue; break; } case 3: { if(!(data.type & TYPE_TRAP)) continue; if(filter_type2 && data.type != filter_type2) continue; break; } } if(filter_effect && !(data.category & filter_effect)) continue; if(filter_lm) { if(filter_lm <= 3 && (!filterList->count(ptr->first) || (*filterList)[ptr->first] != filter_lm - 1)) continue; if(filter_lm == 4 && data.ot != 1) continue; if(filter_lm == 5 && data.ot != 2) continue; } if(pstr) { if(pstr[0] == L'$') { if(wcsstr(text.name, &pstr[1]) == 0) continue; } else if(pstr[0] == L'@' && set_code) { unsigned long long sc = data.setcode; if(data.alias) { auto aptr = dataManager._datas.find(data.alias); if(aptr != dataManager._datas.end()) sc = aptr->second.setcode; } bool res = false; int settype = set_code & 0xfff; int setsubtype = set_code & 0xf000; while(sc) { if ((sc & 0xfff) == settype && (sc & 0xf000 & setsubtype) == setsubtype) res = true; sc = sc >> 16; } if(!res) continue; } else { if(wcsstr(text.name, pstr) == 0 && wcsstr(text.text, pstr) == 0) continue; } }
bool DeckBuilder::OnEvent(const irr::SEvent& event) { if(mainGame->dField.OnCommonEvent(event)) return false; switch(event.EventType) { case irr::EET_GUI_EVENT: { s32 id = event.GUIEvent.Caller->getID(); if(mainGame->wCategories->isVisible() && id != BUTTON_CATEGORY_OK) break; if(mainGame->wQuery->isVisible() && id != BUTTON_YES && id != BUTTON_NO) break; if(mainGame->wLinkMarks->isVisible() && id != BUTTON_MARKERS_OK) break; switch(event.GUIEvent.EventType) { case irr::gui::EGET_BUTTON_CLICKED: { switch(id) { case BUTTON_CLEAR_DECK: { deckManager.current_deck.main.clear(); deckManager.current_deck.extra.clear(); deckManager.current_deck.side.clear(); break; } case BUTTON_SORT_DECK: { std::sort(deckManager.current_deck.main.begin(), deckManager.current_deck.main.end(), ClientCard::deck_sort_lv); std::sort(deckManager.current_deck.extra.begin(), deckManager.current_deck.extra.end(), ClientCard::deck_sort_lv); std::sort(deckManager.current_deck.side.begin(), deckManager.current_deck.side.end(), ClientCard::deck_sort_lv); break; } case BUTTON_SHUFFLE_DECK: { std::random_shuffle(deckManager.current_deck.main.begin(), deckManager.current_deck.main.end()); break; } case BUTTON_SAVE_DECK: { int sel = mainGame->cbDBDecks->getSelected(); if(sel >= 0 && deckManager.SaveDeck(deckManager.current_deck, mainGame->cbDBDecks->getItem(sel))) { mainGame->stACMessage->setText(dataManager.GetSysString(1335)); mainGame->PopupElement(mainGame->wACMessage, 20); } break; } case BUTTON_SAVE_DECK_AS: { const wchar_t* dname = mainGame->ebDeckname->getText(); if(*dname == 0) break; int sel = -1; for(size_t i = 0; i < mainGame->cbDBDecks->getItemCount(); ++i) { if(!wcscmp(dname, mainGame->cbDBDecks->getItem(i))) { sel = i; break; } } if(sel >= 0) mainGame->cbDBDecks->setSelected(sel); else { mainGame->cbDBDecks->addItem(dname); mainGame->cbDBDecks->setSelected(mainGame->cbDBDecks->getItemCount() - 1); } if(deckManager.SaveDeck(deckManager.current_deck, dname)) { mainGame->stACMessage->setText(dataManager.GetSysString(1335)); mainGame->PopupElement(mainGame->wACMessage, 20); } break; } case BUTTON_DELETE_DECK: { int sel = mainGame->cbDBDecks->getSelected(); if(sel == -1) break; mainGame->gMutex.Lock(); wchar_t textBuffer[256]; myswprintf(textBuffer, L"%ls\n%ls", mainGame->cbDBDecks->getItem(sel), dataManager.GetSysString(1337)); mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, (wchar_t*)textBuffer); mainGame->PopupElement(mainGame->wQuery); mainGame->gMutex.Unlock(); prev_operation = id; break; } case BUTTON_LEAVE_GAME: { Terminate(); break; } case BUTTON_EFFECT_FILTER: { mainGame->PopupElement(mainGame->wCategories); break; } case BUTTON_START_FILTER: { StartFilter(); break; } case BUTTON_CLEAR_FILTER: { ClearSearch(); break; } case BUTTON_CATEGORY_OK: { filter_effect = 0; long long filter = 0x1; for(int i = 0; i < 32; ++i, filter <<= 1) if(mainGame->chkCategory[i]->isChecked()) filter_effect |= filter; mainGame->HideElement(mainGame->wCategories); break; } case BUTTON_SIDE_OK: { if(deckManager.current_deck.main.size() != deckManager.pre_deck.main.size() || deckManager.current_deck.extra.size() != deckManager.pre_deck.extra.size() || deckManager.current_deck.side.size() != deckManager.pre_deck.side.size()) { mainGame->env->addMessageBox(L"", dataManager.GetSysString(1410)); break; } mainGame->imgCard->setImage(imageManager.tCover[0]); mainGame->stName->setText(L""); mainGame->stInfo->setText(L""); mainGame->stDataInfo->setText(L""); mainGame->stSetName->setText(L""); mainGame->stText->setText(L""); mainGame->showingcard = 0; mainGame->scrCardText->setVisible(false); char deckbuf[1024]; char* pdeck = deckbuf; BufferIO::WriteInt32(pdeck, deckManager.current_deck.main.size() + deckManager.current_deck.extra.size()); BufferIO::WriteInt32(pdeck, deckManager.current_deck.side.size()); for(size_t i = 0; i < deckManager.current_deck.main.size(); ++i) BufferIO::WriteInt32(pdeck, deckManager.current_deck.main[i]->first); for(size_t i = 0; i < deckManager.current_deck.extra.size(); ++i) BufferIO::WriteInt32(pdeck, deckManager.current_deck.extra[i]->first); for(size_t i = 0; i < deckManager.current_deck.side.size(); ++i) BufferIO::WriteInt32(pdeck, deckManager.current_deck.side[i]->first); DuelClient::SendBufferToServer(CTOS_UPDATE_DECK, deckbuf, pdeck - deckbuf); break; } case BUTTON_SIDE_RELOAD: { deckManager.current_deck = deckManager.pre_deck; break; } case BUTTON_MSG_OK: { mainGame->HideElement(mainGame->wMessage); mainGame->actionSignal.Set(); break; } case BUTTON_YES: { mainGame->HideElement(mainGame->wQuery); if(!mainGame->is_building || mainGame->is_siding) break; if(prev_operation == BUTTON_DELETE_DECK) { int sel = mainGame->cbDBDecks->getSelected(); if(deckManager.DeleteDeck(deckManager.current_deck, mainGame->cbDBDecks->getItem(sel))) { mainGame->cbDBDecks->removeItem(sel); int count = mainGame->cbDBDecks->getItemCount(); if(sel >= count) sel = count - 1; mainGame->cbDBDecks->setSelected(sel); if(sel != -1) deckManager.LoadDeck(mainGame->cbDBDecks->getItem(sel)); mainGame->stACMessage->setText(dataManager.GetSysString(1338)); mainGame->PopupElement(mainGame->wACMessage, 20); prev_deck = sel; } } else if(prev_operation == BUTTON_LEAVE_GAME) { Terminate(); } else if(prev_operation == COMBOBOX_DBDECKS) { int sel = mainGame->cbDBDecks->getSelected(); deckManager.LoadDeck(mainGame->cbDBDecks->getItem(sel)); prev_deck = sel; } prev_operation = 0; break; } case BUTTON_NO: { mainGame->HideElement(mainGame->wQuery); if (prev_operation == COMBOBOX_DBDECKS) { mainGame->cbDBDecks->setSelected(prev_deck); } prev_operation = 0; break; } case BUTTON_MARKS_FILTER: { mainGame->PopupElement(mainGame->wLinkMarks); break; } case BUTTON_MARKERS_OK: { filter_marks = 0; if (mainGame->btnMark[0]->isPressed()) filter_marks |= 0100; if (mainGame->btnMark[1]->isPressed()) filter_marks |= 0200; if (mainGame->btnMark[2]->isPressed()) filter_marks |= 0400; if (mainGame->btnMark[3]->isPressed()) filter_marks |= 0010; if (mainGame->btnMark[4]->isPressed()) filter_marks |= 0040; if (mainGame->btnMark[5]->isPressed()) filter_marks |= 0001; if (mainGame->btnMark[6]->isPressed()) filter_marks |= 0002; if (mainGame->btnMark[7]->isPressed()) filter_marks |= 0004; mainGame->HideElement(mainGame->wLinkMarks); StartFilter(); break; } } break; } case irr::gui::EGET_EDITBOX_ENTER: { switch(id) { case EDITBOX_KEYWORD: { StartFilter(); break; } } break; } case irr::gui::EGET_EDITBOX_CHANGED: { switch (id) { case EDITBOX_KEYWORD: { stringw filter = mainGame->ebCardName->getText(); if (filter.size() > 2) { StartFilter(); } break; } case EDITBOX_DECK_NAME: { mainGame->ValidateName(mainGame->ebDeckname); break; } } break; } case irr::gui::EGET_COMBO_BOX_CHANGED: { switch(id) { case COMBOBOX_DBLFLIST: { filterList = deckManager._lfList[mainGame->cbDBLFList->getSelected()].content; break; } case COMBOBOX_DBDECKS: { int sel = mainGame->cbDBDecks->getSelected(); if(sel >= 0) deckManager.LoadDeck(mainGame->cbDBDecks->getItem(sel)); prev_deck = sel; break; } case COMBOBOX_MAINTYPE: { mainGame->cbCardType2->setSelected(0); mainGame->cbAttribute->setSelected(0); mainGame->cbRace->setSelected(0); mainGame->ebAttack->setText(L""); mainGame->ebDefense->setText(L""); mainGame->ebStar->setText(L""); mainGame->ebScale->setText(L""); switch(mainGame->cbCardType->getSelected()) { case 0: { mainGame->cbCardType2->setEnabled(false); mainGame->cbCardType2->setSelected(0); mainGame->cbRace->setEnabled(false); mainGame->cbAttribute->setEnabled(false); mainGame->ebAttack->setEnabled(false); mainGame->ebDefense->setEnabled(false); mainGame->ebStar->setEnabled(false); mainGame->ebScale->setEnabled(false); break; } case 1: { wchar_t normaltuner[32]; wchar_t normalpen[32]; wchar_t syntuner[32]; mainGame->cbCardType2->setEnabled(true); mainGame->cbRace->setEnabled(true); mainGame->cbAttribute->setEnabled(true); mainGame->ebAttack->setEnabled(true); mainGame->ebDefense->setEnabled(true); mainGame->ebStar->setEnabled(true); mainGame->ebScale->setEnabled(true); mainGame->cbCardType2->clear(); mainGame->cbCardType2->addItem(dataManager.GetSysString(1080), 0); mainGame->cbCardType2->addItem(dataManager.GetSysString(1054), TYPE_MONSTER + TYPE_NORMAL); mainGame->cbCardType2->addItem(dataManager.GetSysString(1055), TYPE_MONSTER + TYPE_EFFECT); mainGame->cbCardType2->addItem(dataManager.GetSysString(1056), TYPE_MONSTER + TYPE_FUSION); mainGame->cbCardType2->addItem(dataManager.GetSysString(1057), TYPE_MONSTER + TYPE_RITUAL); mainGame->cbCardType2->addItem(dataManager.GetSysString(1063), TYPE_MONSTER + TYPE_SYNCHRO); mainGame->cbCardType2->addItem(dataManager.GetSysString(1073), TYPE_MONSTER + TYPE_XYZ); mainGame->cbCardType2->addItem(dataManager.GetSysString(1074), TYPE_MONSTER + TYPE_PENDULUM); mainGame->cbCardType2->addItem(dataManager.GetSysString(1076), TYPE_MONSTER + TYPE_LINK); mainGame->cbCardType2->addItem(dataManager.GetSysString(1075), TYPE_MONSTER + TYPE_SPSUMMON); myswprintf(normaltuner, L"%ls|%ls", dataManager.GetSysString(1054), dataManager.GetSysString(1062)); mainGame->cbCardType2->addItem(normaltuner, TYPE_MONSTER + TYPE_NORMAL + TYPE_TUNER); myswprintf(normalpen, L"%ls|%ls", dataManager.GetSysString(1054), dataManager.GetSysString(1074)); mainGame->cbCardType2->addItem(normalpen, TYPE_MONSTER + TYPE_NORMAL + TYPE_PENDULUM); myswprintf(syntuner, L"%ls|%ls", dataManager.GetSysString(1063), dataManager.GetSysString(1062)); mainGame->cbCardType2->addItem(syntuner, TYPE_MONSTER + TYPE_SYNCHRO + TYPE_TUNER); mainGame->cbCardType2->addItem(dataManager.GetSysString(1062), TYPE_MONSTER + TYPE_TUNER); mainGame->cbCardType2->addItem(dataManager.GetSysString(1061), TYPE_MONSTER + TYPE_DUAL); mainGame->cbCardType2->addItem(dataManager.GetSysString(1060), TYPE_MONSTER + TYPE_UNION); mainGame->cbCardType2->addItem(dataManager.GetSysString(1059), TYPE_MONSTER + TYPE_SPIRIT); mainGame->cbCardType2->addItem(dataManager.GetSysString(1071), TYPE_MONSTER + TYPE_FLIP); mainGame->cbCardType2->addItem(dataManager.GetSysString(1072), TYPE_MONSTER + TYPE_TOON); break; } case 2: { mainGame->cbCardType2->setEnabled(true); mainGame->cbRace->setEnabled(false); mainGame->cbAttribute->setEnabled(false); mainGame->ebAttack->setEnabled(false); mainGame->ebDefense->setEnabled(false); mainGame->ebStar->setEnabled(false); mainGame->ebScale->setEnabled(false); mainGame->cbCardType2->clear(); mainGame->cbCardType2->addItem(dataManager.GetSysString(1080), 0); mainGame->cbCardType2->addItem(dataManager.GetSysString(1054), TYPE_SPELL); mainGame->cbCardType2->addItem(dataManager.GetSysString(1066), TYPE_SPELL + TYPE_QUICKPLAY); mainGame->cbCardType2->addItem(dataManager.GetSysString(1067), TYPE_SPELL + TYPE_CONTINUOUS); mainGame->cbCardType2->addItem(dataManager.GetSysString(1057), TYPE_SPELL + TYPE_RITUAL); mainGame->cbCardType2->addItem(dataManager.GetSysString(1068), TYPE_SPELL + TYPE_EQUIP); mainGame->cbCardType2->addItem(dataManager.GetSysString(1069), TYPE_SPELL + TYPE_FIELD); break; } case 3: { mainGame->cbCardType2->setEnabled(true); mainGame->cbRace->setEnabled(false); mainGame->cbAttribute->setEnabled(false); mainGame->ebAttack->setEnabled(false); mainGame->ebDefense->setEnabled(false); mainGame->ebStar->setEnabled(false); mainGame->ebScale->setEnabled(false); mainGame->cbCardType2->clear(); mainGame->cbCardType2->addItem(dataManager.GetSysString(1080), 0); mainGame->cbCardType2->addItem(dataManager.GetSysString(1054), TYPE_TRAP); mainGame->cbCardType2->addItem(dataManager.GetSysString(1067), TYPE_TRAP + TYPE_CONTINUOUS); mainGame->cbCardType2->addItem(dataManager.GetSysString(1070), TYPE_TRAP + TYPE_COUNTER); break; } } StartFilter(); break; } case COMBOBOX_SECONDTYPE: case COMBOBOX_OTHER_FILT: { if (id==COMBOBOX_SECONDTYPE && mainGame->cbCardType->getSelected() == 1) { if (mainGame->cbCardType2->getSelected() == 8) { mainGame->ebDefense->setEnabled(false); mainGame->ebDefense->setText(L""); } else { mainGame->ebDefense->setEnabled(true); } } StartFilter(); break; } case COMBOBOX_SORTTYPE: { SortList(); mainGame->env->setFocus(0); break; } } break; } case irr::gui::EGET_CHECKBOX_CHANGED: { switch (id) { case CHECKBOX_SHOW_ANIME: { int prevLimit = mainGame->cbLimit->getSelected(); mainGame->cbLimit->clear(); mainGame->cbLimit->addItem(dataManager.GetSysString(1310)); mainGame->cbLimit->addItem(dataManager.GetSysString(1316)); mainGame->cbLimit->addItem(dataManager.GetSysString(1317)); mainGame->cbLimit->addItem(dataManager.GetSysString(1318)); mainGame->cbLimit->addItem(dataManager.GetSysString(1240)); mainGame->cbLimit->addItem(dataManager.GetSysString(1241)); mainGame->cbLimit->addItem(dataManager.GetSysString(1242)); if(mainGame->chkAnime->isChecked()) { mainGame->cbLimit->addItem(dataManager.GetSysString(1243)); mainGame->cbLimit->addItem(L"Illegal"); mainGame->cbLimit->addItem(L"VG"); mainGame->cbLimit->addItem(L"Custom"); } if (prevLimit < 8) mainGame->cbLimit->setSelected(prevLimit); StartFilter(); break; } } break; } default: break; } break; } case irr::EET_MOUSE_INPUT_EVENT: { switch(event.MouseInput.Event) { case irr::EMIE_LMOUSE_PRESSED_DOWN: { irr::gui::IGUIElement* root = mainGame->env->getRootGUIElement(); if(root->getElementFromPoint(mouse_pos) != root) break; if(mainGame->wCategories->isVisible() || mainGame->wQuery->isVisible()) break; if(hovered_pos == 0 || hovered_seq == -1) break; click_pos = hovered_pos; dragx = event.MouseInput.X; dragy = event.MouseInput.Y; draging_pointer = dataManager.GetCodePointer(hovered_code); if(draging_pointer == dataManager._datas.end()) break; if(hovered_pos == 4) { if(!check_limit(draging_pointer)) break; } is_draging = true; if(hovered_pos == 1) pop_main(hovered_seq); else if(hovered_pos == 2) pop_extra(hovered_seq); else if(hovered_pos == 3) pop_side(hovered_seq); mouse_pos.set(event.MouseInput.X, event.MouseInput.Y); GetHoveredCard(); break; } case irr::EMIE_LMOUSE_LEFT_UP: { if(!is_draging) break; bool pushed = false; if(hovered_pos == 1) pushed = push_main(draging_pointer, hovered_seq); else if(hovered_pos == 2) pushed = push_extra(draging_pointer, hovered_seq + is_lastcard); else if(hovered_pos == 3) pushed = push_side(draging_pointer, hovered_seq + is_lastcard); else if(hovered_pos == 4 && !mainGame->is_siding) pushed = true; if(!pushed) { if(click_pos == 1) push_main(draging_pointer); else if(click_pos == 2) push_extra(draging_pointer); else if(click_pos == 3) push_side(draging_pointer); } is_draging = false; break; } case irr::EMIE_RMOUSE_LEFT_UP: { if(mainGame->is_siding) { if(is_draging) break; if(hovered_pos == 0 || hovered_seq == -1) break; auto pointer = dataManager.GetCodePointer(hovered_code); if(pointer == dataManager._datas.end()) break; if(hovered_pos == 1) { if(push_side(pointer)) pop_main(hovered_seq); } else if(hovered_pos == 2) { if(push_side(pointer)) pop_extra(hovered_seq); } else { if(push_extra(pointer) || push_main(pointer)) pop_side(hovered_seq); } break; } if(mainGame->wCategories->isVisible() || mainGame->wQuery->isVisible()) break; if(!is_draging) { if(hovered_pos == 0 || hovered_seq == -1) break; if(hovered_pos == 1) { pop_main(hovered_seq); } else if(hovered_pos == 2) { pop_extra(hovered_seq); } else if(hovered_pos == 3) { pop_side(hovered_seq); } else { auto pointer = dataManager.GetCodePointer(hovered_code); if(pointer == dataManager._datas.end()) break; if(event.MouseInput.Shift) push_side(pointer); else { if (!check_limit(pointer)) break; if (!push_extra(pointer) && !push_main(pointer)) push_side(pointer); } } } else { if(click_pos == 1) { push_side(draging_pointer); } else if(click_pos == 2) { push_side(draging_pointer); } else if(click_pos == 3) { if(!push_extra(draging_pointer)) push_main(draging_pointer); } else { push_side(draging_pointer); } is_draging = false; } break; } case irr::EMIE_MMOUSE_LEFT_UP: { if (mainGame->is_siding) break; if (mainGame->wCategories->isVisible() || mainGame->wQuery->isVisible()) break; if (hovered_pos == 0 || hovered_seq == -1) break; if (is_draging) break; auto pointer = dataManager.GetCodePointer(hovered_code); if(!check_limit(pointer)) break; if (hovered_pos == 1) { if(!push_main(pointer)) push_side(pointer); } else if (hovered_pos == 2) { if(!push_extra(pointer)) push_side(pointer); } else if (hovered_pos == 3) { if(!push_side(pointer) && !push_extra(pointer)) push_main(pointer); } else { if(!push_extra(pointer) && !push_main(pointer)) push_side(pointer); } break; } case irr::EMIE_MOUSE_MOVED: { mouse_pos.set(event.MouseInput.X, event.MouseInput.Y); GetHoveredCard(); break; } case irr::EMIE_MOUSE_WHEEL: { if(!mainGame->scrFilter->isVisible()) break; if(!mainGame->Resize(805, 160, 1020, 630).isPointInside(mouse_pos)) break; if(event.MouseInput.Wheel < 0) { if(mainGame->scrFilter->getPos() < mainGame->scrFilter->getMax()) mainGame->scrFilter->setPos(mainGame->scrFilter->getPos() + 1); } else { if(mainGame->scrFilter->getPos() > 0) mainGame->scrFilter->setPos(mainGame->scrFilter->getPos() - 1); } GetHoveredCard(); break; } default: break; } break; } default: break; } return false; }
bool ReplayMode::StartDuel() { const ReplayHeader& rh = cur_replay.pheader; mtrandom rnd; int seed = rh.seed; rnd.reset(seed); if (mainGame->dInfo.isRelay) { cur_replay.ReadName(mainGame->dInfo.hostname[0]); cur_replay.ReadName(mainGame->dInfo.hostname[1]); cur_replay.ReadName(mainGame->dInfo.hostname[2]); cur_replay.ReadName(mainGame->dInfo.clientname[0]); cur_replay.ReadName(mainGame->dInfo.clientname[1]); cur_replay.ReadName(mainGame->dInfo.clientname[2]); } else if (mainGame->dInfo.isTag) { cur_replay.ReadName(mainGame->dInfo.hostname[0]); cur_replay.ReadName(mainGame->dInfo.hostname[1]); cur_replay.ReadName(mainGame->dInfo.clientname[1]); cur_replay.ReadName(mainGame->dInfo.clientname[0]); } else { cur_replay.ReadName(mainGame->dInfo.hostname[0]); cur_replay.ReadName(mainGame->dInfo.clientname[0]); } pduel = create_duel(rnd.rand()); int start_lp = cur_replay.ReadInt32(); int start_hand = cur_replay.ReadInt32(); int draw_count = cur_replay.ReadInt32(); int opt = cur_replay.ReadInt32(); int duel_rule = opt >> 16; int rule = opt >> 16; //backwards compatibility with master rule replays if (rule) switch (rule) { case 1: { opt |= MASTER_RULE_1; break; } case 2: { opt |= MASTER_RULE_2; break; } case 3: { opt |= MASTER_RULE_3; break; } case 4: { opt |= MASTER_RULE_4; break; } } //pre mr4 replay compatibility if (opt & DUEL_OBSOLETE_RULING) { opt &= ~DUEL_OBSOLETE_RULING; opt |= MASTER_RULE_1; } else if (!(opt & 0xff80)) opt |= MASTER_RULE_3; mainGame->dInfo.duel_field = 2; if ((opt & DUEL_PZONE) && (opt & DUEL_SEPARATE_PZONE) && (opt & DUEL_EMZONE)) mainGame->dInfo.duel_field = 5; else if (opt & DUEL_EMZONE) mainGame->dInfo.duel_field = 4; else if (opt & DUEL_PZONE) mainGame->dInfo.duel_field = 3; mainGame->dInfo.extraval = (opt & SPEED_DUEL) ? 1 : 0; mainGame->SetPhaseButtons(); set_player_info(pduel, 0, start_lp, start_hand, draw_count); set_player_info(pduel, 1, start_lp, start_hand, draw_count); mainGame->dInfo.lp[0] = start_lp; mainGame->dInfo.lp[1] = start_lp; mainGame->dInfo.startlp = start_lp; myswprintf(mainGame->dInfo.strLP[0], L"%d", mainGame->dInfo.lp[0]); myswprintf(mainGame->dInfo.strLP[1], L"%d", mainGame->dInfo.lp[1]); mainGame->dInfo.turn = 0; if (!mainGame->dInfo.isSingleMode) { if (!(opt & DUEL_TAG_MODE)) { int main = cur_replay.ReadInt32(); for (int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); int extra = cur_replay.ReadInt32(); for (int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(0, main, extra); main = cur_replay.ReadInt32(); for (int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); extra = cur_replay.ReadInt32(); for (int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(1, main, extra); } else { int main = cur_replay.ReadInt32(); for (int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); int extra = cur_replay.ReadInt32(); for (int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(0, main, extra); main = cur_replay.ReadInt32(); for (int i = 0; i < main; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 0, LOCATION_DECK); extra = cur_replay.ReadInt32(); for (int i = 0; i < extra; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 0, LOCATION_EXTRA); main = cur_replay.ReadInt32(); for (int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); extra = cur_replay.ReadInt32(); for (int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(1, main, extra); main = cur_replay.ReadInt32(); for (int i = 0; i < main; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 1, LOCATION_DECK); extra = cur_replay.ReadInt32(); for (int i = 0; i < extra; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 1, LOCATION_EXTRA); } } else { char filename[256]; size_t slen = cur_replay.ReadInt16(); cur_replay.ReadData(filename, slen); filename[slen] = 0; if (!preload_script(pduel, filename, slen)) { return false; } } start_duel(pduel, opt); return true; }
bool DeckBuilder::OnEvent(const irr::SEvent& event) { switch(event.EventType) { case irr::EET_GUI_EVENT: { s32 id = event.GUIEvent.Caller->getID(); if(mainGame->wCategories->isVisible() && id != BUTTON_CATEGORY_OK) break; if(mainGame->wQuery->isVisible() && id != BUTTON_YES && id != BUTTON_NO) break; switch(event.GUIEvent.EventType) { case irr::gui::EGET_BUTTON_CLICKED: { switch(id) { case BUTTON_CLEAR_DECK: { mainGame->gMutex.Lock(); mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, (wchar_t*)dataManager.GetSysString(1339)); mainGame->PopupElement(mainGame->wQuery); mainGame->gMutex.Unlock(); is_clearing = true; break; } case BUTTON_SORT_DECK: { std::sort(deckManager.current_deck.main.begin(), deckManager.current_deck.main.end(), ClientCard::deck_sort_lv); std::sort(deckManager.current_deck.extra.begin(), deckManager.current_deck.extra.end(), ClientCard::deck_sort_lv); std::sort(deckManager.current_deck.side.begin(), deckManager.current_deck.side.end(), ClientCard::deck_sort_lv); break; } case BUTTON_SHUFFLE_DECK: { std::random_shuffle(deckManager.current_deck.main.begin(), deckManager.current_deck.main.end()); break; } case BUTTON_SAVE_DECK: { if(deckManager.SaveDeck(deckManager.current_deck, mainGame->cbDBDecks->getItem(mainGame->cbDBDecks->getSelected()))) { mainGame->stACMessage->setText(dataManager.GetSysString(1335)); mainGame->PopupElement(mainGame->wACMessage, 20); } break; } case BUTTON_SAVE_DECK_AS: { const wchar_t* dname = mainGame->ebDeckname->getText(); if(*dname == 0) break; int sel = -1; for(size_t i = 0; i < mainGame->cbDBDecks->getItemCount(); ++i) { if(!wcscmp(dname, mainGame->cbDBDecks->getItem(i))) { sel = i; break; } } if(sel >= 0) mainGame->cbDBDecks->setSelected(sel); else { mainGame->cbDBDecks->addItem(dname); mainGame->cbDBDecks->setSelected(mainGame->cbDBDecks->getItemCount() - 1); } if(deckManager.SaveDeck(deckManager.current_deck, dname)) { mainGame->stACMessage->setText(dataManager.GetSysString(1335)); mainGame->PopupElement(mainGame->wACMessage, 20); } break; } case BUTTON_DELETE_DECK: { int sel = mainGame->cbDBDecks->getSelected(); if(sel == -1) break; mainGame->gMutex.Lock(); wchar_t textBuffer[256]; myswprintf(textBuffer, L"%ls\n%ls", mainGame->cbDBDecks->getItem(sel), dataManager.GetSysString(1337)); mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, (wchar_t*)textBuffer); mainGame->PopupElement(mainGame->wQuery); mainGame->gMutex.Unlock(); is_deleting = true; break; } case BUTTON_LEAVE_GAME: { mainGame->is_building = false; mainGame->wDeckEdit->setVisible(false); mainGame->wCategories->setVisible(false); mainGame->wFilter->setVisible(false); mainGame->wSort->setVisible(false); mainGame->wCardImg->setVisible(false); mainGame->wInfos->setVisible(false); mainGame->btnLeaveGame->setVisible(false); mainGame->PopupElement(mainGame->wMainMenu); mainGame->device->setEventReceiver(&mainGame->menuHandler); mainGame->wACMessage->setVisible(false); imageManager.ClearTexture(); mainGame->scrFilter->setVisible(false); if(mainGame->cbDBDecks->getSelected() != -1) { BufferIO::CopyWStr(mainGame->cbDBDecks->getItem(mainGame->cbDBDecks->getSelected()), mainGame->gameConf.lastdeck, 64); } if(exit_on_return) mainGame->device->closeDevice(); break; } case BUTTON_EFFECT_FILTER: { mainGame->PopupElement(mainGame->wCategories); break; } case BUTTON_START_FILTER: { filter_type = mainGame->cbCardType->getSelected(); filter_type2 = mainGame->cbCardType2->getItemData(mainGame->cbCardType2->getSelected()); filter_lm = mainGame->cbLimit->getSelected(); if(filter_type == 1) { filter_attrib = mainGame->cbAttribute->getItemData(mainGame->cbAttribute->getSelected()); filter_race = mainGame->cbRace->getItemData(mainGame->cbRace->getSelected()); filter_atk = parse_filter(mainGame->ebAttack->getText(), &filter_atktype); filter_def = parse_filter(mainGame->ebDefense->getText(), &filter_deftype); filter_lv = parse_filter(mainGame->ebStar->getText(), &filter_lvtype); filter_scl = parse_filter(mainGame->ebScale->getText(), &filter_scltype); } FilterCards(); if(!mainGame->gameConf.separate_clear_button) ClearFilter(); break; } case BUTTON_CLEAR_FILTER: { ClearSearch(); break; } case BUTTON_CATEGORY_OK: { filter_effect = 0; long long filter = 0x1; for(int i = 0; i < 32; ++i, filter <<= 1) if(mainGame->chkCategory[i]->isChecked()) filter_effect |= filter; mainGame->HideElement(mainGame->wCategories); break; } case BUTTON_SIDE_OK: { if(deckManager.current_deck.main.size() != pre_mainc || deckManager.current_deck.extra.size() != pre_extrac || deckManager.current_deck.side.size() != pre_sidec) { mainGame->env->addMessageBox(L"", dataManager.GetSysString(1410)); break; } char deckbuf[1024]; char* pdeck = deckbuf; BufferIO::WriteInt32(pdeck, deckManager.current_deck.main.size() + deckManager.current_deck.extra.size()); BufferIO::WriteInt32(pdeck, deckManager.current_deck.side.size()); for(size_t i = 0; i < deckManager.current_deck.main.size(); ++i) BufferIO::WriteInt32(pdeck, deckManager.current_deck.main[i]->first); for(size_t i = 0; i < deckManager.current_deck.extra.size(); ++i) BufferIO::WriteInt32(pdeck, deckManager.current_deck.extra[i]->first); for(size_t i = 0; i < deckManager.current_deck.side.size(); ++i) BufferIO::WriteInt32(pdeck, deckManager.current_deck.side[i]->first); DuelClient::SendBufferToServer(CTOS_UPDATE_DECK, deckbuf, pdeck - deckbuf); break; } case BUTTON_YES: { mainGame->HideElement(mainGame->wQuery); if(!mainGame->is_building || mainGame->is_siding) break; if(is_clearing) { deckManager.current_deck.main.clear(); deckManager.current_deck.extra.clear(); deckManager.current_deck.side.clear(); } else if(is_deleting) { int sel = mainGame->cbDBDecks->getSelected(); if (deckManager.DeleteDeck(deckManager.current_deck, mainGame->cbDBDecks->getItem(sel))) { mainGame->cbDBDecks->removeItem(sel); int count = mainGame->cbDBDecks->getItemCount(); if (sel >= count) sel = count - 1; mainGame->cbDBDecks->setSelected(sel); if (sel != -1) deckManager.LoadDeck(mainGame->cbDBDecks->getItem(sel)); mainGame->stACMessage->setText(dataManager.GetSysString(1338)); mainGame->PopupElement(mainGame->wACMessage, 20); } } is_clearing = false; is_deleting = false; break; } case BUTTON_NO: { mainGame->HideElement(mainGame->wQuery); is_deleting = false; is_clearing = false; break; } } break; } case irr::gui::EGET_SCROLL_BAR_CHANGED: { switch(id) { case SCROLL_CARDTEXT: { u32 pos = mainGame->scrCardText->getPos(); mainGame->SetStaticText(mainGame->stText, mainGame->stText->getRelativePosition().getWidth()-25, mainGame->textFont, mainGame->showingtext, pos); break; } break; } } case irr::gui::EGET_EDITBOX_ENTER: { switch(id) { case EDITBOX_KEYWORD: { irr::SEvent me; me.EventType = irr::EET_GUI_EVENT; me.GUIEvent.EventType = irr::gui::EGET_BUTTON_CLICKED; me.GUIEvent.Caller = mainGame->btnStartFilter; me.GUIEvent.Element = mainGame->btnStartFilter; mainGame->device->postEventFromUser(me); break; } } break; } case irr::gui::EGET_COMBO_BOX_CHANGED: { switch(id) { case COMBOBOX_DBLFLIST: { filterList = deckManager._lfList[mainGame->cbDBLFList->getSelected()].content; break; } case COMBOBOX_DBDECKS: { deckManager.LoadDeck(mainGame->cbDBDecks->getItem(mainGame->cbDBDecks->getSelected())); break; } case COMBOBOX_MAINTYPE: { mainGame->cbCardType2->setSelected(0); mainGame->cbAttribute->setSelected(0); mainGame->cbRace->setSelected(0); mainGame->ebAttack->setText(L""); mainGame->ebDefense->setText(L""); mainGame->ebStar->setText(L""); mainGame->ebScale->setText(L""); switch(mainGame->cbCardType->getSelected()) { case 0: { mainGame->cbCardType2->setEnabled(false); mainGame->cbCardType2->setSelected(0); mainGame->cbRace->setEnabled(false); mainGame->cbAttribute->setEnabled(false); mainGame->ebAttack->setEnabled(false); mainGame->ebDefense->setEnabled(false); mainGame->ebStar->setEnabled(false); mainGame->ebScale->setEnabled(false); break; } case 1: { wchar_t normaltuner[32]; wchar_t normalpen[32]; wchar_t syntuner[32]; mainGame->cbCardType2->setEnabled(true); mainGame->cbRace->setEnabled(true); mainGame->cbAttribute->setEnabled(true); mainGame->ebAttack->setEnabled(true); mainGame->ebDefense->setEnabled(true); mainGame->ebStar->setEnabled(true); mainGame->ebScale->setEnabled(true); mainGame->cbCardType2->clear(); mainGame->cbCardType2->addItem(dataManager.GetSysString(1080), 0); mainGame->cbCardType2->addItem(dataManager.GetSysString(1054), TYPE_MONSTER + TYPE_NORMAL); mainGame->cbCardType2->addItem(dataManager.GetSysString(1055), TYPE_MONSTER + TYPE_EFFECT); mainGame->cbCardType2->addItem(dataManager.GetSysString(1056), TYPE_MONSTER + TYPE_FUSION); mainGame->cbCardType2->addItem(dataManager.GetSysString(1057), TYPE_MONSTER + TYPE_RITUAL); mainGame->cbCardType2->addItem(dataManager.GetSysString(1063), TYPE_MONSTER + TYPE_SYNCHRO); mainGame->cbCardType2->addItem(dataManager.GetSysString(1073), TYPE_MONSTER + TYPE_XYZ); mainGame->cbCardType2->addItem(dataManager.GetSysString(1074), TYPE_MONSTER + TYPE_PENDULUM); myswprintf(normaltuner, L"%ls|%ls", dataManager.GetSysString(1054), dataManager.GetSysString(1062)); mainGame->cbCardType2->addItem(normaltuner, TYPE_MONSTER + TYPE_NORMAL + TYPE_TUNER); myswprintf(normalpen, L"%ls|%ls", dataManager.GetSysString(1054), dataManager.GetSysString(1074)); mainGame->cbCardType2->addItem(normalpen, TYPE_MONSTER + TYPE_NORMAL + TYPE_PENDULUM); myswprintf(syntuner, L"%ls|%ls", dataManager.GetSysString(1063), dataManager.GetSysString(1062)); mainGame->cbCardType2->addItem(syntuner, TYPE_MONSTER + TYPE_SYNCHRO + TYPE_TUNER); mainGame->cbCardType2->addItem(dataManager.GetSysString(1062), TYPE_MONSTER + TYPE_TUNER); mainGame->cbCardType2->addItem(dataManager.GetSysString(1061), TYPE_MONSTER + TYPE_DUAL); mainGame->cbCardType2->addItem(dataManager.GetSysString(1060), TYPE_MONSTER + TYPE_UNION); mainGame->cbCardType2->addItem(dataManager.GetSysString(1059), TYPE_MONSTER + TYPE_SPIRIT); mainGame->cbCardType2->addItem(dataManager.GetSysString(1071), TYPE_MONSTER + TYPE_FLIP); mainGame->cbCardType2->addItem(dataManager.GetSysString(1072), TYPE_MONSTER + TYPE_TOON); break; } case 2: { mainGame->cbCardType2->setEnabled(true); mainGame->cbRace->setEnabled(false); mainGame->cbAttribute->setEnabled(false); mainGame->ebAttack->setEnabled(false); mainGame->ebDefense->setEnabled(false); mainGame->ebStar->setEnabled(false); mainGame->ebScale->setEnabled(false); mainGame->cbCardType2->clear(); mainGame->cbCardType2->addItem(dataManager.GetSysString(1080), 0); mainGame->cbCardType2->addItem(dataManager.GetSysString(1054), TYPE_SPELL); mainGame->cbCardType2->addItem(dataManager.GetSysString(1066), TYPE_SPELL + TYPE_QUICKPLAY); mainGame->cbCardType2->addItem(dataManager.GetSysString(1067), TYPE_SPELL + TYPE_CONTINUOUS); mainGame->cbCardType2->addItem(dataManager.GetSysString(1057), TYPE_SPELL + TYPE_RITUAL); mainGame->cbCardType2->addItem(dataManager.GetSysString(1068), TYPE_SPELL + TYPE_EQUIP); mainGame->cbCardType2->addItem(dataManager.GetSysString(1069), TYPE_SPELL + TYPE_FIELD); break; } case 3: { mainGame->cbCardType2->setEnabled(true); mainGame->cbRace->setEnabled(false); mainGame->cbAttribute->setEnabled(false); mainGame->ebAttack->setEnabled(false); mainGame->ebDefense->setEnabled(false); mainGame->ebStar->setEnabled(false); mainGame->ebScale->setEnabled(false); mainGame->cbCardType2->clear(); mainGame->cbCardType2->addItem(dataManager.GetSysString(1080), 0); mainGame->cbCardType2->addItem(dataManager.GetSysString(1054), TYPE_TRAP); mainGame->cbCardType2->addItem(dataManager.GetSysString(1067), TYPE_TRAP + TYPE_CONTINUOUS); mainGame->cbCardType2->addItem(dataManager.GetSysString(1070), TYPE_TRAP + TYPE_COUNTER); break; } } break; } case COMBOBOX_SORTTYPE: { SortList(); mainGame->env->setFocus(0); break; } } } default: break; } break; } case irr::EET_MOUSE_INPUT_EVENT: { switch(event.MouseInput.Event) { case irr::EMIE_LMOUSE_PRESSED_DOWN: { irr::core::position2di mouse_pos(event.MouseInput.X, event.MouseInput.Y); irr::gui::IGUIElement* root = mainGame->env->getRootGUIElement(); if(root->getElementFromPoint(mouse_pos) != root) break; if(mainGame->wCategories->isVisible() || mainGame->wQuery->isVisible()) break; if(hovered_pos == 0 || hovered_seq == -1) break; click_pos = hovered_pos; dragx = event.MouseInput.X; dragy = event.MouseInput.Y; draging_pointer = dataManager.GetCodePointer(hovered_code); if(draging_pointer == dataManager._datas.end()) break; unsigned int limitcode = draging_pointer->second.alias ? draging_pointer->second.alias : draging_pointer->first; if(hovered_pos == 4) { int limit = 3; if(filterList->count(limitcode)) limit = (*filterList)[limitcode]; for(size_t i = 0; i < deckManager.current_deck.main.size(); ++i) if(deckManager.current_deck.main[i]->first == limitcode || deckManager.current_deck.main[i]->second.alias == limitcode) limit--; for(size_t i = 0; i < deckManager.current_deck.extra.size(); ++i) if(deckManager.current_deck.extra[i]->first == limitcode || deckManager.current_deck.extra[i]->second.alias == limitcode) limit--; for(size_t i = 0; i < deckManager.current_deck.side.size(); ++i) if(deckManager.current_deck.side[i]->first == limitcode || deckManager.current_deck.side[i]->second.alias == limitcode) limit--; if(limit <= 0) break; } if(hovered_pos == 1) deckManager.current_deck.main.erase(deckManager.current_deck.main.begin() + hovered_seq); else if(hovered_pos == 2) deckManager.current_deck.extra.erase(deckManager.current_deck.extra.begin() + hovered_seq); else if(hovered_pos == 3) deckManager.current_deck.side.erase(deckManager.current_deck.side.begin() + hovered_seq); is_draging = true; break; } case irr::EMIE_LMOUSE_LEFT_UP: { if(!is_draging) break; if(!mainGame->is_siding) { if((hovered_pos == 1 && (draging_pointer->second.type & 0x802040)) || (hovered_pos == 2 && !(draging_pointer->second.type & 0x802040))) hovered_pos = 0; if((hovered_pos == 1 || (hovered_pos == 0 && click_pos == 1)) && deckManager.current_deck.main.size() < 60) { if(hovered_seq == -1) deckManager.current_deck.main.push_back(draging_pointer); else if(hovered_seq < (int)deckManager.current_deck.main.size() && hovered_pos) deckManager.current_deck.main.insert(deckManager.current_deck.main.begin() + hovered_seq, draging_pointer); else deckManager.current_deck.main.push_back(draging_pointer); is_draging = false; } else if((hovered_pos == 2 || (hovered_pos == 0 && click_pos == 2)) && deckManager.current_deck.extra.size() < 15) { if(hovered_seq == -1) deckManager.current_deck.extra.push_back(draging_pointer); else if(hovered_seq < (int)deckManager.current_deck.extra.size() && hovered_pos) deckManager.current_deck.extra.insert(deckManager.current_deck.extra.begin() + hovered_seq, draging_pointer); else deckManager.current_deck.extra.push_back(draging_pointer); is_draging = false; } else if((hovered_pos == 3 || (hovered_pos == 0 && click_pos == 3)) && deckManager.current_deck.side.size() < 15) { if(hovered_seq == -1) deckManager.current_deck.side.push_back(draging_pointer); else if(hovered_seq < (int)deckManager.current_deck.side.size() && hovered_pos) deckManager.current_deck.side.insert(deckManager.current_deck.side.begin() + hovered_seq, draging_pointer); else deckManager.current_deck.side.push_back(draging_pointer); is_draging = false; } else if (hovered_pos == 4) is_draging = false; } else { if((hovered_pos == 1 && (draging_pointer->second.type & 0x802040)) || (hovered_pos == 2 && !(draging_pointer->second.type & 0x802040)) || hovered_pos == 4) hovered_pos = 0; if((hovered_pos == 1 || (hovered_pos == 0 && click_pos == 1)) && deckManager.current_deck.main.size() < 65) { if(hovered_seq == -1) deckManager.current_deck.main.push_back(draging_pointer); else if(hovered_seq < (int)deckManager.current_deck.main.size() && hovered_pos) deckManager.current_deck.main.insert(deckManager.current_deck.main.begin() + hovered_seq, draging_pointer); else deckManager.current_deck.main.push_back(draging_pointer); is_draging = false; } else if((hovered_pos == 2 || (hovered_pos == 0 && click_pos == 2)) && deckManager.current_deck.extra.size() < 20) { if(hovered_seq == -1) deckManager.current_deck.extra.push_back(draging_pointer); else if(hovered_seq < (int)deckManager.current_deck.extra.size() && hovered_pos) deckManager.current_deck.extra.insert(deckManager.current_deck.extra.begin() + hovered_seq, draging_pointer); else deckManager.current_deck.extra.push_back(draging_pointer); is_draging = false; } else if((hovered_pos == 3 || (hovered_pos == 0 && click_pos == 3)) && deckManager.current_deck.side.size() < 20) { if(hovered_seq == -1) deckManager.current_deck.side.push_back(draging_pointer); else if(hovered_seq < (int)deckManager.current_deck.side.size() && hovered_pos) deckManager.current_deck.side.insert(deckManager.current_deck.side.begin() + hovered_seq, draging_pointer); else deckManager.current_deck.side.push_back(draging_pointer); is_draging = false; } } if(is_draging) { if(click_pos == 1) deckManager.current_deck.main.push_back(draging_pointer); else if(click_pos == 2) deckManager.current_deck.extra.push_back(draging_pointer); else if(click_pos == 3) deckManager.current_deck.side.push_back(draging_pointer); } is_draging = false; break; } case irr::EMIE_RMOUSE_LEFT_UP: { if(mainGame->is_siding) { if(is_draging) break; if(hovered_pos == 0 || hovered_seq == -1) break; draging_pointer = dataManager.GetCodePointer(hovered_code); if(draging_pointer == dataManager._datas.end()) break; if(hovered_pos == 1) { if(deckManager.current_deck.side.size() < 20) { deckManager.current_deck.main.erase(deckManager.current_deck.main.begin() + hovered_seq); deckManager.current_deck.side.push_back(draging_pointer); } } else if(hovered_pos == 2) { if(deckManager.current_deck.side.size() < 20) { deckManager.current_deck.extra.erase(deckManager.current_deck.extra.begin() + hovered_seq); deckManager.current_deck.side.push_back(draging_pointer); } } else { if((draging_pointer->second.type & 0x802040) && deckManager.current_deck.extra.size() < 20) { deckManager.current_deck.side.erase(deckManager.current_deck.side.begin() + hovered_seq); deckManager.current_deck.extra.push_back(draging_pointer); } if(!(draging_pointer->second.type & 0x802040) && deckManager.current_deck.main.size() < 64) { deckManager.current_deck.side.erase(deckManager.current_deck.side.begin() + hovered_seq); deckManager.current_deck.main.push_back(draging_pointer); } } break; } if(mainGame->wCategories->isVisible() || mainGame->wQuery->isVisible()) break; if(hovered_pos == 0 || hovered_seq == -1) break; if(!is_draging) { draging_pointer = dataManager.GetCodePointer(hovered_code); if(draging_pointer == dataManager._datas.end()) break; } if(hovered_pos == 1) { if(!is_draging) deckManager.current_deck.main.erase(deckManager.current_deck.main.begin() + hovered_seq); else if(deckManager.current_deck.side.size() < 15) { deckManager.current_deck.side.push_back(draging_pointer); is_draging = false; } } else if(hovered_pos == 2) { if(!is_draging) deckManager.current_deck.extra.erase(deckManager.current_deck.extra.begin() + hovered_seq); else if(deckManager.current_deck.side.size() < 15) { deckManager.current_deck.side.push_back(draging_pointer); is_draging = false; } } else if(hovered_pos == 3) { if(!is_draging) deckManager.current_deck.side.erase(deckManager.current_deck.side.begin() + hovered_seq); else { if((draging_pointer->second.type & 0x802040) && deckManager.current_deck.extra.size() < 15) { deckManager.current_deck.extra.push_back(draging_pointer); is_draging = false; } else if(!(draging_pointer->second.type & 0x802040) && deckManager.current_deck.main.size() < 60) { deckManager.current_deck.main.push_back(draging_pointer); is_draging = false; } } } else { if(is_draging) { if(deckManager.current_deck.side.size() < 15) { deckManager.current_deck.side.push_back(draging_pointer); is_draging = false; } } else { unsigned int limitcode = draging_pointer->second.alias ? draging_pointer->second.alias : draging_pointer->first; int limit = 3; if(filterList->count(limitcode)) limit = (*filterList)[limitcode]; for(size_t i = 0; i < deckManager.current_deck.main.size(); ++i) if(deckManager.current_deck.main[i]->first == limitcode || deckManager.current_deck.main[i]->second.alias == limitcode) limit--; for(size_t i = 0; i < deckManager.current_deck.extra.size(); ++i) if(deckManager.current_deck.extra[i]->first == limitcode || deckManager.current_deck.extra[i]->second.alias == limitcode) limit--; for(size_t i = 0; i < deckManager.current_deck.side.size(); ++i) if(deckManager.current_deck.side[i]->first == limitcode || deckManager.current_deck.side[i]->second.alias == limitcode) limit--; if(limit <= 0) break; if((draging_pointer->second.type & 0x802040) && deckManager.current_deck.extra.size() < 15) { deckManager.current_deck.extra.push_back(draging_pointer); } else if(!(draging_pointer->second.type & 0x802040) && deckManager.current_deck.main.size() < 60) { deckManager.current_deck.main.push_back(draging_pointer); } else if (deckManager.current_deck.side.size() < 15) { deckManager.current_deck.side.push_back(draging_pointer); } } } break; } case irr::EMIE_MMOUSE_LEFT_UP: { if (mainGame->is_siding) break; if (mainGame->wCategories->isVisible() || mainGame->wQuery->isVisible()) break; if (hovered_pos == 0 || hovered_seq == -1) break; if (is_draging) break; draging_pointer = dataManager.GetCodePointer(hovered_code); unsigned int limitcode = draging_pointer->second.alias ? draging_pointer->second.alias : draging_pointer->first; int limit = 3; if (filterList->count(limitcode)) limit = (*filterList)[limitcode]; for (size_t i = 0; i < deckManager.current_deck.main.size(); ++i) if (deckManager.current_deck.main[i]->first == limitcode || deckManager.current_deck.main[i]->second.alias == limitcode) limit--; for (size_t i = 0; i < deckManager.current_deck.extra.size(); ++i) if (deckManager.current_deck.extra[i]->first == limitcode || deckManager.current_deck.extra[i]->second.alias == limitcode) limit--; for (size_t i = 0; i < deckManager.current_deck.side.size(); ++i) if (deckManager.current_deck.side[i]->first == limitcode || deckManager.current_deck.side[i]->second.alias == limitcode) limit--; if (limit <= 0) break; if (hovered_pos == 1) { if (deckManager.current_deck.main.size() < 60) deckManager.current_deck.main.push_back(draging_pointer); else if (deckManager.current_deck.side.size() < 15) deckManager.current_deck.side.push_back(draging_pointer); } else if (hovered_pos == 2) { if (deckManager.current_deck.extra.size() < 15) deckManager.current_deck.extra.push_back(draging_pointer); else if (deckManager.current_deck.side.size() < 15) deckManager.current_deck.side.push_back(draging_pointer); } else if (hovered_pos == 3) { if (deckManager.current_deck.side.size() < 15) deckManager.current_deck.side.push_back(draging_pointer); else { if ((draging_pointer->second.type & 0x802040) && deckManager.current_deck.extra.size() < 15) deckManager.current_deck.extra.push_back(draging_pointer); else if (!(draging_pointer->second.type & 0x802040) && deckManager.current_deck.main.size() < 60) deckManager.current_deck.main.push_back(draging_pointer); } } else { if ((draging_pointer->second.type & 0x802040) && deckManager.current_deck.extra.size() < 15) deckManager.current_deck.extra.push_back(draging_pointer); else if (!(draging_pointer->second.type & 0x802040) && deckManager.current_deck.main.size() < 60) deckManager.current_deck.main.push_back(draging_pointer); else if (deckManager.current_deck.side.size() < 15) deckManager.current_deck.side.push_back(draging_pointer); } break; } case irr::EMIE_MOUSE_MOVED: { int x = event.MouseInput.X; int y = event.MouseInput.Y; irr::core::position2di mouse_pos(x, y); irr::gui::IGUIElement* root = mainGame->env->getRootGUIElement(); if(root->getElementFromPoint(mouse_pos) != root) break; int pre_code = hovered_code; if(x >= 314 && x <= 794 && y >= 164 && y <= 435) { int lx = 10, px, py = (y - 164) / 68; hovered_pos = 1; if(deckManager.current_deck.main.size() > 40) lx = (deckManager.current_deck.main.size() - 41) / 4 + 11; if(x >= 750) px = lx - 1; else px = (x - 314) * (lx - 1) / 436; if(py*lx + px >= (int)deckManager.current_deck.main.size()) { hovered_seq = -1; hovered_code = 0; } else { hovered_seq = py * lx + px; hovered_code = deckManager.current_deck.main[hovered_seq]->first; } } else if(x >= 314 && x <= 794 && y >= 466 && y <= 530) { int lx = deckManager.current_deck.extra.size(); hovered_pos = 2; if(lx < 10) lx = 10; if(x >= 750) hovered_seq = lx - 1; else hovered_seq = (x - 314) * (lx - 1) / 436; if(hovered_seq >= (int)deckManager.current_deck.extra.size()) { hovered_seq = -1; hovered_code = 0; } else { hovered_code = deckManager.current_deck.extra[hovered_seq]->first; } } else if (x >= 314 && x <= 794 && y >= 564 && y <= 628) { int lx = deckManager.current_deck.side.size(); hovered_pos = 3; if(lx < 10) lx = 10; if(x >= 750) hovered_seq = lx - 1; else hovered_seq = (x - 314) * (lx - 1) / 436; if(hovered_seq >= (int)deckManager.current_deck.side.size()) { hovered_seq = -1; hovered_code = 0; } else { hovered_code = deckManager.current_deck.side[hovered_seq]->first; } } else if(x >= 810 && x <= 995 && y >= 165 && y <= 626) { hovered_pos = 4; hovered_seq = (y - 165) / 66; if(mainGame->scrFilter->getPos() + hovered_seq >= (int)results.size()) { hovered_seq = -1; hovered_code = 0; } else { hovered_code = results[mainGame->scrFilter->getPos() + hovered_seq]->first; } } else { hovered_pos = 0; hovered_code = 0; } if(is_draging) { dragx = x; dragy = y; } if(!is_draging && pre_code != hovered_code) { if(hovered_code) { mainGame->ShowCardInfo(hovered_code); } if(pre_code) imageManager.RemoveTexture(pre_code); } break; } case irr::EMIE_MOUSE_WHEEL: { if(!mainGame->scrFilter->isVisible()) break; if(event.MouseInput.Wheel < 0) { if(mainGame->scrFilter->getPos() < mainGame->scrFilter->getMax()) mainGame->scrFilter->setPos(mainGame->scrFilter->getPos() + 1); } else { if(mainGame->scrFilter->getPos() > 0) mainGame->scrFilter->setPos(mainGame->scrFilter->getPos() - 1); } SEvent e = event; e.MouseInput.Event = irr::EMIE_MOUSE_MOVED; mainGame->device->postEventFromUser(e); break; } default: break; } break; } case irr::EET_KEY_INPUT_EVENT: { switch(event.KeyInput.Key) { case irr::KEY_KEY_R: { if(!event.KeyInput.PressedDown && !mainGame->HasFocus(EGUIET_EDIT_BOX)) mainGame->textFont->setTransparency(true); break; } case irr::KEY_ESCAPE: { if(!mainGame->HasFocus(EGUIET_EDIT_BOX)) mainGame->device->minimizeWindow(); break; } default: break; } break; } default: break; } return false; }
int ReplayMode::ReplayThread(void* param) { const ReplayHeader& rh = cur_replay.pheader; mainGame->dInfo.isFirst = true; mtrandom rnd; int seed = rh.seed; rnd.reset(seed); if(rh.flag & REPLAY_TAG) { cur_replay.ReadData(mainGame->dInfo.hostname, 40); cur_replay.ReadData(mainGame->dInfo.hostname_tag, 40); cur_replay.ReadData(mainGame->dInfo.clientname_tag, 40); cur_replay.ReadData(mainGame->dInfo.clientname, 40); mainGame->dInfo.isTag = true; mainGame->dInfo.tag_player[0] = false; mainGame->dInfo.tag_player[1] = false; } else { cur_replay.ReadData(mainGame->dInfo.hostname, 40); cur_replay.ReadData(mainGame->dInfo.clientname, 40); } set_script_reader(default_script_reader); set_card_reader((card_reader)DataManager::CardReader); set_message_handler((message_handler)MessageHandler); pduel = create_duel(rnd.rand()); int start_lp = cur_replay.ReadInt32(); int start_hand = cur_replay.ReadInt32(); int draw_count = cur_replay.ReadInt32(); int opt = cur_replay.ReadInt32(); set_player_info(pduel, 0, start_lp, start_hand, draw_count); set_player_info(pduel, 1, start_lp, start_hand, draw_count); mainGame->dInfo.lp[0] = start_lp; mainGame->dInfo.lp[1] = start_lp; myswprintf(mainGame->dInfo.strLP[0], L"%d", mainGame->dInfo.lp[0]); myswprintf(mainGame->dInfo.strLP[1], L"%d", mainGame->dInfo.lp[1]); mainGame->dInfo.turn = 0; if(!(opt & DUEL_TAG_MODE)) { int main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); int extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(0, main, extra); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(1, main, extra); } else { int main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); int extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(0, main, extra); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 0, LOCATION_DECK); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 0, LOCATION_EXTRA); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(1, main, extra); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 1, LOCATION_DECK); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 1, LOCATION_EXTRA); } start_duel(pduel, opt); ReplayRefreshDeck(0); ReplayRefreshDeck(1); ReplayRefreshExtra(0); ReplayRefreshExtra(1); mainGame->dInfo.isStarted = true; mainGame->dInfo.isReplay = true; char engineBuffer[0x1000]; is_continuing = true; exit_pending = false; current_step = 0; skip_step = 0; if(skip_turn < 0) skip_turn = 0; if(skip_turn) { mainGame->dInfo.isReplaySkiping = true; mainGame->gMutex.Lock(); } else mainGame->dInfo.isReplaySkiping = false; int len = 0; while (is_continuing && !exit_pending) { int result = process(pduel); len = result & 0xffff; /*int flag = result >> 16;*/ if (len > 0) { get_message(pduel, (byte*)engineBuffer); is_continuing = ReplayAnalyze(engineBuffer, len); } } if(mainGame->dInfo.isReplaySkiping) { mainGame->dInfo.isReplaySkiping = false; mainGame->dField.RefreshAllCards(); mainGame->gMutex.Unlock(); } end_duel(pduel); if(!is_closing) { mainGame->actionSignal.Reset(); mainGame->gMutex.Lock(); mainGame->stMessage->setText(dataManager.GetSysString(1501)); if(mainGame->wCardSelect->isVisible()) mainGame->HideElement(mainGame->wCardSelect); mainGame->PopupElement(mainGame->wMessage); mainGame->gMutex.Unlock(); mainGame->actionSignal.Wait(); mainGame->gMutex.Lock(); mainGame->dInfo.isStarted = false; mainGame->dInfo.isReplay = false; mainGame->gMutex.Unlock(); mainGame->closeDoneSignal.Reset(); mainGame->closeSignal.Set(); mainGame->closeDoneSignal.Wait(); mainGame->gMutex.Lock(); mainGame->ShowElement(mainGame->wReplay); mainGame->device->setEventReceiver(&mainGame->menuHandler); mainGame->gMutex.Unlock(); if(exit_on_return) mainGame->device->closeDevice(); } return 0; }
void ReplayMode::Restart(bool refresh) { end_duel(pduel); mainGame->dInfo.isStarted = false; mainGame->dField.panel = 0; mainGame->dField.hovered_card = 0; mainGame->dField.clicked_card = 0; mainGame->dField.Clear(); //mainGame->device->setEventReceiver(&mainGame->dField); cur_replay.Rewind(); const ReplayHeader& rh = cur_replay.pheader; //mainGame->dInfo.isFirst = true; mtrandom rnd; int seed = rh.seed; rnd.reset(seed); if(rh.flag & REPLAY_TAG) { cur_replay.ReadData(mainGame->dInfo.hostname, 40); cur_replay.ReadData(mainGame->dInfo.hostname_tag, 40); cur_replay.ReadData(mainGame->dInfo.clientname_tag, 40); cur_replay.ReadData(mainGame->dInfo.clientname, 40); mainGame->dInfo.isTag = true; mainGame->dInfo.tag_player[0] = false; mainGame->dInfo.tag_player[1] = false; } else { cur_replay.ReadData(mainGame->dInfo.hostname, 40); cur_replay.ReadData(mainGame->dInfo.clientname, 40); } //set_card_reader((card_reader)DataManager::CardReader); //set_message_handler((message_handler)MessageHandler); pduel = create_duel(rnd.rand()); int start_lp = cur_replay.ReadInt32(); int start_hand = cur_replay.ReadInt32(); int draw_count = cur_replay.ReadInt32(); int opt = cur_replay.ReadInt32(); set_player_info(pduel, 0, start_lp, start_hand, draw_count); set_player_info(pduel, 1, start_lp, start_hand, draw_count); mainGame->dInfo.lp[0] = start_lp; mainGame->dInfo.lp[1] = start_lp; myswprintf(mainGame->dInfo.strLP[0], L"%d", mainGame->dInfo.lp[0]); myswprintf(mainGame->dInfo.strLP[1], L"%d", mainGame->dInfo.lp[1]); mainGame->dInfo.turn = 0; if(!(opt & DUEL_TAG_MODE)) { int main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); int extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(0, main, extra); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(1, main, extra); } else { int main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); int extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(0, main, extra); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 0, LOCATION_DECK); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 0, LOCATION_EXTRA); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(1, main, extra); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 1, LOCATION_DECK); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 1, LOCATION_EXTRA); } start_duel(pduel, opt); if(refresh) { mainGame->dField.RefreshAllCards(); mainGame->dInfo.isStarted = true; //mainGame->dInfo.isReplay = true; } skip_turn = 0; is_restarting = true; }
int NetManager::JoinThread(void* adr) { SOCKADDR_IN server; NetManager* pnet = (NetManager*)adr; server.sin_addr.s_addr = pnet->remote_addr; server.sin_family = AF_INET; server.sin_port = htons(pnet->remote_port); if(connect(pnet->sRemote, (sockaddr*)&server, sizeof(sockaddr)) == SOCKET_ERROR) { closesocket(pnet->sRemote); if(!mainGame->is_closing) { mainGame->btnLanStartServer->setEnabled(true); mainGame->btnLanConnect->setEnabled(true); mainGame->btnRefreshList->setEnabled(true); mainGame->btnLoadReplay->setEnabled(true); mainGame->btnDeckEdit->setEnabled(true); mainGame->stModeStatus->setText(L"无法连接至主机"); } return 0; } char* pbuf = pnet->send_buf; NetManager::WriteInt16(pbuf, PROTO_VERSION); const wchar_t* pname = mainGame->ebJoinPass->getText(); int i = 0; while(pname[i] != 0 && i < 19) NetManager::WriteInt16(pbuf, pname[i++]); NetManager::WriteInt16(pbuf, 0); i = 0; pname = mainGame->ebUsername->getText(); while(pname[i] != 0 && i < 19) { mainGame->dInfo.hostname[i] = pname[i]; NetManager::WriteInt16(pbuf, pname[i++]); } NetManager::WriteInt16(pbuf, 0); mainGame->dInfo.hostname[i] = 0; NetManager::WriteInt16(pbuf, mainGame->deckManager.deckhost.main.size() + mainGame->deckManager.deckhost.extra.size()); NetManager::WriteInt16(pbuf, mainGame->deckManager.deckhost.side.size()); for(int i = 0; i < mainGame->deckManager.deckhost.main.size(); ++i) NetManager::WriteInt32(pbuf, mainGame->deckManager.deckhost.main[i]->first); for(int i = 0; i < mainGame->deckManager.deckhost.extra.size(); ++i) NetManager::WriteInt32(pbuf, mainGame->deckManager.deckhost.extra[i]->first); for(int i = 0; i < mainGame->deckManager.deckhost.side.size(); ++i) NetManager::WriteInt32(pbuf, mainGame->deckManager.deckhost.side[i]->first); pnet->SendtoRemote(pnet->send_buf, pbuf - pnet->send_buf); int result = recv(pnet->sRemote, pnet->recv_buf, 4096, 0); if(result == SOCKET_ERROR || pnet->recv_buf[0] != 0) { closesocket(pnet->sRemote); if(!mainGame->is_closing) { mainGame->btnLanStartServer->setEnabled(true); mainGame->btnLanConnect->setEnabled(true); mainGame->btnRefreshList->setEnabled(true); mainGame->btnLoadReplay->setEnabled(true); mainGame->btnDeckEdit->setEnabled(true); if(result == SOCKET_ERROR) mainGame->stModeStatus->setText(L"网络连接发生错误"); else if(pnet->recv_buf[0] == 0x1) { wchar_t errorbuf[32]; myswprintf(errorbuf, L"当前版本(0x%X)与主机版本(0x%X)不匹配", PROTO_VERSION, (int)(*(short*)&pnet->recv_buf[1])); mainGame->stModeStatus->setText(errorbuf); } else if(pnet->recv_buf[0] == 0x2) { mainGame->stModeStatus->setText(L"无效卡组或者卡组不符合禁卡表规范"); } else mainGame->stModeStatus->setText(L"密码错误"); } return 0; } wchar_t* pn = (wchar_t*)&pnet->recv_buf[1]; int pi = 0; while(pn[pi] && pi < 19) { mainGame->dInfo.clientname[pi] = pn[pi]; pi++; } mainGame->gMutex.Lock(); tracking.clearHost(); mainGame->dInfo.clientname[pi] = 0; mainGame->imgCard->setImage(mainGame->imageManager.tCover); mainGame->wCardImg->setVisible(true); mainGame->wInfos->setVisible(true); mainGame->stName->setText(L""); mainGame->stInfo->setText(L""); mainGame->stDataInfo->setText(L""); mainGame->stText->setText(L""); mainGame->lstServerList->clear(); mainGame->stModeStatus->setText(L""); mainGame->dInfo.engLen = 0; mainGame->dInfo.msgLen = 0; mainGame->dInfo.is_local_host = false; mainGame->dField.Clear(); mainGame->btnLanStartServer->setEnabled(true); mainGame->btnLanConnect->setEnabled(true); mainGame->btnRefreshList->setEnabled(true); mainGame->btnLoadReplay->setEnabled(true); mainGame->btnDeckEdit->setEnabled(true); mainGame->HideElement(mainGame->wModeSelection); mainGame->gMutex.Unlock(); mainGame->WaitFrameSignal(10); Thread::NewThread(Game::RecvThread, &mainGame->dInfo); Thread::NewThread(Game::GameThread, &mainGame->dInfo); }
void Game::DrawMisc() { static irr::core::vector3df act_rot(0, 0, 0); irr::core::matrix4 im, ic, it; act_rot.Z += 0.02f; im.setRotationRadians(act_rot); matManager.mTexture.setTexture(0, imageManager.tAct); driver->setMaterial(matManager.mTexture); if(dField.deck_act) { im.setTranslation(vector3df(matManager.vFields[0].Pos.X - (matManager.vFields[0].Pos.X - matManager.vFields[1].Pos.X)/2, matManager.vFields[0].Pos.Y - (matManager.vFields[0].Pos.Y - matManager.vFields[3].Pos.Y)/2, dField.deck[0].size() * 0.01f + 0.02f)); driver->setTransform(irr::video::ETS_WORLD, im); driver->drawVertexPrimitiveList(matManager.vActivate, 4, matManager.iRectangle, 2); } if(dField.grave_act) { im.setTranslation(vector3df(matManager.vFields[4].Pos.X - (matManager.vFields[4].Pos.X - matManager.vFields[5].Pos.X)/2, matManager.vFields[4].Pos.Y - (matManager.vFields[4].Pos.Y - matManager.vFields[6].Pos.Y)/2, dField.grave[0].size() * 0.01f + 0.02f)); driver->setTransform(irr::video::ETS_WORLD, im); driver->drawVertexPrimitiveList(matManager.vActivate, 4, matManager.iRectangle, 2); } if(dField.remove_act) { im.setTranslation(vector3df(matManager.vFields[12].Pos.X - (matManager.vFields[12].Pos.X - matManager.vFields[13].Pos.X)/2, matManager.vFields[12].Pos.Y - (matManager.vFields[12].Pos.Y - matManager.vFields[14].Pos.Y)/2, dField.remove[0].size() * 0.01f + 0.02f)); driver->setTransform(irr::video::ETS_WORLD, im); driver->drawVertexPrimitiveList(matManager.vActivate, 4, matManager.iRectangle, 2); } if(dField.extra_act) { im.setTranslation(vector3df(matManager.vFields[8].Pos.X - (matManager.vFields[8].Pos.X - matManager.vFields[9].Pos.X)/2, matManager.vFields[8].Pos.Y - (matManager.vFields[8].Pos.Y - matManager.vFields[10].Pos.Y)/2, dField.extra[0].size() * 0.01f + 0.02f)); driver->setTransform(irr::video::ETS_WORLD, im); driver->drawVertexPrimitiveList(matManager.vActivate, 4, matManager.iRectangle, 2); } if(dField.pzone_act) { im.setTranslation(vector3df(matManager.vFields[60].Pos.X - (matManager.vFields[60].Pos.X - matManager.vFields[61].Pos.X)/2, matManager.vFields[60].Pos.Y - (matManager.vFields[60].Pos.Y - matManager.vFields[62].Pos.Y)/2, 0.03f)); driver->setTransform(irr::video::ETS_WORLD, im); driver->drawVertexPrimitiveList(matManager.vActivate, 4, matManager.iRectangle, 2); } if(dField.chains.size() > 1) { for(size_t i = 0; i < dField.chains.size(); ++i) { if(dField.chains[i].solved) break; matManager.mTRTexture.setTexture(0, imageManager.tChain); matManager.mTRTexture.AmbientColor = 0xffffff00; ic.setRotationRadians(act_rot); ic.setTranslation(dField.chains[i].chain_pos); driver->setMaterial(matManager.mTRTexture); driver->setTransform(irr::video::ETS_WORLD, ic); driver->drawVertexPrimitiveList(matManager.vSymbol, 4, matManager.iRectangle, 2); it.setScale(0.6f); it.setTranslation(dField.chains[i].chain_pos); matManager.mTRTexture.setTexture(0, imageManager.tNumber); matManager.vChainNum[0].TCoords = vector2df(0.19375f * (i % 5), 0.2421875f * (i / 5)); matManager.vChainNum[1].TCoords = vector2df(0.19375f * (i % 5 + 1), 0.2421875f * (i / 5)); matManager.vChainNum[2].TCoords = vector2df(0.19375f * (i % 5), 0.2421875f * (i / 5 + 1)); matManager.vChainNum[3].TCoords = vector2df(0.19375f * (i % 5 + 1), 0.2421875f * (i / 5 + 1)); driver->setMaterial(matManager.mTRTexture); driver->setTransform(irr::video::ETS_WORLD, it); driver->drawVertexPrimitiveList(matManager.vChainNum, 4, matManager.iRectangle, 2); } } //lp bar if((dInfo.turn % 2 && dInfo.isFirst) || (!(dInfo.turn % 2) && !dInfo.isFirst)) { driver->draw2DRectangle(0xa0000000, recti(327, 8, 630, 51)); driver->draw2DRectangleOutline(recti(327, 8, 630, 51), 0xffff8080); } else { driver->draw2DRectangle(0xa0000000, recti(689, 8, 991, 51)); driver->draw2DRectangleOutline(recti(689, 8, 991, 51), 0xffff8080); } driver->draw2DImage(imageManager.tLPFrame, recti(330, 10, 629, 30), recti(0, 0, 200, 20), 0, 0, true); driver->draw2DImage(imageManager.tLPFrame, recti(691, 10, 990, 30), recti(0, 0, 200, 20), 0, 0, true); if(dInfo.lp[0] >= 8000) driver->draw2DImage(imageManager.tLPBar, recti(335, 12, 625, 28), recti(0, 0, 16, 16), 0, 0, true); else driver->draw2DImage(imageManager.tLPBar, recti(335, 12, 335 + 290 * dInfo.lp[0] / 8000, 28), recti(0, 0, 16, 16), 0, 0, true); if(dInfo.lp[1] >= 8000) driver->draw2DImage(imageManager.tLPBar, recti(696, 12, 986, 28), recti(0, 0, 16, 16), 0, 0, true); else driver->draw2DImage(imageManager.tLPBar, recti(986 - 290 * dInfo.lp[1] / 8000, 12, 986, 28), recti(0, 0, 16, 16), 0, 0, true); if(lpframe) { dInfo.lp[lpplayer] -= lpd; myswprintf(dInfo.strLP[lpplayer], L"%d", dInfo.lp[lpplayer]); lpccolor -= 0x19000000; lpframe--; } if(lpcstring) { if(lpplayer == 0) { lpcFont->draw(lpcstring, recti(400, 470, 920, 520), lpccolor | 0x00ffffff, true, false, 0); lpcFont->draw(lpcstring, recti(400, 472, 922, 520), lpccolor, true, false, 0); } else { lpcFont->draw(lpcstring, recti(400, 160, 920, 210), lpccolor | 0x00ffffff, true, false, 0); lpcFont->draw(lpcstring, recti(400, 162, 922, 210), lpccolor, true, false, 0); } } if(!dInfo.isReplay && dInfo.player_type < 7 && dInfo.time_limit) { driver->draw2DRectangle(recti(525, 34, 525 + dInfo.time_left[0] * 100 / dInfo.time_limit, 44), 0xa0e0e0e0, 0xa0e0e0e0, 0xa0c0c0c0, 0xa0c0c0c0); driver->draw2DRectangleOutline(recti(525, 34, 625, 44), 0xffffffff); driver->draw2DRectangle(recti(795 - dInfo.time_left[1] * 100 / dInfo.time_limit, 34, 795, 44), 0xa0e0e0e0, 0xa0e0e0e0, 0xa0c0c0c0, 0xa0c0c0c0); driver->draw2DRectangleOutline(recti(695, 34, 795, 44), 0xffffffff); } numFont->draw(dInfo.strLP[0], recti(330, 11, 629, 30), 0xff000000, true, false, 0); numFont->draw(dInfo.strLP[0], recti(330, 12, 631, 30), 0xffffff00, true, false, 0); numFont->draw(dInfo.strLP[1], recti(691, 11, 990, 30), 0xff000000, true, false, 0); numFont->draw(dInfo.strLP[1], recti(691, 12, 992, 30), 0xffffff00, true, false, 0); if(!dInfo.isTag || !dInfo.tag_player[0]) textFont->draw(dInfo.hostname, recti(335, 31, 629, 50), 0xffffffff, false, false, 0); else textFont->draw(dInfo.hostname_tag, recti(335, 31, 629, 50), 0xffffffff, false, false, 0); if(!dInfo.isTag || !dInfo.tag_player[1]) { auto cld = textFont->getDimension(dInfo.clientname); textFont->draw(dInfo.clientname, recti(986 - cld.Width, 31, 986, 50), 0xffffffff, false, false, 0); } else { auto cld = textFont->getDimension(dInfo.clientname_tag); textFont->draw(dInfo.clientname_tag, recti(986 - cld.Width, 31, 986, 50), 0xffffffff, false, false, 0); } driver->draw2DRectangle(recti(632, 10, 688, 30), 0x00000000, 0x00000000, 0xffffffff, 0xffffffff); driver->draw2DRectangle(recti(632, 30, 688, 50), 0xffffffff, 0xffffffff, 0x00000000, 0x00000000); lpcFont->draw(dataManager.GetNumString(dInfo.turn), recti(635, 5, 685, 40), 0x80000000, true, false, 0); lpcFont->draw(dataManager.GetNumString(dInfo.turn), recti(635, 5, 687, 40), 0x8000ffff, true, false, 0); ClientCard* pcard; for(int i = 0; i < 5; ++i) { pcard = dField.mzone[0][i]; if(pcard && pcard->code != 0) { int m = 493 + i * 85; adFont->draw(L"/", recti(m - 4, 416, m + 4, 436), 0xff000000, true, false, 0); adFont->draw(L"/", recti(m - 3, 417, m + 5, 437), 0xffffffff, true, false, 0); int w = adFont->getDimension(pcard->atkstring).Width; adFont->draw(pcard->atkstring, recti(m - 5 - w, 416, m - 5, 436), 0xff000000, false, false, 0); adFont->draw(pcard->atkstring, recti(m - 4 - w, 417, m - 4, 437), pcard->attack > pcard->base_attack ? 0xffffff00 : pcard->attack < pcard->base_attack ? 0xffff2090 : 0xffffffff , false, false, 0); w = adFont->getDimension(pcard->defstring).Width; adFont->draw(pcard->defstring, recti(m + 4, 416, m + 4 + w, 436), 0xff000000, false, false, 0); adFont->draw(pcard->defstring, recti(m + 5, 417, m + 5 + w, 437), pcard->defence > pcard->base_defence ? 0xffffff00 : pcard->defence < pcard->base_defence ? 0xffff2090 : 0xffffffff , false, false, 0); adFont->draw(pcard->lvstring, recti(473 + i * 80, 356, 475 + i * 80, 366), 0xff000000, false, false, 0); adFont->draw(pcard->lvstring, recti(474 + i * 80, 357, 476 + i * 80, 367), (pcard->type & TYPE_XYZ) ? 0xffff80ff : (pcard->type & TYPE_TUNER) ? 0xffffff00 : 0xffffffff, false, false, 0); } } for(int i = 0; i < 5; ++i) { pcard = dField.mzone[1][i]; if(pcard && (pcard->position & POS_FACEUP)) { int m = 803 - i * 68; adFont->draw(L"/", recti(m - 4, 235, m + 4, 255), 0xff000000, true, false, 0); adFont->draw(L"/", recti(m - 3, 236, m + 5, 256), 0xffffffff, true, false, 0); int w = adFont->getDimension(pcard->atkstring).Width; adFont->draw(pcard->atkstring, recti(m - 5 - w, 235, m - 5, 255), 0xff000000, false, false, 0); adFont->draw(pcard->atkstring, recti(m - 4 - w, 236, m - 4, 256), pcard->attack > pcard->base_attack ? 0xffffff00 : pcard->attack < pcard->base_attack ? 0xffff2090 : 0xffffffff , false, false, 0); w = adFont->getDimension(pcard->defstring).Width; adFont->draw(pcard->defstring, recti(m + 4, 235, m + 4 + w, 255), 0xff000000, false, false, 0); adFont->draw(pcard->defstring, recti(m + 5, 236, m + 5 + w, 256), pcard->defence > pcard->base_defence ? 0xffffff00 : pcard->defence < pcard->base_defence ? 0xffff2090 : 0xffffffff , false, false, 0); adFont->draw(pcard->lvstring, recti(779 - i * 71, 272, 800 - i * 71, 292), 0xff000000, false, false, 0); adFont->draw(pcard->lvstring, recti(780 - i * 71, 273, 800 - i * 71, 293), (pcard->type & TYPE_XYZ) ? 0xffff80ff : (pcard->type & TYPE_TUNER) ? 0xffffff00 : 0xffffffff, false, false, 0); } } pcard = dField.szone[0][6]; if(pcard) { adFont->draw(pcard->lscstring, recti(426, 394, 438, 414), 0xff000000, true, false, 0); adFont->draw(pcard->lscstring, recti(427, 395, 439, 415), 0xffffffff, true, false, 0); } pcard = dField.szone[0][7]; if(pcard) { adFont->draw(pcard->rscstring, recti(880, 394, 912, 414), 0xff000000, true, false, 0); adFont->draw(pcard->rscstring, recti(881, 395, 913, 415), 0xffffffff, true, false, 0); } pcard = dField.szone[1][6]; if(pcard) { adFont->draw(pcard->lscstring, recti(839, 245, 871, 265), 0xff000000, true, false, 0); adFont->draw(pcard->lscstring, recti(840, 246, 872, 266), 0xffffffff, true, false, 0); } pcard = dField.szone[1][7]; if(pcard) { adFont->draw(pcard->rscstring, recti(463, 245, 495, 265), 0xff000000, true, false, 0); adFont->draw(pcard->rscstring, recti(464, 246, 496, 266), 0xffffffff, true, false, 0); } if(dField.extra[0].size()) { numFont->draw(dataManager.GetNumString(dField.extra[0].size()), recti(330, 562, 381, 552), 0xff000000, true, false, 0); numFont->draw(dataManager.GetNumString(dField.extra[0].size()), recti(330, 563, 383, 553), 0xffffff00, true, false, 0); } if(dField.deck[0].size()) { numFont->draw(dataManager.GetNumString(dField.deck[0].size()), recti(907, 562, 1021, 552), 0xff000000, true, false, 0); numFont->draw(dataManager.GetNumString(dField.deck[0].size()), recti(908, 563, 1023, 553), 0xffffff00, true, false, 0); } if(dField.grave[0].size()) { numFont->draw(dataManager.GetNumString(dField.grave[0].size()), recti(837, 375, 984, 456), 0xff000000, true, false, 0); numFont->draw(dataManager.GetNumString(dField.grave[0].size()), recti(837, 376, 986, 457), 0xffffff00, true, false, 0); } if(dField.remove[0].size()) { numFont->draw(dataManager.GetNumString(dField.remove[0].size()), recti(1015, 375, 957, 380), 0xff000000, true, false, 0); numFont->draw(dataManager.GetNumString(dField.remove[0].size()), recti(1015, 376, 959, 381), 0xffffff00, true, false, 0); } if(dField.extra[1].size()) { numFont->draw(dataManager.GetNumString(dField.extra[1].size()), recti(818, 207, 908, 232), 0xff000000, true, false, 0); numFont->draw(dataManager.GetNumString(dField.extra[1].size()), recti(818, 208, 910, 233), 0xffffff00, true, false, 0); } if(dField.deck[1].size()) { numFont->draw(dataManager.GetNumString(dField.deck[1].size()), recti(465, 207, 481, 232), 0xff000000, true, false, 0); numFont->draw(dataManager.GetNumString(dField.deck[1].size()), recti(465, 208, 483, 233), 0xffffff00, true, false, 0); } if(dField.grave[1].size()) { numFont->draw(dataManager.GetNumString(dField.grave[1].size()), recti(420, 310, 462, 281), 0xff000000, true, false, 0); numFont->draw(dataManager.GetNumString(dField.grave[1].size()), recti(420, 311, 464, 282), 0xffffff00, true, false, 0); } if(dField.remove[1].size()) { numFont->draw(dataManager.GetNumString(dField.remove[1].size()), recti(300, 310, 443, 340), 0xff000000, true, false, 0); numFont->draw(dataManager.GetNumString(dField.remove[1].size()), recti(300, 311, 445, 341), 0xffffff00, true, false, 0); } }
bool ReplayMode::StartDuel() { const ReplayHeader& rh = cur_replay.pheader; mtrandom rnd; int seed = rh.seed; rnd.reset(seed); if(mainGame->dInfo.isTag) { cur_replay.ReadName(mainGame->dInfo.hostname); cur_replay.ReadName(mainGame->dInfo.hostname_tag); cur_replay.ReadName(mainGame->dInfo.clientname_tag); cur_replay.ReadName(mainGame->dInfo.clientname); } else { cur_replay.ReadName(mainGame->dInfo.hostname); cur_replay.ReadName(mainGame->dInfo.clientname); } pduel = create_duel(rnd.rand()); int start_lp = cur_replay.ReadInt32(); int start_hand = cur_replay.ReadInt32(); int draw_count = cur_replay.ReadInt32(); int opt = cur_replay.ReadInt32(); int duel_rule = opt >> 16; mainGame->dInfo.duel_rule = duel_rule; set_player_info(pduel, 0, start_lp, start_hand, draw_count); set_player_info(pduel, 1, start_lp, start_hand, draw_count); mainGame->dInfo.lp[0] = start_lp; mainGame->dInfo.lp[1] = start_lp; myswprintf(mainGame->dInfo.strLP[0], L"%d", mainGame->dInfo.lp[0]); myswprintf(mainGame->dInfo.strLP[1], L"%d", mainGame->dInfo.lp[1]); mainGame->dInfo.turn = 0; if(!mainGame->dInfo.isSingleMode) { if(!(opt & DUEL_TAG_MODE)) { int main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); int extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(0, main, extra); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(1, main, extra); } else { int main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); int extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(0, main, extra); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 0, LOCATION_DECK); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 0, LOCATION_EXTRA); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(1, main, extra); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 1, LOCATION_DECK); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 1, LOCATION_EXTRA); } } else { char filename[256]; size_t slen = cur_replay.ReadInt16(); cur_replay.ReadData(filename, slen); filename[slen] = 0; if(!preload_script(pduel, filename, 0)) { return false; } } start_duel(pduel, opt); return true; }
void DeckBuilder::FilterCards() { results.clear(); const wchar_t* pstr = mainGame->ebCardName->getText(); int trycode = BufferIO::GetVal(pstr); if(dataManager.GetData(trycode, 0)) { auto ptr = dataManager.GetCodePointer(trycode); // verified by GetData() results.push_back(ptr); mainGame->scrFilter->setVisible(false); mainGame->scrFilter->setPos(0); myswprintf(result_string, L"%d", results.size()); return; } unsigned int set_code = 0; if (pstr[0] == L'@') set_code = dataManager.GetSetCode(&pstr[1]); else set_code = dataManager.GetSetCode(&pstr[0]); if (pstr[0] == 0 || (pstr[0] == L'$' && pstr[1] == 0) || (pstr[0] == L'@' && pstr[1] == 0)) pstr = 0; auto strpointer = dataManager._strings.begin(); for(code_pointer ptr = dataManager._datas.begin(); ptr != dataManager._datas.end(); ++ptr, ++strpointer) { const CardDataC& data = ptr->second; const CardString& text = strpointer->second; if(data.type & TYPE_TOKEN || (data.ot > 3 && !mainGame->chkAnime->isChecked())) continue; switch(filter_type) { case 1: { if(!(data.type & TYPE_MONSTER) || (data.type & filter_type2) != filter_type2) continue; if(filter_race && data.race != filter_race) continue; if(filter_attrib && data.attribute != filter_attrib) continue; if(filter_atktype) { if((filter_atktype == 1 && data.attack != filter_atk) || (filter_atktype == 2 && data.attack < filter_atk) || (filter_atktype == 3 && data.attack <= filter_atk) || (filter_atktype == 4 && (data.attack > filter_atk || data.attack < 0)) || (filter_atktype == 5 && (data.attack >= filter_atk || data.attack < 0)) || (filter_atktype == 6 && data.attack != -2)) continue; } if(filter_deftype) { if((filter_deftype == 1 && data.defense != filter_def) || (filter_deftype == 2 && data.defense < filter_def) || (filter_deftype == 3 && data.defense <= filter_def) || (filter_deftype == 4 && (data.defense > filter_def || data.defense < 0)) || (filter_deftype == 5 && (data.defense >= filter_def || data.defense < 0)) || (filter_deftype == 6 && data.defense != -2) || (data.type & TYPE_LINK)) continue; } if(filter_lvtype) { if((filter_lvtype == 1 && data.level != filter_lv) || (filter_lvtype == 2 && data.level < filter_lv) || (filter_lvtype == 3 && data.level <= filter_lv) || (filter_lvtype == 4 && data.level > filter_lv) || (filter_lvtype == 5 && data.level >= filter_lv) || filter_lvtype == 6) continue; } if(filter_scltype) { if((filter_scltype == 1 && data.lscale != filter_scl) || (filter_scltype == 2 && data.lscale < filter_scl) || (filter_scltype == 3 && data.lscale <= filter_scl) || (filter_scltype == 4 && (data.lscale > filter_scl || data.lscale == 0)) || (filter_scltype == 5 && (data.lscale >= filter_scl || data.lscale == 0)) || filter_scltype == 6 || !(data.type & TYPE_PENDULUM)) continue; } break; } case 2: { if(!(data.type & TYPE_SPELL)) continue; if(filter_type2 && data.type != filter_type2) continue; break; } case 3: { if(!(data.type & TYPE_TRAP)) continue; if(filter_type2 && data.type != filter_type2) continue; break; } } if(filter_effect && !(data.category & filter_effect)) continue; if(filter_marks && (data.link_marker & filter_marks)!= filter_marks) continue; if(filter_lm) { if(filter_lm <= 3 && (!filterList->count(ptr->first) || (*filterList)[ptr->first] != filter_lm - 1)) continue; if(filter_lm == 4 && data.ot != 1) continue; if(filter_lm == 5 && data.ot != 2) continue; if(filter_lm == 6 && data.ot != 3) continue; if(filter_lm == 7 && data.ot != 4) continue; if(filter_lm == 8 && data.ot != 8) continue; if(filter_lm == 9 && data.ot != 16) continue; if(filter_lm == 10 && data.ot != 32) continue; } if(pstr) { if(pstr[0] == L'$') { if(!CardNameCompare(text.name.c_str(), &pstr[1])) continue; } else if(pstr[0] == L'@' && set_code) { if(!check_set_code(data, set_code)) continue; } else { if(!CardNameCompare(text.name.c_str(), pstr) && !(CardNameCompare(text.text.c_str(), pstr)) && (!set_code || !check_set_code(data, set_code))) continue; } } results.push_back(ptr); } myswprintf(result_string, L"%d", results.size()); if(results.size() > 7) { mainGame->scrFilter->setVisible(true); mainGame->scrFilter->setMax(results.size() - 7); mainGame->scrFilter->setPos(0); } else { mainGame->scrFilter->setVisible(false); mainGame->scrFilter->setPos(0); } SortList(); }
void ClientCard::UpdateInfo(char* buf) { int flag = NetManager::ReadInt32(buf); if(flag == 0) return; int pdata; if(flag & QUERY_CODE) { pdata = NetManager::ReadInt32(buf); if(location == LOCATION_HAND && controler == 1 && pdata != code) mainGame->dField.MoveCard(this, 5); code = pdata; } if(flag & QUERY_POSITION) pdata = NetManager::ReadInt32(buf); if(flag & QUERY_ALIAS) alias = NetManager::ReadInt32(buf); if(flag & QUERY_TYPE) type = NetManager::ReadInt32(buf); if(flag & QUERY_LEVEL) { pdata = NetManager::ReadInt32(buf); if(pdata && level != pdata) { level = pdata; myswprintf(lvstring, L"L%d", level); } } if(flag & QUERY_RANK) { pdata = NetManager::ReadInt32(buf); if(pdata && rank != pdata) { rank = pdata; myswprintf(lvstring, L"R%d", rank); } } if(flag & QUERY_ATTRIBUTE) attribute = NetManager::ReadInt32(buf); if(flag & QUERY_RACE) race = NetManager::ReadInt32(buf); if(flag & QUERY_ATTACK) { attack = NetManager::ReadInt32(buf); if(attack < 0) { atkstring[0] = '?'; atkstring[1] = 0; } else myswprintf(atkstring, L"%d", attack); } if(flag & QUERY_DEFENCE) { defence = NetManager::ReadInt32(buf); if(defence < 0) { defstring[0] = '?'; defstring[1] = 0; } else myswprintf(defstring, L"%d", defence); } if(flag & QUERY_BASE_ATTACK) base_attack = NetManager::ReadInt32(buf); if(flag & QUERY_BASE_DEFENCE) base_defence = NetManager::ReadInt32(buf); if(flag & QUERY_REASON) reason = NetManager::ReadInt32(buf); if(flag & QUERY_IS_DISABLED) is_disabled = NetManager::ReadInt32(buf); if(flag & QUERY_IS_PUBLIC) is_public = NetManager::ReadInt32(buf); }
void DeckBuilder::FilterCards() { results.clear(); struct element_t { std::wstring keyword; int setcode; enum class type_t { all, name, setcode } type; bool exclude; element_t(): setcode(0), type(type_t::all), exclude(false) {} }; const wchar_t* pstr = mainGame->ebCardName->getText(); std::wstring str = std::wstring(pstr); std::vector<element_t> query_elements; if(mainGame->gameConf.search_multiple_keywords) { const wchar_t separator = mainGame->gameConf.search_multiple_keywords == 1 ? L' ' : L'+'; const wchar_t minussign = L'-'; const wchar_t quotation = L'\"'; size_t element_start = 0; for(;;) { element_start = str.find_first_not_of(separator, element_start); if(element_start == std::wstring::npos) break; element_t element; if(str[element_start] == minussign) { element.exclude = true; element_start++; } if(element_start >= str.size()) break; if(str[element_start] == L'$') { element.type = element_t::type_t::name; element_start++; } else if(str[element_start] == L'@') { element.type = element_t::type_t::setcode; element_start++; } if(element_start >= str.size()) break; wchar_t delimiter = separator; if(str[element_start] == quotation) { delimiter = quotation; element_start++; } size_t element_end = str.find_first_of(delimiter, element_start); if(element_end != std::wstring::npos) { size_t length = element_end - element_start; element.keyword = str.substr(element_start, length); } else element.keyword = str.substr(element_start); element.setcode = dataManager.GetSetCode(element.keyword.c_str()); query_elements.push_back(element); if(element_end == std::wstring::npos) break; element_start = element_end + 1; } } else { element_t element; size_t element_start = 0; if(str[element_start] == L'$') { element.type = element_t::type_t::name; element_start++; } else if(str[element_start] == L'@') { element.type = element_t::type_t::setcode; element_start++; } if(element_start < str.size()) { element.keyword = str.substr(element_start); element.setcode = dataManager.GetSetCode(element.keyword.c_str()); query_elements.push_back(element); } } auto strpointer = dataManager._strings.begin(); for(code_pointer ptr = dataManager._datas.begin(); ptr != dataManager._datas.end(); ++ptr, ++strpointer) { const CardDataC& data = ptr->second; const CardString& text = strpointer->second; if(data.type & TYPE_TOKEN) continue; switch(filter_type) { case 1: { if(!(data.type & TYPE_MONSTER) || (data.type & filter_type2) != filter_type2) continue; if(filter_race && data.race != filter_race) continue; if(filter_attrib && data.attribute != filter_attrib) continue; if(filter_atktype) { if((filter_atktype == 1 && data.attack != filter_atk) || (filter_atktype == 2 && data.attack < filter_atk) || (filter_atktype == 3 && data.attack <= filter_atk) || (filter_atktype == 4 && (data.attack > filter_atk || data.attack < 0)) || (filter_atktype == 5 && (data.attack >= filter_atk || data.attack < 0)) || (filter_atktype == 6 && data.attack != -2)) continue; } if(filter_deftype) { if((filter_deftype == 1 && data.defense != filter_def) || (filter_deftype == 2 && data.defense < filter_def) || (filter_deftype == 3 && data.defense <= filter_def) || (filter_deftype == 4 && (data.defense > filter_def || data.defense < 0)) || (filter_deftype == 5 && (data.defense >= filter_def || data.defense < 0)) || (filter_deftype == 6 && data.defense != -2) || (data.type & TYPE_LINK)) continue; } if(filter_lvtype) { if((filter_lvtype == 1 && data.level != filter_lv) || (filter_lvtype == 2 && data.level < filter_lv) || (filter_lvtype == 3 && data.level <= filter_lv) || (filter_lvtype == 4 && data.level > filter_lv) || (filter_lvtype == 5 && data.level >= filter_lv) || filter_lvtype == 6) continue; } if(filter_scltype) { if((filter_scltype == 1 && data.lscale != filter_scl) || (filter_scltype == 2 && data.lscale < filter_scl) || (filter_scltype == 3 && data.lscale <= filter_scl) || (filter_scltype == 4 && (data.lscale > filter_scl || data.lscale == 0)) || (filter_scltype == 5 && (data.lscale >= filter_scl || data.lscale == 0)) || filter_scltype == 6 || !(data.type & TYPE_PENDULUM)) continue; } break; } case 2: { if(!(data.type & TYPE_SPELL)) continue; if(filter_type2 && data.type != filter_type2) continue; break; } case 3: { if(!(data.type & TYPE_TRAP)) continue; if(filter_type2 && data.type != filter_type2) continue; break; } } if(filter_effect && !(data.category & filter_effect)) continue; if(filter_marks && (data.link_marker & filter_marks)!= filter_marks) continue; if(filter_lm) { if(filter_lm <= 3 && (!filterList->count(ptr->first) || (*filterList)[ptr->first] != filter_lm - 1)) continue; if(filter_lm == 4 && data.ot != 1) continue; if(filter_lm == 5 && data.ot != 2) continue; if(filter_lm == 6 && data.ot != 3) continue; if(filter_lm == 7 && data.ot != 4) continue; } bool is_target = true; for (auto elements_iterator = query_elements.begin(); elements_iterator != query_elements.end(); ++elements_iterator) { bool match = false; if (elements_iterator->type == element_t::type_t::name) { match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str()); } else if (elements_iterator->type == element_t::type_t::setcode) { match = elements_iterator->setcode && check_set_code(data, elements_iterator->setcode); } else { int trycode = BufferIO::GetVal(elements_iterator->keyword.c_str()); bool tryresult = dataManager.GetData(trycode, 0); if(!tryresult) { match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str()) || text.text.find(elements_iterator->keyword) != std::wstring::npos || (elements_iterator->setcode && check_set_code(data, elements_iterator->setcode)); } else { match = data.code == trycode || data.alias == trycode; } } if(elements_iterator->exclude) match = !match; if(!match) { is_target = false; break; } } if(is_target) results.push_back(ptr); else continue; } myswprintf(result_string, L"%d", results.size()); if(results.size() > 7) { mainGame->scrFilter->setVisible(true); mainGame->scrFilter->setMax(results.size() - 7); mainGame->scrFilter->setPos(0); } else { mainGame->scrFilter->setVisible(false); mainGame->scrFilter->setPos(0); } SortList(); }