CasinoShopItem.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using PlayerStatus;
  7. using UnityEngine;
  8. public class CasinoShopItem
  9. {
  10. public CasinoShopItem(CsvParser csv, int cy)
  11. {
  12. for (int i = 0; i < csv.max_cell_x; i++)
  13. {
  14. switch (i)
  15. {
  16. case 0:
  17. this.ID = csv.GetCellAsInteger(i, cy);
  18. break;
  19. case 1:
  20. this.Name = csv.GetCellAsString(i, cy);
  21. break;
  22. case 2:
  23. this.Price = csv.GetCellAsInteger(i, cy);
  24. break;
  25. case 3:
  26. this.MyCategory = ((!(csv.GetCellAsString(i, cy) == "衣装")) ? CasinoShopItem.Category.FacilityItem : CasinoShopItem.Category.Costume);
  27. break;
  28. case 4:
  29. {
  30. string text = csv.GetCellAsString(i, cy);
  31. if (text.IndexOf(".tex") < 0)
  32. {
  33. text += ".tex";
  34. }
  35. if (!GameUty.FileSystem.IsExistentFile(text))
  36. {
  37. Debug.LogError("アイコンファイル[" + text + "]が見つかりませんでした");
  38. }
  39. Texture2D texture2D = ImportCM.CreateTexture(text);
  40. this.Icon = Sprite.Create(texture2D, new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), Vector2.one * 0.5f);
  41. break;
  42. }
  43. case 5:
  44. this.Document = csv.GetCellAsString(i, cy);
  45. break;
  46. }
  47. }
  48. if (this.IsCategoryCostume)
  49. {
  50. this.ReadMenuFile();
  51. }
  52. else
  53. {
  54. this.ReadFacilityID();
  55. }
  56. }
  57. public CasinoShopItem()
  58. {
  59. }
  60. public bool IsSoldOut
  61. {
  62. get
  63. {
  64. return this.m_IsSoldOut;
  65. }
  66. }
  67. public string NameTerm
  68. {
  69. get
  70. {
  71. return "SceneCasino/アイテム/" + this.Name;
  72. }
  73. }
  74. public string DocumentTerm
  75. {
  76. get
  77. {
  78. return "SceneCasino/アイテム説明/" + this.Name;
  79. }
  80. }
  81. public bool IsCategoryCostume
  82. {
  83. get
  84. {
  85. return this.MyCategory == CasinoShopItem.Category.Costume;
  86. }
  87. }
  88. public bool IsCanBuy
  89. {
  90. get
  91. {
  92. return (long)this.Price <= GameMain.Instance.CharacterMgr.status.casinoCoin;
  93. }
  94. }
  95. public void ItemBuy()
  96. {
  97. this.m_IsSoldOut = true;
  98. CasinoShopItem.Category myCategory = this.MyCategory;
  99. if (myCategory != CasinoShopItem.Category.Costume)
  100. {
  101. if (myCategory == CasinoShopItem.Category.FacilityItem)
  102. {
  103. FacilityManager facilityMgr = GameMain.Instance.FacilityMgr;
  104. facilityMgr.SetHavePowerUpMaterial(this.m_FacilytyItemID, true);
  105. }
  106. }
  107. else
  108. {
  109. Status status = GameMain.Instance.CharacterMgr.status;
  110. foreach (List<CasinoShopItem.MenuData> list in this.m_WearDataList)
  111. {
  112. foreach (CasinoShopItem.MenuData menuData in list)
  113. {
  114. status.AddHavePartsItem(menuData.FileName);
  115. }
  116. }
  117. }
  118. }
  119. public void Serialize(BinaryWriter bw)
  120. {
  121. bw.Write(this.m_IsSoldOut);
  122. }
  123. public void Deserialize(BinaryReader br)
  124. {
  125. this.m_IsSoldOut = br.ReadBoolean();
  126. }
  127. public void Recet()
  128. {
  129. this.m_IsSoldOut = false;
  130. }
  131. private void ReadMenuFile()
  132. {
  133. Action<string[], List<CasinoShopItem.MenuData>> action = delegate(string[] file_array, List<CasinoShopItem.MenuData> list)
  134. {
  135. foreach (string text in file_array)
  136. {
  137. if (text.IndexOf(".menu") < 0)
  138. {
  139. this.ReadMenuDetail(text + ".menu", list);
  140. }
  141. else
  142. {
  143. this.ReadMenuDetail(text, list);
  144. }
  145. }
  146. };
  147. using (AFileBase afileBase = GameUty.FileSystem.FileOpen("casinoshop_costume_data.nei"))
  148. {
  149. using (CsvParser csvParser = new CsvParser())
  150. {
  151. bool condition = csvParser.Open(afileBase);
  152. NDebug.Assert(condition, "casinoshop_costume_data.nei]");
  153. for (int i = 1; i < csvParser.max_cell_y; i++)
  154. {
  155. if (csvParser.IsCellToExistData(0, i) && csvParser.GetCellAsInteger(0, i) == this.ID)
  156. {
  157. for (int j = 0; j < csvParser.max_cell_x; j++)
  158. {
  159. if (csvParser.IsCellToExistData(j, i))
  160. {
  161. switch (j)
  162. {
  163. case 0:
  164. case 1:
  165. break;
  166. case 2:
  167. this.m_WearMask = (TBody.MaskMode)Enum.Parse(typeof(TBody.MaskMode), csvParser.GetCellAsString(j, i));
  168. break;
  169. case 3:
  170. {
  171. string[] arg = csvParser.GetCellAsString(j, i).Split(new char[]
  172. {
  173. '\n'
  174. });
  175. action(arg, this.m_TrywearData);
  176. break;
  177. }
  178. default:
  179. {
  180. this.m_WearDataList.Add(new List<CasinoShopItem.MenuData>());
  181. string[] arg2 = csvParser.GetCellAsString(j, i).Split(new char[]
  182. {
  183. '\n'
  184. });
  185. action(arg2, this.m_WearDataList.Last<List<CasinoShopItem.MenuData>>());
  186. break;
  187. }
  188. }
  189. }
  190. }
  191. break;
  192. }
  193. }
  194. }
  195. }
  196. }
  197. private void ReadMenuDetail(string menu_file, List<CasinoShopItem.MenuData> menu_list)
  198. {
  199. byte[] buffer = null;
  200. using (AFileBase afileBase = GameUty.FileSystem.FileOpen(menu_file))
  201. {
  202. NDebug.Assert(afileBase.IsValid(), menu_file + "\nnot file open.");
  203. buffer = afileBase.ReadAll();
  204. }
  205. BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer), Encoding.UTF8);
  206. string text = binaryReader.ReadString();
  207. NDebug.Assert(text == "CM3D2_MENU", "ProcScriptBin 例外 : ヘッダーファイルが不正です。" + text);
  208. int num = binaryReader.ReadInt32();
  209. string text2 = binaryReader.ReadString();
  210. string text3 = binaryReader.ReadString();
  211. string mpn = binaryReader.ReadString();
  212. binaryReader.Close();
  213. buffer = null;
  214. menu_list.Add(new CasinoShopItem.MenuData(mpn, menu_file));
  215. }
  216. public void TryWear(Maid maid)
  217. {
  218. if (!this.IsCategoryCostume)
  219. {
  220. return;
  221. }
  222. foreach (CasinoShopItem.MenuData menuData in this.m_TrywearData)
  223. {
  224. maid.SetProp(menuData.Mpn, menuData.FileName, 0, false, false);
  225. }
  226. maid.body0.SetMaskMode(this.m_WearMask);
  227. }
  228. private void ReadFacilityID()
  229. {
  230. using (AFileBase afileBase = GameUty.FileSystem.FileOpen("casinoshop_facilityitem_data.nei"))
  231. {
  232. using (CsvParser csvParser = new CsvParser())
  233. {
  234. bool condition = csvParser.Open(afileBase);
  235. NDebug.Assert(condition, "casinoshop_facility_data.nei]");
  236. for (int i = 1; i < csvParser.max_cell_y; i++)
  237. {
  238. if (csvParser.IsCellToExistData(0, i) && csvParser.GetCellAsInteger(0, i) == this.ID)
  239. {
  240. this.m_FacilytyItemID = csvParser.GetCellAsInteger(2, i);
  241. break;
  242. }
  243. }
  244. }
  245. }
  246. }
  247. public readonly int ID;
  248. public readonly string Name;
  249. public readonly int Price;
  250. public readonly Sprite Icon;
  251. public readonly string Document;
  252. public readonly CasinoShopItem.Category MyCategory;
  253. private bool m_IsSoldOut;
  254. private List<CasinoShopItem.MenuData> m_TrywearData = new List<CasinoShopItem.MenuData>();
  255. private TBody.MaskMode m_WearMask;
  256. private List<List<CasinoShopItem.MenuData>> m_WearDataList = new List<List<CasinoShopItem.MenuData>>();
  257. private int m_FacilytyItemID = -1;
  258. public enum Category
  259. {
  260. Costume,
  261. FacilityItem
  262. }
  263. private class MenuData
  264. {
  265. public MenuData(string mpn, string file_name)
  266. {
  267. this.Mpn = mpn;
  268. this.FileName = file_name;
  269. }
  270. public readonly string Mpn;
  271. public readonly string FileName;
  272. }
  273. }