Advertisement
Guest User

player.h

a guest
Oct 1st, 2017
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.45 KB | None | 0 0
  1. /**
  2. * The Forgotten Server - a free and open-source MMORPG server emulator
  3. * Copyright (C) 2017 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_PLAYER_H_4083D3D3A05B4EDE891B31BB720CD06F
  21. #define FS_PLAYER_H_4083D3D3A05B4EDE891B31BB720CD06F
  22.  
  23. #include "creature.h"
  24. #include "container.h"
  25. #include "cylinder.h"
  26. #include "outfit.h"
  27. #include "enums.h"
  28. #include "vocation.h"
  29. #include "protocolgame.h"
  30. #include "ioguild.h"
  31. #include "party.h"
  32. #include "inbox.h"
  33. #include "depotchest.h"
  34. #include "depotlocker.h"
  35. #include "guild.h"
  36. #include "groups.h"
  37. #include "town.h"
  38. #include "reward.h"
  39. #include "rewardchest.h"
  40.  
  41. class House;
  42. class NetworkMessage;
  43. class Weapon;
  44. class ProtocolGame;
  45. class Npc;
  46. class Party;
  47. class SchedulerTask;
  48. class Bed;
  49. class Guild;
  50.  
  51. enum skillsid_t {
  52. SKILLVALUE_LEVEL = 0,
  53. SKILLVALUE_TRIES = 1,
  54. SKILLVALUE_PERCENT = 2,
  55. };
  56.  
  57. enum fightMode_t : uint8_t {
  58. FIGHTMODE_ATTACK = 1,
  59. FIGHTMODE_BALANCED = 2,
  60. FIGHTMODE_DEFENSE = 3,
  61. };
  62.  
  63. enum tradestate_t : uint8_t {
  64. TRADE_NONE,
  65. TRADE_INITIATED,
  66. TRADE_ACCEPT,
  67. TRADE_ACKNOWLEDGE,
  68. TRADE_TRANSFER,
  69. };
  70.  
  71. struct VIPEntry {
  72. VIPEntry(uint32_t guid, std::string name, std::string description, uint32_t icon, bool notify) :
  73. guid(guid), name(std::move(name)), description(std::move(description)), icon(icon), notify(notify) {}
  74.  
  75. uint32_t guid;
  76. std::string name;
  77. std::string description;
  78. uint32_t icon;
  79. bool notify;
  80. };
  81.  
  82. struct OpenContainer {
  83. Container* container;
  84. uint16_t index;
  85. };
  86.  
  87. struct OutfitEntry {
  88. constexpr OutfitEntry(uint16_t lookType, uint8_t addons) : lookType(lookType), addons(addons) {}
  89.  
  90. uint16_t lookType;
  91. uint8_t addons;
  92. };
  93.  
  94. struct Skill {
  95. uint64_t tries = 0;
  96. uint16_t level = 10;
  97. uint8_t percent = 0;
  98. };
  99.  
  100. using MuteCountMap = std::map<uint32_t, uint32_t>;
  101.  
  102. static constexpr int32_t PLAYER_MAX_SPEED = 1500;
  103. static constexpr int32_t PLAYER_MIN_SPEED = 10;
  104.  
  105. class Player final : public Creature, public Cylinder
  106. {
  107. public:
  108. explicit Player(ProtocolGame_ptr p);
  109. ~Player();
  110.  
  111. // non-copyable
  112. Player(const Player&) = delete;
  113. Player& operator=(const Player&) = delete;
  114.  
  115. Player* getPlayer() final {
  116. return this;
  117. }
  118. const Player* getPlayer() const final {
  119. return this;
  120. }
  121.  
  122. void setID() final {
  123. if (id == 0) {
  124. id = playerAutoID++;
  125. }
  126. }
  127.  
  128. static MuteCountMap muteCountMap;
  129.  
  130. const std::string& getName() const final {
  131. return name;
  132. }
  133. void setName(std::string name) {
  134. this->name = std::move(name);
  135. }
  136. const std::string& getNameDescription() const final {
  137. return name;
  138. }
  139. std::string getDescription(int32_t lookDistance) const final;
  140.  
  141. CreatureType_t getType() const final {
  142. return CREATURETYPE_PLAYER;
  143. }
  144.  
  145. void sendFYIBox(const std::string& message) {
  146. if (client) {
  147. client->sendFYIBox(message);
  148. }
  149. }
  150.  
  151. void setGUID(uint32_t guid) {
  152. this->guid = guid;
  153. }
  154. uint32_t getGUID() const {
  155. return guid;
  156. }
  157. bool canSeeInvisibility() const final {
  158. return hasFlag(PlayerFlag_CanSenseInvisibility) || group->access;
  159. }
  160.  
  161. void removeList() final;
  162. void addList() final;
  163. void kickPlayer(bool displayEffect);
  164.  
  165. static uint64_t getExpForLevel(int32_t lv) {
  166. lv--;
  167. return ((50ULL * lv * lv * lv) - (150ULL * lv * lv) + (400ULL * lv)) / 3ULL;
  168. }
  169.  
  170. uint16_t getStaminaMinutes() const {
  171. return staminaMinutes;
  172. }
  173.  
  174. bool addOfflineTrainingTries(skills_t skill, uint64_t tries);
  175.  
  176. void addOfflineTrainingTime(int32_t addTime) {
  177. offlineTrainingTime = std::min<int32_t>(12 * 3600 * 1000, offlineTrainingTime + addTime);
  178. }
  179. void removeOfflineTrainingTime(int32_t removeTime) {
  180. offlineTrainingTime = std::max<int32_t>(0, offlineTrainingTime - removeTime);
  181. }
  182. int32_t getOfflineTrainingTime() const {
  183. return offlineTrainingTime;
  184. }
  185.  
  186. int32_t getOfflineTrainingSkill() const {
  187. return offlineTrainingSkill;
  188. }
  189. void setOfflineTrainingSkill(int32_t skill) {
  190. offlineTrainingSkill = skill;
  191. }
  192.  
  193. uint64_t getBankBalance() const {
  194. return bankBalance;
  195. }
  196. void setBankBalance(uint64_t balance) {
  197. bankBalance = balance;
  198. }
  199.  
  200. Guild* getGuild() const {
  201. return guild;
  202. }
  203. void setGuild(Guild* guild);
  204.  
  205. const GuildRank* getGuildRank() const {
  206. return guildRank;
  207. }
  208. void setGuildRank(const GuildRank* newGuildRank) {
  209. guildRank = newGuildRank;
  210. }
  211.  
  212. bool isGuildMate(const Player* player) const;
  213.  
  214. const std::string& getGuildNick() const {
  215. return guildNick;
  216. }
  217. void setGuildNick(std::string nick) {
  218. guildNick = nick;
  219. }
  220.  
  221. bool isInWar(const Player* player) const;
  222. bool isInWarList(uint32_t guild_id) const;
  223.  
  224. void setLastWalkthroughAttempt(int64_t walkthroughAttempt) {
  225. lastWalkthroughAttempt = walkthroughAttempt;
  226. }
  227. void setLastWalkthroughPosition(Position walkthroughPosition) {
  228. lastWalkthroughPosition = walkthroughPosition;
  229. }
  230.  
  231. Inbox* getInbox() const {
  232. return inbox;
  233. }
  234.  
  235. uint16_t getClientIcons() const;
  236.  
  237. const GuildWarVector& getGuildWarVector() const {
  238. return guildWarVector;
  239. }
  240.  
  241. Vocation* getVocation() const {
  242. return vocation;
  243. }
  244.  
  245. OperatingSystem_t getOperatingSystem() const {
  246. return operatingSystem;
  247. }
  248. void setOperatingSystem(OperatingSystem_t clientos) {
  249. operatingSystem = clientos;
  250. }
  251.  
  252. uint16_t getProtocolVersion() const {
  253. if (!client) {
  254. return 0;
  255. }
  256.  
  257. return client->getVersion();
  258. }
  259.  
  260. bool hasSecureMode() const {
  261. return secureMode;
  262. }
  263.  
  264. void setParty(Party* party) {
  265. this->party = party;
  266. }
  267. Party* getParty() const {
  268. return party;
  269. }
  270. PartyShields_t getPartyShield(const Player* player) const;
  271. bool isInviting(const Player* player) const;
  272. bool isPartner(const Player* player) const;
  273. void sendPlayerPartyIcons(Player* player);
  274. bool addPartyInvitation(Party* party);
  275. void removePartyInvitation(Party* party);
  276. void clearPartyInvitations();
  277.  
  278. GuildEmblems_t getGuildEmblem(const Player* player) const;
  279.  
  280. uint64_t getSpentMana() const {
  281. return manaSpent;
  282. }
  283.  
  284. bool hasFlag(PlayerFlags value) const {
  285. return (group->flags & value) != 0;
  286. }
  287.  
  288. BedItem* getBedItem() {
  289. return bedItem;
  290. }
  291. void setBedItem(BedItem* b) {
  292. bedItem = b;
  293. }
  294.  
  295. void addBlessing(uint8_t blessing) {
  296. blessings |= blessing;
  297. }
  298. void removeBlessing(uint8_t blessing) {
  299. blessings &= ~blessing;
  300. }
  301. bool hasBlessing(uint8_t value) const {
  302. return (blessings & (static_cast<uint8_t>(1) << value)) != 0;
  303. }
  304.  
  305. bool isOffline() const {
  306. return (getID() == 0);
  307. }
  308. void disconnect() {
  309. if (client) {
  310. client->disconnect();
  311. }
  312. }
  313. uint32_t getIP() const;
  314.  
  315. void addContainer(uint8_t cid, Container* container);
  316. void closeContainer(uint8_t cid);
  317. void setContainerIndex(uint8_t cid, uint16_t index);
  318.  
  319. Container* getContainerByID(uint8_t cid);
  320. int8_t getContainerID(const Container* container) const;
  321. uint16_t getContainerIndex(uint8_t cid) const;
  322.  
  323. bool canOpenCorpse(uint32_t ownerId) const;
  324.  
  325. void addStorageValue(const uint32_t key, const int32_t value, const bool isLogin = false);
  326. bool getStorageValue(const uint32_t key, int32_t& value) const;
  327. void genReservedStorageRange();
  328.  
  329. void setGroup(Group* newGroup) {
  330. group = newGroup;
  331. }
  332. Group* getGroup() const {
  333. return group;
  334. }
  335.  
  336. void setLastDepotId(int16_t newId) {
  337. lastDepotId = newId;
  338. }
  339. int16_t getLastDepotId() const {
  340. return lastDepotId;
  341. }
  342.  
  343. void resetIdleTime() {
  344. idleTime = 0;
  345. }
  346.  
  347. bool isInGhostMode() const {
  348. return ghostMode;
  349. }
  350. void switchGhostMode() {
  351. ghostMode = !ghostMode;
  352. }
  353.  
  354. uint32_t getAccount() const {
  355. return accountNumber;
  356. }
  357. AccountType_t getAccountType() const {
  358. return accountType;
  359. }
  360. uint32_t getLevel() const {
  361. return level;
  362. }
  363. uint8_t getLevelPercent() const {
  364. return levelPercent;
  365. }
  366. uint32_t getMagicLevel() const {
  367. return std::max<int32_t>(0, magLevel + varStats[STAT_MAGICPOINTS]);
  368. }
  369. uint32_t getBaseMagicLevel() const {
  370. return magLevel;
  371. }
  372. uint8_t getMagicLevelPercent() const {
  373. return magLevelPercent;
  374. }
  375. uint8_t getSoul() const {
  376. return soul;
  377. }
  378. bool isAccessPlayer() const {
  379. return group->access;
  380. }
  381. bool isPremium() const;
  382. void setPremiumDays(int32_t v);
  383.  
  384. bool setVocation(uint16_t vocId);
  385. uint16_t getVocationId() const {
  386. return vocation->getId();
  387. }
  388.  
  389. PlayerSex_t getSex() const {
  390. return sex;
  391. }
  392. void setSex(PlayerSex_t);
  393. uint64_t getExperience() const {
  394. return experience;
  395. }
  396.  
  397. time_t getLastLoginSaved() const {
  398. return lastLoginSaved;
  399. }
  400.  
  401. time_t getLastLogout() const {
  402. return lastLogout;
  403. }
  404.  
  405. const Position& getLoginPosition() const {
  406. return loginPosition;
  407. }
  408. const Position& getTemplePosition() const {
  409. return town->getTemplePosition();
  410. }
  411. Town* getTown() const {
  412. return town;
  413. }
  414. void setTown(Town* town) {
  415. this->town = town;
  416. }
  417.  
  418. bool isPushable() const final;
  419. uint32_t isMuted() const;
  420. void addMessageBuffer();
  421. void removeMessageBuffer();
  422.  
  423. bool removeItemOfType(uint16_t itemId, uint32_t amount, int32_t subType, bool ignoreEquipped = false) const;
  424.  
  425. uint32_t getCapacity() const {
  426. if (hasFlag(PlayerFlag_CannotPickupItem)) {
  427. return 0;
  428. } else if (hasFlag(PlayerFlag_HasInfiniteCapacity)) {
  429. return std::numeric_limits<uint32_t>::max();
  430. }
  431. return capacity;
  432. }
  433.  
  434. uint32_t getFreeCapacity() const {
  435. if (hasFlag(PlayerFlag_CannotPickupItem)) {
  436. return 0;
  437. } else if (hasFlag(PlayerFlag_HasInfiniteCapacity)) {
  438. return std::numeric_limits<uint32_t>::max();
  439. } else {
  440. return std::max<int32_t>(0, capacity - inventoryWeight);
  441. }
  442. }
  443.  
  444. int32_t getMaxHealth() const final {
  445. return std::max<int32_t>(1, healthMax + varStats[STAT_MAXHITPOINTS]);
  446. }
  447. uint32_t getMaxMana() const {
  448. return std::max<int32_t>(0, manaMax + varStats[STAT_MAXMANAPOINTS]);
  449. }
  450.  
  451. Item* getInventoryItem(slots_t slot) const;
  452.  
  453. bool isItemAbilityEnabled(slots_t slot) const {
  454. return inventoryAbilities[slot];
  455. }
  456. void setItemAbility(slots_t slot, bool enabled) {
  457. inventoryAbilities[slot] = enabled;
  458. }
  459.  
  460. void setVarSkill(skills_t skill, int32_t modifier) {
  461. varSkills[skill] += modifier;
  462. }
  463.  
  464. void setVarStats(stats_t stat, int32_t modifier);
  465. int32_t getDefaultStats(stats_t stat) const;
  466.  
  467. void addConditionSuppressions(uint32_t conditions);
  468. void removeConditionSuppressions(uint32_t conditions);
  469.  
  470. Reward* getReward(uint32_t rewardId, bool autoCreate);
  471. void removeReward(uint32_t rewardId);
  472. void getRewardList(std::vector<uint32_t>& rewards);
  473. RewardChest* getRewardChest();
  474.  
  475. DepotChest* getDepotChest(uint32_t depotId, bool autoCreate);
  476. DepotLocker* getDepotLocker(uint32_t depotId);
  477. void onReceiveMail() const;
  478. bool isNearDepotBox() const;
  479.  
  480. bool canSee(const Position& pos) const final;
  481. bool canSeeCreature(const Creature* creature) const final;
  482.  
  483. bool canWalkthrough(const Creature* creature) const;
  484. bool canWalkthroughEx(const Creature* creature) const;
  485.  
  486. RaceType_t getRace() const final {
  487. return RACE_BLOOD;
  488. }
  489.  
  490. uint64_t getMoney() const;
  491.  
  492. //safe-trade functions
  493. void setTradeState(tradestate_t state) {
  494. tradeState = state;
  495. }
  496. tradestate_t getTradeState() const {
  497. return tradeState;
  498. }
  499. Item* getTradeItem() {
  500. return tradeItem;
  501. }
  502.  
  503. //shop functions
  504. void setShopOwner(Npc* owner, int32_t onBuy, int32_t onSell) {
  505. shopOwner = owner;
  506. purchaseCallback = onBuy;
  507. saleCallback = onSell;
  508. }
  509.  
  510. Npc* getShopOwner(int32_t& onBuy, int32_t& onSell) {
  511. onBuy = purchaseCallback;
  512. onSell = saleCallback;
  513. return shopOwner;
  514. }
  515.  
  516. const Npc* getShopOwner(int32_t& onBuy, int32_t& onSell) const {
  517. onBuy = purchaseCallback;
  518. onSell = saleCallback;
  519. return shopOwner;
  520. }
  521.  
  522. //V.I.P. functions
  523. void notifyStatusChange(Player* player, bool online);
  524. bool removeVIP(uint32_t vipGuid);
  525. bool addVIP(uint32_t vipGuid, const std::string& vipName, bool online);
  526. bool addVIPInternal(uint32_t vipGuid);
  527. bool editVIP(uint32_t vipGuid, const std::string& description, uint32_t icon, bool notify);
  528.  
  529. //follow functions
  530. bool setFollowCreature(Creature* creature) final;
  531. void goToFollowCreature() final;
  532.  
  533. //follow events
  534. void onFollowCreature(const Creature* creature) final;
  535.  
  536. //walk events
  537. void onWalk(Direction& dir) final;
  538. void onWalkAborted() final;
  539. void onWalkComplete() final;
  540.  
  541. void stopWalk();
  542. void openShopWindow(Npc* npc, const std::list<ShopInfo>& shop);
  543. bool closeShopWindow(bool sendCloseShopWindow = true);
  544. bool updateSaleShopList(const Item* item);
  545. bool hasShopItemForSale(uint32_t itemId, uint8_t subType) const;
  546.  
  547. void setChaseMode(bool mode);
  548. void setFightMode(fightMode_t mode) {
  549. fightMode = mode;
  550. }
  551. void setSecureMode(bool mode) {
  552. secureMode = mode;
  553. }
  554.  
  555. //combat functions
  556. bool setAttackedCreature(Creature* creature) final;
  557. bool isImmune(CombatType_t type) const final;
  558. bool isImmune(ConditionType_t type) const final;
  559. bool hasShield() const;
  560. bool isAttackable() const final;
  561. static bool lastHitIsPlayer(Creature* lastHitCreature);
  562.  
  563. void changeHealth(int32_t healthChange, bool sendHealthChange = true) final;
  564. void changeMana(int32_t manaChange) final;
  565. void changeSoul(int32_t soulChange);
  566.  
  567. bool isPzLocked() const {
  568. return pzLocked;
  569. }
  570. BlockType_t blockHit(Creature* attacker, CombatType_t combatType, int32_t& damage,
  571. bool checkDefense = false, bool checkArmor = false, bool field = false) final;
  572. void doAttacking(uint32_t interval) final;
  573. bool hasExtraSwing() final {
  574. return lastAttack > 0 && ((OTSYS_TIME() - lastAttack) >= getAttackSpeed());
  575. }
  576.  
  577. uint16_t getSkillLevel(uint8_t skill) const {
  578. return std::max<int32_t>(0, skills[skill].level + varSkills[skill]);
  579. }
  580. uint16_t getBaseSkill(uint8_t skill) const {
  581. return skills[skill].level;
  582. }
  583. uint8_t getSkillPercent(uint8_t skill) const {
  584. return skills[skill].percent;
  585. }
  586.  
  587. bool getAddAttackSkill() const {
  588. return addAttackSkillPoint;
  589. }
  590. BlockType_t getLastAttackBlockType() const {
  591. return lastAttackBlockType;
  592. }
  593.  
  594. Item* getWeapon(slots_t slot, bool ignoreAmmo) const;
  595. Item* getWeapon(bool ignoreAmmo = false) const;
  596. WeaponType_t getWeaponType() const;
  597. int32_t getWeaponSkill(const Item* item) const;
  598. void getShieldAndWeapon(const Item*& shield, const Item*& weapon) const;
  599.  
  600. void drainHealth(Creature* attacker, int32_t damage) final;
  601. void drainMana(Creature* attacker, int32_t manaLoss) final;
  602. void addManaSpent(uint64_t amount);
  603. void addSkillAdvance(skills_t skill, uint64_t count);
  604.  
  605. int32_t getArmor() const final;
  606. int32_t getDefense() const final;
  607. float getAttackFactor() const final;
  608. float getDefenseFactor() const final;
  609.  
  610. void addCombatExhaust(uint32_t ticks);
  611. void addHealExhaust(uint32_t ticks);
  612.  
  613. void addInFightTicks(bool pzlock = false);
  614.  
  615. uint64_t getGainedExperience(Creature* attacker) const final;
  616.  
  617. //combat event functions
  618. void onAddCondition(ConditionType_t type) final;
  619. void onAddCombatCondition(ConditionType_t type) final;
  620. void onEndCondition(ConditionType_t type) final;
  621. void onCombatRemoveCondition(Condition* condition) final;
  622. void onAttackedCreature(Creature* target) final;
  623. void onAttacked() final;
  624. void onAttackedCreatureDrainHealth(Creature* target, int32_t points) final;
  625. void onTargetCreatureGainHealth(Creature* target, int32_t points) final;
  626. bool onKilledCreature(Creature* target, bool lastHit = true) final;
  627. void onGainExperience(uint64_t gainExp, Creature* target) final;
  628. void onGainSharedExperience(uint64_t gainExp, Creature* source);
  629. void onAttackedCreatureBlockHit(BlockType_t blockType) final;
  630. void onBlockHit() final;
  631. void onChangeZone(ZoneType_t zone) final;
  632. void onAttackedCreatureChangeZone(ZoneType_t zone) final;
  633. void onIdleStatus() final;
  634. void onPlacedCreature() final;
  635.  
  636. void getCreatureLight(LightInfo& light) const final;
  637.  
  638. Skulls_t getSkull() const final;
  639. Skulls_t getSkullClient(const Creature* creature) const final;
  640. int64_t getSkullTicks() const { return skullTicks; }
  641. void setSkullTicks(int64_t ticks) { skullTicks = ticks; }
  642.  
  643. bool hasAttacked(const Player* attacked) const;
  644. void addAttacked(const Player* attacked);
  645. void removeAttacked(const Player* attacked);
  646. void clearAttacked();
  647. void addUnjustifiedDead(const Player* attacked);
  648. void sendCreatureSkull(const Creature* creature) const {
  649. if (client) {
  650. client->sendCreatureSkull(creature);
  651. }
  652. }
  653. void checkSkullTicks(int32_t ticks);
  654.  
  655. bool canWear(uint32_t lookType, uint8_t addons) const;
  656. void addOutfit(uint16_t lookType, uint8_t addons);
  657. bool removeOutfit(uint16_t lookType);
  658. bool removeOutfitAddon(uint16_t lookType, uint8_t addons);
  659. bool getOutfitAddons(const Outfit& outfit, uint8_t& addons) const;
  660.  
  661. bool canLogout();
  662.  
  663. size_t getMaxVIPEntries() const;
  664. size_t getMaxDepotItems() const;
  665.  
  666. //tile
  667. //send methods
  668. void sendAddTileItem(const Tile* tile, const Position& pos, const Item* item) {
  669. if (client) {
  670. int32_t stackpos = tile->getStackposOfItem(this, item);
  671. if (stackpos != -1) {
  672. client->sendAddTileItem(pos, stackpos, item);
  673. }
  674. }
  675. }
  676. void sendUpdateTileItem(const Tile* tile, const Position& pos, const Item* item) {
  677. if (client) {
  678. int32_t stackpos = tile->getStackposOfItem(this, item);
  679. if (stackpos != -1) {
  680. client->sendUpdateTileItem(pos, stackpos, item);
  681. }
  682. }
  683. }
  684. void sendRemoveTileThing(const Position& pos, int32_t stackpos) {
  685. if (stackpos != -1 && client) {
  686. client->sendRemoveTileThing(pos, stackpos);
  687. }
  688. }
  689. void sendUpdateTile(const Tile* tile, const Position& pos) {
  690. if (client) {
  691. client->sendUpdateTile(tile, pos);
  692. }
  693. }
  694.  
  695. void sendChannelMessage(const std::string& author, const std::string& text, SpeakClasses type, uint16_t channel) {
  696. if (client) {
  697. client->sendChannelMessage(author, text, type, channel);
  698. }
  699. }
  700. void sendCreatureAppear(const Creature* creature, const Position& pos, bool isLogin) {
  701. if (client) {
  702. client->sendAddCreature(creature, pos, creature->getTile()->getStackposOfCreature(this, creature), isLogin);
  703. }
  704. }
  705. void sendCreatureMove(const Creature* creature, const Position& newPos, int32_t newStackPos, const Position& oldPos, int32_t oldStackPos, bool teleport) {
  706. if (client) {
  707. client->sendMoveCreature(creature, newPos, newStackPos, oldPos, oldStackPos, teleport);
  708. }
  709. }
  710. void sendCreatureTurn(const Creature* creature) {
  711. if (client && canSeeCreature(creature)) {
  712. int32_t stackpos = creature->getTile()->getStackposOfCreature(this, creature);
  713. if (stackpos != -1) {
  714. client->sendCreatureTurn(creature, stackpos);
  715. }
  716. }
  717. }
  718. void sendCreatureSay(const Creature* creature, SpeakClasses type, const std::string& text, const Position* pos = nullptr) {
  719. if (client) {
  720. client->sendCreatureSay(creature, type, text, pos);
  721. }
  722. }
  723. void sendPrivateMessage(const Player* speaker, SpeakClasses type, const std::string& text) {
  724. if (client) {
  725. client->sendPrivateMessage(speaker, type, text);
  726. }
  727. }
  728. void sendCreatureSquare(const Creature* creature, SquareColor_t color) {
  729. if (client) {
  730. client->sendCreatureSquare(creature, color);
  731. }
  732. }
  733. void sendCreatureChangeOutfit(const Creature* creature, const Outfit_t& outfit) {
  734. if (client) {
  735. client->sendCreatureOutfit(creature, outfit);
  736. }
  737. }
  738. void sendCreatureChangeVisible(const Creature* creature, bool visible) {
  739. if (!client) {
  740. return;
  741. }
  742.  
  743. if (creature->getPlayer()) {
  744. if (visible) {
  745. client->sendCreatureOutfit(creature, creature->getCurrentOutfit());
  746. } else {
  747. static Outfit_t outfit;
  748. client->sendCreatureOutfit(creature, outfit);
  749. }
  750. } else if (canSeeInvisibility()) {
  751. client->sendCreatureOutfit(creature, creature->getCurrentOutfit());
  752. } else {
  753. int32_t stackpos = creature->getTile()->getStackposOfCreature(this, creature);
  754. if (stackpos == -1) {
  755. return;
  756. }
  757.  
  758. if (visible) {
  759. client->sendAddCreature(creature, creature->getPosition(), stackpos, false);
  760. } else {
  761. client->sendRemoveTileThing(creature->getPosition(), stackpos);
  762. }
  763. }
  764. }
  765. void sendCreatureLight(const Creature* creature) {
  766. if (client) {
  767. client->sendCreatureLight(creature);
  768. }
  769. }
  770. void sendCreatureWalkthrough(const Creature* creature, bool walkthrough) {
  771. if (client) {
  772. client->sendCreatureWalkthrough(creature, walkthrough);
  773. }
  774. }
  775. void sendCreatureShield(const Creature* creature) {
  776. if (client) {
  777. client->sendCreatureShield(creature);
  778. }
  779. }
  780. void sendAnimatedText(const std::string& message, const Position& pos, TextColor_t color) {
  781. if (client) {
  782. client->sendAnimatedText(message, pos, color);
  783. }
  784. }
  785.  
  786. //container
  787. void sendAddContainerItem(const Container* container, const Item* item);
  788. void sendUpdateContainerItem(const Container* container, uint16_t slot, const Item* newItem);
  789. void sendRemoveContainerItem(const Container* container, uint16_t slot);
  790. void sendContainer(uint8_t cid, const Container* container, bool hasParent, uint16_t firstIndex) {
  791. if (client) {
  792. client->sendContainer(cid, container, hasParent, firstIndex);
  793. }
  794. }
  795.  
  796. //inventory
  797. void sendInventoryItem(slots_t slot, const Item* item) {
  798. if (client) {
  799. client->sendInventoryItem(slot, item);
  800. }
  801. }
  802.  
  803. //event methods
  804. void onUpdateTileItem(const Tile* tile, const Position& pos, const Item* oldItem,
  805. const ItemType& oldType, const Item* newItem, const ItemType& newType) final;
  806. void onRemoveTileItem(const Tile* tile, const Position& pos, const ItemType& iType,
  807. const Item* item) final;
  808.  
  809. void onCreatureAppear(Creature* creature, bool isLogin) final;
  810. void onRemoveCreature(Creature* creature, bool isLogout) final;
  811. void onCreatureMove(Creature* creature, const Tile* newTile, const Position& newPos,
  812. const Tile* oldTile, const Position& oldPos, bool teleport) final;
  813.  
  814. void onAttackedCreatureDisappear(bool isLogout) final;
  815. void onFollowCreatureDisappear(bool isLogout) final;
  816.  
  817. //container
  818. void onAddContainerItem(const Item* item);
  819. void onUpdateContainerItem(const Container* container, const Item* oldItem, const Item* newItem);
  820. void onRemoveContainerItem(const Container* container, const Item* item);
  821.  
  822. void onCloseContainer(const Container* container);
  823. void onSendContainer(const Container* container);
  824. void autoCloseContainers(const Container* container);
  825.  
  826. //inventory
  827. void onUpdateInventoryItem(Item* oldItem, Item* newItem);
  828. void onRemoveInventoryItem(Item* item);
  829.  
  830. void sendCancelMessage(const std::string& msg) const {
  831. if (client) {
  832. client->sendTextMessage(TextMessage(MESSAGE_STATUS_SMALL, msg));
  833. }
  834. }
  835. void sendCancelMessage(ReturnValue message) const;
  836. void sendCancelTarget() const {
  837. if (client) {
  838. client->sendCancelTarget();
  839. }
  840. }
  841. void sendCancelWalk() const {
  842. if (client) {
  843. client->sendCancelWalk();
  844. }
  845. }
  846. void sendChangeSpeed(const Creature* creature, uint32_t newSpeed) const {
  847. if (client) {
  848. client->sendChangeSpeed(creature, newSpeed);
  849. }
  850. }
  851. void sendCreatureHealth(const Creature* creature) const {
  852. if (client) {
  853. client->sendCreatureHealth(creature);
  854. }
  855. }
  856. void sendDistanceShoot(const Position& from, const Position& to, unsigned char type) const {
  857. if (client) {
  858. client->sendDistanceShoot(from, to, type);
  859. }
  860. }
  861. void sendHouseWindow(House* house, uint32_t listId) const;
  862. void sendCreatePrivateChannel(uint16_t channelId, const std::string& channelName) {
  863. if (client) {
  864. client->sendCreatePrivateChannel(channelId, channelName);
  865. }
  866. }
  867. void sendClosePrivate(uint16_t channelId);
  868. void sendIcons() const {
  869. if (client) {
  870. client->sendIcons(getClientIcons());
  871. }
  872. }
  873. void sendMagicEffect(const Position& pos, uint8_t type) const {
  874. if (client) {
  875. client->sendMagicEffect(pos, type);
  876. }
  877. }
  878. void sendPing();
  879. void sendStats();
  880. void sendSkills() const {
  881. if (client) {
  882. client->sendSkills();
  883. }
  884. }
  885. void sendTextMessage(MessageClasses mclass, const std::string& message) const {
  886. if (client) {
  887. client->sendTextMessage(TextMessage(mclass, message));
  888. }
  889. }
  890. void sendTextMessage(const TextMessage& message) const {
  891. if (client) {
  892. client->sendTextMessage(message);
  893. }
  894. }
  895. void sendReLoginWindow() const {
  896. if (client) {
  897. client->sendReLoginWindow();
  898. }
  899. }
  900. void sendTextWindow(Item* item, uint16_t maxlen, bool canWrite) const {
  901. if (client) {
  902. client->sendTextWindow(windowTextId, item, maxlen, canWrite);
  903. }
  904. }
  905. void sendTextWindow(uint32_t itemId, const std::string& text) const {
  906. if (client) {
  907. client->sendTextWindow(windowTextId, itemId, text);
  908. }
  909. }
  910. void sendToChannel(const Creature* creature, SpeakClasses type, const std::string& text, uint16_t channelId) const {
  911. if (client) {
  912. client->sendToChannel(creature, type, text, channelId);
  913. }
  914. }
  915. void sendShop(Npc* npc) const {
  916. if (client) {
  917. client->sendShop(npc, shopItemList);
  918. }
  919. }
  920. void sendSaleItemList() const {
  921. if (client) {
  922. client->sendSaleItemList(shopItemList);
  923. }
  924. }
  925. void sendCloseShop() const {
  926. if (client) {
  927. client->sendCloseShop();
  928. }
  929. }
  930. void sendTradeItemRequest(const std::string& traderName, const Item* item, bool ack) const {
  931. if (client) {
  932. client->sendTradeItemRequest(traderName, item, ack);
  933. }
  934. }
  935. void sendTradeClose() const {
  936. if (client) {
  937. client->sendCloseTrade();
  938. }
  939. }
  940. void sendWorldLight(const LightInfo& lightInfo) {
  941. if (client) {
  942. client->sendWorldLight(lightInfo);
  943. }
  944. }
  945. void sendChannelsDialog() {
  946. if (client) {
  947. client->sendChannelsDialog();
  948. }
  949. }
  950. void sendOpenPrivateChannel(const std::string& receiver) {
  951. if (client) {
  952. client->sendOpenPrivateChannel(receiver);
  953. }
  954. }
  955. void sendOutfitWindow() {
  956. if (client) {
  957. client->sendOutfitWindow();
  958. }
  959. }
  960. void sendCloseContainer(uint8_t cid) {
  961. if (client) {
  962. client->sendCloseContainer(cid);
  963. }
  964. }
  965.  
  966. void sendChannel(uint16_t channelId, const std::string& channelName) {
  967. if (client) {
  968. client->sendChannel(channelId, channelName);
  969. }
  970. }
  971. void sendTutorial(uint8_t tutorialId) {
  972. if (client) {
  973. client->sendTutorial(tutorialId);
  974. }
  975. }
  976. void sendAddMarker(const Position& pos, uint8_t markType, const std::string& desc) {
  977. if (client) {
  978. client->sendAddMarker(pos, markType, desc);
  979. }
  980. }
  981. void sendQuestLog() {
  982. if (client) {
  983. client->sendQuestLog();
  984. }
  985. }
  986. void sendQuestLine(const Quest* quest) {
  987. if (client) {
  988. client->sendQuestLine(quest);
  989. }
  990. }
  991. void sendFightModes() {
  992. if (client) {
  993. client->sendFightModes();
  994. }
  995. }
  996. void sendNetworkMessage(const NetworkMessage& message) {
  997. if (client) {
  998. client->writeToOutputBuffer(message);
  999. }
  1000. }
  1001.  
  1002. void receivePing() {
  1003. lastPong = OTSYS_TIME();
  1004. }
  1005.  
  1006. void onThink(uint32_t interval) final;
  1007.  
  1008. void postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, cylinderlink_t link = LINK_OWNER) final;
  1009. void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, cylinderlink_t link = LINK_OWNER) final;
  1010.  
  1011. void setNextAction(int64_t time) {
  1012. if (time > nextAction) {
  1013. nextAction = time;
  1014. }
  1015. }
  1016. bool canDoAction() const {
  1017. return nextAction <= OTSYS_TIME();
  1018. }
  1019. uint32_t getNextActionTime() const;
  1020.  
  1021. Item* getWriteItem(uint32_t& windowTextId, uint16_t& maxWriteLen);
  1022. void setWriteItem(Item* item, uint16_t maxWriteLen = 0);
  1023.  
  1024. House* getEditHouse(uint32_t& windowTextId, uint32_t& listId);
  1025. void setEditHouse(House* house, uint32_t listId = 0);
  1026.  
  1027. void learnInstantSpell(const std::string& spellName);
  1028. void forgetInstantSpell(const std::string& spellName);
  1029. bool hasLearnedInstantSpell(const std::string& spellName) const;
  1030.  
  1031. protected:
  1032. std::forward_list<Condition*> getMuteConditions() const;
  1033.  
  1034. void checkTradeState(const Item* item);
  1035. bool hasCapacity(const Item* item, uint32_t count) const;
  1036.  
  1037. void gainExperience(uint64_t exp, Creature* source);
  1038. void addExperience(Creature* source, uint64_t exp, bool sendText = false);
  1039. void removeExperience(uint64_t exp, bool sendText = false);
  1040.  
  1041. void updateInventoryWeight();
  1042.  
  1043. void setNextWalkActionTask(SchedulerTask* task);
  1044. void setNextWalkTask(SchedulerTask* task);
  1045. void setNextActionTask(SchedulerTask* task);
  1046.  
  1047. void death(Creature* lastHitCreature) final;
  1048. bool dropCorpse(Creature* lastHitCreature, Creature* mostDamageCreature, bool lastHitUnjustified, bool mostDamageUnjustified) final;
  1049. Item* getCorpse(Creature* lastHitCreature, Creature* mostDamageCreature) final;
  1050.  
  1051. //cylinder implementations
  1052. ReturnValue queryAdd(int32_t index, const Thing& thing, uint32_t count,
  1053. uint32_t flags, Creature* actor = nullptr) const final;
  1054. ReturnValue queryMaxCount(int32_t index, const Thing& thing, uint32_t count, uint32_t& maxQueryCount,
  1055. uint32_t flags) const final;
  1056. ReturnValue queryRemove(const Thing& thing, uint32_t count, uint32_t flags) const final;
  1057. Cylinder* queryDestination(int32_t& index, const Thing& thing, Item** destItem,
  1058. uint32_t& flags) final;
  1059.  
  1060. void addThing(Thing*) final {}
  1061. void addThing(int32_t index, Thing* thing) final;
  1062.  
  1063. void updateThing(Thing* thing, uint16_t itemId, uint32_t count) final;
  1064. void replaceThing(uint32_t index, Thing* thing) final;
  1065.  
  1066. void removeThing(Thing* thing, uint32_t count) final;
  1067.  
  1068. int32_t getThingIndex(const Thing* thing) const final;
  1069. size_t getFirstIndex() const final;
  1070. size_t getLastIndex() const final;
  1071. uint32_t getItemTypeCount(uint16_t itemId, int32_t subType = -1) const final;
  1072. std::map<uint32_t, uint32_t>& getAllItemTypeCount(std::map<uint32_t, uint32_t>& countMap) const final;
  1073. Thing* getThing(size_t index) const final;
  1074.  
  1075. void internalAddThing(Thing* thing) final;
  1076. void internalAddThing(uint32_t index, Thing* thing) final;
  1077.  
  1078. std::unordered_set<uint32_t> attackedSet;
  1079. std::unordered_set<uint32_t> VIPList;
  1080.  
  1081. std::map<uint8_t, OpenContainer> openContainers;
  1082. std::map<uint32_t, DepotLocker*> depotLockerMap;
  1083. std::map<uint32_t, DepotChest*> depotChests;
  1084. std::map<uint32_t, int32_t> storageMap;
  1085.  
  1086. std::map<uint32_t, Reward*> rewardMap;
  1087.  
  1088. std::vector<OutfitEntry> outfits;
  1089. GuildWarVector guildWarVector;
  1090.  
  1091. std::list<ShopInfo> shopItemList;
  1092.  
  1093. std::forward_list<Party*> invitePartyList;
  1094. std::forward_list<std::string> learnedInstantSpellList;
  1095. std::forward_list<Condition*> storedConditionList; // TODO: This variable is only temporarily used when logging in, get rid of it somehow
  1096.  
  1097. std::string name;
  1098. std::string guildNick;
  1099.  
  1100. Skill skills[SKILL_LAST + 1];
  1101. LightInfo itemsLight;
  1102. Position loginPosition;
  1103. Position lastWalkthroughPosition;
  1104.  
  1105. time_t lastLoginSaved = 0;
  1106. time_t lastLogout = 0;
  1107.  
  1108. uint64_t experience = 0;
  1109. uint64_t manaSpent = 0;
  1110. uint64_t lastAttack = 0;
  1111. uint64_t bankBalance = 0;
  1112. uint64_t lastQuestlogUpdate = 0;
  1113. int64_t lastFailedFollow = 0;
  1114. int64_t skullTicks = 0;
  1115. int64_t lastWalkthroughAttempt = 0;
  1116. int64_t lastToggleMount = 0;
  1117. int64_t lastPing;
  1118. int64_t lastPong;
  1119. int64_t nextAction = 0;
  1120.  
  1121. BedItem* bedItem = nullptr;
  1122. Guild* guild = nullptr;
  1123. const GuildRank* guildRank = nullptr;
  1124. Group* group = nullptr;
  1125. Inbox* inbox;
  1126. Item* tradeItem = nullptr;
  1127. Item* inventory[CONST_SLOT_LAST + 1] = {};
  1128. Item* writeItem = nullptr;
  1129. House* editHouse = nullptr;
  1130. Npc* shopOwner = nullptr;
  1131. Party* party = nullptr;
  1132. Player* tradePartner = nullptr;
  1133. ProtocolGame_ptr client;
  1134. SchedulerTask* walkTask = nullptr;
  1135. Town* town = nullptr;
  1136. Vocation* vocation = nullptr;
  1137. RewardChest* rewardChest = nullptr;
  1138.  
  1139. uint32_t inventoryWeight = 0;
  1140. uint32_t capacity = 40000;
  1141. uint32_t damageImmunities = 0;
  1142. uint32_t conditionImmunities = 0;
  1143. uint32_t conditionSuppressions = 0;
  1144. uint32_t level = 1;
  1145. uint32_t magLevel = 0;
  1146. uint32_t actionTaskEvent = 0;
  1147. uint32_t nextStepEvent = 0;
  1148. uint32_t walkTaskEvent = 0;
  1149. uint32_t MessageBufferTicks = 0;
  1150. uint32_t lastIP = 0;
  1151. uint32_t accountNumber = 0;
  1152. uint32_t guid = 0;
  1153. uint32_t windowTextId = 0;
  1154. uint32_t editListId = 0;
  1155. uint32_t manaMax = 0;
  1156. int32_t varSkills[SKILL_LAST + 1] = {};
  1157. int32_t varStats[STAT_LAST + 1] = {};
  1158. int32_t purchaseCallback = -1;
  1159. int32_t saleCallback = -1;
  1160. int32_t MessageBufferCount = 0;
  1161. int32_t premiumDays = 0;
  1162. int32_t bloodHitCount = 0;
  1163. int32_t shieldBlockCount = 0;
  1164. int32_t offlineTrainingSkill = -1;
  1165. int32_t offlineTrainingTime = 0;
  1166. int32_t idleTime = 0;
  1167.  
  1168. uint16_t lastStatsTrainingTime = 0;
  1169. uint16_t staminaMinutes = 2520;
  1170. uint16_t maxWriteLen = 0;
  1171. int16_t lastDepotId = -1;
  1172.  
  1173. uint8_t soul = 0;
  1174. uint8_t blessings = 0;
  1175. uint8_t levelPercent = 0;
  1176. uint8_t magLevelPercent = 0;
  1177.  
  1178. PlayerSex_t sex = PLAYERSEX_FEMALE;
  1179. OperatingSystem_t operatingSystem = CLIENTOS_NONE;
  1180. BlockType_t lastAttackBlockType = BLOCK_NONE;
  1181. tradestate_t tradeState = TRADE_NONE;
  1182. fightMode_t fightMode = FIGHTMODE_ATTACK;
  1183. AccountType_t accountType = ACCOUNT_TYPE_NORMAL;
  1184.  
  1185. bool chaseMode = false;
  1186. bool secureMode = false;
  1187. bool ghostMode = false;
  1188. bool pzLocked = false;
  1189. bool isConnecting = false;
  1190. bool addAttackSkillPoint = false;
  1191. bool inventoryAbilities[CONST_SLOT_LAST + 1] = {};
  1192.  
  1193. static uint32_t playerAutoID;
  1194.  
  1195. void updateItemsLight(bool internal = false);
  1196. int32_t getStepSpeed() const final {
  1197. return std::max<int32_t>(PLAYER_MIN_SPEED, std::min<int32_t>(PLAYER_MAX_SPEED, getSpeed()));
  1198. }
  1199. void updateBaseSpeed() {
  1200. if (!hasFlag(PlayerFlag_SetMaxSpeed)) {
  1201. baseSpeed = vocation->getBaseSpeed() + (2 * (level - 1));
  1202. } else {
  1203. baseSpeed = PLAYER_MAX_SPEED;
  1204. }
  1205. }
  1206.  
  1207. bool isPromoted() const;
  1208.  
  1209. uint32_t getAttackSpeed() const {
  1210. return vocation->getAttackSpeed();
  1211. }
  1212.  
  1213. static uint8_t getPercentLevel(uint64_t count, uint64_t nextLevelCount);
  1214. double getLostPercent() const;
  1215. uint64_t getLostExperience() const final {
  1216. return skillLoss ? static_cast<uint64_t>(experience * getLostPercent()) : 0;
  1217. }
  1218. uint32_t getDamageImmunities() const final {
  1219. return damageImmunities;
  1220. }
  1221. uint32_t getConditionImmunities() const final {
  1222. return conditionImmunities;
  1223. }
  1224. uint32_t getConditionSuppressions() const final {
  1225. return conditionSuppressions;
  1226. }
  1227. uint16_t getLookCorpse() const final;
  1228. void getPathSearchParams(const Creature* creature, FindPathParams& fpp) const final;
  1229.  
  1230. friend class Game;
  1231. friend class Npc;
  1232. friend class LuaScriptInterface;
  1233. friend class Map;
  1234. friend class Actions;
  1235. friend class IOLoginData;
  1236. friend class ProtocolGame;
  1237. };
  1238.  
  1239. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement