118 lines
3.6 KiB
C#
118 lines
3.6 KiB
C#
using Photon.Pun;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
//[CreateAssetMenu(fileName = "BaseAbility", menuName = "RiftMayhem/AbilitySystem/Abilities/Base Ability", order = 1)]
|
|
public class BaseAbility : ScriptableObject
|
|
{
|
|
public string displayName;
|
|
public Sprite Icon;
|
|
public List<TargetTag> targettingTags = new List<TargetTag>();
|
|
public List<GameTag> tags = new List<GameTag>();
|
|
public List<BaseEffect> abilityEffects = new List<BaseEffect>();
|
|
[Space]
|
|
public float castTime;
|
|
public float manaCost;
|
|
public float healthCost = 0;
|
|
public float classResourceCost = 0;
|
|
public float percentMaxManaCost = 0;
|
|
public float percentMaxHealthCost = 0;
|
|
public float cooldown;
|
|
public bool castableWhileMoving;
|
|
public AbilityAnimationType animationType;
|
|
|
|
Mana userMana;
|
|
protected Health userHealth;
|
|
|
|
private float maxManaCostInValue;
|
|
private float maxHealthCostInValue;
|
|
private float finalManaCost;
|
|
private float finalHealthCost;
|
|
|
|
public virtual void Execute(PhotonView user, Taggable userTag)
|
|
{
|
|
SpendResourcesNecessary(user, userTag);
|
|
|
|
//for (int i = 0; i < abilityEffects.Count; i++)
|
|
//{
|
|
// Debug.Log($"Ability {this.name} applied {abilityEffects[i].name} effect at xtarget");
|
|
//}
|
|
}
|
|
public virtual void Execute(PhotonView user, Taggable userTag, Vector3 point)
|
|
{
|
|
SpendResourcesNecessary(user, userTag);
|
|
}
|
|
|
|
public virtual void Execute(PhotonView user, Taggable userTag, Transform target)
|
|
{
|
|
SpendResourcesNecessary(user, userTag);
|
|
}
|
|
|
|
public virtual void SpendResourcesNecessary(PhotonView user, Taggable userTag)
|
|
{
|
|
userMana = user.GetComponent<Mana>();
|
|
maxManaCostInValue = userMana.GetMaxValue() * percentMaxManaCost;
|
|
finalManaCost = manaCost + maxManaCostInValue;
|
|
|
|
userHealth = user.GetComponent<Health>();
|
|
maxHealthCostInValue = userHealth.GetMaxValue() * percentMaxHealthCost;
|
|
finalHealthCost = healthCost + maxHealthCostInValue;
|
|
|
|
userMana.ChangeValue(-finalManaCost);
|
|
userHealth.ChangeValue(-finalHealthCost);
|
|
user.GetComponent<ClassResource>()?.ChangeValue(-classResourceCost);
|
|
|
|
}
|
|
|
|
public virtual float GetFinalManaCost(Mana userMana)
|
|
{
|
|
maxManaCostInValue = userMana.GetMaxValue() * percentMaxManaCost;
|
|
finalManaCost = manaCost + maxManaCostInValue;
|
|
return finalManaCost;
|
|
}
|
|
public virtual float GetFinalHealthCost(Health userHealth)
|
|
{
|
|
maxHealthCostInValue = userHealth.GetMaxValue() * percentMaxHealthCost;
|
|
finalHealthCost = healthCost + maxHealthCostInValue;
|
|
return finalHealthCost;
|
|
}
|
|
|
|
private void OnValidate()
|
|
{
|
|
InitializeUniqueTags();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
InitializeUniqueTags();
|
|
}
|
|
|
|
public void InitializeUniqueTags()
|
|
{
|
|
tags.Clear();
|
|
|
|
// Iterate through each effect and add unique GameTags to uniqueTags list
|
|
foreach (var effect in abilityEffects)
|
|
{
|
|
if (effect != null)
|
|
{
|
|
foreach (var tag in effect.tags)
|
|
{
|
|
if (!tags.Contains(tag))
|
|
{
|
|
tags.Add(tag);
|
|
}
|
|
}
|
|
foreach (var influencingStat in effect.influencingStats)
|
|
{
|
|
if(!tags.Contains(influencingStat.statTag))
|
|
{
|
|
tags.Add(influencingStat.statTag);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|