예제 #1
0
 bool OnSell(GoodsData data, int amount = 1)
 {
     if (MShop == null || data == null || !data.IsValid || amount < 1)
     {
         return(false);
     }
     if (!MShop.Commodities.Contains(data))
     {
         return(false);
     }
     if (!BackpackManager.Instance.CanGet(data.Item, amount))
     {
         return(false);
     }
     if (data.Info.EmptyAble && amount > data.LeftAmount)
     {
         if (!data.IsEmpty)
         {
             MessageManager.Instance.New("该商品数量不足");
         }
         else
         {
             MessageManager.Instance.New("该商品暂时缺货");
         }
         return(false);
     }
     if (!BackpackManager.Instance.CanLoseMoney(amount * data.Info.SellPrice))
     {
         return(false);
     }
     BackpackManager.Instance.LoseMoney(amount * data.Info.SellPrice);
     BackpackManager.Instance.GetItem(data.Item, amount);
     if (data.Info.EmptyAble)
     {
         data.LeftAmount -= amount;
     }
     goodsList.RefreshItemIf(x => x.Data == data);
     return(true);
 }