Commit 82c273f8 authored by argon.sun's avatar argon.sun

single

parent a1619691
......@@ -326,11 +326,11 @@ void Game::DrawMisc() {
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.is_tag || !dInfo.tag_player[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.is_tag || !dInfo.tag_player[1]) {
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 {
......
......@@ -326,13 +326,13 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
}
mainGame->gMutex.Lock();
if(pkt->info.mode == 2) {
mainGame->dInfo.is_tag = true;
mainGame->dInfo.isTag = true;
mainGame->chkHostPrepReady[2]->setVisible(true);
mainGame->chkHostPrepReady[3]->setVisible(true);
mainGame->stHostPrepDuelist[2]->setVisible(true);
mainGame->stHostPrepDuelist[3]->setVisible(true);
} else {
mainGame->dInfo.is_tag = false;
mainGame->dInfo.isTag = false;
mainGame->chkHostPrepReady[2]->setVisible(false);
mainGame->chkHostPrepReady[3]->setVisible(false);
mainGame->stHostPrepDuelist[2]->setVisible(false);
......@@ -368,7 +368,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
}
case STOC_TYPE_CHANGE: {
STOC_TypeChange* pkt = (STOC_TypeChange*)pdata;
if(!mainGame->dInfo.is_tag) {
if(!mainGame->dInfo.isTag) {
selftype = pkt->type & 0xf;
is_host = (pkt->type >> 4) & 0xf;
mainGame->btnHostPrepKick[2]->setVisible(false);
......@@ -449,7 +449,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
mainGame->wChat->setVisible(true);
mainGame->imgCard->setImage(imageManager.tCover);
mainGame->device->setEventReceiver(&mainGame->dField);
if(!mainGame->dInfo.is_tag) {
if(!mainGame->dInfo.isTag) {
if(selftype > 1) {
mainGame->dInfo.player_type = 7;
mainGame->btnLeaveGame->setText(dataManager.GetSysString(1350));
......@@ -544,7 +544,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
BufferIO::CopyWStr(pkt->msg, msg, 256);
msg[(len - 3) / 2] = 0;
mainGame->gMutex.Lock();
if(!mainGame->dInfo.is_tag) {
if(!mainGame->dInfo.isTag) {
if(mainGame->dInfo.isStarted)
mainGame->AddChatMsg(msg, mainGame->LocalPlayer(pkt->player));
else
......@@ -600,7 +600,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
break;
wchar_t name[20];
BufferIO::CopyWStr(pkt->name, name, 20);
if(mainGame->dInfo.is_tag) {
if(mainGame->dInfo.isTag) {
if(pkt->pos == 0)
BufferIO::CopyWStr(pkt->name, mainGame->dInfo.hostname, 20);
else if(pkt->pos == 1)
......@@ -853,7 +853,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
mainGame->dInfo.isFirst = (playertype & 0xf) ? false : true;
if(playertype & 0xf0)
mainGame->dInfo.player_type = 7;
if(mainGame->dInfo.is_tag) {
if(mainGame->dInfo.isTag) {
if(mainGame->dInfo.isFirst)
mainGame->dInfo.tag_player[1] = true;
else
......@@ -1675,11 +1675,11 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
case MSG_NEW_TURN: {
int player = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf));
mainGame->dInfo.turn++;
if(!mainGame->dInfo.is_tag && mainGame->dInfo.turn == 5 && !mainGame->dInfo.isReplay && mainGame->dInfo.player_type < 7) {
if(!mainGame->dInfo.isTag && mainGame->dInfo.turn == 5 && !mainGame->dInfo.isReplay && mainGame->dInfo.player_type < 7) {
mainGame->btnLeaveGame->setText(dataManager.GetSysString(1351));
mainGame->btnLeaveGame->setVisible(true);
}
if(mainGame->dInfo.is_tag && mainGame->dInfo.turn != 1) {
if(mainGame->dInfo.isTag && mainGame->dInfo.turn != 1) {
if(player == 0)
mainGame->dInfo.tag_player[0] = !mainGame->dInfo.tag_player[0];
else
......@@ -2719,6 +2719,76 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
mainGame->WaitFrameSignal(5);
break;
}
case MSG_RELOAD_FIELD: {
mainGame->gMutex.Lock();
mainGame->dField.Clear();
int val = 0;
for(int p = 0; p < 2; ++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, 0);
ccard->position = BufferIO::ReadInt8(pbuf);
mainGame->dField.GetCardLocation(ccard, &ccard->curPos, &ccard->curRot);
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);
mainGame->gMutex.Unlock();
xcard->overlayTarget = ccard;
xcard->location = 0x80;
xcard->sequence = ccard->overlayed.size() - 1;
mainGame->dField.GetCardLocation(xcard, &xcard->curPos, &xcard->curRot);
}
}
}
}
for(int seq = 0; seq < 6; ++seq) {
val = BufferIO::ReadInt8(pbuf);
if(val) {
ClientCard* ccard = new ClientCard;
mainGame->dField.AddCard(ccard, p, LOCATION_SZONE, seq);
ccard->position = BufferIO::ReadInt8(pbuf);
mainGame->dField.GetCardLocation(ccard, &ccard->curPos, &ccard->curRot);
}
}
val = BufferIO::ReadInt8(pbuf);
for(int seq = 0; seq < val; ++seq) {
ClientCard* ccard = new ClientCard;
mainGame->dField.AddCard(ccard, p, LOCATION_DECK, seq);
mainGame->dField.GetCardLocation(ccard, &ccard->curPos, &ccard->curRot);
}
val = BufferIO::ReadInt8(pbuf);
for(int seq = 0; seq < val; ++seq) {
ClientCard* ccard = new ClientCard;
mainGame->dField.AddCard(ccard, p, LOCATION_HAND, seq);
mainGame->dField.GetCardLocation(ccard, &ccard->curPos, &ccard->curRot);
}
val = BufferIO::ReadInt8(pbuf);
for(int seq = 0; seq < val; ++seq) {
ClientCard* ccard = new ClientCard;
mainGame->dField.AddCard(ccard, p, LOCATION_EXTRA, seq);
mainGame->dField.GetCardLocation(ccard, &ccard->curPos, &ccard->curRot);
}
val = BufferIO::ReadInt8(pbuf);
for(int seq = 0; seq < val; ++seq) {
ClientCard* ccard = new ClientCard;
mainGame->dField.AddCard(ccard, p, LOCATION_GRAVE, seq);
mainGame->dField.GetCardLocation(ccard, &ccard->curPos, &ccard->curRot);
}
val = BufferIO::ReadInt8(pbuf);
for(int seq = 0; seq < val; ++seq) {
ClientCard* ccard = new ClientCard;
mainGame->dField.AddCard(ccard, p, LOCATION_REMOVED, seq);
mainGame->dField.GetCardLocation(ccard, &ccard->curPos, &ccard->curRot);
}
}
mainGame->gMutex.Unlock();
break;
}
}
return true;
}
......@@ -2768,8 +2838,12 @@ void DuelClient::SendResponse() {
break;
}
}
mainGame->dInfo.time_player = 2;
SendBufferToServer(CTOS_RESPONSE, response_buf, response_len);
if(mainGame->dInfo.isSingleMode) {
mainGame->singleSignal.Set();
} else {
mainGame->dInfo.time_player = 2;
SendBufferToServer(CTOS_RESPONSE, response_buf, response_len);
}
}
void DuelClient::BeginRefreshHost() {
if(is_refreshing)
......
......@@ -776,7 +776,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
unsigned short msgbuf[256];
if(mainGame->dInfo.isStarted) {
if(mainGame->dInfo.player_type < 7) {
if(mainGame->dInfo.is_tag && (mainGame->dInfo.player_type % 2))
if(mainGame->dInfo.isTag && (mainGame->dInfo.player_type % 2))
mainGame->AddChatMsg((wchar_t*)input, 2);
else
mainGame->AddChatMsg((wchar_t*)input, 0);
......
......@@ -30,8 +30,9 @@ struct DuelInfo {
bool isStarted;
bool isReplay;
bool isFirst;
bool isTag;
bool isSingleMode;
bool is_shuffling;
bool is_tag;
bool tag_player[2];
int lp[2];
int turn;
......@@ -99,6 +100,7 @@ public:
Signal frameSignal;
Signal actionSignal;
Signal replaySignal;
Signal singleSignal;
Config gameConf;
DuelInfo dInfo;
......
......@@ -4,6 +4,7 @@
#include "duelclient.h"
#include "deck_manager.h"
#include "replay_mode.h"
#include "single_mode.h"
#include "image_manager.h"
#include "game.h"
......@@ -168,6 +169,9 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_LOAD_SINGLEPLAY: {
if(mainGame->lstSinglePlayList->getSelected() == -1)
break;
SingleMode::StartPlay();
break;
}
case BUTTON_CANCEL_SINGLEPLAY: {
......@@ -300,7 +304,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
unsigned short msgbuf[256];
if(mainGame->dInfo.isStarted) {
if(mainGame->dInfo.player_type < 7) {
if(mainGame->dInfo.is_tag && (mainGame->dInfo.player_type % 2))
if(mainGame->dInfo.isTag && (mainGame->dInfo.player_type % 2))
mainGame->AddChatMsg((wchar_t*)input, 2);
else
mainGame->AddChatMsg((wchar_t*)input, 0);
......
......@@ -61,7 +61,7 @@ int ReplayMode::ReplayThread(void* param) {
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.is_tag = true;
mainGame->dInfo.isTag = true;
} else {
cur_replay.ReadData(mainGame->dInfo.hostname, 40);
cur_replay.ReadData(mainGame->dInfo.clientname, 40);
......
......@@ -296,6 +296,7 @@ void SingleDuel::StartDuel(DuelPlayer* dp) {
if(!ready[0] || !ready[1])
return;
NetServer::StopListen();
//NetServer::StopBroadcast();
NetServer::SendPacketToPlayer(players[0], STOC_DUEL_START);
NetServer::ReSendToPlayer(players[1]);
for(auto oit = observers.begin(); oit != observers.end(); ++oit) {
......
This diff is collapsed.
......@@ -11,12 +11,12 @@ namespace ygo {
class SingleMode {
private:
static long pduel;
static bool is_closing;
static wchar_t event_string[256];
public:
static bool StartPlay();
static void StopReplay(bool is_exiting = false);
static bool ReadReplayResponse();
static void StopPlay(bool is_exiting = false);
static int SinglePlayThread(void* param);
static bool SinglePlayAnalyze(char* msg, unsigned int len);
......
......@@ -262,6 +262,7 @@ void TagDuel::StartDuel(DuelPlayer* dp) {
if(!ready[0] || !ready[1] || !ready[2] || !ready[3])
return;
NetServer::StopListen();
//NetServer::StopBroadcast();
for(int i = 0; i < 4; ++i)
NetServer::SendPacketToPlayer(players[i], STOC_DUEL_START);
for(auto oit = observers.begin(); oit != observers.end(); ++oit) {
......
......@@ -31,6 +31,21 @@ duel::~duel() {
delete lua;
delete game_field;
}
void duel::clear() {
for(std::set<card*>::iterator cit = cards.begin(); cit != cards.end(); ++cit)
delete *cit;
for(std::set<group*>::iterator git = groups.begin(); git != groups.end(); ++git)
delete *git;
for(std::set<effect*>::iterator eit = effects.begin(); eit != effects.end(); ++eit)
delete *eit;
delete lua;
delete game_field;
lua = new interpreter(this);
game_field = new field(this);
game_field->temp_card = new_card(0);
bufferlen = 0;
bufferp = buffer;
}
card* duel::new_card(uint32 code) {
card* pcard = new card();
cards.insert(pcard);
......
......@@ -39,7 +39,8 @@ public:
std::set<effect*> uncopy;
duel();
~duel();
void clear();
card* new_card(uint32 code);
group* new_group(card* pcard = 0);
effect* new_effect();
......
......@@ -84,6 +84,37 @@ field::field(duel* pduel) {
field::~field() {
}
void field::reload_field_info() {
pduel->write_buffer8(MSG_RELOAD_FIELD);
card* pcard;
for(int playerid = 0; playerid < 2; ++playerid) {
for(uint32 i = 0; i < 5; ++i) {
pcard = player[playerid].list_mzone[i];
if(pcard) {
pduel->write_buffer8(1);
pduel->write_buffer8(pcard->current.position);
pduel->write_buffer8(pcard->xyz_materials.size());
} else {
pduel->write_buffer8(0);
}
}
for(uint32 i = 0; i < 6; ++i) {
pcard = player[playerid].list_szone[i];
if(pcard) {
pduel->write_buffer8(1);
pduel->write_buffer8(pcard->current.position);
} else {
pduel->write_buffer8(0);
}
}
pduel->write_buffer8(player[playerid].list_main.size());
pduel->write_buffer8(player[playerid].list_hand.size());
pduel->write_buffer8(player[playerid].list_grave.size());
pduel->write_buffer8(player[playerid].list_remove.size());
pduel->write_buffer8(player[playerid].list_extra.size());
}
}
void field::add_card(uint8 playerid, card* pcard, uint8 location, uint8 sequence) {
if (pcard->current.location != 0)
return;
......
......@@ -284,7 +284,8 @@ public:
static int32 field_used_count[32];
field(duel* pduel);
~field();
void reload_field_info();
void add_card(uint8 playerid, card* pcard, uint8 location, uint8 sequence);
void remove_card(card* pcard);
void move_card(uint8 playerid, card* pcard, uint8 location, uint8 sequence);
......@@ -728,4 +729,5 @@ public:
#define MSG_ANNOUNCE_NUMBER 143
#define MSG_CARD_HINT 160
#define MSG_TAG_SWAP 161
#define MSG_RELOAD_FIELD 162
#endif /* FIELD_H_ */
......@@ -83,6 +83,11 @@ int32 scriptlib::debug_set_duel_info(lua_State *L) {
return 0;
}
int32 scriptlib::debug_reload_field_begin(lua_State *L) {
duel* pduel = interpreter::get_duel_info(L);
pduel->clear();
}
int32 scriptlib::debug_reload_field_end(lua_State *L) {
duel* pduel = interpreter::get_duel_info(L);
pduel->game_field->reload_field_info();
return 0;
}
......@@ -282,6 +282,37 @@ extern "C" DECL_DLLEXPORT int32 query_field_card(ptr pduel, uint8 playerid, uint
}
return ct;
}
extern "C" DECL_DLLEXPORT int32 query_field_info(ptr pduel, byte* buf) {
duel* ptduel = (duel*)pduel;
*buf++ = MSG_RELOAD_FIELD;
card* pcard;
for(int playerid = 0; playerid < 2; ++playerid) {
for(uint32 i = 0; i < 5; ++i) {
pcard = ptduel->game_field->player[playerid].list_mzone[i];
if(pcard) {
*buf++ = 1;
*buf++ = pcard->current.position;
*buf++ = pcard->xyz_materials.size();
} else {
*buf++ = 0;
}
}
for(uint32 i = 0; i < 6; ++i) {
pcard = ptduel->game_field->player[playerid].list_szone[i];
if(pcard) {
*buf++ = 1;
*buf++ = pcard->current.position;
} else {
*buf++ = 0;
}
}
*buf++ = ptduel->game_field->player[playerid].list_main.size();
*buf++ = ptduel->game_field->player[playerid].list_hand.size();
*buf++ = ptduel->game_field->player[playerid].list_grave.size();
*buf++ = ptduel->game_field->player[playerid].list_remove.size();
*buf++ = ptduel->game_field->player[playerid].list_extra.size();
}
}
extern "C" DECL_DLLEXPORT void set_responsei(ptr pduel, int32 value) {
((duel*)pduel)->set_responsei(value);
}
......
......@@ -47,6 +47,7 @@ extern "C" DECL_DLLEXPORT void new_tag_card(ptr pduel, uint32 code, uint8 owner,
extern "C" DECL_DLLEXPORT int32 query_card(ptr pduel, uint8 playerid, uint8 location, uint8 sequence, int32 query_flag, byte* buf, int32 use_cache);
extern "C" DECL_DLLEXPORT int32 query_field_count(ptr pduel, uint8 playerid, uint8 location);
extern "C" DECL_DLLEXPORT int32 query_field_card(ptr pduel, uint8 playerid, uint8 location, int32 query_flag, byte* buf, int32 use_cache);
extern "C" DECL_DLLEXPORT int32 query_field_info(ptr pduel, byte* buf);
extern "C" DECL_DLLEXPORT void set_responsei(ptr pduel, int32 value);
extern "C" DECL_DLLEXPORT void set_responseb(ptr pduel, byte* buf);
extern "C" DECL_DLLEXPORT int32 preload_script(ptr pduel, char* script, int32 len);
......
......@@ -594,3 +594,11 @@ TIMING_TODECK =0x400000
TIMING_TOGRAVE =0x800000
TIMING_BATTLE_PHASE =0x1000000
TIMING_EQUIP =0x2000000
--
DUEL_TEST_MODE =0x01
DUEL_ATTACK_FIRST_TURN =0x02
DUEL_NO_CHAIN_HINT =0x04
DUEL_ENABLE_PRIORITY =0x08
DUEL_PSEUDO_SHUFFLE =0x10
DUEL_TAG_MODE =0x20
DUEL_SIMPLE_AI =0x40
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