RemoveItemFromContainer() 공개 메소드

public RemoveItemFromContainer ( int index ) : bool
index int
리턴 bool
예제 #1
0
 public static void SetPickedUpFlag(Container cn, bool NewValue)
 {    //Recursivly sets the picked up flag on all items in the container and all sub-container contents.
     for (int i = 0; i < cn.MaxCapacity(); i++)
     {
         string ItemName = cn.GetItemAt(i);
         if (ItemName != "")
         {
             GameObject item = GameObject.Find(cn.GetItemAt(i));
             if (item != null)
             {
                 if (item.GetComponent <ObjectInteraction>() != null)
                 {
                     item.GetComponent <ObjectInteraction>().PickedUp = NewValue;
                     if (item.GetComponent <ObjectInteraction>().ItemType == ObjectInteraction.A_PICK_UP_TRIGGER)
                     {                        //Special case
                         item.GetComponent <a_pick_up_trigger>().Activate();
                         if (item == null)
                         {                            //Use trigger is no more.
                             cn.RemoveItemFromContainer(i);
                         }
                     }
                     else if (item.GetComponent <Container>() != null)
                     {
                         Container.SetPickedUpFlag(item.GetComponent <Container>(), NewValue);
                     }
                 }
             }
         }
     }
 }
예제 #2
0
 public static bool RemoveItemFromSubContainers(Container cn, string objectName)
 {
     for (int i = 0; i <= cn.MaxCapacity(); i++)
     {
         if (cn.items[i] == objectName)
         {
             cn.RemoveItemFromContainer(i);
             return(true);
         }
         else
         {
             if (cn.items[i] != "")
             {
                 GameObject obj = GameObject.Find(cn.items[i]);
                 if (obj != null)
                 {
                     if (obj.GetComponent <Container>() != null)
                     {
                         return(RemoveItemFromSubContainers(obj.GetComponent <Container>(), objectName));
                     }
                 }
             }
         }
     }
     return(false);
 }
예제 #3
0
 public static bool RemoveItemFromSubContainers(Container cn, string objectName)
 {
     for (int i =0; i<=cn.MaxCapacity ();i++)
     {
         if (cn.items[i] == objectName)
         {
             cn.RemoveItemFromContainer(i);
             return true;
         }
         else
         {
             if (cn.items[i] !="")
             {
                 GameObject obj = GameObject.Find (cn.items[i]);
                 if (obj!=null)
                 {
                     if (obj.GetComponent<Container>()!=null)
                     {
                         return RemoveItemFromSubContainers(obj.GetComponent<Container>(),objectName);
                     }
                 }
             }
         }
     }
     return false;
 }
예제 #4
0
 public static void removeFromContainer(Container cn, string objectName)
 {                   //Only removes from the top level container cn
     for (int i = 0; i <= cn.MaxCapacity(); i++)
     {
         if (cn.items[i] == objectName)
         {
             cn.RemoveItemFromContainer(i);
             return;
         }
     }
 }
 public void consumeObject()
 {
     if ((isQuant == false) || ((isQuant) && (Link == 1)) || (isEnchanted == true))
     {          //the last of the item or is not a quantity;
         Container cn = playerUW.playerInventory.GetCurrentContainer();
         //Code for objects that get destroyed when they are used. Eg food, potion, fuel etc
         if (!cn.RemoveItemFromContainer(this.name))
         {                    //Try and remove from the paperdoll if not found in the current container.
             playerUW.playerInventory.RemoveItemFromEquipment(this.name);
         }
         playerUW.playerInventory.Refresh();
         Destroy(this.gameObject);
     }
     else
     {                //just decrement the quantity value;
         Link--;
     }
 }
 public static void SetPickedUpFlag(Container cn, bool NewValue)
 {//Recursivly sets the picked up flag on all items in the container and all sub-container contents.
     for (short i = 0; i <= cn.MaxCapacity(); i++)
     {
         ObjectInteraction item = cn.GetItemAt(i);
         if (item != null)
         {
             //FIELD PICKUP item.GetComponent<ObjectInteraction>().PickedUp=NewValue;
             if (item.GetItemType() == ObjectInteraction.A_PICK_UP_TRIGGER)
             {//Special case
                 item.GetComponent <a_pick_up_trigger>().Activate(cn.gameObject);
                 cn.RemoveItemFromContainer(i);
             }
             else if (item.GetComponent <Container>() != null)
             {
                 Container.SetPickedUpFlag(item.GetComponent <Container>(), NewValue);
             }
         }
     }
 }
