CountItems() публичный Метод

Counts the number of items in the container..
public CountItems ( ) : int
Результат int
 public void OnClick()
 {
     if (Dragging == true)
     {
         return;
     }
     if ((UWCharacter.Instance.isRoaming == true) || (Quest.instance.InDreamWorld))
     {//No inventory use while using wizard eye.
         return;
     }
     if (UWCharacter.Instance.playerInventory.currentContainer == UWCharacter.Instance.playerInventory.playerContainer) // UWCharacter.Instance.name)
     {                                                                                                                  //Don't do anything on the top level
         UWCharacter.Instance.playerInventory.ContainerOffset = 0;
         BackpackBg.SetActive(false);
         return;
     }
     if (CurrentObjectInHand == null)
     {//Player has no object in their hand. We close up the container.
         ScrollButtonInventory.ScrollValue = 0;
         UWCharacter.Instance.playerInventory.ContainerOffset = 0;
         Container currentContainerObj = UWCharacter.Instance.playerInventory.currentContainer;
         UWCharacter.Instance.playerInventory.currentContainer = currentContainerObj.ContainerParent;
         currentContainerObj.isOpenOnPanel = false;
         //Close child containers as well
         CloseChildContainer(currentContainerObj);
         Container DestinationContainer = UWCharacter.Instance.playerInventory.currentContainer;
         if (UWCharacter.Instance.playerInventory.currentContainer == UWCharacter.Instance.playerInventory.playerContainer)
         {
             GetComponent <RawImage>().texture = UWCharacter.Instance.playerInventory.Blank;
             BackpackBg.SetActive(false);
             if ((DestinationContainer.CountItems() >= 8) && (DestinationContainer != UWCharacter.Instance.playerInventory.playerContainer))
             {
                 InvUp.SetActive(true);
                 InvDown.SetActive(true);
             }
             else
             {
                 InvUp.SetActive(false);
                 InvDown.SetActive(false);
             }
         }
         else
         {
             GetComponent <RawImage>().texture = DestinationContainer.transform.GetComponent <ObjectInteraction>().GetEquipDisplay().texture;
             BackpackBg.SetActive(true);
             if ((DestinationContainer.CountItems() >= 8) && (DestinationContainer != UWCharacter.Instance.playerInventory.playerContainer))
             {
                 InvUp.SetActive(true);
                 InvDown.SetActive(true);
             }
             else
             {
                 InvUp.SetActive(false);
                 InvDown.SetActive(false);
             }
         }
         for (short i = 0; i < 8; i++)
         {
             UWCharacter.Instance.playerInventory.SetObjectAtSlot((short)(i + 11), DestinationContainer.GetItemAt(i));
         }
     }
     else
     {
         if (UWCharacter.InteractionMode != UWCharacter.InteractionModePickup)
         {//Only allow this to happen when in pickup mode.
             return;
         }
         //Move the contents out of the container into the parent.
         //Container CurrentContainer = UWCharacter.Instance.playerInventory.currentContainer; //GameObject.Find(UWCharacter.Instance.playerInventory.currentContainer).GetComponent<Container>();
         Container DestinationContainer = UWCharacter.Instance.playerInventory.currentContainer.ContainerParent; //GameObject.Find(CurrentContainer.ContainerParent).GetComponent<Container>();
         if (Container.TestContainerRules(DestinationContainer, 11, false))
         {
             if (!CurrentObjectInHand.IsStackable())
             {
                 if (DestinationContainer.AddItemToContainer(CurrentObjectInHand))
                 {//Object has moved
                     CurrentObjectInHand = null;
                 }
             }
             else
             {
                 if (DestinationContainer.AddItemMergedItemToContainer(CurrentObjectInHand))
                 {//Object has moved
                     CurrentObjectInHand = null;
                 }
             }
         }
     }
 }
