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

public class YotogiResultManager : WfScreenChildren
{
	public override void Awake()
	{
		base.Awake();
		this.yotogi_mgr_ = base.GetComponentInParent<YotogiManager>();
		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/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<YotogiParameterViewer>();
		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_class_parent_ = UTY.GetChildObject(base.root_obj, "AcquiredParameterViewer/YotogiClass/AcquiredSkillParent/Contents/UnitParent", false).GetComponent<UIGrid>();
		this.acquired_skill_parent_ = UTY.GetChildObject(base.root_obj, "AcquiredParameterViewer/AcquiredSkill/AcquiredSkillParent/Contents/UnitParent", 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>();
		YotogiManager.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) && play_skill_array[i].skill_pair.base_data.specialConditionType != Skill.Data.SpecialConditionType.Faint)
			{
				hashSet.Add(play_skill_array[i].skill_pair.base_data.id);
				YotogiSkillUnit yotogiSkillUnit = this.AddSkillUnit(play_skill_array[i].skill_pair);
				int num = play_skill_array[i].skill_pair.skill_data.expSystem.GetTotalExp() - play_skill_array[i].backup_total_exp;
				if (0 < num)
				{
					yotogiSkillUnit.SetExpAnime(play_skill_array[i].backup_total_exp, num, this.AnimeTime);
				}
				if (play_skill_array[i].skill_pair.base_data.specialConditionType == Skill.Data.SpecialConditionType.Drunk)
				{
					GameMain.Instance.CharacterMgr.status.AddHaveTrophy(1130);
				}
				if (play_skill_array[i].skill_pair.base_data.specialConditionType == Skill.Data.SpecialConditionType.Drug)
				{
					GameMain.Instance.CharacterMgr.status.AddHaveTrophy(1140);
				}
				if (play_skill_array[i].skill_pair.base_data.specialConditionType == Skill.Data.SpecialConditionType.Mask)
				{
					GameMain.Instance.CharacterMgr.status.AddHaveTrophy(1150);
				}
			}
		}
		YotogiManager.BackUpStatus backUpStatus = this.yotogi_mgr_.GetBackUpStatus();
		YotogiPlay.Param param = YotogiPlay.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.yotogiClass.datas.GetKeyArray();
		for (int k = 0; k < keyArray2.Length; k++)
		{
			hashSet3.Add(keyArray2[k]);
		}
		foreach (int item3 in backUpStatus.yotogi_class_list)
		{
			hashSet3.Remove(item3);
		}
		foreach (int id2 in hashSet3)
		{
			if (!YotogiClass.IsNTRClass(id2, false))
			{
				this.AddYotogiClass(YotogiClass.GetData(id2).drawName);
			}
		}
		HashSet<int> hashSet4 = new HashSet<int>();
		keyArray2 = this.maid_.status.yotogiSkill.datas.GetKeyArray();
		for (int l = 0; l < keyArray2.Length; l++)
		{
			hashSet4.Add(keyArray2[l]);
		}
		foreach (int item4 in backUpStatus.skill_id_list)
		{
			hashSet4.Remove(item4);
		}
		bool lockNTRPlay = GameMain.Instance.CharacterMgr.status.lockNTRPlay;
		foreach (int id3 in hashSet4)
		{
			Skill.Data data = Skill.Get(id3);
			if (data.specialConditionType != Skill.Data.SpecialConditionType.Faint)
			{
				if (!lockNTRPlay || (data.category != Yotogi.Category.交換 && data.category != Yotogi.Category.乱交))
				{
					if (data.IsExecSeikeiken(this.maid_.status.seikeiken))
					{
						this.AddAcquiredSkill(data.name);
					}
				}
			}
		}
		this.fluctuation_status_parent_.Reposition();
		this.acquired_skill_parent_.Reposition();
		this.acquired_class_parent_.Reposition();
		this.acquired_attribute_parent_.Reposition();
		this.skill_unit_parent_.Reposition();
		UTY.GetChildObject(base.root_obj, "wall", false).SetActive(true);
		base.SetFadeTime(0f);
		base.SetCallInFadeWaitFrame(100000);
		base.SetFadeStatus(WfScreenChildren.FadeStatus.Wait);
		this.OnClickNext();
	}

	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_class_parent_.gameObject);
		this.acquired_class_parent_.Reposition();
		Utility.ResetNGUI(UTY.GetChildObject(this.acquired_class_parent_.transform.parent.parent.gameObject, "Contents", false).GetComponent<UIScrollView>());
		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 AddYotogiClass(string name)
	{
		UIGrid uigrid = this.acquired_class_parent_;
		GameObject gameObject = Utility.CreatePrefab(uigrid.gameObject, "SceneYotogi/Result/Prefab/AcquiredYotogiClassUnit", true);
		AcquiredSkillUnit component = gameObject.GetComponent<AcquiredSkillUnit>();
		component.SetText(name);
		component.SetBGVisible(uigrid.transform.childCount % 2 != 0);
		uigrid.repositionNow = true;
	}

	public void AddAcquiredSkill(string name)
	{
		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 YotogiSkillUnit AddSkillUnit(Yotogi.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/YotogiSkillUnit", true);
		UTY.GetChildObject(gameObject, "Button", false).SetActive(false);
		UTY.GetChildObject(gameObject, "Description/BG", false).GetComponent<UISprite>().alpha = 1f;
		YotogiSkillUnit component = gameObject.GetComponent<YotogiSkillUnit>();
		component.SetSkillData(this.maid_, skill_data_pair.base_data, skill_data_pair.skill_data, null, null);
		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<YotogiSkillUnit>().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.MulTexRemove("body", 0, "_MainTex", 24);
				maid.body0.MulTexRemove("body", 0, "_ShadowTex", 24);
				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(YotogiManager.CallScreenType.Null.ToString());
			}
		}
	}

	public float AnimeTime = 1.5f;

	private Maid maid_;

	private YotogiManager yotogi_mgr_;

	private YotogiCommonButtons common_buttons_;

	private YotogiParameterViewer paramenter_viewer_;

	private UITable fluctuation_status_parent_;

	private UIGrid acquired_skill_parent_;

	private UIGrid acquired_class_parent_;

	private UIGrid acquired_attribute_parent_;

	private UIGrid skill_unit_parent_;
}
