-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainplayer.cpp
More file actions
97 lines (81 loc) · 2.85 KB
/
Copy pathmainplayer.cpp
File metadata and controls
97 lines (81 loc) · 2.85 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
#include "mainplayer.h"
namespace SSJServer {
string MainPlayer::getPlayerId() const
{
return playerId;
}
void MainPlayer::setPlayerId(const string &value)
{
playerId = value;
}
MainPlayer::MainPlayer(): DynamicObject()
{
this->setActivity(true);
this->setMaxHP(100);
frags = 0;
this->velocity = 200.0;
this->setHP(this->getMaxHP());
this->isFiring = false;
}
void MainPlayer::update(){
if(this->isDead()){
this->setMapPosition(640,640);
this->setHP(100);
this->frags++;
}
if(this->frags == 10)
{
for(map<string, Object*>::iterator it = DataContainer::PlayerList.begin() ; it != DataContainer::PlayerList.end() ; it++)
{
((MainPlayer*)it->second)->setMapPosition(640,640);
((MainPlayer*)it->second)->setHP(100);
((MainPlayer*)it->second)->frags = 0;
}
}
}
void MainPlayer::SynchronizeWithClientOwner(Json::Value jsonObject){
if(jsonObject.isMember(_J(_mapPositionX))){
this->mapPosition.x = jsonObject[_J(_mapPositionX)].asFloat();
}
if(jsonObject.isMember(_J(_mapPositionY))){
this->mapPosition.y = jsonObject[_J(_mapPositionY)].asFloat();
}
if(jsonObject.isMember(_J(_activity))){
this->activity = jsonObject[_J(_activity)].asBool();
}
if(jsonObject.isMember(_J(_hp))){
this->hp = jsonObject[_J(_hp)].asUInt();
}
if(jsonObject.isMember(_J(_maxHP))){
this->maxHP = jsonObject[_J(_maxHP)].asUInt();
}
if(jsonObject.isMember(_J(_velocity))){
this->velocity = jsonObject[_J(_velocity)].asUInt();
}
if(jsonObject.isMember(_J(_angle))){
this->angle = jsonObject[_J(_angle)].asFloat();
}
if(jsonObject.isMember(_J(_targetAngle))){
this->targetAngle = jsonObject[_J(_targetAngle)].asFloat();
}
}
Json::Value MainPlayer::serialize()
{
Json::Value object;
object[_J(_objectName)] = _MainPlayer;
object[_J(_playerId)] = this->getPlayerId();
object[_J(_mapPositionX)] = this->getMapPosition().x;
object[_J(_mapPositionY)] = this->getMapPosition().y;
object[_J(_activity)] = this->activity;
object[_J(_hp)] = (unsigned int)this->getHP();
object[_J(_maxHP)] = (unsigned int)this->getMaxHP();
object[_J(_velocity)] = (unsigned int)this->velocity;
object[_J(_angle)] = this->getAngle().getDegrees();
object[_J(_targetAngle)] = this->targetAngle.getDegrees();
object[_J(_syncId)] = this->syncId;
object[_J(_deaths)] = this->frags;
if(this->syncEventActive)
this->syncNow = false;
return object;
}
}