82 lines
2.9 KiB
C#

using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Template_RuntimeInstance
{
public class AbilityInstance
{
public string id;
public BaseAbility template;
public float currentCooldown;
public float currentManaCost;
public float currentHealthCost;
public float currentClassResourceCost;
public List<BaseEffect> currentEffects;
public List<IAbilityModifier> currentModifiers;
public IAbilityProperties properties;
public AbilityInstance(BaseAbility template)
{
this.id = System.Guid.NewGuid().ToString();
this.template = template;
this.currentCooldown = template.cooldown;
this.currentManaCost = template.manaCost;
this.currentHealthCost = template.healthCost;
this.currentClassResourceCost = template.classResourceCost;
this.currentEffects = new List<BaseEffect>(template.abilityEffects);
this.currentModifiers = new List<IAbilityModifier>();
this.properties = template.CreateProperties();
this.properties.Initialize(template);
}
public void AddModifier(IAbilityModifier abilityModifier)
{
currentModifiers.Add(abilityModifier);
}
public void RemoveModifier(IAbilityModifier abilityModifier)
{
currentModifiers.Remove(abilityModifier);
}
public void Execute(PhotonView user, Taggable userTag, Vector3 targetPosition, Taggable targetTag)
{
AbilityExecutionContext context = new AbilityExecutionContext
{
User = user,
UserTag = userTag,
TargetPosition = targetPosition,
TargetTag = targetTag,
Cooldown = currentCooldown,
ManaCost = currentManaCost,
HealthCost = currentHealthCost,
ClassResourceCost = currentClassResourceCost,
Effects = currentEffects,
Modifiers = currentModifiers
};
SpendResourcesNecessary(user);
properties.ModifiedExecution(context);
/*foreach (var effect in context.Effects)
{
effect.ApplyEffect(context.UserTag, new List<Taggable> { context.TargetTag });
}
currentCooldown = context.Cooldown;
currentManaCost = context.ManaCost;
currentHealthCost = context.HealthCost;
currentClassResourceCost = context.ClassResourceCost;*/
}
public void SpendResourcesNecessary(PhotonView user)
{
user.GetComponent<Mana>().ChangeValue(-currentManaCost);
user.GetComponent<Health>().ChangeValue(-currentHealthCost);
user.GetComponent<ClassResource>()?.ChangeValue(-currentClassResourceCost);
}
}
}