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

public class YotogiOld
{
	public static void CreateData()
	{
		if (YotogiOld.stage_data_list_ != null)
		{
			return;
		}
		Dictionary<YotogiOld.Stage, string> enabled_stage_dic = new Dictionary<YotogiOld.Stage, string>();
		Action<string> action = delegate(string file_name)
		{
			file_name += ".nei";
			if (!GameUty.FileSystemOld.IsExistentFile(file_name))
			{
				return;
			}
			using (AFileBase afileBase = GameUty.FileSystemOld.FileOpen(file_name))
			{
				using (CsvParser csvParser = new CsvParser())
				{
					bool condition = csvParser.Open(afileBase);
					NDebug.Assert(condition, file_name + "\nopen failed.");
					for (int j = 1; j < csvParser.max_cell_y; j++)
					{
						if (csvParser.IsCellToExistData(0, j))
						{
							string cellAsString = csvParser.GetCellAsString(0, j);
							string cellAsString2 = csvParser.GetCellAsString(1, j);
							YotogiOld.Stage stage = YotogiOld.Stage.MAX;
							try
							{
								stage = (YotogiOld.Stage)Enum.Parse(typeof(YotogiOld.Stage), cellAsString);
							}
							catch
							{
								NDebug.Assert(cellAsString + " enum error", false);
							}
							if (stage != YotogiOld.Stage.MAX && !enabled_stage_dic.ContainsKey(stage))
							{
								enabled_stage_dic.Add(stage, cellAsString2);
							}
						}
					}
				}
			}
		};
		action("yotogi_stage_list");
		for (int i = 0; i < GameUty.PathListOld.Count; i++)
		{
			action("yotogi_stage_list_" + GameUty.PathListOld[i]);
		}
		HashSet<int> enabled_vr_stage_set = new HashSet<int>();
		CsvCommonIdManager.ReadEnabledIdList(GameUty.FileSystemOld, GameUty.PathListOld, "vr_yotogi_stage_enabled_list", ref enabled_vr_stage_set);
		Func<string, bool, Dictionary<YotogiOld.Stage, YotogiOld.StageData>> func = delegate(string file_name, bool is_vr_csv)
		{
			Dictionary<YotogiOld.Stage, YotogiOld.StageData> dictionary = new Dictionary<YotogiOld.Stage, YotogiOld.StageData>();
			file_name += ".nei";
			if (!GameUty.FileSystemOld.IsExistentFile(file_name))
			{
				return dictionary;
			}
			using (AFileBase afileBase = GameUty.FileSystemOld.FileOpen(file_name))
			{
				using (CsvParser csvParser = new CsvParser())
				{
					bool condition = csvParser.Open(afileBase);
					NDebug.Assert(condition, file_name + "\nopen failed.");
					for (int j = 1; j < csvParser.max_cell_y; j++)
					{
						if (csvParser.IsCellToExistData(0, j))
						{
							YotogiOld.StageData stageData = new YotogiOld.StageData(csvParser, j, is_vr_csv);
							bool flag;
							if (!is_vr_csv)
							{
								flag = enabled_stage_dic.ContainsKey(stageData.stage);
							}
							else
							{
								flag = enabled_vr_stage_set.Contains(stageData.sort_id);
							}
							if (flag)
							{
								if (!is_vr_csv)
								{
									stageData.SetPrefabName(enabled_stage_dic[stageData.stage]);
								}
								dictionary.Add(stageData.stage, stageData);
							}
						}
					}
				}
			}
			return dictionary;
		};
		YotogiOld.stage_data_list_ = func("yotogi_stage_setting", false);
		YotogiOld.vr_stage_data_list_ = func("vr_yotogi_stage_setting", true);
	}

	public static Skill.Old.Data GetSkillData(int skill_id)
	{
		Skill.Old.Data data = Skill.Old.Get(skill_id);
		NDebug.Assert(data != null, "夜伽スキルID[" + skill_id.ToString() + "]のスキルを見つける事ができませんでした");
		return data;
	}

	public static bool IsSkillData(int skill_id)
	{
		return Skill.Old.Contains(skill_id);
	}

	public static YotogiOld.VRSkillData GetVRSkillData(int id)
	{
		foreach (YotogiOld.VRSkillData vrskillData in YotogiOld.vr_skill_data_dic_)
		{
			Skill.Old.Data skill = vrskillData.skill;
			if (skill.id == id)
			{
				return vrskillData;
			}
		}
		return null;
	}

