Entity.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #pragma once
  2. #include <Maybe.h>
  3. #include <Vec3.h>
  4. #include <Writer.h>
  5. #include <Zeit.h>
  6. #include "Inventory.h"
  7. #include "ItemSkill.h"
  8. #include "ModelInfo.h"
  9. #include "NetworkMessage.h"
  10. #include "UIObservable.h"
  11. class EntityType;
  12. class Dimension;
  13. class ActionTarget
  14. {
  15. private:
  16. Framework::Vec3<int> blockPos;
  17. Direction targetBlockSide;
  18. int entityId;
  19. public:
  20. ActionTarget(Framework::Vec3<int> blockPos, Direction blockSide);
  21. ActionTarget(int entityId);
  22. bool isBlock(Framework::Vec3<int> blockPos, Direction blockSide) const;
  23. bool isEntity(int entityId) const;
  24. bool useItemSkillOnTarget(
  25. Entity* zActor, ItemSkill* zItemSkill, Item* zUsedItem);
  26. bool interactItemSkillOnTarget(
  27. Entity* zActor, ItemSkill* zItemSkill, Item* zUsedItem);
  28. bool placeBlock(Entity* zActor, Item* zItem);
  29. static void toMessage(
  30. const ActionTarget* zTarget, int dimensionId, NetworkMessage* zMsg);
  31. static void save(ActionTarget* zTarget, Framework::StreamWriter* zWriter);
  32. static ActionTarget* load(Framework::StreamReader* zReader);
  33. };
  34. class MovementFlags
  35. {
  36. public:
  37. static const int SNEAKING = 0x00001;
  38. static const int SPRINTING = 0x00002;
  39. static const int FLYING = 0x00004;
  40. static const int JUMPING = 0x00008;
  41. static const int WALK_FORWARD = 0x00010;
  42. static const int WALK_BACKWARD = 0x00020;
  43. static const int WALK_LEFT = 0x00040;
  44. static const int WALK_RIGHT = 0x00080;
  45. static const int ROTATE_LEFT = 0x00100;
  46. static const int ROTATE_RIGHT = 0x00200;
  47. static const int GROUND_CONTACT = 0x01000;
  48. static const int ROTATE_TO_FACE = 0x02000;
  49. };
  50. class Entity : public Inventory
  51. {
  52. private:
  53. UIObservable statusBarObservable;
  54. float stamina;
  55. float hunger;
  56. float currentHP;
  57. float thirst;
  58. int chatSecurityLevel;
  59. Framework::Punkt lastChunkCenter;
  60. int lastDimensionId;
  61. Framework::Maybe<Framework::Punkt> lastSavedChunkCenter;
  62. protected:
  63. float maxHP;
  64. float maxStamina;
  65. float maxHunger;
  66. float maxThirst;
  67. float targetDistanceLimit;
  68. float maxMovementSpeed;
  69. Framework::Vec3<float> speed;
  70. Framework::Vec3<float> faceDir;
  71. Framework::Vec3<float> faceOffset;
  72. Framework::RCArray<ItemSkill> skills;
  73. ActionTarget* target;
  74. int typeId;
  75. bool removed;
  76. float gravityMultiplier;
  77. float jumpSpeed;
  78. int id;
  79. double placeBlockCooldown;
  80. Framework::Critical cs;
  81. Framework::Vec3<float> boundingBox;
  82. float rotation;
  83. int movementFlags;
  84. bool* collisionMap;
  85. int collisionMapLength;
  86. virtual void onDeath(
  87. Entity* zActor, Item* zUsedItem, ItemSkill* zUsedSkill);
  88. virtual bool useItem(int typeId, ItemStack* zStack, bool left);
  89. Entity(int typeId,
  90. Framework::Vec3<float> location,
  91. int dimensionId,
  92. int entityId);
  93. void calculateTarget(const Item* zItem);
  94. void notifyStatusBarObservers(NetworkMessage* msg);
  95. ItemSkill* zSkill(int itemType);
  96. void calcBlockCollision(int& x, int& y, int& xl, int& yl);
  97. bool isCollidingWithBlock(const Dimension* zDimension);
  98. bool isCollidingWithBlock(
  99. const Dimension* zDimension, int x, int y, int xl, int yl);
  100. void addItems(
  101. ItemStack* zItems, Direction dir, ItemFilter* zFilter) override;
  102. public:
  103. virtual void prepareTick(const Dimension* zDimension, double seconds);
  104. virtual void tick(const Dimension* zDimension, double seconds);
  105. virtual void api(Framework::StreamReader* zRequest,
  106. NetworkMessage* zResponse,
  107. Entity* zSource);
  108. virtual void onTargetChange();
  109. virtual bool interact(Item* zItem, Entity* zActor);
  110. virtual void onFall(float collisionSpeed);
  111. virtual Framework::XML::Element* getTargetUIML() const;
  112. void setChatSecurityLevel(int level);
  113. void setPosition(Framework::Vec3<float> pos);
  114. virtual void takeDamage(
  115. Entity* zSource, Item* zUsedItem, ItemSkill* zUsedSkill, float damage);
  116. void setHP(
  117. Entity* zActor, Item* zUsedItem, ItemSkill* zUsedSkill, float hp);
  118. void setStamina(float stamina);
  119. void setHunger(float hunger);
  120. void setThirst(float thirst);
  121. void setGravityMultiplier(float multiplier);
  122. void setJumpSpeed(float speed);
  123. float getMaxHP() const;
  124. float getCurrentHP() const;
  125. float getStamina() const;
  126. float getMaxStamina() const;
  127. float getHunger() const;
  128. float getMaxHunger() const;
  129. float getThirst() const;
  130. float getMaxThirst() const;
  131. Framework::Vec3<float> getSpeed() const;
  132. Framework::Vec3<float> getFaceDir() const;
  133. Framework::Vec3<float> getPosition() const;
  134. float getGravityMultiplier() const;
  135. float getJumpSpeed() const;
  136. bool isRemoved() const;
  137. const EntityType* zType() const;
  138. const ActionTarget* zTarget() const;
  139. int getId() const;
  140. virtual bool hasDefaultModel() const;
  141. virtual ModelInfo* zSpecialModel() const;
  142. float getMaxSpeed() const;
  143. bool isMoving() const;
  144. int getChatSecurityLevel() const;
  145. Framework::Maybe<Framework::Punkt> getLastSavedChunkCenter() const;
  146. void setLastSavedChunkCenter(Framework::Punkt pos);
  147. void setRemoved();
  148. double getHitDistance(Framework::Vec3<float> rayOrigin,
  149. Framework::Vec3<float> rayDirection) const;
  150. float getRotation() const;
  151. void addItems(ItemSlot* zSlot, ItemStack* zItems, Direction dir) override;
  152. friend EntityType;
  153. };