Example #1
0
        public bool HasItem(IWIBase item, out WIStack stack)
        {
            stack = null;
            if (mContainerEnabler == null)
            {
                return(false);
            }
            if (!mContainerEnabler.HasEnablerStack)
            {
                return(false);
            }
            WIStack        nextStack     = null;
            List <WIStack> enablerStacks = mContainerEnabler.EnablerStacks;

            for (int i = 0; i < enablerStacks.Count; i++)
            {
                nextStack = enablerStacks [i];
                if (nextStack.Items.Contains(item))
                {
                    stack = nextStack;
                    break;
                }
            }

            if (stack == null)
            {
                ShopOwner shopOwner = null;
                if (worlditem.Is <ShopOwner> (out shopOwner))
                {
                    //are we alive? if so, this can mean any containers that are owned by us in the group
                    //start in the group that
                    List <Container> containers = new List <Container> ();
                    if (WIGroups.GetAllContainers(worlditem.Group, containers))
                    {
                        foreach (Container container in containers)
                        {
                            if (Stacks.Find.Item(container.worlditem.StackContainer, item, out stack))
                            {
                                Debug.Log("Found item in shop owner container");
                                break;
                            }
                        }
                    }
                }
            }

            return(stack != null);
        }
Example #2
0
        public IEnumerator GetInventoryContainer(int currentIndex, bool forward, GetInventoryContainerResult result)
        {
            if (result == null)
            {
                yield break;
            }

            mOnAccessInventory.SafeInvoke();

            if (mContainerEnabler == null)
            {
                //if we don't have an enabler, we need one now
                if (CharacterInventoryGroup == null)
                {
                    //if we don't have a character group, we'll need to create it to store our stuff
                    CharacterInventoryGroup = WIGroups.GetOrAdd(worlditem.FileName, WIGroups.Get.World, worlditem);
                }
                //make sure the group is loaded
                CharacterInventoryGroup.Load();
                //create a new container enabler for our stuff
                mContainerEnabler = Stacks.Create.StackEnabler(CharacterInventoryGroup);
            }

            int       totalContainers = 1;
            ShopOwner shopOwner       = null;

            if (worlditem.Is <ShopOwner> (out shopOwner))
            {
                //are we alive? if so, this can mean any containers that are owned by us in the group
                //start in the group that
                int nextIndex = currentIndex;
                List <Container> containers = new List <Container> ();
                if (WIGroups.GetAllContainers(worlditem.Group, containers))
                {
                    if (forward)
                    {
                        nextIndex = containers.NextIndex <Container> (currentIndex);
                    }
                    else
                    {
                        nextIndex = containers.PrevIndex <Container> (currentIndex);
                    }
                    //tell the container that we're opening it, then wait a tick for it to fill
                    try {
                        containers [nextIndex].OnOpenContainer();
                    } catch (Exception e) {
                        Debug.LogException(e);
                        yield break;
                    }
                    yield return(null);

                    mContainerEnabler.EnablerStack.Items.Clear();
                    Stacks.Display.ItemInEnabler(containers [nextIndex].worlditem, mContainerEnabler);
                    result.ContainerEnabler = mContainerEnabler;
                    result.ContainerIndex   = nextIndex;
                    result.TotalContainers  = containers.Count;
                }
            }
            else
            {
                //if we're not a shop owner
                //then there's exactly one container, our inventory container
                //if we're holding a temporary item then there are two
                if (IsHoldingTemporaryItem)
                {
                    Debug.Log("We're holding item so we'll return 2 containers");
                    //index 0 is our container enabler
                    //index 1 is our temporary item
                    result.TotalContainers = 2;
                    if (currentIndex == 0)                      //toggle to our held item
                    //Stacks.Display.ItemInEnabler (worlditem, mTemporaryItemEnabler);
                    {
                        result.ContainerIndex   = 1;
                        result.ContainerEnabler = mTemporaryItemEnabler;
                    }
                    else                        //toggle to our container enabler
                    {
                        Stacks.Display.ItemInEnabler(worlditem, mContainerEnabler);
                        result.ContainerIndex   = 0;
                        result.ContainerEnabler = mContainerEnabler;
                    }
                }
                else
                {
                    Stacks.Display.ItemInEnabler(worlditem, mContainerEnabler);
                    result.ContainerIndex   = 0;
                    result.TotalContainers  = 1;
                    result.ContainerEnabler = mContainerEnabler;
                }
                //this is always the same
                result.InventoryBank = InventoryBank;
            }
            yield break;
        }