Пример #2
0
    public static bool TestContainerRules(Container cn, int SlotIndex)
    {
        if (SlotIndex<11)
        {
            return true;
        }
        if (GameWorldController.instance.playerUW.playerInventory.ObjectInHand=="")
        {
            return true;
        }
        //Test the various rules for this slot
        ObjectInteraction objInt = GameWorldController.instance.playerUW.playerInventory.GetGameObjectInHand().GetComponent<ObjectInteraction>();
        //If in a non player container check that the object in hand can be added to it.
        bool TypeTest=false;
        //If in a non player container check that the container has the weight capacity to accept it.
        bool WeightTest=false;
        //		Container curContainer = this;
        bool CapacityTest=false;

        switch (cn.ObjectsAccepted)
        {//objects accepted; 0: runes, 1: arrows, 2: scrolls, 3: edibles, 0xFF: any
        case 0://runes
            TypeTest=(objInt.GetItemType()==ObjectInteraction.RUNE);break;
        case 1://Arrows
            TypeTest=(objInt.GetItemType()==ObjectInteraction.AMMO);break;
        case 2://Scrolls
            TypeTest=(
                (objInt.GetItemType()==ObjectInteraction.SCROLL)
                ||
                (objInt.GetItemType()==ObjectInteraction.MAGICSCROLL)
                ||
                (objInt.GetItemType()==ObjectInteraction.MAP)
                ||
                (objInt.GetItemType()==ObjectInteraction.BOOK)
                );
            break;
        case 3: //Edibles
            TypeTest=((objInt.GetItemType()==ObjectInteraction.FOOD) || (objInt.GetItemType()==ObjectInteraction.POTIONS));break;
        default:
            TypeTest=true;break;
        }

        if (TypeTest==true)
        {
            if (objInt.GetWeight() >= cn.GetFreeCapacity())
            {
                WeightTest=false;
                UWHUD.instance.MessageScroll.Add ("The " + StringController.instance.GetSimpleObjectNameUW(cn.objInt()) + " is too full.");
            }
            else
            {
                WeightTest=true;
            }
        }
        else
        {//000~001~248~That item does not fit.
            UWHUD.instance.MessageScroll.Add (StringController.instance.GetString(1,248));
        }

        if (WeightTest==true)
        {
            if (cn.CountItems()<=cn.MaxCapacity())
            {
                CapacityTest=true;
            }
            else
            {//000~001~248~That item does not fit.
                UWHUD.instance.MessageScroll.Add (StringController.instance.GetString(1,248));
            }
        }
        return (TypeTest && WeightTest && CapacityTest);
    }
