Beispiel #1
0
 /// <summary>
 /// Handle the mouse wheel event when gui is open
 /// </summary>
 /// <param name="currentContainer">current container</param>
 /// <param name="slotIndex">the slot mouse is over</param>
 private void handleMouseWheel(ContainerSlots currentContainer, int slotIndex)
 {
     if (Input.GetAxis("Mouse ScrollWheel") > 0f)
     {
         if (slotIndex >= 0 && slotIndex < currentContainer.Capacity)
         {
             Slot slot = currentContainer.GetSlotAt(slotIndex);
             if (containerCursor.itemStack == null && slot.itemStack != null)
             {
                 containerCursor.itemStack = slot.itemStack.Split(1);
             }
             else if (containerCursor.itemStack != null && slot.itemStack != null && slot.itemStack.mergeable(containerCursor.itemStack))
             {
                 slot.itemStack = containerCursor.itemStack.takeNumberReturnRemain(slot.itemStack, 1);
             }
         }
     }
     else if (Input.GetAxis("Mouse ScrollWheel") < 0f)
     {
         if (slotIndex >= 0 && slotIndex < currentContainer.Capacity)
         {
             Slot slot = currentContainer.GetSlotAt(slotIndex);
             if (containerCursor.itemStack != null && slot.IsEmpty())
             {
                 slot.itemStack = containerCursor.itemStack.Split(1);
             }
             else if (containerCursor.itemStack != null && slot.itemStack != null && slot.itemStack.mergeable(containerCursor.itemStack))
             {
                 containerCursor.itemStack = slot.itemStack.takeNumberReturnRemain(containerCursor.itemStack, 1);
             }
         }
     }
 }
Beispiel #2
0
        public void TestAddGetItem()
        {
            ContainerSlots container = new ContainerSlots(5);

            Assert.AreEqual(5, container.Capacity);

            Assert.IsNull(container.GetItemStackAt(-1)); // invalid do not crash
            Assert.IsNull(container.GetItemStackAt(0));  // emtpy statck

            container.AddItemStack(new ItemStack(ItemRegistry.ItemRadioactive, 10));
            container.AddItemStack(new ItemStack(ItemRegistry.ItemRadioactive, 10));
            container.AddItemStack(new ItemStack(ItemRegistry.ItemRadioactive, 10));
            container.AddItemStack(new ItemStack(ItemRegistry.ItemRadioactive, 10));
            Assert.AreEqual(40, container.GetItemStackAt(0).stackSize);

            container.AddItemStack(new ItemStack(ItemRegistry.ItemDebug, 1));
            container.AddItemStack(new ItemStack(ItemRegistry.ItemDebug, 1));
            container.AddItemStack(new ItemStack(ItemRegistry.ItemDebug, 1));

            Assert.AreEqual(ItemRegistry.ItemDebug.id, container.GetItemStackAt(1).itemId);
            Assert.AreEqual(ItemRegistry.ItemDebug.id, container.GetItemStackAt(2).itemId);
            Assert.AreEqual(ItemRegistry.ItemDebug.id, container.GetItemStackAt(3).itemId);
            Assert.IsNull(container.GetItemStackAt(4));

            container.AddItemStack(new ItemStack(ItemRegistry.ItemRadioactive, 60));
            Assert.AreEqual(1, container.GetItemStackAt(4).stackSize);

            Assert.AreEqual(1, container.AddItemStack(new ItemStack(ItemRegistry.ItemRadioactive, 99)).stackSize);
        }
Beispiel #3
0
        public override Handler DoOpen(ParsedInput input)
        {
            if (input.Words.Length == 1)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_WHAT, "Open".ToParagraph()));
            }
            if (IsDead)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_PLAYER_IS_DEAD));
            }

            ItemContainer container = ContainerSlots.GetContainer(input.Words[1]);

            if (container == null)
            {
                container = Hands.GetItem(input.Words[1], false, ITEM_TYPE.CONTAINER_ANY) as ItemContainer;
            }
            if (container == null)
            {
                container = CurrentRoom.Items.Find(input.Words[1], ITEM_TYPE.CONTAINER_ANY) as ItemContainer;
            }
            if (container == null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_ITEM));
            }

            if (!container.Closed)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_CONTAINER_ALREADY_OPEN, container.NameAsParagraph));
            }

            container.Closed = false;
            return(Handler.HANDLED(MESSAGE_ENUM.PLAYER_OPEN, container.NameAsParagraph));
        }
