Entity.h 2.4 KB

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