using System; using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; public class Skill { private SkillSO retainedSkillData; private Entity attachedEntity; private bool hasBeenActivated; public Skill(SkillSO skillDataRef, Entity attachedEntity) { this.retainedSkillData = skillDataRef; this.attachedEntity = attachedEntity; ActivateSkill(); } public string GetName() => retainedSkillData.SkillName; public bool HasSkillBeenActivated() => hasBeenActivated; public void ActivateSkill() { bool isChoice = retainedSkillData.IsChoice; switch (retainedSkillData.Type) { case SkillSO.SkillType.Ability: if (!isChoice) { foreach (AbilitySO ability in retainedSkillData.ability) attachedEntity.GetInventory().Add(Globals.TurnAbilityFromObject(ability)); } else { List<Ability> abilities = new List<Ability>(); foreach (AbilitySO abilityObj in retainedSkillData.ability) abilities.Add(Globals.TurnAbilityFromObject(abilityObj)); SkillTreeManager.Instance.SignalChoice(retainedSkillData, abilities); } break; case SkillSO.SkillType.Spell: if (!isChoice) { foreach (SpellSO spell in retainedSkillData.spell) attachedEntity.GetInventory().Add(Globals.TurnSpellFromObject(spell)); } else { List<Spell> spells = new List<Spell>(); foreach (SpellSO spellObj in retainedSkillData.spell) spells.Add(Globals.TurnSpellFromObject(spellObj)); SkillTreeManager.Instance.SignalChoice(retainedSkillData, spells); } break; case SkillSO.SkillType.WeaponResistance: if (!isChoice) { foreach (WeaponSO.Type resist in retainedSkillData.weaponResistances) attachedEntity.GatherStats().AddTypeResistance(resist); } else SkillTreeManager.Instance.SignalChoice(retainedSkillData, retainedSkillData.weaponResistances); break; case SkillSO.SkillType.ElementResistance: if (!isChoice) { foreach (SpellSO.Element resist in retainedSkillData.elementResistances) attachedEntity.GatherStats().AddElementalResistance(resist); } else SkillTreeManager.Instance.SignalChoice(retainedSkillData, retainedSkillData.elementResistances); break; case SkillSO.SkillType.StatModifier: if (!isChoice) { foreach (Vector2Int modifier in retainedSkillData.statMods) ModifierFilter(modifier); } else SkillTreeManager.Instance.SignalChoice(retainedSkillData, retainedSkillData.statMods); break; case SkillSO.SkillType.Other: if (!isChoice) { if (retainedSkillData.SkillName.Equals("Vine Coverings")) { attachedEntity.GatherStats().AddElementalResistance(SpellSO.Element.Fire); int vineArmor = attachedEntity.RetrieveArmor() + 1; attachedEntity.SetArmor(vineArmor); } if (retainedSkillData.SkillName.Equals("Bark Growth")) { int barkArmor = attachedEntity.RetrieveArmor() + 2; attachedEntity.SetArmor(barkArmor); attachedEntity.IncreaseMaxHealth(attachedEntity.RetrieveMaxHealth()); attachedEntity.IncreaseHealth(attachedEntity.RetrieveMaxHealth()); } } else SkillTreeManager.Instance.SignalChoice(retainedSkillData, retainedSkillData.Flags); break; } hasBeenActivated = true; } /// <summary> /// Filters through what modifier is being set from the skill /// </summary> /// <param name="modifier">The modifier with x being the stat ID and y being the modifier value</param> private void ModifierFilter(Vector2Int modifier, bool deactivating = false) { int modification = !deactivating ? modifier.y : -modifier.y; switch (modifier.x) { case 0: // STR attachedEntity.GatherStats().SetModifierToStat(EntityStats.Stat.Strength, modification); break; case 1: // INT attachedEntity.GatherStats().SetModifierToStat(EntityStats.Stat.Intelligence, modification); break; case 2: // CON attachedEntity.GatherStats().SetModifierToStat(EntityStats.Stat.Constitution, modification); break; case 3: // DEX attachedEntity.GatherStats().SetModifierToStat(EntityStats.Stat.Dexterity, modification); break; case 4: // CHA attachedEntity.GatherStats().SetModifierToStat(EntityStats.Stat.Charisma, modification); break; case 5: // WIS attachedEntity.GatherStats().SetModifierToStat(EntityStats.Stat.Wisdom, modification); break; case 6: // LCK attachedEntity.GatherStats().SetModifierToStat(EntityStats.Stat.Luck, modification); break; } } public void DeactivateSkill() { switch (retainedSkillData.Type) { case SkillSO.SkillType.Ability: foreach (AbilitySO ability in retainedSkillData.ability) attachedEntity.GetInventory().Remove(Globals.TurnAbilityFromObject(ability)); break; case SkillSO.SkillType.Spell: foreach (SpellSO spell in retainedSkillData.spell) attachedEntity.GetInventory().Remove(Globals.TurnSpellFromObject(spell)); break; case SkillSO.SkillType.WeaponResistance: foreach (WeaponSO.Type resist in retainedSkillData.weaponResistances) attachedEntity.GatherStats().RemoveTypeResistance(resist); break; case SkillSO.SkillType.ElementResistance: foreach (SpellSO.Element resist in retainedSkillData.elementResistances) attachedEntity.GatherStats().RemoveElementalResistance(resist); break; case SkillSO.SkillType.StatModifier: foreach (Vector2Int modifier in retainedSkillData.statMods) ModifierFilter(modifier, true); break; case SkillSO.SkillType.Other: // TODO ---> Implement? break; } } }