Otclient  14/8/2020
localplayer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 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 
23 #ifndef LOCALPLAYER_H
24 #define LOCALPLAYER_H
25 
26 #include "player.h"
27 
28 // @bindclass
29 class LocalPlayer : public Player
30 {
31  enum {
32  PREWALK_TIMEOUT = 1000
33  };
34 
35 public:
36  LocalPlayer();
37 
38  void unlockWalk() { m_walkLockExpiration = 0; }
39  void lockWalk(int millis = 250);
40  void stopAutoWalk();
41  bool autoWalk(const Position& destination);
42  bool canWalk(Otc::Direction direction);
43 
44  void setStates(int states);
45  void setSkill(Otc::Skill skill, int level, int levelPercent);
46  void setBaseSkill(Otc::Skill skill, int baseLevel);
47  void setHealth(double health, double maxHealth);
48  void setFreeCapacity(double freeCapacity);
49  void setTotalCapacity(double totalCapacity);
50  void setExperience(double experience);
51  void setLevel(double level, double levelPercent);
52  void setMana(double mana, double maxMana);
53  void setMagicLevel(double magicLevel, double magicLevelPercent);
54  void setBaseMagicLevel(double baseMagicLevel);
55  void setSoul(double soul);
56  void setStamina(double stamina);
57  void setKnown(bool known) { m_known = known; }
58  void setPendingGame(bool pending) { m_pending = pending; }
59  void setInventoryItem(Otc::InventorySlot inventory, const ItemPtr& item);
60  void setVocation(int vocation);
61  void setPremium(bool premium);
62  void setRegenerationTime(double regenerationTime);
63  void setOfflineTrainingTime(double offlineTrainingTime);
64  void setSpells(const std::vector<int>& spells);
65  void setBlessings(int blessings);
66 
67  int getStates() { return m_states; }
68  int getSkillLevel(Otc::Skill skill) { return m_skillsLevel[skill]; }
69  int getSkillBaseLevel(Otc::Skill skill) { return m_skillsBaseLevel[skill]; }
70  int getSkillLevelPercent(Otc::Skill skill) { return m_skillsLevelPercent[skill]; }
71  int getVocation() { return m_vocation; }
72  double getHealth() { return m_health; }
73  double getMaxHealth() { return m_maxHealth; }
74  double getFreeCapacity() { return m_freeCapacity; }
75  double getTotalCapacity() { return m_totalCapacity; }
76  double getExperience() { return m_experience; }
77  double getLevel() { return m_level; }
78  double getLevelPercent() { return m_levelPercent; }
79  double getMana() { return m_mana; }
80  double getMaxMana() { return m_maxMana; }
81  double getMagicLevel() { return m_magicLevel; }
82  double getMagicLevelPercent() { return m_magicLevelPercent; }
83  double getBaseMagicLevel() { return m_baseMagicLevel; }
84  double getSoul() { return m_soul; }
85  double getStamina() { return m_stamina; }
86  double getRegenerationTime() { return m_regenerationTime; }
87  double getOfflineTrainingTime() { return m_offlineTrainingTime; }
88  std::vector<int> getSpells() { return m_spells; }
89  ItemPtr getInventoryItem(Otc::InventorySlot inventory) { return m_inventoryItems[inventory]; }
90  int getBlessings() { return m_blessings; }
91 
92  bool hasSight(const Position& pos);
93  bool isKnown() { return m_known; }
94  bool isPreWalking() { return m_preWalking; }
95  bool isAutoWalking() { return m_autoWalkDestination.isValid(); }
96  bool isServerWalking() { return m_serverWalking; }
97  bool isPremium() { return m_premium; }
98  bool isPendingGame() { return m_pending; }
99 
100  LocalPlayerPtr asLocalPlayer() { return static_self_cast<LocalPlayer>(); }
101  bool isLocalPlayer() { return true; }
102 
103  virtual void onAppear();
104  virtual void onPositionChange(const Position& newPos, const Position& oldPos);
105 
106 protected:
107  void walk(const Position& oldPos, const Position& newPos);
108  void preWalk(Otc::Direction direction);
110  void stopWalk();
111 
112  friend class Game;
113 
114 protected:
115  void updateWalkOffset(int totalPixelsWalked);
116  void updateWalk();
117  void terminateWalk();
118 
119 private:
120  // walk related
121  Position m_lastPrewalkDestination;
122  Position m_autoWalkDestination;
123  Position m_lastAutoWalkPosition;
124  ScheduledEventPtr m_serverWalkEndEvent;
125  ScheduledEventPtr m_autoWalkContinueEvent;
126  ticks_t m_walkLockExpiration;
127  stdext::boolean<false> m_preWalking;
128  stdext::boolean<true> m_lastPrewalkDone;
129  stdext::boolean<false> m_secondPreWalk;
130  stdext::boolean<false> m_serverWalking;
131  stdext::boolean<false> m_knownCompletePath;
132 
133  stdext::boolean<false> m_premium;
134  stdext::boolean<false> m_known;
135  stdext::boolean<false> m_pending;
136 
137  ItemPtr m_inventoryItems[Otc::LastInventorySlot];
138  Timer m_idleTimer;
139 
140  std::array<int, Otc::LastSkill> m_skillsLevel;
141  std::array<int, Otc::LastSkill> m_skillsBaseLevel;
142  std::array<int, Otc::LastSkill> m_skillsLevelPercent;
143  std::vector<int> m_spells;
144 
145  int m_states;
146  int m_vocation;
147  int m_blessings;
148 
149  double m_health;
150  double m_maxHealth;
151  double m_freeCapacity;
152  double m_totalCapacity;
153  double m_experience;
154  double m_level;
155  double m_levelPercent;
156  double m_mana;
157  double m_maxMana;
158  double m_magicLevel;
159  double m_magicLevelPercent;
160  double m_baseMagicLevel;
161  double m_soul;
162  double m_stamina;
163  double m_regenerationTime;
164  double m_offlineTrainingTime;
165 };
166 
167 #endif
stdext::millis
ticks_t millis()
Definition: time.cpp:37
Otc::InvalidDirection
@ InvalidDirection
Definition: const.h:170
LocalPlayer::setHealth
void setHealth(double health, double maxHealth)
Definition: localplayer.cpp:364
LocalPlayer::getMagicLevelPercent
double getMagicLevelPercent()
Definition: localplayer.h:82
LocalPlayer::setRegenerationTime
void setRegenerationTime(double regenerationTime)
Definition: localplayer.cpp:513
LocalPlayer::getMagicLevel
double getMagicLevel()
Definition: localplayer.h:81
LocalPlayer::getBaseMagicLevel
double getBaseMagicLevel()
Definition: localplayer.h:83
LocalPlayer::cancelWalk
void cancelWalk(Otc::Direction direction=Otc::InvalidDirection)
Definition: localplayer.cpp:139
LocalPlayer::canWalk
bool canWalk(Otc::Direction direction)
Definition: localplayer.cpp:65
LocalPlayer::updateWalkOffset
void updateWalkOffset(int totalPixelsWalked)
Definition: localplayer.cpp:248
LocalPlayer::setMana
void setMana(double mana, double maxMana)
Definition: localplayer.cpp:425
LocalPlayer::stopWalk
void stopWalk()
Definition: localplayer.cpp:240
LocalPlayer::isKnown
bool isKnown()
Definition: localplayer.h:93
LocalPlayer::getStamina
double getStamina()
Definition: localplayer.h:85
LocalPlayer::onAppear
virtual void onAppear()
Definition: localplayer.cpp:300
LocalPlayer::getFreeCapacity
double getFreeCapacity()
Definition: localplayer.h:74
LocalPlayer::lockWalk
void lockWalk(int millis=250)
Definition: localplayer.cpp:60
LocalPlayer::isPremium
bool isPremium()
Definition: localplayer.h:97
LocalPlayer
Definition: localplayer.h:29
LocalPlayer::getVocation
int getVocation()
Definition: localplayer.h:71
Position::isValid
bool isValid() const
Definition: position.h:182
LocalPlayer::getStates
int getStates()
Definition: localplayer.h:67
LocalPlayer::setLevel
void setLevel(double level, double levelPercent)
Definition: localplayer.cpp:413
Otc::LastInventorySlot
@ LastInventorySlot
Definition: const.h:125
LocalPlayer::asLocalPlayer
LocalPlayerPtr asLocalPlayer()
Definition: localplayer.h:100
LocalPlayer::getSpells
std::vector< int > getSpells()
Definition: localplayer.h:88
LocalPlayer::autoWalk
bool autoWalk(const Position &destination)
Definition: localplayer.cpp:167
LocalPlayer::setKnown
void setKnown(bool known)
Definition: localplayer.h:57
LocalPlayer::getSkillBaseLevel
int getSkillBaseLevel(Otc::Skill skill)
Definition: localplayer.h:69
ticks_t
int64 ticks_t
Definition: types.h:43
LocalPlayer::getMana
double getMana()
Definition: localplayer.h:79
LocalPlayer::setInventoryItem
void setInventoryItem(Otc::InventorySlot inventory, const ItemPtr &item)
Definition: localplayer.cpp:479
LocalPlayer::isLocalPlayer
bool isLocalPlayer()
Definition: localplayer.h:101
LocalPlayer::hasSight
bool hasSight(const Position &pos)
Definition: localplayer.cpp:553
stdext::boolean< false >
Otc::Skill
Skill
Definition: const.h:144
LocalPlayer::setBaseMagicLevel
void setBaseMagicLevel(double baseMagicLevel)
Definition: localplayer.cpp:449
LocalPlayer::preWalk
void preWalk(Otc::Direction direction)
Definition: localplayer.cpp:118
LocalPlayer::getMaxHealth
double getMaxHealth()
Definition: localplayer.h:73
LocalPlayer::unlockWalk
void unlockWalk()
Definition: localplayer.h:38
Otc::Direction
Direction
Definition: const.h:161
LocalPlayer::getExperience
double getExperience()
Definition: localplayer.h:76
LocalPlayer::stopAutoWalk
void stopAutoWalk()
Definition: localplayer.cpp:230
LocalPlayer::setMagicLevel
void setMagicLevel(double magicLevel, double magicLevelPercent)
Definition: localplayer.cpp:437
LocalPlayer::setStates
void setStates(int states)
Definition: localplayer.cpp:321
LocalPlayer::setPremium
void setPremium(bool premium)
Definition: localplayer.cpp:504
LocalPlayer::setExperience
void setExperience(double experience)
Definition: localplayer.cpp:403
LocalPlayer::terminateWalk
void terminateWalk()
Definition: localplayer.cpp:282
LocalPlayer::setSoul
void setSoul(double soul)
Definition: localplayer.cpp:459
LocalPlayer::isServerWalking
bool isServerWalking()
Definition: localplayer.h:96
Position
Definition: position.h:33
LocalPlayer::onPositionChange
virtual void onPositionChange(const Position &newPos, const Position &oldPos)
Definition: localplayer.cpp:311
LocalPlayer::setVocation
void setVocation(int vocation)
Definition: localplayer.cpp:494
LocalPlayer::getHealth
double getHealth()
Definition: localplayer.h:72
LocalPlayer::isAutoWalking
bool isAutoWalking()
Definition: localplayer.h:95
LocalPlayer::LocalPlayer
LocalPlayer()
Definition: localplayer.cpp:30
LocalPlayer::setOfflineTrainingTime
void setOfflineTrainingTime(double offlineTrainingTime)
Definition: localplayer.cpp:523
player.h
LocalPlayer::getMaxMana
double getMaxMana()
Definition: localplayer.h:80
LocalPlayer::getSoul
double getSoul()
Definition: localplayer.h:84
LocalPlayer::setTotalCapacity
void setTotalCapacity(double totalCapacity)
Definition: localplayer.cpp:393
LocalPlayer::getRegenerationTime
double getRegenerationTime()
Definition: localplayer.h:86
Otc::InventorySlot
InventorySlot
Definition: const.h:109
LocalPlayer::getOfflineTrainingTime
double getOfflineTrainingTime()
Definition: localplayer.h:87
LocalPlayer::setBaseSkill
void setBaseSkill(Otc::Skill skill, int baseLevel)
Definition: localplayer.cpp:349
LocalPlayer::isPreWalking
bool isPreWalking()
Definition: localplayer.h:94
stdext::shared_object_ptr< Item >
LocalPlayer::getBlessings
int getBlessings()
Definition: localplayer.h:90
LocalPlayer::setStamina
void setStamina(double stamina)
Definition: localplayer.cpp:469
LocalPlayer::setSpells
void setSpells(const std::vector< int > &spells)
Definition: localplayer.cpp:533
LocalPlayer::isPendingGame
bool isPendingGame()
Definition: localplayer.h:98
LocalPlayer::getInventoryItem
ItemPtr getInventoryItem(Otc::InventorySlot inventory)
Definition: localplayer.h:89
Timer
Definition: timer.h:28
LocalPlayer::getSkillLevelPercent
int getSkillLevelPercent(Otc::Skill skill)
Definition: localplayer.h:70
LocalPlayer::setBlessings
void setBlessings(int blessings)
Definition: localplayer.cpp:543
LocalPlayer::getLevelPercent
double getLevelPercent()
Definition: localplayer.h:78
LocalPlayer::walk
void walk(const Position &oldPos, const Position &newPos)
Definition: localplayer.cpp:93
LocalPlayer::getLevel
double getLevel()
Definition: localplayer.h:77
LocalPlayer::setFreeCapacity
void setFreeCapacity(double freeCapacity)
Definition: localplayer.cpp:383
LocalPlayer::getTotalCapacity
double getTotalCapacity()
Definition: localplayer.h:75
Player
Definition: player.h:29
LocalPlayer::getSkillLevel
int getSkillLevel(Otc::Skill skill)
Definition: localplayer.h:68
LocalPlayer::setPendingGame
void setPendingGame(bool pending)
Definition: localplayer.h:58
Game
Definition: game.h:61
LocalPlayer::setSkill
void setSkill(Otc::Skill skill, int level, int levelPercent)
Definition: localplayer.cpp:331
LocalPlayer::updateWalk
void updateWalk()
Definition: localplayer.cpp:266