using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(fileName = "AntiProjectileAbility", menuName = "RiftMayhem/AbilitySystem/Abilities/Anti Projectile Ability", order = 0)]
public class AntiProjectileAbility : BaseAbility
{
    public GameObject antiProjectilePrefab;

    public float duration;
    public bool followUser;

    private GameObject instantiatedProjectile;
    private NetworkedAntiProjectile networkedAntiProjectile;

    public override void Execute(PhotonView user, Taggable userTag)
    {
        base.Execute(user, userTag);

        Debug.Log($"Player {user.name} casted {this.name} and spent {manaCost} mana.");

        instantiatedProjectile = PhotonNetwork.Instantiate("Abilities/" + antiProjectilePrefab.name, user.transform.position, user.GetComponentInChildren<ProjectileSpawnLocationController>().transform.rotation);

        networkedAntiProjectile = instantiatedProjectile.GetComponent<NetworkedAntiProjectile>();

        networkedAntiProjectile.duration = duration;
        networkedAntiProjectile.owner = user;
        networkedAntiProjectile.ownerTag = userTag;
        networkedAntiProjectile.ability = this;
        networkedAntiProjectile.followUser = followUser;

        networkedAntiProjectile.Init();
    }
}
