using System;
using System.Collections.Generic;
using MaidStatus;
using MaidStatus.Old;
using UnityEngine;
using wf;
using Yotogis;

public class YotogiOldResultManager : WfScreenChildren
{
	public override void Awake()
	{
		base.Awake();
		this.yotogi_mgr_ = base.GetComponentInParent<YotogiOldManager>();
		this.common_buttons_ = UTY.GetChildObject(base.root_obj, "CommonPanel", false).GetComponent<YotogiCommonButtons>();
		this.common_buttons_.viwe_reset_btn.gameObject.SetActive(false);
		GameObject gameObject = Utility.CreatePrefab(base.root_obj, "SceneYotogi/Common/Prefab/Old/ParameterViewer", true);
		gameObject.transform.SetParent(UTY.GetChildObject(base.root_obj, "ParameterViewer", false).transform, false);
		gameObject.transform.localPosition = new Vector3(0f, 360f, 0f);
		this.paramenter_viewer_ = gameObject.GetComponent<YotogiOldParameterViewer>();
		this.paramenter_viewer_.SetCostumeButtonVisible(false);
		this.paramenter_viewer_.SetAttributeViewer(UTY.GetChildObject(base.root_obj.transform.parent.gameObject, "AttributeViewer", false));
		this.fluctuation_status_parent_ = UTY.GetChildObject(base.root_obj, "AcquiredParameterViewer/FluctuationOfParameter/FluctuationOfParameterParent", false).GetComponent<UITable>();
		this.acquired_skill_parent_ = UTY.GetChildObject(base.root_obj, "AcquiredParameterViewer/AcquiredSkill/AcquiredSkillParent", false).GetComponent<UIGrid>();
		this.acquired_attribute_parent_ = UTY.GetChildObject(base.root_obj, "AcquiredParameterViewer/AcquiredAttribute/AcquiredAttributeParent", false).GetComponent<UIGrid>();
		this.skill_unit_parent_ = UTY.GetChildObject(base.root_obj, "SkillViewer/SkillUnitParent", false).GetComponent<UIGrid>();
	}

