Entity.h 4.4 KB

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