/// <summary> /// 失去道具(精确到个例) /// </summary> /// <param name="info">道具信息</param> /// <param name="amount">失去数量</param> /// <param name="simulGetItems">会同时获得的道具</param> /// <returns>是否成功</returns> public bool LoseItem(ItemInfo info, int amount, params ItemInfo[] simulGetItems) { if (Backpack == null || info == null || !info.item || amount < 1) { return(false); } if (!TryLoseItem_Boolean(info, amount)) { return(false); } if (simulGetItems != null) { foreach (var si in simulGetItems) { if (!TryGetItem_Boolean(si, new ItemInfo(info.item, amount))) { return(false); } } } Backpack.LoseItemSimple(info, amount); ItemAgent ia = itemAgents.Find(x => x.MItemInfo == info); if (ia) { ia.UpdateInfo(); } OnLoseItemEvent?.Invoke(info.ItemID, GetItemAmount(info.item)); if (ItemWindowManager.Instance.MItemInfo == info && info.Amount < 1) { ItemWindowManager.Instance.CloseWindow(); } if (simulGetItems != null) { foreach (var si in simulGetItems) { GetItem(si); } } UpdateUI(); return(true); }
public void WhenLoseItem(string id) { OnLoseItemEvent?.Invoke(id, SDDataManager.Instance.GetItemAmount(id)); }