	protected override void OnCall()
	{
		this.common_buttons_.next_btn.onClick.Clear();
		EventDelegate.Add(this.common_buttons_.next_btn.onClick, new EventDelegate.Callback(this.OnClickNext));
		this.maid_ = this.yotogi_mgr_.maid;
		this.Clear();
		this.paramenter_viewer_.SetMaid(this.maid_);
		this.paramenter_viewer_.UpdateTextCommon();
		this.paramenter_viewer_.UpdateTextParam();
		HashSet<int> hashSet = new HashSet<int>();
		YotogiOldManager.PlayingSkillData[] play_skill_array = this.yotogi_mgr_.play_skill_array;
		for (int i = 0; i < play_skill_array.Length; i++)
		{
			if (play_skill_array[i].skill_pair.base_data != null && !hashSet.Contains(play_skill_array[i].skill_pair.base_data.id))
			{
				hashSet.Add(play_skill_array[i].skill_pair.base_data.id);
				YotogiOldSkillUnit yotogiOldSkillUnit = this.AddSkillUnit(play_skill_array[i].skill_pair);
				int num = play_skill_array[i].skill_pair.param.expSystem.GetTotalExp() - play_skill_array[i].backup_total_exp;
				if (0 < num)
				{
					yotogiOldSkillUnit.SetExpAnime(play_skill_array[i].backup_total_exp, num, this.AnimeTime);
				}
			}
		}
		YotogiOldManager.BackUpStatus backUpStatus = this.yotogi_mgr_.GetBackUpStatus();
		YotogiOldPlay.Param param = YotogiOldPlay.Param.Create(this.maid_) - backUpStatus.param;
		this.AddFluctuationStatus("夜伽クラスレベル", param.yotogi_type_level);
		this.AddFluctuationStatus("夜伽クラスEXP", param.yotogi_type_total_exp);
		this.AddFluctuationStatus("奉仕", param.housi);
		this.AddFluctuationStatus("淫欲", param.inyoku);
		this.AddFluctuationStatus("M性", param.m_value);
		this.AddFluctuationStatus("変態", param.hentai);
		this.AddFluctuationStatus("可憐", param.lovely);
		this.AddFluctuationStatus("気品", param.elegance);
		this.AddFluctuationStatus("魅惑", param.charm);
		this.AddFluctuationStatus("指導", param.teach_rate / 10);
		HashSet<int> hashSet2 = new HashSet<int>();
		foreach (int item in this.maid_.status.propensitys.GetKeyArray())
		{
			hashSet2.Add(item);
		}
		foreach (int item2 in backUpStatus.propensity)
		{
			hashSet2.Remove(item2);
		}
		foreach (int id in hashSet2)
		{
			this.AddAcquiredAttribute(Propensity.GetData(id).drawName);
		}
		HashSet<int> hashSet3 = new HashSet<int>();
		int[] keyArray2 = this.maid_.status.yotogiSkill.oldDatas.GetKeyArray();
		for (int k = 0; k < keyArray2.Length; k++)
		{
			hashSet3.Add(keyArray2[k]);
		}
		foreach (int item3 in backUpStatus.skill_id_list)
		{
			hashSet3.Remove(item3);
		}
		bool lockNTRPlay = GameMain.Instance.CharacterMgr.status.lockNTRPlay;
		foreach (int skill_id in hashSet3)
		{
			Skill.Old.Data skillData = YotogiOld.GetSkillData(skill_id);
			if (!lockNTRPlay || (skillData.category != YotogiOld.Category.交換 && skillData.category != YotogiOld.Category.乱交))
			{
				if (!skillData.drunk_skill && !skillData.osioki_skill)
				{
					this.AddAcquiredSkill(skillData.name);
				}
			}
		}
		this.fluctuation_status_parent_.Reposition();
		this.acquired_skill_parent_.Reposition();
		this.acquired_attribute_parent_.Reposition();
		this.skill_unit_parent_.Reposition();
		if (0 < this.maid_.status.currentMind && this.maid_.status.OldStatus.condition != Condition.Osioki)
		{
			string text = "?_GIG_0001.ks";
			string text2 = "?_GIG_0002.ks";
			string text3 = string.Empty;
			if (this.maid_.status.OldStatus.frustration < 50)
			{
				int num2 = param.inyoku + param.housi + param.hentai + param.m_value;
				if (400 <= num2)
				{
					text3 = text;
				}
			}
			else
			{
				int num3 = param.inyoku + param.housi + param.hentai + param.m_value;
				if (num3 < 400)
				{
					text3 = text2;
				}
			}
			if (!string.IsNullOrEmpty(text3))
			{
				GameMain.Instance.ScriptMgr.EvalScript("global.__skill_first_file = '" + text3 + "';");
				GameMain.Instance.ScriptMgr.EvalScript("global.__skill_first_file_label = '';");
				GameMain.Instance.ScriptMgr.LoadYotogiScript("yotogi_skill_call_main.ks", string.Empty);
			}
		}
		this.StartAnime();
	}

	public void Clear()
	{
		Action<GameObject> action = delegate(GameObject game_object)
		{
			Transform transform = game_object.transform;
			for (int i = 0; i < transform.childCount; i++)
			{
				UnityEngine.Object.Destroy(transform.GetChild(i).gameObject);
			}
			transform.DetachChildren();
		};
		action(this.fluctuation_status_parent_.gameObject);
		this.fluctuation_status_parent_.Reposition();
		action(this.acquired_skill_parent_.gameObject);
		this.acquired_skill_parent_.Reposition();
		action(this.acquired_attribute_parent_.gameObject);
		this.acquired_attribute_parent_.Reposition();
		action(this.skill_unit_parent_.gameObject);
		this.skill_unit_parent_.Reposition();
	}

	public void AddFluctuationStatus(string param_name, int value)
	{
		if (14 <= this.fluctuation_status_parent_.transform.childCount || value == 0)
		{
			return;
		}
		GameObject gameObject = Utility.CreatePrefab(this.fluctuation_status_parent_.gameObject, "SceneYotogi/Result/Prefab/FluctuationOfParameterUnit", true);
		FluctuationOfParameterUnit component = gameObject.GetComponent<FluctuationOfParameterUnit>();
		component.AnimeTime = this.AnimeTime;
		component.SetTextName(param_name);
		component.SetTextValue(value);
		component.SetBGVisible((this.fluctuation_status_parent_.transform.childCount + 1) / 2 % 2 == 0);
		this.fluctuation_status_parent_.repositionNow = true;
	}

	public void AddAcquiredSkill(string name)
	{
		if (8 <= this.acquired_skill_parent_.transform.childCount)
		{
			return;
		}
		GameObject gameObject = Utility.CreatePrefab(this.acquired_skill_parent_.gameObject, "SceneYotogi/Result/Prefab/AcquiredSkillUnit", true);
		AcquiredSkillUnit component = gameObject.GetComponent<AcquiredSkillUnit>();
		component.SetText(name);
		component.SetBGVisible(this.acquired_skill_parent_.transform.childCount % 2 != 0);
		this.acquired_skill_parent_.repositionNow = true;
	}