	public static List<YotogiOld.VRSkillData> GetVRSkillDataList(YotogiOld.Stage stage, int spot_no)
	{
		if (spot_no < 0)
		{
			return null;
		}
		List<YotogiOld.VRSkillData> list = new List<YotogiOld.VRSkillData>();
		foreach (YotogiOld.VRSkillData vrskillData in YotogiOld.vr_skill_data_dic_)
		{
			if (vrskillData.stage_data_dic.ContainsKey(stage) && vrskillData.stage_data_dic[stage].enabled_stage && spot_no < vrskillData.stage_data_dic[stage].enabled_spot.Length && vrskillData.stage_data_dic[stage].enabled_spot[spot_no])
			{
				list.Add(vrskillData);
			}
		}
		return list;
	}

	public static SortedDictionary<int, Skill.Old.Data> GetCategorySkillDataList(YotogiOld.Category category)
	{
		return Skill.Old.skill_data_list[(int)category];
	}

	public static List<KeyValuePair<YotogiOld.StageData, bool>> GetPlayableStageList(int grade_id, Dictionary<string, int> check_flag_dic)
	{
		List<KeyValuePair<YotogiOld.StageData, bool>> list = new List<KeyValuePair<YotogiOld.StageData, bool>>();
		for (int i = 0; i < 28; i++)
		{
			YotogiOld.Stage key = (YotogiOld.Stage)i;
			if (YotogiOld.stage_data_list_.ContainsKey(key))
			{
				bool value;
				if (string.IsNullOrEmpty(YotogiOld.stage_data_list_[key].need_flag))
				{
					value = (YotogiOld.stage_data_list_[key].need_grade <= grade_id);
				}
				else
				{
					value = (check_flag_dic == null || (check_flag_dic.Count > 0 && check_flag_dic.ContainsKey(YotogiOld.stage_data_list_[key].need_flag) && 1 <= check_flag_dic[YotogiOld.stage_data_list_[key].need_flag]));
				}
				list.Add(new KeyValuePair<YotogiOld.StageData, bool>(YotogiOld.stage_data_list_[key], value));
			}
		}
		list.Sort((KeyValuePair<YotogiOld.StageData, bool> a, KeyValuePair<YotogiOld.StageData, bool> b) => a.Key.sort_id - b.Key.sort_id);
		return list;
	}

	public static YotogiOld.StageData GetStageData(string bg_prefab_name)
	{
		YotogiOld.StageData result = null;
		foreach (KeyValuePair<YotogiOld.Stage, YotogiOld.StageData> keyValuePair in YotogiOld.stage_data_list_)
		{
			if (keyValuePair.Value.prefab_name == bg_prefab_name || keyValuePair.Value.prefab_name_night == bg_prefab_name)
			{
				result = keyValuePair.Value;
				break;
			}
		}
		return result;
	}

	public static SortedDictionary<int, Skill.Old.Data>[] skill_data_list
	{
		get
		{
			return Skill.Old.skill_data_list;
		}
	}

	public static Dictionary<YotogiOld.Stage, YotogiOld.StageData> stage_data_list
	{
		get
		{
			return YotogiOld.stage_data_list_;
		}
	}

	public static List<YotogiOld.VRSkillData> vr_skill_data_dic
	{
		get
		{
			return YotogiOld.vr_skill_data_dic_;
		}
	}

	public static Dictionary<YotogiOld.Stage, YotogiOld.StageData> vr_stage_data_list
	{
		get
		{
			return YotogiOld.vr_stage_data_list_;
		}
	}

	public const int kSkillMaxSlot = 7;

	private static List<YotogiOld.VRSkillData> vr_skill_data_dic_;

	private static Dictionary<YotogiOld.Stage, YotogiOld.StageData> stage_data_list_;

	private static Dictionary<YotogiOld.Stage, YotogiOld.StageData> vr_stage_data_list_;

	public enum SexualType
	{
		Null,
		Mouth,
		Throat,
		Nipple,
		Front,
		Back,
		Curi
	}

	public enum ExcitementStatus
	{
		Minus,
		Small,
		Medium,
		Large
	}

	public enum SkillCommandType
	{
		挿入,
		継続,
		単発,
		単発_挿入,
		絶頂,
		止める
	}

	public enum RCType
	{
		RCNull,
		RC_1,
		RC0,
		RC1,
		RC2
	}

	public enum RRCType
	{
		RRCNull,
		RRC_4,
		RRC_3,
		RRC_2,
		RRC_1,
		RRC1,
		RRC2,
		RRC3,
		RRC4,
		RRC5,
		RRC6,
		RRC7,
		RRC8,
		RRC9,
		RRC10
	}

	public enum RRType
	{
		RRNull,
		RR_2,
		RR_1,
		RR1,
		RR2,
		RR3,
		RR4,
		RR5,
		RR6
	}

