ItemProxy.cs 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  1. using Newtonsoft.Json.Linq;
  2. using System;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using UnityEngine;
  7. /// <summary>
  8. /// 道具/背包模块
  9. /// </summary>
  10. public class ItemProxy : ProxyBase<ItemProxy>
  11. {
  12. public BagMainUIVo BagMain() => new BagMainUIVo();
  13. #region 英雄碎片
  14. /// <summary>
  15. /// 6415 碎片合成
  16. /// </summary>
  17. /// <param name="typeId1"></param>
  18. /// <param name="typeId2"></param>
  19. /// <param name="typeId3"></param>
  20. /// <param name="callback"></param>
  21. [Obsolete("2019年12月31日")]
  22. public void PiecesCompose(string typeId1, string typeId2, string typeId3, Action<JObject> callback = null)
  23. {
  24. Post(CmdCode.cmd_store_PiecesCompose, new object[] { typeId1, typeId2, typeId3 }, resp => callback?.Invoke(resp.result));
  25. }
  26. #endregion
  27. /// <summary>
  28. /// [6412] 购买物品格子数 李宁给定的方案是买一次就是50个钻石,十个格子,不能批量购买.
  29. /// </summary>
  30. /// <param name="num">购买数量</param>
  31. /// <param name="callback">成功回调函数</param>
  32. public void AddMaxPacketNum(Action<JObject> callback)
  33. {
  34. Post(CmdCode.cmd_store_AddMaxPacketNum, new object[] { }, resp => callback?.Invoke(resp.result));
  35. }
  36. #region 装备
  37. /// <summary>
  38. /// [6413]装备熔炼升级
  39. /// </summary>
  40. /// <param name="obj"></param>
  41. /// <param name="callback"></param>
  42. [Obsolete("2019年12月31日")]
  43. public void MeltUpgradeEquip(int itemuid, Action<JObject> callback)
  44. {
  45. Post(CmdCode.cmd_store_MeltEquip, new object[] { itemuid }, resp => callback?.Invoke(resp.result));
  46. }
  47. /// <summary>
  48. /// [6417]让指定英雄脱下该言灵
  49. /// </summary>
  50. /// <param name="ItemType"></param>
  51. /// <param name="ItemuId"></param>
  52. /// <param name="herouid"></param>
  53. /// <param name="callback"></param>
  54. public void UnWieldYanling(int ItemType, int ItemuId, int herouid, Action<string> callback)
  55. {
  56. Post(CmdCode.cmd_store_UnWieldYanling, new object[] { ItemType, ItemuId, herouid },
  57. resp =>
  58. {
  59. UserProxy.Instance.player.collectYanling.items[ItemuId].herouid = 0;
  60. UserProxy.Instance.player.collectHero.collectHeroDic[herouid.ToString()].yanling[ItemType] = new HeroGameVo_Yanling() { itemuid = 0 };
  61. callback?.Invoke(resp.result["resp"].ToString());
  62. });
  63. }
  64. /// <summary>
  65. /// [6416]给英雄装上言灵
  66. /// </summary>
  67. /// <param name="ItemType"></param>
  68. /// <param name="ItemuId"></param>
  69. /// <param name="herouid"></param>
  70. /// <param name="callback"></param>
  71. public void WearYanlingToHero(int ItemType, int ItemuId, int herouid, Action<string> callback)
  72. {
  73. Post(CmdCode.cmd_store_WearYanling, new object[] { ItemType, ItemuId, herouid },
  74. resp =>
  75. {
  76. var p = UserProxy.Instance.player;
  77. //p.InitFromStore((JObject)resp.result["store"]); // 更新任务卡
  78. var yanlingVo = p.collectYanling.items[ItemuId];
  79. yanlingVo.herouid = herouid;
  80. var oidYanlingId = p.collectHero.collectHeroDic[herouid.ToString()].yanling[ItemType].itemuid;
  81. if (oidYanlingId > 0 && oidYanlingId != ItemuId)
  82. {
  83. p.collectYanling.items[oidYanlingId].herouid = 0;
  84. }
  85. sm_item_yanling newYanling = sm_item_yanling.GetMoById(int.Parse(yanlingVo.typeId));
  86. p.collectHero.collectHeroDic[herouid.ToString()].yanling[ItemType] = new HeroGameVo_Yanling()
  87. {
  88. itemuid = ItemuId,
  89. typeId = int.Parse(yanlingVo.typeId),
  90. sp_now = newYanling.sp_max,
  91. cd_now = newYanling.skill_cd
  92. };
  93. callback?.Invoke(resp.result["resp"].ToString());
  94. });
  95. }
  96. /// <summary>
  97. /// 试穿言灵,
  98. /// </summary>
  99. /// <param name="yanlingUID"></param>
  100. /// <param name="heroUID"></param>
  101. /// <returns>战力有增长则返回true,否则返回false</returns>
  102. public bool TestWearYanlingToHeroCanImproveFightPower(int yanlingUID, int heroUID)
  103. {
  104. var p = UserProxy.Instance.player;
  105. var yanlingVo = p.collectYanling.items[yanlingUID]; // 言灵对象
  106. var heroVo = p.collectHero.collectHeroDic[heroUID.ToString()]; // 唤灵师对象
  107. var yanlingType = yanlingVo.nMo.GetYanlingExt().position;
  108. var oldPower = heroVo.GetPower(); // 记录当前战力
  109. var oldYanlingUID = heroVo.yanling[yanlingType]; // 记录旧言灵
  110. heroVo.yanling[yanlingType] = yanlingUID; // 替换上新言灵
  111. var newPower = heroVo.GetPower(); // 计算新战力
  112. heroVo.yanling[yanlingType] = oldYanlingUID; // 换回旧言灵
  113. return newPower > oldPower; // 返回结果
  114. }
  115. /// <summary>
  116. /// [6411]让指定英雄脱下该装备
  117. /// </summary>
  118. /// <param name="ItemType"></param>
  119. /// <param name="ItemuId"></param>
  120. /// <param name="herouid"></param>
  121. /// <param name="callback"></param>
  122. public void UnWieldEquip(int ItemType, int ItemuId, int herouid, Action<string> callback)
  123. {
  124. Post(CmdCode.cmd_store_UnWield, new object[] { 1, ItemuId, herouid }, resp => callback?.Invoke(resp.result["resp"].ToString()));
  125. }
  126. /// <summary>
  127. /// [6410]给英雄穿装备
  128. /// </summary>
  129. /// <param name="ItemType"></param>
  130. /// <param name="ItemuId"></param>
  131. /// <param name="herouid"></param>
  132. /// <param name="callback"></param>
  133. public void WearEquipToHero(int ItemType, int ItemuId, int herouid, Action<string> callback)
  134. {
  135. Post(CmdCode.cmd_store_WearEquip, new object[] { 1, ItemuId, herouid },
  136. resp =>
  137. {
  138. var p = UserProxy.Instance.player;
  139. //p.InitFromStore((JObject)resp.result["store"]); // 更新任务卡
  140. p.collectEquip.equipments[ItemuId].herouid = herouid;
  141. var oidYanlingId = int.Parse(p.collectHero.collectHeroDic[herouid.ToString()].equips["weapon"].equipItemUID);
  142. if (oidYanlingId > 0 && oidYanlingId != ItemuId)
  143. {
  144. p.collectEquip.equipments[oidYanlingId].herouid = 0;
  145. }
  146. p.collectHero.collectHeroDic[herouid.ToString()].equips["weapon"] = new HeroGameVo_Equip() { equipItemUID = ItemuId.ToString() };
  147. callback?.Invoke(resp.result["resp"].ToString());
  148. });
  149. }
  150. /// <summary>
  151. /// 试穿武器,
  152. /// </summary>
  153. /// <param name="yanlingUID"></param>
  154. /// <param name="heroUID"></param>
  155. /// <returns>战力有增长则返回true,否则返回false</returns>
  156. public bool TestWearEquipToHeroCanImproveFightPower(int equipUID, int heroUID)
  157. {
  158. var p = UserProxy.Instance.player;
  159. var equipVo = p.collectEquip.equipments[equipUID]; // 言灵对象
  160. var heroVo = p.collectHero.collectHeroDic[heroUID.ToString()]; // 唤灵师对象
  161. var weaponType = "weapon";
  162. var oldPower = heroVo.GetPower(); // 记录当前战力
  163. int oldEquipUID = heroVo.equips[weaponType]; // 记录旧言灵
  164. heroVo.equips[weaponType] = equipUID; // 替换上新言灵
  165. var newPower = heroVo.GetPower(); // 计算新战力
  166. heroVo.equips[weaponType] = oldEquipUID; // 换回旧言灵
  167. return newPower > oldPower; // 返回结果
  168. }
  169. /// <summary>
  170. /// [6409]宝石合成vc=-0
  171. /// </summary>
  172. /// <param name="obj"></param>
  173. /// <param name="callback"></param>
  174. [Obsolete("2019年12月31日")]
  175. //public void GemCompose(int lowTypeId, int useNum, int highTypeId, int addNum, int needGold, Action<string> callback)
  176. //{
  177. // Post(CmdCode.cmd_store_GemCompose, new object[] { lowTypeId, useNum, highTypeId, addNum, needGold }, resp => callback?.Invoke(resp.result["resp"].ToString()));
  178. //}
  179. /// <summary>
  180. /// [6408]装备打造升级
  181. /// </summary>
  182. /// <param name="obj"></param>
  183. /// <param name="callback"></param>
  184. //[Obsolete("2019年12月31日")]
  185. public void UpdateItem(int itemuid, int needgold, Dictionary<string, string> obj, object[] ary, Action<JObject> callback)
  186. {
  187. Post(CmdCode.cmd_store_ItemUpgrage, new object[] { itemuid, needgold, obj, ary }, resp => callback?.Invoke(resp.result));
  188. }
  189. /// <summary>
  190. /// [6406]从仓库删除道具
  191. /// </summary>
  192. /// <param name="obj"></param>
  193. /// <param name="callback"></param>
  194. public void DelItemFromStore(int itemuid, int num, Action callback)
  195. {
  196. Post(CmdCode.cmd_store_delItem, new object[] { itemuid, num }, resp =>
  197. {
  198. //UserProxy.Instance.player.InitFromStore((JObject)resp.result["store"]);
  199. callback?.Invoke();
  200. });
  201. }
  202. #endregion
  203. /// <summary>
  204. /// [6405] 刷新背包
  205. /// </summary>
  206. private void RefreshStore(Action callback)
  207. {
  208. Post(CmdCode.cmd_packet_Refresh, new object[] { }, resp => callback?.Invoke());
  209. }
  210. /// <summary>
  211. /// [6404] 使用道具
  212. /// </summary>
  213. public void UseItem(int itemTypeId, int num, Action callback)
  214. {
  215. Post<Ret_UseItem>(CmdCode.cmd_packet_useItem, new object[] { itemTypeId, num },
  216. ret =>
  217. {
  218. UserProxy.Instance.player.PrivateState = ret.priv; // ((JObject)resp.result["priv"]).ToObject<Info_PrivateState>();
  219. callback?.Invoke();
  220. });
  221. }
  222. /// <summary>
  223. /// [6403]卖出多个物品
  224. /// </summary>
  225. /// <param name="num">卖出物品数量</param>
  226. /// <param name="obj">物品结构</param>
  227. /// <param name="callback"></param>
  228. public void SellMultiItemFromStore(object[] obj, Action<string> callback)
  229. {
  230. Post(CmdCode.cmd_packet_SellMultiItem, new object[] { obj }, resp => callback.Invoke(resp.result["resp"].ToString()));
  231. }
  232. /// <summary>
  233. /// [6402] 卖单个物品
  234. /// </summary>
  235. /// <param name="ItemId">物品id</param>
  236. /// <param name="ItemType">物品类型</param>
  237. /// <param name="num">数量或者uid</param>
  238. /// <param name="callback"></param>
  239. public void SellItemFromStore(int ItemType, int ItemId, int num, Action<string> callback)
  240. {
  241. Post(CmdCode.cmd_packet_SellSingleItem, new object[] { ItemType, ItemId, num }, resp => callback?.Invoke(resp.result["resp"].ToString()));
  242. }
  243. /// <summary>
  244. /// [6401]向后台同步奖励数据
  245. /// </summary>
  246. /// <param name="rwdStr"></param>
  247. /// <param name="callback"></param>
  248. public void PutItemInStore(string rwdStr, Action callback, Action fail)
  249. {
  250. Post<Ret_PutItemInStore>(CmdCode.cmd_packet_putItemInStore, new object[] { rwdStr, 1 }, ret =>
  251. {
  252. var p = UserProxy.Instance.player;
  253. p.baseInfo.gold = ret.gold;
  254. p.baseInfo.tili = ret.tili;
  255. p.baseInfo.cash = ret.cash;
  256. p.baseInfo.resPoint = ret.resPoint;
  257. callback?.Invoke();
  258. }, err => fail?.Invoke());
  259. //Post(CmdCode.cmd_packet_putItemInStore, new object[] { rwdStr, 1 }, resp =>
  260. //{
  261. // var p = UserProxy.Instance.player;
  262. // p.baseInfo.gold = Convert.ToInt32(resp.result["gold"].ToString());
  263. // p.baseInfo.cash = Convert.ToInt32(resp.result["cash"].ToString());
  264. // p.baseInfo.resPoint = Convert.ToInt32(resp.result["resPoint"].ToString());
  265. // callback?.Invoke();
  266. //}, err => fail?.Invoke());
  267. }
  268. /// <summary>
  269. /// [6418]碎片合成言灵召唤书 2020.7.22
  270. /// </summary>
  271. /// <param name="bookId"></param>
  272. /// <param name="callback"></param>
  273. public void MergeYanlingBook(int bookId, Action callback)
  274. {
  275. Post(CmdCode.cmd_store_mergeYanlingbook, new object[] { bookId }, resp => callback?.Invoke());
  276. }
  277. /// <summary>
  278. /// [6419]利用言灵召唤书召唤言灵 2020.7.22
  279. /// </summary>
  280. /// <param name="bookId"></param>
  281. /// <param name="callback"></param>
  282. public void CallYanling(int bookId, Action callback)
  283. {
  284. Post(CmdCode.cmd_store_callyanling, new object[] { bookId }, resp => callback?.Invoke());
  285. }
  286. /// <summary>
  287. /// [6420]言灵进阶 2020.7.29-------废弃
  288. /// </summary>
  289. /// <param name="bookId"></param>
  290. /// <param name="callback"></param>
  291. public void YanlingUpgrade(int yanlingUID, Action callback)
  292. {
  293. Post(CmdCode.cmd_store_yanling_upgrade, new object[] { yanlingUID }, resp => callback?.Invoke());
  294. }
  295. /// <summary>
  296. /// 武器升级
  297. /// </summary>
  298. /// <param name="uid"></param>
  299. /// <param name="wuqiList"></param>
  300. /// <param name="items"></param>
  301. /// <param name="callback"></param>
  302. public void WeaponUpgrade(int uid, List<ItemVo> itemList, Action<UserEquipmentVo> callback)
  303. {
  304. List<string> wuqiList = new List<string>();
  305. Dictionary<string, int> items = new Dictionary<string, int>();
  306. foreach (ItemVo vo in itemList)
  307. {
  308. if (vo.IsWeapon)
  309. {
  310. wuqiList.Add(vo.uid);
  311. }
  312. else
  313. {
  314. items[vo.typeId] = vo.count;
  315. }
  316. }
  317. Post<Ret_WeaponUp>(CmdCode.cmd_store_weapon_upgrade, new object[] { uid, wuqiList, items }, ret =>
  318. {
  319. var p = UserProxy.Instance.player;
  320. p.baseInfo.gold = ret.gold; // int.Parse(resp.result["gold"].ToString());
  321. callback?.Invoke(p.collectEquip.equipments[uid]);
  322. });
  323. //Post(CmdCode.cmd_store_weapon_upgrade, new object[] { uid, wuqiList, items }, resp =>
  324. //{
  325. // var p = UserProxy.Instance.player;
  326. // p.InitFromStore((JObject)resp.result["store"]);
  327. // UserProxy.Instance.player.baseInfo.gold = int.Parse(resp.result["gold"].ToString());
  328. // callback?.Invoke(p.collectEquip.equipments[uid]);
  329. //});
  330. }
  331. /// <summary>
  332. /// 武器突破
  333. /// </summary>
  334. /// <param name="yanlingUID"></param>
  335. /// <param name="callback"></param>
  336. public void WeaponTupo(int uid, Action callback)
  337. {
  338. Post<Ret_WeaponUp>(CmdCode.cmd_store_weapon_tupo, new object[] { uid }, resp =>
  339. {
  340. UserProxy.Instance.player.baseInfo.gold = resp.gold; // int.Parse(resp.result["gold"].ToString());
  341. callback?.Invoke();
  342. });
  343. //Post(CmdCode.cmd_store_weapon_tupo, new object[] { uid }, resp =>
  344. //{
  345. // UserProxy.Instance.player.baseInfo.gold = int.Parse(resp.result["gold"].ToString());
  346. // callback?.Invoke();
  347. //});
  348. }
  349. /// <summary>
  350. ///
  351. /// </summary>
  352. /// <param name="uid"></param>
  353. /// <param name="replaceId"></param>
  354. /// <param name="callback"></param>
  355. public void WeaponReplace(int uid, int replaceId, Action callback)
  356. {
  357. Post(CmdCode.cmd_store_weaponReplace, new object[] { uid, replaceId }, resp => callback?.Invoke());
  358. }
  359. /// <summary>
  360. /// 查看新道具
  361. /// </summary>
  362. /// <param name="type"></param>
  363. /// <param name="uid"></param>
  364. /// <param name="callback"></param>
  365. public void RefreshItem(EItemSubType type, int uid, Action callback)
  366. {
  367. Post<Ret_Store>(CmdCode.cmd_store_refreshItem, new object[] { (int)type, uid }, ret =>
  368. {
  369. //var p = UserProxy.Instance.player;
  370. //p.InitFromStore(ret.store); // (JObject)resp.result["store"]);
  371. callback?.Invoke();
  372. });
  373. }
  374. #region----------->宝石系统
  375. /// <summary>
  376. /// 所有的宝石信息
  377. /// </summary>
  378. /// <returns></returns>
  379. public Dictionary<int, List<GemDataVo>> GetAllGemComposeData()
  380. {
  381. Dictionary<int, List<GemDataVo>> dic = new Dictionary<int, List<GemDataVo>>();
  382. int researchLevel = UserProxy.Instance.player.gemInfo.level;
  383. List<string> allList = new List<string>();
  384. List<GemDataVo> zlist = new List<GemDataVo>();
  385. List<GemDataVo> redlist = new List<GemDataVo>();
  386. List<GemDataVo> llist = new List<GemDataVo>();
  387. List<GemDataVo> hlist = new List<GemDataVo>();
  388. List<GemDataVo> blist = new List<GemDataVo>();
  389. for (int i = 1; i <= researchLevel; i++)
  390. {
  391. string[] gemIsList = GameConfigData.Ins.Getgem_researchlevelMo(i).unlockGemIds.Split(',');
  392. foreach (string id in gemIsList)
  393. {
  394. sm_gem_formula gemMo = GameConfigData.Ins.Getgem_formulaMo(int.Parse(id));
  395. GemDataVo vo = new GemDataVo(int.Parse(id));
  396. string type = id[..4];
  397. switch (type)
  398. {
  399. case "7011":
  400. zlist.Add(vo);
  401. break;
  402. case "7012":
  403. redlist.Add(vo);
  404. break;
  405. case "7013":
  406. llist.Add(vo);
  407. break;
  408. case "7014":
  409. hlist.Add(vo);
  410. break;
  411. case "7015":
  412. blist.Add(vo);
  413. break;
  414. }
  415. }
  416. }
  417. if (zlist.Count != 0)
  418. {
  419. dic[7011] = this.listSort(zlist);
  420. }
  421. if (redlist.Count != 0)
  422. {
  423. dic[7012] = this.listSort(redlist);
  424. }
  425. if (llist.Count != 0)
  426. {
  427. dic[7013] = this.listSort(llist);
  428. }
  429. if (hlist.Count != 0)
  430. {
  431. dic[7014] = this.listSort(hlist);
  432. }
  433. if (blist.Count != 0)
  434. {
  435. dic[7015] = this.listSort(blist);
  436. }
  437. return dic;
  438. }
  439. public List<GemDataVo> listSort(List<GemDataVo> arr)
  440. {
  441. int n = arr.Count;
  442. GemDataVo temp_v = null;
  443. int j = 0;
  444. for (int i = 0; i < n - 1; i++)
  445. {
  446. for (j = i + 1; j < n; j++)
  447. {
  448. if (arr[i].itemMo.quality > arr[j].itemMo.quality)
  449. {
  450. temp_v = arr[i];
  451. arr[i] = arr[j];
  452. arr[j] = temp_v;
  453. }
  454. else if (arr[i].itemMo.quality == arr[j].itemMo.quality && arr[i].itemMo.typeId < arr[j].itemMo.typeId)
  455. {
  456. temp_v = arr[i];
  457. arr[i] = arr[j];
  458. arr[j] = temp_v;
  459. }
  460. }
  461. }
  462. return arr;
  463. }
  464. /// <summary>
  465. /// 宝石合成
  466. /// </summary>
  467. /// <param name="gemId"></param>
  468. /// <param name="num"></param>
  469. /// <param name="callback"></param>
  470. public void GemComposeItem(int gemId, int num, Action<Dictionary<int, List<GemDataVo>>> callback)
  471. {
  472. Post(CmdCode.cmd_store_GemCompose, new object[] { gemId, num }, resp =>
  473. {
  474. var p = UserProxy.Instance.player;
  475. p.InitFromStore((JObject)resp.result["store"]);
  476. p.baseInfo.gold = Convert.ToInt32(resp.result["gold"].ToString());
  477. Dictionary<int, List<GemDataVo>> dic = this.GetAllGemComposeData();
  478. callback?.Invoke(dic);
  479. });
  480. }
  481. /// <summary>
  482. /// 研究等级提升
  483. /// </summary>
  484. /// <param name="callback"></param>
  485. public void GemResearchLvUp(Action<ResearchVo> callback)
  486. {
  487. Post(CmdCode.cmd_store_GemResearchLvUp, new object[] { }, resp =>
  488. {
  489. var p = UserProxy.Instance.player;
  490. //p.InitFromStore((JObject)resp.result["store"]);
  491. p.baseInfo.gold = Convert.ToInt32(resp.result["gold"].ToString());
  492. p.gemInfo.level = Convert.ToInt32(resp.result["lv"].ToString());
  493. callback?.Invoke(new ResearchVo());
  494. });
  495. }
  496. /// <summary>
  497. /// 背包里的所有宝石信息
  498. /// </summary>
  499. /// <returns></returns>
  500. public Dictionary<int, List<ItemVo>> StoreGemInfo()
  501. {
  502. Dictionary<string, ItemVo> collectItemDic = UserProxy.Instance.player.collectItem.collectItemDic;
  503. List<ItemVo> zlist = new List<ItemVo>();
  504. List<ItemVo> redlist = new List<ItemVo>();
  505. List<ItemVo> llist = new List<ItemVo>();
  506. List<ItemVo> hlist = new List<ItemVo>();
  507. List<ItemVo> blist = new List<ItemVo>();
  508. foreach (KeyValuePair<string, ItemVo> kv in collectItemDic)
  509. {
  510. if (kv.Value.nMo.subType != (int)EItemSubType.Gemstone)
  511. {
  512. continue;
  513. }
  514. string type = kv.Key.Substring(0, 4);
  515. switch (type)
  516. {
  517. case "7011":
  518. zlist.Add(kv.Value);
  519. break;
  520. case "7012":
  521. redlist.Add(kv.Value);
  522. break;
  523. case "7013":
  524. llist.Add(kv.Value);
  525. break;
  526. case "7014":
  527. hlist.Add(kv.Value);
  528. break;
  529. case "7015":
  530. blist.Add(kv.Value);
  531. break;
  532. }
  533. }
  534. Dictionary<int, List<ItemVo>> dic = new Dictionary<int, List<ItemVo>>();
  535. if (zlist.Count != 0)
  536. {
  537. dic[7011] = this.listSort_ItemVo(zlist);
  538. }
  539. if (redlist.Count != 0)
  540. {
  541. dic[7012] = this.listSort_ItemVo(redlist);
  542. }
  543. if (llist.Count != 0)
  544. {
  545. dic[7013] = this.listSort_ItemVo(llist);
  546. }
  547. if (hlist.Count != 0)
  548. {
  549. dic[7014] = this.listSort_ItemVo(hlist);
  550. }
  551. if (blist.Count != 0)
  552. {
  553. dic[7015] = this.listSort_ItemVo(blist);
  554. }
  555. //dic[7011] = this.listSort_ItemVo(zlist);
  556. //dic[7012] = this.listSort_ItemVo(redlist);
  557. //dic[7013] = this.listSort_ItemVo(llist);
  558. //dic[7014] = this.listSort_ItemVo(hlist);
  559. //dic[7015] = this.listSort_ItemVo(blist);
  560. return dic;
  561. }
  562. public List<ItemVo> listSort_ItemVo(List<ItemVo> arr)
  563. {
  564. int n = arr.Count;
  565. ItemVo temp_v = null;
  566. int j = 0;
  567. for (int i = 0; i < n - 1; i++)
  568. {
  569. for (j = i + 1; j < n; j++)
  570. {
  571. if (arr[i].nMo.quality > arr[j].nMo.quality)
  572. {
  573. temp_v = arr[i];
  574. arr[i] = arr[j];
  575. arr[j] = temp_v;
  576. }
  577. else if (arr[i].nMo.quality == arr[j].nMo.quality && arr[i].nMo.typeId < arr[j].nMo.typeId)
  578. {
  579. temp_v = arr[i];
  580. arr[i] = arr[j];
  581. arr[j] = temp_v;
  582. }
  583. }
  584. }
  585. return arr;
  586. }
  587. /// <summary>
  588. /// 宝石镶嵌
  589. /// </summary>
  590. /// <param name="gemId"></param>
  591. /// <param name="yanlingUid"></param>
  592. /// <param name="callback"></param>
  593. public void GemSet(int gemId, int yanlingUid, Action callback)
  594. {
  595. Post(CmdCode.cmd_store_GemSet, new object[] { gemId, yanlingUid }, resp =>
  596. {
  597. var p = UserProxy.Instance.player;
  598. p.InitFromStore((JObject)resp.result["store"]);
  599. callback?.Invoke();
  600. });
  601. }
  602. /// <summary>
  603. /// 宝石卸下
  604. /// </summary>
  605. /// <param name="yanlingUid"></param>
  606. /// <param name="callback"></param>
  607. public void GemRemove(int yanlingUid, Action callback)
  608. {
  609. Post(CmdCode.cmd_store_GemRemove, new object[] { yanlingUid }, resp =>
  610. {
  611. var p = UserProxy.Instance.player;
  612. p.InitFromStore((JObject)resp.result["store"]);
  613. callback?.Invoke();
  614. });
  615. }
  616. /// <summary>
  617. ///
  618. /// </summary>
  619. /// <param name="callback"></param>
  620. public void UnlockStore(Action callback)
  621. {
  622. Post(CmdCode.cmd_store_unlockStore, new object[] { }, resp =>
  623. {
  624. var p = UserProxy.Instance.player;
  625. //p.InitFromStore((JObject)resp.result["store"]);
  626. p.baseInfo.gold = Convert.ToInt32(resp.result["gold"].ToString());
  627. p.PrivateState.expandNum = Convert.ToInt32(resp.result["expandNum"].ToString());
  628. callback?.Invoke();
  629. });
  630. }
  631. /// <summary>
  632. /// 删除所有类型道具
  633. /// </summary>
  634. /// <param name="subType"></param>
  635. /// <param name="id"></param>
  636. /// <param name="num"></param>
  637. /// <param name="callback"></param>
  638. public void removeItem(List<ItemVo> list, Action callback)
  639. {
  640. string str = "";
  641. int count = list.Count;
  642. int index = 0;
  643. foreach (ItemVo vo in list)
  644. {
  645. index += 1;
  646. int type = vo.nMo.itemType;
  647. string uid = vo.uid;
  648. string id = vo.typeId;
  649. int num = vo.count;
  650. string s = "";
  651. if (index >= count)
  652. {
  653. s = type + "-" + uid + "-" + id + "-" + num;
  654. }
  655. else
  656. {
  657. s = type + "-" + uid + "-" + id + "-" + num + ";";
  658. }
  659. str += s;
  660. }
  661. Post(CmdCode.cmd_store_removeItem, new object[] { str }, resp =>
  662. {
  663. var p = UserProxy.Instance.player;
  664. p.InitFromStore((JObject)resp.result["store"]);
  665. callback?.Invoke();
  666. });
  667. }
  668. /// <summary>
  669. /// 击杀怪,唤灵师获得的信息加成,暂时是经验
  670. /// </summary>
  671. /// <param name="heroUid"></param>
  672. /// <param name="mosterId"></param>
  673. /// <param name="callback"></param>
  674. public void killMosterAddData(string heroUid, int mosterId, Action<int> callback)
  675. {
  676. Post(CmdCode.cmd_store_killMosterAddData, new object[] { heroUid, mosterId }, resp =>
  677. {
  678. var p = UserProxy.Instance.player;
  679. int exp = Convert.ToInt32(resp.result["exp"].ToString());
  680. var hero = UserProxy.Instance.player.collectHero.UpdateHero(JObject.FromObject(resp.result["hero"]));
  681. callback?.Invoke(exp);
  682. });
  683. }
  684. #endregion
  685. #region-------->武器商店
  686. /// <summary>
  687. /// 获取武器商店里的信息
  688. /// </summary>
  689. /// <param name="npcid"></param>
  690. /// <param name="callback"></param>
  691. public void GetShopWeapon(int npcid, Action<List<UserEquipmentVo>> callback)
  692. {
  693. Post(CmdCode.map_getShopWeapon, new object[] { npcid }, resp =>
  694. {
  695. var p = UserProxy.Instance.player;
  696. p.InitFromStore((JObject)resp.result["store"]);
  697. List<UserEquipmentVo> weaponList = this.initShopWeapon(npcid);
  698. callback?.Invoke(weaponList);
  699. });
  700. }
  701. /// <summary>
  702. /// 购买武器
  703. /// </summary>
  704. /// <param name="npcid"></param>
  705. /// <param name="callback"></param>
  706. public void BuyWeapon(int npcid, int weaponId, Action<List<UserEquipmentVo>> callback)
  707. {
  708. Post(CmdCode.map_buyWeapon, new object[] { npcid, weaponId }, resp =>
  709. {
  710. var p = UserProxy.Instance.player;
  711. p.InitFromStore((JObject)resp.result["store"]);
  712. p.baseInfo.gold -= int.Parse(resp.result["cost"].ToString());
  713. List<UserEquipmentVo> weaponList = this.initShopWeapon(npcid);
  714. callback?.Invoke(weaponList);
  715. });
  716. }
  717. public List<UserEquipmentVo> initShopWeapon(int npcid)
  718. {
  719. List<UserEquipmentVo> weaponList = new List<UserEquipmentVo>();
  720. if (UserProxy.Instance.player.weaponPool.Count == 0)
  721. {
  722. return weaponList;
  723. }
  724. Dictionary<int, List<int>> weaponPool = UserProxy.Instance.player.weaponPool[npcid];
  725. Dictionary<int, Dictionary<int, List<int>>> weaponReward = UserProxy.Instance.player.weaponReward;
  726. List<sm_shop_weapon> mo = GameConfigData.Ins.shop_weapon[npcid];
  727. foreach (KeyValuePair<int, List<int>> kv in weaponPool)
  728. {
  729. int type = kv.Key;
  730. int cost = 0;
  731. foreach (sm_shop_weapon item in mo)
  732. {
  733. if (item.id == type)
  734. {
  735. cost = int.Parse(item.cost);
  736. break;
  737. }
  738. }
  739. kv.Value.ForEach(weaponId =>
  740. {
  741. UserEquipmentVo vo = new UserEquipmentVo();
  742. vo.typeId = weaponId.ToString();
  743. vo.level = 1;
  744. vo.starLevel = 0;
  745. vo.cost = cost;
  746. vo.isSellOut = false;
  747. if (weaponReward.ContainsKey(npcid) && weaponReward[npcid].ContainsKey(type) && weaponReward[npcid][type].Contains(weaponId))
  748. {
  749. vo.isSellOut = true;
  750. }
  751. weaponList.Add(vo);
  752. });
  753. }
  754. return weaponList;
  755. }
  756. /// <summary>
  757. /// 获取补给品商店信息
  758. /// </summary>
  759. /// <param name="npcid"></param>
  760. /// <returns></returns>
  761. public List<ShopSuppliesVo> getShopSuppliesInfo(int npcid)
  762. {
  763. List<ShopSuppliesVo> list = new List<ShopSuppliesVo>();
  764. Dictionary<string, sm_shop_supplies> dic = GameConfigData.Ins.shop_supplies[npcid];
  765. foreach (KeyValuePair<string, sm_shop_supplies> kv in dic)
  766. {
  767. ShopSuppliesVo vo = new ShopSuppliesVo(kv.Value);
  768. vo.typeId = kv.Key;
  769. list.Add(vo);
  770. }
  771. return list;
  772. }
  773. /// <summary>
  774. /// 购买补给品
  775. /// </summary>
  776. /// <param name="npcid"></param>
  777. /// <param name="itemId"></param>
  778. /// <param name="num"></param>
  779. /// <param name="callback"></param>
  780. public void buySupplies(int npcid, int itemId, int num, Action<List<ShopSuppliesVo>> callback)
  781. {
  782. Post(CmdCode.map_buySupplies, new object[] { npcid, itemId, num }, resp =>
  783. {
  784. var p = UserProxy.Instance.player;
  785. p.InitFromStore((JObject)resp.result["store"]);
  786. p.baseInfo.gold -= int.Parse(resp.result["cost"].ToString());
  787. List<ShopSuppliesVo> list = this.getShopSuppliesInfo(npcid);
  788. callback?.Invoke(list);
  789. });
  790. }
  791. /// <summary>
  792. /// 储物间扩容第三个格子
  793. /// </summary>
  794. /// <param name="callback"></param>
  795. public void expandStorage(Action<Dictionary<int, StorageVo>> callback)
  796. {
  797. Post(CmdCode.map_expandStorage, new object[] { }, resp =>
  798. {
  799. var p = UserProxy.Instance.player;
  800. p.initStorageInfo(resp.result["storage"]);
  801. string[] list = resp.result["cost"].ToString().Split(',');
  802. if (int.Parse(list[0]) == (int)EItemSubType.Gold)
  803. {
  804. p.baseInfo.gold -= int.Parse(list[1]);
  805. }
  806. else if (int.Parse(list[0]) == (int)EItemSubType.Gem)
  807. {
  808. p.baseInfo.cash -= int.Parse(list[1]);
  809. }
  810. Dictionary<int, StorageVo> dic = UserProxy.Instance.player.storage;
  811. callback?.Invoke(dic);
  812. });
  813. }
  814. /// <summary>
  815. /// type: 1:放进储物间一个道具/2是从储物间移出一个东西到背包itemType:是武器还是言灵还是其他道具【EItemSubType】;
  816. /// index:第几页(1,2,3)
  817. /// </summary>
  818. /// <param name="type"></param>
  819. /// <param name="uid"></param>
  820. /// <param name="callback"></param>
  821. public void changeStorage(int index, int type, int itemType, int uid, Action<Dictionary<int, StorageVo>> callback)
  822. {
  823. Post(CmdCode.map_changeStorage, new object[] { index, type, itemType, uid }, resp =>
  824. {
  825. var p = UserProxy.Instance.player;
  826. p.InitFromStore((JObject)resp.result["store"]);
  827. Dictionary<int, StorageVo> dic = UserProxy.Instance.player.storage;
  828. callback?.Invoke(dic);
  829. });
  830. }
  831. public Dictionary<int, StorageVo> getStorageVo()
  832. {
  833. Dictionary<int, StorageVo> dic = UserProxy.Instance.player.storage;
  834. return dic;
  835. }
  836. #endregion
  837. #region--------->血瓶 蓝瓶 回城券
  838. /// <summary>
  839. /// 获取槽位信息
  840. /// </summary>
  841. /// <returns></returns>
  842. public Dictionary<int, Ins_battleItem> ChangeBettleItem()
  843. {
  844. return UserProxy.Instance.player.StoreNewFeild.battleItem;
  845. }
  846. /// <summary>
  847. /// type = 0,从背包里添加到槽位;=1.从曹位移除到背包
  848. /// </summary>
  849. /// <param name="type"></param>
  850. /// <param name="index"></param>
  851. /// <param name="itemid"></param>
  852. /// <param name="callback"></param>
  853. public void ChangeBettleItem(int type, int index, int itemid, Action<Dictionary<int, Ins_battleItem>> callback)
  854. {
  855. Post(CmdCode.cmd_store_changeBettleItem, new object[] { type, index, itemid, }, resp =>
  856. {
  857. var p = UserProxy.Instance.player;
  858. p.InitFromStore((JObject)resp.result["store"]);
  859. callback?.Invoke(p.StoreNewFeild.battleItem);
  860. });
  861. }
  862. /// <summary>
  863. /// 使用血瓶、蓝瓶
  864. /// </summary>
  865. /// <param name="index"></param>
  866. /// <param name="callback"></param>
  867. public void UseBattleItem(int index, Action<Dictionary<int, Ins_battleItem>> callback)
  868. {
  869. Post(CmdCode.cmd_store_removeBettleItem, new object[] { index }, resp =>
  870. {
  871. var p = UserProxy.Instance.player;
  872. p.InitFromStore((JObject)resp.result["store"]);
  873. callback?.Invoke(p.StoreNewFeild.battleItem);
  874. });
  875. }
  876. /// <summary>
  877. /// 设置是否自动使用即其值
  878. /// </summary>
  879. /// <param name="index"></param>
  880. /// <param name="val"></param>
  881. /// <param name="callback"></param>
  882. public void setBettleItemUseVal(int index, int val, Action<Dictionary<int, Ins_battleItem>> callback)
  883. {
  884. Post(CmdCode.cmd_store_setBettleItemUseVal, new object[] { index, val }, resp =>
  885. {
  886. var p = UserProxy.Instance.player;
  887. p.InitFromStore((JObject)resp.result["store"]);
  888. callback?.Invoke(p.StoreNewFeild.battleItem);
  889. });
  890. }
  891. /// <summary>
  892. /// 获取回城券vo
  893. /// </summary>
  894. /// <returns></returns>
  895. public ItemVo getTownPortalScroll()
  896. {
  897. List<ItemVo> list = UserProxy.Instance.player.collectItem.GetItemList(EItemSubType.TownPortalScroll);
  898. if (list.Count <= 0)
  899. {
  900. return null;
  901. }
  902. return list[0];
  903. }
  904. #endregion
  905. #region ' 数据直接同步 '
  906. private Dictionary<int, int> itemList = new Dictionary<int, int>();
  907. /// <summary>
  908. /// 添加客户端掉落道具
  909. /// </summary>
  910. /// <param name="itemId"></param>
  911. /// <param name="num"></param>
  912. public void AddItem(int itemId, int num)
  913. {
  914. if (itemId > 0)
  915. {
  916. if ((EItemSubType)sm_item_base.GetMoById(itemId).subType == EItemSubType.BattleItem_HP
  917. || (EItemSubType)sm_item_base.GetMoById(itemId).subType == EItemSubType.BattleItem_MP)
  918. {
  919. UnityEngine.Debug.LogWarning("添加血瓶,蓝瓶" + itemId);
  920. return;
  921. }
  922. if (itemList.ContainsKey(itemId))
  923. {
  924. itemList[itemId] += num;
  925. }
  926. else
  927. {
  928. itemList.Add(itemId, num);
  929. }
  930. if (itemList.Count > 5)
  931. {
  932. UpdateItems();
  933. }
  934. }
  935. else
  936. {
  937. UpdateItems();
  938. }
  939. }
  940. /// <summary>
  941. /// todo: 这里的调用引擎谁来附则?
  942. /// 同步客户端掉落数据到服务器
  943. /// </summary>
  944. public void UpdateItems()
  945. {
  946. if (itemList.Count > 0)
  947. {
  948. var tmp = new Dictionary<int, int>(itemList);
  949. itemList.Clear();
  950. var rwdStr = tmp.ToList().ConvertAll<string>(kv => $"{kv.Key},{kv.Value}").Implode(";");
  951. PutItemInStore(rwdStr, () =>
  952. { /* 成功,无需操作*/
  953. LogHelper.Log(rwdStr);
  954. SplitAndTips(rwdStr);
  955. }, () =>
  956. {
  957. _PutsItemFailCount++;
  958. if (_PutsItemFailCount > 1)
  959. {
  960. //UI_TipsWindow.InitStaticDialog("警告", "我将抛弃此道具!");
  961. _PutsItemFailCount = 0;
  962. }
  963. else
  964. {
  965. tmp.ToList().ForEach(kv => itemList.Add(kv.Key, kv.Value)); // 失败了.再把道具填到列表里,重新来过.
  966. }
  967. });
  968. }
  969. }
  970. /// <summary>
  971. /// 同步背包操作失败计数器, (达到n次以后放弃)
  972. /// </summary>
  973. private static volatile int _PutsItemFailCount = 0;
  974. /// <summary>
  975. /// 将物品字符串拆分解析,然后给出提示
  976. /// </summary>
  977. /// <param name="itemlist"></param>
  978. private void SplitAndTips(string itemlist)
  979. {
  980. if (itemlist.Contains(';'))
  981. {
  982. string[] Items = itemlist.Split(';');
  983. for (int i = 0; i < Items.Length; ++i)
  984. {
  985. string[] item = Items[i].Split(',');
  986. int itemId = int.Parse(item[0]);
  987. int itemNum = int.Parse(item[1]);
  988. ItemVo itemVO = new ItemVo();
  989. itemVO.typeId = itemId.ToString();
  990. itemVO.count = itemNum;
  991. SetGetItemTips(itemVO);
  992. }
  993. }
  994. else
  995. {
  996. string[] item = itemlist.Split(',');
  997. int itemId = int.Parse(item[0]);
  998. int itemNum = int.Parse(item[1]);
  999. ItemVo itemVO = new ItemVo();
  1000. itemVO.typeId = itemId.ToString();
  1001. itemVO.count = itemNum;
  1002. SetGetItemTips(itemVO);
  1003. }
  1004. }
  1005. private void SetGetItemTips(ItemVo vo)
  1006. {
  1007. if (vo.nMo.quality > 1)
  1008. {
  1009. var color = vo.nMo.quality switch
  1010. {
  1011. 2 => "#45e050ff",
  1012. 3 => "#3ab6edff",
  1013. 4 => "#db51e3ff",
  1014. 5 => "#db51e3ff",
  1015. _ => "#000000", // 未知等级
  1016. };
  1017. UI_TipsWindow.InitFloatDialog($"捡取到{vo.count}个<color={color}>{vo.nMo.name}</color>");
  1018. }
  1019. }
  1020. #endregion
  1021. #region ` constructor `
  1022. public ItemProxy() => this.opeCode = OpeCode.ope_store;
  1023. #endregion
  1024. #region Ret vo
  1025. class Ret_Store
  1026. {
  1027. public JObject store;
  1028. }
  1029. class Ret_WeaponUp : Ret_Store
  1030. {
  1031. public int gold;
  1032. }
  1033. class Ret_PutItemInStore : Ret_Store
  1034. {
  1035. public int gold;
  1036. public int tili;
  1037. public int cash;
  1038. public int resPoint;
  1039. }
  1040. class Ret_UseItem : Ret_Store
  1041. {
  1042. public Info_PrivateState priv;
  1043. }
  1044. #endregion
  1045. }