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 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 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 setIcon(uint8 icon);
  59. void setSkullTexture(const std::string& filename);
  60. void setShieldTexture(const std::string& filename, bool blink);
  61. void setEmblemTexture(const std::string& filename);
  62. void setIconTexture(const std::string& filename);
  63. void setPassable(bool passable) { m_passable = passable; }
  64. void setSpeedFormula(double speedA, double speedB, double speedC);
  65. void addTimedSquare(uint8 color);
  66. void removeTimedSquare() { m_showTimedSquare = false; }
  67. void showStaticSquare(const Color& color) { m_showStaticSquare = true; m_staticSquareColor = color; }
  68. void hideStaticSquare() { m_showStaticSquare = false; }
  69. uint32 getId() { return m_id; }
  70. std::string getName() { return m_name; }
  71. uint8 getHealthPercent() { return m_healthPercent; }
  72. Otc::Direction getDirection() { return m_direction; }
  73. Outfit getOutfit() { return m_outfit; }
  74. Light getLight() { return m_light; }
  75. uint16 getSpeed() { return m_speed; }
  76. double getBaseSpeed() { return m_baseSpeed; }
  77. uint8 getSkull() { return m_skull; }
  78. uint8 getShield() { return m_shield; }
  79. uint8 getEmblem() { return m_emblem; }
  80. uint8 getIcon() { return m_icon; }
  81. bool isPassable() { return m_passable; }
  82. Point getDrawOffset();
  83. int getStepDuration(bool ignoreDiagonal = false, Otc::Direction dir = Otc::InvalidDirection);
  84. Point getWalkOffset() { return m_walkOffset; }
  85. Position getLastStepFromPosition() { return m_lastStepFromPosition; }
  86. Position getLastStepToPosition() { return m_lastStepToPosition; }
  87. float getStepProgress() { return m_walkTimer.ticksElapsed() / getStepDuration(); }
  88. float getStepTicksLeft() { return getStepDuration() - m_walkTimer.ticksElapsed(); }
  89. ticks_t getWalkTicksElapsed() { return m_walkTimer.ticksElapsed(); }
  90. double getSpeedFormula(Otc::SpeedFormula formula) { return m_speedFormula[formula]; }
  91. bool hasSpeedFormula();
  92. std::array<double, Otc::LastSpeedFormula> getSpeedFormulaArray() { return m_speedFormula; }
  93. virtual Point getDisplacement();
  94. virtual int getDisplacementX();
  95. virtual int getDisplacementY();
  96. virtual int getExactSize(int layer = 0, int xPattern = 0, int yPattern = 0, int zPattern = 0, int animationPhase = 0);
  97. PointF getJumpOffset() { return m_jumpOffset; }
  98. void updateShield();
  99. // walk related
  100. void turn(Otc::Direction direction);
  101. void jump(int height, int duration);
  102. virtual void walk(const Position& oldPos, const Position& newPos);
  103. virtual void stopWalk();
  104. void allowAppearWalk() { m_allowAppearWalk = true; }
  105. bool isWalking() { return m_walking; }
  106. bool isRemoved() { return m_removed; }
  107. bool isInvisible() { return m_outfit.getCategory() == ThingCategoryEffect && m_outfit.getAuxId() == 13; }
  108. bool isDead() { return m_healthPercent <= 0; }
  109. bool canBeSeen() { return !isInvisible() || isPlayer(); }
  110. bool isCreature() { return true; }
  111. const ThingTypePtr& getThingType();
  112. ThingType *rawGetThingType();
  113. virtual void onPositionChange(const Position& newPos, const Position& oldPos);
  114. virtual void onAppear();
  115. virtual void onDisappear();
  116. virtual void onDeath();
  117. protected:
  118. virtual void updateWalkAnimation(int totalPixelsWalked);
  119. virtual void updateWalkOffset(int totalPixelsWalked);
  120. void updateWalkingTile();
  121. virtual void nextWalkUpdate();
  122. virtual void updateWalk();
  123. virtual void terminateWalk();
  124. void updateOutfitColor(Color color, Color finalColor, Color delta, int duration);
  125. void updateJump();
  126. uint32 m_id;
  127. std::string m_name;
  128. uint8 m_healthPercent;
  129. Otc::Direction m_direction;
  130. Outfit m_outfit;
  131. Light m_light;
  132. int m_speed;
  133. double m_baseSpeed;
  134. uint8 m_skull;
  135. uint8 m_shield;
  136. uint8 m_emblem;
  137. uint8 m_icon;
  138. TexturePtr m_skullTexture;
  139. TexturePtr m_shieldTexture;
  140. TexturePtr m_emblemTexture;
  141. TexturePtr m_iconTexture;
  142. stdext::boolean<true> m_showShieldTexture;
  143. stdext::boolean<false> m_shieldBlink;
  144. stdext::boolean<false> m_passable;
  145. Color m_timedSquareColor;
  146. Color m_staticSquareColor;
  147. stdext::boolean<false> m_showTimedSquare;
  148. stdext::boolean<false> m_showStaticSquare;
  149. stdext::boolean<true> m_removed;
  150. CachedText m_nameCache;
  151. Color m_informationColor;
  152. Color m_outfitColor;
  153. ScheduledEventPtr m_outfitColorUpdateEvent;
  154. Timer m_outfitColorTimer;
  155. std::array<double, Otc::LastSpeedFormula> m_speedFormula;
  156. // walk related
  157. int m_walkAnimationPhase;
  158. int m_walkedPixels;
  159. uint m_footStep;
  160. Timer m_walkTimer;
  161. Timer m_footTimer;
  162. TilePtr m_walkingTile;
  163. stdext::boolean<false> m_walking;
  164. stdext::boolean<false> m_allowAppearWalk;
  165. stdext::boolean<false> m_footStepDrawn;
  166. ScheduledEventPtr m_walkUpdateEvent;
  167. ScheduledEventPtr m_walkFinishAnimEvent;
  168. EventPtr m_disappearEvent;
  169. Point m_walkOffset;
  170. Otc::Direction m_walkTurnDirection;
  171. Otc::Direction m_lastStepDirection;
  172. Position m_lastStepFromPosition;
  173. Position m_lastStepToPosition;
  174. Position m_oldPosition;
  175. // jump related
  176. float m_jumpHeight;
  177. float m_jumpDuration;
  178. PointF m_jumpOffset;
  179. Timer m_jumpTimer;
  180. };
  181. // @bindclass
  182. class Npc : public Creature
  183. {
  184. public:
  185. bool isNpc() { return true; }
  186. };
  187. // @bindclass
  188. class Monster : public Creature
  189. {
  190. public:
  191. bool isMonster() { return true; }
  192. };
  193. #endif