Entity.h 4.0 KB

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