Beispiel #4
0
        public override Handler DoPut(ParsedInput input)
        {
            // TODO: put <item> on <surface>
            //// put <item> in <container>

            if (input.Words.Length < 4)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
            }
            if (input.Words[2] != "in")
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
            }
            if (IsDead)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_PLAYER_IS_DEAD));
            }

            // TODO: put <item> in MY <container>
            // if (input.Words.Length == 5 && input.Words[3] == "my") { return Handler.HANDLED(MESSAGE_ENUM.ERROR_NEED_TO_IMPLEMENT); }

            // must be holding item
            // don't remove item here
            Item item = Hands.GetItem(input.Words[1], false);

            if (item == null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_NOT_CARRYING_ITEM));
            }

            MESSAGE_ENUM  message   = MESSAGE_ENUM.PLAYER_PUT_IN_PLAYER_CONTAINER;
            ItemContainer container = ContainerSlots.GetContainer(input.Words[3]);

            if (container == null)
            {
                container = Hands.GetItem(input.Words[3], false, ITEM_TYPE.CONTAINER_ANY) as ItemContainer;
            }
            if (container == null || container.Equals(item))
            {
                message   = MESSAGE_ENUM.PLAYER_PUT_IN_GROUND_CONTAINER;
                container = CurrentRoom.Items.Find(input.Words[3], ITEM_TYPE.CONTAINER_ANY) as ItemContainer;
            }
            if (container == null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
            }

            if (container.Closed)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_CONTAINER_CLOSED, container.NameAsParagraph));
            }

            item = Hands.GetItem(input.Words[1], true);
            container.Items.Add(item);
            return(Handler.HANDLED(message, item.NameAsParagraph, container.NameAsParagraph));
        }
Beispiel #5
0
        public bool active;                              // gui is active

        /// <summary>
        /// Initialize all components
        /// </summary>
        void Start()
        {
            guiHotbar       = GetComponent <GuiHotbar>();
            containerHotbar = GetComponent <ContainerHotbar>();

            guiPlayerInventory       = GetComponent <GuiInventory>();
            containerPlayerInventory = GetComponent <ContainerSlots>();

            containerCursor = GetComponent <ContainerCursor>();

            player = GetComponent <EntityPlayer>();
        }
Beispiel #6
0
        protected override Handler DoLook(string strWord1, string strWord2, string strWord3)
        {
            // TODO: strWord2 could be ordinal OR "my"
            if (strWord1 == "at")
            {
                return(DoLook(strWord2, strWord3));
            }
            if (strWord1 == "in")
            {
                int ordinal;
                if (Statics.OrdinalStringToInt.TryGetValue(strWord2, out ordinal))
                {
                    return(DoLookInContainer(strWord3, ordinal));
                }
                else if (strWord2 == "my")
                {
                    // TODO: fix GetItem to look for BOTH types of container here
                    EntityHand hand = Hands.GetHandWithItem(strWord3);
                    if (hand.Item != null)
                    {
                        if ((hand.Item.Type & ITEM_TYPE.CONTAINER_ANY) != hand.Item.Type)
                        {
                            // matched input with a hand, but hand is not holding a container
                            return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
                        }

                        // hand is holding requested container
                        ItemContainer handContainer = hand.Item as ItemContainer;
                        if (handContainer.Closed)
                        {
                            return(Handler.HANDLED(MESSAGE_ENUM.ERROR_CONTAINER_CLOSED, handContainer.NameAsParagraph));
                        }

                        return(Handler.HANDLED(MESSAGE_ENUM.BASE_STRING, handContainer.ItemsParagraph));
                    }

                    // hands didn't work; check container slots
                    ItemContainer equippedContainer = ContainerSlots.GetContainer(strWord3);
                    if (equippedContainer != null)
                    {
                        if (equippedContainer.Closed)
                        {
                            return(Handler.HANDLED(MESSAGE_ENUM.ERROR_CONTAINER_CLOSED, equippedContainer.NameAsParagraph));
                        }
                        return(Handler.HANDLED(MESSAGE_ENUM.BASE_STRING, equippedContainer.ItemsParagraph));
                    }

                    return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
                }
            }
            return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
        }
Beispiel #7
0
 /// <summary>
 /// Get the current container where player can interact with
 /// </summary>
 /// <param name="gui">output the gui</param>
 /// <param name="container">output the container</param>
 private void GetCurrent(out GuiSlotsBase gui, out ContainerSlots container)
 {
     gui = null; container = null;
     if (guiHotbar.CursorOverGui())
     {
         gui = guiHotbar; container = containerHotbar;
     }
     if (guiPlayerInventory.CursorOverGui())
     {
         gui = guiPlayerInventory; container = containerPlayerInventory;
     }
     if (guiOtherInventory != null && guiOtherInventory.CursorOverGui())
     {
         gui = guiOtherInventory; container = containerOtherInventory;
     }
 }
