-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsendaction.cpp
More file actions
176 lines (155 loc) · 6.95 KB
/
sendaction.cpp
File metadata and controls
176 lines (155 loc) · 6.95 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
166
167
168
169
170
171
172
173
174
175
176
#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 "logic/timeoutlogic/core/actiontimeout.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 SendAction(GameRoot *root, int opType)
{
PERFSTATS_ENTRY();
__TRY__
DLOG_TRACE("roomid:" << root->roomid() << ", " << "SendAction roomid:" << root->roomid());
using namespace context;
using namespace message;
using namespace nnlogic;
using namespace config;
using namespace process;
using namespace RoomSo;
using namespace timeoutlogic;
if(root->pro->getProcess() < NN_STATE_JIAODIZHU || root->pro->getProcess() > NN_STATE_DAPAI )
{
DLOG_TRACE("roomid:" << root->roomid() << ", " << "SendAction process err. process:" << root->pro->getProcess());
return ;
}
DLOG_TRACE("roomid:" << root->roomid() << ", " << "tokencid: " << root->con->getTokenCid() <<", firstdapai: "<< root->con->isFirstDaPai());
//是否第一手牌
if(root->con->isFirstDaPai())
{
root->con->setTokenCid(root->con->getBankerCid());
}
else
{
if(root->con->getTokenCid() == nil_cid)
{
root->con->setTokenCid(rand() % 3);
}
else
{
cid_t nextCid = root->con->getNextCid(root->con->getTokenCid(), 3, 1);
root->con->setTokenCid(nextCid);
}
}
root->con->setCurCid(root->con->getTokenCid());
if(root->con->getStartCid() == nil_cid)
{
root->con->setStartCid(root->con->getTokenCid());
}
int cfgActionTime = root->cfg->getDecisionTime(opType);
int remainActionTime = cfgActionTime;
XGameDDZProto::DDZ_msg2sActNotify shcm2;
shcm2.set_icid(root->con->getTokenCid());
shcm2.set_iacttype(opType);
shcm2.set_bfirstdapai(root->con->isFirstDaPai());
switch(opType)
{
case 1://叫地主
break;
case 2://加倍
break;
case 3: //打牌
{
User* user = root->con->getUserByCid(root->con->getTokenCid());
if(user)
{
if(root->con->getLastDecision().size() == 1)
{
if(root->con->getLastDecision().begin()->first == user->getCid())
{
root->con->clearLastDecision();
}
}
vecc_t vecCards = user->getVecCards();
auto last_decision = root->con->getLastDecision();
E_NN_TYPE lastCardType = root->con->getLastCardType();
vecc_t vecDaPaiCards;
E_NN_TYPE cardType = E_NN_TYPE::NN_TYPE_NN_NONE;
user->setCanDaPai(nnlogic::check(vecDaPaiCards, vecCards ,last_decision, lastCardType, cardType, 1) == 1);
shcm2.set_bcandapai(user->isCanDaPai());
for(auto decision : last_decision)
{
for(auto card : decision.second)
{
shcm2.add_sprecards(card);
}
}
shcm2.set_iprecardtype(lastCardType);
if(user->isRobot())
{
cfgActionTime = rand() % 5 + 1;
}
if(user->isTuoGuan() || !user->isCanDaPai())
{
cfgActionTime = 3;
}
}
root->con->setFirstDaPai(false);
}
break;
default:
DLOG_TRACE("roomid:" << root->roomid() << ", " << "opType err. opType:" << opType);
break;
}
shcm2.set_icfgoptiontime(cfgActionTime);
shcm2.set_iremainoptiontime(remainActionTime);
if(opType == 1 || opType == 3)
{
sendAllClientMessage<XGameDDZProto::DDZ_msg2sActNotify>(XGameDDZProto::DDZ_msg2sActNotify_E, shcm2, root);
DLOG_TRACE("roomid:" << root->roomid() << ", " << ">>>SendAction shcm2: " << logPb(shcm2));
}
else
{
std::map<cid_t, User> &usermap = root->con->refUserMap();
for (auto it = usermap.begin(); it != usermap.end(); it++)
{
if(!it->second.isReady())
{
continue;
}
shcm2.set_icid(it->first);
sendClientMessage<XGameDDZProto::DDZ_msg2sActNotify>(it->second.getUid(), XGameDDZProto::DDZ_msg2sActNotify_E, shcm2, root);
DLOG_TRACE("roomid:" << root->roomid() << ", " << ">>>SendAction shcm2: " << logPb(shcm2));
}
}
root->con->setOptionTime();
EndTimer(NN_XTIME_GAME_XTIME, root, false);
BeginTimer(NN_XTIME_GAME_XTIME, cfgActionTime, [](TimerParam & param)->int
{
auto body = static_cast<std::tuple<GameRoot *> const *>(param.getBody());
auto root = std::get<0>(*body);
ActionTimeOut(root);
return 0;
}, root, false);
__CATCH__
PERFSTATS_EXIT();
}
}
}
}