using System; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; /// <summary> /// Retainer class for the information within the Ability Scriptable Object /// </summary> public class Ability { public int AbilityID { get; private set; } public string AbilityName { get; private set; } public Sprite AbilitySprite { get; private set; } public string AbilityDescription { get; private set; } public List<string> HelperEffects { get; private set; } public Modifier Mod { get; private set; } public Vector2Int SavingThrow { get; private set; } public bool HasRequirements { get; private set; } public List<AbilitySO.PossReqs> Requirements { get; private set; } /// <summary> /// This indicator is meant for the requirements listed to NOT be present on the entity if true /// </summary> public bool HasRequirementsInverted { get; private set; } public readonly int numberOfStatReqs; public readonly List<Vector3Int> statReqs; public readonly int numberOfSecStatReqs; public readonly List<Vector3Int> secStatReqs; public readonly bool requiresSpecificItem; public readonly int numberOfItems; public readonly List<string> reqItems; public readonly bool requiresWeaponType; public readonly WeaponSO.Type weaponType; public readonly bool requiresApparelType; public readonly ApparelSO.Type apparelType; public readonly int numberOfAbilities; public readonly List<string> reqAbilities; public int uniqueCounter; // Reference for abilities that have cooldowns/counters to consider public Entity priorTarget; // Reference for prior targetting for certain abilities public bool active; public bool HasNotModifiedEntity; // Reference to if the ability is a single check sort of ability that supplies spells or stat increase once public object ReferenceObject; // Reference for any kind of object that needs to be stored public Ability(AbilitySO reference) { try { if (string.IsNullOrEmpty(reference.Name) || string.IsNullOrEmpty(reference.Description) || reference.AbilitySprite == null || reference.ID < 0) throw new ArgumentNullException("An ability value shows an impossible value. Creating Error Ability."); this.AbilityID = reference.ID; this.AbilityName = reference.Name; this.AbilitySprite = reference.AbilitySprite; this.AbilityDescription = reference.Description; this.HelperEffects = new List<string>(reference.HelperEffects); this.Mod = reference.Modifier != null ? Globals.TurnModifierFromObject(reference.Modifier) : null; this.SavingThrow = reference.SavingThrow; this.uniqueCounter = 0; this.priorTarget = null; this.active = true; this.HasNotModifiedEntity = reference.ModificationAbility; this.HasRequirements = reference.Has_Requirement; if (this.HasRequirements) { this.HasRequirementsInverted = reference.RequirementsEntityCantHave; this.Requirements = new List<AbilitySO.PossReqs>(reference.Requirements); if (this.Requirements.Contains(AbilitySO.PossReqs.Stats)) { this.numberOfStatReqs = reference.Number_Of_Stat_Reqs; this.statReqs = new List<Vector3Int>(reference.Stats_List); } if (this.Requirements.Contains(AbilitySO.PossReqs.Sec_Stats)) { this.numberOfSecStatReqs = reference.Number_Of_Sec_Stat_Reqs; this.secStatReqs = new List<Vector3Int>(reference.Sec_Stats_List); } if (this.Requirements.Contains(AbilitySO.PossReqs.Item)) { this.numberOfItems = reference.Number_Of_Items; this.reqItems = new List<string>(reference.Item_List); this.requiresWeaponType = reference.Requires_WType; this.weaponType = reference.W_Type; this.requiresApparelType = reference.Requires_AType; this.apparelType = reference.A_Type; } if (this.Requirements.Contains(AbilitySO.PossReqs.Ability)) { this.numberOfAbilities = reference.Number_Of_Abs; this.reqAbilities = new List<string>(reference.Ability_List); } } } catch { this.AbilityID = -1; this.AbilityName = "I am Error"; this.AbilitySprite = Resources.Load<Sprite>("Sprites/Error"); this.AbilityDescription = "???"; this.HelperEffects = new List<string>() { "Error", "Error", "Error" }; this.Mod = null; this.SavingThrow = Vector2Int.zero; this.uniqueCounter = 0; this.priorTarget = null; this.active = false; this.HasNotModifiedEntity = false; this.HasRequirements = false; } } // Copy Constructor public Ability(Ability reference) { this.AbilityID = reference.AbilityID; this.AbilityName = reference.AbilityName; this.AbilitySprite = reference.AbilitySprite; this.AbilityDescription = reference.AbilityDescription; this.HelperEffects = new List<string>(reference.HelperEffects); this.Mod = reference.Mod; this.SavingThrow = reference.SavingThrow; this.uniqueCounter = 0; this.priorTarget = null; this.active = true; this.HasNotModifiedEntity = reference.HasNotModifiedEntity; this.HasRequirements = reference.HasRequirements; if (this.HasRequirements) { this.HasRequirementsInverted = reference.HasRequirementsInverted; this.Requirements = new List<AbilitySO.PossReqs>(reference.Requirements); if (this.Requirements.Contains(AbilitySO.PossReqs.Stats)) { this.numberOfStatReqs = reference.numberOfStatReqs; this.statReqs = new List<Vector3Int>(reference.statReqs); } if (this.Requirements.Contains(AbilitySO.PossReqs.Sec_Stats)) { this.numberOfSecStatReqs = reference.numberOfSecStatReqs; this.secStatReqs = new List<Vector3Int>(reference.secStatReqs); } if (this.Requirements.Contains(AbilitySO.PossReqs.Item)) { this.numberOfItems = reference.numberOfItems; this.reqItems = new List<string>(reference.reqItems); this.requiresWeaponType = reference.requiresWeaponType; this.weaponType = reference.weaponType; this.requiresApparelType = reference.requiresApparelType; this.apparelType = reference.apparelType; } if (this.Requirements.Contains(AbilitySO.PossReqs.Ability)) { this.numberOfAbilities = reference.numberOfAbilities; this.reqAbilities = new List<string>(reference.reqAbilities); } } } public override bool Equals(object obj) { return obj is Ability ability && AbilityID == ability.AbilityID && AbilityName == ability.AbilityName; } public override int GetHashCode() { return HashCode.Combine(AbilityID, AbilityName); } public static bool operator ==(Ability left, Ability right) { return EqualityComparer<Ability>.Default.Equals(left, right); } public static bool operator !=(Ability left, Ability right) { return !(left == right); } #region Overloaded Operators #endregion }