/// <summary> /// 更新物品。 /// </summary> /// <param name="data">网络消息数据。</param> private void OnItemUpdate(MsgData data) { MsgData_sItemUpdate info = data as MsgData_sItemUpdate; BagInfo bag = GetBagInfo(info.Bag); if (bag != null) { ItemInfo iteminfo = bag.GetItemInfo(info.Pos); if (iteminfo == null) { return; } bool newuid = iteminfo.UID != info.UID; if (newuid) { mItems.Remove(iteminfo.UID); } bag.UpdateItem(info); if (newuid) { mItems.Add(info.UID, bag.GetItemInfo(info.Pos)); } TriggerEventItemUpdate(info.Bag, info.Pos); if (info.Bag == BagType.ITEM_BAG_TYPE_EQUIP) { ShowEquipChange(info.ID); } } else { LogMgr.ErrorLog("未知背包编号 id:{0}", info.Bag); } }
/// <summary> /// 初始化背包信息。 /// </summary> /// <param name="data">网络消息数据。</param> private void OnBagInfo(MsgData data) { MsgData_sQueryItemResult info = data as MsgData_sQueryItemResult; BagInfo bag = GetBagInfo(info.Bag); if (bag != null) { //从mItems删除原来背包的东西 foreach (var kvp in bag.ItemInfos) { mItems.Remove(kvp.Value.UID); } bag.Init(info); //重新添加 foreach (var kvp in bag.ItemInfos) { mItems.Add(kvp.Value.UID, kvp.Value); } TriggerEventBagInfo(bag.BagType); } else { LogMgr.ErrorLog("未知背包编号 id:{0}", info.Bag); } }
/// <summary> /// 删除物品。 /// </summary> /// <param name="data">网络消息数据。</param> private void OnItemDel(MsgData data) { MsgData_sItemDel info = data as MsgData_sItemDel; BagInfo bag = GetBagInfo(info.Bag); if (bag != null) { ItemInfo iteminfo = bag.GetItemInfo(info.Pos); if (mCacheAddUID == iteminfo.UID) { //抵消前一个Add mCacheAddUID = 0; } else { mItems.Remove(iteminfo.UID); } bag.DeleteItem(info.Pos); TriggerEventItemDel(1, info.Bag, info.Pos, iteminfo.UID); } else { LogMgr.ErrorLog("未知背包编号 id:{0}", info.Bag); } }
/// <summary> /// 构造函数。 /// </summary> public BagData() { for (int i = 0; i < mBags.Length; ++i) { mBags[i] = new BagInfo(); } }
private void OnBagChange(GameEvent ge, EventParameter parameter) { //装备背包变更 if (parameter.intParameter == BagType.ITEM_BAG_TYPE_EQUIP) { BagInfo baginfo = PlayerData.Instance.BagData.GetBagInfo(BagType.ITEM_BAG_TYPE_EQUIP); int olddress = Dress; //mBasicAttr.Dress = baginfo.GetItemID(PlayerEquipPos.Cloth); if (FashionDress == 0 && olddress != Dress) { EventParameter ep = EventParameter.Get(); ep.intParameter = (int)EModelChange.MODEL_CHANGE_DRESS; CoreEntry.gEventMgr.TriggerEvent(GameEvent.GE_PLAYER_SHOW_CHANGED, ep); } int oldweapon = Weapon; if (baginfo != null) { mBasicAttr.Weapon = baginfo.GetItemID(PlayerEquipPos.Weapon); } if (FashionWeapon == 0 && oldweapon != Weapon) { EventParameter ep = EventParameter.Get(); ep.intParameter = (int)EModelChange.MODEL_CHANGE_WEAPON; CoreEntry.gEventMgr.TriggerEvent(GameEvent.GE_PLAYER_SHOW_CHANGED, ep); } } if (parameter.intParameter == BagType.ITEM_BAG_TYPE_ROLEITEM) { } }
/// <summary> /// 添加物品。 /// </summary> /// <param name="data">网络消息数据。</param> private void OnItemAdd(MsgData data) { MsgData_sItemAdd info = data as MsgData_sItemAdd; BagInfo bag = GetBagInfo(info.Bag); if (bag != null) { bag.AddItem(info); if (mItems.ContainsKey(info.UID)) { //额外多Add了一次,下次Del时抵消 mCacheAddUID = info.UID; mItems.Remove(mCacheAddUID); } mItems.Add(info.UID, bag.GetItemInfo(info.Pos)); TriggerEventItemAdd(info.Bag, info.Pos); if (info.Bag == BagType.ITEM_BAG_TYPE_EQUIP) { ShowEquipChange(info.ID); } } else { LogMgr.ErrorLog("未知背包编号 id:{0}", info.Bag); } }
/// <summary> /// 背包扩充提示。 /// </summary> /// <param name="data">网络消息数据。</param> private void OnExpandBagTips(MsgData data) { MsgData_sExpandBagTips info = data as MsgData_sExpandBagTips; LogMgr.Log("背包扩充提示 bag:{0}", info.Bag); BagInfo bag = GetBagInfo(info.Bag); if (bag != null) { SendExpandBagRequest(info.Bag, bag.Size + 1, 0); } }
/// <summary> /// 发送背包扩展请求。 /// </summary> /// <param name="bag">背包类型。</param> /// <param name="size">新格子数。</param> /// <param name="mt">物品不足时:0不扩展 1消耗元宝(优先绑定)</param> public void SendExpandBagRequest(int bag, int size, int mt) { BagInfo baginfo = GetBagInfo(bag); if (baginfo != null) { MsgData_cExpandBag data = new MsgData_cExpandBag(); data.Bag = bag; data.NewSize = size - baginfo.Size; data.MoneyType = mt; CoreEntry.netMgr.send((Int16)NetMsgDef.C_EXPAND_BAG, data); } }
void OnWudi() { string strResult = System.String.Empty; MsgData_sItemTips msg = new MsgData_sItemTips(); msg.items = new List <MsgData_sItemTipsVO>(); BagInfo bag = PlayerData.Instance.BagData.GetBagInfo(BagType.ITEM_BAG_TYPE_COMMON); if (bag != null) { foreach (KeyValuePair <int, ItemInfo> key in bag.ItemInfos) { MsgData_sItemTipsVO itemdata = new MsgData_sItemTipsVO(); itemdata.type = 1; itemdata.id = key.Value.ID; itemdata.count = key.Value.Count; msg.items.Add(itemdata); } } CoreEntry.gEventMgr.TriggerEvent(GameEvent.GE_ITEMTIPS, EventParameter.Get(msg)); //LuaTable tbl = LuaMgr.Instance.GetLuaEnv().Global.Get<LuaTable>("t_equip"); if (mGmMgr.WuDi()) { if (mHotKeyBtn.image.color == Color.gray) { mHotKeyBtn.image.color = Color.white; strResult = "取消" + mHotKeyMap[mHotKeyIndex].strName + "成功"; mHotKeyLabel.text = mHotKeyMap[mHotKeyIndex].strName; } else { mHotKeyBtn.image.color = Color.gray; strResult = "设置" + mHotKeyMap[mHotKeyIndex].strName + "成功"; mHotKeyLabel.text = "取消" + mHotKeyMap[mHotKeyIndex].strName; } } else { strResult = mHotKeyMap[mHotKeyIndex].strName + "失败"; } LogToBuff(DEBUG_TYPE.DEBUG_GM, LOG_TYPE.LOG_NULL, strResult); }
private void OnMoShenItemResult(MsgData data) { MsgData_sMoShenItemResult info = data as MsgData_sMoShenItemResult; if (info.Result == 0) { for (int i = 0; i < info.ResultList.Count; i++) { //交换物品成功 先将物品从背包移除,再放入对方背包 BagInfo srcbag = GetBagInfo(info.ResultList[i].SrcBag); BagInfo dstbag = GetBagInfo(info.ResultList[i].DstBag); if (dstbag == null) { return; } if (srcbag == null) { return; } ItemInfo srciteminfo = srcbag.GetItemInfo(info.ResultList[i].SrcPos); ItemInfo dstiteminfo = dstbag.GetItemInfo(info.ResultList[i].DstPos); srcbag.DeleteItem(info.ResultList[i].SrcPos); dstbag.DeleteItem(info.ResultList[i].DstPos); if (srciteminfo != null) { srciteminfo.Bag = info.ResultList[i].DstBag; srciteminfo.Pos = info.ResultList[i].DstPos; dstbag.AddItem(srciteminfo); } if (dstiteminfo != null) { dstiteminfo.Bag = info.ResultList[i].SrcBag; dstiteminfo.Pos = info.ResultList[i].SrcPos; srcbag.AddItem(dstiteminfo); } } } EventParameter par = EventParameter.Get(); par.intParameter = info.Result; CoreEntry.gEventMgr.TriggerEvent(GameEvent.GE_CC_MOSHEN_BAGCHANGEOVER, par); }
//获取主法宝星级 public int GetMasterMagicKeyStar() { int star = 0; BagInfo baginfo = PlayerData.Instance.BagData.GetBagInfo(BagType.TIEM_BAG_TYPE_MAGICKEY); if (baginfo != null) { var mkinfo = baginfo.GetItemInfo(0); if (mkinfo != null) { var magickKeyInfo = PlayerData.Instance.MagicKeyDataMgr.GetMagicKeyInfo(mkinfo.UID); if (magickKeyInfo != null) { star = magickKeyInfo.starCount; } } } return(star); }
//获取主法宝id public int GetMasterMagicKey() { int magickeyid = 0; BagInfo baginfo = PlayerData.Instance.BagData.GetBagInfo(BagType.TIEM_BAG_TYPE_MAGICKEY); if (baginfo != null) { var mkinfo = baginfo.GetItemInfo(0); if (mkinfo != null) { var magickKeyInfo = PlayerData.Instance.MagicKeyDataMgr.GetMagicKeyInfo(mkinfo.UID); if (magickKeyInfo != null) { magickeyid = magickKeyInfo.magickeyID; } } } return(magickeyid); }
/// <summary> /// 背包扩充回复。 /// </summary> /// <param name="data">网络消息数据。</param> private void OnExpandBag(MsgData data) { MsgData_sExpandBagResult info = data as MsgData_sExpandBagResult; LogMgr.Log("背包扩充回复 bag:{0} size:{1} result:{2}", info.Bag, info.NewSize, info.Result); if (info.Result == 0) { //背包扩充成功 BagInfo bag = GetBagInfo(info.Bag); if (bag != null) { int oldsize = bag.Size; bag.Size = info.NewSize; bag.OpenLastTime = ConfigManager.Instance.BagItem.GetOpenNeedTime(info.Bag, info.NewSize); TriggerEventBagSize(bag.BagType, oldsize, info.NewSize); //只提示通用背包开启 if (info.Bag == BagType.ITEM_BAG_TYPE_COMMON) { string msg = string.Format("成功开启{0}格背包!", info.NewSize - oldsize); UITips.ShowTips(msg); } } } }
/// <summary> /// 判断背包是否可放入物品。 /// </summary> /// <param name="bag">背包类型。</param> /// <param name="id">物品编号。</param> /// <param name="num">物品数量。</param> /// <returns>是否可放入。</returns> public bool IsCanPut(int bag, int id, int num) { BagInfo baginfo = GetBagInfo(bag); return(baginfo != null && baginfo.IsCanPut(id, num)); }
/// <summary> /// 获取指定类型的物品列表。 /// </summary> /// <param name="bag">背包类型。</param> /// <param name="type">物品类型。</param> /// <returns>物品列表。</returns> public List <ItemInfo> GetItemByType(int bag, int type) { BagInfo baginfo = GetBagInfo(bag); return(baginfo != null?baginfo.GetItemByType(type) : null); }
public List <ItemInfo> GetItemListByID(int iBagType, int itemid) { BagInfo bag = GetBagInfo(iBagType); return(bag != null?bag.GetItemListByID(itemid) : null); }
public ItemInfo GetItemInfoById(int bag, int itemid) { BagInfo baginfo = GetBagInfo(bag); return(baginfo != null?baginfo.GetItemInfoById(itemid) : null); }
/// <summary> /// 获取某个背包内物品数量。 /// </summary> /// <param name="bag">背包类型。</param> /// <param name="id">物品编号。</param> /// <returns>物品数量。</returns> public int GetItemNumber(int bag, int id) { BagInfo baginfo = GetBagInfo(bag); return(baginfo != null?baginfo.GetItemNumber(id) : 0); }
/// <summary> /// 获取物品信息。 /// </summary> /// <param name="bag">背包类型。</param> /// <param name="pos">物品位置。</param> /// <returns>物品信息。</returns> public ItemInfo GetItemInfo(int bag, int pos) { BagInfo baginfo = GetBagInfo(bag); return(baginfo != null?baginfo.GetItemInfo(pos) : null); }
/// <summary> /// 交换物品回复。 /// </summary> /// <param name="data">网络消息数据。</param> private void OnSwapItem(MsgData data) { MsgData_sSwapItemResult info = data as MsgData_sSwapItemResult; LogMgr.Log("交换物品回复 srcbag:{0} desbag:{1} srcpos:{2} dstpos:{3}", info.SrcBag, info.DstBag, info.SrcPos, info.DstPos); if (info.Result == 0) { //交换物品成功 先将物品从背包移除,再放入对方背包 BagInfo srcbag = GetBagInfo(info.SrcBag); BagInfo dstbag = GetBagInfo(info.DstBag); if (dstbag == null) { return; } if (srcbag == null) { return; } ItemInfo srciteminfo = srcbag.GetItemInfo(info.SrcPos); ItemInfo dstiteminfo = dstbag.GetItemInfo(info.DstPos); srcbag.DeleteItem(info.SrcPos); dstbag.DeleteItem(info.DstPos); if ((info.DstBag == (int)BagType.ITEM_BAG_TYPE_EQUIP || info.DstBag == (int)BagType.ITEM_BAG_TYPE_RIDE) && srciteminfo != null) { SG.CoreEntry.gAudioMgr.PlayUISound(900011); } if (srciteminfo != null) { srciteminfo.Bag = info.DstBag; srciteminfo.Pos = info.DstPos; dstbag.AddItem(srciteminfo); if (dstbag.BagType == BagType.ITEM_BAG_TYPE_EQUIP) { ShowEquipChange(srciteminfo.ID); } } if (dstiteminfo != null) { dstiteminfo.Bag = info.SrcBag; dstiteminfo.Pos = info.SrcPos; srcbag.AddItem(dstiteminfo); } if (srciteminfo != null && dstiteminfo != null) { //两者不为空,两边更新 TriggerEventItemUpdate(info.SrcBag, info.SrcPos); TriggerEventItemUpdate(info.DstBag, info.DstPos); } else if (srciteminfo != null) { //源背包删除 目标背包添加 TriggerEventItemDel(2, info.SrcBag, info.SrcPos, srciteminfo.UID); TriggerEventItemAdd(info.DstBag, info.DstPos); } else if (dstiteminfo != null) { //源背包添加 目标背包删除 TriggerEventItemAdd(info.SrcBag, info.SrcPos); TriggerEventItemDel(2, info.DstBag, info.DstPos, dstiteminfo.UID); } } EventParameter par = EventParameter.Get(data); CoreEntry.gEventMgr.TriggerEvent(GameEvent.GE_CC_BAGCHANGEOVER, par); }