using System;
using UnityEngine;

// Token: 0x02000041 RID: 65
public class PlayerBorders : MonoBehaviour
{
	// Token: 0x0600083E RID: 2110 RVA: 0x000B3480 File Offset: 0x000B1680
	private void Awake()
	{
		this._layer = 12;
		this._borders = new Transform[this._count];
		this.tr = base.transform;
		for (int i = 0; i < this._count; i++)
		{
			this._borders[i] = GameObject.CreatePrimitive(PrimitiveType.Cube).transform;
			this._borders[i].localScale = new Vector3(2f, 4f, 0.1f);
			this._borders[i].gameObject.SetActive(base.isActiveAndEnabled);
			this._borders[i].GetComponent<Renderer>().enabled = false;
			this._borders[i].gameObject.layer = this._layer;
			this._borders[i].gameObject.name = "Player Border";
			this._borders[i].gameObject.transform.SetParent(Links.x.gameplay.gameObject.transform);
		}
		this.startMinDistance = this._minDistance;
		this.startWallDistance = this.wallDistance;
		this.startDistance = this._distance;
		this.startCharacterDistance = this.characterDistance;
	}

	// Token: 0x0600083F RID: 2111 RVA: 0x000B35B4 File Offset: 0x000B17B4
	public void UpdateSize(float r)
	{
		if (r == 1f)
		{
			this._minDistance = this.startMinDistance;
			this._distance = this.startDistance;
			this.wallDistance = this.startWallDistance;
			this.characterDistance = this.startCharacterDistance;
			for (int i = 0; i < 8; i++)
			{
				this._borders[i].localScale = new Vector3(2f, 4f, 0.1f);
			}
			return;
		}
		if (r == 8f)
		{
			this._minDistance = 2.75f;
			this._distance = 4f;
			this.wallDistance = 3.5f;
			this.characterDistance = 2.5f;
			for (int j = 0; j < 8; j++)
			{
				this._borders[j].localScale = new Vector3(3f, 4f, 0.1f);
			}
		}
	}

	// Token: 0x06000840 RID: 2112 RVA: 0x000B3688 File Offset: 0x000B1888
	private void OnEnable()
	{
		for (int i = 0; i < this._count; i++)
		{
			this._borders[i].gameObject.SetActive(true);
		}
	}

	// Token: 0x06000841 RID: 2113 RVA: 0x000B36BC File Offset: 0x000B18BC
	private void OnDisable()
	{
		for (int i = 0; i < this._count; i++)
		{
			if (this._borders[i])
			{
				this._borders[i].gameObject.SetActive(false);
			}
		}
	}

	// Token: 0x06000842 RID: 2114 RVA: 0x000B36FC File Offset: 0x000B18FC
	private void Update()
	{
		if (this.sailing)
		{
			return;
		}
		float maxHeight = this._maxHeight;
		Vector3 vector = this.tr.position + this.heightAdd;
		for (int i = 0; i < this._count; i++)
		{
			float num = (float)(360 / this._count * i);
			Vector3 vector2 = Quaternion.Euler(0f, num, 0f) * Vector3.forward;
			float num2 = this._minDistance;
			for (int j = 0; j < this._testsCount; j++)
			{
				float num3 = (this._distance - this._minDistance) / (float)this._testsCount * (float)j + this._minDistance;
				Vector3 vector3 = vector + vector2 * num3;
				if (!Physics.Raycast(new Ray(vector3, Vector3.down), maxHeight, 4194305))
				{
					break;
				}
				RaycastHit raycastHit;
				bool flag = Physics.Linecast(vector, vector3, out raycastHit, -2147483584);
				bool flag2 = false;
				GameObject gameObject;
				if (num3 < this.characterDistance && flag && !this.character.charging)
				{
					Collider collider = raycastHit.collider;
					if (collider)
					{
						gameObject = collider.gameObject;
						if (gameObject.layer == 31)
						{
							SelectionCircle component = gameObject.GetComponent<SelectionCircle>();
							if (component && (component.character.npc || Records.x.InCombat(false) || component.character.isBoro))
							{
								flag2 = true;
							}
						}
						else if (gameObject.layer == 6)
						{
							Character component2 = gameObject.GetComponent<Character>();
							if (component2 && (component2.npc || Records.x.InCombat(false) || component2.isBoro))
							{
								flag2 = true;
							}
						}
					}
				}
				if (flag2)
				{
					break;
				}
				bool flag3 = false;
				if (num3 > this.wallDistance)
				{
					flag3 = true;
				}
				bool flag4 = false;
				if (!flag3)
				{
					flag4 = Physics.Linecast(vector, vector3, 4195072);
				}
				bool flag5 = false;
				if (!flag3 && !flag4)
				{
					flag5 = Physics.Linecast(vector - new Vector3(0f, 1f, 0f), vector3 - new Vector3(0f, 1f, 0f), 65536);
				}
				if (((flag4 || flag5) && !flag3) || !Physics.Raycast(new Ray(vector3, Vector3.down), out raycastHit, 10f, 4194449))
				{
					break;
				}
				gameObject = raycastHit.collider.gameObject;
				if (gameObject.layer == 4 || gameObject.layer == 7)
				{
					break;
				}
				num2 = num3;
			}
			this._borders[i].position = vector + vector2 * num2;
			this._borders[i].transform.forward = -vector2;
		}
	}

	// Token: 0x04000CE0 RID: 3296
	public float _minDistance = 1f;

	// Token: 0x04000CE1 RID: 3297
	public float _distance = 2f;

	// Token: 0x04000CE2 RID: 3298
	public float wallDistance = 1.25f;

	// Token: 0x04000CE3 RID: 3299
	public float characterDistance = 2f;

	// Token: 0x04000CE4 RID: 3300
	public int _count = 8;

	// Token: 0x04000CE5 RID: 3301
	public float _maxHeight = 4f;

	// Token: 0x04000CE6 RID: 3302
	public int _testsCount = 16;

	// Token: 0x04000CE7 RID: 3303
	public int _layer;

	// Token: 0x04000CE8 RID: 3304
	public Vector3 heightAdd = new Vector3(0f, 1.5f, 0f);

	// Token: 0x04000CE9 RID: 3305
	private Transform[] _borders;

	// Token: 0x04000CEA RID: 3306
	private Transform tr;

	// Token: 0x04000CEB RID: 3307
	public bool sailing;

	// Token: 0x04000CEC RID: 3308
	public bool hitCollider;

	// Token: 0x04000CED RID: 3309
	public Character character;

	// Token: 0x04000CEE RID: 3310
	private float startMinDistance;

	// Token: 0x04000CEF RID: 3311
	private float startDistance;

	// Token: 0x04000CF0 RID: 3312
	private float startWallDistance;

	// Token: 0x04000CF1 RID: 3313
	private float startCharacterDistance;
}
