Entity.h 3.2 KB

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