Example #1
0
    // 卸下装备
    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);
    }
Example #2
0
    // 请求穿戴装备
    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);
    }