Encounter / Assets / Scripts / InventoryManagement / Consumable.cs
Consumable.cs
Raw
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Consumable : Item
{
    public List<ConsumableSO.Effect> Effects { get; private set; }
    public List<Dice.DiceR> HealChance { get; private set; }
    public List<Dice.DiceR> RefillChance { get; private set; }
    public List<Dice.DiceR> DamageChance { get; private set; }
    public Dice.DiceR EffectLength { get; private set; }
    public int BaseValue { get; private set; }
    public bool EffectAllType { get; private set; }
    public bool EffectAll { get; private set; }

    private readonly ModifierSO modifier;

    public Consumable(ConsumableSO reference) : base(reference)
    {
        try
        {
            this.Effects                = new List<ConsumableSO.Effect>(reference.Effects);
            if (reference.HealChance != null)
                this.HealChance         = new List<Dice.DiceR>(reference.HealChance);
            if (reference.RefillChance != null)
                this.RefillChance = new List<Dice.DiceR>(reference.RefillChance);
            if (reference.DamageChance != null)
                this.DamageChance       = new List<Dice.DiceR>(reference.DamageChance);
            this.EffectLength           = reference.EffectLength;
            this.BaseValue              = reference.BaseValue;
            this.EffectAllType          = reference.EffectAllOfType;
            this.EffectAll              = reference.EffectAll;
            this.modifier               = reference.Mod;
        }
        catch
        {
            this.Effects                = new List<ConsumableSO.Effect>();
            this.HealChance             = new List<Dice.DiceR>();
            this.RefillChance           = new List<Dice.DiceR>();
            this.DamageChance           = new List<Dice.DiceR>();
            this.EffectLength           = Dice.DiceR.Hundred;
            this.BaseValue              = 0;
            this.EffectAllType          = false;
            this.EffectAll              = false;
            this.modifier               = null;
        }
    }

    #region Overriden Operators
    public static bool operator ==(Consumable left, Consumable right)
        => left.ItemId == right.ItemId && left.ItemName == right.ItemName;
    public static bool operator !=(Consumable left, Consumable right) 
        => !(left == right);
    public override bool Equals(object obj)
    {
        bool output = false;

        try
        {
            Consumable con = obj as Consumable;

            if (this.ItemId == con.ItemId &&
                this.ItemName == con.ItemName)
            {
                output = true;
            }
        }
        catch
        {

        }

        return output;
    }
    public override int GetHashCode()
    {
        if (this.ItemName is null)
            return 0;

        return ItemName.GetHashCode();
    }
    #endregion
    /// <summary>
    /// Acquisition method for getting the modifier attached to the consumable
    /// </summary>
    /// <returns>The modifier that the consumable puts onto entities</returns>
    public ModifierSO AcquireModifier() 
        => modifier;
}