예제 #7
0
    public static void SortContainer(Container cn)
    {
        //Debug.Log ("Sorting container");
        //Flattens the contents of a container so that they occupy the first slots
        int    currFreeSlot = -1;
        string ItemName;
        bool   GetNextSlot = true;

        for (short i = 0; i <= cn.MaxCapacity(); i++)
        {
            //Find the first free slot
            if (GetNextSlot == true)
            {
                for (short j = 0; j <= cn.MaxCapacity(); j++)
                {
                    ItemName = cn.GetItemAt(j);
                    if (ItemName == "")
                    {
                        currFreeSlot = j;
                        GetNextSlot  = false;
                        break;
                    }
                }
            }
            if ((i > currFreeSlot) && (currFreeSlot != -1))
            {
                ItemName = cn.GetItemAt(i);
                if (ItemName != "")
                {                //Move this item to the free slot
                    cn.RemoveItemFromContainer(i);
                    cn.AddItemToContainer(ItemName, currFreeSlot);
                    GetNextSlot  = true;
                    currFreeSlot = -1;
                }
            }
        }
    }
예제 #8
0
    void LeftClickPickup()
    {    //Code for when I left click in pickup mode
        GameObject ObjectUsedOn = null;
        bool       DoNotPickup  = false;

        if (UWCharacter.Instance.playerInventory.ObjectInHand != "")
        {
            ObjectInteraction objInt = UWCharacter.Instance.playerInventory.GetObjIntInHand();
            //Eating food dropped in helm slot
            if (SlotCategory == HELM)
            {
                if (objInt.GetItemType() == ObjectInteraction.FOOD)
                {
                    objInt.Use();
                    DoNotPickup = true;
                    return;
                }
            }

            if ((SlotCategory != objInt.GetItemType()) && (SlotCategory != -1))
            {                    //Slot is not a general use one andThis item type does not go in this slot.
                //Debug.Log ("cannot pickup an " + objInt.GetItemType() + " in a " + SlotCategory + " at " + this.name);
                DoNotPickup = true;
            }

            if (objInt.IsStackable())
            {
                ObjectUsedOn = GameObject.Find(UWCharacter.Instance.playerInventory.GetObjectAtSlot(slotIndex));
                if (ObjectUsedOn != null)
                {
                    if (ObjectInteraction.CanMerge(ObjectUsedOn.GetComponent <ObjectInteraction>(), objInt))
                    {
                        ObjectInteraction.Merge(ObjectUsedOn.GetComponent <ObjectInteraction>(), objInt);
                        UWHUD.instance.CursorIcon = UWHUD.instance.CursorIconDefault;
                        UWCharacter.Instance.playerInventory.ObjectInHand = "";
                        UWCharacter.Instance.playerInventory.Refresh(slotIndex);
                        return;
                    }
                }
            }
        }

        if (UWCharacter.Instance.playerInventory.GetObjectAtSlot(slotIndex) == "")      //No object in slot
        {
            if (DoNotPickup == false)
            {
                if (Container.TestContainerRules(UWCharacter.Instance.playerInventory.GetCurrentContainer(), slotIndex, false))
                {
                    UWCharacter.Instance.playerInventory.SetObjectAtSlot(slotIndex, UWCharacter.Instance.playerInventory.ObjectInHand);
                    UWHUD.instance.CursorIcon = UWHUD.instance.CursorIconDefault;
                    UWCharacter.Instance.playerInventory.SetObjectInHand("");
                }
            }
        }
        else
        {
            //Get the object at the slot and test it's activation.
            ObjectUsedOn = UWCharacter.Instance.playerInventory.GetGameObjectAtSlot(slotIndex); //GameObject.Find (pInv.GetObjectAtSlot(slotIndex));
            if (ObjectUsedOn.GetComponent <ObjectInteraction>().Use() == false)
            {                                                                                   //if nothing happened when I clicked on the object at the slot.
                if (UWCharacter.Instance.playerInventory.ObjectInHand != "")
                {
                    //TODO: Make sure this works with Equipment slots
                    //No effect occurred. Swap the two objects.
                    if (DoNotPickup == false)
                    {
                        if (Container.TestContainerRules(UWCharacter.Instance.playerInventory.GetCurrentContainer(), slotIndex, true))
                        {
                            UWCharacter.Instance.playerInventory.SwapObjects(ObjectUsedOn, slotIndex, UWCharacter.Instance.playerInventory.ObjectInHand);
                        }
                    }
                }
                else
                {                                //Pick up the item at that slot.
                    //TODO: Make this work with Equipment slots
                    UWCharacter.Instance.playerInventory.ObjectInHand = ObjectUsedOn.name;
                    UWHUD.instance.CursorIcon = ObjectUsedOn.GetComponent <ObjectInteraction>().GetInventoryDisplay().texture;
                    //UWCharacter.Instance.CurrObjectSprite = ObjectUsedOn.GetComponent<ObjectInteraction>().InventoryString;
                    if (this.slotIndex >= 11)
                    {
                        Container cn = GameObject.Find(UWCharacter.Instance.playerInventory.currentContainer).GetComponent <Container>();
                        cn.RemoveItemFromContainer(UWCharacter.Instance.playerInventory.ContainerOffset + this.slotIndex - 11);
                    }
                    UWCharacter.Instance.playerInventory.ClearSlot(this.slotIndex);
                }
            }
        }
    }
