Encounter / Assets / Scripts / EntityHandler / Ally.cs
Ally.cs
Raw
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// Will be representative in event and battle encounters
/// </summary>
[RequireComponent(typeof(EntityStats))]
public class Ally : Entity
{
    [HideInInspector] public bool IsMinion;                                 // Indicator if this ally instance is a minion or not

    [Header("Ally/Neutral Components")]
    [SerializeField] private int inventory_Limit;
    [SerializeField] private List<ItemSO> startingItems;
    [SerializeField] private List<ConsumableSO> startingConsumables;
    [SerializeField] private List<RelicSO> startingRelics;
    [SerializeField] private List<WeaponSO> startingWeapons;
    
    [SerializeField] private List<ApparelSO> startingApparel;
    [SerializeField] private List<SpellSO> startingSpells;
    [SerializeField] private List<AbilitySO> startingAbilities;

    [Header("GUI Components")]
    [SerializeField] private Sprite ally_Sprite;

    public WeaponSO.Type attackType = WeaponSO.Type.None;
    public List<Dice.DiceR> damageDice;
    private PartyMemberGUI selfGUI;
    private Inventory inventory;
    private bool initialized;

    public List<Weapon> GetWeapons()
    {
        List<Weapon> output = new();

        // If the list of weapons is blank than simply returns an empty list
        try
        {
            startingWeapons.ForEach(weapon =>
            {
                output.Add(Globals.TurnWeaponFromObject(weapon));
            });
        }
        catch { }

        return output;
    }
    public List<Apparel> GetApparel()
    {
        List<Apparel> output = new();

        // If the list of apparel is blank than simply returns an empty list
        try
        {
            startingApparel.ForEach(apparel =>
            {
                output.Add(Globals.TurnApparelFromObject(apparel));
            });
        }
        catch { }

        return output;
    }
    public List<Spell> GetSpells()
    {
        List<Spell> output = new();

        // If the list of spells is blank than simply returns an empty list
        try
        {
            startingSpells.ForEach(spell =>
            {
                output.Add(Globals.TurnSpellFromObject(spell));
            });
        }
        catch { }

        return output;
    }
    public List<Ability> GetAbilities()
    {
        List<Ability> output = new();

        // If the list of abilities is blank than simply returns an empty list
        try
        {
            startingAbilities.ForEach(ability =>
            {
                output.Add(Globals.TurnAbilityFromObject(ability));
            });
        }
        catch { }

        return output;
    }
    public List<Item> GetItems()
    {
        List<Item> output = new();

        // If the list of items is blank than simply returns an empty list
        try
        {
            startingItems.ForEach(item =>
            {
                output.Add(Globals.TurnItemFromObject(item));
            });
        }
        catch { }

        return output;
    }
    public List<Consumable> GetConsumables()
    {
        List<Consumable> output = new();

        try
        {
            startingConsumables.ForEach(consumable =>
            {
                output.Add(Globals.TurnConsumableFromObject(consumable));
            });
        }
        catch { }

        return output;
    }
    public List<Relic> GetRelics()
    {
        List<Relic> output = new();
        
        try
        {
            startingRelics.ForEach(relic =>
            {
                output.Add(Globals.TurnRelicFromObject(relic));
            });
        }
        catch { }

        return output;
    }
    public override Inventory GetInventory()
    {
        inventory ??= new Inventory(this);
        return inventory;
    }
    /// <summary>
    /// Injects the necessary GUI into the ally object
    /// </summary>
    /// <param name="gui">The GUI object component attached to the object instantiated in scene</param>
    public void InjectGUI(PartyMemberGUI gui)
    {
        this.selfGUI = gui;
        this.selfGUI.UpdateStats(this);
    }
    public PartyMemberGUI GetGUI() 
        => this.selfGUI;
    public override Sprite GetSprite() 
        => this.ally_Sprite;
    public int GetInventoryLimit() 
        => inventory_Limit;
    protected override void OnEnable()
    {
        if (initialized)
            return;

        base.OnEnable();

        initialized = true;
    }
    protected override void UpdateHealthVis()
    {
        base.UpdateHealthVis();

        selfGUI.UpdateStats(this);
        genStatsChanged = false;
    }
    protected override void UpdateStatusFields()
    {
        base.UpdateStatusFields();

        selfGUI.UpdateStats(this);
        selfGUI.RemoveModifiers();
        selfGUI.UpdateModifiers();
    }
    /// <summary>
    /// Injects preset information from a previous ally state of this designated ally type from a PartyMember container
    /// </summary>
    /// <param name="allyState">The previously referenced ally state</param>
    public void InjectAllyInformation(Ally allyState)
    {
        this.Health                 = allyState.RetrieveHealth();
        this.maxHealth              = allyState.RetrieveMaxHealth();
        this.Mana                   = allyState.RetrieveMana();  
        this.maxMana                = allyState.RetrieveMaxMana();
        this.Armor                  = allyState.RetrieveArmor();
        this.stats                  = allyState.GatherStats();
        this.inventory_Limit        = allyState.GetInventoryLimit();
        this.modList                = allyState.GatherModList();

        try
        {
            this.inventory = allyState.GetInventory();

            if (this.inventory == null)
                throw new NullReferenceException();
        }
        catch
        {
            this.inventory ??= new Inventory(this);
        }
    }
}