Commit 1481c3ae authored by nanahira's avatar nanahira

Merge branch 'master' into 2pick

parents ae41b942 aa439a3a
No preview for this file type
......@@ -203,8 +203,21 @@ void ClientField::AddCard(ClientCard* pcard, int controler, int location, int se
break;
}
case LOCATION_EXTRA: {
extra[controler].push_back(pcard);
pcard->sequence = extra[controler].size() - 1;
if(extra_p_count[controler] == 0 || (pcard->position & POS_FACEUP)) {
extra[controler].push_back(pcard);
pcard->sequence = extra[controler].size() - 1;
} else {
extra[controler].push_back(0);
int p = extra[controler].size() - extra_p_count[controler] - 1;
for(int i = extra[controler].size() - 1; i > p; --i) {
extra[controler][i] = extra[controler][i - 1];
extra[controler][i]->sequence++;
extra[controler][i]->curPos += irr::core::vector3df(0, 0, 0.01f);
extra[controler][i]->mTransform.setTranslation(extra[controler][i]->curPos);
}
extra[controler][p] = pcard;
pcard->sequence = p;
}
if (pcard->position & POS_FACEUP)
extra_p_count[controler]++;
break;
......
......@@ -80,5 +80,6 @@ extern int enable_log;
extern bool exit_on_return;
extern bool open_file;
extern wchar_t open_file_name[256];
extern bool bot_mode;
#endif
This diff is collapsed.
......@@ -125,7 +125,12 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
mainGame->btnCreateHost->setEnabled(true);
mainGame->btnJoinHost->setEnabled(true);
mainGame->btnJoinCancel->setEnabled(true);
mainGame->ShowElement(mainGame->wLanWindow);
mainGame->btnStartBot->setEnabled(true);
mainGame->btnBotCancel->setEnabled(true);
if(bot_mode)
mainGame->ShowElement(mainGame->wSinglePlay);
else
mainGame->ShowElement(mainGame->wLanWindow);
} else {
DuelClient::SendPacketToServer(CTOS_SURRENDER);
}
......
......@@ -118,7 +118,7 @@ bool Game::Initialize() {
wMainMenu = env->addWindow(rect<s32>(370, 200, 650, 415), false, strbuf);
wMainMenu->getCloseButton()->setVisible(false);
btnLanMode = env->addButton(rect<s32>(10, 30, 270, 60), wMainMenu, BUTTON_LAN_MODE, dataManager.GetSysString(1200));
btnServerMode = env->addButton(rect<s32>(10, 65, 270, 95), wMainMenu, BUTTON_SINGLE_MODE, dataManager.GetSysString(1201));
btnSingleMode = env->addButton(rect<s32>(10, 65, 270, 95), wMainMenu, BUTTON_SINGLE_MODE, dataManager.GetSysString(1201));
btnReplayMode = env->addButton(rect<s32>(10, 100, 270, 130), wMainMenu, BUTTON_REPLAY_MODE, dataManager.GetSysString(1202));
// btnTestMode = env->addButton(rect<s32>(10, 135, 270, 165), wMainMenu, BUTTON_TEST_MODE, dataManager.GetSysString(1203));
btnDeckEdit = env->addButton(rect<s32>(10, 135, 270, 165), wMainMenu, BUTTON_DECK_EDIT, dataManager.GetSysString(1204));
......@@ -585,12 +585,27 @@ bool Game::Initialize() {
wSinglePlay = env->addWindow(rect<s32>(220, 100, 800, 520), false, dataManager.GetSysString(1201));
wSinglePlay->getCloseButton()->setVisible(false);
wSinglePlay->setVisible(false);
lstSinglePlayList = env->addListBox(rect<s32>(10, 30, 350, 400), wSinglePlay, LISTBOX_SINGLEPLAY_LIST, true);
irr::gui::IGUITabControl* wSingle = env->addTabControl(rect<s32>(0, 20, 579, 419), wSinglePlay, true);
if(gameConf.enable_bot_mode) {
irr::gui::IGUITab* tabBot = wSingle->addTab(dataManager.GetSysString(1380));
lstBotList = env->addListBox(rect<s32>(10, 10, 350, 350), tabBot, LISTBOX_BOT_LIST, true);
lstBotList->setItemHeight(18);
btnStartBot = env->addButton(rect<s32>(459, 301, 569, 326), tabBot, BUTTON_BOT_START, dataManager.GetSysString(1211));
btnBotCancel = env->addButton(rect<s32>(459, 331, 569, 356), tabBot, BUTTON_CANCEL_SINGLEPLAY, dataManager.GetSysString(1210));
env->addStaticText(dataManager.GetSysString(1382), rect<s32>(360, 10, 550, 30), false, true, tabBot);
stBotInfo = env->addStaticText(L"", rect<s32>(360, 40, 560, 160), false, true, tabBot);
chkBotOldRule = env->addCheckBox(false, rect<s32>(360, 170, 560, 190), tabBot, CHECKBOX_BOT_OLD_RULE, dataManager.GetSysString(1383));
chkBotHand = env->addCheckBox(false, rect<s32>(360, 200, 560, 220), tabBot, -1, dataManager.GetSysString(1384));
chkBotNoCheckDeck = env->addCheckBox(false, rect<s32>(360, 230, 560, 250), tabBot, -1, dataManager.GetSysString(1229));
chkBotNoShuffleDeck = env->addCheckBox(false, rect<s32>(360, 260, 560, 280), tabBot, -1, dataManager.GetSysString(1230));
}
irr::gui::IGUITab* tabSingle = wSingle->addTab(dataManager.GetSysString(1381));
lstSinglePlayList = env->addListBox(rect<s32>(10, 10, 350, 350), tabSingle, LISTBOX_SINGLEPLAY_LIST, true);
lstSinglePlayList->setItemHeight(18);
btnLoadSinglePlay = env->addButton(rect<s32>(460, 355, 570, 380), wSinglePlay, BUTTON_LOAD_SINGLEPLAY, dataManager.GetSysString(1211));
btnSinglePlayCancel = env->addButton(rect<s32>(460, 385, 570, 410), wSinglePlay, BUTTON_CANCEL_SINGLEPLAY, dataManager.GetSysString(1210));
env->addStaticText(dataManager.GetSysString(1352), rect<s32>(360, 30, 570, 50), false, true, wSinglePlay);
stSinglePlayInfo = env->addStaticText(L"", rect<s32>(360, 60, 570, 350), false, true, wSinglePlay);
btnLoadSinglePlay = env->addButton(rect<s32>(459, 301, 569, 326), tabSingle, BUTTON_LOAD_SINGLEPLAY, dataManager.GetSysString(1211));
btnSinglePlayCancel = env->addButton(rect<s32>(459, 331, 569, 356), tabSingle, BUTTON_CANCEL_SINGLEPLAY, dataManager.GetSysString(1210));
env->addStaticText(dataManager.GetSysString(1352), rect<s32>(360, 10, 550, 30), false, true, tabSingle);
stSinglePlayInfo = env->addStaticText(L"", rect<s32>(360, 40, 550, 280), false, true, tabSingle);
//replay save
wReplaySave = env->addWindow(rect<s32>(510, 200, 820, 320), false, dataManager.GetSysString(1340));
wReplaySave->getCloseButton()->setVisible(false);
......@@ -932,6 +947,46 @@ void Game::RefreshSingleplay() {
closedir(dir);
#endif
}
void Game::RefreshBot() {
if(!gameConf.enable_bot_mode)
return;
botInfo.clear();
FILE* fp = fopen("bot.conf", "r");
char linebuf[256];
char strbuf[256];
if(fp) {
while(fgets(linebuf, 256, fp)) {
if(linebuf[0] == '#')
continue;
if(linebuf[0] == '!') {
BotInfo newinfo;
sscanf(linebuf, "!%240[^\n]", strbuf);
BufferIO::DecodeUTF8(strbuf, newinfo.name);
fgets(linebuf, 256, fp);
sscanf(linebuf, "%240[^\n]", strbuf);
BufferIO::DecodeUTF8(strbuf, newinfo.command);
fgets(linebuf, 256, fp);
sscanf(linebuf, "%240[^\n]", strbuf);
BufferIO::DecodeUTF8(strbuf, newinfo.desc);
fgets(linebuf, 256, fp);
newinfo.support_master_rule_3 = !!strstr(linebuf, "SUPPORT_MASTER_RULE_3");
newinfo.support_new_master_rule = !!strstr(linebuf, "SUPPORT_NEW_MASTER_RULE");
if((chkBotOldRule->isChecked() && newinfo.support_master_rule_3)
|| (!chkBotOldRule->isChecked() && newinfo.support_new_master_rule))
botInfo.push_back(newinfo);
continue;
}
}
fclose(fp);
}
lstBotList->clear();
stBotInfo->setText(L"");
for(unsigned int i = 0; i < botInfo.size(); ++i) {
lstBotList->addItem(botInfo[i].name);
}
if(botInfo.size() == 0)
SetStaticText(stBotInfo, 200, guiFont, dataManager.GetSysString(1385));
}
void Game::LoadConfig() {
FILE* fp = fopen("system.conf", "r");
if(!fp)
......@@ -969,6 +1024,7 @@ void Game::LoadConfig() {
gameConf.auto_search_limit = -1;
gameConf.chkIgnoreDeckChanges = 0;
gameConf.defaultOT = 1;
gameConf.enable_bot_mode = 0;
while(fgets(linebuf, 256, fp)) {
sscanf(linebuf, "%s = %s", strbuf, valbuf);
if(!strcmp(strbuf, "antialias")) {
......@@ -1029,6 +1085,8 @@ void Game::LoadConfig() {
gameConf.chkIgnoreDeckChanges = atoi(valbuf);
} else if(!strcmp(strbuf, "default_ot")) {
gameConf.defaultOT = atoi(valbuf);
} else if(!strcmp(strbuf, "enable_bot_mode")) {
gameConf.enable_bot_mode = atoi(valbuf);
} else {
// options allowing multiple words
sscanf(linebuf, "%s = %240[^\n]", strbuf, valbuf);
......@@ -1088,6 +1146,7 @@ void Game::SaveConfig() {
fprintf(fp, "auto_search_limit = %d\n", gameConf.auto_search_limit);
fprintf(fp, "ignore_deck_changes = %d\n", ((mainGame->chkIgnoreDeckChanges->isChecked()) ? 1 : 0));
fprintf(fp, "default_ot = %d\n", gameConf.defaultOT);
fprintf(fp, "enable_bot_mode = %d\n", gameConf.enable_bot_mode);
fclose(fp);
}
void Game::ShowCardInfo(int code) {
......
......@@ -46,6 +46,7 @@ struct Config {
int auto_search_limit;
int chkIgnoreDeckChanges;
int defaultOT;
int enable_bot_mode;
};
struct DuelInfo {
......@@ -73,6 +74,14 @@ struct DuelInfo {
unsigned short time_left[2];
};
struct BotInfo {
wchar_t name[256];
wchar_t command[256];
wchar_t desc[256];
bool support_master_rule_3;
bool support_new_master_rule;
};
struct FadingUnit {
bool signalAction;
bool isFadein;
......@@ -103,6 +112,7 @@ public:
void RefreshDeck(irr::gui::IGUIComboBox* cbDeck);
void RefreshReplay();
void RefreshSingleplay();
void RefreshBot();
void DrawSelectionLine(irr::video::S3DVertex* vec, bool strip, int width, float* cv);
void DrawBackGround();
void DrawLinkedZones(ClientCard* pcard);
......@@ -153,6 +163,7 @@ public:
std::list<FadingUnit> fadingList;
std::vector<int> logParam;
std::wstring chatMsg[8];
std::vector<BotInfo> botInfo;
int hideChatTimer;
bool hideChat;
......@@ -233,7 +244,7 @@ public:
//main menu
irr::gui::IGUIWindow* wMainMenu;
irr::gui::IGUIButton* btnLanMode;
irr::gui::IGUIButton* btnServerMode;
irr::gui::IGUIButton* btnSingleMode;
irr::gui::IGUIButton* btnReplayMode;
irr::gui::IGUIButton* btnTestMode;
irr::gui::IGUIButton* btnDeckEdit;
......@@ -288,6 +299,14 @@ public:
irr::gui::IGUIEditBox* ebRepStartTurn;
//single play
irr::gui::IGUIWindow* wSinglePlay;
irr::gui::IGUIListBox* lstBotList;
irr::gui::IGUIStaticText* stBotInfo;
irr::gui::IGUIButton* btnStartBot;
irr::gui::IGUIButton* btnBotCancel;
irr::gui::IGUICheckBox* chkBotOldRule;
irr::gui::IGUICheckBox* chkBotHand;
irr::gui::IGUICheckBox* chkBotNoCheckDeck;
irr::gui::IGUICheckBox* chkBotNoShuffleDeck;
irr::gui::IGUIListBox* lstSinglePlayList;
irr::gui::IGUIStaticText* stSinglePlayInfo;
irr::gui::IGUIButton* btnLoadSinglePlay;
......@@ -582,6 +601,9 @@ extern HostInfo game_info;
#define BUTTON_REPLAY_SWAP 325
#define BUTTON_REPLAY_SAVE 330
#define BUTTON_REPLAY_CANCEL 331
#define BUTTON_BOT_START 340
#define LISTBOX_BOT_LIST 341
#define CHECKBOX_BOT_OLD_RULE 342
#define LISTBOX_SINGLEPLAY_LIST 350
#define BUTTON_LOAD_SINGLEPLAY 351
#define BUTTON_CANCEL_SINGLEPLAY 352
......
......@@ -11,6 +11,7 @@ int enable_log = 0;
bool exit_on_return = false;
bool open_file = false;
wchar_t open_file_name[256] = L"";
bool bot_mode = false;
void GetParameter(char* param, const char* arg) {
#ifdef _WIN32
......@@ -200,7 +201,7 @@ int main(int argc, char* argv[]) {
open_file = true;
GetParameterW(open_file_name, &argv[i + 1][0]);
}
ClickButton(ygo::mainGame->btnServerMode);
ClickButton(ygo::mainGame->btnSingleMode);
if(open_file)
ClickButton(ygo::mainGame->btnLoadSinglePlay);
break;
......
......@@ -46,6 +46,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_JOIN_HOST: {
bot_mode = false;
char ip[20];
const wchar_t* pstr = mainGame->ebJoinHost->getText();
BufferIO::CopyWStr(pstr, ip, 16);
......@@ -103,6 +104,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_HOST_CONFIRM: {
bot_mode = false;
BufferIO::CopyWStr(mainGame->ebServerName->getText(), mainGame->gameConf.gamename, 20);
if(!NetServer::StartServer(mainGame->gameConf.serverport))
break;
......@@ -167,8 +169,13 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
mainGame->btnCreateHost->setEnabled(true);
mainGame->btnJoinHost->setEnabled(true);
mainGame->btnJoinCancel->setEnabled(true);
mainGame->btnStartBot->setEnabled(true);
mainGame->btnBotCancel->setEnabled(true);
mainGame->HideElement(mainGame->wHostPrepare);
mainGame->ShowElement(mainGame->wLanWindow);
if(bot_mode)
mainGame->ShowElement(mainGame->wSinglePlay);
else
mainGame->ShowElement(mainGame->wLanWindow);
mainGame->wChat->setVisible(false);
if(exit_on_return)
mainGame->device->closeDevice();
......@@ -185,6 +192,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
mainGame->HideElement(mainGame->wMainMenu);
mainGame->ShowElement(mainGame->wSinglePlay);
mainGame->RefreshSingleplay();
mainGame->RefreshBot();
break;
}
case BUTTON_LOAD_REPLAY: {
......@@ -227,6 +235,58 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
mainGame->ShowElement(mainGame->wMainMenu);
break;
}
case BUTTON_BOT_START: {
int sel = mainGame->lstBotList->getSelected();
if(sel == -1)
break;
bot_mode = true;
#ifdef _WIN32
if(!NetServer::StartServer(mainGame->gameConf.serverport))
break;
if(!DuelClient::StartClient(0x7f000001, mainGame->gameConf.serverport)) {
NetServer::StopServer();
break;
}
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
wchar_t cmd[MAX_PATH];
int flag = 0;
flag += (mainGame->chkBotHand->isChecked() ? 0x1 : 0);
myswprintf(cmd, L"Bot.exe \"%ls\" %d %d", mainGame->botInfo[sel].command, flag, mainGame->gameConf.serverport);
if(!CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
{
NetServer::StopServer();
break;
}
#else
if(fork() == 0) {
usleep(100000);
char arg1[512];
BufferIO::EncodeUTF8(mainGame->botInfo[sel].command, arg1);
int flag = 0;
flag += (mainGame->chkBotHand->isChecked() ? 0x1 : 0);
char arg2[8];
sprintf(arg2, "%d", flag);
char arg3[8];
sprintf(arg3, "%d", mainGame->gameConf.serverport);
execl("./bot", "bot", arg1, arg2, arg3, NULL);
exit(0);
} else {
if(!NetServer::StartServer(mainGame->gameConf.serverport))
break;
if(!DuelClient::StartClient(0x7f000001, mainGame->gameConf.serverport)) {
NetServer::StopServer();
break;
}
}
#endif
mainGame->btnStartBot->setEnabled(false);
mainGame->btnBotCancel->setEnabled(false);
break;
}
case BUTTON_LOAD_SINGLEPLAY: {
if(!open_file && mainGame->lstSinglePlayList->getSelected() == -1)
break;
......@@ -317,6 +377,13 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
mainGame->SetStaticText(mainGame->stReplayInfo, 180, mainGame->guiFont, (wchar_t*)repinfo.c_str());
break;
}
case LISTBOX_BOT_LIST: {
int sel = mainGame->lstBotList->getSelected();
if(sel == -1)
break;
mainGame->SetStaticText(mainGame->stBotInfo, 200, mainGame->guiFont, mainGame->botInfo[sel].desc);
break;
}
}
break;
}
......@@ -341,6 +408,10 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
}
break;
}
case CHECKBOX_BOT_OLD_RULE: {
mainGame->RefreshBot();
break;
}
}
break;
}
......
......@@ -435,6 +435,13 @@ bool ReplayMode::ReplayAnalyze(char* msg, unsigned int len) {
DuelClient::ClientAnalyze(offset, pbuf - offset);
break;
}
case MSG_CONFIRM_EXTRATOP: {
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);
......@@ -455,6 +462,13 @@ bool ReplayMode::ReplayAnalyze(char* msg, unsigned int len) {
DuelClient::ClientAnalyze(offset, pbuf - offset);
break;
}
case MSG_SHUFFLE_EXTRA: {
/*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);
......
......@@ -952,6 +952,16 @@ int SingleDuel::Analyze(char* msgbuffer, unsigned int len) {
#endif
break;
}
case MSG_CONFIRM_EXTRATOP: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
pbuf += count * 7;
NetServer::SendBufferToPlayer(players[0], STOC_GAME_MSG, offset, pbuf - offset);
NetServer::ReSendToPlayer(players[1]);
for (auto oit = observers.begin(); oit != observers.end(); ++oit)
NetServer::ReSendToPlayer(*oit);
break;
}
case MSG_CONFIRM_CARDS: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
......@@ -999,6 +1009,18 @@ int SingleDuel::Analyze(char* msgbuffer, unsigned int len) {
RefreshHand(player, 0x781fff, 0);
break;
}
case MSG_SHUFFLE_EXTRA: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
NetServer::SendBufferToPlayer(players[player], STOC_GAME_MSG, offset, (pbuf - offset) + count * 4);
for (int i = 0; i < count; ++i)
BufferIO::WriteInt32(pbuf, 0);
NetServer::SendBufferToPlayer(players[1 - player], STOC_GAME_MSG, offset, pbuf - offset);
for (auto oit = observers.begin(); oit != observers.end(); ++oit)
NetServer::ReSendToPlayer(*oit);
RefreshExtra(player);
break;
}
case MSG_REFRESH_DECK: {
pbuf++;
NetServer::SendBufferToPlayer(players[0], STOC_GAME_MSG, offset, pbuf - offset);
......
......@@ -355,6 +355,13 @@ bool SingleMode::SinglePlayAnalyze(char* msg, unsigned int len) {
DuelClient::ClientAnalyze(offset, pbuf - offset);
break;
}
case MSG_CONFIRM_EXTRATOP: {
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);
......@@ -375,6 +382,13 @@ bool SingleMode::SinglePlayAnalyze(char* msg, unsigned int len) {
DuelClient::ClientAnalyze(offset, pbuf - offset);
break;
}
case MSG_SHUFFLE_EXTRA: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
pbuf += count * 4;
DuelClient::ClientAnalyze(offset, pbuf - offset);
break;
}
case MSG_REFRESH_DECK: {
pbuf++;
DuelClient::ClientAnalyze(offset, pbuf - offset);
......
......@@ -872,6 +872,18 @@ int TagDuel::Analyze(char* msgbuffer, unsigned int len) {
#endif
break;
}
case MSG_CONFIRM_EXTRATOP: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
pbuf += count * 7;
NetServer::SendBufferToPlayer(players[0], STOC_GAME_MSG, offset, pbuf - offset);
NetServer::ReSendToPlayer(players[1]);
NetServer::ReSendToPlayer(players[2]);
NetServer::ReSendToPlayer(players[3]);
for (auto oit = observers.begin(); oit != observers.end(); ++oit)
NetServer::ReSendToPlayer(*oit);
break;
}
case MSG_CONFIRM_CARDS: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
......@@ -925,6 +937,20 @@ int TagDuel::Analyze(char* msgbuffer, unsigned int len) {
RefreshHand(player, 0x781fff, 0);
break;
}
case MSG_SHUFFLE_EXTRA: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
NetServer::SendBufferToPlayer(players[player], STOC_GAME_MSG, offset, (pbuf - offset) + count * 4);
NetServer::ReSendToPlayer(players[player * 2 + 1]);
for(int i = 0; i < count; ++i)
BufferIO::WriteInt32(pbuf, 0);
for (int p = (1 - player) * 2, i = 0; i < 2; i++, p++)
NetServer::SendBufferToPlayer(players[p], STOC_GAME_MSG, offset, pbuf - offset);
for(auto oit = observers.begin(); oit != observers.end(); ++oit)
NetServer::ReSendToPlayer(*oit);
RefreshExtra(player);
break;
}
case MSG_REFRESH_DECK: {
pbuf++;
NetServer::SendBufferToPlayer(players[0], STOC_GAME_MSG, offset, pbuf - offset);
......
......@@ -215,10 +215,13 @@ void field::add_card(uint8 playerid, card* pcard, uint8 location, uint8 sequence
break;
}
case LOCATION_EXTRA: {
player[playerid].list_extra.push_back(pcard);
pcard->current.sequence = player[playerid].list_extra.size() - 1;
if(player[playerid].extra_p_count == 0 || (pcard->data.type & TYPE_PENDULUM) && (pcard->sendto_param.position & POS_FACEUP))
player[playerid].list_extra.push_back(pcard);
else
player[playerid].list_extra.insert(player[playerid].list_extra.end() - player[playerid].extra_p_count, pcard);
if((pcard->data.type & TYPE_PENDULUM) && (pcard->sendto_param.position & POS_FACEUP))
++player[playerid].extra_p_count;
reset_sequence(playerid, LOCATION_EXTRA);
break;
}
}
......@@ -825,9 +828,9 @@ void field::get_cards_in_zone(card_set* cset, uint32 zone, int32 playerid, int32
}
}
void field::shuffle(uint8 playerid, uint8 location) {
if(!(location & (LOCATION_HAND | LOCATION_DECK)))
if(!(location & (LOCATION_HAND | LOCATION_DECK | LOCATION_EXTRA)))
return;
card_vector& svector = (location == LOCATION_HAND) ? player[playerid].list_hand : player[playerid].list_main;
card_vector& svector = (location == LOCATION_HAND) ? player[playerid].list_hand : (location == LOCATION_DECK) ? player[playerid].list_main : player[playerid].list_extra;
if(svector.size() == 0)
return;
if(location == LOCATION_HAND) {
......@@ -841,8 +844,11 @@ void field::shuffle(uint8 playerid, uint8 location) {
}
}
if(location == LOCATION_HAND || !(core.duel_options & DUEL_PSEUDO_SHUFFLE)) {
if(svector.size() > 1) {
uint32 i = 0, s = svector.size(), r;
uint32 s = svector.size();
if(location == LOCATION_EXTRA)
s = s - player[playerid].extra_p_count;
if(s > 1) {
uint32 i = 0, r;
for(i = 0; i < s - 1; ++i) {
r = pduel->get_next_integer(i, s - 1);
card* t = svector[i];
......@@ -852,13 +858,14 @@ void field::shuffle(uint8 playerid, uint8 location) {
reset_sequence(playerid, location);
}
}
if(location == LOCATION_HAND) {
pduel->write_buffer8(MSG_SHUFFLE_HAND);
if(location == LOCATION_HAND || location == LOCATION_EXTRA) {
pduel->write_buffer8((location == LOCATION_HAND) ? MSG_SHUFFLE_HAND : MSG_SHUFFLE_EXTRA);
pduel->write_buffer8(playerid);
pduel->write_buffer8(player[playerid].list_hand.size());
pduel->write_buffer8(svector.size());
for(auto cit = svector.begin(); cit != svector.end(); ++cit)
pduel->write_buffer32((*cit)->data.code);
core.shuffle_hand_check[playerid] = FALSE;
if(location == LOCATION_HAND)
core.shuffle_hand_check[playerid] = FALSE;
} else {
pduel->write_buffer8(MSG_SHUFFLE_DECK);
pduel->write_buffer8(playerid);
......
......@@ -844,8 +844,10 @@ public:
#define MSG_SHUFFLE_SET_CARD 36
#define MSG_REVERSE_DECK 37
#define MSG_DECK_TOP 38
#define MSG_SHUFFLE_EXTRA 39
#define MSG_NEW_TURN 40
#define MSG_NEW_PHASE 41
#define MSG_CONFIRM_EXTRATOP 42
#define MSG_MOVE 50
#define MSG_POS_CHANGE 53
#define MSG_SET 54
......
......@@ -419,6 +419,7 @@ static const struct luaL_Reg duellib[] = {
{ "SetChainLimitTillChainEnd", scriptlib::duel_set_chain_limit_p },
{ "GetChainMaterial", scriptlib::duel_get_chain_material },
{ "ConfirmDecktop", scriptlib::duel_confirm_decktop },
{ "ConfirmExtratop", scriptlib::duel_confirm_extratop },
{ "ConfirmCards", scriptlib::duel_confirm_cards },
{ "SortDecktop", scriptlib::duel_sort_decktop },
{ "CheckEvent", scriptlib::duel_check_event },
......@@ -442,6 +443,7 @@ static const struct luaL_Reg duellib[] = {
{ "DiscardHand", scriptlib::duel_discard_hand },
{ "DisableShuffleCheck", scriptlib::duel_disable_shuffle_check },
{ "ShuffleDeck", scriptlib::duel_shuffle_deck },
{ "ShuffleExtra", scriptlib::duel_shuffle_extra },
{ "ShuffleHand", scriptlib::duel_shuffle_hand },
{ "ShuffleSetCard", scriptlib::duel_shuffle_setcard },
{ "ChangeAttacker", scriptlib::duel_change_attacker },
......@@ -485,6 +487,7 @@ static const struct luaL_Reg duellib[] = {
{ "GetFieldGroup", scriptlib::duel_get_field_group },
{ "GetFieldGroupCount", scriptlib::duel_get_field_group_count },
{ "GetDecktopGroup", scriptlib::duel_get_decktop_group },
{ "GetExtraTopGroup", scriptlib::duel_get_extratop_group },
{ "GetMatchingGroup", scriptlib::duel_get_matching_group },
{ "GetMatchingGroupCount", scriptlib::duel_get_matching_count },
{ "GetFirstMatchingCard", scriptlib::duel_get_first_matching_card },
......
......@@ -945,6 +945,28 @@ int32 scriptlib::duel_confirm_decktop(lua_State *L) {
pduel->game_field->add_process(PROCESSOR_WAIT, 0, 0, 0, 0, 0);
return lua_yield(L, 0);
}
int32 scriptlib::duel_confirm_extratop(lua_State *L) {
check_param_count(L, 2);
int32 playerid = lua_tonumberint(L, 1);
if(playerid != 0 && playerid != 1)
return 0;
uint32 count = lua_tonumberint(L, 2);
duel* pduel = interpreter::get_duel_info(L);
if(count >= pduel->game_field->player[playerid].list_extra.size() - pduel->game_field->player[playerid].extra_p_count)
count = pduel->game_field->player[playerid].list_extra.size() - pduel->game_field->player[playerid].extra_p_count;
auto cit = pduel->game_field->player[playerid].list_extra.rbegin() + pduel->game_field->player[playerid].extra_p_count;
pduel->write_buffer8(MSG_CONFIRM_EXTRATOP);
pduel->write_buffer8(playerid);
pduel->write_buffer8(count);
for(uint32 i = 0; i < count && cit != pduel->game_field->player[playerid].list_extra.rend(); ++i, ++cit) {
pduel->write_buffer32((*cit)->data.code);
pduel->write_buffer8((*cit)->current.controler);
pduel->write_buffer8((*cit)->current.location);
pduel->write_buffer8((*cit)->current.sequence);
}
pduel->game_field->add_process(PROCESSOR_WAIT, 0, 0, 0, 0, 0);
return lua_yield(L, 0);
}
int32 scriptlib::duel_confirm_cards(lua_State *L) {
check_param_count(L, 2);
int32 playerid = lua_tonumberint(L, 1);
......@@ -1427,6 +1449,15 @@ int32 scriptlib::duel_shuffle_deck(lua_State *L) {
pduel->game_field->shuffle(playerid, LOCATION_DECK);
return 0;
}
int32 scriptlib::duel_shuffle_extra(lua_State *L) {
check_param_count(L, 1);
uint32 playerid = lua_tonumberint(L, 1);
if (playerid != 0 && playerid != 1)
return 0;
duel* pduel = interpreter::get_duel_info(L);
pduel->game_field->shuffle(playerid, LOCATION_EXTRA);
return 0;
}
int32 scriptlib::duel_shuffle_hand(lua_State *L) {
check_param_count(L, 1);
uint32 playerid = lua_tonumberint(L, 1);
......@@ -2187,6 +2218,23 @@ int32 scriptlib::duel_get_decktop_group(lua_State *L) {
interpreter::group2value(L, pgroup);
return 1;
}
/**
* \brief Duel.GetExtraTopGroup
* \param playerid, count
* \return Group
*/
int32 scriptlib::duel_get_extratop_group(lua_State *L) {
check_param_count(L, 2);
uint32 playerid = lua_tonumberint(L, 1);
uint32 count = lua_tonumberint(L, 2);
duel* pduel = interpreter::get_duel_info(L);
group* pgroup = pduel->new_group();
auto cit = pduel->game_field->player[playerid].list_extra.rbegin() + pduel->game_field->player[playerid].extra_p_count;
for(uint32 i = 0; i < count && cit != pduel->game_field->player[playerid].list_extra.rend(); ++i, ++cit)
pgroup->container.insert(*cit);
interpreter::group2value(L, pgroup);
return 1;
}
/**
* \brief Duel.GetMatchingGroup
* \param filter_func, self, location1, location2, exception card, (extraargs...)
......
......@@ -410,6 +410,7 @@ public:
static int32 duel_set_chain_limit_p(lua_State *L);
static int32 duel_get_chain_material(lua_State *L);
static int32 duel_confirm_decktop(lua_State *L);
static int32 duel_confirm_extratop(lua_State *L);
static int32 duel_confirm_cards(lua_State *L);
static int32 duel_sort_decktop(lua_State *L);
static int32 duel_check_event(lua_State *L);
......@@ -434,6 +435,7 @@ public:
static int32 duel_discard_hand(lua_State *L);
static int32 duel_disable_shuffle_check(lua_State *L);
static int32 duel_shuffle_deck(lua_State *L);
static int32 duel_shuffle_extra(lua_State *L);
static int32 duel_shuffle_hand(lua_State *L);
static int32 duel_shuffle_setcard(lua_State *L);
static int32 duel_change_attacker(lua_State *L);
......@@ -478,6 +480,7 @@ public:
static int32 duel_get_field_group(lua_State *L);
static int32 duel_get_field_group_count(lua_State *L);
static int32 duel_get_decktop_group(lua_State *L);
static int32 duel_get_extratop_group(lua_State *L);
static int32 duel_get_matching_group(lua_State *L);
static int32 duel_get_matching_count(lua_State *L);
static int32 duel_get_first_matching_card(lua_State *L);
......
......@@ -523,6 +523,7 @@
!counter 0x43 缺陷指示物
!counter 0x44 指示物(弹带城壁龙)
!counter 0x1045 鳞粉指示物
!counter 0x46 指示物(刚鬼死斗)
#setnames, using tab for comment
!setname 0x1 正义盟军 AOJ
!setname 0x2 次世代 ジェネクス
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment