SRMP-Public/SRMP/Networking/NetworkGordo.cs

87 lines
3.2 KiB
C#
Raw Normal View History

2023-05-29 22:23:11 +02:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace SRMultiplayer.Networking
{
public class NetworkGordo : MonoBehaviour
{
public string ID { get { return Gordo.id == null ? Gordo.GetComponentInParent<GadgetSite>(true).id : Gordo.id; } }
2023-05-29 22:23:11 +02:00
public GordoEat Gordo;
public NetworkRegion Region;
private void OnDestroy()
{
Globals.Gordos.Remove(ID);
}
public void Eat(Vector3 position, Quaternion rotation)
{
if (Gordo.eatFX != null)
{
SRBehaviour.SpawnAndPlayFX(Gordo.eatFX, position, rotation);
}
if (Gordo.eatCue != null)
{
SECTR_AudioSystem.Play(Gordo.eatCue, position, false);
}
}
public void Burst()
{
//if object is in active mark the reach target
2023-05-29 22:23:11 +02:00
if (gameObject.activeInHierarchy)
{
StartCoroutine(ReachedTarget());
}
else
{
//if not just dismiss the gordo completely
2023-05-29 22:23:11 +02:00
Gordo.gameObject.SetActive(false);
Gordo.SetEatenCount(-1);
}
}
//process the gordo burst reaction
2023-05-29 22:23:11 +02:00
private IEnumerator ReachedTarget()
{
//start the burst and begin sounds and animations
2023-05-29 22:23:11 +02:00
Gordo.WillStartBurst();
Gordo.GetComponent<GordoFaceAnimator>().SetTrigger("Strain");
SECTR_AudioSystem.Play(Gordo.strainCue, Gordo.transform.position, false);
//wait for amination/sounds to finish
2023-05-29 22:23:11 +02:00
yield return new WaitForSeconds(2f);
SECTR_AudioSystem.Play(Gordo.burstCue, Gordo.transform.position, false);
//if the gordo has a destroy effect process it
2023-05-29 22:23:11 +02:00
if (Gordo.destroyFX != null)
{
//play the spawn behavior for destroy events for the gordo that is bursting
2023-05-29 22:23:11 +02:00
GameObject gameObject = SRBehaviour.SpawnAndPlayFX(Gordo.destroyFX, Gordo.transform.position + Vector3.up * 2f, Gordo.transform.rotation);
//get the gordo slime type
2023-05-29 22:23:11 +02:00
Identifiable component = Gordo.gameObject.GetComponent<Identifiable>();
//get the color of the current gordo
2023-05-29 22:23:11 +02:00
Color[] colors = SlimeUtil.GetColors(Gordo.gameObject, (component != null) ? component.id : Identifiable.Id.NONE, true);
//get the slime children spawned by the gordo
2023-05-29 22:23:11 +02:00
RecolorSlimeMaterial[] componentsInChildren = gameObject.GetComponentsInChildren<RecolorSlimeMaterial>();
for (int i = 0; i < componentsInChildren.Length; i++)
{
//foreach slime in the count spawned by the gordo, set their coloring
2023-05-29 22:23:11 +02:00
componentsInChildren[i].SetColors(colors[0], colors[1], colors[2]);
}
}
//trigger the burst completed event
2023-05-29 22:23:11 +02:00
Gordo.DidCompleteBurst();
//despawn the bursted gordo from game
2023-05-29 22:23:11 +02:00
Gordo.gameObject.SetActive(false);
Gordo.SetEatenCount(-1);
yield break;
}
}
}