Пример #3
0
    public static bool TestContainerRules(Container cn, int SlotIndex, bool Swapping)
    {
        if (SlotIndex < 11)
        {
            return(true);
        }
        if (UWCharacter.Instance.playerInventory.ObjectInHand == "")
        {
            return(true);
        }
        //Test the various rules for this slot
        ObjectInteraction objInt = UWCharacter.Instance.playerInventory.GetGameObjectInHand().GetComponent <ObjectInteraction>();
        //If in a non player container check that the object in hand can be added to it.
        bool TypeTest = false;
        //If in a non player container check that the container has the weight capacity to accept it.
        bool WeightTest = false;
//		Container curContainer = this;
        bool CapacityTest = false;

        if (EditorMode)                        //Anything is allowed in editor mode.
        {
            return(true);
        }
        switch (cn.ObjectsAccepted())
        {        //objects accepted; 0: runes, 1: arrows, 2: scrolls, 3: edibles, 0xFF: any
        case 0:  //runes
            TypeTest = (objInt.GetItemType() == ObjectInteraction.RUNE); break;

        case 1:        //Arrows
            TypeTest = (objInt.GetItemType() == ObjectInteraction.AMMO); break;

        case 2:        //Scrolls
            TypeTest = (
                (objInt.GetItemType() == ObjectInteraction.SCROLL)
                ||
                (objInt.GetItemType() == ObjectInteraction.MAGICSCROLL)
                ||
                (objInt.GetItemType() == ObjectInteraction.MAP)
                ||
                (objInt.GetItemType() == ObjectInteraction.BOOK)
                );
            break;

        case 3:         //Edibles
            TypeTest = ((objInt.GetItemType() == ObjectInteraction.FOOD) || (objInt.GetItemType() == ObjectInteraction.POTIONS)); break;

        default:
            TypeTest = true; break;
        }

        if (TypeTest == true)
        {
            if (objInt.GetWeight() >= cn.GetFreeCapacity())
            {
                WeightTest = false;
                UWHUD.instance.MessageScroll.Add("The " + StringController.instance.GetSimpleObjectNameUW(cn.objInt()) + " is too full.");
            }
            else
            {
                WeightTest = true;
            }
        }
        else
        {        //000~001~248~That item does not fit.
            UWHUD.instance.MessageScroll.Add(StringController.instance.GetString(1, StringController.str_that_item_does_not_fit_));
        }

        if (WeightTest == true)
        {
            if (cn.CountItems() <= cn.MaxCapacity())
            {
                CapacityTest = true;
            }
            else
            {            //000~001~248~That item does not fit.
                UWHUD.instance.MessageScroll.Add(StringController.instance.GetString(1, StringController.str_that_item_does_not_fit_));
            }
        }
        return(TypeTest && WeightTest && (CapacityTest | Swapping));
    }
 public void OnClick()
 {
     if (Dragging == true)
     {
         return;
     }
     if (UWCharacter.Instance.playerInventory.currentContainer == UWCharacter.Instance.name)
     {                        //Don't do anything on the top level
         UWCharacter.Instance.playerInventory.ContainerOffset = 0;
         BackpackBg.SetActive(false);
         return;
     }
     if (UWCharacter.Instance.playerInventory.ObjectInHand == "")
     {                        //Player has no object in their hand. We close up the container.
         ScrollButtonInventory.ScrollValue = 0;
         UWCharacter.Instance.playerInventory.ContainerOffset = 0;
         Container currentContainerObj = UWCharacter.Instance.playerInventory.GetCurrentContainer();
         UWCharacter.Instance.playerInventory.currentContainer = currentContainerObj.ContainerParent;
         currentContainerObj.isOpenOnPanel = false;
         //Close child containers as well
         CloseChildContainer(currentContainerObj);
         Container DestinationContainer = UWCharacter.Instance.playerInventory.GetCurrentContainer();
         if (UWCharacter.Instance.playerInventory.currentContainer == UWCharacter.Instance.name)
         {
             GetComponent <RawImage>().texture = UWCharacter.Instance.playerInventory.Blank;
             BackpackBg.SetActive(false);
             if ((DestinationContainer.CountItems() >= 8) && (DestinationContainer != UWCharacter.Instance.playerInventory.playerContainer))
             {
                 InvUp.SetActive(true);
                 InvDown.SetActive(true);
             }
             else
             {
                 InvUp.SetActive(false);
                 InvDown.SetActive(false);
             }
         }
         else
         {
             GetComponent <RawImage>().texture = DestinationContainer.transform.GetComponent <ObjectInteraction>().GetEquipDisplay().texture;
             BackpackBg.SetActive(true);
             if ((DestinationContainer.CountItems() >= 8) && (DestinationContainer != UWCharacter.Instance.playerInventory.playerContainer))
             {
                 InvUp.SetActive(true);
                 InvDown.SetActive(true);
             }
             else
             {
                 InvUp.SetActive(false);
                 InvDown.SetActive(false);
             }
         }
         for (short i = 0; i < 8; i++)
         {
             string sItem = DestinationContainer.GetItemAt(i);
             UWCharacter.Instance.playerInventory.SetObjectAtSlot((short)(i + 11), sItem);
         }
     }
     else
     {
         if (UWCharacter.InteractionMode != UWCharacter.InteractionModePickup)
         {                                    //Only allow this to happen when in pickup mode.
             return;
         }
         //Move the contents out of the container into the parent.
         Container         CurrentContainer     = GameObject.Find(UWCharacter.Instance.playerInventory.currentContainer).GetComponent <Container>();
         Container         DestinationContainer = GameObject.Find(CurrentContainer.ContainerParent).GetComponent <Container>();
         ObjectInteraction item = GameObject.Find(UWCharacter.Instance.playerInventory.ObjectInHand).GetComponent <ObjectInteraction>();
         if (Container.TestContainerRules(DestinationContainer, 11, false))
         {
             //if ((item.isQuant()==false) || (item.isEnchanted()))
             if (!item.IsStackable())
             {
                 if (DestinationContainer.AddItemToContainer(UWCharacter.Instance.playerInventory.ObjectInHand))
                 {                                                            //Object has moved
                     UWHUD.instance.CursorIcon = UWHUD.instance.CursorIconDefault;
                     UWCharacter.Instance.playerInventory.ObjectInHand = "";
                 }
             }
             else
             {
                 if (DestinationContainer.AddItemMergedItemToContainer(item.gameObject))
                 {                                                            //Object has moved
                     UWHUD.instance.CursorIcon = UWHUD.instance.CursorIconDefault;
                     UWCharacter.Instance.playerInventory.ObjectInHand = "";
                 }
             }
         }
     }
 }