using System;
using UnityEngine;

// Token: 0x02000076 RID: 118
[ExecuteInEditMode]
public class Moonlight : MonoBehaviour
{
	// Token: 0x06000B96 RID: 2966 RVA: 0x000E0139 File Offset: 0x000DE339
	private void Start()
	{
		this.SetupLight(false);
	}

	// Token: 0x06000B97 RID: 2967 RVA: 0x000E0142 File Offset: 0x000DE342
	private void OnEnable()
	{
		this.SetupLight(false);
		if (this.characterID == -1 && Links.x && Links.x.diorama)
		{
			Links.x.diorama.MoonlightList(this, true);
		}
	}

	// Token: 0x06000B98 RID: 2968 RVA: 0x000E0182 File Offset: 0x000DE382
	public void EnableRevealer()
	{
		if (this.moonlightRevealer)
		{
			this.moonlightRevealer.enabled = true;
			return;
		}
		this.SetupLight(false);
	}

	// Token: 0x06000B99 RID: 2969 RVA: 0x000E01A8 File Offset: 0x000DE3A8
	public void SetupLight(bool alwaysSetup)
	{
		this.tr = base.transform;
		this.l = base.gameObject.GetComponent<Light>();
		if (this.l)
		{
			this.radius = this.l.range * this.l.range;
			this.radius /= 2f;
			this.moonlightRevealer = base.gameObject.GetComponent<MoonlightRevealer>();
			if (!this.moonlightRevealer || this.prevInteriorLight != this.interiorLight || this.prevDynamicLight != this.dynamicLight || alwaysSetup)
			{
				if (this.moonlightRevealer)
				{
					if (Application.isPlaying)
					{
						Object.Destroy(this.moonlightRevealer);
					}
					else
					{
						Object.DestroyImmediate(this.moonlightRevealer);
					}
				}
				if (base.gameObject.name.Contains("nteractive"))
				{
					this.dynamicLight = true;
				}
				this.moonlightRevealer = base.gameObject.AddComponent<MoonlightRevealer>();
				this.moonlightRevealer.range = new Vector2(1f, this.l.range);
				this.moonlightRevealer.yOffset = this.yOffset;
				this.moonlightRevealer.characterID = this.characterID;
				if (this.characterID != -1)
				{
					if (base.gameObject.GetComponent<Character>())
					{
						this.moonlightRevealer.main = base.gameObject.GetComponent<Character>().mainSelected;
					}
					if (Links.x.diorama)
					{
						Links.x.diorama.MoonlightList(this, false);
					}
				}
				this.SetColor();
				if (this.dynamicLight)
				{
					this.moonlightRevealer.lineOfSightCheck = MoonlightSystem.LOSChecks.EveryUpdate;
				}
				else
				{
					this.moonlightRevealer.lineOfSightCheck = MoonlightSystem.LOSChecks.OnlyOnce;
				}
				this.moonlightRevealer.interiorLight = this.interiorLight;
			}
			this.prevInteriorLight = this.interiorLight;
			this.prevDynamicLight = this.dynamicLight;
			this.l.enabled = false;
		}
	}

	// Token: 0x06000B9A RID: 2970 RVA: 0x000E03AC File Offset: 0x000DE5AC
	public void SetColor()
	{
		float num = this.l.intensity;
		if (num > 1f)
		{
			num = 1f + num / 5f;
		}
		float num2 = 2f;
		if (this.dynamicLight)
		{
			num2 = 1f;
		}
		Color color = this.l.color / num2 * num;
		color.a = 1f;
		this.moonlightRevealer.lightColor = color;
	}

	// Token: 0x06000B9B RID: 2971 RVA: 0x000E0424 File Offset: 0x000DE624
	private void OnDisable()
	{
		if (this.characterID == -1 && Links.x && Links.x.diorama)
		{
			Links.x.diorama.MoonlightList(this, false);
		}
	}

	// Token: 0x040011B5 RID: 4533
	public Transform tr;

	// Token: 0x040011B6 RID: 4534
	public Light l;

	// Token: 0x040011B7 RID: 4535
	public MoonlightRevealer moonlightRevealer;

	// Token: 0x040011B8 RID: 4536
	public bool dynamicLight;

	// Token: 0x040011B9 RID: 4537
	public bool interiorLight;

	// Token: 0x040011BA RID: 4538
	public float yOffset;

	// Token: 0x040011BB RID: 4539
	private bool prevInteriorLight;

	// Token: 0x040011BC RID: 4540
	private bool prevDynamicLight;

	// Token: 0x040011BD RID: 4541
	public float radius;

	// Token: 0x040011BE RID: 4542
	public int characterID = -1;
}
