PlayData.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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 < 6; 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. string cellAsString8 = csv.GetCellAsString(cell_x++, i);
  290. string[] array3 = null;
  291. if (!string.IsNullOrEmpty(cellAsString8))
  292. {
  293. array3 = cellAsString8.Split(new char[]
  294. {
  295. ','
  296. });
  297. for (int m = 0; m < array3.Length; m++)
  298. {
  299. array3[m] = array3[m].Trim();
  300. }
  301. }
  302. this.strEnablePersonalArray = array3;
  303. Dictionary<ManDataType, bool> dictionary = new Dictionary<ManDataType, bool>();
  304. int num = Enum.GetNames(typeof(ManDataType)).Length;
  305. for (int n = 0; n < num; n++)
  306. {
  307. string cellAsString9 = csv.GetCellAsString(cell_x, 0);
  308. ManDataType manType = ManData.GetData(cellAsString9).manType;
  309. dictionary.Add(manType, csv.GetCellAsString(cell_x++, i) == "○");
  310. }
  311. this.enableManTypeDic = new ReadOnlyDictionary<ManDataType, bool>(dictionary);
  312. }
  313. }
  314. }
  315. public bool IsPassed
  316. {
  317. get
  318. {
  319. string text = Enum.GetName(typeof(SystemDataType), SystemDataType.プレイ実行\uFF3F);
  320. text += this.ID.ToString();
  321. bool flag;
  322. return GameMain.Instance.KasizukiMgr.TryGetSystemData<bool>(text, out flag) && flag;
  323. }
  324. set
  325. {
  326. string text = Enum.GetName(typeof(SystemDataType), SystemDataType.プレイ実行\uFF3F);
  327. text += this.ID.ToString();
  328. GameMain.Instance.KasizukiMgr.SetSystemData<bool>(text, value, false);
  329. }
  330. }
  331. public string GetScenarioFileNameReplace(Maid maid)
  332. {
  333. return ScriptManager.ReplacePersonal(maid, this.strScenarioFileName);
  334. }
  335. public bool IsCorrectMaid(Maid maid, ManDataType manType)
  336. {
  337. return this.IsCorrectLikability(maid, manType) && this.IsCorrectWorkCount(maid) && this.IsCorrectParameter(maid) && this.IsCorrectSkill(maid) && this.IsCorrectSeikeiken(maid) && this.IsCorrectRelation(maid) && this.IsCorrectPersonal(maid);
  338. }
  339. public bool IsCorrectParameter(Maid maid)
  340. {
  341. if (this.strNeedParameterArray == null)
  342. {
  343. return true;
  344. }
  345. bool flag = true;
  346. int num = 0;
  347. while (num < this.strNeedParameterArray.Length && flag)
  348. {
  349. try
  350. {
  351. string name = this.strNeedParameterArray[num++];
  352. string s = this.strNeedParameterArray[num++];
  353. int maidStatus = maid.GetMaidStatus(name);
  354. flag &= (maidStatus >= int.Parse(s));
  355. }
  356. catch (Exception ex)
  357. {
  358. NDebug.Assert(ex.ToString(), false);
  359. Debug.LogError(ex);
  360. }
  361. }
  362. return flag;
  363. }
  364. public bool IsCorrectSkill(Maid maid)
  365. {
  366. if (this.strNeedSkillArray == null)
  367. {
  368. return true;
  369. }
  370. bool flag = true;
  371. int num = 0;
  372. while (num < this.strNeedSkillArray.Length && flag)
  373. {
  374. try
  375. {
  376. flag &= maid.status.yotogiSkill.Contains(int.Parse(this.strNeedSkillArray[num]));
  377. }
  378. catch (Exception ex)
  379. {
  380. NDebug.Assert(ex.ToString(), false);
  381. Debug.LogError(ex);
  382. }
  383. num++;
  384. }
  385. return flag;
  386. }
  387. public bool IsCorrectLikability(Maid maid, ManDataType manType)
  388. {
  389. int maidLikability = GameMain.Instance.KasizukiMgr.GetMaidLikability(maid, manType);
  390. return this.needLikability <= maidLikability;
  391. }
  392. public bool IsCorrectWorkCount(Maid maid)
  393. {
  394. if (this.workCountEnableDic == null || this.workCountEnableDic.Count <= 0)
  395. {
  396. return true;
  397. }
  398. int maidData = GameMain.Instance.KasizukiMgr.GetMaidData<int>(maid, MaidDataType.仕事回数, true);
  399. string workCountName = WorkCountReplace.GetWorkCountName(maidData);
  400. return this.workCountEnableDic.ContainsKey(workCountName);
  401. }
  402. public bool IsCorrectSeikeiken(Maid maid)
  403. {
  404. Seikeiken seikeiken = maid.status.seikeiken;
  405. return this.seikeikenEnableDic.ContainsKey(seikeiken);
  406. }
  407. public bool IsCorrectRelation(Maid maid)
  408. {
  409. if (this.relationEnableDic == null || this.relationEnableDic.Count <= 0)
  410. {
  411. return true;
  412. }
  413. Relation relation = maid.status.relation;
  414. return this.relationEnableDic.ContainsKey(relation);
  415. }
  416. public bool IsCorrectPersonal(Maid maid)
  417. {
  418. if (this.strEnablePersonalArray == null || this.strEnablePersonalArray.Length <= 0)
  419. {
  420. return true;
  421. }
  422. for (int i = 0; i < this.strEnablePersonalArray.Length; i++)
  423. {
  424. if (maid.status.personal.uniqueName == this.strEnablePersonalArray[i])
  425. {
  426. return true;
  427. }
  428. }
  429. return false;
  430. }
  431. public List<Maid> GetFilteringPlayDataMaidArray(ManDataType manType)
  432. {
  433. CharacterMgr characterMgr = GameMain.Instance.CharacterMgr;
  434. List<Maid> list = new List<Maid>();
  435. for (int i = 0; i < characterMgr.GetStockMaidCount(); i++)
  436. {
  437. Maid stockMaid = characterMgr.GetStockMaid(i);
  438. if (!(stockMaid == null))
  439. {
  440. if (stockMaid.status.heroineType != HeroineType.Transfer)
  441. {
  442. if (stockMaid.status.heroineType != HeroineType.Sub)
  443. {
  444. if (this.IsCorrectMaid(stockMaid, manType))
  445. {
  446. list.Add(stockMaid);
  447. }
  448. }
  449. }
  450. }
  451. }
  452. return list;
  453. }
  454. private void SplitParameterBlock(string strParameterBlock, out string[] output)
  455. {
  456. if (string.IsNullOrEmpty(strParameterBlock))
  457. {
  458. output = null;
  459. return;
  460. }
  461. string[] array = strParameterBlock.Split(new char[]
  462. {
  463. ','
  464. });
  465. output = new string[array.Length * 2];
  466. for (int i = 0; i < array.Length; i++)
  467. {
  468. string[] array2 = array[i].Split(new char[]
  469. {
  470. '|'
  471. });
  472. NDebug.Assert(array2.Length == 2, string.Format("kasizukiDataTable.PlayData\n表データの「必要パラメータ条件式」の数が不正です\n{0}", array[i]));
  473. output[i * 2] = array2[0];
  474. output[i * 2 + 1] = array2[1];
  475. }
  476. }
  477. private const int CONDITION_COUNT = 6;
  478. public readonly int ID;
  479. public readonly int roomID;
  480. public readonly string strScenarioFileName;
  481. public readonly string drawName;
  482. public readonly string strDescription;
  483. public readonly string[] strConditionArray;
  484. public readonly Dictionary<Seikeiken, bool> seikeikenEnableDic;
  485. public readonly string[] strNeedParameterArray;
  486. public readonly string[] strNeedSkillArray;
  487. public readonly int needLikability;
  488. public readonly Dictionary<string, bool> workCountEnableDic;
  489. public readonly Dictionary<Relation, bool> relationEnableDic;
  490. public readonly string[] strEnablePersonalArray;
  491. public readonly ReadOnlyDictionary<ManDataType, bool> enableManTypeDic;
  492. }
  493. }
  494. }