예제 #1
0
    /// <summary>
    /// Remove an InventorySpace from the view.
    /// </summary>
    public void Remove(InventorySpace space)
    {
        int index = -1;

        for (int i = 0; i < _sets.Length; ++i)
        {
            if (_sets[i].space == space)
            {
                index = i;  break;
            }
        }

        if (index != -1)
        {
            _sets[index].Clear();
            if (index != _sets.Length - 1 && _sets[index + 1].space != null)
            {
                for (int i = index + 1; i < _sets.Length; ++i)
                {
                    _sets[i - 1] = _sets[i];
                    _sets[i].Clear();
                }
            }
            --_count;
        }
    }
예제 #2
0
    public void OnAfterDeserialize()
    {
        _views.Clear();

        foreach (SerializableInventoryView data in serializedViews)
        {
            InventoryView view = new InventoryView(data.name, data.spaces.Length);

            // Add all the spaces to the view.
            for (int i = 0; i < data.spaces.Length; ++i)
            {
                InventorySpace space = FindSpaceByName(data.spaces[i]);
                if (space != null)
                {
                    view.Add(space);
                }
            }

            // Add all the filters to the view.
            for (int i = 0; i < data.filters.Length; ++i)
            {
                view.AddFilter(data.filters[i]);
            }

            // Set the sorting method.
            view.Sorting = data.sortBy;
        }

        serializedViews.Clear();
    }
예제 #3
0
    /// <summary>
    /// Adds a new InventorySpace to the list of spaces in this
    /// InventoryView.
    /// </summary>
    public void Add(InventorySpace space)
    {
        int index = -1;

        for (int i = 0; i < _sets.Length; ++i)
        {
            if (_sets[i].space == null)
            {
                _sets[i].Set(space);
                index = i;
                break;
            }
        }

        if (index != -1)
        {
            index = _sets.Length;
            // Otherwise, have to grow array.  This should happen rarely, if ever.
            Debug.LogWarning("Growing array in InventoryView from [" + index + "]");
            _sets = AHArray.Added(_sets, new InventoryViewSet());
            _sets[index].Set(space);
        }

        ++_count;

        if (Active)
        {
            Filter(_sets[index]);
            Sort(_sets[index]);
        }
    }
예제 #4
0
    /// <summary>
    /// Try and take the specified number of items from a specific inventory space.
    /// </summary>
    /// <returns>An InventoryItem, with number of items taken (0 if none).</returns>
    public InventoryItem TakeFrom(string name, IGameItem item, uint count = 1)
    {
        InventorySpace space = FindSpaceByName(name);

        if (space != null)
        {
            return(space.Take(item, count));
        }
        else
        {
            return(item.CreateInventoryItem());            /* Creates empty inventory item. */
        }
    }
예제 #5
0
    /// <summary>Get the total number of `item` in the specified InventorySpace.</summary>
    public ulong CountIn(string name, IGameItem item)
    {
        InventorySpace space = FindSpaceByName(name);

        if (space != null)
        {
            return(space.Count(item));
        }
        else
        {
            return(0);
        }
    }
예제 #6
0
    /// <summary>
    /// Remove and returns the InventorySpace with the provided name.
    /// </summary>
    public InventorySpace RemoveSpace(string name)
    {
        InventorySpace space = FindSpaceByName(name);

        if (space != null)
        {
            stores.Remove(space);
        }

        // Make sure the InventorySpace is removed from all
        // InventoryViews.
        foreach (InventoryView view in _views)
        {
            view.Remove(space);
        }

        return(space);
    }
예제 #7
0
    /// <summary>
    /// Try and store the items into the specified inventory space.
    /// </summary>
    public InventoryResult StoreIn(string name, InventoryItem item, uint count = 0)
    {
        if (count != 0)
        {
            Debug.Assert(item.count == 0, "[InventoryComponent] Overwriting count of InventoryItem with count > 0 on StoreIn!");
            item.count = count;
        }

        InventorySpace space = FindSpaceByName(name);

        if (space != null)
        {
            return(space.Store(item));
        }
        else
        {
            return(InventoryResult.InvalidSpace);
        }
    }
예제 #8
0
    /// <summary>
    /// Adds a new InventorySpace to the list of spaces.
    /// If an InventorySpace already exists with the provided name, it will
    /// return `SpaceAlreadyExists`, otherwise will return `Success`.
    /// </summary>
    public InventoryResult AddSpace(string name, float capacity)
    {
        if (FindSpaceByName(name) != null)
        {
            return(InventoryResult.SpaceAlreadyExists);
        }

        InventorySpace space = new InventorySpace(name, capacity);

        stores.Add(space);

        // Make sure if there are any InventoryViews active, then we
        // update them with the new InventorySpace.
        foreach (InventoryView view in _views)
        {
            if (view.Active)
            {
                view.Add(space);
            }
        }

        return(InventoryResult.Success);
    }
예제 #9
0
 public void Set(InventorySpace space)
 {
     this.space = space;
     _items     = null;
 }
예제 #10
0
 public void Clear()
 {
     space  = null;
     _items = null;
 }