<commit_before>﻿using System;
using System.Collections;
using Mirror;
using UnityEngine;

namespace Alien
{
	public class AlienEggCycle : NetworkBehaviour, IInteractable<HandApply>, IServerSpawn
	{
		private const float OPENING_ANIM_TIME = 1.6f;
		private const int SMALL_SPRITE = 0;
		private const int BIG_SPRITE = 1;
		private const int OPENING_SPRITE = 2;
		private const int HATCHED_SPRITE = 3;
		private const int SQUISHED_SPRITE = 4;

		[Tooltip("How much  time should the egg take incubating the facehugger. This includes from the growing phase until the actual spawn")]
		[SerializeField]
		private float incubationTime = 300;
		[Tooltip("In what state will this egg spawn in the world.")]
		[SerializeField]
		private EggState initialState = EggState.Growing;
		[Tooltip("A reference for the facehugger mob so we can spawn it.")]
		[SerializeField]
		private GameObject facehugger;

		[SyncVar(hook = nameof(SyncState))]
		private EggState currentState;
		private SpriteHandler spriteHandler;
		private RegisterObject registerObject;
		private ObjectAttributes objectAttributes;
		public EggState State => currentState;

		private void Awake()
		{
			spriteHandler = GetComponentInChildren<SpriteHandler>();
			registerObject = GetComponent<RegisterObject>();
			objectAttributes = GetComponent<ObjectAttributes>();

			EnsureInit();
		}

		public void OnSpawnServer(SpawnInfo info)
		{
			EnsureInit();
		}

		private void EnsureInit()
		{
			if (isServer)
			{
				UpdateState(initialState);
			}

			SyncState(currentState, currentState);
		}

		private void SyncState(EggState oldState, EggState newState)
		{
			currentState = newState;

			switch (currentState)
			{
				case EggState.Growing:
					StopAllCoroutines();
					StartCoroutine(nameof(StartIncubation));
					break;
				case EggState.Grown:
					StopAllCoroutines();
					StartCoroutine(nameof(FinishIncubation));
					break;
				case EggState.Burst:
					StopAllCoroutines();
					StartCoroutine(nameof(OpenEgg));
					break;
				case EggState.Squished:
					spriteHandler.SetSprite(spriteHandler.Sprites[SQUISHED_SPRITE]);
					break;
			}
		}

		private IEnumerator StartIncubation()
		{
			spriteHandler.SetSprite(spriteHandler.Sprites[SMALL_SPRITE]);
			yield return WaitFor.Seconds(incubationTime / 2);
			UpdateState(currentState == EggState.Growing ? EggState.Grown : currentState);
		}

		private IEnumerator FinishIncubation()
		{
			spriteHandler.SetSprite(spriteHandler.Sprites[BIG_SPRITE]);
			yield return WaitFor.Seconds(incubationTime / 2);
			UpdateState(currentState == EggState.Grown ? EggState.Burst : currentState);
		}

		private IEnumerator OpenEgg()
		{<commit_msg>add field to allow mappers to freeze egg cycle<commit_after>﻿using System;
using System.Collections;
using Mirror;
using UnityEngine;

namespace Alien
{
	public class AlienEggCycle : NetworkBehaviour, IInteractable<HandApply>, IServerSpawn
	{
		private const float OPENING_ANIM_TIME = 1.6f;
		private const int SMALL_SPRITE = 0;
		private const int BIG_SPRITE = 1;
		private const int OPENING_SPRITE = 2;
		private const int HATCHED_SPRITE = 3;
		private const int SQUISHED_SPRITE = 4;

		[Tooltip("How much  time should the egg take incubating the facehugger. This includes from the growing phase until the actual spawn")]
		[SerializeField]
		private float incubationTime = 300;
		[Tooltip("In what state will this egg spawn in the world.")]
		[SerializeField]
		private EggState initialState = EggState.Growing;

		[Tooltip("Allows mappers to have eggs that won't start cycle once spawned, but are still intractable")][SerializeField]
		private bool freezeCycle = false;
		[Tooltip("A reference for the facehugger mob so we can spawn it.")]
		[SerializeField]
		private GameObject facehugger;

		[SyncVar(hook = nameof(SyncState))]
		private EggState currentState;
		private SpriteHandler spriteHandler;
		private RegisterObject registerObject;
		private ObjectAttributes objectAttributes;
		public EggState State => currentState;

		private void Awake()
		{
			spriteHandler = GetComponentInChildren<SpriteHandler>();
			registerObject = GetComponent<RegisterObject>();
			objectAttributes = GetComponent<ObjectAttributes>();

			EnsureInit();
		}

		public void OnSpawnServer(SpawnInfo info)
		{
			EnsureInit();
		}

		private void EnsureInit()
		{
			if (isServer)
			{
				UpdateState(initialState);
			}

			SyncState(currentState, currentState);
		}

		private void SyncState(EggState oldState, EggState newState)
		{
			currentState = newState;

			switch (currentState)
			{
				case EggState.Growing:
					StopAllCoroutines();
					StartCoroutine(nameof(StartIncubation));
					break;
				case EggState.Grown:
					StopAllCoroutines();
					StartCoroutine(nameof(FinishIncubation));
					break;
				case EggState.Burst:
					StopAllCoroutines();
					StartCoroutine(nameof(OpenEgg));
					break;
				case EggState.Squished:
					spriteHandler.SetSprite(spriteHandler.Sprites[SQUISHED_SPRITE]);
					break;
			}
		}

		private IEnumerator StartIncubation()
		{
			spriteHandler.SetSprite(spriteHandler.Sprites[SMALL_SPRITE]);

			if (freezeCycle)
			{
				yield break;
			}

			yield return WaitFor.Seconds(incubationTime / 2);
			UpdateState(currentState == EggState.Growing ? EggState.Grown : currentState);
		}

		private IEnumerator FinishIncubation()
		{
			spriteHandler.SetSprite(spriteHandler.Sprites[BIG_SPRITE]);

			if (freezeCycle)
			{
				yield break;
			}
			
			yield return WaitFor.Seconds(incubationTime / 2);
			UpdateState(currentState == EggState.Grown ? EggState.Burst : currentState);
		}

		private IEnumerator OpenEgg()
		{
{'fraction_non_alphanumeric': 0.08565843255731295, 'fraction_numerical': 0.004265150168828861, 'mean_word_length': 4.284507042253521, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1556323', 'n_tokens_mistral': 2155, 'n_tokens_neox': 1755, 'n_words': 431}