using Newtonsoft.Json.Linq;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
///
/// 道具/背包模块
///
public class ItemProxy : ProxyBase
{
public BagMainUIVo BagMain() => new BagMainUIVo();
#region 英雄碎片
///
/// 6415 碎片合成
///
///
///
///
///
[Obsolete("2019年12月31日")]
public void PiecesCompose(string typeId1, string typeId2, string typeId3, Action callback = null)
{
Post(CmdCode.cmd_store_PiecesCompose, new object[] { typeId1, typeId2, typeId3 }, resp => callback?.Invoke(resp.result));
}
#endregion
///
/// [6412] 购买物品格子数 李宁给定的方案是买一次就是50个钻石,十个格子,不能批量购买.
///
/// 购买数量
/// 成功回调函数
public void AddMaxPacketNum(Action callback)
{
Post(CmdCode.cmd_store_AddMaxPacketNum, new object[] { }, resp => callback?.Invoke(resp.result));
}
#region 装备
///
/// [6413]装备熔炼升级
///
///
///
[Obsolete("2019年12月31日")]
public void MeltUpgradeEquip(int itemuid, Action callback)
{
Post(CmdCode.cmd_store_MeltEquip, new object[] { itemuid }, resp => callback?.Invoke(resp.result));
}
///
/// [6417]让指定英雄脱下该言灵
///
///
///
///
///
public void UnWieldYanling(int ItemType, int ItemuId, int herouid, Action 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());
});
}
///
/// [6416]给英雄装上言灵
///
///
///
///
///
public void WearYanlingToHero(int ItemType, int ItemuId, int herouid, Action 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());
});
}
///
/// 试穿言灵,
///
///
///
/// 战力有增长则返回true,否则返回false
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; // 返回结果
}
///
/// [6411]让指定英雄脱下该装备
///
///
///
///
///
public void UnWieldEquip(int ItemType, int ItemuId, int herouid, Action callback)
{
Post(CmdCode.cmd_store_UnWield, new object[] { 1, ItemuId, herouid }, resp => callback?.Invoke(resp.result["resp"].ToString()));
}
///
/// [6410]给英雄穿装备
///
///
///
///
///
public void WearEquipToHero(int ItemType, int ItemuId, int herouid, Action 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());
});
}
///
/// 试穿武器,
///
///
///
/// 战力有增长则返回true,否则返回false
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; // 返回结果
}
///
/// [6409]宝石合成vc=-0
///
///
///
[Obsolete("2019年12月31日")]
//public void GemCompose(int lowTypeId, int useNum, int highTypeId, int addNum, int needGold, Action callback)
//{
// Post(CmdCode.cmd_store_GemCompose, new object[] { lowTypeId, useNum, highTypeId, addNum, needGold }, resp => callback?.Invoke(resp.result["resp"].ToString()));
//}
///
/// [6408]装备打造升级
///
///
///
//[Obsolete("2019年12月31日")]
public void UpdateItem(int itemuid, int needgold, Dictionary obj, object[] ary, Action callback)
{
Post(CmdCode.cmd_store_ItemUpgrage, new object[] { itemuid, needgold, obj, ary }, resp => callback?.Invoke(resp.result));
}
///
/// [6406]从仓库删除道具
///
///
///
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
///
/// [6405] 刷新背包
///
private void RefreshStore(Action callback)
{
Post(CmdCode.cmd_packet_Refresh, new object[] { }, resp => callback?.Invoke());
}
///
/// [6404] 使用道具
///
public void UseItem(int itemTypeId, int num, Action callback)
{
Post(CmdCode.cmd_packet_useItem, new object[] { itemTypeId, num },
ret =>
{
UserProxy.Instance.player.PrivateState = ret.priv; // ((JObject)resp.result["priv"]).ToObject();
callback?.Invoke();
});
}
///
/// [6403]卖出多个物品
///
/// 卖出物品数量
/// 物品结构
///
public void SellMultiItemFromStore(object[] obj, Action callback)
{
Post(CmdCode.cmd_packet_SellMultiItem, new object[] { obj }, resp => callback.Invoke(resp.result["resp"].ToString()));
}
///
/// [6402] 卖单个物品
///
/// 物品id
/// 物品类型
/// 数量或者uid
///
public void SellItemFromStore(int ItemType, int ItemId, int num, Action callback)
{
Post(CmdCode.cmd_packet_SellSingleItem, new object[] { ItemType, ItemId, num }, resp => callback?.Invoke(resp.result["resp"].ToString()));
}
///
/// [6401]向后台同步奖励数据
///
///
///
public void PutItemInStore(string rwdStr, Action callback, Action fail)
{
Post(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());
}
///
/// [6418]碎片合成言灵召唤书 2020.7.22
///
///
///
public void MergeYanlingBook(int bookId, Action callback)
{
Post(CmdCode.cmd_store_mergeYanlingbook, new object[] { bookId }, resp => callback?.Invoke());
}
///
/// [6419]利用言灵召唤书召唤言灵 2020.7.22
///
///
///
public void CallYanling(int bookId, Action callback)
{
Post(CmdCode.cmd_store_callyanling, new object[] { bookId }, resp => callback?.Invoke());
}
///
/// [6420]言灵进阶 2020.7.29-------废弃
///
///
///
public void YanlingUpgrade(int yanlingUID, Action callback)
{
Post(CmdCode.cmd_store_yanling_upgrade, new object[] { yanlingUID }, resp => callback?.Invoke());
}
///
/// 武器升级
///
///
///
///
///
public void WeaponUpgrade(int uid, List itemList, Action callback)
{
List wuqiList = new List();
Dictionary items = new Dictionary();
foreach (ItemVo vo in itemList)
{
if (vo.IsWeapon)
{
wuqiList.Add(vo.uid);
}
else
{
items[vo.typeId] = vo.count;
}
}
Post(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]);
//});
}
///
/// 武器突破
///
///
///
public void WeaponTupo(int uid, Action callback)
{
Post(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();
//});
}
///
///
///
///
///
///
public void WeaponReplace(int uid, int replaceId, Action callback)
{
Post(CmdCode.cmd_store_weaponReplace, new object[] { uid, replaceId }, resp => callback?.Invoke());
}
///
/// 查看新道具
///
///
///
///
public void RefreshItem(EItemSubType type, int uid, Action callback)
{
Post(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----------->宝石系统
///
/// 所有的宝石信息
///
///
public Dictionary> GetAllGemComposeData()
{
Dictionary> dic = new Dictionary>();
int researchLevel = UserProxy.Instance.player.gemInfo.level;
List allList = new List();
List zlist = new List();
List redlist = new List();
List llist = new List();
List hlist = new List();
List blist = new List();
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 listSort(List 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;
}
///
/// 宝石合成
///
///
///
///
public void GemComposeItem(int gemId, int num, Action>> 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> dic = this.GetAllGemComposeData();
callback?.Invoke(dic);
});
}
///
/// 研究等级提升
///
///
public void GemResearchLvUp(Action 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());
});
}
///
/// 背包里的所有宝石信息
///
///
public Dictionary> StoreGemInfo()
{
Dictionary collectItemDic = UserProxy.Instance.player.collectItem.collectItemDic;
List zlist = new List();
List redlist = new List();
List llist = new List();
List hlist = new List();
List blist = new List();
foreach (KeyValuePair 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> dic = new Dictionary>();
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 listSort_ItemVo(List 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;
}
///
/// 宝石镶嵌
///
///
///
///
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();
});
}
///
/// 宝石卸下
///
///
///
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();
});
}
///
///
///
///
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();
});
}
///
/// 删除所有类型道具
///
///
///
///
///
public void removeItem(List 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();
});
}
///
/// 击杀怪,唤灵师获得的信息加成,暂时是经验
///
///
///
///
public void killMosterAddData(string heroUid, int mosterId, Action 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-------->武器商店
///
/// 获取武器商店里的信息
///
///
///
public void GetShopWeapon(int npcid, Action> callback)
{
Post(CmdCode.map_getShopWeapon, new object[] { npcid }, resp =>
{
var p = UserProxy.Instance.player;
p.InitFromStore((JObject)resp.result["store"]);
List weaponList = this.initShopWeapon(npcid);
callback?.Invoke(weaponList);
});
}
///
/// 购买武器
///
///
///
public void BuyWeapon(int npcid, int weaponId, Action> 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 weaponList = this.initShopWeapon(npcid);
callback?.Invoke(weaponList);
});
}
public List initShopWeapon(int npcid)
{
List weaponList = new List();
if (UserProxy.Instance.player.weaponPool.Count == 0)
{
return weaponList;
}
Dictionary> weaponPool = UserProxy.Instance.player.weaponPool[npcid];
Dictionary>> weaponReward = UserProxy.Instance.player.weaponReward;
List mo = GameConfigData.Ins.shop_weapon[npcid];
foreach (KeyValuePair> 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;
}
///
/// 获取补给品商店信息
///
///
///
public List getShopSuppliesInfo(int npcid)
{
List list = new List();
Dictionary dic = GameConfigData.Ins.shop_supplies[npcid];
foreach (KeyValuePair kv in dic)
{
ShopSuppliesVo vo = new ShopSuppliesVo(kv.Value);
vo.typeId = kv.Key;
list.Add(vo);
}
return list;
}
///
/// 购买补给品
///
///
///
///
///
public void buySupplies(int npcid, int itemId, int num, Action> 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 list = this.getShopSuppliesInfo(npcid);
callback?.Invoke(list);
});
}
///
/// 储物间扩容第三个格子
///
///
public void expandStorage(Action> 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 dic = UserProxy.Instance.player.storage;
callback?.Invoke(dic);
});
}
///
/// type: 1:放进储物间一个道具/2是从储物间移出一个东西到背包itemType:是武器还是言灵还是其他道具【EItemSubType】;
/// index:第几页(1,2,3)
///
///
///
///
public void changeStorage(int index, int type, int itemType, int uid, Action> callback)
{
Post(CmdCode.map_changeStorage, new object[] { index, type, itemType, uid }, resp =>
{
var p = UserProxy.Instance.player;
p.InitFromStore((JObject)resp.result["store"]);
Dictionary dic = UserProxy.Instance.player.storage;
callback?.Invoke(dic);
});
}
public Dictionary getStorageVo()
{
Dictionary dic = UserProxy.Instance.player.storage;
return dic;
}
#endregion
#region--------->血瓶 蓝瓶 回城券
///
/// 获取槽位信息
///
///
public Dictionary ChangeBettleItem()
{
return UserProxy.Instance.player.StoreNewFeild.battleItem;
}
///
/// type = 0,从背包里添加到槽位;=1.从曹位移除到背包
///
///
///
///
///
public void ChangeBettleItem(int type, int index, int itemid, Action> 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);
});
}
///
/// 使用血瓶、蓝瓶
///
///
///
public void UseBattleItem(int index, Action> 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);
});
}
///
/// 设置是否自动使用即其值
///
///
///
///
public void setBettleItemUseVal(int index, int val, Action> 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);
});
}
///
/// 获取回城券vo
///
///
public ItemVo getTownPortalScroll()
{
List list = UserProxy.Instance.player.collectItem.GetItemList(EItemSubType.TownPortalScroll);
if (list.Count <= 0)
{
return null;
}
return list[0];
}
#endregion
#region ' 数据直接同步 '
private Dictionary itemList = new Dictionary();
///
/// 添加客户端掉落道具
///
///
///
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();
}
}
///
/// todo: 这里的调用引擎谁来附则?
/// 同步客户端掉落数据到服务器
///
public void UpdateItems()
{
if (itemList.Count > 0)
{
var tmp = new Dictionary(itemList);
itemList.Clear();
var rwdStr = tmp.ToList().ConvertAll(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)); // 失败了.再把道具填到列表里,重新来过.
}
});
}
}
///
/// 同步背包操作失败计数器, (达到n次以后放弃)
///
private static volatile int _PutsItemFailCount = 0;
///
/// 将物品字符串拆分解析,然后给出提示
///
///
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}个{vo.nMo.name}");
}
}
#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
}