No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

localplayer.h 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (c) 2010-2014 OTClient <https://github.com/edubart/otclient>
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. * THE SOFTWARE.
  21. */
  22. #ifndef LOCALPLAYER_H
  23. #define LOCALPLAYER_H
  24. #include "player.h"
  25. // @bindclass
  26. class LocalPlayer : public Player
  27. {
  28. enum {
  29. PREWALK_TIMEOUT = 1000
  30. };
  31. public:
  32. LocalPlayer();
  33. void unlockWalk() { m_walkLockExpiration = 0; }
  34. void lockWalk(int millis = 250);
  35. void stopAutoWalk();
  36. bool autoWalk(const Position& destination);
  37. bool canWalk(Otc::Direction direction);
  38. void setStates(int states);
  39. void setSkill(Otc::Skill skill, int level, int levelPercent);
  40. void setBaseSkill(Otc::Skill skill, int baseLevel);
  41. void setHealth(double health, double maxHealth);
  42. void setFreeCapacity(double freeCapacity);
  43. void setTotalCapacity(double totalCapacity);
  44. void setExperience(double experience);
  45. void setLevel(double level, double levelPercent);
  46. void setMana(double mana, double maxMana);
  47. void setMagicLevel(double magicLevel, double magicLevelPercent);
  48. void setBaseMagicLevel(double baseMagicLevel);
  49. void setSoul(double soul);
  50. void setStamina(double stamina);
  51. void setKnown(bool known) { m_known = known; }
  52. void setPendingGame(bool pending) { m_pending = pending; }
  53. void setInventoryItem(Otc::InventorySlot inventory, const ItemPtr& item);
  54. void setVocation(int vocation);
  55. void setPremium(bool premium);
  56. void setRegenerationTime(double regenerationTime);
  57. void setOfflineTrainingTime(double offlineTrainingTime);
  58. void setSpells(const std::vector<int>& spells);
  59. void setBlessings(int blessings);
  60. int getStates() { return m_states; }
  61. int getSkillLevel(Otc::Skill skill) { return m_skillsLevel[skill]; }
  62. int getSkillBaseLevel(Otc::Skill skill) { return m_skillsBaseLevel[skill]; }
  63. int getSkillLevelPercent(Otc::Skill skill) { return m_skillsLevelPercent[skill]; }
  64. int getVocation() { return m_vocation; }
  65. double getHealth() { return m_health; }
  66. double getMaxHealth() { return m_maxHealth; }
  67. double getFreeCapacity() { return m_freeCapacity; }
  68. double getTotalCapacity() { return m_totalCapacity; }
  69. double getExperience() { return m_experience; }
  70. double getLevel() { return m_level; }
  71. double getLevelPercent() { return m_levelPercent; }
  72. double getMana() { return m_mana; }
  73. double getMaxMana() { return m_maxMana; }
  74. double getMagicLevel() { return m_magicLevel; }
  75. double getMagicLevelPercent() { return m_magicLevelPercent; }
  76. double getBaseMagicLevel() { return m_baseMagicLevel; }
  77. double getSoul() { return m_soul; }
  78. double getStamina() { return m_stamina; }
  79. double getRegenerationTime() { return m_regenerationTime; }
  80. double getOfflineTrainingTime() { return m_offlineTrainingTime; }
  81. std::vector<int> getSpells() { return m_spells; }
  82. ItemPtr getInventoryItem(Otc::InventorySlot inventory) { return m_inventoryItems[inventory]; }
  83. int getBlessings() { return m_blessings; }
  84. bool hasSight(const Position& pos);
  85. bool isKnown() { return m_known; }
  86. bool isPreWalking() { return m_preWalking; }
  87. bool isAutoWalking() { return m_autoWalkDestination.isValid(); }
  88. bool isServerWalking() { return m_serverWalking; }
  89. bool isPremium() { return m_premium; }
  90. bool isPendingGame() { return m_pending; }
  91. LocalPlayerPtr asLocalPlayer() { return static_self_cast<LocalPlayer>(); }
  92. bool isLocalPlayer() { return true; }
  93. virtual void onAppear();
  94. virtual void onPositionChange(const Position& newPos, const Position& oldPos);
  95. protected:
  96. void walk(const Position& oldPos, const Position& newPos);
  97. void preWalk(Otc::Direction direction);
  98. void cancelWalk(Otc::Direction direction = Otc::InvalidDirection);
  99. void stopWalk();
  100. friend class Game;
  101. protected:
  102. void updateWalkOffset(int totalPixelsWalked);
  103. void updateWalk();
  104. void terminateWalk();
  105. private:
  106. // walk related
  107. Position m_lastPrewalkDestination;
  108. Position m_autoWalkDestination;
  109. Position m_lastAutoWalkPosition;
  110. ScheduledEventPtr m_serverWalkEndEvent;
  111. ScheduledEventPtr m_autoWalkContinueEvent;
  112. ticks_t m_walkLockExpiration;
  113. stdext::boolean<false> m_preWalking;
  114. stdext::boolean<true> m_lastPrewalkDone;
  115. stdext::boolean<false> m_secondPreWalk;
  116. stdext::boolean<false> m_serverWalking;
  117. stdext::boolean<false> m_knownCompletePath;
  118. stdext::boolean<false> m_premium;
  119. stdext::boolean<false> m_known;
  120. stdext::boolean<false> m_pending;
  121. ItemPtr m_inventoryItems[Otc::LastInventorySlot];
  122. Timer m_idleTimer;
  123. std::array<int, Otc::LastSkill> m_skillsLevel;
  124. std::array<int, Otc::LastSkill> m_skillsBaseLevel;
  125. std::array<int, Otc::LastSkill> m_skillsLevelPercent;
  126. std::vector<int> m_spells;
  127. int m_states;
  128. int m_vocation;
  129. int m_blessings;
  130. double m_health;
  131. double m_maxHealth;
  132. double m_freeCapacity;
  133. double m_totalCapacity;
  134. double m_experience;
  135. double m_level;
  136. double m_levelPercent;
  137. double m_mana;
  138. double m_maxMana;
  139. double m_magicLevel;
  140. double m_magicLevelPercent;
  141. double m_baseMagicLevel;
  142. double m_soul;
  143. double m_stamina;
  144. double m_regenerationTime;
  145. double m_offlineTrainingTime;
  146. };
  147. #endif