예제 #9
0
 public static void SortContainer(Container cn)
 {
     //Debug.Log ("Sorting container");
     //Flattens the contents of a container so that they occupy the first slots
     int currFreeSlot=-1;
     string ItemName;
     bool GetNextSlot=true;
     for (int i=0;i<=cn.MaxCapacity();i++)
     {
         //Find the first free slot
         if (GetNextSlot==true)
         {
             for (int j=0;j<=cn.MaxCapacity();j++)
             {
                 ItemName=cn.GetItemAt(j);
                 if (ItemName=="")
                 {
                     currFreeSlot=j;
                     GetNextSlot=false;
                     break;
                 }
             }
         }
         if ((i>currFreeSlot) &&(currFreeSlot!=-1))
         {
             ItemName=cn.GetItemAt(i);
             if (ItemName!="")
             {//Move this item to the free slot
                 cn.RemoveItemFromContainer(i);
                 cn.AddItemToContainer(ItemName,currFreeSlot);
                 GetNextSlot=true;
                 currFreeSlot=-1;
             }
         }
     }
 }
예제 #10
0
 public static void SetPickedUpFlag(Container cn, bool NewValue)
 {
     //Recursivly sets the picked up flag on all items in the container and all sub-container contents.
     for (int i =0; i<=cn.MaxCapacity();i++)
     {
         string ItemName=cn.GetItemAt(i);
         if (ItemName != "")
         {
             GameObject item = GameObject.Find (cn.GetItemAt(i));
             if (item !=null)
             {
                 if (item.GetComponent<ObjectInteraction>()!=null)
                 {
                     item.GetComponent<ObjectInteraction>().PickedUp=NewValue;
                     if (item.GetComponent<ObjectInteraction>().GetItemType()==ObjectInteraction.A_PICK_UP_TRIGGER)
                     {//Special case
                         item.GetComponent<a_pick_up_trigger>().Activate();
                         //if (item==null)
                         //{//Use trigger is no more.
                         cn.RemoveItemFromContainer(i);
                         //}
                     }
                     else if (item.GetComponent<Container>()!=null)
                     {
                         Container.SetPickedUpFlag(item.GetComponent<Container>(),NewValue);
                     }
                 }
             }
         }
     }
 }
