Entity.h 3.2 KB

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