Entity.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. private:
  42. float stamina;
  43. float hunger;
  44. float currentHP;
  45. float thirst;
  46. protected:
  47. float maxHP;
  48. float maxStamina;
  49. float maxHunger;
  50. float maxThirst;
  51. float targetDistanceLimit;
  52. float maxMovementSpeed;
  53. Framework::Vec3<float> speed;
  54. Framework::Vec3<float> faceDir;
  55. Framework::Vec3<float> faceOffset;
  56. Framework::RCArray<ItemSkill> skills;
  57. ActionTarget* target;
  58. int typeId;
  59. int currentDimensionId;
  60. bool removed;
  61. float gravityMultiplier;
  62. int id;
  63. int placeBlockCooldown;
  64. Framework::ZeitMesser time;
  65. Framework::Array<MovementFrame> movements;
  66. Framework::Critical cs;
  67. Framework::Array<Framework::ImmutablePair<int, Framework::Text>>
  68. statusBarObservers;
  69. virtual void onDeath();
  70. virtual void useItem(int typeId, Item* zItem);
  71. Entity(int typeId,
  72. Framework::Vec3<float> location,
  73. int dimensionId,
  74. int entityId);
  75. void addMovementFrame(MovementFrame& frame);
  76. void calculateTarget(
  77. Framework::Vec3<float> basePos, Framework::Vec3<float> direction);
  78. void removeStatusBarObserver(Entity* zSource, Framework::Text id);
  79. void addStatusBarObserver(Entity* zSource, Framework::Text id);
  80. void notifyStatusBarObservers(NetworkMessage* msg);
  81. public:
  82. virtual void prepareTick(const Dimension* zDimension);
  83. virtual void tick(const Dimension* zDimension);
  84. virtual void api(Framework::StreamReader* zRequest,
  85. NetworkMessage* zResponse, Entity* zSource);
  86. virtual void onTargetChange();
  87. virtual void onFall(float collisionSpeed);
  88. void setPosition(Framework::Vec3<float> pos);
  89. void setHP(float hp);
  90. void setStamina(float stamina);
  91. void setHunger(float hunger);
  92. void setThirst(float thirst);
  93. float getMaxHP() const;
  94. float getCurrentHP() const;
  95. float getStamina() const;
  96. float getMaxStamina() const;
  97. float getHunger() const;
  98. float getMaxHunger() const;
  99. float getThirst() const;
  100. float getMaxThirst() const;
  101. Framework::Vec3<float> getSpeed() const;
  102. Framework::Vec3<float> getFaceDir() const;
  103. Framework::Vec3<float> getPosition() const;
  104. float getGravityMultiplier() const;
  105. int getCurrentDimensionId() const;
  106. bool isRemoved() const;
  107. const EntityType* zType() const;
  108. const ActionTarget* zTarget() const;
  109. int getId() const;
  110. virtual bool hasDefaultModel() const;
  111. virtual ModelInfo getSpecialModel() const;
  112. float getMaxSpeed() const;
  113. bool isMoving() const;
  114. friend Effect;
  115. friend EntityType;
  116. };