Beispiel #8
0
 /// <summary>
 /// Open or close the gui
 /// </summary>
 /// <param name="open"></param>
 private void setGuiOpen(bool open)
 {
     if (!open)
     {
         resetOther();
     }
     else
     {
         if (player.LookObject != null && player.LookObject.GetComponent <ContainerSlots>() != null)
         {
             containerOtherInventory = player.LookObject.GetComponent <ContainerSlots>();
             guiOtherInventory       = player.LookObject.GetComponent <GuiInventory>();
         }
     }
     this.active    = open;
     Cursor.visible = open;
 }
Beispiel #9
0
        protected override Handler DoLook(string strWord)
        {
            // look hands - special case
            if (strWord == "hands")
            {
                return(DoLookHands(null));
            }

            // TODO: consider more specific strings for held or equipped items
            Item item = CurrentRoom.Items.Find(strWord);

            if (item != null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.BASE_STRING, (item.Description).ToParagraph()));
            }

            item = Hands.GetItem(strWord, false);
            if (item != null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.BASE_STRING, (item.Description).ToParagraph()));
            }

            item = Body.GetItem(strWord, false);
            if (item != null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.BASE_STRING, (item.Description).ToParagraph()));
            }

            item = ContainerSlots.GetContainer(strWord); //GetItem(strWord, false);
            if (item != null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.BASE_STRING, (item.Description).ToParagraph()));
            }

            EntityNPCBase npc = CurrentRoom.NPCs.Find(strWord);

            if (npc != null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.BASE_STRING, npc.LookParagraph));
            }

            return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
        }
Beispiel #10
0
        public override Handler DoClose(ParsedInput input)
        {
            if (input.Words.Length == 1)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_WHAT, "Close".ToParagraph()));
            }
            if (IsDead)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_PLAYER_IS_DEAD));
            }

            // TODO: close MY <container>
            //if (input.Words.Length == 3 && input.Words[1] == "my") { return Handler.HANDLED(MESSAGE_ENUM.ERROR_NEED_TO_IMPLEMENT); }

            ItemContainer container = ContainerSlots.GetContainer(input.Words[1]);

            if (container == null)
            {
                container = Hands.GetItem(input.Words[1], false, ITEM_TYPE.CONTAINER_ANY) as ItemContainer;
            }
            if (container == null)
            {
                container = CurrentRoom.Items.Find(input.Words[1], ITEM_TYPE.CONTAINER_ANY) as ItemContainer;
            }
            if (container == null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_ITEM));
            }

            if (container.Closed)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_CONTAINER_ALREADY_CLOSED, container.NameAsParagraph));
            }
            if (!container.Closable)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_CONTAINER_NOT_CLOSABLE, container.NameAsParagraph));
            }

            container.Closed = true;
            return(Handler.HANDLED(MESSAGE_ENUM.PLAYER_CLOSE, container.NameAsParagraph));
        }
Beispiel #11
0
        public void TestUpdate()
        {
            ContainerSlots container = new ContainerSlots(5);

            Assert.AreEqual(5, container.Capacity);

            container.AddItemStack(new ItemStack(ItemRegistry.ItemRadioactive, 10));

            container.UpdateWith(5);

            container.AddItemStack(new ItemStack(ItemRegistry.ItemRadioactive, 10));

            Assert.IsNotNull(container.GetItemStackAt(1)); // the items differ

            container.UpdateWith(26);
            Assert.IsNull(container.GetItemStackAt(0));
            Assert.IsNotNull(container.GetItemStackAt(1)); // decay

            container.UpdateWith(8);
            Assert.IsNull(container.GetItemStackAt(1));
        }
Beispiel #12
0
 /// <summary>
 /// Handle the mouse click event when the gui is open
 /// </summary>
 /// <param name="currentContainer"></param>
 /// <param name="slotIndex"></param>
 private void handleMouseClick(ContainerSlots currentContainer, int slotIndex)
 {
     if (slotIndex >= 0 && slotIndex < currentContainer.Capacity)
     {
         Slot slot = currentContainer.GetSlotAt(slotIndex);
         if (containerCursor.itemStack != null && slot.itemStack != null && slot.itemStack.mergeable(containerCursor.itemStack))
         {
             player.playerAudio.PlayOneShot(containerCursor.itemStack.GetClickSound());
             containerCursor.itemStack = slot.itemStack.mergeWith(containerCursor.itemStack);
         }
         else
         {
             if (containerCursor.itemStack != null || slot.itemStack != null)
             {
                 player.playerAudio.PlayOneShot((containerCursor.itemStack != null? containerCursor.itemStack : slot.itemStack).GetClickSound());
             }
             ItemStack tempStack = containerCursor.itemStack;
             containerCursor.itemStack = slot.itemStack;
             slot.itemStack            = tempStack;
         }
     }
 }