	public enum Category
	{
		淫欲,
		変態,
		奉仕,
		M性,
		交換,
		乱交,
		詰られ,
		ハ\u30FCレム,
		百合,
		MAX
	}

	public enum Stage
	{
		サロン,
		主人公の部屋,
		プレイル\u30FCム,
		プ\u30FCル,
		初代バスル\u30FCム,
		ＳＭル\u30FCム,
		プレイル\u30FCム2,
		中庭,
		大浴場,
		メイド部屋,
		花魁風プレイル\u30FCム,
		新ペントハウス,
		屋外,
		地下室,
		ロッカ\u30FCル\u30FCム,
		トイレ,
		電車,
		教室,
		ハネム\u30FCンル\u30FCム,
		南国,
		和風旅館,
		コスプレ会場,
		プライベ\u30FCトル\u30FCム,
		海,
		畑,
		ヴィラ,
		ベットル\u30FCム,
		露天風呂,
		MAX
	}

	public class StageData
	{
		public StageData(CsvParser csv, int csv_y, bool vr_stage)
		{
			int cell_x = 0;
			if (!vr_stage)
			{
				string cellAsString = csv.GetCellAsString(cell_x++, csv_y);
				bool flag = true;
				foreach (char c in cellAsString)
				{
					if ((c < '0' || c > '9') && c != ' ' && c != '-')
					{
						flag = false;
						break;
					}
				}
				if (flag)
				{
					this.need_flag = string.Empty;
					this.need_grade = int.Parse(cellAsString);
				}
				else
				{
					this.need_flag = cellAsString;
					this.need_grade = 0;
				}
				this.sort_id = csv.GetCellAsInteger(cell_x++, csv_y);
				this.draw_name = csv.GetCellAsString(cell_x++, csv_y);
				this.stage_name = csv.GetCellAsString(cell_x++, csv_y);
				string text2 = this.stage_name;
				try
				{
					this.stage = (YotogiOld.Stage)Enum.Parse(typeof(YotogiOld.Stage), text2);
				}
				catch (ArgumentException)
				{
					NDebug.Assert("Yotogi.Stage\nenum parse error.[" + text2 + "]", false);
				}
				this.thumbnail_name = csv.GetCellAsString(cell_x++, csv_y);
				this.bgm_file = csv.GetCellAsString(cell_x++, csv_y) + ".ogg";
				string cellAsString2 = csv.GetCellAsString(cell_x++, csv_y);
				string[] array = cellAsString2.Split(new char[]
				{
					','
				});
				NDebug.Assert(array.Length == 6, "ステージカメラ設定が不正です\nLine : " + csv_y.ToString());
				this.camera_data.stage_select_camera_center = new Vector3(float.Parse(array[0]), float.Parse(array[1]), float.Parse(array[2]));
				this.camera_data.stage_select_camera_radius = float.Parse(array[3]);
				this.camera_data.stage_select_camera_rotate = new Vector2(float.Parse(array[4]), float.Parse(array[5]));
				cellAsString2 = csv.GetCellAsString(cell_x++, csv_y);
				array = cellAsString2.Split(new char[]
				{
					','
				});
				NDebug.Assert(array.Length == 6, "カス子位置情報が不正です\nLine : " + csv_y.ToString());
				this.camera_data.skill_select_chara_pos = new Vector3(float.Parse(array[0]), float.Parse(array[1]), float.Parse(array[2]));
				this.camera_data.skill_select_chara_rotate = new Vector3(float.Parse(array[3]), float.Parse(array[4]), float.Parse(array[5]));
				cellAsString2 = csv.GetCellAsString(cell_x++, csv_y);
				array = cellAsString2.Split(new char[]
				{
					','
				});
				NDebug.Assert(array.Length == 2, "スキル選択時カメラデータが不正です\nLine : " + csv_y.ToString());
				this.camera_data.skill_select_camera_rotate = new Vector2(float.Parse(array[0]), float.Parse(array[1]));
				string cellAsString3 = csv.GetCellAsString(cell_x++, csv_y);
				string[] array2 = cellAsString3.Split(new char[]
				{
					','
				});
				NDebug.Assert(array2.Length == 4, "スキル選択時ライトデータが不正です\nLine : " + csv_y.ToString());
				this.camera_data.skill_select_light_pos = new Vector3(float.Parse(array2[0]), float.Parse(array2[1]), float.Parse(array2[2]));
				this.camera_data.skill_select_light_intensity = float.Parse(array2[3]);
			}
			else
			{
				this.sort_id = csv.GetCellAsInteger(cell_x++, csv_y);
				this.draw_name = csv.GetCellAsString(cell_x++, csv_y);
				this.stage_name = csv.GetCellAsString(cell_x++, csv_y);
				string text3 = this.stage_name;
				try
				{
					this.stage = (YotogiOld.Stage)Enum.Parse(typeof(YotogiOld.Stage), text3);
				}
				catch (ArgumentException)
				{
					NDebug.Assert("Yotogi.Stage\nenum parse error.[" + text3 + "]", false);
				}
				string[] array3 = csv.GetCellAsString(cell_x++, csv_y).Split(new char[]
				{
					','
				});
				this.prefab_name_ = array3[0];
				this.prefab_name_night_ = array3[1];
				array3 = csv.GetCellAsString(cell_x++, csv_y).Split(new char[]
				{
					','
				});
				this.bgm_file = array3[0];
				this.bgm_file_night = array3[0];
				array3 = csv.GetCellAsString(cell_x++, csv_y).Split(new char[]
				{
					','
				});
				this.thumbnail_name = array3[0];
				this.thumbnail_name_night = array3[1];
				List<string[]> list = new List<string[]>();
				while (csv.IsCellToExistData(cell_x, csv_y))
				{
					list.Add(csv.GetCellAsString(cell_x++, csv_y).Split(new char[]
					{
						','
					}));
				}
				this.spot_data = new YotogiOld.StageData.SpotData[list.Count];
				for (int j = 0; j < list.Count; j++)
				{
					YotogiOld.StageData.SpotData spotData = default(YotogiOld.StageData.SpotData);
					spotData.name = list[j][0];
					spotData.thumbnail_name_daytime = list[j][1];
					spotData.thumbnail_name_night = list[j][2];
					this.spot_data[j] = spotData;
				}
			}
		}

