using Kryz.CharacterStats;
using Kryz.CharacterStats.Examples;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


[CreateAssetMenu(fileName = "AbsorbEffect", menuName = "RiftMayhem/AbilitySystem/Effects/Absorb Effect", order = 1)]
public class AbsorbEffect : StatusEffect
{
    public float amount;
    public float percentStatInfluence;

    AbsorbEffectInstance targetAbsorbEffect;

    public override void ApplyEffect(Taggable user, List<Taggable> targets)
    {
        base.ApplyEffect(user, targets);

        if(applyToTargetsHit)
        {
            foreach (Taggable target in targets)
            {
                if (IsAlliedTarget(user, target))
                {
                    targetAbsorbEffect = target.GetComponent<AbsorbEffectInstance>();
                    targetAbsorbEffect.owner.RPC(nameof(targetAbsorbEffect.RPC_ApplyAbsorbEffect), targetAbsorbEffect.owner.Owner, StatusEffectIndexer.Instance.StatusEffects.IndexOf(this));
                }
            }
        }
        if (applyToSelf)
        {
            targetAbsorbEffect = user.GetComponent<AbsorbEffectInstance>();
            targetAbsorbEffect.ApplyEffect(this);
            //targetAbsorbEffect.owner.RPC(nameof(targetAbsorbEffect.RPC_ApplyAbsorbEffect), targetAbsorbEffect.owner.Owner, StatusEffectIndexer.Instance.StatusEffects.IndexOf(this));
        }
    }

    private bool IsAlliedTarget(Taggable user, Taggable target)
    {
        return user.targetTag.AlliedTags.Contains(target.targetTag);
    }
}