Beispiel #13
0
        public override Handler DoRemove(ParsedInput input)
        {
            if (input.Words.Length == 1)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_WHAT, "Remove".ToParagraph()));
            }
            if (input.Words.Length > 2)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
            }
            if (IsDead)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_PLAYER_IS_DEAD));
            }

            EntityHand hand = Hands.GetEmptyHand();

            if (hand == null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_HANDS_ARE_FULL));
            }

            REMOVE_RESULT result = Body.DoRemove(input.Words[1], hand);

            if (result == REMOVE_RESULT.NOT_REMOVED)
            {
                result = ContainerSlots.DoRemove(input.Words[1], hand);
            }
            if (result == REMOVE_RESULT.NOT_REMOVED)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
            }

            MESSAGE_ENUM message = Statics.ItemTypeToRemoveMessage[hand.Item.Type];

            return(Handler.HANDLED(message, hand.Item.NameAsParagraph));
        }
Beispiel #14
0
        public override Handler DoEquip(ParsedInput input)
        {
            if (input.Words.Length == 1)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_WHAT, "Equip".ToParagraph()));
            }
            if (IsDead)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_PLAYER_IS_DEAD));
            }

            string strItemToEquip = input.Words[1];

            // equip my <item>; strip 'my'
            if (input.Words.Length == 3 && input.Words[1] == "my")
            {
                strItemToEquip = input.Words[2];
            }

            EntityHand hand = Hands.GetHandWithItem(strItemToEquip);

            if (hand == null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
            }
            if ((hand.Item.Type & ITEM_TYPE.ARMOR_ANY) == hand.Item.Type)
            {
                return(Body.DoEquip(hand));
            }
            if ((hand.Item.Type & ITEM_TYPE.CONTAINER_ANY) == hand.Item.Type)
            {
                return(ContainerSlots.DoEquip(hand));
            }

            return(Handler.HANDLED(MESSAGE_ENUM.ERROR_ITEM_NOT_EQUIPPABLE));
        }
Beispiel #15
0
 /// <summary>
 /// Reset the other inventory to nothing
 /// </summary>
 public void resetOther()
 {
     this.guiOtherInventory       = null;
     this.containerOtherInventory = null;
 }
Beispiel #16
0
 /// <summary>
 /// Set the other inventory the player interact with
 /// </summary>
 /// <param name="gui"></param>
 /// <param name="container"></param>
 public void setOther(GuiInventory gui, ContainerSlots container)
 {
     this.guiOtherInventory       = gui;
     this.containerOtherInventory = container;
 }
Beispiel #17
0
        public override Handler DoGet(ParsedInput input)
        {
            // take <item> from <container>
            if (input.Words.Length == 4)
            {
                return(DoGetExtended(input));
            }

            // take <item>
            if (input.Words.Length == 1)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_WHAT, input.Words[0].ToSentenceCase().ToParagraph()));
            }

            if (IsDead)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_PLAYER_IS_DEAD));
            }

            ItemContainer container = null;
            MESSAGE_ENUM  message   = MESSAGE_ENUM.PLAYER_GET;

            // find item in current room
            Item item = CurrentRoom.Items.Find(input.Words[1]);

            if (item == null)
            {
                // find item in a room container
                List <Item> containers = CurrentRoom.Items.GetItemsOfType(ITEM_TYPE.CONTAINER_ANY);
                for (int i = containers.Count() - 1; i >= 0; i--)
                {
                    container = containers[i] as ItemContainer;
                    item      = container.Items.Find(input.Words[1]);
                    if (item != null)
                    {
                        message = MESSAGE_ENUM.PLAYER_GET_FROM_ROOM_CONTAINER;
                        break;
                    }
                }
            }
            if (item == null)
            {
                message = MESSAGE_ENUM.PLAYER_GET_FROM_CONTAINER;

                foreach (EntityHand hand in Hands.Hands)
                {
                    if (hand.Item == null)
                    {
                        continue;
                    }
                    if (hand.Item.IsType(ITEM_TYPE.CONTAINER_ANY))
                    {
                        item = container.Items.Find(input.Words[1]);
                        if (item != null)
                        {
                            break;
                        }
                    }
                }
            }
            if (item == null)
            {
                item = ContainerSlots.FindItem(input.Words[1]);
            }
            if (item == null)
            {
                // item not found
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_ITEM));
            }

            // item found; attempt to put in hands
            if (Hands.Full)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_HANDS_ARE_FULL));
            }

            EntityHand emptyHand = Hands.GetEmptyHand();

            emptyHand.Item = item;

            // if we found in a container, remove from container
            if (container != null)
            {
                container.Items.RemoveItem(item);
            }
            // otherwise, remove from room
            else
            {
                CurrentRoom.Items.Remove(item);
            }

            return(Handler.HANDLED(message, item.NameWithIndefiniteArticle, container == null ? null : container.NameAsParagraph));
        }