示例#1
0
    public override void Revert()
    {
        //Get whether the item is currently in the player's inventory
        bool curItemState = myData.curItemState;

        if (inInventory == false && curItemState == false)
        {
            //If item was picked up and thrown somewhere else, place it back (or recreate it if it was destroyed)
            base.Revert();
        }
        else if (inInventory == false && curItemState == true)
        {
            //Get item out of inventory and create at position/in hand of pickedUp
            Instantiate(Inventory.instance.GetItem(myData.inventoryIndex).concreteObject, position, Quaternion.identity).GetComponent <Material>().PickedUp(parent.gameObject);
            Inventory.instance.Remove(myData.inventoryIndex);
        }
        else if (inInventory == true && curItemState == false)
        {
            //Destroy memento and place back in inventory
            ConcreteItem itemParent = parent as ConcreteItem;
            if (itemParent)
            {
                itemParent.EmptyMemento();
            }
            Inventory.instance.TransferIn(myData.inventoryIndex, parent);
        }
    }
示例#2
0
    //This is a secondary add tool used when a PickedUp item is toggled left or right
    protected bool AddAt(int index, ConcreteItem itemObj)
    {
        Item item = itemObj.GetItem();

        if (items.Count >= space)
        {
            // Send GUI message to Player here (todo), return false.
            return(false);
        }
        // Otherwise we can pick up the item, return true.
        items.Insert(index, item);
        //If item has a memento, update it to know the object is now in the players' inventory
        ItemMemento tempMemento = itemObj.GetMemento() as ItemMemento;

        if (tempMemento != null)
        {
            itemObj.setInInventory(true, handIndex);
            tempMemento.setParent(null);
            ItemMementos.Insert(index, tempMemento);
        }
        else
        {
            ItemMementos.Insert(index, null);
        }
        //Create a new ItemBox at index
        CreateItemBox(index);
        //Destroy old handObject to make new one
        if (handObject != null)
        {
            Destroy(handObject);
        }
        makeHandObject();
        return(true);
    }
示例#3
0
        public void Item_Name_Should_Default_To_Id()
        {
            // Arrange
            var item = new ConcreteItem();

            // Act
            item.Id = "joe";

            // Assert
            item.Name.Should().Be("joe");
        }
示例#4
0
    protected bool Add(ConcreteItem itemObj)
    {
        Item item = itemObj.GetItem();

        if (items.Count >= space)
        {
            // Send GUI message to Player here (todo), return false.
            return(false);
        }
        // Otherwise we can pick up the item, return true.
        items.Add(item);
        ItemMementos.Add(itemObj.GetMemento() as ItemMemento);
        //Create a new ItemBox at index Count (end of list)-1 to parallel this item added at the end
        CreateItemBox(items.Count - 1);
        return(true);
    }
示例#5
0
    public void makeHandObject()
    {
        makeObject(items[handIndex]);
        ConcreteItem itemInHand = handScript as ConcreteItem;

        if (itemInHand && ItemMementos.Count > handIndex)
        {
            //Update the item's memento, to tell it there is now a concrete version of it in existence
            if (ItemMementos[handIndex] != null)
            {
                ItemMementos[handIndex].setParent(handScript);
                //itemInHand.SetMemento(ItemMementos[handIndex]);
            }
            //Set curMemento
            handScript.setMemento(ItemMementos[handIndex]);
        }
    }
示例#6
0
    //Takes the object and places it in the inventory, destroying the concrete object
    //@error: Method raises an error if the concreteObject parameter is not compatible with the inventory
    public void TransferIn(int index, Material concreteObject)
    {
        Debug.Log("Transferring object back in!");
        ConcreteItem itemToRevert = concreteObject as ConcreteItem;

        if (itemToRevert)
        {
            itemToRevert.EmptyMemento();
            AddAt(index, itemToRevert);
            //Destroy the concreteObject version
            concreteObject.Destroy();
            //Update UI
            UpdateUI();
        }
        else
        {
            Debug.LogException(new Exception("Inventory Revert method expected a ConcreteItem object"), this);
        }
    }
示例#7
0
 public void SaveInventory(QuickLife script)
 {
     for (int i = 0; i < items.Count; i++)
     {
         if (i == handIndex)
         {
             ConcreteItem itemInHand = handScript as ConcreteItem;
             if (itemInHand)
             {
                 ItemMementos[i] = itemInHand.CreateInventoryMemento();
                 //The item in your hand will already be saved in the QuickLife script by the timeVibration
                 script.SaveMemento(ItemMementos[i]);
             }
         }
         else
         {
             ItemMemento newMemento = Instantiate(MementoType).GetComponent <ItemMemento>();
             newMemento.InitializeInventory(i);
             script.SaveMemento(newMemento);
             //Place memento into a list of Mementos
             ItemMementos[i] = newMemento;
         }
     }
 }
示例#8
0
        public void PriceCantBeLessThan0()
        {
            IItem item = new ConcreteItem(-100, new Salesman("customer name"));

            Assert.That(item.GetPrice(), Is.GreaterThanOrEqualTo(0));
        }
示例#9
0
 //Switches out held item for the one to the right in the list and returns the object to be displayed on the GUI
 public Item toggleHand(int directionAmount)
 {
     if (directionAmount == 0)
     {
         return(null);
     }
     //Check to see if this toggle function is moving from a null area
     if (handIndex >= items.Count && items.Count > 0)
     {
         //Change directionAmount to either 1 or -1
         directionAmount = directionAmount / Mathf.Abs(directionAmount);
         do
         {
             handIndex += directionAmount;
             if (handIndex >= items.Count)
             {
                 handIndex = 0;
             }
             if (handIndex < 0)
             {
                 handIndex = items.Count - 1;
             }
         } while(handIndex >= items.Count);
     }
     else
     {
         //The 'as' function returns null if the operation is impossible. This checks if the item in your
         //hand is a ConcreteItem that can be placed in the inventory
         ConcreteItem itemInHand = handScript as ConcreteItem;
         if (itemInHand)
         {
             if (newlyHeldObject == true)
             {
                 AddAt(handIndex, itemInHand);
                 newlyHeldObject = false;
             }
             else if (items.Count > 0)
             {
                 //Move handObject
                 handIndex += directionAmount;
                 if (handIndex >= items.Count)
                 {
                     handIndex = 0;
                 }
                 if (handIndex < 0)
                 {
                     handIndex = items.Count - 1;
                 }
             }
             else
             {
                 //If neither the object in hand is added to the inventory, nor are there any items left,
                 //Return null
                 return(null);
             }
         }
         else
         {
             //If the hand object isn't an item, return null
             return(null);
         }
     }
     //If either of the above options was activated, reset the handObject and update the UI
     //Destroy old handObject
     if (handObject != null)
     {
         Destroy(handObject);
     }
     makeHandObject();
     //Move UI Boxes
     moveUI(handIndex);
     UpdateUI();
     //Return object in hand for methods that require it
     return(GetObjectInHand());
 }