	public void AddAcquiredAttribute(string name)
	{
		if (5 <= this.acquired_attribute_parent_.transform.childCount)
		{
			return;
		}
		GameObject gameObject = Utility.CreatePrefab(this.acquired_attribute_parent_.gameObject, "SceneYotogi/Result/Prefab/AcquiredAttributeUnit", true);
		AcquiredAttributeUnit component = gameObject.GetComponent<AcquiredAttributeUnit>();
		component.SetText(name);
		this.acquired_attribute_parent_.repositionNow = true;
	}

	public YotogiOldSkillUnit AddSkillUnit(YotogiOld.SkillDataPair skill_data_pair)
	{
		if (7 <= this.skill_unit_parent_.transform.childCount)
		{
			return null;
		}
		GameObject gameObject = Utility.CreatePrefab(this.skill_unit_parent_.gameObject, "SceneYotogi/SkillSelect/Prefab/Old/SkillUnit", true);
		UTY.GetChildObject(gameObject, "Button", false).SetActive(false);
		UTY.GetChildObject(gameObject, "Description/BG", false).GetComponent<UISprite>().alpha = 1f;
		YotogiOldSkillUnit component = gameObject.GetComponent<YotogiOldSkillUnit>();
		component.SetSkillData(this.maid_, skill_data_pair.base_data, skill_data_pair.param);
		this.skill_unit_parent_.repositionNow = true;
		return component;
	}

	public void StartAnime()
	{
		Transform transform = this.fluctuation_status_parent_.gameObject.transform;
		for (int i = 0; i < transform.childCount; i++)
		{
			transform.GetChild(i).GetComponent<FluctuationOfParameterUnit>().StartAnime();
		}
		transform = this.skill_unit_parent_.gameObject.transform;
		for (int j = 0; j < transform.childCount; j++)
		{
			transform.GetChild(j).GetComponent<YotogiOldSkillUnit>().StartAnime();
		}
	}

	private void OnClickNext()
	{
		if (this.yotogi_mgr_.null_mgr.IsExistNextLabel())
		{
			this.Finish();
		}
	}

	protected override void OnFinish()
	{
		base.OnFinish();
		GameMain.Instance.SoundMgr.VoiceStopAll();
		GameMain.Instance.SoundMgr.StopSe();
		CharacterMgr characterMgr = GameMain.Instance.CharacterMgr;
		GameMain.Instance.ScriptMgr.ClearForcExecWaitEvent();
		for (int i = 0; i < characterMgr.GetMaidCount(); i++)
		{
			Maid maid = characterMgr.GetMaid(i);
			if (maid != null)
			{
				maid.FaceAnime("通常", 0f, 0);
				maid.FaceBlend("無し");
				maid.body0.SetMaskMode(TBody.MaskMode.None);
				for (int j = 10; j <= 20; j++)
				{
					maid.body0.MulTexRemove("body", 0, "_MainTex", j);
					maid.body0.MulTexRemove("body", 0, "_ShadowTex", j);
					maid.body0.MulTexRemove("head", 5, "_MainTex", j);
					maid.body0.MulTexRemove("head", 5, "_ShadowTex", j);
				}
				maid.body0.MulTexProc("body");
				maid.body0.MulTexProc("head");
			}
		}
		this.yotogi_mgr_.ResetWorld();
	}

	protected override void OnFadeEnd()
	{
		bool flag = !this.yotogi_mgr_.IsAllCharaBusy();
		if (flag)
		{
			GameMain.Instance.MainLight.Reset();
			GameMain.Instance.CharacterMgr.ResetCharaPosAll();
			GameMain.Instance.MainCamera.Reset(CameraMain.CameraType.Target, true);
			GameMain.Instance.SoundMgr.VoiceStopAll();
			this.yotogi_mgr_.UnVisibleMaidAndMan(true, true);
			this.maid_.Visible = true;
			if (this.yotogi_mgr_.null_mgr.IsExistNextLabel())
			{
				this.yotogi_mgr_.CallScreen(YotogiOldManager.CallScreenType.Null.ToString());
			}
		}
	}

	public float AnimeTime = 1.5f;

	private Maid maid_;

	private YotogiOldManager yotogi_mgr_;

	private YotogiCommonButtons common_buttons_;

	private YotogiOldParameterViewer paramenter_viewer_;

	private UITable fluctuation_status_parent_;

	private UIGrid acquired_skill_parent_;

	private UIGrid acquired_attribute_parent_;

	private UIGrid skill_unit_parent_;
}
