Entity.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #pragma once
  2. #include <ReferenceCounter.h>
  3. #include <Vec3.h>
  4. #include <Vec2.h>
  5. #include <Writer.h>
  6. #include <Zeit.h>
  7. #include "Effect.h"
  8. #include "Inventory.h"
  9. #include "NetworkMessage.h"
  10. #include "ItemSkill.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. void applyItemSkillOnTarget(Entity* zActor, ItemSkill* zItemSkill, Item* zUsedItem);
  25. void placeBlock(Entity* zActor, Item* zItem);
  26. static void toMessage(const ActionTarget* zTarget, NetworkMessage* zMsg);
  27. static void save(ActionTarget* zTarget, Framework::StreamWriter* zWriter);
  28. static ActionTarget* load(Framework::StreamReader* zReader);
  29. };
  30. struct MovementFrame
  31. {
  32. Framework::Vec3<float> direction;
  33. Framework::Vec3<float> targetPosition;
  34. int movementFlags;
  35. double duration;
  36. };
  37. class Entity : public Inventory
  38. {
  39. protected:
  40. float maxHP;
  41. float currentHP;
  42. float stamina;
  43. float maxStamina;
  44. float hunger;
  45. float maxHunger;
  46. float thirst;
  47. float maxThirst;
  48. float targetDistanceLimit;
  49. float maxMovementSpeed;
  50. Framework::Vec3<float> speed;
  51. Framework::Vec3<float> faceDir;
  52. Framework::Vec3<float> faceOffset;
  53. Framework::RCArray<ItemSkill> skills;
  54. ActionTarget* target;
  55. const EntityType* zEntityType;
  56. int currentDimensionId;
  57. bool removed;
  58. float gravityMultiplier;
  59. int id;
  60. Framework::ZeitMesser time;
  61. Framework::Array<MovementFrame> movements;
  62. Framework::Critical cs;
  63. virtual void onDeath();
  64. virtual void useItem(const ItemType* zType, Item* zItem);
  65. Entity(const EntityType* zType, Framework::Vec3<float> location, int dimensionId, int entityId);
  66. virtual void onTargetChange();
  67. void addMovementFrame(MovementFrame& frame);
  68. void calculateTarget(Framework::Vec3<float> basePos, Framework::Vec3<float> direction);
  69. public:
  70. virtual void prepareTick(const Dimension* zDimension);
  71. virtual void tick(const Dimension* zDimension);
  72. virtual void api(Framework::StreamReader* zRequest, NetworkMessage* zResponse);
  73. virtual void onFall(float collisionSpeed);
  74. void setPosition(Framework::Vec3<float> pos);
  75. float getMaxHP() const;
  76. float getCurrentHP() const;
  77. float getStamina() const;
  78. float getMaxStamina() const;
  79. float getHunger() const;
  80. float getMaxHunger() const;
  81. float getThirst() const;
  82. float getMaxThirst() const;
  83. Framework::Vec3<float> getSpeed() const;
  84. Framework::Vec3<float> getFaceDir() const;
  85. Framework::Vec3<float> getPosition() const;
  86. float getGravityMultiplier() const;
  87. int getCurrentDimensionId() const;
  88. bool isRemoved() const;
  89. const EntityType* zType() const;
  90. const ActionTarget* zTarget() const;
  91. int getId() const;
  92. virtual bool hasDefaultModel() const;
  93. virtual ModelInfo getSpecialModel() const;
  94. float getMaxSpeed() const;
  95. bool isMoving() const;
  96. friend Effect;
  97. friend EntityType;
  98. };