Entity.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 "NetworkResponse.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 save( ActionTarget* zTarget, Framework::StreamWriter* zWriter );
  26. static ActionTarget* load( Framework::StreamReader* zReader );
  27. };
  28. class Entity : public Inventory
  29. {
  30. protected:
  31. float maxHP;
  32. float currentHP;
  33. float stamina;
  34. float maxStamina;
  35. float hunger;
  36. float maxHunger;
  37. float thirst;
  38. float maxThirst;
  39. float targetDistanceLimit;
  40. Framework::Vec3<float> speed;
  41. Framework::Vec3<float> faceDir;
  42. Framework::Vec3<float> faceOffset;
  43. Framework::RCArray<ItemSkill> skills;
  44. ActionTarget* target;
  45. const EntityType* zEntityType;
  46. int currentDimensionId;
  47. bool removed;
  48. float gravityMultiplier;
  49. bool needUpdate;
  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. public:
  55. void prepareTick( const Dimension* zDimension );
  56. virtual void tick( const Dimension* zDimension );
  57. virtual void api( Framework::StreamReader* zRequest, NetworkResponse* zResponse );
  58. virtual void onFall( float collisionSpeed );
  59. void setPosition( Framework::Vec3<float> pos );
  60. float getMaxHP() const;
  61. float getCurrentHP() const;
  62. float getStamina() const;
  63. float getMaxStamina() const;
  64. float getHunger() const;
  65. float getMaxHunger() const;
  66. float getThirst() const;
  67. float getMaxThirst() const;
  68. Framework::Vec3<float> getSpeed() const;
  69. Framework::Vec3<float> getFaceDir() const;
  70. Framework::Vec3<float> getPosition() const;
  71. float getGravityMultiplier() const;
  72. int getCurrentDimensionId() const;
  73. bool isRemoved() const;
  74. const EntityType* zType() const;
  75. const ActionTarget* zTarget() const;
  76. int getId() const;
  77. friend Effect;
  78. friend EntityType;
  79. };