public bool TrySubItem(Player player, int itemId, int count, string reason, out PlayerItem item) { item = player.Items.FirstOrDefault(x => x.Tid == itemId); if (item == null) { return(false); } else { if (item.Count >= count) { item.Count -= count; if (item.Count == 0) { //player.Items.Remove(item); _db.Items.Remove(item); } ResourceAmountChangedNotify notify = new ResourceAmountChangedNotify { success = true, items = new List <ResourceInfo>() { new ResourceInfo() { type = 2, id = itemId, count = item.Count, sid = item.Id } } }; Server.SendByUserNameAsync(player.Id, notify); return(true); } else { return(false); } } }
/// <summary> /// 添加资源 /// </summary> public void AddCurrency(Player player, int type, int value, string reason) { if (value == 0) { return; } var currency = player.Wallet.AddCurrency(type, value); ResourceAmountChangedNotify notify = new ResourceAmountChangedNotify(); notify.success = true; notify.items = new List <ResourceInfo>() { new ResourceInfo() { type = 1, id = type, count = currency } }; Server.SendByUserNameAsync(player.Id, notify); }
public PlayerItem AddItem(Player player, int itemId, int count, string reason) { var item = player.Items.FirstOrDefault(x => x.Tid == itemId); if (item == null) { item = new PlayerItem() { Tid = itemId, PlayerId = player.Id, Count = count, Id = Guid.NewGuid().ToString("D") }; player.Items.Add(item); } else { item.Count += count; } ResourceAmountChangedNotify notify = new ResourceAmountChangedNotify { success = true, items = new List <ResourceInfo>() { new ResourceInfo() { type = 2, id = itemId, count = item.Count, sid = item.Id } } }; Server.SendByUserNameAsync(player.Id, notify); return(item); }