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

[RequireComponent(typeof(ConeOfSight))]
public class MobFlee : MobPathFinder
{
	private ConeOfSight coneOfSight;
	public Transform fleeTarget;
	private int doorMask;
	private int doorAndObstacleMask;

	public override void OnEnable()
	{
		base.OnEnable();
		coneOfSight = GetComponent<ConeOfSight>();
		doorMask = LayerMask.GetMask("Door Open", "Door Closed", "Windows");
		doorAndObstacleMask = LayerMask.GetMask("Walls", "Machines", "Windows", "Furniture", "Objects", "Door Open",
			"Door Closed", "Players");
	}

	[ContextMenu("Force Activate")]
	void ForceActivate()
	{
		Activate();
		TryToFlee();
	}

	public void FleeFromTarget(Transform target)
	{
		fleeTarget = target;
		Activate();
		TryToFlee();
	}

	protected override void FollowCompleted()
	{
		if (health.IsDead || health.IsCrit || health.IsCardiacArrest || fleeTarget == null) return;
		TryToFlee();
	}

	void TryToFlee()
	{
		if (!activated) return;

		var oppositeDir = ((fleeTarget.localPosition - transform.localPosition).normalized) * -1f;
		StartCoroutine(FindValidWayPoint(oppositeDir));
	}

	IEnumerator FindValidWayPoint(Vector2 oppositeDir)
	{
		//First try to escape the room by looking for a door
		var possibleDoors = Physics2D.OverlapCircleAll(transform.position, 20f, doorMask);

		//See if the door is visible to npc:
		List<Collider2D> visibleDoors = new List<Collider2D>();<commit_msg>Fixed FPS killer mob flee spam<commit_after>﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(ConeOfSight))]
public class MobFlee : MobPathFinder
{
	private ConeOfSight coneOfSight;
	public Transform fleeTarget;
	private int doorMask;
	private int doorAndObstacleMask;

	private DateTime lastFlee;
	private float fleeCoolDown = 4f;

	public override void OnEnable()
	{
		base.OnEnable();
		lastFlee = DateTime.Now;
		coneOfSight = GetComponent<ConeOfSight>();
		doorMask = LayerMask.GetMask("Door Open", "Door Closed", "Windows");
		doorAndObstacleMask = LayerMask.GetMask("Walls", "Machines", "Windows", "Furniture", "Objects", "Door Open",
			"Door Closed", "Players");
	}

	[ContextMenu("Force Activate")]
	void ForceActivate()
	{
		Activate();
		TryToFlee();
	}

	public void FleeFromTarget(Transform target)
	{
		var totalSeconds = (DateTime.Now - lastFlee).TotalSeconds;
		if (totalSeconds < fleeCoolDown) return;
		lastFlee = DateTime.Now;
		fleeTarget = target;
		Activate();
		TryToFlee();
	}

	protected override void FollowCompleted()
	{
		if (health.IsDead || health.IsCrit || health.IsCardiacArrest || fleeTarget == null) return;
		TryToFlee();
	}

	void TryToFlee()
	{
		if (!activated) return;

		var oppositeDir = ((fleeTarget.localPosition - transform.localPosition).normalized) * -1f;
		StartCoroutine(FindValidWayPoint(oppositeDir));
	}

	IEnumerator FindValidWayPoint(Vector2 oppositeDir)
	{
		//First try to escape the room by looking for a door
		var possibleDoors = Physics2D.OverlapCircleAll(transform.position, 20f, doorMask);

		//See if the door is visible to npc:
		List<Collider2D> visibleDoors = new List<Collider2D>();
{'fraction_non_alphanumeric': 0.11644695543000627, 'fraction_numerical': 0.004708097928436911, 'mean_word_length': 5.261296660117878, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 9, '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': '4323300', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1050, 'n_words': 255}