Commit 4770a4fb authored by VanillaSalt's avatar VanillaSalt

update MSG_ANNOUNCE_CARD_FILTER

parent 9808111f
#include <stack>
#include "client_field.h"
#include "client_card.h"
#include "duelclient.h"
......@@ -1329,7 +1330,148 @@ static bool is_declarable(T const& cd, int declarable_type) {
return cd.code == CARD_MARINE_DOLPHIN || cd.code == CARD_TWINKLE_MOSS
|| (!cd.alias && (cd.type & (TYPE_MONSTER + TYPE_TOKEN)) != (TYPE_MONSTER + TYPE_TOKEN));
}
void ClientField::UpdateDeclarableCode(bool enter) {
template <class T>
static bool is_declarable(T const& cd, const std::vector<int>& opcode) {
std::stack<int> stack;
for(auto it = opcode.begin(); it != opcode.end(); ++it) {
switch(*it) {
case OPCODE_ADD: {
if (stack.size() >= 2) {
int rhs = stack.top();
stack.pop();
int lhs = stack.top();
stack.pop();
stack.push(lhs + rhs);
}
break;
}
case OPCODE_SUB: {
if (stack.size() >= 2) {
int rhs = stack.top();
stack.pop();
int lhs = stack.top();
stack.pop();
stack.push(lhs - rhs);
}
break;
}
case OPCODE_MUL: {
if (stack.size() >= 2) {
int rhs = stack.top();
stack.pop();
int lhs = stack.top();
stack.pop();
stack.push(lhs * rhs);
}
break;
}
case OPCODE_DIV: {
if (stack.size() >= 2) {
int rhs = stack.top();
stack.pop();
int lhs = stack.top();
stack.pop();
stack.push(lhs / rhs);
}
break;
}
case OPCODE_AND: {
if (stack.size() >= 2) {
int rhs = stack.top();
stack.pop();
int lhs = stack.top();
stack.pop();
stack.push(lhs && rhs);
}
break;
}
case OPCODE_OR: {
if (stack.size() >= 2) {
int rhs = stack.top();
stack.pop();
int lhs = stack.top();
stack.pop();
stack.push(lhs || rhs);
}
break;
}
case OPCODE_NEG: {
if (stack.size() >= 1) {
int val = stack.top();
stack.pop();
stack.push(-val);
}
break;
}
case OPCODE_NOT: {
if (stack.size() >= 1) {
int val = stack.top();
stack.pop();
stack.push(!val);
}
break;
}
case OPCODE_ISCODE: {
if (stack.size() >= 1) {
int code = stack.top();
stack.pop();
stack.push(cd.code == code);
}
break;
}
case OPCODE_ISSETCARD: {
if (stack.size() >= 1) {
int set_code = stack.top();
stack.pop();
unsigned long long sc = cd.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;
}
stack.push(res);
}
break;
}
case OPCODE_ISTYPE: {
if (stack.size() >= 1) {
int val = stack.top();
stack.pop();
stack.push(cd.type & val);
}
break;
}
case OPCODE_ISRACE: {
if (stack.size() >= 1) {
int race = stack.top();
stack.pop();
stack.push(cd.race & race);
}
break;
}
case OPCODE_ISATTRIBUTE: {
if (stack.size() >= 1) {
int attribute = stack.top();
stack.pop();
stack.push(cd.attribute & attribute);
}
break;
}
default: {
stack.push(*it);
break;
}
}
}
if(stack.size() != 1 || stack.top() == 0)
return false;
return cd.code == CARD_MARINE_DOLPHIN || cd.code == CARD_TWINKLE_MOSS
|| (!cd.alias && (cd.type & (TYPE_MONSTER + TYPE_TOKEN)) != (TYPE_MONSTER + TYPE_TOKEN));
}
void ClientField::UpdateDeclarableCodeType(bool enter) {
const wchar_t* pname = mainGame->ebANCard->getText();
int trycode = BufferIO::GetVal(pname);
CardString cstr;
......@@ -1341,7 +1483,7 @@ void ClientField::UpdateDeclarableCode(bool enter) {
ancard.push_back(trycode);
return;
}
if(pname[0] == 0 || (pname[1] == 0 && !enter))
if((pname[0] == 0 || pname[1] == 0) && !enter)
return;
mainGame->lstANCard->clear();
ancard.clear();
......@@ -1356,4 +1498,37 @@ void ClientField::UpdateDeclarableCode(bool enter) {
}
}
}
void ClientField::UpdateDeclarableCodeOpcode(bool enter) {
const wchar_t* pname = mainGame->ebANCard->getText();
int trycode = BufferIO::GetVal(pname);
CardString cstr;
CardData cd;
if(dataManager.GetString(trycode, &cstr) && dataManager.GetData(trycode, &cd) && is_declarable(cd, opcode)) {
mainGame->lstANCard->clear();
ancard.clear();
mainGame->lstANCard->addItem(cstr.name);
ancard.push_back(trycode);
return;
}
if((pname[0] == 0 || pname[1] == 0) && !enter)
return;
mainGame->lstANCard->clear();
ancard.clear();
for(auto cit = dataManager._strings.begin(); cit != dataManager._strings.end(); ++cit) {
if(wcsstr(cit->second.name, pname) != 0) {
auto cp = dataManager.GetCodePointer(cit->first); //verified by _strings
//datas.alias can be double card names or alias
if(is_declarable(cp->second, opcode)) {
mainGame->lstANCard->addItem(cit->second.name);
ancard.push_back(cit->first);
}
}
}
}
void ClientField::UpdateDeclarableCode(bool enter) {
if(opcode.size() == 0)
UpdateDeclarableCodeType(enter);
else
UpdateDeclarableCodeOpcode(enter);
}
}
......@@ -63,6 +63,7 @@ public:
std::vector<ClientCard*> selected_cards;
std::set<ClientCard*> selectsum_cards;
std::vector<ClientCard*> selectsum_all;
std::vector<int> opcode;
std::vector<ClientCard*> display_cards;
std::vector<int> sort_list;
std::map<int, int> player_desc_hints[2];
......@@ -104,7 +105,9 @@ public:
bool check_sel_sum_s(const std::set<ClientCard*>& left, int index, int acc);
void check_sel_sum_t(const std::set<ClientCard*>& left, int acc);
bool check_sum(std::set<ClientCard*>::const_iterator index, std::set<ClientCard*>::const_iterator end, int acc, int count);
void UpdateDeclarableCodeType(bool enter);
void UpdateDeclarableCodeOpcode(bool enter);
void UpdateDeclarableCode(bool enter);
irr::gui::IGUIElement* panel;
......
......@@ -2928,6 +2928,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
case MSG_ANNOUNCE_CARD: {
/*int player = */mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf));
mainGame->dField.declarable_type = BufferIO::ReadInt32(pbuf);
mainGame->dField.opcode.clear();
if(select_hint)
myswprintf(textBuffer, L"%ls", dataManager.GetDesc(select_hint));
else myswprintf(textBuffer, dataManager.GetSysString(564));
......@@ -2935,6 +2936,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
mainGame->gMutex.Lock();
mainGame->ebANCard->setText(L"");
mainGame->wANCard->setText(textBuffer);
mainGame->dField.UpdateDeclarableCode(true);
mainGame->PopupElement(mainGame->wANCard);
mainGame->gMutex.Unlock();
return false;
......@@ -2959,6 +2961,25 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
mainGame->gMutex.Unlock();
return false;
}
case MSG_ANNOUNCE_CARD_FILTER: {
/*int player = */mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf));
int count = BufferIO::ReadInt8(pbuf);
mainGame->dField.declarable_type = 0;
mainGame->dField.opcode.clear();
for (int i = 0; i < count; ++i)
mainGame->dField.opcode.push_back(BufferIO::ReadInt32(pbuf));
if(select_hint)
myswprintf(textBuffer, L"%ls", dataManager.GetDesc(select_hint));
else myswprintf(textBuffer, dataManager.GetSysString(564));
select_hint = 0;
mainGame->gMutex.Lock();
mainGame->ebANCard->setText(L"");
mainGame->wANCard->setText(textBuffer);
mainGame->dField.UpdateDeclarableCode(true);
mainGame->PopupElement(mainGame->wANCard);
mainGame->gMutex.Unlock();
return false;
}
case MSG_CARD_HINT: {
int c = mainGame->LocalPlayer(BufferIO::ReadInt8(pbuf));
int l = BufferIO::ReadInt8(pbuf);
......
......@@ -756,7 +756,8 @@ bool ReplayMode::ReplayAnalyze(char* msg, unsigned int len) {
pbuf += 4;
return ReadReplayResponse();
}
case MSG_ANNOUNCE_NUMBER: {
case MSG_ANNOUNCE_NUMBER:
case MSG_ANNOUNCE_CARD_FILTER: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
pbuf += 4 * count;
......
......@@ -1273,7 +1273,8 @@ int SingleDuel::Analyze(char* msgbuffer, unsigned int len) {
NetServer::SendBufferToPlayer(players[player], STOC_GAME_MSG, offset, pbuf - offset);
return 1;
}
case MSG_ANNOUNCE_NUMBER: {
case MSG_ANNOUNCE_NUMBER:
case MSG_ANNOUNCE_CARD_FILTER: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
pbuf += 4 * count;
......
......@@ -588,7 +588,8 @@ bool SingleMode::SinglePlayAnalyze(char* msg, unsigned int len) {
}
break;
}
case MSG_ANNOUNCE_NUMBER: {
case MSG_ANNOUNCE_NUMBER:
case MSG_ANNOUNCE_CARD_FILTER: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
pbuf += 4 * count;
......
......@@ -1312,7 +1312,8 @@ int TagDuel::Analyze(char* msgbuffer, unsigned int len) {
NetServer::SendBufferToPlayer(cur_player[player], STOC_GAME_MSG, offset, pbuf - offset);
return 1;
}
case MSG_ANNOUNCE_NUMBER: {
case MSG_ANNOUNCE_NUMBER:
case MSG_ANNOUNCE_CARD_FILTER: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
pbuf += 4 * count;
......
Subproject commit 9b3dbc2c28d1e4f37d24cd1779cac93f59674e45
Subproject commit b2d983470ed5da3989e2b217c3e13b3c4e9352f5
Subproject commit caba7e1f82e5286e5ed165f9aea46cb798e019df
Subproject commit 95e774916b34e4aaf47972742854cf4f30eec505
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