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

public class MobSpawnControlScript : NetworkBehaviour
{
	public List<GameObject> MobSpawners;

	public bool DetectViaMatrix;

	private bool SpawnedMobs;

	private float timeElapsedServer = 0;

	[Server]
	public void SpawnMobs()
	{
		if (SpawnedMobs) return;

		SpawnedMobs = true;

		foreach (GameObject Spawner in MobSpawners)
		{
			if (Spawner != null)
			{
				Spawner.GetComponent<MobSpawnScript>().SpawnMob();
			}
		}
	}

	protected virtual void UpdateMe()
	{
		if (isServer)
		{
			timeElapsedServer += Time.deltaTime;
			if (timeElapsedServer > 1f && !SpawnedMobs)
			{
				DetectPlayer();
				timeElapsedServer = 0;
			}
		}
	}

	private void OnEnable()
	{
		if (!DetectViaMatrix) return;
		UpdateManager.Add(CallbackType.UPDATE, UpdateMe);
	}
	void OnDisable()
	{
		UpdateManager.Remove(CallbackType.UPDATE, UpdateMe);
	}

	[Server]
	private void DetectPlayer()
	{
		foreach (var player in PlayerList.Instance.InGamePlayers)
		{
			var playerScript = player.Script;

			if (playerScript == null) return;

			if (playerScript.registerTile.Matrix == gameObject.GetComponent<RegisterObject>().Matrix)
			{
				SpawnMobs();
				UpdateManager.Remove(CallbackType.UPDATE, UpdateMe);
				return;
			}
		}
	}

	void OnDrawGizmosSelected()
	{
		var sprite = GetComponentInChildren<SpriteRenderer>();
		if (sprite == null)
			return;

		//Highlighting all controlled lightSources
		Gizmos.color = new Color(0.5f, 0.5f, 1, 1);
		for (int i = 0; i < MobSpawners.Count; i++)
		{
			var mobSpawner = MobSpawners[i];
			if (mobSpawner == null) continue;
			Gizmos.DrawLine(sprite.transform.position, mobSpawner.transform.position);
			Gizmos.DrawSphere(mobSpawner.transform.position, 0.25f);
		}
	}
}<commit_msg>Update MobSpawnControlScript.cs<commit_after>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;

public class MobSpawnControlScript : NetworkBehaviour
{
	public List<GameObject> MobSpawners;

	public bool DetectViaMatrix;

	private bool SpawnedMobs;

	private float timeElapsedServer = 0;

	private const float PlayerCheckTime = 1f;

	[Server]
	public void SpawnMobs()
	{
		if (SpawnedMobs) return;

		SpawnedMobs = true;

		foreach (GameObject Spawner in MobSpawners)
		{
			if (Spawner != null)
			{
				Spawner.GetComponent<MobSpawnScript>().SpawnMob();
			}
		}
	}

	protected virtual void UpdateMe()
	{
		if (isServer)
		{
			timeElapsedServer += Time.deltaTime;
			if (timeElapsedServer > PlayerCheckTime && !SpawnedMobs)
			{
				DetectPlayer();
				timeElapsedServer = 0;
			}
		}
	}

	private void OnEnable()
	{
		if (!DetectViaMatrix) return;
		UpdateManager.Add(CallbackType.UPDATE, UpdateMe);
	}
	void OnDisable()
	{
		UpdateManager.Remove(CallbackType.UPDATE, UpdateMe);
	}

	[Server]
	private void DetectPlayer()
	{
		if (PlayerList.Instance.GetPlayersOnMatrix(MatrixManager.Get(gameObject)).Count > 0)
		{
			SpawnMobs();
			UpdateManager.Remove(CallbackType.UPDATE, UpdateMe);
			return;
		}
	}

	void OnDrawGizmosSelected()
	{
		var sprite = GetComponentInChildren<SpriteRenderer>();
		if (sprite == null)
			return;

		//Highlighting all controlled lightSources
		Gizmos.color = new Color(0.5f, 0.5f, 1, 1);
		for (int i = 0; i < MobSpawners.Count; i++)
		{
			var mobSpawner = MobSpawners[i];
			if (mobSpawner == null) continue;
			Gizmos.DrawLine(sprite.transform.position, mobSpawner.transform.position);
			Gizmos.DrawSphere(mobSpawner.transform.position, 0.25f);
		}
	}
}
{'fraction_non_alphanumeric': 0.11361079865016872, 'fraction_numerical': 0.007592800899887514, 'mean_word_length': 4.081428571428572, 'pattern_counts': {'":': 0, '<': 12, '<?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': '7485612', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1277, 'n_words': 254}