Entity.h 4.3 KB

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