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

public class NetworkMultipleProjectileChainReaction : NetworkAbilityChainReaction, IPunObservable
{
    public List<NetworkedProjectile> projectiles = new List<NetworkedProjectile>();

    ProjectileAbility projectileAbility;

    public override void ExecuteAbilityChainReaction(PhotonView owner, Taggable ownerTag)
    {
        projectileAbility = (ProjectileAbility)ability;
        foreach (NetworkedProjectile projectile in projectiles)
        {

            projectile.speed = projectileAbility.projectileSpeed;
            projectile.owner = owner;
            projectile.ownerTag = ownerTag;
            projectile.ability = projectileAbility;
            projectile.lifeSpan = projectileAbility.lifeSpan;
            projectile.canPierce = projectileAbility.canPierce;
            projectile.canHitSelf = projectileAbility.canHitSelf;

            projectile.gameObject.SetActive(true);

            projectile.Init();
        }
    }

    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.IsWriting)
        {
            for (int i = 0; i < projectiles.Count; i++)
            {
                stream.SendNext(projectiles[i].gameObject.activeSelf);
            }
        }
        if (stream.IsReading)
        {
            for (int i = 0; i < projectiles.Count; i++)
            {
                projectiles[i].gameObject.SetActive((bool)stream.ReceiveNext());
            }
        }
    }
}
