using System;
using System.Collections.Generic;
using UnityEngine;

// Token: 0x02000045 RID: 69
public class PuzzleListener : MonoBehaviour
{
	// Token: 0x060008A6 RID: 2214 RVA: 0x000BC45C File Offset: 0x000BA65C
	public void Setup()
	{
		this.top = this.coll.bounds.center + new Vector3(0f, this.coll.bounds.size.y / 2f, 0f);
		this.coll.gameObject.layer = 0;
		this.coll.isTrigger = true;
		GameObject gameObject = Object.Instantiate<GameObject>(this.coll.gameObject);
		gameObject.name = "Collider_floor";
		this.altCollider = gameObject.transform;
		this.altCollider.SetParent(base.transform.parent, true);
		this.altCollider.position = this.coll.gameObject.transform.position;
		this.altCollider.rotation = this.coll.gameObject.transform.rotation;
		this.altCollider.gameObject.layer = 0;
		this.altCollider.localScale = this.coll.gameObject.transform.localScale;
		this.altCollider.position = this.coll.gameObject.transform.position - new Vector3(0f, 0.2f, 0f);
		BoxCollider boxCollider = gameObject.AddComponent<BoxCollider>();
		boxCollider.center = this.coll.center;
		boxCollider.size = this.coll.size;
	}

	// Token: 0x060008A7 RID: 2215 RVA: 0x000BC5E4 File Offset: 0x000BA7E4
	private void OnTriggerEnter(Collider other)
	{
		GameObject gameObject = other.gameObject;
		if (gameObject && this.puzzleID.Contains("WeightPuzzle"))
		{
			if (gameObject.layer == 6)
			{
				Character component = gameObject.gameObject.GetComponent<Character>();
				if (component && component.stats && component.stats.Floating() == 0 && !component.dead && !component.stats.flying)
				{
					if (this.hitObjects.IndexOf(gameObject) == -1)
					{
						this.puzzleActions.AddWeightCharacter(component);
					}
					this.puzzleActions.ChangeWeight();
				}
			}
			if (gameObject.layer == 11)
			{
				if (this.hitObjects.IndexOf(gameObject) == -1)
				{
					this.hitObjects.Add(gameObject);
					this.hitItems.Add(gameObject);
					this.puzzleActions.updateWeight = 1;
				}
				this.puzzleActions.ChangeWeight();
			}
			return;
		}
	}

	// Token: 0x060008A8 RID: 2216 RVA: 0x000BC6D4 File Offset: 0x000BA8D4
	public void SetHeight(float newHeight)
	{
		for (int i = 0; i < this.hitItems.Count; i++)
		{
			if (this.hitItems[i])
			{
				Vector3 position = this.hitItems[i].transform.position;
				position.y = newHeight;
				this.hitItems[i].gameObject.transform.position = position + new Vector3(0f, 0.2f, 0f);
			}
		}
	}

	// Token: 0x060008A9 RID: 2217 RVA: 0x000BC760 File Offset: 0x000BA960
	public void CheckItems()
	{
		bool flag = false;
		for (int i = 0; i < this.hitItems.Count; i++)
		{
			bool flag2 = false;
			if (!this.hitItems[i])
			{
				flag2 = true;
			}
			else
			{
				if (!this.hitItems[i].activeInHierarchy)
				{
					flag2 = true;
				}
				if (!this.hitItems[i].activeSelf)
				{
					flag2 = true;
				}
			}
			if (flag2)
			{
				int num = this.hitObjects.IndexOf(this.hitItems[i]);
				if (num > -1)
				{
					this.hitObjects.RemoveAt(num);
				}
				this.hitItems[i] = null;
				this.puzzleActions.ChangeWeight();
				flag = true;
			}
		}
		if (flag)
		{
			this.hitItems.RemoveAll((GameObject item) => item == null);
		}
	}

	// Token: 0x060008AA RID: 2218 RVA: 0x000BC841 File Offset: 0x000BAA41
	public void AddCharacter(Character character)
	{
		if (!this.hitObjects.Contains(character.gameObject))
		{
			this.hitObjects.Add(character.gameObject);
			this.hitCharacters.Add(character);
		}
	}

	// Token: 0x060008AB RID: 2219 RVA: 0x000BC874 File Offset: 0x000BAA74
	public void CheckToRemoveCharacter(Character character)
	{
		if (character == null)
		{
			return;
		}
		GameObject gameObject = character.gameObject;
		int num = this.hitCharacters.IndexOf(character);
		if (num > -1)
		{
			this.hitCharacters.RemoveAt(num);
			int num2 = this.hitObjects.IndexOf(gameObject);
			if (num2 > -1)
			{
				this.hitObjects.RemoveAt(num2);
			}
			else if (this.hitObjects.Count != this.hitCharacters.Count)
			{
				this.hitObjects.RemoveAll((GameObject item) => item == null);
			}
			this.puzzleActions.ChangeWeight();
		}
	}

	// Token: 0x060008AC RID: 2220 RVA: 0x000BC91C File Offset: 0x000BAB1C
	public int GetHitObjectCount()
	{
		return this.hitObjects.Count;
	}

	// Token: 0x04000D89 RID: 3465
	public string puzzleID;

	// Token: 0x04000D8A RID: 3466
	public PuzzleActions puzzleActions;

	// Token: 0x04000D8B RID: 3467
	public List<GameObject> hitObjects = new List<GameObject>();

	// Token: 0x04000D8C RID: 3468
	public List<Character> hitCharacters = new List<Character>();

	// Token: 0x04000D8D RID: 3469
	public List<GameObject> hitItems = new List<GameObject>();

	// Token: 0x04000D8E RID: 3470
	public BoxCollider coll;

	// Token: 0x04000D8F RID: 3471
	public Vector3 top;

	// Token: 0x04000D90 RID: 3472
	private Transform altCollider;
}
