Container.TestContainerRules C# (CSharp) Method

TestContainerRules() public static method

public static TestContainerRules ( Container, cn, int SlotIndex ) : bool
cn Container,
SlotIndex int
return bool
    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);
    }

Usage Example

Ejemplo n.º 1
0
    public override bool use()
    {
        GameObject ObjectInHand = playerUW.playerInventory.GetGameObjectInHand();

        //TODO:add object to container or open container.
        //Container cn = this.gameObject.GetComponent<Container>();
        if (ObjectInHand == null)
        {        //Open the container
            OpenContainer();
            return(true);
        }
        else
        {        //Put the item in the container.
            bool Valid = true;
            if (ObjectInHand.GetComponent <Container>() != null)
            {
                if (this.gameObject.name == ObjectInHand.GetComponent <Container>().name)
                {
                    Valid = false;
                    Debug.Log("Attempt to add a container to itself");
                }
            }
            //TODO:Do a test for Container capacity  here.
            //TODO:Do a test for item types accepted.
            if (Container.TestContainerRules(this, 11) == false)
            {
                Valid = false;
                return(true);
            }


            if (Valid)
            {
                if ((ObjectInHand.GetComponent <ObjectInteraction>().isQuant == false) || (ObjectInHand.GetComponent <ObjectInteraction>().isEnchanted))
                {
                    AddItemToContainer(playerUW.playerInventory.ObjectInHand);
                }
                else
                {
                    AddItemMergedItemToContainer(ObjectInHand.gameObject);
                }

                if (isOpenOnPanel == true)
                {                //Container is open for display force a refresh.
                    OpenContainer();
                }
                playerUW.playerInventory.ObjectInHand = "";
                playerUW.CursorIcon = playerUW.CursorIconDefault;

                return(true);
            }
            else
            {
                return(false);
            }
        }
    }
All Usage Examples Of Container::TestContainerRules