This repository was archived by the owner on Mar 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy pathhouse.h
More file actions
276 lines (216 loc) · 7.81 KB
/
Copy pathhouse.h
File metadata and controls
276 lines (216 loc) · 7.81 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
//////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//////////////////////////////////////////////////////////////////////
#ifndef __OTSERV_HOUSE_H__
#define __OTSERV_HOUSE_H__
#include <boost/regex.hpp>
#include <unordered_set>
#include "position.h"
#include "item.h"
#include "container.h"
class AccessList
{
public:
AccessList();
~AccessList();
bool parseList(const std::string& _list);
bool addPlayer(std::string& name);
bool addGuild(const std::string& guildName, const std::string& rank);
bool addExpression(const std::string& expression);
bool isInList(const Player* player);
void getList(std::string& _list) const;
private:
typedef std::unordered_set<uint32_t> PlayerList;
typedef std::list< std::pair<uint32_t, std::string> > GuildList;
typedef std::list<std::string> ExpressionList;
typedef std::list<std::pair<boost::regex, bool> > RegExList;
std::string list;
PlayerList playerList;
GuildList guildList;
ExpressionList expressionList;
RegExList regExList;
};
class Door : public Item
{
public:
Door(uint16_t _type);
virtual ~Door();
virtual Door* getDoor() {return this;}
virtual const Door* getDoor() const {return this;}
House* getHouse(){return house;}
//serialization
virtual Attr_ReadValue readAttr(AttrTypes_t attr, PropStream& propStream);
virtual bool serializeAttr(PropWriteStream& propWriteStream) const;
void setDoorId(uint32_t _doorId) {setAttribute("doorid", (int32_t)_doorId);}
uint32_t getDoorId() const {const int32_t* _doorId = getIntegerAttribute("doorid"); if(_doorId) return (uint32_t)*_doorId; return 0;}
bool canUse(const Player* player);
void setAccessList(const std::string& textlist);
bool getAccessList(std::string& list) const;
//overrides
virtual void onRemoved();
void copyAttributes(Item* item);
protected:
void setHouse(House* _house);
private:
House* house;
AccessList* accessList;
friend class House;
};
enum AccessList_t{
GUEST_LIST = 0x100,
SUBOWNER_LIST = 0x101
};
enum AccessHouseLevel_t{
HOUSE_NO_INVITED = 0,
HOUSE_GUEST = 1,
HOUSE_SUBOWNER = 2,
HOUSE_OWNER = 3
};
typedef std::list<HouseTile*> HouseTileList;
typedef std::list<Door*> HouseDoorList;
typedef std::list<BedItem*> HouseBedItemList;
class House
{
public:
enum syncflags_t{
HOUSE_SYNC_TOWNID = 0,
HOUSE_SYNC_NAME = 1 << 0,
HOUSE_SYNC_PRICE = 1 << 1,
HOUSE_SYNC_RENT = 1 << 2,
HOUSE_SYNC_GUILDHALL = 1 << 3
};
House(uint32_t _houseid);
~House();
void addTile(HouseTile* tile);
bool canEditAccessList(uint32_t listId, const Player* player);
// listId special values:
// GUEST_LIST guest list
// SUBOWNER_LIST subowner list
void setAccessList(uint32_t listId, const std::string& textlist);
bool getAccessList(uint32_t listId, std::string& list) const;
bool isInvited(const Player* player);
AccessHouseLevel_t getHouseAccessLevel(const Player* player);
bool kickPlayer(Player* player, const std::string& name);
void setEntryPos(const Position& pos) {posEntry = pos;}
const Position& getEntryPosition() const {return posEntry;}
void setName(const std::string& _houseName) {houseName = _houseName;}
const std::string& getName() const {return houseName;}
void setHouseOwner(uint32_t guid);
uint32_t getHouseOwner() const {return houseOwner;}
void setPaidUntil(time_t paid){paidUntil = paid;}
time_t getPaidUntil() const {return paidUntil;}
void setRent(uint32_t _rent){rent = _rent;}
uint32_t getRent() const {return rent;}
bool hasSyncFlag(syncflags_t flag) const {return ((syncFlags & (uint32_t)flag) == (uint32_t)flag);}
void resetSyncFlag(syncflags_t flag) {syncFlags &= ~(uint32_t)flag;}
void setLastWarning(time_t _lastWarning) {lastWarning = _lastWarning;}
time_t getLastWarning() const {return lastWarning;}
void setPayRentWarnings(uint32_t warnings) {rentWarnings = warnings;}
uint32_t getPayRentWarnings() const {return rentWarnings;}
void setTownId(uint32_t _town){townid = _town;}
uint32_t getTownId() const {return townid;}
void setGuildHall(bool _guildHall) {guildHall = _guildHall;}
bool isGuildHall() const {return guildHall;}
void setPendingDepotTransfer(bool _pendingDepotTransfer) {pendingDepotTransfer = _pendingDepotTransfer;}
bool getPendingDepotTransfer() const {return pendingDepotTransfer;}
uint32_t getHouseId() const {return houseid;}
void addDoor(Door* door);
void removeDoor(Door* door);
void addBed(BedItem* bed);
Door* getDoorByNumber(uint32_t doorId);
Door* getDoorByNumber(uint32_t doorId) const;
Door* getDoorByPosition(const Position& pos);
HouseTileList::iterator getTileBegin() {return houseTiles.begin();}
HouseTileList::iterator getTileEnd() {return houseTiles.end();}
size_t getTileCount() const {return houseTiles.size();}
HouseDoorList::iterator getDoorBegin() {return doorList.begin();}
HouseDoorList::iterator getDoorEnd() {return doorList.end();}
size_t getDoorCount() const {return doorList.size();}
HouseBedItemList::iterator getBedsBegin() {return bedsList.begin();}
HouseBedItemList::iterator getBedsEnd() {return bedsList.end();}
size_t getBedTiles() const {return bedsList.size();}
uint32_t getBedCount() const {return (uint32_t)std::ceil((double)getBedTiles() / 2);} //each bed takes 2 sqms of space, ceil is just for bad maps
// Transfers all items to depot and clicks all players (useful for map updates, for example)
void cleanHouse();
private:
void updateDoorDescription();
bool transferToDepot();
bool isLoaded;
uint32_t houseid;
uint32_t houseOwner;
std::string houseOwnerName;
HouseTileList houseTiles;
HouseDoorList doorList;
HouseBedItemList bedsList;
AccessList guestList;
AccessList subOwnerList;
std::string houseName;
Position posEntry;
time_t paidUntil;
uint32_t rentWarnings;
time_t lastWarning;
uint32_t rent;
uint32_t townid;
bool guildHall;
uint32_t syncFlags;
bool pendingDepotTransfer;
};
typedef std::map<uint32_t, House*> HouseMap;
enum RentPeriod_t{
RENTPERIOD_DAILY,
RENTPERIOD_WEEKLY,
RENTPERIOD_MONTHLY,
RENTPERIOD_YEARLY,
RENTPERIOD_NEVER
};
class Houses
{
public:
Houses();
~Houses();
static Houses* getInstance();
House* getHouse(uint32_t houseid, bool add = false)
{
HouseMap::iterator it = houseMap.find(houseid);
if(it != houseMap.end()){
return it->second;
}
if(add){
House* house = new House(houseid);
houseMap[houseid] = house;
return house;
}
else{
return NULL;
}
}
House* getHouseByPlayerId(uint32_t playerId);
bool loadHousesXML(std::string filename);
bool payRent(Player* player, House* house, time_t time = 0);
bool payHouses();
void getRentPeriodString(std::string& strPeriod);
HouseMap::iterator getHouseBegin() {return houseMap.begin();}
HouseMap::iterator getHouseEnd() {return houseMap.end();}
bool payHouse(House* house, time_t time);
private:
RentPeriod_t rentPeriod;
HouseMap houseMap;
friend class IOMapSerialize;
};
#endif