Advertisement
Guest User

game.h

a guest
May 17th, 2021
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 29.83 KB | None | 0 0
  1. /**
  2.  * The Forgotten Server - a free and open-source MMORPG server emulator
  3.  * Copyright (C) 2019  Mark Samman <mark.samman@gmail.com>
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License along
  16.  * with this program; if not, write to the Free Software Foundation, Inc.,
  17.  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18.  */
  19.  
  20. #ifndef FS_GAME_H_3EC96D67DD024E6093B3BAC29B7A6D7F
  21. #define FS_GAME_H_3EC96D67DD024E6093B3BAC29B7A6D7F
  22.  
  23. #include <unordered_set>
  24.  
  25. #include "account.hpp"
  26. #include "combat.h"
  27. #include "groups.h"
  28. #include "map.h"
  29. #include "position.h"
  30. #include "item.h"
  31. #include "container.h"
  32. #include "player.h"
  33. #include "raids.h"
  34. #include "npc.h"
  35. #include "wildcardtree.h"
  36. #include "gamestore.h"
  37. #include "iobestiary.h"
  38.  
  39. class ServiceManager;
  40. class Creature;
  41. class Monster;
  42. class Npc;
  43. class CombatInfo;
  44. class Charm;
  45.  
  46. enum stackPosType_t {
  47.     STACKPOS_MOVE,
  48.     STACKPOS_LOOK,
  49.     STACKPOS_TOPDOWN_ITEM,
  50.     STACKPOS_USEITEM,
  51.     STACKPOS_USETARGET,
  52.     STACKPOS_FIND_THING,
  53. };
  54.  
  55. enum WorldType_t {
  56.     WORLD_TYPE_NO_PVP = 1,
  57.     WORLD_TYPE_PVP = 2,
  58.     WORLD_TYPE_PVP_ENFORCED = 3,
  59. };
  60.  
  61. enum GameState_t {
  62.     GAME_STATE_STARTUP,
  63.     GAME_STATE_INIT,
  64.     GAME_STATE_NORMAL,
  65.     GAME_STATE_CLOSED,
  66.     GAME_STATE_SHUTDOWN,
  67.     GAME_STATE_CLOSING,
  68.     GAME_STATE_MAINTAIN,
  69. };
  70.  
  71. static constexpr int32_t EVENT_LIGHTINTERVAL_MS = 10000;
  72. static constexpr int32_t EVENT_DECAYINTERVAL = 250;
  73. static constexpr int32_t EVENT_DECAY_BUCKETS = 4;
  74. static constexpr int32_t EVENT_IMBUEMENTINTERVAL = 250;
  75. static constexpr int32_t EVENT_IMBUEMENT_BUCKETS = 4;
  76.  
  77. /**
  78.   * Main Game class.
  79.   * This class is responsible to control everything that happens
  80.   */
  81.  
  82. class Game
  83. {
  84.     public:
  85.         Game();
  86.         ~Game();
  87.  
  88.         // non-copyable
  89.         Game(const Game&) = delete;
  90.         Game& operator=(const Game&) = delete;
  91.  
  92.         void loadBoostedCreature();
  93.         void start(ServiceManager* manager);
  94.  
  95.         void forceAddCondition(uint32_t creatureId, Condition* condition);
  96.         void forceRemoveCondition(uint32_t creatureId, ConditionType_t type);
  97.  
  98.         bool loadMainMap(const std::string& filename);
  99.         void loadMap(const std::string& path);
  100.         bool loadCustomSpawnFile(const std::string& fileName);
  101.  
  102.         /**
  103.           * Get the map size - info purpose only
  104.           * \param width width of the map
  105.           * \param height height of the map
  106.           */
  107.         void getMapDimensions(uint32_t& width, uint32_t& height) const {
  108.             width = map.width;
  109.             height = map.height;
  110.         }
  111.  
  112.         void setWorldType(WorldType_t type);
  113.         WorldType_t getWorldType() const {
  114.             return worldType;
  115.         }
  116.  
  117.         std::map<uint32_t, TeamFinder*> getTeamFinderList() const {
  118.             return teamFinderMap;
  119.         }
  120.         void registerTeamFinderAssemble(uint32_t leaderGuid, TeamFinder* teamFinder) {
  121.             teamFinderMap[leaderGuid] = teamFinder;
  122.         }
  123.         void removeTeamFinderListed(uint32_t leaderGuid) {
  124.             teamFinderMap.erase(leaderGuid);
  125.         }
  126.         // Event schedule xml load
  127.         bool loadScheduleEventFromXml();
  128.  
  129.         Cylinder* internalGetCylinder(Player* player, const Position& pos) const;
  130.         Thing* internalGetThing(Player* player, const Position& pos, int32_t index,
  131.                                 uint32_t spriteId, stackPosType_t type) const;
  132.         static void internalGetPosition(Item* item, Position& pos, uint8_t& stackpos);
  133.  
  134.         static std::string getTradeErrorDescription(ReturnValue ret, Item* item);
  135.  
  136.         /**
  137.           * Returns a creature based on the unique creature identifier
  138.           * \param id is the unique creature id to get a creature pointer to
  139.           * \returns A Creature pointer to the creature
  140.           */
  141.         Creature* getCreatureByID(uint32_t id);
  142.  
  143.         /**
  144.           * Returns a monster based on the unique creature identifier
  145.           * \param id is the unique monster id to get a monster pointer to
  146.           * \returns A Monster pointer to the monster
  147.           */
  148.         Monster* getMonsterByID(uint32_t id);
  149.  
  150.         /**
  151.           * Returns a npc based on the unique creature identifier
  152.           * \param id is the unique npc id to get a npc pointer to
  153.           * \returns A NPC pointer to the npc
  154.           */
  155.         Npc* getNpcByID(uint32_t id);
  156.  
  157.         /**
  158.           * Returns a player based on the unique creature identifier
  159.           * \param id is the unique player id to get a player pointer to
  160.           * \returns A Pointer to the player
  161.           */
  162.         Player* getPlayerByID(uint32_t id);
  163.  
  164.         /**
  165.           * Returns a creature based on a string name identifier
  166.           * \param s is the name identifier
  167.           * \returns A Pointer to the creature
  168.           */
  169.         Creature* getCreatureByName(const std::string& s);
  170.  
  171.         /**
  172.           * Returns a npc based on a string name identifier
  173.           * \param s is the name identifier
  174.           * \returns A Pointer to the npc
  175.           */
  176.         Npc* getNpcByName(const std::string& s);
  177.  
  178.         /**
  179.           * Returns a player based on a string name identifier
  180.           * \param s is the name identifier
  181.           * \returns A Pointer to the player
  182.           */
  183.         Player* getPlayerByName(const std::string& s);
  184.  
  185.         /**
  186.           * Returns a player based on guid
  187.           * \returns A Pointer to the player
  188.           */
  189.         Player* getPlayerByGUID(const uint32_t& guid);
  190.  
  191.         /**
  192.           * Returns a player based on a string name identifier, with support for the "~" wildcard.
  193.           * \param s is the name identifier, with or without wildcard
  194.           * \param player will point to the found player (if any)
  195.           * \return "RETURNVALUE_PLAYERWITHTHISNAMEISNOTONLINE" or "RETURNVALUE_NAMEISTOOAMBIGIOUS"
  196.           */
  197.         ReturnValue getPlayerByNameWildcard(const std::string& s, Player*& player);
  198.  
  199.         /**
  200.           * Returns a player based on an account number identifier
  201.           * \param acc is the account identifier
  202.           * \returns A Pointer to the player
  203.           */
  204.         Player* getPlayerByAccount(uint32_t acc);
  205.  
  206.         /* Place Creature on the map without sending out events to the surrounding.
  207.           * \param creature Creature to place on the map
  208.           * \param pos The position to place the creature
  209.           * \param extendedPos If true, the creature will in first-hand be placed 2 tiles away
  210.           * \param forced If true, placing the creature will not fail because of obstacles (creatures/items)
  211.           */
  212.         bool internalPlaceCreature(Creature* creature, const Position& pos, bool extendedPos = false, bool forced = false);
  213.  
  214.         /**
  215.           * Place Creature on the map.
  216.           * \param creature Creature to place on the map
  217.           * \param pos The position to place the creature
  218.           * \param extendedPos If true, the creature will in first-hand be placed 2 tiles away
  219.           * \param force If true, placing the creature will not fail because of obstacles (creatures/items)
  220.           */
  221.         bool placeCreature(Creature* creature, const Position& pos, bool extendedPos = false, bool force = false);
  222.  
  223.         /**
  224.           * Remove Creature from the map.
  225.           * Removes the Creature the map
  226.           * \param c Creature to remove
  227.           */
  228.         bool removeCreature(Creature* creature, bool isLogout = true);
  229.         void executeDeath(uint32_t creatureId);
  230.  
  231.         void addCreatureCheck(Creature* creature);
  232.         static void removeCreatureCheck(Creature* creature);
  233.  
  234.         size_t getPlayersOnline() const {
  235.             return players.size();
  236.         }
  237.         size_t getMonstersOnline() const {
  238.             return monsters.size();
  239.         }
  240.         size_t getNpcsOnline() const {
  241.             return npcs.size();
  242.         }
  243.         uint32_t getPlayersRecord() const {
  244.             return playersRecord;
  245.         }
  246.         uint16_t getItemsPriceCount() const {
  247.             return itemsSaleCount;
  248.         }
  249.  
  250.         LightInfo getWorldLightInfo() const;
  251.  
  252.         bool gameIsDay();
  253.  
  254.         ReturnValue internalMoveCreature(Creature* creature, Direction direction, uint32_t flags = 0);
  255.         ReturnValue internalMoveCreature(Creature& creature, Tile& toTile, uint32_t flags = 0);
  256.  
  257.         ReturnValue internalMoveItem(Cylinder* fromCylinder, Cylinder* toCylinder, int32_t index,
  258.                                      Item* item, uint32_t count, Item** _moveItem, uint32_t flags = 0, Creature* actor = nullptr, Item* tradeItem = nullptr);
  259.  
  260.         ReturnValue internalAddItem(Cylinder* toCylinder, Item* item, int32_t index = INDEX_WHEREEVER,
  261.                                     uint32_t flags = 0, bool test = false);
  262.         ReturnValue internalAddItem(Cylinder* toCylinder, Item* item, int32_t index,
  263.                                     uint32_t flags, bool test, uint32_t& remainderCount);
  264.         ReturnValue internalRemoveItem(Item* item, int32_t count = -1, bool test = false, uint32_t flags = 0);
  265.  
  266.         ReturnValue internalPlayerAddItem(Player* player, Item* item, bool dropOnMap = true, slots_t slot = CONST_SLOT_WHEREEVER);
  267.  
  268.         /**
  269.           * Find an item of a certain type
  270.           * \param cylinder to search the item
  271.           * \param itemId is the item to remove
  272.           * \param subType is the extra type an item can have such as charges/fluidtype, default is -1
  273.             * meaning it's not used
  274.           * \param depthSearch if true it will check child containers aswell
  275.           * \returns A pointer to the item to an item and nullptr if not found
  276.           */
  277.         Item* findItemOfType(Cylinder* cylinder, uint16_t itemId,
  278.                              bool depthSearch = true, int32_t subType = -1) const;
  279.  
  280.         /**
  281.           * Remove/Add item(s) with a monetary value
  282.           * \param cylinder to remove the money from
  283.           * \param money is the amount to remove
  284.           * \param flags optional flags to modifiy the default behaviour
  285.           * \returns true if the removal was successful
  286.           */
  287.         bool removeMoney(Cylinder* cylinder, uint64_t money, uint32_t flags = 0, bool useBank = false);
  288.  
  289.         /**
  290.           * Add item(s) with monetary value
  291.           * \param cylinder which will receive money
  292.           * \param money the amount to give
  293.           * \param flags optional flags to modify default behavior
  294.           */
  295.         void addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags = 0);
  296.  
  297.         /**
  298.           * Transform one item to another type/count
  299.           * \param item is the item to transform
  300.           * \param newId is the new itemid
  301.           * \param newCount is the new count value, use default value (-1) to not change it
  302.           * \returns true if the tranformation was successful
  303.           */
  304.         Item* transformItem(Item* item, uint16_t newId, int32_t newCount = -1);
  305.  
  306.         /**
  307.           * Teleports an object to another position
  308.           * \param thing is the object to teleport
  309.           * \param newPos is the new position
  310.           * \param pushMove force teleport if false
  311.           * \param flags optional flags to modify default behavior
  312.           * \returns true if the teleportation was successful
  313.           */
  314.         ReturnValue internalTeleport(Thing* thing, const Position& newPos, bool pushMove = true, uint32_t flags = 0);
  315.  
  316.         /**
  317.           * Turn a creature to a different direction.
  318.           * \param creature Creature to change the direction
  319.           * \param dir Direction to turn to
  320.           */
  321.         bool internalCreatureTurn(Creature* creature, Direction dir);
  322.  
  323.         /**
  324.           * Creature wants to say something.
  325.           * \param creature Creature pointer
  326.           * \param type Type of message
  327.           * \param text The text to say
  328.           */
  329.         bool internalCreatureSay(Creature* creature, SpeakClasses type, const std::string& text,
  330.                                  bool ghostMode, SpectatorHashSet* spectatorsPtr = nullptr, const Position* pos = nullptr);
  331.  
  332.         /**
  333.           * Player wants to loot a corpse
  334.           * \param player Player pointer
  335.           * \param corpse Container pointer to be looted
  336.           */
  337.         void internalQuickLootCorpse(Player* player, Container* corpse);
  338.  
  339.         /**
  340.           * Player wants to loot a single item
  341.           * \param player Player pointer
  342.           * \param item Item pointer to be looted
  343.           * \param category Category of the item
  344.           * \returns true if the looting was successful
  345.           */
  346.         ReturnValue internalQuickLootItem(Player* player, Item* item,
  347.                                     ObjectCategory_t category = OBJECTCATEGORY_DEFAULT);
  348.  
  349.         ObjectCategory_t getObjectCategory(const Item* item);
  350.  
  351.         void loadPlayersRecord();
  352.         void checkPlayersRecord();
  353.  
  354.         void sendGuildMotd(uint32_t playerId);
  355.         void kickPlayer(uint32_t playerId, bool displayEffect);
  356.         void playerReportBug(uint32_t playerId, const std::string& message, const Position& position, uint8_t category);
  357.         void playerDebugAssert(uint32_t playerId, const std::string& assertLine, const std::string& date, const std::string& description, const std::string& comment);
  358.         void playerNpcGreet(uint32_t playerId, uint32_t npcId);
  359.         void playerAnswerModalWindow(uint32_t playerId, uint32_t modalWindowId, uint8_t button, uint8_t choice);
  360.         void playerReportRuleViolationReport(uint32_t playerId, const std::string& targetName, uint8_t reportType, uint8_t reportReason, const std::string& comment, const std::string& translation);
  361.  
  362.         void playerCyclopediaCharacterInfo(Player* player, uint32_t characterID, CyclopediaCharacterInfoType_t characterInfoType, uint16_t entriesPerPage, uint16_t page);
  363.  
  364.         void playerHighscores(Player* player, HighscoreType_t type, uint8_t category, uint32_t vocation, const std::string& worldName, uint16_t page, uint8_t entriesPerPage);
  365.  
  366.         void playerTournamentLeaderboard(uint32_t playerId, uint8_t leaderboardType);
  367.  
  368.         void updatePlayerSaleItems(uint32_t playerId);
  369.  
  370.         bool internalStartTrade(Player* player, Player* partner, Item* tradeItem);
  371.         void internalCloseTrade(Player* player);
  372.         bool playerBroadcastMessage(Player* player, const std::string& text) const;
  373.         void broadcastMessage(const std::string& text, MessageClasses type) const;
  374.  
  375.         //Implementation of player invoked events
  376.         void playerTeleport(uint32_t playerId, const Position& pos);
  377.         void playerMoveThing(uint32_t playerId, const Position& fromPos, uint16_t spriteId, uint8_t fromStackPos,
  378.                              const Position& toPos, uint8_t count);
  379.         void playerMoveCreatureByID(uint32_t playerId, uint32_t movingCreatureId, const Position& movingCreatureOrigPos, const Position& toPos);
  380.         void playerMoveCreature(Player* playerId, Creature* movingCreature, const Position& movingCreatureOrigPos, Tile* toTile);
  381.         void playerMoveItemByPlayerID(uint32_t playerId, const Position& fromPos, uint16_t spriteId, uint8_t fromStackPos, const Position& toPos, uint8_t count);
  382.         void playerMoveItem(Player* player, const Position& fromPos,
  383.                             uint16_t spriteId, uint8_t fromStackPos, const Position& toPos, uint8_t count, Item* item, Cylinder* toCylinder);
  384.         void playerEquipItem(uint32_t playerId, uint16_t spriteId);
  385.         void playerMove(uint32_t playerId, Direction direction);
  386.         void playerCreatePrivateChannel(uint32_t playerId);
  387.         void playerChannelInvite(uint32_t playerId, const std::string& name);
  388.         void playerChannelExclude(uint32_t playerId, const std::string& name);
  389.         void playerRequestChannels(uint32_t playerId);
  390.         void playerOpenChannel(uint32_t playerId, uint16_t channelId);
  391.         void playerCloseChannel(uint32_t playerId, uint16_t channelId);
  392.         void playerOpenPrivateChannel(uint32_t playerId, std::string& receiver);
  393.         void playerStowItem(Player* player, const Position& pos, uint16_t spriteId, uint8_t stackpos, uint8_t count, bool allItems);
  394.         void playerStashWithdraw(Player* player, uint16_t spriteId, uint32_t count, uint8_t stackpos);
  395.         void playerCloseNpcChannel(uint32_t playerId);
  396.         void playerReceivePing(uint32_t playerId);
  397.         void playerReceivePingBack(uint32_t playerId);
  398.         void playerAutoWalk(uint32_t playerId, const std::forward_list<Direction>& listDir);
  399.         void playerStopAutoWalk(uint32_t playerId);
  400.         void playerUseItemEx(uint32_t playerId, const Position& fromPos, uint8_t fromStackPos,
  401.                              uint16_t fromSpriteId, const Position& toPos, uint8_t toStackPos, uint16_t toSpriteId);
  402.         void playerUseItem(uint32_t playerId, const Position& pos, uint8_t stackPos, uint8_t index, uint16_t spriteId);
  403.         void playerUseWithCreature(uint32_t playerId, const Position& fromPos, uint8_t fromStackPos, uint32_t creatureId, uint16_t spriteId);
  404.         void playerCloseContainer(uint32_t playerId, uint8_t cid);
  405.         void playerMoveUpContainer(uint32_t playerId, uint8_t cid);
  406.         void playerUpdateContainer(uint32_t playerId, uint8_t cid);
  407.         void playerRotateItem(uint32_t playerId, const Position& pos, uint8_t stackPos, const uint16_t spriteId);
  408.         void playerConfigureShowOffSocket(uint32_t playerId, const Position& pos, uint8_t stackPos, const uint16_t spriteId);
  409.         void playerSetShowOffSocket(uint32_t playerId, Outfit_t& outfit, const Position& pos, uint8_t stackPos, const uint16_t spriteId, uint8_t podiumVisible, uint8_t direction);
  410.         void playerWrapableItem(uint32_t playerId, const Position& pos, uint8_t stackPos, const uint16_t spriteId);
  411.         void playerWriteItem(uint32_t playerId, uint32_t windowTextId, const std::string& text);
  412.         void playerBrowseField(uint32_t playerId, const Position& pos);
  413.         void playerSeekInContainer(uint32_t playerId, uint8_t containerId, uint16_t index);
  414.         void playerUpdateHouseWindow(uint32_t playerId, uint8_t listId, uint32_t windowTextId, const std::string& text);
  415.         void playerRequestTrade(uint32_t playerId, const Position& pos, uint8_t stackPos,
  416.                                 uint32_t tradePlayerId, uint16_t spriteId);
  417.         void playerAcceptTrade(uint32_t playerId);
  418.         void playerLookInTrade(uint32_t playerId, bool lookAtCounterOffer, uint8_t index);
  419.         void playerPurchaseItem(uint32_t playerId, uint16_t spriteId, uint8_t count, uint8_t amount,
  420.                                 bool ignoreCap = false, bool inBackpacks = false);
  421.         void playerSellItem(uint32_t playerId, uint16_t spriteId, uint8_t count,
  422.                                 uint8_t amount, bool ignoreEquipped = false);
  423.         void playerCloseShop(uint32_t playerId);
  424.         void playerLookInShop(uint32_t playerId, uint16_t spriteId, uint8_t count);
  425.         void playerCloseTrade(uint32_t playerId);
  426.         void playerSetAttackedCreature(uint32_t playerId, uint32_t creatureId);
  427.         void playerFollowCreature(uint32_t playerId, uint32_t creatureId);
  428.         void playerCancelAttackAndFollow(uint32_t playerId);
  429.         void playerSetFightModes(uint32_t playerId, fightMode_t fightMode, bool chaseMode, bool secureMode);
  430.         void playerLookAt(uint32_t playerId, const Position& pos, uint8_t stackPos);
  431.         void playerLookInBattleList(uint32_t playerId, uint32_t creatureId);
  432.         void playerQuickLoot(uint32_t playerId, const Position& pos,
  433.                                 uint16_t spriteId, uint8_t stackPos, Item* defaultItem = nullptr);
  434.         void playerSetLootContainer(uint32_t playerId, ObjectCategory_t category,
  435.                                 const Position& pos, uint16_t spriteId, uint8_t stackPos);
  436.         void playerClearLootContainer(uint32_t playerId, ObjectCategory_t category);;
  437.         void playerOpenLootContainer(uint32_t playerId, ObjectCategory_t category);
  438.         void playerSetQuickLootFallback(uint32_t playerId, bool fallback);
  439.         void playerQuickLootBlackWhitelist(uint32_t playerId,
  440.                                 QuickLootFilter_t filter, std::vector<uint16_t> clientIds);
  441.         void playerRequestLockFind(uint32_t playerId);
  442.         void playerRequestAddVip(uint32_t playerId, const std::string& name);
  443.         void playerRequestRemoveVip(uint32_t playerId, uint32_t guid);
  444.         void playerRequestEditVip(uint32_t playerId, uint32_t guid, const std::string& description, uint32_t icon, bool notify);
  445.         void playerApplyImbuement(uint32_t playerId, uint32_t imbuementid, uint8_t slot, bool protectionCharm);
  446.         void playerClearingImbuement(uint32_t playerid, uint8_t slot);
  447.         void playerCloseImbuingWindow(uint32_t playerid);
  448.         void playerTurn(uint32_t playerId, Direction dir);
  449.         void playerRequestOutfit(uint32_t playerId);
  450.         void playerShowQuestLog(uint32_t playerId);
  451.         void playerShowQuestLine(uint32_t playerId, uint16_t questId);
  452.         void playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type,
  453.                        const std::string& receiver, const std::string& text);
  454.         void playerChangeOutfit(uint32_t playerId, Outfit_t outfit);
  455.         void playerInviteToParty(uint32_t playerId, uint32_t invitedId);
  456.         void playerJoinParty(uint32_t playerId, uint32_t leaderId);
  457.         void playerRevokePartyInvitation(uint32_t playerId, uint32_t invitedId);
  458.         void playerPassPartyLeadership(uint32_t playerId, uint32_t newLeaderId);
  459.         void playerLeaveParty(uint32_t playerId);
  460.         void playerEnableSharedPartyExperience(uint32_t playerId, bool sharedExpActive);
  461.         void playerToggleMount(uint32_t playerId, bool mount);
  462.         void playerLeaveMarket(uint32_t playerId);
  463.         void playerBrowseMarket(uint32_t playerId, uint16_t spriteId);
  464.         void playerBrowseMarketOwnOffers(uint32_t playerId);
  465.         void playerBrowseMarketOwnHistory(uint32_t playerId);
  466.         void playerCreateMarketOffer(uint32_t playerId, uint8_t type, uint16_t spriteId, uint16_t amount, uint32_t price, bool anonymous);
  467.         void playerCancelMarketOffer(uint32_t playerId, uint32_t timestamp, uint16_t counter);
  468.         void playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16_t counter, uint16_t amount);
  469.         void playerStoreOpen(uint32_t playerId, uint8_t serviceType);
  470.         void playerShowStoreCategoryOffers(uint32_t playerId, StoreCategory* category);
  471.         void playerBuyStoreOffer(uint32_t playerId, uint32_t offerId, uint8_t productType, const std::string& additionalInfo="");
  472.         void playerCoinTransfer(uint32_t playerId, const std::string& receiverName, uint32_t amount);
  473.         void playerStoreTransactionHistory(uint32_t playerId, uint32_t page);
  474.  
  475.         void parsePlayerExtendedOpcode(uint32_t playerId, uint8_t opcode, const std::string& buffer);
  476.  
  477.         std::forward_list<Item*> getMarketItemList(uint16_t wareId, uint16_t sufficientCount, DepotLocker* depotLocker);
  478.  
  479.         static void updatePremium(account::Account& account);
  480.  
  481.         void cleanup();
  482.         void shutdown();
  483.         void ReleaseCreature(Creature* creature);
  484.         void ReleaseItem(Item* item);
  485.         void addBestiaryList(uint16_t raceid, std::string name);
  486.         const std::map<uint16_t, std::string>& getBestiaryList() const { return BestiaryList; }
  487.  
  488.         void setBoostedName(std::string name) {
  489.             boostedCreature = name;
  490.         }
  491.  
  492.         std::string getBoostedName() const {
  493.             return boostedCreature;
  494.         }
  495.  
  496.         void onPressHotkeyEquip(Player* player, uint16_t spriteid);
  497.  
  498.         bool canThrowObjectTo(const Position& fromPos, const Position& toPos, bool checkLineOfSight = true,
  499.                               int32_t rangex = Map::maxClientViewportX, int32_t rangey = Map::maxClientViewportY) const;
  500.         bool isSightClear(const Position& fromPos, const Position& toPos, bool sameFloor) const;
  501.  
  502.         void changeSpeed(Creature* creature, int32_t varSpeedDelta);
  503.         void internalCreatureChangeOutfit(Creature* creature, const Outfit_t& oufit);
  504.         void internalCreatureChangeVisible(Creature* creature, bool visible);
  505.         void changeLight(const Creature* creature);
  506.         void updateCreatureIcon(const Creature* creature);
  507.         void updateCreatureSkull(const Creature* player);
  508.         void updatePlayerShield(Player* player);
  509.         void updateCreatureType(Creature* creature);
  510.         void updateCreatureWalkthrough(const Creature* creature);
  511.  
  512.         GameState_t getGameState() const;
  513.         void setGameState(GameState_t newState);
  514.         void saveGameState();
  515.  
  516.         //Events
  517.         void checkCreatureWalk(uint32_t creatureId);
  518.         void updateCreatureWalk(uint32_t creatureId);
  519.         void checkCreatureAttack(uint32_t creatureId);
  520.         void checkCreatures(size_t index);
  521.         void checkLight();
  522.  
  523.         bool combatBlockHit(CombatDamage& damage, Creature* attacker, Creature* target, bool checkDefense, bool checkArmor, bool field);
  524.  
  525.         void combatGetTypeInfo(CombatType_t combatType, Creature* target, TextColor_t& color, uint8_t& effect);
  526.  
  527.         bool combatChangeHealth(Creature* attacker, Creature* target, CombatDamage& damage, bool isEvent = false);
  528.         bool combatChangeMana(Creature* attacker, Creature* target, CombatDamage& damage);
  529.  
  530.         //animation help functions
  531.         void addCreatureHealth(const Creature* target);
  532.         static void addCreatureHealth(const SpectatorHashSet& spectators, const Creature* target);
  533.         void addPlayerMana(const Player* target);
  534.         void addPlayerVocation(const Player* target);
  535.         void addMagicEffect(const Position& pos, uint8_t effect);
  536.         static void addMagicEffect(const SpectatorHashSet& spectators, const Position& pos, uint8_t effect);
  537.         void addDistanceEffect(const Position& fromPos, const Position& toPos, uint8_t effect);
  538.         static void addDistanceEffect(const SpectatorHashSet& spectators, const Position& fromPos, const Position& toPos, uint8_t effect);
  539.  
  540.         void startImbuementCountdown(Item* item) {
  541.             item->incrementReferenceCounter();
  542.             toImbuedItems.push_front(item);
  543.         }
  544.  
  545.         void startDecay(Item* item);
  546.         int32_t getLightHour() const {
  547.             return lightHour;
  548.         }
  549.  
  550.         bool loadItemsPrice();
  551.  
  552.         void loadMotdNum();
  553.         void saveMotdNum() const;
  554.         const std::string& getMotdHash() const { return motdHash; }
  555.         uint32_t getMotdNum() const { return motdNum; }
  556.         void incrementMotdNum() { motdNum++; }
  557.  
  558.         void sendOfflineTrainingDialog(Player* player);
  559.  
  560.         const std::map<uint16_t, uint32_t>& getItemsPrice() const { return itemsPriceMap; }
  561.         const std::unordered_map<uint32_t, Player*>& getPlayers() const { return players; }
  562.         const std::map<uint32_t, Npc*>& getNpcs() const { return npcs; }
  563.  
  564.         void addPlayer(Player* player);
  565.         void removePlayer(Player* player);
  566.  
  567.         void addNpc(Npc* npc);
  568.         void removeNpc(Npc* npc);
  569.  
  570.         void addMonster(Monster* npc);
  571.         void removeMonster(Monster* npc);
  572.  
  573.         Guild* getGuild(uint32_t id) const;
  574.         void addGuild(Guild* guild);
  575.         void removeGuild(uint32_t guildId);
  576.         void decreaseBrowseFieldRef(const Position& pos);
  577.  
  578.         std::unordered_map<Tile*, Container*> browseFields;
  579.  
  580.         void internalRemoveItems(std::vector<Item*> itemList, uint32_t amount, bool stackable);
  581.  
  582.         BedItem* getBedBySleeper(uint32_t guid) const;
  583.         void setBedSleeper(BedItem* bed, uint32_t guid);
  584.         void removeBedSleeper(uint32_t guid);
  585.  
  586.         Item* getUniqueItem(uint16_t uniqueId);
  587.         bool addUniqueItem(uint16_t uniqueId, Item* item);
  588.         void removeUniqueItem(uint16_t uniqueId);
  589.  
  590.         bool reload(ReloadTypes_t reloadType);
  591.  
  592.         bool itemidHasMoveevent(uint32_t itemid);
  593.         bool hasEffect(uint8_t effectId);
  594.         bool hasDistanceEffect(uint8_t effectId);
  595.  
  596.         Groups groups;
  597.         Map map;
  598.         Mounts mounts;
  599.         Raids raids;
  600.         GameStore gameStore;
  601.  
  602.         std::forward_list<Item*> toDecayItems;
  603.  
  604.         std::unordered_set<Tile*> getTilesToClean() const {
  605.             return tilesToClean;
  606.         }
  607.         void addTileToClean(Tile* tile) {
  608.             tilesToClean.emplace(tile);
  609.         }
  610.         void removeTileToClean(Tile* tile) {
  611.             tilesToClean.erase(tile);
  612.         }
  613.         void clearTilesToClean() {
  614.             tilesToClean.clear();
  615.         }
  616.  
  617.         std::forward_list<Item*> toImbuedItems;
  618.  
  619.         // Event schedule
  620.         uint16_t getExpSchedule() const {
  621.             return expSchedule;
  622.         }
  623.         void setExpSchedule(uint16_t exprate) {
  624.             expSchedule = (expSchedule * exprate)/100;
  625.         }
  626.  
  627.         uint16_t getLootSchedule() const {
  628.             return lootSchedule;
  629.         }
  630.         void setLootSchedule(uint16_t lootrate) {
  631.             lootSchedule = (lootSchedule * lootrate)/100;
  632.         }
  633.  
  634.         uint32_t getSpawnSchedule() const {
  635.             return spawnSchedule;
  636.         }
  637.         void setSpawnSchedule(uint32_t spawnrate) {
  638.             spawnSchedule = (spawnSchedule * spawnrate)/100;
  639.         }
  640.  
  641.         uint16_t getSkillSchedule() const {
  642.             return skillSchedule;
  643.         }
  644.         void setSkillSchedule(uint16_t skillrate) {
  645.             skillSchedule = (skillSchedule * skillrate)/100;
  646.         }
  647.  
  648.         void playerInspectItem(Player* player, const Position& pos);
  649.         void playerInspectItem(Player* player, uint16_t itemId, uint8_t itemCount, bool cyclopedia);
  650.  
  651.         void addCharmRune(Charm* charm)
  652.         {
  653.             CharmList.push_back(charm);
  654.             CharmList.shrink_to_fit();
  655.         }
  656.  
  657.         std::vector<Charm*> getCharmList() {
  658.             return CharmList;
  659.         }
  660.  
  661.     private:
  662.         void checkImbuements();
  663.         bool playerSaySpell(Player* player, SpeakClasses type, const std::string& text);
  664.         void playerWhisper(Player* player, const std::string& text);
  665.         bool playerYell(Player* player, const std::string& text);
  666.         bool playerSpeakTo(Player* player, SpeakClasses type, const std::string& receiver, const std::string& text);
  667.         void playerSpeakToNpc(Player* player, const std::string& text);
  668.  
  669.         void checkDecay();
  670.         void internalDecayItem(Item* item);
  671.  
  672.         std::unordered_map<uint32_t, Player*> players;
  673.         std::unordered_map<std::string, Player*> mappedPlayerNames;
  674.         std::unordered_map<uint32_t, Guild*> guilds;
  675.         std::unordered_map<uint16_t, Item*> uniqueItems;
  676.         std::map<uint32_t, uint32_t> stages;
  677.  
  678.         std::list<Item*> decayItems[EVENT_DECAY_BUCKETS];
  679.         std::list<Creature*> checkCreatureLists[EVENT_CREATURECOUNT];
  680.  
  681.         std::list<Item*> imbuedItems[EVENT_IMBUEMENT_BUCKETS];
  682.  
  683.         std::map<uint16_t, std::string> BestiaryList;
  684.         std::string boostedCreature = "";
  685.  
  686.         std::vector<Charm*> CharmList;
  687.         std::vector<Creature*> ToReleaseCreatures;
  688.         std::vector<Item*> ToReleaseItems;
  689.  
  690.         size_t lastBucket = 0;
  691.         size_t lastImbuedBucket = 0;
  692.  
  693.         WildcardTreeNode wildcardTree { false };
  694.  
  695.         std::map<uint32_t, Npc*> npcs;
  696.         std::map<uint32_t, Monster*> monsters;
  697.  
  698.         std::map<uint32_t, TeamFinder*> teamFinderMap; // [leaderGUID] = TeamFinder*
  699.  
  700.         //list of items that are in trading state, mapped to the player
  701.         std::map<Item*, uint32_t> tradeItems;
  702.  
  703.         std::map<uint32_t, BedItem*> bedSleepersMap;
  704.  
  705.         std::unordered_set<Tile*> tilesToClean;
  706.  
  707.         ModalWindow offlineTrainingWindow { std::numeric_limits<uint32_t>::max(), "Choose a Skill", "Please choose a skill:" };
  708.  
  709.         static constexpr int32_t DAY_LENGTH_SECONDS = 3600;
  710.         static constexpr int32_t LIGHT_DAY_LENGTH = 1440;
  711.         static constexpr int32_t LIGHT_LEVEL_DAY = 250;
  712.         static constexpr int32_t LIGHT_LEVEL_NIGHT = 40;
  713.         static constexpr int32_t SUNSET = 1050;
  714.         static constexpr int32_t SUNRISE = 360;
  715.  
  716.         bool isDay = false;
  717.  
  718.         GameState_t gameState = GAME_STATE_NORMAL;
  719.         WorldType_t worldType = WORLD_TYPE_PVP;
  720.  
  721.         // Event schedule
  722.         uint16_t expSchedule = 100;
  723.         uint16_t lootSchedule = 100;
  724.         uint16_t skillSchedule = 100;
  725.         uint32_t spawnSchedule = 100;
  726.  
  727.         LightState_t lightState = LIGHT_STATE_DAY;
  728.         LightState_t currentLightState = lightState;
  729.         uint8_t lightLevel = LIGHT_LEVEL_DAY;
  730.         int32_t lightHour = SUNRISE + (SUNSET - SUNRISE) / 2;
  731.         // (1440 total light of tibian day)/(3600 real seconds each tibian day) * 10 seconds event interval
  732.         int32_t lightHourDelta = (LIGHT_DAY_LENGTH * (EVENT_LIGHTINTERVAL_MS/1000)) / DAY_LENGTH_SECONDS;
  733.  
  734.         ServiceManager* serviceManager = nullptr;
  735.  
  736.         void updatePlayersRecord() const;
  737.         uint32_t playersRecord = 0;
  738.  
  739.         std::string motdHash;
  740.         uint32_t motdNum = 0;
  741.  
  742.         std::map<uint16_t, uint32_t> itemsPriceMap;
  743.         uint16_t itemsSaleCount;
  744. };
  745.  
  746. #endif
  747.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement