Entity.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #pragma once
  2. #include <ReferenceCounter.h>
  3. #include <Vec2.h>
  4. #include <Vec3.h>
  5. #include <Writer.h>
  6. #include <Zeit.h>
  7. #include "Effect.h"
  8. #include "Inventory.h"
  9. #include "ItemSkill.h"
  10. #include "ModelInfo.h"
  11. #include "NetworkMessage.h"
  12. class EntityType;
  13. class Dimension;
  14. class ActionTarget
  15. {
  16. private:
  17. Framework::Vec3<int> blockPos;
  18. Direction targetBlockSide;
  19. int entityId;
  20. public:
  21. ActionTarget(Framework::Vec3<int> blockPos, Direction blockSide);
  22. ActionTarget(int entityId);
  23. bool isBlock(Framework::Vec3<int> blockPos, Direction blockSide) const;
  24. bool isEntity(int entityId) const;
  25. bool useItemSkillOnTarget(
  26. Entity* zActor, ItemSkill* zItemSkill, Item* zUsedItem);
  27. bool interactItemSkillOnTarget(
  28. Entity* zActor, ItemSkill* zItemSkill, Item* zUsedItem);
  29. bool placeBlock(Entity* zActor, Item* zItem);
  30. static void toMessage(
  31. const ActionTarget* zTarget, int dimensionId, NetworkMessage* zMsg);
  32. static void save(ActionTarget* zTarget, Framework::StreamWriter* zWriter);
  33. static ActionTarget* load(Framework::StreamReader* zReader);
  34. };
  35. struct MovementFrame
  36. {
  37. Framework::Vec3<float> direction;
  38. Framework::Vec3<float> targetPosition;
  39. int movementFlags;
  40. double duration;
  41. };
  42. class Entity : public Inventory
  43. {
  44. private:
  45. float stamina;
  46. float hunger;
  47. float currentHP;
  48. float thirst;
  49. int chatSecurityLevel;
  50. Framework::Punkt lastChunkCenter;
  51. int lastDimensionId;
  52. protected:
  53. float maxHP;
  54. float maxStamina;
  55. float maxHunger;
  56. float maxThirst;
  57. float targetDistanceLimit;
  58. float maxMovementSpeed;
  59. Framework::Vec3<float> speed;
  60. Framework::Vec3<float> faceDir;
  61. Framework::Vec3<float> faceOffset;
  62. Framework::RCArray<ItemSkill> skills;
  63. ActionTarget* target;
  64. int typeId;
  65. bool removed;
  66. float gravityMultiplier;
  67. float jumpSpeed;
  68. int id;
  69. int placeBlockCooldown;
  70. Framework::ZeitMesser time;
  71. Framework::Array<MovementFrame> movements;
  72. Framework::Critical cs;
  73. Framework::Array<Framework::ImmutablePair<int, Framework::Text>>
  74. statusBarObservers;
  75. virtual void onDeath();
  76. virtual bool useItem(int typeId, ItemStack* zStack, bool left);
  77. Entity(int typeId,
  78. Framework::Vec3<float> location,
  79. int dimensionId,
  80. int entityId);
  81. void addMovementFrame(MovementFrame& frame);
  82. void calculateTarget(Framework::Vec3<float> basePos,
  83. Framework::Vec3<float> direction,
  84. const Item* zItem);
  85. void removeStatusBarObserver(Entity* zSource, Framework::Text id);
  86. void addStatusBarObserver(Entity* zSource, Framework::Text id);
  87. void notifyStatusBarObservers(NetworkMessage* msg);
  88. ItemSkill* zSkill(int itemType);
  89. public:
  90. virtual void prepareTick(const Dimension* zDimension);
  91. virtual void tick(const Dimension* zDimension);
  92. virtual void api(Framework::StreamReader* zRequest,
  93. NetworkMessage* zResponse,
  94. Entity* zSource);
  95. virtual void onTargetChange();
  96. virtual bool interact(Item* zItem, Entity* zActor);
  97. virtual void onFall(float collisionSpeed);
  98. void setChatSecurityLevel(int level);
  99. void setPosition(Framework::Vec3<float> pos);
  100. virtual void takeDamage(Entity* zSource, float damage);
  101. void setHP(float hp);
  102. void setStamina(float stamina);
  103. void setHunger(float hunger);
  104. void setThirst(float thirst);
  105. void setGravityMultiplier(float multiplier);
  106. void setJumpSpeed(float speed);
  107. float getMaxHP() const;
  108. float getCurrentHP() const;
  109. float getStamina() const;
  110. float getMaxStamina() const;
  111. float getHunger() const;
  112. float getMaxHunger() const;
  113. float getThirst() const;
  114. float getMaxThirst() const;
  115. Framework::Vec3<float> getSpeed() const;
  116. Framework::Vec3<float> getFaceDir() const;
  117. Framework::Vec3<float> getPosition() const;
  118. float getGravityMultiplier() const;
  119. float getJumpSpeed() const;
  120. bool isRemoved() const;
  121. const EntityType* zType() const;
  122. const ActionTarget* zTarget() const;
  123. int getId() const;
  124. virtual bool hasDefaultModel() const;
  125. virtual ModelInfo* zSpecialModel() const;
  126. float getMaxSpeed() const;
  127. bool isMoving() const;
  128. int getChatSecurityLevel() const;
  129. friend Effect;
  130. friend EntityType;
  131. };