Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Game.Boosters;
- using Game.Breeds;
- using Game.CameraLogic.Animals.Behaviours;
- using Game.Characteristics;
- using Game.Data;
- using Game.Infrastructure.Factory;
- using Game.Infrastructure.GamePreparing;
- using Game.Logic;
- using Game.Logic.Characteristics;
- using Game.StaticData;
- using Game.UI.Elements;
- using Game.UtilityAI;
- using MalbersAnimations;
- using MalbersAnimations.Controller;
- using MalbersAnimations.Controller.AI;
- using UnityEngine;
- using Zenject;
- using Stats = Game.Characteristics.Stats;
- namespace Game.CameraLogic.Animals
- {
- [RequireComponent(typeof(PreviewComponent))]
- [RequireComponent(typeof(CameraPoints))]
- public class Animal : MonoBehaviour
- {
- public PreviewComponent PreviewComponent;
- public CameraPoints CameraPoints;
- private readonly Dictionary<Type, IAnimalService> _services = new();
- public AnimalSaveData Save { get; private set; }
- [SerializeField] private AnimalUI _animalUI;
- [SerializeField] private MalbersInput _input;
- [SerializeField] private MAnimalAIControl _aiControl;
- [SerializeField] private StatsStaticData _statsStaticData;
- [SerializeField] private Animator _animator;
- [SerializeField] private MAnimal _mAnimal;
- [SerializeField] private Renderer _renderer;
- [SerializeField] private Tameable _tameable;
- [SerializeField] private Tamer _tamer;
- [SerializeField] private AnimalTrigger _animalTrigger;
- [SerializeField] private AnimalAI _ai;
- [SerializeField] private FollowPoint[] _followPoints;
- private void OnValidate()
- {
- CameraPoints ??= GetComponent<CameraPoints>();
- PreviewComponent ??= GetComponentInChildren<PreviewComponent>();
- _aiControl ??= GetComponentInChildren<MAnimalAIControl>(true);
- _input ??= GetComponent<MalbersInput>();
- _animalUI ??= GetComponentInChildren<AnimalUI>();
- _animator ??= GetComponent<Animator>();
- _followPoints = GetComponentsInChildren<FollowPoint>();
- _mAnimal ??= GetComponent<MAnimal>();
- _animalTrigger ??= GetComponentInChildren<AnimalTrigger>();
- _tameable ??= GetComponent<Tameable>();
- _tamer ??= GetComponent<Tamer>();
- }
- private readonly List<ITickable> _tickables = new();
- public void Inject(Stats stats, SpecieAnimal specie, AnimalSaveData save)
- {
- Specie = specie;
- Save = save;
- Breed = specie.Breed(save);
- AIAnimalService aiAnimalService = AIAnimalService();
- FollowPointsService followPointsService = FollowPointsService();
- StatModificatorContainer statModificatorContainer = StatModificatorContainer(stats);
- AnimalCustomization animalCustomization = AnimalCustomization(specie);
- animalCustomization.ReadFromSave();
- var level = new Level(save.Level);
- var experience = new Experience(level, Specie, save.Experience);
- _tamer.Inject(followPointsService);
- _services.Add(typeof(IStats), stats);
- _services.Add(typeof(IAnimalUI), _animalUI);
- _services.Add(typeof(ITameable), _tameable);
- _services.Add(typeof(IFollowPointsService), followPointsService);
- _services.Add(typeof(IAIAnimalService), aiAnimalService);
- _services.Add(typeof(IAnimalInputService), new AnimalInputService(_input));
- _services.Add(typeof(IStatModificatorContainer), statModificatorContainer);
- _services.Add(typeof(IAnimalBehaviourSwitcher), AnimalBehaviourSwitcher(aiAnimalService));
- _services.Add(typeof(IAnimalCustomization), animalCustomization);
- _services.Add(typeof(IStatsRequirementSystem), StatsRequirementSystem(stats));
- _services.Add(typeof(IAnimalCameraService), new AnimalCameraService(MAnimal));
- _services.Add(typeof(IAnimalTameService), new AnimalTameService(_animalTrigger, Specie, _tamer));
- _services.Add(typeof(ILevel), level);
- _services.Add(typeof(IExperience), experience);
- _tickables.Add(statModificatorContainer);
- }
- private AIAnimalService AIAnimalService() => new(AIControl);
- public DamageProvider DamageProvider { get; } = new(10);
- [field: SerializeField]
- public SpecieAnimal Specie { get; private set; }
- public AnimalGender Gender => Save.Gender;
- public Age Age => Save.Age;
- public BreedData Breed { get; private set; }
- public Renderer Renderer => _renderer;
- public MAnimalAIControl AIControl => _aiControl;
- public MAnimal MAnimal => _mAnimal;
- private void Update()
- {
- for (int i = _tickables.Count - 1; i >= 0; i--)
- _tickables[i].Tick();
- }
- public TAnimalService GetService<TAnimalService>() where TAnimalService : IAnimalService =>
- (TAnimalService)_services[typeof(TAnimalService)];
- private AnimalCustomization AnimalCustomization(SpecieAnimal specieAnimal)
- {
- CustomizationData customizationData = specieAnimal.Customization;
- List<string> mouthProperties = customizationData.MouthProperties;
- var animationController = new AnimationCustomizationController(_animator, MAnimal, mouthProperties);
- return new AnimalCustomization(Renderer, animationController, Save);
- }
- private static StatModificatorContainer StatModificatorContainer(Stats stats) =>
- new(stats);
- private StatsRequirementSystem StatsRequirementSystem(IStats stats) =>
- new(_statsStaticData, stats, new MostRequirementStatChanged());
- private FollowPointsService FollowPointsService() =>
- new(_followPoints.Select(point => point.transform));
- private AnimalBehaviourSwitcher AnimalBehaviourSwitcher(IAIAnimalService aiService)
- {
- var switcher = new AnimalBehaviourSwitcher();
- switcher.Add<IPlayerAnimalBehaviour>(new PlayerAnimalBehaviour(_input));
- switcher.Add<IFamilyMemberAnimalBehaviour>(new FamilyMemberAnimalBehaviour(aiService));
- return switcher;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement