2025-02-21 18:35:51 +00:00

127 lines
6.1 KiB
C#

using Kryz.CharacterStats;
using Kryz.CharacterStats.Examples;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "SummonAbility", menuName = "RiftMayhem/AbilitySystem/Abilities/Summon Ability", order = 0)]
public class SummonAbility : BaseAbility
{
public GameObject minionPrefab;
public int numberOfSpawns = 1;
public bool instantlyReady = false;
public bool isImage = false;
[Space]
public float StrengthPercentFromMaster;
public float AgilityPercentFromMaster;
public float IntelligencePercentFromMaster;
public float SpiritPercentFromMaster;
public float VitalityPercentFromMaster;
[Space]
public float AttackDamagePercentFromMaster;
public float SpellDamagePercentFromMaster;
public float CritChancePercentFromMaster;
public float CritDamagePercentFromMaster;
public float MaxHealthPercentFromMaster;
public float ArmorPercentFromMaster;
public float MagicResistancePercentFromMaster;
private GameObject instantiatedMinion;
private CharacterStats ownerStats;
private CharacterStats minionStats;
private MinionSpiritPowerReleaseController minionSpiritPowerReleaseController;
public override void Execute(Taggable user)
{
base.Execute(user);
//Debug.Log($"Player {user.name} casted {this.name} and spent {manaCost} mana.");
for (int i = 0; i < numberOfSpawns; i++)
{
instantiatedMinion = Instantiate(minionPrefab, user.GetComponentInChildren<ProjectileSpawnLocationController>().transform.position + Vector3.one * i, user.GetComponentInChildren<ProjectileSpawnLocationController>().transform.rotation);
InitializeStatsBasedOnOwner(user);
SetupMinionSpiritPowerReleaseController(user);
}
}
public override void Execute(Taggable user, Vector3 point)
{
base.Execute(user);
//Debug.Log($"Player {user.name} casted {this.name} and spent {manaCost} mana.");
for (int i = 0; i < numberOfSpawns; i++)
{
instantiatedMinion = Instantiate(minionPrefab, user.GetComponentInChildren<ProjectileSpawnLocationController>().transform.position + Vector3.one * i, user.GetComponentInChildren<ProjectileSpawnLocationController>().transform.rotation);
InitializeStatsBasedOnOwner(user);
SetupMinionSpiritPowerReleaseController(user);
}
}
public override void Execute(Taggable user, Transform target)
{
base.Execute(user);
//Debug.Log($"Player {user.name} casted {this.name} and spent {manaCost} mana.");
for (int i = 0; i < numberOfSpawns; i++)
{
instantiatedMinion = Instantiate(minionPrefab, user.GetComponentInChildren<ProjectileSpawnLocationController>().transform.position + Vector3.one * i, user.GetComponentInChildren<ProjectileSpawnLocationController>().transform.rotation);
InitializeStatsBasedOnOwner(user);
SetupMinionSpiritPowerReleaseController(user);
}
}
public void AutoSummonOnSceneLoad(Taggable user)
{
instantiatedMinion = Instantiate(minionPrefab, user.GetComponentInChildren<ProjectileSpawnLocationController>().transform.position, user.GetComponentInChildren<ProjectileSpawnLocationController>().transform.rotation);
InitializeStatsBasedOnOwner(user);
SetupMinionSpiritPowerReleaseController(user);
}
private void SetupMinionSpiritPowerReleaseController(Taggable owner)
{
minionSpiritPowerReleaseController = instantiatedMinion.GetComponentInChildren<MinionSpiritPowerReleaseController>();
if (minionSpiritPowerReleaseController == null) return;
minionSpiritPowerReleaseController.OwnerSpiritPower = owner.GetComponent<SpiritPower>();
minionSpiritPowerReleaseController.spiritPowerReserved = spiritPowerReserveCost;
}
private void InitializeStatsBasedOnOwner(Taggable user)
{
ownerStats = user.GetComponent<CharacterStats>();
minionStats = instantiatedMinion.GetComponent<CharacterStats>();
minionStats.Strength.AddModifier(new StatModifier(ownerStats.Strength.Value * StrengthPercentFromMaster, StatModType.Flat, ownerStats));
minionStats.Agility.AddModifier(new StatModifier(ownerStats.Agility.Value * AgilityPercentFromMaster, StatModType.Flat, ownerStats));
minionStats.Intelligence.AddModifier(new StatModifier(ownerStats.Intelligence.Value * IntelligencePercentFromMaster, StatModType.Flat, ownerStats));
minionStats.Spirit.AddModifier(new StatModifier(ownerStats.Spirit.Value * SpiritPercentFromMaster, StatModType.Flat, ownerStats));
minionStats.Vitality.AddModifier(new StatModifier(ownerStats.Vitality.Value * VitalityPercentFromMaster, StatModType.Flat, ownerStats));
minionStats.AttackDamage.AddModifier(new StatModifier(ownerStats.AttackDamage.Value * AttackDamagePercentFromMaster, StatModType.Flat, ownerStats));
minionStats.SpellDamage.AddModifier(new StatModifier(ownerStats.SpellDamage.Value * SpellDamagePercentFromMaster, StatModType.Flat, ownerStats));
minionStats.CritChance.AddModifier(new StatModifier(ownerStats.CritChance.Value * CritChancePercentFromMaster, StatModType.Flat, ownerStats));
minionStats.CritDamage.AddModifier(new StatModifier(ownerStats.CritDamage.Value * CritDamagePercentFromMaster, StatModType.Flat, ownerStats));
minionStats.MaxHealth.AddModifier(new StatModifier(ownerStats.MaxHealth.Value * MaxHealthPercentFromMaster, StatModType.Flat, ownerStats));
minionStats.Armor.AddModifier(new StatModifier(ownerStats.Armor.Value * ArmorPercentFromMaster, StatModType.Flat, ownerStats));
minionStats.MagicResistance.AddModifier(new StatModifier(ownerStats.MagicResistance.Value * MagicResistancePercentFromMaster, StatModType.Flat, ownerStats));
minionStats.onUpdateStatValues.Invoke();
instantiatedMinion.GetComponent<MinionNPCController>().owner = user;
if (instantlyReady)
{
instantiatedMinion.GetComponent<MinionNPCController>().SetMinionReadyWithoutAnimation();
}
}
}