-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendhdcard.cpp
More file actions
165 lines (144 loc) · 6.38 KB
/
sendhdcard.cpp
File metadata and controls
165 lines (144 loc) · 6.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "common/macros.h"
#include "common/nndef.h"
#include "common/nnlogic.h"
#include "gameroot.h"
#include "logic/gamelogic/core/sendhdcard.h"
#include "utils/tarslog.h"
#include "context/context.h"
#include "message/sendclientmessage.h"
#include "config/gameconfig.h"
#include "logic/gamelogic/core/begintimer.h"
#include "logic/gamelogic/core/endtimer.h"
#include "process/process.h"
#include "message/sendroommessage.h"
#include "third.pb.h"
#include "XGameComm.pb.h"
#include "ddz.pb.h"
using namespace nndef;
namespace game
{
namespace logic
{
namespace gamelogic
{
void SendHdCard(GameRoot *root)
{
PERFSTATS_ENTRY();
__TRY__
DLOG_TRACE("roomid:" << root->roomid() << ", " << "SendHdCard roomid:" << root->roomid());
using namespace context;
using namespace message;
using namespace nnlogic;
using namespace config;
using namespace process;
using namespace RoomSo;
if(root->pro->getProcess() != NN_STATE_SEND_CARD )
{
DLOG_TRACE("roomid:" << root->roomid() << ", " << "SendHdCard process err. process:" << root->pro->getProcess());
return ;
}
vecc_t &vecWallCards = root->con->refVecWallCard();
//筑牌
nnlogic::build(vecWallCards);
//洗牌
nnlogic::shuffle<card_t>(vecWallCards);
if(vecWallCards.size() != 54)
{
DLOG_TRACE("roomid:" << root->roomid() << ", " << "SendHdCard vecWallCards size:" << vecWallCards.size());
return ;
}
//优先把debug 弹出来
vecc_t &vecCommCards = root->con->refVecCommCard();
for(auto item : root->con->getDebugCard())
{
DLOG_TRACE("roomid:" << root->roomid() << ", cid: " << item.first <<", card size:" << item.second.size());
if(item.first == -1)//地主牌
{
if(item.second.size() >= 3)
{
vecCommCards.insert(vecCommCards.begin(), item.second.begin(), item.second.begin() + 3);
}
else
{
vecCommCards.insert(vecCommCards.begin(), item.second.begin(), item.second.end());
}
nnlogic::vecremove(vecWallCards, vecCommCards);
}
else
{
User* user= root->con->getUserByCid(item.first);
if(!user || !user->isReady())
{
continue;
}
vecc_t &vecCards = user->refVecCards();
if(item.second.size() >= 17)
{
vecCards.insert(vecCards.begin(), item.second.begin(), item.second.begin() + 17);
}
else
{
vecCards.insert(vecCards.begin(), item.second.begin(), item.second.end());
}
nnlogic::vecremove(vecWallCards, vecCards);
}
}
nnlogic::deal(vecWallCards, vecCommCards, 3 - vecCommCards.size());
XGameDDZProto::DDZ_msg2cSendCardNotify shcm2;
shcm2.set_lbasescore(root->cfg->getBaseScore());
for(int i = 0; i < 3; i++)
{
shcm2.add_scommcards(-1);
}
std::map<cid_t, User> &usermap = root->con->refUserMap();
for (auto it = usermap.begin(); it != usermap.end(); it++)
{
XGameDDZProto::PlayerInfo playerinfo;
vecc_t &vecCards = it->second.refVecCards();
if(vecCards.size() < 17)
{
nnlogic::deal(vecWallCards, vecCards, 17 - vecCards.size());
}
for(int i = 0; i < 17; i++)
{
playerinfo.add_shdcards(-1);
}
(*shcm2.mutable_mplayerinfo())[it->first] = playerinfo;
}
//发包
for (auto it = usermap.begin(); it != usermap.end(); it++)
{
auto fd = (*shcm2.mutable_mplayerinfo()).find(it->first);
if (fd != (*shcm2.mutable_mplayerinfo()).end())
{
fd->second.clear_shdcards();
for (auto itcards = it->second.getVecCards().begin(); itcards != it->second.getVecCards().end(); ++itcards)
{
fd->second.add_shdcards(*itcards);
}
sendClientMessage<XGameDDZProto::DDZ_msg2cSendCardNotify>(it->second.getUid(), XGameDDZProto::DDZ_msg2cSendCardNotify_E, shcm2, root);
DLOG_TRACE("roomid:" << root->roomid() << ", " << ">>>SendHdCard shcm2: " << logPb(shcm2));
//
fd->second.clear_shdcards();
//重置-1
for(int i = 0; i < 17; i++)
{
fd->second.add_shdcards(-1);
}
}
}
root->con->setWaitGameTime(-1, 0);
EndTimer(NN_XTIME_GAME_XTIME, root, false);
BeginTimer(NN_XTIME_GAME_XTIME, 3, [](TimerParam & param)->int
{
auto body = static_cast<std::tuple<GameRoot *> const *>(param.getBody());
auto root = std::get<0>(*body);
root->pro->turnProcess(NN_STATE_JIAODIZHU);
return 0;
}, root, false);
__CATCH__
PERFSTATS_EXIT();
}
}
}
}