using System.Collections; using System.Collections.Generic; using UnityEngine; /// <summary> /// Retainer class for the information within the Apparel Scriptable Object /// </summary> public class Apparel : Item { public List<ApparelSO.ApparelEffect> ApparelEffects { get; private set; } public ApparelSO.Type ApparelType { get; private set; } public ApparelSO.Location ApparelLocation { get; private set; } public readonly int? DefenseModifier; public readonly int? DamageModifier; public readonly int? ToHitModifier; public readonly List<SpellSO.Element> ElementResistances; public readonly List<WeaponSO.Type> TypeResistances; public readonly int? HealthRegenPercentage; public readonly int? ManaRegenPercentage; public readonly List<Spell> AvailableSpells; public readonly List<Ability> AvailableAbilities; public readonly List<ClimateManager.Weather> RequiredWeather; public readonly List<Vector2Int> StatModifiers; public readonly int? ExtraMana; public readonly int? ExtraHealth; public readonly int? FlagValue; public readonly List<Spell> SpellsToAdd; public readonly List<Ability> AbilitiesToAdd; public Apparel(ApparelSO reference) : base(reference) { this.ApparelType = reference.ApparelType; this.ApparelLocation = reference.ApparelLocation; this.ApparelEffects = new List<ApparelSO.ApparelEffect>(reference.ApparelEffects); foreach (ApparelSO.ApparelEffect effect in this.ApparelEffects) { switch (effect) { case ApparelSO.ApparelEffect.Defense: this.DefenseModifier = reference.Defense; break; case ApparelSO.ApparelEffect.Resistances: this.ElementResistances = new List<SpellSO.Element>(reference.ApparelElementResistances); this.TypeResistances = new List<WeaponSO.Type>(reference.ApparelTypeResistances); break; case ApparelSO.ApparelEffect.HealthRegen: this.HealthRegenPercentage = reference.HealthRegeneration; break; case ApparelSO.ApparelEffect.ManaRegen: this.ManaRegenPercentage = reference.ManaRegeneration; break; case ApparelSO.ApparelEffect.DamageModifier: this.DamageModifier = reference.Damage; break; case ApparelSO.ApparelEffect.ToHitModifier: this.ToHitModifier = reference.ToHit; break; case ApparelSO.ApparelEffect.GiveSpell: this.AvailableSpells = new List<Spell>(); foreach (SpellSO spell in reference.Spells) this.AvailableSpells.Add(Globals.TurnSpellFromObject(spell)); break; case ApparelSO.ApparelEffect.GiveAbility: this.AvailableAbilities = new List<Ability>(); foreach (AbilitySO ability in reference.Abilities) this.AvailableAbilities.Add(Globals.TurnAbilityFromObject(ability)); break; case ApparelSO.ApparelEffect.Stats: this.StatModifiers = new List<Vector2Int>(reference.StatMods); break; case ApparelSO.ApparelEffect.MoreMana: this.ExtraMana = reference.ExtraMana; break; case ApparelSO.ApparelEffect.MoreHealth: this.ExtraHealth = reference.ExtraHealth; break; case ApparelSO.ApparelEffect.Other: this.FlagValue = reference.FlagValue; break; } } if (reference.RequiresWeatherType) { this.RequiredWeather = new List<ClimateManager.Weather>(); this.RequiredWeather = reference.RequiredWeather; } if (reference.AddSpells) { this.SpellsToAdd = new List<Spell>(); foreach (SpellSO spellObject in reference.SpellsToAdd) this.SpellsToAdd.Add(Globals.TurnSpellFromObject(spellObject)); } if (reference.AddAbilities) { this.AbilitiesToAdd = new List<Ability>(); foreach (AbilitySO abilityObject in reference.AbilitiesToAdd) this.AbilitiesToAdd.Add(Globals.TurnAbilityFromObject(abilityObject)); } } #region Overriden Operators public static bool operator ==(Apparel left, Apparel right) { // When either is null then simply return false bool leftNullCheck = false; bool rightNullCheck = false; try { string check = left.ItemName; } catch { leftNullCheck = true; } try { string check = right.ItemName; } catch { rightNullCheck = true; } if (leftNullCheck && rightNullCheck) return true; else if ((!rightNullCheck && leftNullCheck) || (rightNullCheck && !leftNullCheck)) return false; return left.ItemId == right.ItemId && left.ItemName == right.ItemName; } public static bool operator !=(Apparel left, Apparel right) => !(left == right); public override bool Equals(object obj) { return this == obj as Apparel; } public override int GetHashCode() { if (this.ItemName is null) return 0; return ItemName.GetHashCode(); } #endregion }