示例#1
0
        public static ChestResult OpenChestResult(ItemEntity chest, int count)
        {
            var itemInfo     = chest.GetItemAttr();
            var needKeyCount = (int)itemInfo.Data * count;

            if (chest.GetItemInfo().Count < needKeyCount)
            {
                throw new MsgException($"开启[{count}]个[{itemInfo.Name}]需要[{needKeyCount}]把钥匙,你的钥匙不足");
            }
            var openResult = new ChestResult();

            for (var i = 0; i < count; i++)
            {
                OpenChest(itemInfo.PropLevel, openResult);
            }
            foreach (var item in openResult.ItemList)
            {
                item.Key.AddItem(item.Value);
            }
            Startup.MyGameData.WeponList.AddRange(openResult.WeponList);
            chest.AddItem(-count);
            ItemEntity.ChestKey.UseItemActAndCheck(-(int)chest.GetItemAttr().Data *count, null);
            return(openResult);
        }
示例#2
0
        public static void SellItem(this ItemEntity item, int sellCount)
        {
            var itemAttr = item.GetItemAttr();

            if (!itemAttr.SellInMarket)
            {
                throw new MsgException("物品不可出售");
            }
            if (sellCount <= 0)
            {
                throw new MsgException("出售数量不能小于等于0");
            }
            var itemInfo = item.GetItemInfo();

            if (itemInfo.Count >= sellCount)
            {
                item.AddItem(-sellCount);
                Startup.MyGameData.Gold += sellCount * itemAttr.SellPrice;
            }
            else
            {
                throw new MsgException("物品数量不足");
            }
        }