Advertisement
Guest User

Untitled

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