Entity.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. float jumpSpeed;
  66. int id;
  67. int placeBlockCooldown;
  68. Framework::ZeitMesser time;
  69. Framework::Array<MovementFrame> movements;
  70. Framework::Critical cs;
  71. Framework::Array<Framework::ImmutablePair<int, Framework::Text>>
  72. statusBarObservers;
  73. virtual void onDeath();
  74. virtual bool useItem(int typeId, ItemStack* zStack, bool left);
  75. Entity(int typeId,
  76. Framework::Vec3<float> location,
  77. int dimensionId,
  78. int entityId);
  79. void addMovementFrame(MovementFrame& frame);
  80. void calculateTarget(Framework::Vec3<float> basePos,
  81. Framework::Vec3<float> direction,
  82. const Item* zItem);
  83. void removeStatusBarObserver(Entity* zSource, Framework::Text id);
  84. void addStatusBarObserver(Entity* zSource, Framework::Text id);
  85. void notifyStatusBarObservers(NetworkMessage* msg);
  86. ItemSkill* zSkill(int itemType);
  87. public:
  88. virtual void prepareTick(const Dimension* zDimension);
  89. virtual void tick(const Dimension* zDimension);
  90. virtual void api(Framework::StreamReader* zRequest,
  91. NetworkMessage* zResponse,
  92. Entity* zSource);
  93. virtual void onTargetChange();
  94. virtual bool interact(Item* zItem, Entity* zActor);
  95. virtual void onFall(float collisionSpeed);
  96. void setChatSecurityLevel(int level);
  97. void setPosition(Framework::Vec3<float> pos);
  98. void setHP(float hp);
  99. void setStamina(float stamina);
  100. void setHunger(float hunger);
  101. void setThirst(float thirst);
  102. void setGravityMultiplier(float multiplier);
  103. void setJumpSpeed(float speed);
  104. float getMaxHP() const;
  105. float getCurrentHP() const;
  106. float getStamina() const;
  107. float getMaxStamina() const;
  108. float getHunger() const;
  109. float getMaxHunger() const;
  110. float getThirst() const;
  111. float getMaxThirst() const;
  112. Framework::Vec3<float> getSpeed() const;
  113. Framework::Vec3<float> getFaceDir() const;
  114. Framework::Vec3<float> getPosition() const;
  115. float getGravityMultiplier() const;
  116. float getJumpSpeed() const;
  117. bool isRemoved() const;
  118. const EntityType* zType() const;
  119. const ActionTarget* zTarget() const;
  120. int getId() const;
  121. virtual bool hasDefaultModel() const;
  122. virtual ModelInfo* zSpecialModel() const;
  123. float getMaxSpeed() const;
  124. bool isMoving() const;
  125. int getChatSecurityLevel() const;
  126. friend Effect;
  127. friend EntityType;
  128. };