<commit_before>﻿using UnityEngine;
using System.Collections;
using RAIN.Core;
using RAIN.Action;

public class FollowClosestPlayer : MonoBehaviour {
	
	public float howOftenToCheckForClosestPlayer = 2.0f;

	public float meleeDistance = 100f;

	void Start()
	{
		StartCoroutine("FindClosestPlayer");
	}

	IEnumerator FindClosestPlayer()
	{

		GameObject[] playerList = GameObject.FindGameObjectsWithTag("Player");

		float closestDistance = float.MaxValue;
		int closePlayerIdx = 0;

		for (int i = 0; i < playerList.Length - 1; i++)
		{
			if( playerList[i].gameObject.transform.parent == null )
			{

				PhotonPlayer p = playerList[i].GetComponent<PhotonView>().owner;

				if(p.customProperties.ContainsKey("Health") && ((int)p.customProperties["Health"]) > 0)
				{
					float tempDistance = Mathf.Abs(Vector3.Distance( playerList[i].gameObject.transform.position, this.gameObject.transform.position));
					if( tempDistance < closestDistance)
					{
						closestDistance = tempDistance;
						closePlayerIdx = i;
					}
				}
			}
		}

		if( playerList[closePlayerIdx] == null )
		{
			Debug.LogError("No players for AI to find");
		}
		this.transform.FindChild("AI").GetComponent<AIRig>().AI.WorkingMemory.SetItem("detectObject2", playerList[closePlayerIdx]);
		/*if( closestDistance < meleeDistance )
		{
			print ("close enough to melee");
			this.transform.FindChild("AI").GetComponent<AIRig>().AI.WorkingMemory.SetItem("attackPlayer", playerList[closePlayerIdx]);
		}
		else
		{
			this.transform.FindChild("AI").GetComponent<AIRig>().AI.WorkingMemory.SetItem("attackPlayer", null);
		}*/

		//}
		/*else if ( playerList.Length == 1 )
		{
			this.transform.FindChild("AI").GetComponent<AIRig>().AI.WorkingMemory.SetItem("detectObject2", playerList[0]);
		}*/<commit_msg>+Fixed some follow player issues<commit_after>﻿using UnityEngine;
using System.Collections;
using RAIN.Core;
using RAIN.Action;

public class FollowClosestPlayer : MonoBehaviour {
	
	public float howOftenToCheckForClosestPlayer = 2.0f;

	public float meleeDistance = 100f;

	void Start()
	{
		StartCoroutine("FindClosestPlayer");
	}

	IEnumerator FindClosestPlayer()
	{

		GameObject[] playerList = GameObject.FindGameObjectsWithTag("Player");

		float closestDistance = float.MaxValue;
		int closePlayerIdx = -1;

		for (int i = 0; i < playerList.Length ; i++)
		{
			if( playerList[i].GetComponent<PhotonView>() == null )
			{
				continue;
			}

			PhotonPlayer p = playerList[i].GetComponent<PhotonView>().owner;

			if( p == null ) 
			{
				continue;
			}

			if(p.customProperties.ContainsKey("Health") && ((int)p.customProperties["Health"]) > 0)
			{
				float tempDistance = Mathf.Abs(Vector3.Distance( playerList[i].gameObject.transform.position, this.gameObject.transform.position));
				if( tempDistance < closestDistance)
				{
					closestDistance = tempDistance;
					closePlayerIdx = i;
				}
			}

		}

		if( closePlayerIdx == -1 )
		{
			Debug.LogError("No players for AI to find");
		}
		this.transform.FindChild("AI").GetComponent<AIRig>().AI.WorkingMemory.SetItem("detectObject2", playerList[closePlayerIdx]);
		/*if( closestDistance < meleeDistance )
		{
			print ("close enough to melee");
			this.transform.FindChild("AI").GetComponent<AIRig>().AI.WorkingMemory.SetItem("attackPlayer", playerList[closePlayerIdx]);
		}
		else
		{
			this.transform.FindChild("AI").GetComponent<AIRig>().AI.WorkingMemory.SetItem("attackPlayer", null);
		}*/

		//}
		/*else if ( playerList.Length == 1 )
		{
			this.transform.FindChild("AI").GetComponent<AIRig>().AI.WorkingMemory.SetItem("detectObject2", playerList[0]);
		}*/
{'fraction_non_alphanumeric': 0.14388489208633093, 'fraction_numerical': 0.00774764803541782, 'mean_word_length': 4.331858407079646, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 16, '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': '5316574', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1167, 'n_words': 194}