using System;
using UnityEngine;

public class OnaholeReactionManager : MonoBehaviour
{
	public Maid maid { get; private set; }

	public bool highlightHeart
	{
		get
		{
			return this.highlightHeart_;
		}
		set
		{
			this.highlightHeart_ = value;
			if (this.highlightHeart_ && this.highlightHide_)
			{
				this.highlightHide_ = false;
			}
			this.UpdateHighligParts();
		}
	}

	public bool highlightHide
	{
		get
		{
			return this.highlightHide_;
		}
		set
		{
			this.highlightHide_ = value;
			if (this.highlightHide_ && this.highlightHeart_)
			{
				this.highlightHeart_ = false;
			}
			this.UpdateHighligParts();
		}
	}

	public bool runnyNoseEffect
	{
		get
		{
			return this.runnyNoseEffect_;
		}
		set
		{
			if (this.isReady)
			{
				this.CallReactionFile("*鼻水", value);
			}
			this.runnyNoseEffect_ = value;
		}
	}

	public bool saladEffect
	{
		get
		{
			return this.saladEffect_;
		}
		set
		{
			if (this.isReady)
			{
				this.CallReactionFile("*涎", value);
			}
			this.saladEffect_ = value;
		}
	}

	public bool sweatEffect
	{
		get
		{
			return this.sweatEffect_;
		}
		set
		{
			if (this.isReady)
			{
				this.CallReactionFile("*汗", value);
			}
			this.sweatEffect_ = value;
		}
	}

	public bool breatheEffect
	{
		get
		{
			return this.breatheEffect_;
		}
		set
		{
			if (this.breatheObject != null)
			{
				this.breatheObject.SetActive(value);
			}
			this.breatheEffect_ = value;
		}
	}

	private void Awake()
	{
		this.maid = base.GetComponent<Maid>();
		this.ReadyCheck();
	}

	private void OnDestroy()
	{
		if (!this.isReady)
		{
			return;
		}
		if (this.breatheObject != null)
		{
			this.maid.DelPrefab("夜伽_吐息");
		}
		if (this.maid == null || this.maid.body0 == null || !this.maid.body0.isLoadedBody)
		{
			return;
		}
		bool visible = this.maid.Visible;
		if (this.runnyNoseEffect)
		{
			this.runnyNoseEffect = false;
		}
		if (this.saladEffect)
		{
			this.saladEffect = false;
		}
		if (this.sweatEffect)
		{
			this.sweatEffect = false;
		}
		if (this.breatheEffect)
		{
			this.breatheEffect = false;
		}
		if (this.highlightHeart)
		{
			this.highlightHeart = false;
		}
		if (this.highlightHide)
		{
			this.highlightHide = false;
		}
		if (this.maid.Visible != visible)
		{
			this.maid.Visible = visible;
		}
	}

	private void Start()
	{
		if (this.maid == null)
		{
			this.maid = base.GetComponent<Maid>();
		}
		this.ReadyCheck();
	}

	public void SetMaid(Maid maid)
	{
		if (this.maid == null || maid != null)
		{
			this.maid = maid;
			this.ReadyCheck();
		}
		else if (this.maid != null)
		{
			Debug.LogWarning("OnaholeReactionManager::SetMaid Error:すでにメイドはセットされています");
		}
	}

	public void ResetReaction()
	{
		this.highlightHeart = false;
		this.highlightHide = false;
		this.runnyNoseEffect = false;
		this.saladEffect = false;
		this.sweatEffect = false;
		this.breatheEffect = false;
	}

	private void Update()
	{
		if (!this.isReady)
		{
			this.ReadyCheck();
		}
	}

	private void ReadyCheck()
	{
		if (this.isReady || this.maid == null || this.maid.body0 == null || !this.maid.body0.isLoadedBody || this.maid.IsAllProcPropBusy)
		{
			return;
		}
		this.isReady = true;
		if (this.breatheObject == null)
		{
			this.maid.AddPrefab("Particle/pToiki", "夜伽_吐息", "Bip01 Head", new Vector3(0.042f, 0.076f, 0f), new Vector3(-90f, 90f, 0f));
			this.breatheObject = this.maid.GetPrefab("夜伽_吐息");
			this.breatheEffect = this.breatheEffect_;
		}
		this.sweatEffect = this.sweatEffect_;
		this.UpdateHighligParts();
	}

	private void CallReactionFile(string label, bool enabled)
	{
		if (!this.isReady)
		{
			return;
		}
		if (this.maid.ActiveSlotNo < 0)
		{
			Debug.LogWarning("リアクションファイルを呼び出そうとしましたが、メイドがActiveではありません");
			return;
		}
		GameMain.Instance.ScriptMgr.EvalScript("tf['痕メイド'] = " + this.maid.ActiveSlotNo.ToString());
		GameMain.Instance.ScriptMgr.EvalScript("tf['痕遅延'] = 0");
		if (!enabled)
		{
			label += "_削除";
		}
		GameMain.Instance.ScriptMgr.LoadTempScript("CBLReactionFile.ks", label);
		GameMain.Instance.ScriptMgr.tmp_kag.Exec();
	}

	private void UpdateHighligParts()
	{
		if (!this.isReady)
		{
			return;
		}
		string text = string.Empty;
		if (this.highlightHeart)
		{
			text = "_i_skinhi_nky003.menu";
		}
		if (this.highlightHide_)
		{
			text = "_i_skinhi002.menu";
		}
		if (string.IsNullOrEmpty(text))
		{
			this.maid.ResetProp(MPN.eye_hi, true);
		}
		else
		{
			this.maid.SetProp(MPN.eye_hi, text, 0, true, false);
		}
		this.maid.AllProcProp();
	}

	private const string kHighlightNoneMenuFile = "_i_skinhi002.menu";

	private const string kHighlightHeartMenuFile = "_i_skinhi_nky003.menu";

	private bool isReady;

	private bool runnyNoseEffect_;

	private bool saladEffect_;

	private bool sweatEffect_;

	private bool breatheEffect_;

	private bool highlightHide_;

	private bool highlightHeart_;

	private GameObject breatheObject;
}
