-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplayer.cpp
More file actions
153 lines (129 loc) · 3.01 KB
/
player.cpp
File metadata and controls
153 lines (129 loc) · 3.01 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
#include "player.h"
#include "room.h"
#include "game_server.h"
#include <iterator>
#include <iostream>
#include "common.h"
#include "database.h"
using namespace std;
Player::Player() {
}
Player::Player(string name, string desc, int id) {
username = name;
description = desc;
playerID = id;
canBuild = true;
}
void Player::save(){
string temp;
if(playerID == -1){
db->increment_lastid();
playerID = db->lastid;
temp = "player \n username:"+getUsername()+"\n"+"desc:"+getDescription()+"\n";
db->write(to_string(playerID),temp);
db->addPlayer(this);
}
}
set<Item*> Player::dropItem(string name) {
set<Item*>::const_iterator p;
set<Item*> newInventoryState;
for (p = inventory.begin(); *p != NULL; p++){
if (!((*p)->getName() == name)) {
newInventoryState.insert(*p);
}
}
return newInventoryState;
}
void Player::setRoom(Room* r) {
room = r;
}
Room* Player::getRoom() const {
return room;
}
set<Item*> Player::getInventory() const {
/*set<Item*>::const_iterator p;
cout << "\nInventory: " << endl;
for (p = inventory.begin(); *p != NULL; p++){
cout << (*p)->getName() << endl;
}*/
return inventory;
}
void Player::addItemToInventory(Item* item) {
inventory.insert(item);
}
Item* Player::findItemInInventory(string name) const {
set<Item*>::const_iterator p;
for(p = inventory.begin(); p != inventory.end(); p++) {
if ((*p)->getName() == name) {
return *p;
}
}
cout << "ERROR: Item not found." << endl;
return NULL;
}
bool Player::isItemInInventory(string name) {
set<Item*>::const_iterator p;
for(p = inventory.begin(); p != inventory.end(); p++) {
if ((*p)->getName() == name) {
return true;
}
}
return false;
}
void Player::setCanBuild(bool permission) {
canBuild = permission;
}
bool Player::getCanBuild() const {
return canBuild;
}
void Player::setCanEdit(bool permission)
{
canEdit = permission;
}
bool Player::getCanEdit() const {
return canEdit;
}
void Player::setUsername(string name) {
username = name;
}
string Player::getUsername() const {
return username;
}
void Player::setLastLoginIp(string ip) {
lastLoginIp = ip;
}
string Player::getLastLoginIp() const {
return lastLoginIp;
}
void Player::setLastLoginTime(string timestamp) {
lastLoginTime = timestamp;
}
string Player::getLastLoginTime() const {
return lastLoginTime;
}
void Player::setPassword(string pass) {
password = pass;
}
string Player::getPassword() const {
return password;
}
void Player::setDescription(string desc) {
description = desc;
}
string Player::getDescription() const {
return description;
}
void Player::setID(int id) {
playerID = id;
}
int Player::getID() const {
return playerID;
}
bool Player::reqisPassed()
{
return true;
}
/*bool Player::connected() const {
return true;
//not needed as there is similar functionality in gameserver
}*/