using System;
using Pathfinding;
using UnityEngine;

// Token: 0x02000057 RID: 87
public class WaterCollisions : MonoBehaviour
{
	// Token: 0x06000B0F RID: 2831 RVA: 0x000DC56C File Offset: 0x000DA76C
	private void Update()
	{
		if (Links.x.gaia.sceneLoaded && Links.x.gaia.pathfindingReady && this.character)
		{
			if (this.sliding)
			{
				Vector3 vector = Vector3.MoveTowards(this.character.tr.position, this.slidePoint, 12f * Time.deltaTime);
				this.character.tr.position = vector;
				if ((this.slidePoint - this.character.tr.position).sqrMagnitude < 0.25f)
				{
					this.slidePoint = Vector3.zero;
					this.sliding = false;
				}
			}
			bool flag = false;
			bool flag2 = false;
			GameObject gameObject = null;
			RaycastHit raycastHit;
			if (Physics.Raycast(this.character.tr.position + new Vector3(0f, 20f, 0f), Vector3.up * -1f, out raycastHit, 50f, 262144) && raycastHit.collider.gameObject != base.gameObject && raycastHit.collider.gameObject != Links.x.diorama.boatCollider)
			{
				flag = true;
				gameObject = raycastHit.collider.gameObject;
			}
			if (!flag)
			{
				Vector3 position = this.character.tr.position;
				position.y = Links.x.diorama.boatColliderY + 0.1f;
				if (Physics.Raycast(position, Vector3.up, out raycastHit, 20f, 262144) && raycastHit.collider.gameObject != base.gameObject && raycastHit.collider.gameObject != Links.x.diorama.boatCollider)
				{
					flag2 = true;
					gameObject = raycastHit.collider.gameObject;
				}
			}
			if (flag || flag2)
			{
				if (!this.sliding)
				{
					this.Slide(gameObject);
				}
				this.character.meshAlwaysOff = true;
				this.character.body.SetMeshState(false, true);
				this.character.body.SeeThroughColliders(false);
			}
			else if (this.character.meshAlwaysOff)
			{
				this.character.meshAlwaysOff = false;
				if (this.character.visible == 1)
				{
					this.character.body.SetMeshState(true, true);
				}
				this.character.body.SeeThroughColliders(true);
			}
			if (Links.x.gameplay.seconds > this.lastSplashTime + 4f)
			{
				if (this.character.moving || this.character.turning || this.character.IsAttacking(this.character.body.currentHash) || this.character.isHit)
				{
					this.character.PlaySplash();
					this.lastSplashTime = Links.x.gameplay.seconds;
				}
				if (this.character.splash)
				{
					Vector3 position2 = this.character.tr.position;
					position2.y = 20.2f;
					this.character.splash.transform.position = position2;
				}
			}
		}
	}

	// Token: 0x06000B10 RID: 2832 RVA: 0x000DC8C0 File Offset: 0x000DAAC0
	private void OnCollisionEnter(Collision collision)
	{
		if (Links.x.gaia.sceneLoaded && Links.x.gaia.pathfindingReady)
		{
			GameObject gameObject = collision.gameObject;
			if (gameObject.layer == 18 && (Time.timeSinceLevelLoad > this.timeSinceCollision + 0.15f || this.timeSinceCollision == 0f) && this.character && gameObject != Links.x.diorama.boatCollider && this.character.node != null)
			{
				this.Slide(gameObject);
			}
		}
	}

	// Token: 0x06000B11 RID: 2833 RVA: 0x000DC958 File Offset: 0x000DAB58
	private void Slide(GameObject go)
	{
		Vector3 position = go.transform.position;
		if (this.nodeConstraint == null)
		{
			this.nodeConstraint = new NNConstraint();
		}
		this.nodeConstraint.constrainToArea = (int)this.character.node.Area;
		this.nodeConstraint.walkable = true;
		this.nodeConstraint.constrainWalkability = true;
		this.nodeConstraint.constrainTags = true;
		this.nodeConstraint.checkCircleID = 0;
		this.nodeConstraint.passID = this.character.nodeStationaryID;
		this.nodeConstraint.passID2 = this.character.nodeMovingID;
		this.nodeConstraint.constrainPenalty = 0;
		this.nodeConstraint.checkConnections = this.character.ConnectionNumber();
		this.nodeConstraint.constrainToEnvironment = 2;
		GraphNode graphNode = this.character.node.ClosestConnection(this.character.node, this.character.nodeStationaryID, this.character.nodeMovingID, 225f, this.character.currentPosition + Quaternion.LookRotation(this.character.currentPosition - position) * Vector3.forward * 2.5f, 0, this.character.ConnectionNumber(), this.nodeConstraint, 0);
		if (graphNode != null && graphNode != this.character.node && this.character.stats.Stuck() == 0 && ((Vector3)graphNode.position - this.character.tr.position).sqrMagnitude < 20f)
		{
			this.timeSinceCollision = Time.timeSinceLevelLoad;
			this.sliding = true;
			this.slidePoint = (Vector3)graphNode.position;
			this.character.ClaimNode(graphNode, (Vector3)graphNode.position, false);
			this.character.PlaySplash();
		}
	}

	// Token: 0x06000B12 RID: 2834 RVA: 0x000DCB4B File Offset: 0x000DAD4B
	private void HitFX()
	{
	}

	// Token: 0x04000FFB RID: 4091
	public Character character;

	// Token: 0x04000FFC RID: 4092
	private float timeSinceCollision;

	// Token: 0x04000FFD RID: 4093
	private NNConstraint nodeConstraint;

	// Token: 0x04000FFE RID: 4094
	public bool sliding;

	// Token: 0x04000FFF RID: 4095
	public Vector3 slidePoint;

	// Token: 0x04001000 RID: 4096
	private float lastSplashTime;
}
