1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192 |
- using Newtonsoft.Json.Linq;
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Diagnostics;
- using UnityEngine;
- /// <summary>
- /// 道具/背包模块
- /// </summary>
- public class ItemProxy : ProxyBase<ItemProxy>
- {
- public BagMainUIVo BagMain() => new BagMainUIVo();
- #region 英雄碎片
- /// <summary>
- /// 6415 碎片合成
- /// </summary>
- /// <param name="typeId1"></param>
- /// <param name="typeId2"></param>
- /// <param name="typeId3"></param>
- /// <param name="callback"></param>
- [Obsolete("2019年12月31日")]
- public void PiecesCompose(string typeId1, string typeId2, string typeId3, Action<JObject> callback = null)
- {
- Post(CmdCode.cmd_store_PiecesCompose, new object[] { typeId1, typeId2, typeId3 }, resp => callback?.Invoke(resp.result));
- }
- #endregion
- /// <summary>
- /// [6412] 购买物品格子数 李宁给定的方案是买一次就是50个钻石,十个格子,不能批量购买.
- /// </summary>
- /// <param name="num">购买数量</param>
- /// <param name="callback">成功回调函数</param>
- public void AddMaxPacketNum(Action<JObject> callback)
- {
- Post(CmdCode.cmd_store_AddMaxPacketNum, new object[] { }, resp => callback?.Invoke(resp.result));
- }
- #region 装备
- /// <summary>
- /// [6413]装备熔炼升级
- /// </summary>
- /// <param name="obj"></param>
- /// <param name="callback"></param>
- [Obsolete("2019年12月31日")]
- public void MeltUpgradeEquip(int itemuid, Action<JObject> callback)
- {
- Post(CmdCode.cmd_store_MeltEquip, new object[] { itemuid }, resp => callback?.Invoke(resp.result));
- }
- /// <summary>
- /// [6417]让指定英雄脱下该言灵
- /// </summary>
- /// <param name="ItemType"></param>
- /// <param name="ItemuId"></param>
- /// <param name="herouid"></param>
- /// <param name="callback"></param>
- public void UnWieldYanling(int ItemType, int ItemuId, int herouid, Action<string> callback)
- {
- Post(CmdCode.cmd_store_UnWieldYanling, new object[] { ItemType, ItemuId, herouid },
- resp =>
- {
- UserProxy.Instance.player.collectYanling.items[ItemuId].herouid = 0;
- UserProxy.Instance.player.collectHero.collectHeroDic[herouid.ToString()].yanling[ItemType] = new HeroGameVo_Yanling() { itemuid = 0 };
- callback?.Invoke(resp.result["resp"].ToString());
- });
- }
- /// <summary>
- /// [6416]给英雄装上言灵
- /// </summary>
- /// <param name="ItemType"></param>
- /// <param name="ItemuId"></param>
- /// <param name="herouid"></param>
- /// <param name="callback"></param>
- public void WearYanlingToHero(int ItemType, int ItemuId, int herouid, Action<string> callback)
- {
- Post(CmdCode.cmd_store_WearYanling, new object[] { ItemType, ItemuId, herouid },
- resp =>
- {
- var p = UserProxy.Instance.player;
- //p.InitFromStore((JObject)resp.result["store"]); // 更新任务卡
- var yanlingVo = p.collectYanling.items[ItemuId];
- yanlingVo.herouid = herouid;
- var oidYanlingId = p.collectHero.collectHeroDic[herouid.ToString()].yanling[ItemType].itemuid;
- if (oidYanlingId > 0 && oidYanlingId != ItemuId)
- {
- p.collectYanling.items[oidYanlingId].herouid = 0;
- }
- sm_item_yanling newYanling = sm_item_yanling.GetMoById(int.Parse(yanlingVo.typeId));
- p.collectHero.collectHeroDic[herouid.ToString()].yanling[ItemType] = new HeroGameVo_Yanling()
- {
- itemuid = ItemuId,
- typeId = int.Parse(yanlingVo.typeId),
- sp_now = newYanling.sp_max,
- cd_now = newYanling.skill_cd
- };
- callback?.Invoke(resp.result["resp"].ToString());
- });
- }
- /// <summary>
- /// 试穿言灵,
- /// </summary>
- /// <param name="yanlingUID"></param>
- /// <param name="heroUID"></param>
- /// <returns>战力有增长则返回true,否则返回false</returns>
- public bool TestWearYanlingToHeroCanImproveFightPower(int yanlingUID, int heroUID)
- {
- var p = UserProxy.Instance.player;
- var yanlingVo = p.collectYanling.items[yanlingUID]; // 言灵对象
- var heroVo = p.collectHero.collectHeroDic[heroUID.ToString()]; // 唤灵师对象
- var yanlingType = yanlingVo.nMo.GetYanlingExt().position;
- var oldPower = heroVo.GetPower(); // 记录当前战力
- var oldYanlingUID = heroVo.yanling[yanlingType]; // 记录旧言灵
- heroVo.yanling[yanlingType] = yanlingUID; // 替换上新言灵
- var newPower = heroVo.GetPower(); // 计算新战力
- heroVo.yanling[yanlingType] = oldYanlingUID; // 换回旧言灵
- return newPower > oldPower; // 返回结果
- }
- /// <summary>
- /// [6411]让指定英雄脱下该装备
- /// </summary>
- /// <param name="ItemType"></param>
- /// <param name="ItemuId"></param>
- /// <param name="herouid"></param>
- /// <param name="callback"></param>
- public void UnWieldEquip(int ItemType, int ItemuId, int herouid, Action<string> callback)
- {
- Post(CmdCode.cmd_store_UnWield, new object[] { 1, ItemuId, herouid }, resp => callback?.Invoke(resp.result["resp"].ToString()));
- }
- /// <summary>
- /// [6410]给英雄穿装备
- /// </summary>
- /// <param name="ItemType"></param>
- /// <param name="ItemuId"></param>
- /// <param name="herouid"></param>
- /// <param name="callback"></param>
- public void WearEquipToHero(int ItemType, int ItemuId, int herouid, Action<string> callback)
- {
- Post(CmdCode.cmd_store_WearEquip, new object[] { 1, ItemuId, herouid },
- resp =>
- {
- var p = UserProxy.Instance.player;
- //p.InitFromStore((JObject)resp.result["store"]); // 更新任务卡
- p.collectEquip.equipments[ItemuId].herouid = herouid;
- var oidYanlingId = int.Parse(p.collectHero.collectHeroDic[herouid.ToString()].equips["weapon"].equipItemUID);
- if (oidYanlingId > 0 && oidYanlingId != ItemuId)
- {
- p.collectEquip.equipments[oidYanlingId].herouid = 0;
- }
- p.collectHero.collectHeroDic[herouid.ToString()].equips["weapon"] = new HeroGameVo_Equip() { equipItemUID = ItemuId.ToString() };
- callback?.Invoke(resp.result["resp"].ToString());
- });
- }
- /// <summary>
- /// 试穿武器,
- /// </summary>
- /// <param name="yanlingUID"></param>
- /// <param name="heroUID"></param>
- /// <returns>战力有增长则返回true,否则返回false</returns>
- public bool TestWearEquipToHeroCanImproveFightPower(int equipUID, int heroUID)
- {
- var p = UserProxy.Instance.player;
- var equipVo = p.collectEquip.equipments[equipUID]; // 言灵对象
- var heroVo = p.collectHero.collectHeroDic[heroUID.ToString()]; // 唤灵师对象
- var weaponType = "weapon";
- var oldPower = heroVo.GetPower(); // 记录当前战力
- int oldEquipUID = heroVo.equips[weaponType]; // 记录旧言灵
- heroVo.equips[weaponType] = equipUID; // 替换上新言灵
- var newPower = heroVo.GetPower(); // 计算新战力
- heroVo.equips[weaponType] = oldEquipUID; // 换回旧言灵
- return newPower > oldPower; // 返回结果
- }
- /// <summary>
- /// [6409]宝石合成vc=-0
- /// </summary>
- /// <param name="obj"></param>
- /// <param name="callback"></param>
- [Obsolete("2019年12月31日")]
- //public void GemCompose(int lowTypeId, int useNum, int highTypeId, int addNum, int needGold, Action<string> callback)
- //{
- // Post(CmdCode.cmd_store_GemCompose, new object[] { lowTypeId, useNum, highTypeId, addNum, needGold }, resp => callback?.Invoke(resp.result["resp"].ToString()));
- //}
- /// <summary>
- /// [6408]装备打造升级
- /// </summary>
- /// <param name="obj"></param>
- /// <param name="callback"></param>
- //[Obsolete("2019年12月31日")]
- public void UpdateItem(int itemuid, int needgold, Dictionary<string, string> obj, object[] ary, Action<JObject> callback)
- {
- Post(CmdCode.cmd_store_ItemUpgrage, new object[] { itemuid, needgold, obj, ary }, resp => callback?.Invoke(resp.result));
- }
- /// <summary>
- /// [6406]从仓库删除道具
- /// </summary>
- /// <param name="obj"></param>
- /// <param name="callback"></param>
- public void DelItemFromStore(int itemuid, int num, Action callback)
- {
- Post(CmdCode.cmd_store_delItem, new object[] { itemuid, num }, resp =>
- {
- //UserProxy.Instance.player.InitFromStore((JObject)resp.result["store"]);
- callback?.Invoke();
- });
- }
- #endregion
- /// <summary>
- /// [6405] 刷新背包
- /// </summary>
- private void RefreshStore(Action callback)
- {
- Post(CmdCode.cmd_packet_Refresh, new object[] { }, resp => callback?.Invoke());
- }
- /// <summary>
- /// [6404] 使用道具
- /// </summary>
- public void UseItem(int itemTypeId, int num, Action callback)
- {
- Post<Ret_UseItem>(CmdCode.cmd_packet_useItem, new object[] { itemTypeId, num },
- ret =>
- {
- UserProxy.Instance.player.PrivateState = ret.priv; // ((JObject)resp.result["priv"]).ToObject<Info_PrivateState>();
- callback?.Invoke();
- });
- }
- /// <summary>
- /// [6403]卖出多个物品
- /// </summary>
- /// <param name="num">卖出物品数量</param>
- /// <param name="obj">物品结构</param>
- /// <param name="callback"></param>
- public void SellMultiItemFromStore(object[] obj, Action<string> callback)
- {
- Post(CmdCode.cmd_packet_SellMultiItem, new object[] { obj }, resp => callback.Invoke(resp.result["resp"].ToString()));
- }
- /// <summary>
- /// [6402] 卖单个物品
- /// </summary>
- /// <param name="ItemId">物品id</param>
- /// <param name="ItemType">物品类型</param>
- /// <param name="num">数量或者uid</param>
- /// <param name="callback"></param>
- public void SellItemFromStore(int ItemType, int ItemId, int num, Action<string> callback)
- {
- Post(CmdCode.cmd_packet_SellSingleItem, new object[] { ItemType, ItemId, num }, resp => callback?.Invoke(resp.result["resp"].ToString()));
- }
- /// <summary>
- /// [6401]向后台同步奖励数据
- /// </summary>
- /// <param name="rwdStr"></param>
- /// <param name="callback"></param>
- public void PutItemInStore(string rwdStr, Action callback, Action fail)
- {
- Post<Ret_PutItemInStore>(CmdCode.cmd_packet_putItemInStore, new object[] { rwdStr, 1 }, ret =>
- {
- var p = UserProxy.Instance.player;
- p.baseInfo.gold = ret.gold;
- p.baseInfo.tili = ret.tili;
- p.baseInfo.cash = ret.cash;
- p.baseInfo.resPoint = ret.resPoint;
- callback?.Invoke();
- }, err => fail?.Invoke());
- //Post(CmdCode.cmd_packet_putItemInStore, new object[] { rwdStr, 1 }, resp =>
- //{
- // var p = UserProxy.Instance.player;
- // p.baseInfo.gold = Convert.ToInt32(resp.result["gold"].ToString());
- // p.baseInfo.cash = Convert.ToInt32(resp.result["cash"].ToString());
- // p.baseInfo.resPoint = Convert.ToInt32(resp.result["resPoint"].ToString());
- // callback?.Invoke();
- //}, err => fail?.Invoke());
- }
- /// <summary>
- /// [6418]碎片合成言灵召唤书 2020.7.22
- /// </summary>
- /// <param name="bookId"></param>
- /// <param name="callback"></param>
- public void MergeYanlingBook(int bookId, Action callback)
- {
- Post(CmdCode.cmd_store_mergeYanlingbook, new object[] { bookId }, resp => callback?.Invoke());
- }
- /// <summary>
- /// [6419]利用言灵召唤书召唤言灵 2020.7.22
- /// </summary>
- /// <param name="bookId"></param>
- /// <param name="callback"></param>
- public void CallYanling(int bookId, Action callback)
- {
- Post(CmdCode.cmd_store_callyanling, new object[] { bookId }, resp => callback?.Invoke());
- }
- /// <summary>
- /// [6420]言灵进阶 2020.7.29-------废弃
- /// </summary>
- /// <param name="bookId"></param>
- /// <param name="callback"></param>
- public void YanlingUpgrade(int yanlingUID, Action callback)
- {
- Post(CmdCode.cmd_store_yanling_upgrade, new object[] { yanlingUID }, resp => callback?.Invoke());
- }
- /// <summary>
- /// 武器升级
- /// </summary>
- /// <param name="uid"></param>
- /// <param name="wuqiList"></param>
- /// <param name="items"></param>
- /// <param name="callback"></param>
- public void WeaponUpgrade(int uid, List<ItemVo> itemList, Action<UserEquipmentVo> callback)
- {
- List<string> wuqiList = new List<string>();
- Dictionary<string, int> items = new Dictionary<string, int>();
- foreach (ItemVo vo in itemList)
- {
- if (vo.IsWeapon)
- {
- wuqiList.Add(vo.uid);
- }
- else
- {
- items[vo.typeId] = vo.count;
- }
- }
- Post<Ret_WeaponUp>(CmdCode.cmd_store_weapon_upgrade, new object[] { uid, wuqiList, items }, ret =>
- {
- var p = UserProxy.Instance.player;
- p.baseInfo.gold = ret.gold; // int.Parse(resp.result["gold"].ToString());
- callback?.Invoke(p.collectEquip.equipments[uid]);
- });
- //Post(CmdCode.cmd_store_weapon_upgrade, new object[] { uid, wuqiList, items }, resp =>
- //{
- // var p = UserProxy.Instance.player;
- // p.InitFromStore((JObject)resp.result["store"]);
- // UserProxy.Instance.player.baseInfo.gold = int.Parse(resp.result["gold"].ToString());
- // callback?.Invoke(p.collectEquip.equipments[uid]);
- //});
- }
- /// <summary>
- /// 武器突破
- /// </summary>
- /// <param name="yanlingUID"></param>
- /// <param name="callback"></param>
- public void WeaponTupo(int uid, Action callback)
- {
- Post<Ret_WeaponUp>(CmdCode.cmd_store_weapon_tupo, new object[] { uid }, resp =>
- {
- UserProxy.Instance.player.baseInfo.gold = resp.gold; // int.Parse(resp.result["gold"].ToString());
- callback?.Invoke();
- });
- //Post(CmdCode.cmd_store_weapon_tupo, new object[] { uid }, resp =>
- //{
- // UserProxy.Instance.player.baseInfo.gold = int.Parse(resp.result["gold"].ToString());
- // callback?.Invoke();
- //});
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="uid"></param>
- /// <param name="replaceId"></param>
- /// <param name="callback"></param>
- public void WeaponReplace(int uid, int replaceId, Action callback)
- {
- Post(CmdCode.cmd_store_weaponReplace, new object[] { uid, replaceId }, resp => callback?.Invoke());
- }
- /// <summary>
- /// 查看新道具
- /// </summary>
- /// <param name="type"></param>
- /// <param name="uid"></param>
- /// <param name="callback"></param>
- public void RefreshItem(EItemSubType type, int uid, Action callback)
- {
- Post<Ret_Store>(CmdCode.cmd_store_refreshItem, new object[] { (int)type, uid }, ret =>
- {
- //var p = UserProxy.Instance.player;
- //p.InitFromStore(ret.store); // (JObject)resp.result["store"]);
- callback?.Invoke();
- });
- }
- #region----------->宝石系统
- /// <summary>
- /// 所有的宝石信息
- /// </summary>
- /// <returns></returns>
- public Dictionary<int, List<GemDataVo>> GetAllGemComposeData()
- {
- Dictionary<int, List<GemDataVo>> dic = new Dictionary<int, List<GemDataVo>>();
- int researchLevel = UserProxy.Instance.player.gemInfo.level;
- List<string> allList = new List<string>();
- List<GemDataVo> zlist = new List<GemDataVo>();
- List<GemDataVo> redlist = new List<GemDataVo>();
- List<GemDataVo> llist = new List<GemDataVo>();
- List<GemDataVo> hlist = new List<GemDataVo>();
- List<GemDataVo> blist = new List<GemDataVo>();
- for (int i = 1; i <= researchLevel; i++)
- {
- string[] gemIsList = GameConfigData.Ins.Getgem_researchlevelMo(i).unlockGemIds.Split(',');
- foreach (string id in gemIsList)
- {
- sm_gem_formula gemMo = GameConfigData.Ins.Getgem_formulaMo(int.Parse(id));
- GemDataVo vo = new GemDataVo(int.Parse(id));
- string type = id[..4];
- switch (type)
- {
- case "7011":
- zlist.Add(vo);
- break;
- case "7012":
- redlist.Add(vo);
- break;
- case "7013":
- llist.Add(vo);
- break;
- case "7014":
- hlist.Add(vo);
- break;
- case "7015":
- blist.Add(vo);
- break;
- }
- }
- }
- if (zlist.Count != 0)
- {
- dic[7011] = this.listSort(zlist);
- }
- if (redlist.Count != 0)
- {
- dic[7012] = this.listSort(redlist);
- }
- if (llist.Count != 0)
- {
- dic[7013] = this.listSort(llist);
- }
- if (hlist.Count != 0)
- {
- dic[7014] = this.listSort(hlist);
- }
- if (blist.Count != 0)
- {
- dic[7015] = this.listSort(blist);
- }
- return dic;
- }
- public List<GemDataVo> listSort(List<GemDataVo> arr)
- {
- int n = arr.Count;
- GemDataVo temp_v = null;
- int j = 0;
- for (int i = 0; i < n - 1; i++)
- {
- for (j = i + 1; j < n; j++)
- {
- if (arr[i].itemMo.quality > arr[j].itemMo.quality)
- {
- temp_v = arr[i];
- arr[i] = arr[j];
- arr[j] = temp_v;
- }
- else if (arr[i].itemMo.quality == arr[j].itemMo.quality && arr[i].itemMo.typeId < arr[j].itemMo.typeId)
- {
- temp_v = arr[i];
- arr[i] = arr[j];
- arr[j] = temp_v;
- }
- }
- }
- return arr;
- }
- /// <summary>
- /// 宝石合成
- /// </summary>
- /// <param name="gemId"></param>
- /// <param name="num"></param>
- /// <param name="callback"></param>
- public void GemComposeItem(int gemId, int num, Action<Dictionary<int, List<GemDataVo>>> callback)
- {
- Post(CmdCode.cmd_store_GemCompose, new object[] { gemId, num }, resp =>
- {
- var p = UserProxy.Instance.player;
- p.InitFromStore((JObject)resp.result["store"]);
- p.baseInfo.gold = Convert.ToInt32(resp.result["gold"].ToString());
- Dictionary<int, List<GemDataVo>> dic = this.GetAllGemComposeData();
- callback?.Invoke(dic);
- });
- }
- /// <summary>
- /// 研究等级提升
- /// </summary>
- /// <param name="callback"></param>
- public void GemResearchLvUp(Action<ResearchVo> callback)
- {
- Post(CmdCode.cmd_store_GemResearchLvUp, new object[] { }, resp =>
- {
- var p = UserProxy.Instance.player;
- //p.InitFromStore((JObject)resp.result["store"]);
- p.baseInfo.gold = Convert.ToInt32(resp.result["gold"].ToString());
- p.gemInfo.level = Convert.ToInt32(resp.result["lv"].ToString());
- callback?.Invoke(new ResearchVo());
- });
- }
- /// <summary>
- /// 背包里的所有宝石信息
- /// </summary>
- /// <returns></returns>
- public Dictionary<int, List<ItemVo>> StoreGemInfo()
- {
- Dictionary<string, ItemVo> collectItemDic = UserProxy.Instance.player.collectItem.collectItemDic;
- List<ItemVo> zlist = new List<ItemVo>();
- List<ItemVo> redlist = new List<ItemVo>();
- List<ItemVo> llist = new List<ItemVo>();
- List<ItemVo> hlist = new List<ItemVo>();
- List<ItemVo> blist = new List<ItemVo>();
- foreach (KeyValuePair<string, ItemVo> kv in collectItemDic)
- {
- if (kv.Value.nMo.subType != (int)EItemSubType.Gemstone)
- {
- continue;
- }
- string type = kv.Key.Substring(0, 4);
- switch (type)
- {
- case "7011":
- zlist.Add(kv.Value);
- break;
- case "7012":
- redlist.Add(kv.Value);
- break;
- case "7013":
- llist.Add(kv.Value);
- break;
- case "7014":
- hlist.Add(kv.Value);
- break;
- case "7015":
- blist.Add(kv.Value);
- break;
- }
- }
- Dictionary<int, List<ItemVo>> dic = new Dictionary<int, List<ItemVo>>();
- if (zlist.Count != 0)
- {
- dic[7011] = this.listSort_ItemVo(zlist);
- }
- if (redlist.Count != 0)
- {
- dic[7012] = this.listSort_ItemVo(redlist);
- }
- if (llist.Count != 0)
- {
- dic[7013] = this.listSort_ItemVo(llist);
- }
- if (hlist.Count != 0)
- {
- dic[7014] = this.listSort_ItemVo(hlist);
- }
- if (blist.Count != 0)
- {
- dic[7015] = this.listSort_ItemVo(blist);
- }
- //dic[7011] = this.listSort_ItemVo(zlist);
- //dic[7012] = this.listSort_ItemVo(redlist);
- //dic[7013] = this.listSort_ItemVo(llist);
- //dic[7014] = this.listSort_ItemVo(hlist);
- //dic[7015] = this.listSort_ItemVo(blist);
- return dic;
- }
- public List<ItemVo> listSort_ItemVo(List<ItemVo> arr)
- {
- int n = arr.Count;
- ItemVo temp_v = null;
- int j = 0;
- for (int i = 0; i < n - 1; i++)
- {
- for (j = i + 1; j < n; j++)
- {
- if (arr[i].nMo.quality > arr[j].nMo.quality)
- {
- temp_v = arr[i];
- arr[i] = arr[j];
- arr[j] = temp_v;
- }
- else if (arr[i].nMo.quality == arr[j].nMo.quality && arr[i].nMo.typeId < arr[j].nMo.typeId)
- {
- temp_v = arr[i];
- arr[i] = arr[j];
- arr[j] = temp_v;
- }
- }
- }
- return arr;
- }
- /// <summary>
- /// 宝石镶嵌
- /// </summary>
- /// <param name="gemId"></param>
- /// <param name="yanlingUid"></param>
- /// <param name="callback"></param>
- public void GemSet(int gemId, int yanlingUid, Action callback)
- {
- Post(CmdCode.cmd_store_GemSet, new object[] { gemId, yanlingUid }, resp =>
- {
- var p = UserProxy.Instance.player;
- p.InitFromStore((JObject)resp.result["store"]);
- callback?.Invoke();
- });
- }
- /// <summary>
- /// 宝石卸下
- /// </summary>
- /// <param name="yanlingUid"></param>
- /// <param name="callback"></param>
- public void GemRemove(int yanlingUid, Action callback)
- {
- Post(CmdCode.cmd_store_GemRemove, new object[] { yanlingUid }, resp =>
- {
- var p = UserProxy.Instance.player;
- p.InitFromStore((JObject)resp.result["store"]);
- callback?.Invoke();
- });
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="callback"></param>
- public void UnlockStore(Action callback)
- {
- Post(CmdCode.cmd_store_unlockStore, new object[] { }, resp =>
- {
- var p = UserProxy.Instance.player;
- //p.InitFromStore((JObject)resp.result["store"]);
- p.baseInfo.gold = Convert.ToInt32(resp.result["gold"].ToString());
- p.PrivateState.expandNum = Convert.ToInt32(resp.result["expandNum"].ToString());
- callback?.Invoke();
- });
- }
- /// <summary>
- /// 删除所有类型道具
- /// </summary>
- /// <param name="subType"></param>
- /// <param name="id"></param>
- /// <param name="num"></param>
- /// <param name="callback"></param>
- public void removeItem(List<ItemVo> list, Action callback)
- {
- string str = "";
- int count = list.Count;
- int index = 0;
- foreach (ItemVo vo in list)
- {
- index += 1;
- int type = vo.nMo.itemType;
- string uid = vo.uid;
- string id = vo.typeId;
- int num = vo.count;
- string s = "";
- if (index >= count)
- {
- s = type + "-" + uid + "-" + id + "-" + num;
- }
- else
- {
- s = type + "-" + uid + "-" + id + "-" + num + ";";
- }
- str += s;
- }
- Post(CmdCode.cmd_store_removeItem, new object[] { str }, resp =>
- {
- var p = UserProxy.Instance.player;
- p.InitFromStore((JObject)resp.result["store"]);
- callback?.Invoke();
- });
- }
- /// <summary>
- /// 击杀怪,唤灵师获得的信息加成,暂时是经验
- /// </summary>
- /// <param name="heroUid"></param>
- /// <param name="mosterId"></param>
- /// <param name="callback"></param>
- public void killMosterAddData(string heroUid, int mosterId, Action<int> callback)
- {
- Post(CmdCode.cmd_store_killMosterAddData, new object[] { heroUid, mosterId }, resp =>
- {
- var p = UserProxy.Instance.player;
- int exp = Convert.ToInt32(resp.result["exp"].ToString());
- var hero = UserProxy.Instance.player.collectHero.UpdateHero(JObject.FromObject(resp.result["hero"]));
- callback?.Invoke(exp);
- });
- }
- #endregion
- #region-------->武器商店
- /// <summary>
- /// 获取武器商店里的信息
- /// </summary>
- /// <param name="npcid"></param>
- /// <param name="callback"></param>
- public void GetShopWeapon(int npcid, Action<List<UserEquipmentVo>> callback)
- {
- Post(CmdCode.map_getShopWeapon, new object[] { npcid }, resp =>
- {
- var p = UserProxy.Instance.player;
- p.InitFromStore((JObject)resp.result["store"]);
- List<UserEquipmentVo> weaponList = this.initShopWeapon(npcid);
- callback?.Invoke(weaponList);
- });
- }
- /// <summary>
- /// 购买武器
- /// </summary>
- /// <param name="npcid"></param>
- /// <param name="callback"></param>
- public void BuyWeapon(int npcid, int weaponId, Action<List<UserEquipmentVo>> callback)
- {
- Post(CmdCode.map_buyWeapon, new object[] { npcid, weaponId }, resp =>
- {
- var p = UserProxy.Instance.player;
- p.InitFromStore((JObject)resp.result["store"]);
- p.baseInfo.gold -= int.Parse(resp.result["cost"].ToString());
- List<UserEquipmentVo> weaponList = this.initShopWeapon(npcid);
- callback?.Invoke(weaponList);
- });
- }
- public List<UserEquipmentVo> initShopWeapon(int npcid)
- {
- List<UserEquipmentVo> weaponList = new List<UserEquipmentVo>();
- if (UserProxy.Instance.player.weaponPool.Count == 0)
- {
- return weaponList;
- }
- Dictionary<int, List<int>> weaponPool = UserProxy.Instance.player.weaponPool[npcid];
- Dictionary<int, Dictionary<int, List<int>>> weaponReward = UserProxy.Instance.player.weaponReward;
- List<sm_shop_weapon> mo = GameConfigData.Ins.shop_weapon[npcid];
- foreach (KeyValuePair<int, List<int>> kv in weaponPool)
- {
- int type = kv.Key;
- int cost = 0;
- foreach (sm_shop_weapon item in mo)
- {
- if (item.id == type)
- {
- cost = int.Parse(item.cost);
- break;
- }
- }
- kv.Value.ForEach(weaponId =>
- {
- UserEquipmentVo vo = new UserEquipmentVo();
- vo.typeId = weaponId.ToString();
- vo.level = 1;
- vo.starLevel = 0;
- vo.cost = cost;
- vo.isSellOut = false;
- if (weaponReward.ContainsKey(npcid) && weaponReward[npcid].ContainsKey(type) && weaponReward[npcid][type].Contains(weaponId))
- {
- vo.isSellOut = true;
- }
- weaponList.Add(vo);
- });
- }
- return weaponList;
- }
- /// <summary>
- /// 获取补给品商店信息
- /// </summary>
- /// <param name="npcid"></param>
- /// <returns></returns>
- public List<ShopSuppliesVo> getShopSuppliesInfo(int npcid)
- {
- List<ShopSuppliesVo> list = new List<ShopSuppliesVo>();
- Dictionary<string, sm_shop_supplies> dic = GameConfigData.Ins.shop_supplies[npcid];
- foreach (KeyValuePair<string, sm_shop_supplies> kv in dic)
- {
- ShopSuppliesVo vo = new ShopSuppliesVo(kv.Value);
- vo.typeId = kv.Key;
- list.Add(vo);
- }
- return list;
- }
- /// <summary>
- /// 购买补给品
- /// </summary>
- /// <param name="npcid"></param>
- /// <param name="itemId"></param>
- /// <param name="num"></param>
- /// <param name="callback"></param>
- public void buySupplies(int npcid, int itemId, int num, Action<List<ShopSuppliesVo>> callback)
- {
- Post(CmdCode.map_buySupplies, new object[] { npcid, itemId, num }, resp =>
- {
- var p = UserProxy.Instance.player;
- p.InitFromStore((JObject)resp.result["store"]);
- p.baseInfo.gold -= int.Parse(resp.result["cost"].ToString());
- List<ShopSuppliesVo> list = this.getShopSuppliesInfo(npcid);
- callback?.Invoke(list);
- });
- }
- /// <summary>
- /// 储物间扩容第三个格子
- /// </summary>
- /// <param name="callback"></param>
- public void expandStorage(Action<Dictionary<int, StorageVo>> callback)
- {
- Post(CmdCode.map_expandStorage, new object[] { }, resp =>
- {
- var p = UserProxy.Instance.player;
- p.initStorageInfo(resp.result["storage"]);
- string[] list = resp.result["cost"].ToString().Split(',');
- if (int.Parse(list[0]) == (int)EItemSubType.Gold)
- {
- p.baseInfo.gold -= int.Parse(list[1]);
- }
- else if (int.Parse(list[0]) == (int)EItemSubType.Gem)
- {
- p.baseInfo.cash -= int.Parse(list[1]);
- }
- Dictionary<int, StorageVo> dic = UserProxy.Instance.player.storage;
- callback?.Invoke(dic);
- });
- }
- /// <summary>
- /// type: 1:放进储物间一个道具/2是从储物间移出一个东西到背包itemType:是武器还是言灵还是其他道具【EItemSubType】;
- /// index:第几页(1,2,3)
- /// </summary>
- /// <param name="type"></param>
- /// <param name="uid"></param>
- /// <param name="callback"></param>
- public void changeStorage(int index, int type, int itemType, int uid, Action<Dictionary<int, StorageVo>> callback)
- {
- Post(CmdCode.map_changeStorage, new object[] { index, type, itemType, uid }, resp =>
- {
- var p = UserProxy.Instance.player;
- p.InitFromStore((JObject)resp.result["store"]);
- Dictionary<int, StorageVo> dic = UserProxy.Instance.player.storage;
- callback?.Invoke(dic);
- });
- }
- public Dictionary<int, StorageVo> getStorageVo()
- {
- Dictionary<int, StorageVo> dic = UserProxy.Instance.player.storage;
- return dic;
- }
- #endregion
- #region--------->血瓶 蓝瓶 回城券
- /// <summary>
- /// 获取槽位信息
- /// </summary>
- /// <returns></returns>
- public Dictionary<int, Ins_battleItem> ChangeBettleItem()
- {
- return UserProxy.Instance.player.StoreNewFeild.battleItem;
- }
- /// <summary>
- /// type = 0,从背包里添加到槽位;=1.从曹位移除到背包
- /// </summary>
- /// <param name="type"></param>
- /// <param name="index"></param>
- /// <param name="itemid"></param>
- /// <param name="callback"></param>
- public void ChangeBettleItem(int type, int index, int itemid, Action<Dictionary<int, Ins_battleItem>> callback)
- {
- Post(CmdCode.cmd_store_changeBettleItem, new object[] { type, index, itemid, }, resp =>
- {
- var p = UserProxy.Instance.player;
- p.InitFromStore((JObject)resp.result["store"]);
- callback?.Invoke(p.StoreNewFeild.battleItem);
- });
- }
- /// <summary>
- /// 使用血瓶、蓝瓶
- /// </summary>
- /// <param name="index"></param>
- /// <param name="callback"></param>
- public void UseBattleItem(int index, Action<Dictionary<int, Ins_battleItem>> callback)
- {
- Post(CmdCode.cmd_store_removeBettleItem, new object[] { index }, resp =>
- {
- var p = UserProxy.Instance.player;
- p.InitFromStore((JObject)resp.result["store"]);
- callback?.Invoke(p.StoreNewFeild.battleItem);
- });
- }
- /// <summary>
- /// 设置是否自动使用即其值
- /// </summary>
- /// <param name="index"></param>
- /// <param name="val"></param>
- /// <param name="callback"></param>
- public void setBettleItemUseVal(int index, int val, Action<Dictionary<int, Ins_battleItem>> callback)
- {
- Post(CmdCode.cmd_store_setBettleItemUseVal, new object[] { index, val }, resp =>
- {
- var p = UserProxy.Instance.player;
- p.InitFromStore((JObject)resp.result["store"]);
- callback?.Invoke(p.StoreNewFeild.battleItem);
- });
- }
- /// <summary>
- /// 获取回城券vo
- /// </summary>
- /// <returns></returns>
- public ItemVo getTownPortalScroll()
- {
- List<ItemVo> list = UserProxy.Instance.player.collectItem.GetItemList(EItemSubType.TownPortalScroll);
- if (list.Count <= 0)
- {
- return null;
- }
- return list[0];
- }
- #endregion
- #region ' 数据直接同步 '
- private Dictionary<int, int> itemList = new Dictionary<int, int>();
- /// <summary>
- /// 添加客户端掉落道具
- /// </summary>
- /// <param name="itemId"></param>
- /// <param name="num"></param>
- public void AddItem(int itemId, int num)
- {
- if (itemId > 0)
- {
- if ((EItemSubType)sm_item_base.GetMoById(itemId).subType == EItemSubType.BattleItem_HP
- || (EItemSubType)sm_item_base.GetMoById(itemId).subType == EItemSubType.BattleItem_MP)
- {
- UnityEngine.Debug.LogWarning("添加血瓶,蓝瓶" + itemId);
- return;
- }
- if (itemList.ContainsKey(itemId))
- {
- itemList[itemId] += num;
- }
- else
- {
- itemList.Add(itemId, num);
- }
- if (itemList.Count > 5)
- {
- UpdateItems();
- }
- }
- else
- {
- UpdateItems();
- }
- }
- /// <summary>
- /// todo: 这里的调用引擎谁来附则?
- /// 同步客户端掉落数据到服务器
- /// </summary>
- public void UpdateItems()
- {
- if (itemList.Count > 0)
- {
- var tmp = new Dictionary<int, int>(itemList);
- itemList.Clear();
- var rwdStr = tmp.ToList().ConvertAll<string>(kv => $"{kv.Key},{kv.Value}").Implode(";");
- PutItemInStore(rwdStr, () =>
- { /* 成功,无需操作*/
- LogHelper.Log(rwdStr);
- SplitAndTips(rwdStr);
- }, () =>
- {
- _PutsItemFailCount++;
- if (_PutsItemFailCount > 1)
- {
- //UI_TipsWindow.InitStaticDialog("警告", "我将抛弃此道具!");
- _PutsItemFailCount = 0;
- }
- else
- {
- tmp.ToList().ForEach(kv => itemList.Add(kv.Key, kv.Value)); // 失败了.再把道具填到列表里,重新来过.
- }
- });
- }
- }
- /// <summary>
- /// 同步背包操作失败计数器, (达到n次以后放弃)
- /// </summary>
- private static volatile int _PutsItemFailCount = 0;
- /// <summary>
- /// 将物品字符串拆分解析,然后给出提示
- /// </summary>
- /// <param name="itemlist"></param>
- private void SplitAndTips(string itemlist)
- {
- if (itemlist.Contains(';'))
- {
- string[] Items = itemlist.Split(';');
- for (int i = 0; i < Items.Length; ++i)
- {
- string[] item = Items[i].Split(',');
- int itemId = int.Parse(item[0]);
- int itemNum = int.Parse(item[1]);
- ItemVo itemVO = new ItemVo();
- itemVO.typeId = itemId.ToString();
- itemVO.count = itemNum;
- SetGetItemTips(itemVO);
- }
- }
- else
- {
- string[] item = itemlist.Split(',');
- int itemId = int.Parse(item[0]);
- int itemNum = int.Parse(item[1]);
- ItemVo itemVO = new ItemVo();
- itemVO.typeId = itemId.ToString();
- itemVO.count = itemNum;
- SetGetItemTips(itemVO);
- }
- }
- private void SetGetItemTips(ItemVo vo)
- {
- if (vo.nMo.quality > 1)
- {
- var color = vo.nMo.quality switch
- {
- 2 => "#45e050ff",
- 3 => "#3ab6edff",
- 4 => "#db51e3ff",
- 5 => "#db51e3ff",
- _ => "#000000", // 未知等级
- };
- UI_TipsWindow.InitFloatDialog($"捡取到{vo.count}个<color={color}>{vo.nMo.name}</color>");
- }
- }
- #endregion
- #region ` constructor `
- public ItemProxy() => this.opeCode = OpeCode.ope_store;
- #endregion
- #region Ret vo
- class Ret_Store
- {
- public JObject store;
- }
- class Ret_WeaponUp : Ret_Store
- {
- public int gold;
- }
- class Ret_PutItemInStore : Ret_Store
- {
- public int gold;
- public int tili;
- public int cash;
- public int resPoint;
- }
- class Ret_UseItem : Ret_Store
- {
- public Info_PrivateState priv;
- }
- #endregion
- }
|