public ItemSellResult SellItem( SessionToken token, string userId, Guid itemId, long amount, decimal pricePerItem) { if (amount <= 0 || pricePerItem <= 0) { return(new ItemSellResult(ItemTradeState.RequestToLow)); } var character = GetCharacterAsync(token, userId); if (character == null) { return(new ItemSellResult(ItemTradeState.Failed)); } if (!playerManager.AcquiredUserLock(token, character)) { return(new ItemSellResult(ItemTradeState.Failed)); } var itemsToSell = gameData.GetInventoryItems(character.Id, itemId); var totalItemCount = itemsToSell.Count > 0 ? itemsToSell.Sum(x => x.Amount.GetValueOrDefault()) : 0; var newItemAmount = totalItemCount - amount; if (itemsToSell.Count == 0 || newItemAmount < 0) { return(new ItemSellResult(ItemTradeState.DoesNotOwn)); } gameData.RemoveRange(itemsToSell); if (newItemAmount > 0) { var mergedInventoryItem = new InventoryItem { Id = Guid.NewGuid(), Amount = newItemAmount, CharacterId = character.Id, Equipped = false, ItemId = itemId, }; gameData.Add(mergedInventoryItem); } var marketItem = new DataModels.MarketItem { Id = Guid.NewGuid(), Amount = amount, Created = DateTime.UtcNow, ItemId = itemId, PricePerItem = pricePerItem, SellerCharacterId = character.Id, }; gameData.Add(marketItem); return(new ItemSellResult(ItemTradeState.Success)); }
public ItemSellResult SellItem( SessionToken token, string userId, Guid itemId, long amount, double pricePerItem) { //if (i != null && i.Category == (int)DataModels.ItemCategory.StreamerToken) //{ // return new ItemSellResult(ItemTradeState.Failed); //} if (amount <= 0 || pricePerItem <= 0) { return(new ItemSellResult(ItemTradeState.RequestToLow)); } if (pricePerItem >= 1_000_000_000) { return(new ItemSellResult(ItemTradeState.Failed)); } var character = GetCharacterAsync(token, userId); if (character == null) { return(new ItemSellResult(ItemTradeState.Failed)); } if (!playerManager.AcquiredUserLock(token, character)) { return(new ItemSellResult(ItemTradeState.Failed)); } var inventory = inventoryProvider.Get(character.Id); var session = gameData.GetSession(token.SessionId); var sessionOwner = gameData.GetUser(session.UserId); var item = gameData.GetItem(itemId); string itemTag = null; if (item.Soulbound.GetValueOrDefault()) { return(new ItemSellResult(ItemTradeState.Untradable)); } if (item.Category == (int)DataModels.ItemCategory.StreamerToken) { itemTag = sessionOwner.UserId; } var itemToSell = inventory.GetUnequippedItem(itemId, tag: itemTag); if (itemToSell.IsNull()) { return(new ItemSellResult(ItemTradeState.DoesNotOwn)); } var totalItemCount = itemToSell.Amount;//itemsToSell.Count > 0 ? itemsToSell.Sum(x => x.Amount.GetValueOrDefault()) : 0; var newItemAmount = totalItemCount - amount; if (newItemAmount < 0) { return(new ItemSellResult(ItemTradeState.DoesNotOwn)); } inventory.RemoveItem(itemToSell, amount); var marketItem = new DataModels.MarketItem { Id = Guid.NewGuid(), Amount = amount, Created = DateTime.UtcNow, ItemId = itemId, PricePerItem = pricePerItem, SellerCharacterId = character.Id, Tag = itemToSell.Tag, Flags = itemToSell.Flags, Enchantment = itemToSell.Enchantment, Name = itemToSell.Name, TransmogrificationId = itemToSell.TransmogrificationId, Expires = DateTime.UtcNow.AddDays(14), }; gameData.Add(marketItem); return(new ItemSellResult(ItemTradeState.Success)); }