Entity.h 3.9 KB

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