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.

thingtype.h 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 THINGTYPE_H
  23. #define THINGTYPE_H
  24. #include "declarations.h"
  25. #include "animator.h"
  26. #include <framework/core/declarations.h>
  27. #include <framework/otml/declarations.h>
  28. #include <framework/graphics/texture.h>
  29. #include <framework/graphics/coordsbuffer.h>
  30. #include <framework/luaengine/luaobject.h>
  31. #include <framework/net/server.h>
  32. enum FrameGroupType : uint8 {
  33. FrameGroupDefault = 0,
  34. FrameGroupIdle = FrameGroupDefault,
  35. FrameGroupMoving
  36. };
  37. enum ThingCategory : uint8 {
  38. ThingCategoryItem = 0,
  39. ThingCategoryCreature,
  40. ThingCategoryEffect,
  41. ThingCategoryMissile,
  42. ThingInvalidCategory,
  43. ThingLastCategory = ThingInvalidCategory
  44. };
  45. enum ThingAttr : uint8 {
  46. ThingAttrGround = 0,
  47. ThingAttrGroundBorder = 1,
  48. ThingAttrOnBottom = 2,
  49. ThingAttrOnTop = 3,
  50. ThingAttrContainer = 4,
  51. ThingAttrStackable = 5,
  52. ThingAttrForceUse = 6,
  53. ThingAttrMultiUse = 7,
  54. ThingAttrWritable = 8,
  55. ThingAttrWritableOnce = 9,
  56. ThingAttrFluidContainer = 10,
  57. ThingAttrSplash = 11,
  58. ThingAttrNotWalkable = 12,
  59. ThingAttrNotMoveable = 13,
  60. ThingAttrBlockProjectile = 14,
  61. ThingAttrNotPathable = 15,
  62. ThingAttrPickupable = 16,
  63. ThingAttrHangable = 17,
  64. ThingAttrHookSouth = 18,
  65. ThingAttrHookEast = 19,
  66. ThingAttrRotateable = 20,
  67. ThingAttrLight = 21,
  68. ThingAttrDontHide = 22,
  69. ThingAttrTranslucent = 23,
  70. ThingAttrDisplacement = 24,
  71. ThingAttrElevation = 25,
  72. ThingAttrLyingCorpse = 26,
  73. ThingAttrAnimateAlways = 27,
  74. ThingAttrMinimapColor = 28,
  75. ThingAttrLensHelp = 29,
  76. ThingAttrFullGround = 30,
  77. ThingAttrLook = 31,
  78. ThingAttrCloth = 32,
  79. ThingAttrMarket = 33,
  80. ThingAttrUsable = 34,
  81. ThingAttrWrapable = 35,
  82. ThingAttrUnwrapable = 36,
  83. ThingAttrTopEffect = 37,
  84. // additional
  85. ThingAttrOpacity = 100,
  86. ThingAttrNotPreWalkable = 101,
  87. ThingAttrFloorChange = 252,
  88. ThingAttrNoMoveAnimation = 253, // 10.10: real value is 16, but we need to do this for backwards compatibility
  89. ThingAttrChargeable = 254, // deprecated
  90. ThingLastAttr = 255
  91. };
  92. enum SpriteMask {
  93. SpriteMaskRed = 1,
  94. SpriteMaskGreen,
  95. SpriteMaskBlue,
  96. SpriteMaskYellow
  97. };
  98. struct MarketData {
  99. std::string name;
  100. int category;
  101. uint16 requiredLevel;
  102. uint16 restrictVocation;
  103. uint16 showAs;
  104. uint16 tradeAs;
  105. };
  106. struct Light {
  107. Light() { intensity = 0; color = 215; }
  108. uint8 intensity;
  109. uint8 color;
  110. };
  111. class ThingType : public LuaObject
  112. {
  113. public:
  114. ThingType();
  115. void unserialize(uint16 clientId, ThingCategory category, const FileStreamPtr& fin);
  116. void unserializeOtml(const OTMLNodePtr& node);
  117. void serialize(const FileStreamPtr& fin);
  118. void exportImage(std::string fileName);
  119. void draw(const Point& dest, float scaleFactor, int layer, int xPattern, int yPattern, int zPattern, int animationPhase, LightView *lightView = nullptr);
  120. uint16 getId() { return m_id; }
  121. ThingCategory getCategory() { return m_category; }
  122. bool isNull() { return m_null; }
  123. bool hasAttr(ThingAttr attr) { return m_attribs.has(attr); }
  124. Size getSize() { return m_size; }
  125. int getWidth() { return m_size.width(); }
  126. int getHeight() { return m_size.height(); }
  127. int getExactSize(int layer = 0, int xPattern = 0, int yPattern = 0, int zPattern = 0, int animationPhase = 0);
  128. int getRealSize() { return m_realSize; }
  129. int getLayers() { return m_layers; }
  130. int getNumPatternX() { return m_numPatternX; }
  131. int getNumPatternY() { return m_numPatternY; }
  132. int getNumPatternZ() { return m_numPatternZ; }
  133. int getAnimationPhases() { return m_animationPhases; }
  134. AnimatorPtr getAnimator() { return m_animator; }
  135. Point getDisplacement() { return m_displacement; }
  136. int getDisplacementX() { return getDisplacement().x; }
  137. int getDisplacementY() { return getDisplacement().y; }
  138. int getElevation() { return m_elevation; }
  139. int getGroundSpeed() { return m_attribs.get<uint16>(ThingAttrGround); }
  140. int getMaxTextLength() { return m_attribs.has(ThingAttrWritableOnce) ? m_attribs.get<uint16>(ThingAttrWritableOnce) : m_attribs.get<uint16>(ThingAttrWritable); }
  141. Light getLight() { return m_attribs.get<Light>(ThingAttrLight); }
  142. int getMinimapColor() { return m_attribs.get<uint16>(ThingAttrMinimapColor); }
  143. int getLensHelp() { return m_attribs.get<uint16>(ThingAttrLensHelp); }
  144. int getClothSlot() { return m_attribs.get<uint16>(ThingAttrCloth); }
  145. MarketData getMarketData() { return m_attribs.get<MarketData>(ThingAttrMarket); }
  146. bool isGround() { return m_attribs.has(ThingAttrGround); }
  147. bool isGroundBorder() { return m_attribs.has(ThingAttrGroundBorder); }
  148. bool isOnBottom() { return m_attribs.has(ThingAttrOnBottom); }
  149. bool isOnTop() { return m_attribs.has(ThingAttrOnTop); }
  150. bool isContainer() { return m_attribs.has(ThingAttrContainer); }
  151. bool isStackable() { return m_attribs.has(ThingAttrStackable); }
  152. bool isForceUse() { return m_attribs.has(ThingAttrForceUse); }
  153. bool isMultiUse() { return m_attribs.has(ThingAttrMultiUse); }
  154. bool isWritable() { return m_attribs.has(ThingAttrWritable); }
  155. bool isChargeable() { return m_attribs.has(ThingAttrChargeable); }
  156. bool isWritableOnce() { return m_attribs.has(ThingAttrWritableOnce); }
  157. bool isFluidContainer() { return m_attribs.has(ThingAttrFluidContainer); }
  158. bool isSplash() { return m_attribs.has(ThingAttrSplash); }
  159. bool isNotWalkable() { return m_attribs.has(ThingAttrNotWalkable); }
  160. bool isNotMoveable() { return m_attribs.has(ThingAttrNotMoveable); }
  161. bool blockProjectile() { return m_attribs.has(ThingAttrBlockProjectile); }
  162. bool isNotPathable() { return m_attribs.has(ThingAttrNotPathable); }
  163. bool isPickupable() { return m_attribs.has(ThingAttrPickupable); }
  164. bool isHangable() { return m_attribs.has(ThingAttrHangable); }
  165. bool isHookSouth() { return m_attribs.has(ThingAttrHookSouth); }
  166. bool isHookEast() { return m_attribs.has(ThingAttrHookEast); }
  167. bool isRotateable() { return m_attribs.has(ThingAttrRotateable); }
  168. bool hasLight() { return m_attribs.has(ThingAttrLight); }
  169. bool isDontHide() { return m_attribs.has(ThingAttrDontHide); }
  170. bool isTranslucent() { return m_attribs.has(ThingAttrTranslucent); }
  171. bool hasDisplacement() { return m_attribs.has(ThingAttrDisplacement); }
  172. bool hasElevation() { return m_attribs.has(ThingAttrElevation); }
  173. bool isLyingCorpse() { return m_attribs.has(ThingAttrLyingCorpse); }
  174. bool isAnimateAlways() { return m_attribs.has(ThingAttrAnimateAlways); }
  175. bool hasMiniMapColor() { return m_attribs.has(ThingAttrMinimapColor); }
  176. bool hasLensHelp() { return m_attribs.has(ThingAttrLensHelp); }
  177. bool isFullGround() { return m_attribs.has(ThingAttrFullGround); }
  178. bool isIgnoreLook() { return m_attribs.has(ThingAttrLook); }
  179. bool isCloth() { return m_attribs.has(ThingAttrCloth); }
  180. bool isMarketable() { return m_attribs.has(ThingAttrMarket); }
  181. bool isUsable() { return m_attribs.has(ThingAttrUsable); }
  182. bool isWrapable() { return m_attribs.has(ThingAttrWrapable); }
  183. bool isUnwrapable() { return m_attribs.has(ThingAttrUnwrapable); }
  184. bool isTopEffect() { return m_attribs.has(ThingAttrTopEffect); }
  185. std::vector<int> getSprites() { return m_spritesIndex; }
  186. // additional
  187. float getOpacity() { return m_opacity; }
  188. bool isNotPreWalkable() { return m_attribs.has(ThingAttrNotPreWalkable); }
  189. void setPathable(bool var);
  190. private:
  191. const TexturePtr& getTexture(int animationPhase);
  192. Size getBestTextureDimension(int w, int h, int count);
  193. uint getSpriteIndex(int w, int h, int l, int x, int y, int z, int a);
  194. uint getTextureIndex(int l, int x, int y, int z);
  195. ThingCategory m_category;
  196. uint16 m_id;
  197. bool m_null;
  198. stdext::dynamic_storage<uint8> m_attribs;
  199. Size m_size;
  200. Point m_displacement;
  201. AnimatorPtr m_animator;
  202. int m_animationPhases;
  203. int m_exactSize;
  204. int m_realSize;
  205. int m_numPatternX, m_numPatternY, m_numPatternZ;
  206. int m_layers;
  207. int m_elevation;
  208. float m_opacity;
  209. std::string m_customImage;
  210. std::vector<int> m_spritesIndex;
  211. std::vector<TexturePtr> m_textures;
  212. std::vector<std::vector<Rect>> m_texturesFramesRects;
  213. std::vector<std::vector<Rect>> m_texturesFramesOriginRects;
  214. std::vector<std::vector<Point>> m_texturesFramesOffsets;
  215. };
  216. #endif