Entity.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #pragma once
  2. #include <ReferenceCounter.h>
  3. #include <Vec3.h>
  4. #include <Vec2.h>
  5. #include <Writer.h>
  6. #include "Effect.h"
  7. #include "Inventory.h"
  8. #include "NetworkMessage.h"
  9. #include "ItemSkill.h"
  10. class EntityType;
  11. class Dimension;
  12. class ActionTarget
  13. {
  14. private:
  15. Framework::Vec3<int> blockPos;
  16. Direction targetBlockSide;
  17. int entityId;
  18. public:
  19. ActionTarget(Framework::Vec3<int> blockPos, Direction blockSide);
  20. ActionTarget(int entityId);
  21. bool isBlock(Framework::Vec3<int> blockPos, Direction blockSide) const;
  22. bool isEntity(int entityId) const;
  23. void applyItemSkillOnTarget(Entity* zActor, ItemSkill* zItemSkill, Item* zUsedItem);
  24. void placeBlock(Entity* zActor, Item* zItem);
  25. static void toMessage(const ActionTarget* zTarget, NetworkMessage& msg);
  26. static void save(ActionTarget* zTarget, Framework::StreamWriter* zWriter);
  27. static ActionTarget* load(Framework::StreamReader* zReader);
  28. };
  29. class Entity : public Inventory
  30. {
  31. protected:
  32. float maxHP;
  33. float currentHP;
  34. float stamina;
  35. float maxStamina;
  36. float hunger;
  37. float maxHunger;
  38. float thirst;
  39. float maxThirst;
  40. float targetDistanceLimit;
  41. Framework::Vec3<float> speed;
  42. Framework::Vec3<float> faceDir;
  43. Framework::Vec3<float> faceOffset;
  44. Framework::RCArray<ItemSkill> skills;
  45. ActionTarget* target;
  46. const EntityType* zEntityType;
  47. int currentDimensionId;
  48. bool removed;
  49. float gravityMultiplier;
  50. int id;
  51. virtual void onDeath();
  52. virtual void useItem(const ItemType* zType, Item* zItem);
  53. Entity(const EntityType* zType, Framework::Vec3<float> location, int dimensionId, int entityId);
  54. virtual void onTargetChange();
  55. public:
  56. void prepareTick(const Dimension* zDimension);
  57. virtual void tick(const Dimension* zDimension);
  58. virtual void api(Framework::StreamReader* zRequest, NetworkMessage* zResponse);
  59. virtual void onFall(float collisionSpeed);
  60. void setPosition(Framework::Vec3<float> pos);
  61. float getMaxHP() const;
  62. float getCurrentHP() const;
  63. float getStamina() const;
  64. float getMaxStamina() const;
  65. float getHunger() const;
  66. float getMaxHunger() const;
  67. float getThirst() const;
  68. float getMaxThirst() const;
  69. Framework::Vec3<float> getSpeed() const;
  70. Framework::Vec3<float> getFaceDir() const;
  71. Framework::Vec3<float> getPosition() const;
  72. float getGravityMultiplier() const;
  73. int getCurrentDimensionId() const;
  74. bool isRemoved() const;
  75. const EntityType* zType() const;
  76. const ActionTarget* zTarget() const;
  77. int getId() const;
  78. virtual bool hasDefaultModel() const;
  79. virtual ModelInfo getSpecialModel() const;
  80. friend Effect;
  81. friend EntityType;
  82. };