-
Notifications
You must be signed in to change notification settings - Fork 21
/
house.h
281 lines (219 loc) · 7.32 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
//////////////////////////////////////////////////////////////////////
// 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 <string>
#include <list>
#include <map>
#include <boost/regex.hpp>
#include "definitions.h"
#include "position.h"
#include "housetile.h"
#include "player.h"
class House;
class BedItem;
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 OTSERV_HASH_SET<uint32_t> PlayerList;
typedef OTSERV_HASH_SET<uint32_t> GuildList; //TODO: include ranks
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){ setIntAttr(ATTR_ITEM_DOORID, (uint32_t)_doorId); }
uint32_t getDoorId() const{ return getIntAttr(ATTR_ITEM_DOORID); }
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 HouseTransferItem : public Item
{
public:
static HouseTransferItem* createHouseTransferItem(House* house);
HouseTransferItem(House* _house) : Item(0) {house = _house;}
virtual ~HouseTransferItem(){}
virtual bool onTradeEvent(TradeEvents_t event, Player* owner);
House* getHouse() {return house;}
virtual bool canTransform() const {return false;}
protected:
House* house;
};
class House
{
public:
House(uint32_t _houseid);
~House();
void addTile(HouseTile* tile);
void updateDoorDescription();
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, Player* player = NULL);
uint32_t getHouseOwner() const {return houseOwner;}
void setPaidUntil(uint32_t paid){paidUntil = paid;}
uint32_t getPaidUntil() const {return paidUntil;}
void setRent(uint32_t _rent){rent = _rent;}
uint32_t getRent() const {return rent;}
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;}
uint32_t getHouseId() const {return houseid;}
void addDoor(Door* door);
void removeDoor(Door* door);
Door* getDoorByNumber(uint32_t doorId);
Door* getDoorByNumber(uint32_t doorId) const;
Door* getDoorByPosition(const Position& pos);
HouseTransferItem* getTransferItem();
void resetTransferItem();
bool executeTransfer(HouseTransferItem* item, Player* player);
HouseTileList::iterator getHouseTileBegin() {return houseTiles.begin();}
HouseTileList::iterator getHouseTileEnd() {return houseTiles.end();}
size_t getHouseTileSize() {return houseTiles.size();}
HouseDoorList::iterator getHouseDoorBegin() {return doorList.begin();}
HouseDoorList::iterator getHouseDoorEnd() {return doorList.end();}
void addBed(BedItem* bed);
HouseBedItemList::iterator getHouseBedsBegin() {return bedsList.begin();}
HouseBedItemList::iterator getHouseBedsEnd() {return bedsList.end();}
size_t getBedTiles() {return bedsList.size();}
uint32_t getBedCount() {return (uint32_t)std::ceil((double)getBedTiles() / 2);} //each bed takes 2 sqms of space, ceil is just for bad maps
private:
bool transferToDepot();
bool transferToDepot(Player* player);
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;
uint32_t paidUntil;
uint32_t rentWarnings;
uint32_t rent;
uint32_t townid;
HouseTransferItem* transferItem;
Container transfer_container;
};
typedef std::map<uint32_t, House*> HouseMap;
enum RentPeriod_t
{
RENTPERIOD_DAILY,
RENTPERIOD_WEEKLY,
RENTPERIOD_MONTHLY,
RENTPERIOD_YEARLY,
RENTPERIOD_NEVER
};
class Houses
{
Houses();
~Houses();
public:
static Houses& getInstance()
{
static Houses instance;
return instance;
}
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(const std::string& filename);
bool payHouses();
HouseMap::iterator getHouseBegin() {return houseMap.begin();}
HouseMap::iterator getHouseEnd() {return houseMap.end();}
private:
RentPeriod_t rentPeriod;
HouseMap houseMap;
};
#endif