forked from peonso/forgottenserver036pl1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhouse.h
289 lines (222 loc) · 7.78 KB
/
house.h
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
277
278
279
280
281
282
283
284
285
286
287
288
289
////////////////////////////////////////////////////////////////////////
// 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 3 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, see <http://www.gnu.org/licenses/>.
////////////////////////////////////////////////////////////////////////
#ifndef __HOUSE__
#define __HOUSE__
#include "otsystem.h"
#include <boost/regex.hpp>
#include <boost/tr1/unordered_set.hpp>
#include "position.h"
#include "housetile.h"
#include "player.h"
class House;
class BedItem;
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
};
enum RentPeriod_t
{
RENTPERIOD_DAILY,
RENTPERIOD_WEEKLY,
RENTPERIOD_MONTHLY,
RENTPERIOD_YEARLY,
RENTPERIOD_NEVER
};
typedef std::list<HouseTile*> HouseTileList;
typedef std::list<Door*> HouseDoorList;
typedef std::list<BedItem*> HouseBedList;
typedef std::map<uint32_t, House*> HouseMap;
class AccessList
{
public:
AccessList() {}
virtual ~AccessList() {}
bool parseList(const std::string& _list);
bool addPlayer(std::string& name);
bool addGuild(const std::string& guildName, const std::string& rankName);
bool addExpression(const std::string& expression);
bool isInList(const Player* player);
void getList(std::string& _list) const;
private:
typedef std::tr1::unordered_set<uint32_t> PlayerList;
typedef std::list<std::pair<uint32_t, int32_t> > 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): Item(type), house(NULL), accessList(NULL) {}
virtual ~Door();
virtual Door* getDoor() {return this;}
virtual const Door* getDoor() const {return this;}
//serialization
virtual Attr_ReadValue readAttr(AttrTypes_t attr, PropStream& propStream);
void setDoorId(uint32_t doorId) {setAttribute("doorid", (int32_t)doorId);}
uint32_t getDoorId() const;
House* getHouse() {return house;}
void setHouse(House* _house);
void setAccessList(const std::string& textList);
bool getAccessList(std::string& list) const;
bool canUse(const Player* player);
//overrides
virtual void onRemoved();
virtual void copyAttributes(Item* item);
private:
House* house;
AccessList* accessList;
};
inline uint32_t Door::getDoorId() const
{
const int32_t* v = getIntegerAttribute("doorid");
if(v)
return (uint32_t)*v;
return 0;
}
class TransferItem : public Item
{
public:
static TransferItem* createTransferItem(House* house);
TransferItem(House* _house): Item(0) {house = _house;}
virtual ~TransferItem() {}
virtual bool onTradeEvent(TradeEvents_t event, Player* owner, Player* seller);
virtual bool canTransform() const {return false;}
House* getHouse() {return house;}
protected:
House* house;
};
class House
{
public:
virtual ~House() {}
enum syncflags_t
{
HOUSE_SYNC_NONE = 0,
HOUSE_SYNC_NAME = 1 << 0,
HOUSE_SYNC_TOWN = 1 << 1,
HOUSE_SYNC_SIZE = 1 << 2,
HOUSE_SYNC_GUILD = 1 << 3,
HOUSE_SYNC_PRICE = 1 << 4,
HOUSE_SYNC_RENT = 1 << 5
};
House(uint32_t houseId);
uint32_t getId() const {return id;}
void setEntry(const Position& pos) {entry = pos;}
Position getEntry() const {return entry;}
void setName(const std::string& houseName) {name = houseName;}
std::string getName() const {return name;}
void setOwner(uint32_t guid);
bool setOwnerEx(uint32_t guid, bool transfer);
uint32_t getOwner() const {return owner;}
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;}
void setPrice(uint32_t _price, bool update = false);
uint32_t getPrice() const {return price;}
void setLastWarning(time_t _lastWarning) {lastWarning = _lastWarning;}
time_t getLastWarning() {return lastWarning;}
void setRentWarnings(uint32_t warnings) {rentWarnings = warnings;}
uint32_t getRentWarnings() const {return rentWarnings;}
void setTownId(uint32_t _town) {townId = _town;}
uint32_t getTownId() const {return townId;}
void setSize(uint32_t _size) {size = _size;}
uint32_t getSize() const {return size;}
void setPendingTransfer(bool transfer) {pendingTransfer = transfer;}
bool hasPendingTransfer() const {return pendingTransfer;}
void setGuild(bool _guild) {guild = _guild;}
bool isGuild() const;
uint32_t getDoorsCount() const {return doorList.size();}
uint32_t getBedsCount() const {return bedsList.size();}
uint32_t getTilesCount() const {return houseTiles.size();}
bool hasSyncFlag(syncflags_t flag) const {return ((syncFlags & (uint32_t)flag) == (uint32_t)flag);}
void resetSyncFlag(syncflags_t flag) {syncFlags &= ~(uint32_t)flag;}
bool canEditAccessList(uint32_t listId, const Player* player);
void setAccessList(uint32_t listId, const std::string& textlist, bool teleport = true);
bool getAccessList(uint32_t listId, std::string& list) const;
bool isInvited(const Player* player);
AccessHouseLevel_t getHouseAccessLevel(const Player* player);
bool kickPlayer(Player* player, Player* target);
void updateDoorDescription(std::string _name = "");
void clean();
void addDoor(Door* door);
void removeDoor(Door* door);
HouseDoorList::iterator getHouseDoorBegin() {return doorList.begin();}
HouseDoorList::iterator getHouseDoorEnd() {return doorList.end();}
void addBed(BedItem* bed);
HouseBedList::iterator getHouseBedsBegin() {return bedsList.begin();}
HouseBedList::iterator getHouseBedsEnd() {return bedsList.end();}
void addTile(HouseTile* tile);
HouseTileList::iterator getHouseTileBegin() {return houseTiles.begin();}
HouseTileList::iterator getHouseTileEnd() {return houseTiles.end();}
Door* getDoorByNumber(uint32_t doorId) const;
Door* getDoorByPosition(const Position& pos);
private:
bool transferToDepot();
void removePlayer(Player* player, bool ignoreRights);
void removePlayers(bool ignoreInvites);
bool guild, pendingTransfer;
time_t paidUntil, lastWarning;
uint32_t id, owner, rentWarnings, rent, price, townId, size, syncFlags;
std::string name;
Position entry;
AccessList guestList, subOwnerList;
HouseTileList houseTiles;
HouseDoorList doorList;
HouseBedList bedsList;
};
class Houses
{
public:
virtual ~Houses() {}
static Houses* getInstance()
{
static Houses instance;
return &instance;
}
bool loadFromXml(std::string filename);
bool reloadPrices();
void payHouses();
bool payHouse(House* house, time_t _time, uint32_t bid);
bool payRent(Player* player, House* house, uint32_t bid, time_t _time = 0);
HouseMap::iterator getHouseBegin() {return houseMap.begin();}
HouseMap::iterator getHouseEnd() {return houseMap.end();}
House* getHouse(uint32_t houseId, bool add = false);
House* getHouseByPlayer(Player* player);
House* getHouseByPlayerId(uint32_t playerId);
House* getHouseByGuildId(uint32_t guildId);
uint32_t getHousesCount(uint32_t accId);
private:
Houses();
HouseMap houseMap;
RentPeriod_t rentPeriod;
friend class IOMapSerialize;
};
#endif