Ejemplo n.º 1
0
        public static MultiplayerItem ConvertToMultiplayerItem(InventoryResponse.Hotbar item)
        {
            if (item != null)
            {
                return(ConvertToMultiplayerItem(item.id, item.count, true, null /*InventoryUtils.GetInstance(item.instanceId)*/));                          //TODO: Implement GetInstance()!
            }
            var multiplayerItem = new MultiplayerItem
            {
                category = new MultiplayerItemCategory {
                    loc = ItemCategory.Invalid, value = (int)ItemCategory.Invalid
                },
                count  = 0,
                guid   = Guid.Parse("00000000-0000-0000-0000-000000000000"),
                owned  = false,
                rarity = new MultiplayerItemRarity {
                    loc = ItemRarity.Invalid, value = 6
                }
            };

            return(multiplayerItem);
        }
Ejemplo n.º 2
0
        /*public static InventoryUtilResult RemoveItemFromInv(string playerId, Guid itemIdToRemove, int count,
         *  float health)
         * {
         *
         *  var inv = ReadInventory(playerId);
         *  var item = inv.result.nonStackableItems.Find(match =>
         *      match.id == itemIdToRemove && match.instances.Any(match => match.health == health));
         *  if (item == null)
         *  {
         *      InventoryResponse.Hotbar instanceItem = Array.Find(inv.result.hotbar, match =>
         *          match.id == itemIdToRemove && match.instanceId.health == health);
         *      return RemoveItemFromInv(playerId, itemIdToRemove, count, instanceItem.instanceId);
         *  }
         *  else
         *  {
         *      return RemoveItemFromInv(playerId, itemIdToRemove, count,
         *          item.instances.Find(match => match.health == health).id);
         *  }
         *
         * }*/

        public static InventoryUtilResult RemoveItemFromInv(string playerId, Guid itemIdToRemove,
                                                            int count = 1, Guid?unstackableItemId = null, bool includeHotbar = true)
        {
            var inv = ReadInventory(playerId);

            if (includeHotbar)
            {
                InventoryResponse.Hotbar hotbarItem = null;
                foreach (InventoryResponse.Hotbar item in inv.result.hotbar)
                {
                    if (item != null && item.id == itemIdToRemove && item.count <= count)
                    {
                        if (!unstackableItemId.HasValue || item.instanceId == unstackableItemId)
                        {
                            hotbarItem = item;
                        }
                        break;
                    }
                }

                if (hotbarItem != null)
                {
                    var hotbar = inv.result.hotbar;
                    var index  = Array.IndexOf(hotbar, hotbarItem);

                    if (hotbarItem.count == count)
                    {
                        hotbarItem = null;
                    }
                    else
                    {
                        hotbarItem.count -= count;
                    }

                    hotbar[index] = hotbarItem;

                    EditHotbar(playerId, hotbar, false);

                    return(InventoryUtilResult.Success);
                }
            }

            var itementry = inv.result.stackableItems.Find(match => match.id == itemIdToRemove && match.owned >= count);

            if (itementry != null)
            {
                itementry.owned  -= count;
                itementry.seen.on = DateTime.UtcNow;

                WriteInventory(playerId, inv);
            }
            else
            {
                var unstackableItem = inv.result.nonStackableItems.Find(match => match.id == itemIdToRemove);
                if (unstackableItem != null)
                {
                    var instance = unstackableItem.instances.Find(match => match.id == unstackableItemId);
                    unstackableItem.instances.Remove(instance);
                    unstackableItem.seen.on = DateTime.UtcNow;

                    WriteInventory(playerId, inv);
                }
                else
                {
                    return(InventoryUtilResult.NotEnoughItemsAvailable);
                }
            }

            return(InventoryUtilResult.Success);
        }