GoodNoodle

Party.cs

Jul 18th, 2023
1,185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.Linq;
  5. using System;
  6.  
  7. public class Party : MonoBehaviour
  8. {
  9.     [SerializeField] public List<Creature> creatures;
  10.  
  11.     public event Action OnUpdated;
  12.  
  13.     public List<Creature> Creatures
  14.     {
  15.         get { return creatures;
  16.         }
  17.         set {
  18.             creatures = value;
  19.             OnUpdated?.Invoke();
  20.         }
  21.        
  22.     }
  23.  
  24.     private void Awake()
  25.     {
  26.         foreach (var creature in creatures)
  27.         {
  28.             creature.Init();
  29.         }
  30.     }
  31.  
  32.     private void Start()
  33.     {
  34.        
  35.     }
  36.  
  37.     public Creature GetUninjuredCreature()
  38.     {
  39.       return creatures.Where(x => x.HP > 0).FirstOrDefault();
  40.     }
  41.  
  42.     public void AddCreature(Creature newCteature)
  43.     {
  44.         if(creatures.Count < 6)
  45.         {
  46.             creatures.Add(newCteature);
  47.             OnUpdated?.Invoke();
  48.         }
  49.         else
  50.         {
  51.             /// transfer to storage box
  52.         }
  53.     }
  54.  
  55.     public IEnumerator CheckForEvolutions()
  56.     {
  57.         foreach (var creature in creatures)
  58.         {
  59.           var evolution =  creature.CheckForEvolution();
  60.             if(evolution != null)
  61.             {
  62.                 yield return GameController.Instance.EvoMan.Evolove(creature, evolution);
  63.             }
  64.         }
  65.     }
  66.  
  67.     public void PartyUpdated()
  68.     {
  69.         OnUpdated?.Invoke();
  70.     }
  71.  
  72.     public static Party GetPlayerParty()
  73.     {
  74.        return FindObjectOfType<PlayerController>().GetComponent<Party>();
  75.     }
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment