// 出售物品 public void ReqSellItem(long itemID, int count) { PUseCommonItem data = new PUseCommonItem(); data.comItem.Add(new PComItem { id = itemID, num = count, }); Net.Send(eCommand.SALE_GOOD_TOSYS, data, (buffer) => { CommonAnswer ret = Net.Deserialize <CommonAnswer>(buffer); if (!Net.CheckErrorCode(ret.err_code, eCommand.SALE_GOOD_TOSYS)) { return; } ItemInfo info = GetItem(itemID); if (info != null) { AddMoney(info.Cfg.Price * count, PriceType.MONEY); } UseItem(itemID, count); UIManager.Instance.RefreshWindow <UINewBagView>(); }); }
// 卸下装备 public bool RequestTakeOffEquip(long heroID, long itemID) { HeroInfo heroInfo = GetHeroInfo(heroID); if (heroInfo == null) { return(false); } PUseCommonItem builder = new PUseCommonItem(); builder.heroId = heroID; ItemInfo itemInfo = heroInfo.GetItem(itemID); if (itemInfo == null) { return(false); } PComItem ibuilder = new PComItem(); ibuilder.id = itemID; builder.comItem.Add(ibuilder); NetworkManager.Instance.Send(eCommand.FIT_DOWN_EQUIP, builder, (buffer) => { PHeroAttr ret = Net.Deserialize <PHeroAttr>(buffer); if (!Net.CheckErrorCode(ret.errorCode, eCommand.FIT_DOWN_EQUIP)) { return; } // 把装备放到背包里 AddItem(itemInfo, false); heroInfo.Deserialize(ret, true); UIManager.Instance.RefreshWindow <UINewHeroView>(); UIManager.Instance.RefreshWindow <UINewHeroListView>(); }); return(true); }
// 使用物品 public void ReqUseItem(long itemID) { PUseCommonItem data = new PUseCommonItem(); data.comItem.Add(new PComItem { id = itemID, num = 1, }); Net.Send(eCommand.USE_PROP_TO_GAINGOOD, data, (buffer) => { PComItemList ret = Net.Deserialize <PComItemList>(buffer); if (!Net.CheckErrorCode(ret.errorCode, eCommand.USE_PROP_TO_GAINGOOD)) { return; } UseItem(itemID, 1); AddItem(ret, true); EventDispatcher.TriggerEvent(EventID.EVENT_UI_MAIN_REFRESH_VALUE); UIManager.Instance.RefreshWindow <UINewBagView>(); }); }
// 请求穿戴装备 public bool RequestEquipItem(long heroID, long itemID) { HeroInfo heroInfo = GetHeroInfo(heroID); if (heroInfo == null) { return(false); } if (heroInfo.GetItem(itemID) != null) { // 已经装备 return(false); } ItemInfo itemInfo = GetItem(itemID); if (itemInfo == null) { // 没有物品 return(false); } if (itemInfo.Cfg.Level > heroInfo.Level) { // 等级不足 UIUtil.ShowMsgFormat("MSG_HERO_LEVEL_LIMIT"); return(false); } PUseCommonItem builder = new PUseCommonItem(); builder.heroId = heroID; PComItem ibuilder = new PComItem(); ibuilder.id = itemInfo.EntityID; builder.comItem.Add(ibuilder); NetworkManager.Instance.Send(eCommand.FIT_UP_EQUIP, builder, (buffer) => { PHeroAttr ret = Net.Deserialize <PHeroAttr>(buffer); if (!Net.CheckErrorCode(ret.errorCode, eCommand.FIT_UP_EQUIP)) { return; } // 把旧装备放在背包里面 ItemInfo oldItemInfo = heroInfo.GetItemByType((ItemType)itemInfo.Cfg.Type); if (oldItemInfo != null) { AddItem(oldItemInfo, false); heroInfo.EquipedItem.Remove(oldItemInfo); } // 同步英雄属性 heroInfo.Deserialize(ret, true); // 移除背包内的装备 UseItem(itemID, 1); UIManager.Instance.RefreshWindow <UINewHeroView>(); UIManager.Instance.RefreshWindow <UINewHeroListView>(); }); return(true); }