using System; using System.Collections; using System.Collections.Generic; using UnityEngine; /// <summary> /// Retainer for the Weapon SO when parsing through Weapons /// </summary> public class Weapon : Item { public List<Dice.DiceR> WeaponDamage { get; private set; } public float ModifierChance { get; private set; } public bool WeaponIsRanged { get; private set; } public bool WeaponIsTwoHanded { get; private set; } public SpellSO.Element WeaponElement { get; private set; } public WeaponSO.Type WeaponType { get; private set; } public List<Spell> SpellsToAdd { get; private set; } public List<Ability> AbilitiesToAdd { get; private set; } public List<Modifier> ModifiersToAdd { get; private set; } public void ModifyTwoHanded(bool state) => this.WeaponIsTwoHanded = state; public Weapon(WeaponSO reference) : base(reference) { this.WeaponDamage = new List<Dice.DiceR>(reference.Damage); this.ModifierChance = reference.ModifierChance / 100f; this.WeaponIsRanged = reference.Is_Ranged; this.WeaponIsTwoHanded = reference.Two_Handed; this.WeaponElement = reference.Weapon_Element; this.WeaponType = reference.Weapon_Type; if (reference.AddSpells) { this.SpellsToAdd = new List<Spell>(); for (int i = 0; i < reference.SpellsToAdd.Count; i++) this.SpellsToAdd.Add(Globals.TurnSpellFromObject(reference.SpellsToAdd[i])); } if (reference.AddAbilities) { this.AbilitiesToAdd = new List<Ability>(); for (int i = 0; i < reference.AbilitiesToAdd.Count; i++) this.AbilitiesToAdd.Add(Globals.TurnAbilityFromObject(reference.AbilitiesToAdd[i])); } if (reference.AddModifiers) { this.ModifiersToAdd = new List<Modifier>(); for (int i = 0; i < reference.ModifiersToAdd.Count; i++) this.ModifiersToAdd.Add(Globals.TurnModifierFromObject(reference.ModifiersToAdd[i])); } } #region Overriden Operators public static bool operator ==(Weapon left, Weapon right) { 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 !=(Weapon left, Weapon right) => !(left == right); public override bool Equals(object obj) { return this == obj as Weapon; } public override int GetHashCode() { if (this.ItemName is null) return 0; return ItemName.GetHashCode(); } #endregion }