SHARE
TWEET

house.h

a guest Aug 23rd, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ////////////////////////////////////////////////////////////////////////
  2. // OpenTibia - an opensource roleplaying game
  3. ////////////////////////////////////////////////////////////////////////
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16. ////////////////////////////////////////////////////////////////////////
  17.  
  18. #ifndef __HOUSE__
  19. #define __HOUSE__
  20. #include "otsystem.h"
  21.  
  22. #include <boost/regex.hpp>
  23. #if defined __GNUC__ && __GNUC__ >= 4
  24. #include <tr1/unordered_set>
  25. #else
  26. #include <boost/tr1/unordered_set.hpp>
  27. #endif
  28.  
  29. #include "position.h"
  30. #include "housetile.h"
  31. #include "player.h"
  32.  
  33. class House;
  34. class BedItem;
  35.  
  36. enum AccessList_t
  37. {
  38.     GUEST_LIST = 0x100,
  39.     SUBOWNER_LIST = 0x101
  40. };
  41.  
  42. enum AccessHouseLevel_t
  43. {
  44.     HOUSE_NO_INVITED = 0,
  45.     HOUSE_GUEST = 1,
  46.     HOUSE_SUBOWNER = 2,
  47.     HOUSE_OWNER = 3
  48. };
  49.  
  50. enum RentPeriod_t
  51. {
  52.     RENTPERIOD_DAILY,
  53.     RENTPERIOD_WEEKLY,
  54.     RENTPERIOD_MONTHLY,
  55.     RENTPERIOD_YEARLY,
  56.     RENTPERIOD_NEVER
  57. };
  58.  
  59. typedef std::list<HouseTile*> HouseTileList;
  60. typedef std::list<Door*> HouseDoorList;
  61. typedef std::list<BedItem*> HouseBedList;
  62. typedef std::map<uint32_t, House*> HouseMap;
  63.  
  64. class AccessList
  65. {
  66.     public:
  67.         AccessList() {}
  68.         virtual ~AccessList() {}
  69.  
  70.         bool parseList(const std::string& _list);
  71.         bool addPlayer(std::string& name);
  72.         bool addGuild(const std::string& guildName, const std::string& rankName);
  73.         bool addExpression(const std::string& expression);
  74.  
  75.         bool isInList(const Player* player);
  76.  
  77.         void getList(std::string& _list) const;
  78.  
  79.     private:
  80.         typedef std::tr1::unordered_set<uint32_t> PlayerList;
  81.         typedef std::list<std::pair<uint32_t, int32_t> > GuildList;
  82.         typedef std::list<std::string> ExpressionList;
  83.         typedef std::list<std::pair<boost::regex, bool> > RegexList;
  84.  
  85.         std::string list;
  86.         PlayerList playerList;
  87.         GuildList guildList;
  88.         ExpressionList expressionList;
  89.         RegexList regexList;
  90. };
  91.  
  92. class Door : public Item
  93. {
  94.     public:
  95.         Door(uint16_t type): Item(type), doorId(0), house(NULL), accessList(NULL) {}
  96.         virtual ~Door();
  97.  
  98.         virtual Door* getDoor() {return this;}
  99.         virtual const Door* getDoor() const {return this;}
  100.  
  101.         //serialization
  102.         virtual Attr_ReadValue readAttr(AttrTypes_t attr, PropStream& propStream);
  103.  
  104.         void setDoorId(uint8_t _doorId) {doorId = _doorId;}
  105.         uint8_t getDoorId() const {return doorId;}
  106.  
  107.         House* getHouse() {return house;}
  108.         void setHouse(House* _house);
  109.  
  110.         void setAccessList(const std::string& textList);
  111.         bool getAccessList(std::string& list) const;
  112.  
  113.         bool canUse(const Player* player);
  114.  
  115.         //overrides
  116.         virtual void onRemoved();
  117.         virtual void copyAttributes(Item* item);
  118.  
  119.     private:
  120.         uint8_t doorId;
  121.  
  122.         House* house;
  123.         AccessList* accessList;
  124. };
  125.  
  126. class TransferItem : public Item
  127. {
  128.     public:
  129.         static TransferItem* createTransferItem(House* house);
  130.  
  131.         TransferItem(House* _house): Item(0) {house = _house;}
  132.         virtual ~TransferItem() {}
  133.  
  134.         virtual bool onTradeEvent(TradeEvents_t event, Player* owner, Player* seller);
  135.         virtual bool canTransform() const {return false;}
  136.  
  137.         House* getHouse() {return house;}
  138.  
  139.     protected:
  140.         House* house;
  141. };
  142.  
  143. class House
  144. {
  145.     public:
  146.         virtual ~House() {}
  147.         enum syncflags_t
  148.         {
  149.             HOUSE_SYNC_NONE = 0,
  150.             HOUSE_SYNC_NAME = 1 << 0,
  151.             HOUSE_SYNC_TOWN = 1 << 1,
  152.             HOUSE_SYNC_SIZE = 1 << 2,
  153.             HOUSE_SYNC_GUILD = 1 << 3,
  154.             HOUSE_SYNC_PRICE = 1 << 4,
  155.             HOUSE_SYNC_RENT = 1 << 5,
  156.             HOUSE_SYNC_UPDATE = 1 << 6
  157.         };
  158.  
  159.         House(uint32_t houseId);
  160.         uint32_t getId() const {return id;}
  161.  
  162.         void setEntry(const Position& pos) {entry = pos;}
  163.         Position getEntry() const {return entry;}
  164.  
  165.         void setName(const std::string& houseName) {name = houseName;}
  166.         std::string getName() const {return name;}
  167.  
  168.         void setOwner(uint32_t guid);
  169.         bool setOwnerEx(uint32_t guid, bool transfer);
  170.         uint32_t getOwner() const {return owner;}
  171.  
  172.         void setPaidUntil(time_t paid) {paidUntil = paid;}
  173.         time_t getPaidUntil() const {return paidUntil;}
  174.  
  175.         void setRent(uint32_t _rent) {rent = _rent;}
  176.         uint32_t getRent() const {return rent;}
  177.  
  178.         void setPrice(uint32_t _price) {price = _price;}
  179.         uint32_t getPrice() const {return price;}
  180.  
  181.         void setLastWarning(time_t _lastWarning) {lastWarning = _lastWarning;}
  182.         time_t getLastWarning() const {return lastWarning;}
  183.  
  184.         void setRentWarnings(uint32_t warnings) {rentWarnings = warnings;}
  185.         uint32_t getRentWarnings() const {return rentWarnings;}
  186.  
  187.         void setTownId(uint32_t _town) {townId = _town;}
  188.         uint32_t getTownId() const {return townId;}
  189.  
  190.         void setSize(uint32_t _size) {size = _size;}
  191.         uint32_t getSize() const {return size;}
  192.  
  193.         void setPendingTransfer(bool transfer) {pendingTransfer = transfer;}
  194.         bool hasPendingTransfer() const {return pendingTransfer;}
  195.  
  196.         void setGuild(bool _guild) {guild = _guild;}
  197.         bool isGuild() const;
  198.  
  199.         uint32_t getDoorsCount() const {return doorList.size();}
  200.         uint32_t getBedsCount() const {return (uint32_t)std::ceil((double)bedsList.size() / 2);}
  201.         uint32_t getTilesCount() const {return houseTiles.size();}
  202.  
  203.         bool hasSyncFlag(syncflags_t flag) const {return ((syncFlags & (uint32_t)flag) == (uint32_t)flag);}
  204.         void setSyncFlag(syncflags_t flag) {syncFlags |= (uint32_t)flag;}
  205.         void resetSyncFlag(syncflags_t flag) {syncFlags &= ~(uint32_t)flag;}
  206.  
  207.         bool canEditAccessList(uint32_t listId, const Player* player);
  208.         void setAccessList(uint32_t listId, const std::string& textlist, bool teleport = true);
  209.         bool getAccessList(uint32_t listId, std::string& list) const;
  210.  
  211.         bool isBidded() const;
  212.         bool isInvited(const Player* player);
  213.         AccessHouseLevel_t getHouseAccessLevel(const Player* player);
  214.  
  215.         bool kickPlayer(Player* player, Player* target);
  216.         void updateDoorDescription(std::string _name = "", Door* door = NULL);
  217.         void clean();
  218.  
  219.         void addDoor(Door* door);
  220.         void removeDoor(Door* door);
  221.         HouseDoorList::iterator getHouseDoorBegin() {return doorList.begin();}
  222.         HouseDoorList::iterator getHouseDoorEnd() {return doorList.end();}
  223.  
  224.         void addBed(BedItem* bed);
  225.         HouseBedList::iterator getHouseBedsBegin() {return bedsList.begin();}
  226.         HouseBedList::iterator getHouseBedsEnd() {return bedsList.end();}
  227.  
  228.         void addTile(HouseTile* tile);
  229.         HouseTileList::iterator getHouseTileBegin() {return houseTiles.begin();}
  230.         HouseTileList::iterator getHouseTileEnd() {return houseTiles.end();}
  231.  
  232.         Door* getDoorByNumber(uint8_t doorId) const;
  233.         Door* getDoorByPosition(const Position& pos);
  234.  
  235.     private:
  236.         bool transferToDepot();
  237.  
  238.         void removePlayer(Player* player, bool ignoreRights);
  239.         void removePlayers(bool ignoreInvites);
  240.  
  241.         bool guild, pendingTransfer;
  242.         time_t paidUntil, lastWarning;
  243.         uint32_t id, owner, rentWarnings, rent, price, townId, size, syncFlags;
  244.         std::string name;
  245.         Position entry;
  246.  
  247.         AccessList guestList, subOwnerList;
  248.         HouseTileList houseTiles;
  249.         HouseDoorList doorList;
  250.         HouseBedList bedsList;
  251. };
  252.  
  253. class Houses
  254. {
  255.     public:
  256.         virtual ~Houses() {}
  257.         static Houses* getInstance()
  258.         {
  259.             static Houses instance;
  260.             return &instance;
  261.         }
  262.  
  263.         bool loadFromXml(std::string filename);
  264.  
  265.         void check();
  266.         bool payHouse(House* house, time_t _time, uint32_t bid);
  267.         bool payRent(Player* player, House* house, uint32_t bid, time_t _time = 0);
  268.  
  269.         HouseMap::iterator getHouseBegin() {return houseMap.begin();}
  270.         HouseMap::iterator getHouseEnd() {return houseMap.end();}
  271.  
  272.         House* getHouse(uint32_t houseId, bool add = false);
  273.         House* getHouseByPlayer(Player* player);
  274.  
  275.         House* getHouseByPlayerId(uint32_t playerId);
  276.         House* getHouseByGuildId(uint32_t guildId);
  277.  
  278.         uint32_t getHousesCount(uint32_t accId);
  279.         RentPeriod_t getRentPeriod() const {return rentPeriod;}
  280.  
  281.     private:
  282.         Houses();
  283.  
  284.         HouseMap houseMap;
  285.         RentPeriod_t rentPeriod;
  286.  
  287.         friend class IOMapSerialize;
  288. };
  289. #endif
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top