-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPlayerController.cpp
More file actions
158 lines (136 loc) · 4.11 KB
/
Copy pathPlayerController.cpp
File metadata and controls
158 lines (136 loc) · 4.11 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
#include "PlayerController.h"
#include <iostream>
#include "World.h"
#include "Vector3.h"
#include "DetourNavMeshQuery.h"
#include "LogHelper.h"
#include "Player.h"
#include "Character.h"
#include "SendMessage.h"
#include "Map.h"
#include "PlayerDataLoader.h"
void PlayerController::handle(const syncnet::GameMessage* msg)
{
lastMessageId_ = msg->id();
switch (msg->msg_type())
{
case syncnet::GameMessages::GameMessages_AddAgent: handle(msg->msg_as_AddAgent()); break;
case syncnet::GameMessages::GameMessages_RemoveAgent: handle(msg->msg_as_RemoveAgent()); break;
case syncnet::GameMessages::GameMessages_SetMoveTarget: handle(msg->msg_as_SetMoveTarget()); break;
case syncnet::GameMessages::GameMessages_Ping: handle(msg->msg_as_Ping()); break;
case syncnet::GameMessages::GameMessages_SetRaycast: handle(msg->msg_as_SetRaycast()); break;
case syncnet::GameMessages::GameMessages_Login: handle(msg->msg_as_Login()); break;
case syncnet::GameMessages::GameMessages_UseSkill: handle(msg->msg_as_UseSkill()); break;
}
}
void PlayerController::handle(const syncnet::AddAgent* msg)
{
LOG.info("add agent pos:({},{},{})", msg->pos()->x(), msg->pos()->y(), msg->pos()->z());
auto actor = world_->OnAddAgent(player_, msg->gameObjectType(), msg->pos());
auto status = syncnet::StatusCode::StatusCode_Success;
int agent_id = 0;
if (!actor) {
LOG.error("OnAddAgent 실패: Actor 생성에 실패했습니다.");
status = syncnet::StatusCode::StatusCode_Failed;
}
else
{
agent_id = actor->GetActorId();
}
player_->Send(
syncnet::CreateAddAgent
, syncnet::GameMessages::GameMessages_AddAgent
, lastMessageId_
, status
, msg->gameObjectType()
, msg->pos()
, agent_id
);
}
void PlayerController::handle(const syncnet::RemoveAgent* msg)
{
LOG.info("remove agent id :{}", msg->agentId());
world_->OnRemoveAgent(msg->agentId());
}
void PlayerController::handle(const syncnet::SetMoveTarget* msg)
{
if(!player_)
{
LOG.error("player is null");
return;
}
if(!player_->GetCharacter())
{
LOG.error("character is null");
return;
}
if(player_->GetCharacter()->IsInputLocked())
{
LOG.debug("character is input locked");
return;
}
LOG.debug("move target agent id :{}, pos:({},{},{})", player_->GetCharacter()->GetActorId(), msg->pos()->x(), msg->pos()->y(), msg->pos()->z());
world_->OnSetMoveTarget(player_->GetCharacter()->GetActorId(), msg->pos());
}
void PlayerController::handle(const syncnet::Ping* msg)
{
//std::cout << "ping seq : " << msg->seq() << std::endl;
player_->Send(
syncnet::CreatePing
, syncnet::GameMessages_Ping
, lastMessageId_
, syncnet::StatusCode::StatusCode_Success
, msg->seq()
);
}
void PlayerController::handle(const syncnet::SetRaycast* msg)
{
LOG.info("SetRaycast pos:({},{},{})", msg->pos()->x(), msg->pos()->y(), msg->pos()->z());
world_->OnSetRaycast(msg->pos());
}
void PlayerController::handle(const syncnet::Login* msg)
{
LOG.info("Login id :{}, lastMessageId:{}", msg->userId()->c_str(), lastMessageId_);
PlayerDataLoader::AsyncLoad(player_);
player_->Send(
syncnet::CreateLoginDirect
, syncnet::GameMessages::GameMessages_Login
, lastMessageId_
, syncnet::StatusCode::StatusCode_Success
, msg->userId()->c_str()
, msg->password()->c_str()
);
}
void PlayerController::handle(const syncnet::UseSkill* msg)
{
LOG.info("UseSkill id :{}, skillId :{}, targetId :{} pos:({},{},{})", msg->id(), msg->skillId(), msg->targetId(), msg->pos()->x(), msg->pos()->y(), msg->pos()->z());
auto character = player_->GetCharacter();
if (!character)
{
LOG.error("character is null");
return;
}
if (player_->GetCharacter()->IsInputLocked())
{
LOG.debug("character is input locked");
return;
}
character->use_skill(msg);
auto builder_ptr = std::make_shared<send_message>();
auto send_msg = syncnet::CreateGameMessage(
*builder_ptr,
syncnet::GameMessages::GameMessages_UseSkill,
syncnet::CreateUseSkill(
*builder_ptr
, msg->id()
, msg->skillId()
, msg->targetId()
, msg->pos()
, msg->dir()
, msg->timestamp()
, msg->duration()
).Union()
);
builder_ptr->Finish(send_msg);
character->GetMap()->SendBroadcast(builder_ptr, player_);
}