Animal.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #pragma once
  2. #include "AnimalAI.h"
  3. #include "BasicBlocks.h"
  4. #include "Entity.h"
  5. #include "EntityType.h"
  6. class Animal : public Entity
  7. {
  8. private:
  9. Framework::Array<SpawnConfig> spawns;
  10. AnimalAI* ai;
  11. protected:
  12. void onDeath() override;
  13. public:
  14. Animal(int typeId,
  15. Framework::Vec3<float> location,
  16. int dimensionId,
  17. int entityId);
  18. ~Animal();
  19. void setSpawns(const Framework::Array<SpawnConfig>& spawnConfig);
  20. void setAI(AnimalAI* ai);
  21. bool interact(Item* zItem, Entity* zActor) override;
  22. void takeDamage(Entity* zSource, float damage) override;
  23. void tick(const Dimension* zDimension) override;
  24. };
  25. class AnimalEntityTypeFactory;
  26. class AnimalEntityType : public EntityType
  27. {
  28. private:
  29. Framework::JSON::JSONObject* ai;
  30. Framework::Array<SpawnConfig> spawns;
  31. protected:
  32. virtual void loadSuperEntity(
  33. Entity* zEntity, Framework::StreamReader* zReader) const;
  34. virtual void saveSuperEntity(
  35. Entity* zEntity, Framework::StreamWriter* zWriter) const;
  36. public:
  37. AnimalEntityType(Framework::Text name, ModelInfo* model);
  38. ~AnimalEntityType();
  39. Entity* createEntity(Framework::Vec3<float> position,
  40. int dimensionId,
  41. int entityId) const override;
  42. friend AnimalEntityTypeFactory;
  43. };
  44. class AnimalEntityTypeFactory
  45. : public SubTypeFactory<EntityType, AnimalEntityType>
  46. {
  47. public:
  48. AnimalEntityTypeFactory();
  49. AnimalEntityType* createValue(
  50. Framework::JSON::JSONObject* zJson) const override;
  51. void fromJson(AnimalEntityType* zResult,
  52. Framework::JSON::JSONObject* zJson) const override;
  53. void toJson(AnimalEntityType* zObject,
  54. Framework::JSON::JSONObject* zResult) const override;
  55. Framework::Text getTypeToken() const override;
  56. JSONObjectValidationBuilder* addToValidator(
  57. JSONObjectValidationBuilder* builder) const override;
  58. };