PlayData.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. using System;
  2. using System.Collections.Generic;
  3. using MaidStatus;
  4. using UnityEngine;
  5. using wf;
  6. namespace Kasizuki
  7. {
  8. public static class PlayData
  9. {
  10. private static int GetMaidStatus(this Maid maid, string name)
  11. {
  12. switch (name)
  13. {
  14. case "接待":
  15. return maid.status.reception;
  16. case "お世話":
  17. return maid.status.care;
  18. case "可憐":
  19. return maid.status.lovely;
  20. case "気品":
  21. return maid.status.elegance;
  22. case "魅惑":
  23. return maid.status.charm;
  24. case "料理":
  25. return maid.status.cooking;
  26. case "ボーカル":
  27. return maid.status.vocal;
  28. case "ダンス":
  29. return maid.status.dance;
  30. case "アピールポイント":
  31. return maid.status.appealPoint;
  32. case "淫欲":
  33. return maid.status.inyoku;
  34. case "M性":
  35. return maid.status.mvalue;
  36. case "変態":
  37. return maid.status.hentai;
  38. case "奉仕":
  39. return maid.status.housi;
  40. case "指導":
  41. return maid.status.teachRate;
  42. case "経験人数":
  43. return maid.status.sexPlayNumberOfPeople;
  44. case "人気ランク":
  45. return maid.status.popularRank;
  46. case "評価":
  47. return maid.status.evaluation;
  48. }
  49. NDebug.Assert(string.Format("メイドパラメータ名「{0}」は未定義です", name), false);
  50. return -1;
  51. }
  52. public static PlayData.Data GetOptimalConditionData(Maid maid, RoomData.Data roomData, ManDataType manType)
  53. {
  54. PlayData.Data result;
  55. try
  56. {
  57. NDebug.Assert(maid != null, "メイドにnullが指定されました");
  58. NDebug.Assert(roomData != null, "部屋情報にnullが指定されました");
  59. NDebug.Assert(Enum.IsDefined(typeof(ManDataType), manType), "男種類に不正な値が入りました");
  60. if (!roomData.enableManTypeDic[manType])
  61. {
  62. result = null;
  63. }
  64. else
  65. {
  66. List<PlayData.Data> playDatas = roomData.GetPlayDatas();
  67. List<PlayData.Data> list = new List<PlayData.Data>();
  68. foreach (PlayData.Data data in playDatas)
  69. {
  70. if (data.enableManTypeDic[manType])
  71. {
  72. if (data.IsCorrectMaid(maid, manType))
  73. {
  74. list.Add(data);
  75. }
  76. }
  77. }
  78. PlayData.Data data2 = null;
  79. for (int i = 0; i < list.Count; i++)
  80. {
  81. if (data2 == null)
  82. {
  83. data2 = list[i];
  84. }
  85. else if (data2.needLikability < list[i].needLikability)
  86. {
  87. data2 = list[i];
  88. }
  89. }
  90. NDebug.Warning(data2 != null, "条件を満たすプレイが一つもない");
  91. result = data2;
  92. }
  93. }
  94. catch (Exception ex)
  95. {
  96. NDebug.Assert(ex.ToString(), false);
  97. Debug.LogError(ex);
  98. result = null;
  99. }
  100. return result;
  101. }
  102. public static int Count
  103. {
  104. get
  105. {
  106. PlayData.CreateData();
  107. return PlayData.commonIdManager.idMap.Count;
  108. }
  109. }
  110. public static bool Contains(string name)
  111. {
  112. return PlayData.commonIdManager.nameMap.ContainsKey(name);
  113. }
  114. public static bool Contains(int id)
  115. {
  116. return PlayData.commonIdManager.idMap.ContainsKey(id);
  117. }
  118. public static int uniqueNameToId(string uniqueName)
  119. {
  120. PlayData.CreateData();
  121. NDebug.Assert(PlayData.commonIdManager.nameMap.ContainsKey(uniqueName), "傅き.プレイ情報\nユニーク名[" + uniqueName + "]をIDに変換できませんでした");
  122. return PlayData.commonIdManager.nameMap[uniqueName];
  123. }
  124. public static string IdToUniqueName(int id)
  125. {
  126. PlayData.CreateData();
  127. NDebug.Assert(PlayData.commonIdManager.idMap.ContainsKey(id), "傅き.プレイ情報\nID[" + id + "]をユニーク名に変換できませんでした");
  128. return PlayData.commonIdManager.idMap[id].Key;
  129. }
  130. public static PlayData.Data GetData(int id)
  131. {
  132. PlayData.CreateData();
  133. NDebug.Assert(PlayData.basicDatas.ContainsKey(id), "傅き.プレイ情報\nID[" + id + "]のデータは存在しません");
  134. return PlayData.basicDatas[id];
  135. }
  136. public static PlayData.Data GetData(string uniqueName)
  137. {
  138. return PlayData.GetData(PlayData.uniqueNameToId(uniqueName));
  139. }
  140. public static bool IsEnabled(string uniqueName)
  141. {
  142. PlayData.CreateData();
  143. return PlayData.commonIdManager.enabledIdList.Contains(PlayData.uniqueNameToId(uniqueName));
  144. }
  145. public static bool IsEnabled(int id)
  146. {
  147. PlayData.CreateData();
  148. return PlayData.commonIdManager.enabledIdList.Contains(id);
  149. }
  150. public static List<PlayData.Data> GetAllDatas(bool onlyEnabled)
  151. {
  152. PlayData.CreateData();
  153. List<PlayData.Data> list = new List<PlayData.Data>();
  154. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in PlayData.commonIdManager.idMap)
  155. {
  156. if (!onlyEnabled || PlayData.commonIdManager.enabledIdList.Contains(keyValuePair.Key))
  157. {
  158. list.Add(PlayData.basicDatas[keyValuePair.Key]);
  159. }
  160. }
  161. return list;
  162. }
  163. public static List<PlayData.Data> GetDatas(Func<PlayData.Data, bool> customCheckFunction)
  164. {
  165. PlayData.CreateData();
  166. List<PlayData.Data> list = new List<PlayData.Data>();
  167. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in PlayData.commonIdManager.idMap)
  168. {
  169. PlayData.Data data = PlayData.basicDatas[keyValuePair.Key];
  170. if (customCheckFunction(data))
  171. {
  172. list.Add(data);
  173. }
  174. }
  175. return list;
  176. }
  177. public static void CreateData()
  178. {
  179. if (PlayData.commonIdManager != null)
  180. {
  181. return;
  182. }
  183. PlayData.commonIdManager = new CsvCommonIdManager("kasizuki_play", "傅き.プレイ情報", CsvCommonIdManager.Type.IdOnly, null);
  184. PlayData.basicDatas = new Dictionary<int, PlayData.Data>();
  185. string[] array = new string[]
  186. {
  187. "list"
  188. };
  189. KeyValuePair<AFileBase, CsvParser>[] array2 = new KeyValuePair<AFileBase, CsvParser>[array.Length];
  190. for (int i = 0; i < array2.Length; i++)
  191. {
  192. string text = "kasizuki_play_" + array[i] + ".nei";
  193. AFileBase afileBase = GameUty.FileSystem.FileOpen(text);
  194. CsvParser csvParser = new CsvParser();
  195. bool condition = csvParser.Open(afileBase);
  196. NDebug.Assert(condition, text + "\nopen failed.");
  197. array2[i] = new KeyValuePair<AFileBase, CsvParser>(afileBase, csvParser);
  198. }
  199. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in PlayData.commonIdManager.idMap)
  200. {
  201. int key = keyValuePair.Key;
  202. PlayData.Data value = new PlayData.Data(key, array2[0].Value);
  203. PlayData.basicDatas.Add(key, value);
  204. }
  205. foreach (KeyValuePair<AFileBase, CsvParser> keyValuePair2 in array2)
  206. {
  207. keyValuePair2.Value.Dispose();
  208. keyValuePair2.Key.Dispose();
  209. }
  210. }
  211. private const string csvTopCommonName = "kasizuki_play";
  212. private const string typeNameForErrorLog = "傅き.プレイ情報";
  213. private static CsvCommonIdManager commonIdManager;
  214. private static Dictionary<int, PlayData.Data> basicDatas;
  215. public class Data
  216. {
  217. public Data(int uniqueID, CsvParser csv)
  218. {
  219. for (int i = 1; i < csv.max_cell_y; i++)
  220. {
  221. if (csv.IsCellToExistData(0, i) && csv.GetCellAsInteger(0, i) == uniqueID)
  222. {
  223. int cell_x = 1;
  224. this.ID = uniqueID;
  225. string cellAsString = csv.GetCellAsString(cell_x++, i);
  226. this.strScenarioFileName = csv.GetCellAsString(cell_x++, i);
  227. this.drawName = csv.GetCellAsString(cell_x++, i);
  228. this.strDescription = csv.GetCellAsString(cell_x++, i);
  229. List<string> list = new List<string>();
  230. for (int j = 0; j < 5; j++)
  231. {
  232. string cellAsString2 = csv.GetCellAsString(cell_x++, i);
  233. if (!string.IsNullOrEmpty(cellAsString2))
  234. {
  235. list.Add(cellAsString2);
  236. }
  237. }
  238. this.strConditionArray = list.ToArray();
  239. string cellAsString3 = csv.GetCellAsString(cell_x++, i);
  240. this.seikeikenEnableDic = new Dictionary<Seikeiken, bool>();
  241. Seikeiken[] array = new Seikeiken[]
  242. {
  243. Seikeiken.No_No,
  244. Seikeiken.Yes_No,
  245. Seikeiken.No_Yes,
  246. Seikeiken.Yes_Yes
  247. };
  248. for (int k = 0; k < array.Length; k++)
  249. {
  250. string cellAsString4 = csv.GetCellAsString(cell_x++, i);
  251. if (cellAsString4 == "〇" || cellAsString4 == "○")
  252. {
  253. this.seikeikenEnableDic.Add(array[k], true);
  254. }
  255. }
  256. string cellAsString5 = csv.GetCellAsString(cell_x++, i);
  257. this.needLikability = csv.GetCellAsInteger(cell_x++, i);
  258. this.workCountEnableDic = new Dictionary<string, bool>();
  259. SortedDictionary<int, string> dic = WorkCountReplace.GetDic();
  260. foreach (string key in dic.Values)
  261. {
  262. string cellAsString6 = csv.GetCellAsString(cell_x++, i);
  263. if (cellAsString6 == "〇" || cellAsString6 == "○")
  264. {
  265. this.workCountEnableDic.Add(key, true);
  266. }
  267. }
  268. this.relationEnableDic = new Dictionary<Relation, bool>();
  269. Relation[] array2 = new Relation[]
  270. {
  271. Relation.Contact,
  272. Relation.Trust,
  273. Relation.Lover
  274. };
  275. for (int l = 0; l < array2.Length; l++)
  276. {
  277. string cellAsString7 = csv.GetCellAsString(cell_x++, i);
  278. if (cellAsString7 == "〇" || cellAsString7 == "○")
  279. {
  280. this.relationEnableDic.Add(array2[l], true);
  281. }
  282. }
  283. this.SplitParameterBlock(cellAsString3, out this.strNeedParameterArray);
  284. this.strNeedSkillArray = (string.IsNullOrEmpty(cellAsString5) ? null : cellAsString5.Split(new char[]
  285. {
  286. ','
  287. }));
  288. this.roomID = RoomData.GetData(cellAsString).ID;
  289. Dictionary<ManDataType, bool> dictionary = new Dictionary<ManDataType, bool>();
  290. int num = Enum.GetNames(typeof(ManDataType)).Length;
  291. for (int m = 0; m < num; m++)
  292. {
  293. string cellAsString8 = csv.GetCellAsString(cell_x, 0);
  294. ManDataType manType = ManData.GetData(cellAsString8).manType;
  295. dictionary.Add(manType, csv.GetCellAsString(cell_x++, i) == "○");
  296. }
  297. this.enableManTypeDic = new ReadOnlyDictionary<ManDataType, bool>(dictionary);
  298. }
  299. }
  300. }
  301. public bool IsPassed
  302. {
  303. get
  304. {
  305. string text = Enum.GetName(typeof(SystemDataType), SystemDataType.プレイ実行\uFF3F);
  306. text += this.ID.ToString();
  307. bool flag;
  308. return GameMain.Instance.KasizukiMgr.TryGetSystemData<bool>(text, out flag) && flag;
  309. }
  310. set
  311. {
  312. string text = Enum.GetName(typeof(SystemDataType), SystemDataType.プレイ実行\uFF3F);
  313. text += this.ID.ToString();
  314. GameMain.Instance.KasizukiMgr.SetSystemData<bool>(text, value, false);
  315. }
  316. }
  317. public string GetScenarioFileNameReplace(Maid maid)
  318. {
  319. return ScriptManager.ReplacePersonal(maid, this.strScenarioFileName);
  320. }
  321. public bool IsCorrectMaid(Maid maid, ManDataType manType)
  322. {
  323. return this.IsCorrectLikability(maid, manType) && this.IsCorrectWorkCount(maid) && this.IsCorrectParameter(maid) && this.IsCorrectSkill(maid) && this.IsCorrectSeikeiken(maid) && this.IsCorrectRelation(maid);
  324. }
  325. public bool IsCorrectParameter(Maid maid)
  326. {
  327. if (this.strNeedParameterArray == null)
  328. {
  329. return true;
  330. }
  331. bool flag = true;
  332. int num = 0;
  333. while (num < this.strNeedParameterArray.Length && flag)
  334. {
  335. try
  336. {
  337. string name = this.strNeedParameterArray[num++];
  338. string s = this.strNeedParameterArray[num++];
  339. int maidStatus = maid.GetMaidStatus(name);
  340. flag &= (maidStatus >= int.Parse(s));
  341. }
  342. catch (Exception ex)
  343. {
  344. NDebug.Assert(ex.ToString(), false);
  345. Debug.LogError(ex);
  346. }
  347. }
  348. return flag;
  349. }
  350. public bool IsCorrectSkill(Maid maid)
  351. {
  352. if (this.strNeedSkillArray == null)
  353. {
  354. return true;
  355. }
  356. bool flag = true;
  357. int num = 0;
  358. while (num < this.strNeedSkillArray.Length && flag)
  359. {
  360. try
  361. {
  362. flag &= maid.status.yotogiSkill.Contains(int.Parse(this.strNeedSkillArray[num]));
  363. }
  364. catch (Exception ex)
  365. {
  366. NDebug.Assert(ex.ToString(), false);
  367. Debug.LogError(ex);
  368. }
  369. num++;
  370. }
  371. return flag;
  372. }
  373. public bool IsCorrectLikability(Maid maid, ManDataType manType)
  374. {
  375. int maidLikability = GameMain.Instance.KasizukiMgr.GetMaidLikability(maid, manType);
  376. return this.needLikability <= maidLikability;
  377. }
  378. public bool IsCorrectWorkCount(Maid maid)
  379. {
  380. if (this.workCountEnableDic == null || this.workCountEnableDic.Count <= 0)
  381. {
  382. return true;
  383. }
  384. int maidData = GameMain.Instance.KasizukiMgr.GetMaidData<int>(maid, MaidDataType.仕事回数, true);
  385. string workCountName = WorkCountReplace.GetWorkCountName(maidData);
  386. return this.workCountEnableDic.ContainsKey(workCountName);
  387. }
  388. public bool IsCorrectSeikeiken(Maid maid)
  389. {
  390. Seikeiken seikeiken = maid.status.seikeiken;
  391. return this.seikeikenEnableDic.ContainsKey(seikeiken);
  392. }
  393. public bool IsCorrectRelation(Maid maid)
  394. {
  395. if (this.relationEnableDic == null || this.relationEnableDic.Count <= 0)
  396. {
  397. return true;
  398. }
  399. Relation relation = maid.status.relation;
  400. return this.relationEnableDic.ContainsKey(relation);
  401. }
  402. public List<Maid> GetFilteringPlayDataMaidArray(ManDataType manType)
  403. {
  404. CharacterMgr characterMgr = GameMain.Instance.CharacterMgr;
  405. List<Maid> list = new List<Maid>();
  406. for (int i = 0; i < characterMgr.GetStockMaidCount(); i++)
  407. {
  408. Maid stockMaid = characterMgr.GetStockMaid(i);
  409. if (!(stockMaid == null))
  410. {
  411. if (stockMaid.status.heroineType != HeroineType.Transfer)
  412. {
  413. if (stockMaid.status.heroineType != HeroineType.Sub)
  414. {
  415. if (this.IsCorrectMaid(stockMaid, manType))
  416. {
  417. list.Add(stockMaid);
  418. }
  419. }
  420. }
  421. }
  422. }
  423. return list;
  424. }
  425. private void SplitParameterBlock(string strParameterBlock, out string[] output)
  426. {
  427. if (string.IsNullOrEmpty(strParameterBlock))
  428. {
  429. output = null;
  430. return;
  431. }
  432. string[] array = strParameterBlock.Split(new char[]
  433. {
  434. ','
  435. });
  436. output = new string[array.Length * 2];
  437. for (int i = 0; i < array.Length; i++)
  438. {
  439. string[] array2 = array[i].Split(new char[]
  440. {
  441. '|'
  442. });
  443. NDebug.Assert(array2.Length == 2, string.Format("kasizukiDataTable.PlayData\n表データの「必要パラメータ条件式」の数が不正です\n{0}", array[i]));
  444. output[i * 2] = array2[0];
  445. output[i * 2 + 1] = array2[1];
  446. }
  447. }
  448. private const int CONDITION_COUNT = 5;
  449. public readonly int ID;
  450. public readonly int roomID;
  451. public readonly string strScenarioFileName;
  452. public readonly string drawName;
  453. public readonly string strDescription;
  454. public readonly string[] strConditionArray;
  455. public readonly Dictionary<Seikeiken, bool> seikeikenEnableDic;
  456. public readonly string[] strNeedParameterArray;
  457. public readonly string[] strNeedSkillArray;
  458. public readonly int needLikability;
  459. public readonly Dictionary<string, bool> workCountEnableDic;
  460. public readonly Dictionary<Relation, bool> relationEnableDic;
  461. public readonly ReadOnlyDictionary<ManDataType, bool> enableManTypeDic;
  462. }
  463. }
  464. }