예제 #11
0
    void LeftClickPickup()
    {    //Code for when I left click in pickup mode
        GameObject ObjectUsedOn = null;
        bool       DoNotPickup  = false;

        if (playerUW.playerInventory.ObjectInHand != "")
        {
            ObjectInteraction objInt = playerUW.playerInventory.GetGameObjectInHand().GetComponent <ObjectInteraction>();
            if ((SlotCategory != objInt.ItemType) && (SlotCategory != -1))
            {                    //Slot is not a general use one andThis item type does not go in this slot.
                Debug.Log("cannot pickup an " + objInt.ItemType + " in a " + SlotCategory);
                DoNotPickup = true;
            }

            if ((objInt.isQuant == true) && (objInt.isEnchanted == false))
            {
                ObjectUsedOn = GameObject.Find(playerUW.playerInventory.GetObjectAtSlot(slotIndex));
                if (ObjectUsedOn != null)
                {
                    if ((objInt.item_id == ObjectUsedOn.GetComponent <ObjectInteraction>().item_id) && (objInt.Quality == ObjectUsedOn.GetComponent <ObjectInteraction>().Quality))
                    {
                        //merge the items
                        ObjectUsedOn.GetComponent <ObjectInteraction>().Link = ObjectUsedOn.GetComponent <ObjectInteraction>().Link + objInt.Link;
                        playerUW.CursorIcon = playerUW.CursorIconDefault;
                        playerUW.playerInventory.ObjectInHand = "";
                        Destroy(objInt.gameObject);
                        return;
                    }
                }
            }
        }

        if (playerUW.playerInventory.GetObjectAtSlot(slotIndex) == "")      //No object in slot
        {
            if (DoNotPickup == false)
            {
                if (Container.TestContainerRules(playerUW.playerInventory.GetCurrentContainer(), slotIndex))
                {
                    playerUW.playerInventory.SetObjectAtSlot(slotIndex, playerUW.playerInventory.ObjectInHand);
                    playerUW.CursorIcon = playerUW.CursorIconDefault;
                    playerUW.playerInventory.SetObjectInHand("");
                }
            }
            //PickupFromSlot();
        }
        else
        {
            //Get the object at the slot and test it's activation.
            ObjectUsedOn = playerUW.playerInventory.GetGameObjectAtSlot(slotIndex); //GameObject.Find (pInv.GetObjectAtSlot(slotIndex));
            if (ObjectUsedOn.GetComponent <ObjectInteraction>().Use() == false)
            {                                                                       //if nothing happened when I clicked on the object at the slot.
                if (playerUW.playerInventory.ObjectInHand != "")
                {
                    //TODO: Make sure this works with Equipment slots
                    //No effect occurred. Swap the two objects.
                    if (DoNotPickup == false)
                    {
                        if (Container.TestContainerRules(playerUW.playerInventory.GetCurrentContainer(), slotIndex))
                        {
                            playerUW.playerInventory.SwapObjects(ObjectUsedOn, slotIndex, playerUW.playerInventory.ObjectInHand);
                        }
                    }
                }
                else
                {                                //Pick up the item at that slot.
                    //TODO: Make this work with Equipment slots
                    playerUW.playerInventory.ObjectInHand = ObjectUsedOn.name;
                    playerUW.CursorIcon = ObjectUsedOn.GetComponent <ObjectInteraction>().GetInventoryDisplay().texture;
                    //playerUW.CurrObjectSprite = ObjectUsedOn.GetComponent<ObjectInteraction>().InventoryString;
                    if (this.slotIndex >= 11)
                    {
                        Container cn = GameObject.Find(playerUW.playerInventory.currentContainer).GetComponent <Container>();
                        cn.RemoveItemFromContainer(playerUW.playerInventory.ContainerOffset + this.slotIndex - 11);
                    }
                    playerUW.playerInventory.ClearSlot(this.slotIndex);
                }
            }
        }
    }