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.

creature.h 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * Copyright (c) 2010-2017 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 CREATURE_H
  23. #define CREATURE_H
  24. #include "thing.h"
  25. #include "outfit.h"
  26. #include "tile.h"
  27. #include "mapview.h"
  28. #include <framework/core/scheduledevent.h>
  29. #include <framework/core/declarations.h>
  30. #include <framework/core/timer.h>
  31. #include <framework/graphics/fontmanager.h>
  32. #include <framework/graphics/cachedtext.h>
  33. // @bindclass
  34. class Creature : public Thing
  35. {
  36. public:
  37. enum {
  38. SHIELD_BLINK_TICKS = 500,
  39. VOLATILE_SQUARE_DURATION = 1000
  40. };
  41. Creature();
  42. virtual void draw(const Point& dest, float scaleFactor, bool animate, LightView *lightView = nullptr);
  43. void internalDrawOutfit(Point dest, float scaleFactor, bool animateWalk, bool animateIdle, Otc::Direction direction, LightView *lightView = nullptr);
  44. void drawOutfit(const Rect& destRect, bool resize);
  45. void drawInformation(const Point& point, bool useGray, const Rect& parentRect, int drawFlags);
  46. void setId(uint32 id) { m_id = id; }
  47. void setName(const std::string& name);
  48. void setHealthPercent(uint8 healthPercent);
  49. void setDirection(Otc::Direction direction);
  50. void setOutfit(const Outfit& outfit);
  51. void setOutfitColor(const Color& color, int duration);
  52. void setLight(const Light& light) { m_light = light; }
  53. void setSpeed(uint16 speed);
  54. void setBaseSpeed(double baseSpeed);
  55. void setSkull(uint8 skull);
  56. void setShield(uint8 shield);
  57. void setEmblem(uint8 emblem);
  58. void setType(uint8 type);
  59. void setIcon(uint8 icon);
  60. void setSkullTexture(const std::string& filename);
  61. void setShieldTexture(const std::string& filename, bool blink);
  62. void setEmblemTexture(const std::string& filename);
  63. void setTypeTexture(const std::string& filename);
  64. void setIconTexture(const std::string& filename);
  65. void setPassable(bool passable) { m_passable = passable; }
  66. void setSpeedFormula(double speedA, double speedB, double speedC);
  67. void addTimedSquare(uint8 color);
  68. void removeTimedSquare() { m_showTimedSquare = false; }
  69. void showStaticSquare(const Color& color) { m_showStaticSquare = true; m_staticSquareColor = color; }
  70. void hideStaticSquare() { m_showStaticSquare = false; }
  71. uint32 getId() { return m_id; }
  72. std::string getName() { return m_name; }
  73. uint8 getHealthPercent() { return m_healthPercent; }
  74. Otc::Direction getDirection() { return m_direction; }
  75. Outfit getOutfit() { return m_outfit; }
  76. Light getLight() { return m_light; }
  77. uint16 getSpeed() { return m_speed; }
  78. double getBaseSpeed() { return m_baseSpeed; }
  79. uint8 getSkull() { return m_skull; }
  80. uint8 getShield() { return m_shield; }
  81. uint8 getEmblem() { return m_emblem; }
  82. uint8 getType() { return m_type; }
  83. uint8 getIcon() { return m_icon; }
  84. bool isPassable() { return m_passable; }
  85. Point getDrawOffset();
  86. int getStepDuration(bool ignoreDiagonal = false, Otc::Direction dir = Otc::InvalidDirection);
  87. Point getWalkOffset() { return m_walkOffset; }
  88. Position getLastStepFromPosition() { return m_lastStepFromPosition; }
  89. Position getLastStepToPosition() { return m_lastStepToPosition; }
  90. float getStepProgress() { return m_walkTimer.ticksElapsed() / getStepDuration(); }
  91. float getStepTicksLeft() { return getStepDuration() - m_walkTimer.ticksElapsed(); }
  92. ticks_t getWalkTicksElapsed() { return m_walkTimer.ticksElapsed(); }
  93. double getSpeedFormula(Otc::SpeedFormula formula) { return m_speedFormula[formula]; }
  94. bool hasSpeedFormula();
  95. std::array<double, Otc::LastSpeedFormula> getSpeedFormulaArray() { return m_speedFormula; }
  96. virtual Point getDisplacement();
  97. virtual int getDisplacementX();
  98. virtual int getDisplacementY();
  99. virtual int getExactSize(int layer = 0, int xPattern = 0, int yPattern = 0, int zPattern = 0, int animationPhase = 0);
  100. PointF getJumpOffset() { return m_jumpOffset; }
  101. void updateShield();
  102. // walk related
  103. void turn(Otc::Direction direction);
  104. void jump(int height, int duration);
  105. virtual void walk(const Position& oldPos, const Position& newPos);
  106. virtual void stopWalk();
  107. void allowAppearWalk() { m_allowAppearWalk = true; }
  108. bool isWalking() { return m_walking; }
  109. bool isRemoved() { return m_removed; }
  110. bool isInvisible() { return m_outfit.getCategory() == ThingCategoryEffect && m_outfit.getAuxId() == 13; }
  111. bool isDead() { return m_healthPercent <= 0; }
  112. bool canBeSeen() { return !isInvisible() || isPlayer(); }
  113. bool isCreature() { return true; }
  114. const ThingTypePtr& getThingType();
  115. ThingType *rawGetThingType();
  116. virtual void onPositionChange(const Position& newPos, const Position& oldPos);
  117. virtual void onAppear();
  118. virtual void onDisappear();
  119. virtual void onDeath();
  120. protected:
  121. virtual void updateWalkAnimation(int totalPixelsWalked);
  122. virtual void updateWalkOffset(int totalPixelsWalked);
  123. void updateWalkingTile();
  124. virtual void nextWalkUpdate();
  125. virtual void updateWalk();
  126. virtual void terminateWalk();
  127. void updateOutfitColor(Color color, Color finalColor, Color delta, int duration);
  128. void updateJump();
  129. uint32 m_id;
  130. std::string m_name;
  131. uint8 m_healthPercent;
  132. Otc::Direction m_direction;
  133. Outfit m_outfit;
  134. Light m_light;
  135. int m_speed;
  136. double m_baseSpeed;
  137. uint8 m_skull;
  138. uint8 m_shield;
  139. uint8 m_emblem;
  140. uint8 m_type;
  141. uint8 m_icon;
  142. TexturePtr m_skullTexture;
  143. TexturePtr m_shieldTexture;
  144. TexturePtr m_emblemTexture;
  145. TexturePtr m_typeTexture;
  146. TexturePtr m_iconTexture;
  147. stdext::boolean<true> m_showShieldTexture;
  148. stdext::boolean<false> m_shieldBlink;
  149. stdext::boolean<false> m_passable;
  150. Color m_timedSquareColor;
  151. Color m_staticSquareColor;
  152. stdext::boolean<false> m_showTimedSquare;
  153. stdext::boolean<false> m_showStaticSquare;
  154. stdext::boolean<true> m_removed;
  155. CachedText m_nameCache;
  156. Color m_informationColor;
  157. Color m_outfitColor;
  158. ScheduledEventPtr m_outfitColorUpdateEvent;
  159. Timer m_outfitColorTimer;
  160. std::array<double, Otc::LastSpeedFormula> m_speedFormula;
  161. // walk related
  162. int m_walkAnimationPhase;
  163. int m_walkedPixels;
  164. uint m_footStep;
  165. Timer m_walkTimer;
  166. Timer m_footTimer;
  167. TilePtr m_walkingTile;
  168. stdext::boolean<false> m_walking;
  169. stdext::boolean<false> m_allowAppearWalk;
  170. stdext::boolean<false> m_footStepDrawn;
  171. ScheduledEventPtr m_walkUpdateEvent;
  172. ScheduledEventPtr m_walkFinishAnimEvent;
  173. EventPtr m_disappearEvent;
  174. Point m_walkOffset;
  175. Otc::Direction m_walkTurnDirection;
  176. Otc::Direction m_lastStepDirection;
  177. Position m_lastStepFromPosition;
  178. Position m_lastStepToPosition;
  179. Position m_oldPosition;
  180. // jump related
  181. float m_jumpHeight;
  182. float m_jumpDuration;
  183. PointF m_jumpOffset;
  184. Timer m_jumpTimer;
  185. };
  186. // @bindclass
  187. class Npc : public Creature
  188. {
  189. public:
  190. bool isNpc() { return true; }
  191. };
  192. // @bindclass
  193. class Monster : public Creature
  194. {
  195. public:
  196. bool isMonster() { return true; }
  197. };
  198. #endif