		public void SetPrefabName(string set_prefab_name)
		{
			this.prefab_name_ = set_prefab_name;
		}

		public string prefab_name
		{
			get
			{
				return this.prefab_name_;
			}
		}

		public string prefab_name_night
		{
			get
			{
				return this.prefab_name_night_;
			}
		}

		public readonly int sort_id;

		public readonly string draw_name;

		public readonly YotogiOld.Stage stage;

		public readonly string stage_name;

		public readonly int need_grade;

		public readonly string need_flag;

		public readonly string thumbnail_name;

		public readonly string thumbnail_name_night;

		public readonly string bgm_file;

		public readonly string bgm_file_night;

		public readonly YotogiOld.StageData.CameraData camera_data = default(YotogiOld.StageData.CameraData);

		public readonly YotogiOld.StageData.SpotData[] spot_data;

		private string prefab_name_;

		private string prefab_name_night_;

		public struct CameraData
		{
			public Vector3 stage_select_camera_center;

			public Vector2 stage_select_camera_rotate;

			public float stage_select_camera_radius;

			public Vector3 skill_select_chara_pos;

			public Vector3 skill_select_chara_rotate;

			public Vector2 skill_select_camera_rotate;

			public Vector3 skill_select_light_pos;

			public float skill_select_light_intensity;
		}

		public struct SpotData
		{
			public string name;

			public string thumbnail_name_daytime;

			public string thumbnail_name_night;
		}
	}

	public class VRSkillData
	{
		public Skill.Old.Data skill;

		public Dictionary<YotogiOld.Stage, YotogiOld.VRSkillData.StageData> stage_data_dic;

		public class StageData
		{
			public YotogiOld.Stage stage;

			public string ft_file_name;

			public bool[] enabled_spot;

			public bool enabled_stage;
		}
	}

	public struct SkillDataPair
	{
		public static YotogiOld.SkillDataPair Create(Maid maid, int skill_id)
		{
			YotogiOld.SkillDataPair result;
			result.maid = maid;
			result.base_data = YotogiOld.GetSkillData(skill_id);
			result.param = maid.status.yotogiSkill.Get(skill_id);
			return result;
		}

		public static YotogiOld.SkillDataPair CreateBaseDataOnly(Maid maid, Skill.Old.Data base_data)
		{
			YotogiOld.SkillDataPair result;
			result.maid = maid;
			result.base_data = base_data;
			result.param = null;
			return result;
		}

		public static YotogiOld.SkillDataPair Create(Maid maid, Skill.Old.Data base_data)
		{
			YotogiOld.SkillDataPair result;
			result.maid = maid;
			result.base_data = base_data;
			result.param = maid.status.yotogiSkill.Get(base_data.id);
			return result;
		}

		public static YotogiOld.SkillDataPair Create(Maid maid, YotogiSkillData param)
		{
			YotogiOld.SkillDataPair result;
			result.maid = maid;
			result.base_data = YotogiOld.GetSkillData(param.id);
			result.param = param;
			return result;
		}

		public Skill.Old.Data base_data;

		public YotogiSkillData param;

		public Maid maid;
	}
}
