CasinoShopItem.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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 bool IsCategoryCostume
  68. {
  69. get
  70. {
  71. return this.MyCategory == CasinoShopItem.Category.Costume;
  72. }
  73. }
  74. public bool IsCanBuy
  75. {
  76. get
  77. {
  78. return (long)this.Price <= GameMain.Instance.CharacterMgr.status.casinoCoin;
  79. }
  80. }
  81. public void ItemBuy()
  82. {
  83. this.m_IsSoldOut = true;
  84. CasinoShopItem.Category myCategory = this.MyCategory;
  85. if (myCategory != CasinoShopItem.Category.Costume)
  86. {
  87. if (myCategory == CasinoShopItem.Category.FacilityItem)
  88. {
  89. FacilityManager facilityMgr = GameMain.Instance.FacilityMgr;
  90. facilityMgr.SetHavePowerUpMaterial(this.m_FacilytyItemID, true);
  91. }
  92. }
  93. else
  94. {
  95. Status status = GameMain.Instance.CharacterMgr.status;
  96. foreach (List<CasinoShopItem.MenuData> list in this.m_WearDataList)
  97. {
  98. foreach (CasinoShopItem.MenuData menuData in list)
  99. {
  100. status.AddHavePartsItem(menuData.FileName);
  101. }
  102. }
  103. }
  104. }
  105. public void Serialize(BinaryWriter bw)
  106. {
  107. bw.Write(this.m_IsSoldOut);
  108. }
  109. public void Deserialize(BinaryReader br)
  110. {
  111. this.m_IsSoldOut = br.ReadBoolean();
  112. }
  113. public void Recet()
  114. {
  115. this.m_IsSoldOut = false;
  116. }
  117. private void ReadMenuFile()
  118. {
  119. Action<string[], List<CasinoShopItem.MenuData>> action = delegate(string[] file_array, List<CasinoShopItem.MenuData> list)
  120. {
  121. foreach (string text in file_array)
  122. {
  123. if (text.IndexOf(".menu") < 0)
  124. {
  125. this.ReadMenuDetail(text + ".menu", list);
  126. }
  127. else
  128. {
  129. this.ReadMenuDetail(text, list);
  130. }
  131. }
  132. };
  133. using (AFileBase afileBase = GameUty.FileSystem.FileOpen("casinoshop_costume_data.nei"))
  134. {
  135. using (CsvParser csvParser = new CsvParser())
  136. {
  137. bool condition = csvParser.Open(afileBase);
  138. NDebug.Assert(condition, "casinoshop_costume_data.nei]");
  139. for (int i = 1; i < csvParser.max_cell_y; i++)
  140. {
  141. if (csvParser.IsCellToExistData(0, i) && csvParser.GetCellAsInteger(0, i) == this.ID)
  142. {
  143. for (int j = 0; j < csvParser.max_cell_x; j++)
  144. {
  145. if (csvParser.IsCellToExistData(j, i))
  146. {
  147. switch (j)
  148. {
  149. case 0:
  150. case 1:
  151. break;
  152. case 2:
  153. this.m_WearMask = (TBody.MaskMode)Enum.Parse(typeof(TBody.MaskMode), csvParser.GetCellAsString(j, i));
  154. break;
  155. case 3:
  156. {
  157. string[] arg = csvParser.GetCellAsString(j, i).Split(new char[]
  158. {
  159. '\n'
  160. });
  161. action(arg, this.m_TrywearData);
  162. break;
  163. }
  164. default:
  165. {
  166. this.m_WearDataList.Add(new List<CasinoShopItem.MenuData>());
  167. string[] arg2 = csvParser.GetCellAsString(j, i).Split(new char[]
  168. {
  169. '\n'
  170. });
  171. action(arg2, this.m_WearDataList.Last<List<CasinoShopItem.MenuData>>());
  172. break;
  173. }
  174. }
  175. }
  176. }
  177. break;
  178. }
  179. }
  180. }
  181. }
  182. }
  183. private void ReadMenuDetail(string menu_file, List<CasinoShopItem.MenuData> menu_list)
  184. {
  185. byte[] buffer = null;
  186. using (AFileBase afileBase = GameUty.FileSystem.FileOpen(menu_file))
  187. {
  188. NDebug.Assert(afileBase.IsValid(), menu_file + "\nnot file open.");
  189. buffer = afileBase.ReadAll();
  190. }
  191. BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer), Encoding.UTF8);
  192. string text = binaryReader.ReadString();
  193. NDebug.Assert(text == "CM3D2_MENU", "ProcScriptBin 例外 : ヘッダーファイルが不正です。" + text);
  194. int num = binaryReader.ReadInt32();
  195. string text2 = binaryReader.ReadString();
  196. string text3 = binaryReader.ReadString();
  197. string mpn = binaryReader.ReadString();
  198. binaryReader.Close();
  199. buffer = null;
  200. menu_list.Add(new CasinoShopItem.MenuData(mpn, menu_file));
  201. }
  202. public void TryWear(Maid maid)
  203. {
  204. if (!this.IsCategoryCostume)
  205. {
  206. return;
  207. }
  208. foreach (CasinoShopItem.MenuData menuData in this.m_TrywearData)
  209. {
  210. maid.SetProp(menuData.Mpn, menuData.FileName, 0, false, false);
  211. }
  212. maid.body0.SetMaskMode(this.m_WearMask);
  213. }
  214. private void ReadFacilityID()
  215. {
  216. using (AFileBase afileBase = GameUty.FileSystem.FileOpen("casinoshop_facilityitem_data.nei"))
  217. {
  218. using (CsvParser csvParser = new CsvParser())
  219. {
  220. bool condition = csvParser.Open(afileBase);
  221. NDebug.Assert(condition, "casinoshop_facility_data.nei]");
  222. for (int i = 1; i < csvParser.max_cell_y; i++)
  223. {
  224. if (csvParser.IsCellToExistData(0, i) && csvParser.GetCellAsInteger(0, i) == this.ID)
  225. {
  226. this.m_FacilytyItemID = csvParser.GetCellAsInteger(2, i);
  227. break;
  228. }
  229. }
  230. }
  231. }
  232. }
  233. public readonly int ID;
  234. public readonly string Name;
  235. public readonly int Price;
  236. public readonly Sprite Icon;
  237. public readonly string Document;
  238. public readonly CasinoShopItem.Category MyCategory;
  239. private bool m_IsSoldOut;
  240. private List<CasinoShopItem.MenuData> m_TrywearData = new List<CasinoShopItem.MenuData>();
  241. private TBody.MaskMode m_WearMask;
  242. private List<List<CasinoShopItem.MenuData>> m_WearDataList = new List<List<CasinoShopItem.MenuData>>();
  243. private int m_FacilytyItemID = -1;
  244. public enum Category
  245. {
  246. Costume,
  247. FacilityItem
  248. }
  249. private class MenuData
  250. {
  251. public MenuData(string mpn, string file_name)
  252. {
  253. this.Mpn = mpn;
  254. this.FileName = file_name;
  255. }
  256. public readonly string Mpn;
  257. public readonly string FileName;
  258. }
  259. }