Commit c4d7ca2d authored by Chen Bill's avatar Chen Bill

match_result use player_id

player_id: the index of players[] when G1 starts
type: first/second player in current duel
parent a4188894
......@@ -347,6 +347,8 @@ void SingleDuel::StartDuel(DuelPlayer* dp) {
hand_result[1] = 0;
players[0]->state = CTOS_HAND_RESULT;
players[1]->state = CTOS_HAND_RESULT;
players[0]->player_id = 0;
players[1]->player_id = 1;
duel_stage = DUEL_STAGE_FINGER;
}
void SingleDuel::HandResult(DuelPlayer* dp, unsigned char res) {
......@@ -394,8 +396,6 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
return;
duel_stage = DUEL_STAGE_DUELING;
bool swapped = false;
pplayer[0] = players[0];
pplayer[1] = players[1];
if((tp && dp->type == 1) || (!tp && dp->type == 0)) {
DuelPlayer* p = players[0];
players[0] = players[1];
......@@ -535,15 +535,6 @@ void SingleDuel::DuelEndProc() {
NetServer::ReSendToPlayer(*oit);
duel_stage = DUEL_STAGE_END;
} else {
if(players[0] != pplayer[0]) {
players[0] = pplayer[0];
players[1] = pplayer[1];
players[0]->type = 0;
players[1]->type = 1;
Deck d = pdeck[0];
pdeck[0] = pdeck[1];
pdeck[1] = d;
}
ready[0] = false;
ready[1] = false;
players[0]->state = CTOS_UPDATE_DECK;
......@@ -557,7 +548,7 @@ void SingleDuel::DuelEndProc() {
}
}
void SingleDuel::Surrender(DuelPlayer* dp) {
if(dp->type > 1 || !pduel)
if (dp->type > 1 || dp->player_id > 1 || !pduel)
return;
unsigned char wbuf[3];
uint32 player = dp->type;
......@@ -568,13 +559,9 @@ void SingleDuel::Surrender(DuelPlayer* dp) {
NetServer::ReSendToPlayer(players[1]);
for(auto oit = observers.begin(); oit != observers.end(); ++oit)
NetServer::ReSendToPlayer(*oit);
if(players[player] == pplayer[player]) {
match_result[duel_count++] = 1 - player;
match_result[duel_count] = 1 - dp->player_id;
++duel_count;
tp_player = player;
} else {
match_result[duel_count++] = player;
tp_player = 1 - player;
}
EndDuel();
DuelEndProc();
event_del(etimer);
......@@ -633,15 +620,14 @@ int SingleDuel::Analyze(unsigned char* msgbuffer, unsigned int len) {
for(auto oit = observers.begin(); oit != observers.end(); ++oit)
NetServer::ReSendToPlayer(*oit);
if(player > 1) {
match_result[duel_count++] = 2;
match_result[duel_count] = 2;
tp_player = 1 - tp_player;
} else if(players[player] == pplayer[player]) {
match_result[duel_count++] = player;
}
else {
match_result[duel_count] = players[player]->player_id;
tp_player = 1 - player;
} else {
match_result[duel_count++] = 1 - player;
tp_player = player;
}
++duel_count;
EndDuel();
return 2;
}
......@@ -1598,13 +1584,9 @@ void SingleDuel::SingleTimer(evutil_socket_t fd, short events, void* arg) {
NetServer::ReSendToPlayer(sd->players[1]);
for(auto oit = sd->observers.begin(); oit != sd->observers.end(); ++oit)
NetServer::ReSendToPlayer(*oit);
if(sd->players[player] == sd->pplayer[player]) {
sd->match_result[sd->duel_count++] = 1 - player;
sd->match_result[sd->duel_count] = sd->players[1 - player]->player_id;
++sd->duel_count;
sd->tp_player = player;
} else {
sd->match_result[sd->duel_count++] = player;
sd->tp_player = 1 - player;
}
sd->EndDuel();
sd->DuelEndProc();
event_del(sd->etimer);
......
......@@ -46,7 +46,6 @@ private:
protected:
DuelPlayer* players[2]{ nullptr };
DuelPlayer* pplayer[2]{nullptr};
bool ready[2]{ false };
Deck pdeck[2];
int deck_error[2]{ 0 };
......
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