CanMerge() public static method

public static CanMerge ( ObjectInteraction mergingInto, ObjectInteraction mergingFrom ) : bool
mergingInto ObjectInteraction
mergingFrom ObjectInteraction
return bool
Exemplo n.º 1
0
 public bool AddItemMergedItemToContainer(GameObject item)
 {
     for (int i = 0; i <= MaxCapacity(); i++)
     {
         if (items[i] != "")
         {
             GameObject founditem = GameObject.Find(items[i]);
             if (ObjectInteraction.CanMerge(founditem.GetComponent <ObjectInteraction>(), item.GetComponent <ObjectInteraction>()))
             {
                 ObjectInteraction.Merge(founditem.GetComponent <ObjectInteraction>(), item.GetComponent <ObjectInteraction>());
                 return(true);
             }
         }
     }
     //otherwise just add in the usual way.
     return(AddItemToContainer(item.name));
 }
    /// <summary>
    /// Gets the game object at index.
    /// </summary>
    /// <returns>The <see cref="UnityEngine.GameObject"/>.</returns>
    /// <param name="index">Index.</param>

    /*	public GameObject GetGameObjectAt(short index)
     *  {
     *      Debug.Log("REMOVE2");
     *      if (GetItemAt(index)!="")
     *      {
     *          return GameObject.Find (GetItemAt (index));
     *      }
     *      else
     *      {
     *          return null;
     *      }
     *  }*/


    /* public ObjectInteraction GetObjectIntAt(short index)
     * {
     *   if (index<=items.GetUpperBound(0))
     *   {
     *       return items[index];
     *   }
     *   return null;
     *
     *   //GameObject obj = GetGameObjectAt(index);
     *   //if (obj!=null)
     *   //{
     *   //    return obj.GetComponent<ObjectInteraction>();
     *   //}
     *   //return null;
     * }*/

    public bool AddItemMergedItemToContainer(ObjectInteraction itemToAdd)
    {
        for (int i = 0; i <= MaxCapacity(); i++)
        {
            if (items[i] != null)
            {
                //GameObject founditem = GameObject.Find (items[i]);
                if (ObjectInteraction.CanMerge(items[i], itemToAdd))
                {
                    ObjectInteraction.Merge(items[i], itemToAdd);
                    return(true);
                }
            }
        }
        //otherwise just add in the usual way.
        return(AddItemToContainer(itemToAdd));
    }
Exemplo n.º 3
0
    void RightClickPickup()
    {
        //pInv = player.GetComponent<PlayerInventory>();
        GameObject ObjectUsedOn = null;      //The object at the clicked slot
        bool       DoNotPickup  = false;

        if (UWCharacter.Instance.playerInventory.ObjectInHand != "")
        {
            ObjectInteraction objInt = UWCharacter.Instance.playerInventory.GetGameObjectInHand().GetComponent <ObjectInteraction>();
            if ((SlotCategory != objInt.GetItemType()) && (SlotCategory != -1))
            {            //Slot is not a general use on andThis item type does not go in this slot.
                         //	Debug.Log ("cannot pickup an " + objInt.GetItemType() + " in a " + SlotCategory);
                DoNotPickup = true;
            }
            //Eating food dropped in helm slot
            if (SlotCategory == HELM)
            {
                if (objInt.GetItemType() == ObjectInteraction.FOOD)
                {
                    objInt.Use();
                    DoNotPickup = true;
                    return;
                }
            }

            //if ((objInt.isQuant()==true) && (objInt.isEnchanted()==false))
            if (objInt.IsStackable())
            {
                ObjectUsedOn = UWCharacter.Instance.playerInventory.GetGameObjectAtSlot(slotIndex);                //GameObject.Find (pInv.GetObjectAtSlot(slotIndex));
                if (ObjectUsedOn != null)
                {
                    if (ObjectInteraction.CanMerge(ObjectUsedOn.GetComponent <ObjectInteraction>(), objInt))
                    //	if ((objInt.item_id==ObjectUsedOn.GetComponent<ObjectInteraction>().item_id) && (objInt.quality==ObjectUsedOn.GetComponent<ObjectInteraction>().quality))
                    {
                        //merge the items
                        ObjectInteraction.Merge(ObjectUsedOn.GetComponent <ObjectInteraction>(), objInt);
                        //ObjectUsedOn.GetComponent<ObjectInteraction>().link=ObjectUsedOn.GetComponent<ObjectInteraction>().link+objInt.link;
                        UWHUD.instance.CursorIcon = UWHUD.instance.CursorIconDefault;
                        UWCharacter.Instance.playerInventory.ObjectInHand = "";
                        UWCharacter.Instance.playerInventory.Refresh(slotIndex);
                        //Destroy(objInt.gameObject);
                        return;
                    }
                }
            }
        }
        //Code for when I right click in pickup mode.
        if (UWCharacter.Instance.playerInventory.GetObjectAtSlot(slotIndex) != "")
        {                //Special case for opening containers in pickup mode.
            ObjectUsedOn = UWCharacter.Instance.playerInventory.GetGameObjectAtSlot(slotIndex);
            if ((UWCharacter.Instance.playerInventory.ObjectInHand == ""))
            {
                if (ObjectUsedOn.GetComponent <Container>() != null)
                {
                    if (ObjectUsedOn.GetComponent <Container>().isOpenOnPanel == true)
                    {
                        return;
                    }
                    UWCharacter.Instance.playerInventory.ObjectInHand = ObjectUsedOn.name;
                    UWHUD.instance.CursorIcon = ObjectUsedOn.GetComponent <ObjectInteraction>().GetInventoryDisplay().texture;
                    if (this.slotIndex >= 11)
                    {
                        //Container cn = //;GameObject.Find(pInv.currentContainer).GetComponent<Container>();
                        UWCharacter.Instance.playerInventory.GetCurrentContainer().RemoveItemFromContainer(UWCharacter.Instance.playerInventory.ContainerOffset + this.slotIndex - 11);
                    }
                    UWCharacter.Instance.playerInventory.ClearSlot(this.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("");                            // .ObjectInHand="";
                }
            }
        }
        else
        {
            bool ObjectActivated = false;
            //Get the object at the slot and test it's activation.
            ObjectUsedOn = UWCharacter.Instance.playerInventory.GetGameObjectAtSlot(slotIndex);            //GameObject.Find (pInv.GetObjectAtSlot(slotIndex));
            //When right clicking only try to activate when an object in in the hand
            if (UWCharacter.Instance.playerInventory.GetObjectInHand() != "")
            {
                ObjectActivated = ObjectUsedOn.GetComponent <ObjectInteraction>().Use();
            }
            if (ObjectActivated == false)
            {                    //if nothing happened when I clicked on the object at the slot with something in hand.
                if (UWCharacter.Instance.playerInventory.GetObjectInHand() != "")
                {
                    if (DoNotPickup == false)
                    {
                        //TODO: Make sure this works with Equipment slots
                        //No effect occurred. Swap the two objects.
                        if (Container.TestContainerRules(UWCharacter.Instance.playerInventory.GetCurrentContainer(), slotIndex, true))
                        {
                            UWCharacter.Instance.playerInventory.SwapObjects(ObjectUsedOn, slotIndex, UWCharacter.Instance.playerInventory.ObjectInHand);
                            UWCharacter.Instance.playerInventory.Refresh();
                        }
                    }
                }
                else
                {                        //Pick up the item at that slot.
                    //TODO: Make this work with Equipment slots
                    if (DoNotPickup == false)
                    {
                        ObjectInteraction objIntUsedOn = ObjectUsedOn.GetComponent <ObjectInteraction>();
                        //if ((ObjectUsedOn.GetComponent<ObjectInteraction>().isQuant() ==false) || ((ObjectUsedOn.GetComponent<ObjectInteraction>().isQuant())&&(ObjectUsedOn.GetComponent<ObjectInteraction>().link==1)) || (ObjectUsedOn.GetComponent<ObjectInteraction>().isEnchanted() ==true))
                        if ((!objIntUsedOn.IsStackable()) || ((objIntUsedOn.IsStackable()) && (objIntUsedOn.GetQty() <= 1)))
                        {                                //Is either not a quant or is a quantity of 1
                            UWCharacter.Instance.playerInventory.ObjectInHand = ObjectUsedOn.name;
                            //UWHUD.instance.CursorIcon= ObjectUsedOn.GetComponent<ObjectInteraction>().GetInventoryDisplay().texture;
                            UWHUD.instance.CursorIcon = objIntUsedOn.GetInventoryDisplay().texture;
                            if (this.slotIndex >= 11)
                            {
                                UWCharacter.Instance.playerInventory.GetCurrentContainer().RemoveItemFromContainer(UWCharacter.Instance.playerInventory.ContainerOffset + this.slotIndex - 11);
                            }
                            UWCharacter.Instance.playerInventory.ClearSlot(this.slotIndex);
                        }
                        else
                        {
                            //Debug.Log("attempting to pick up a quantity");
                            if (ConversationVM.InConversation == true)
                            {
                                //UWHUD.instance.MessageScroll.SetAnchorX(1.0f);//Move off screen.
                                //UWHUD.instance.MessageScrollTemp.SetAnchorX(0.06f);
                                InventorySlot.TempLookAt = UWHUD.instance.MessageScroll.NewUIOUt.text;
                                UWHUD.instance.MessageScroll.Set("Move how many?");

                                ConversationVM.EnteringQty = true;
                            }
                            else
                            {
                                UWHUD.instance.MessageScroll.Set("Move how many?");
                            }
                            InputField inputctrl = UWHUD.instance.InputControl;

                            inputctrl.gameObject.SetActive(true);
                            inputctrl.text = objIntUsedOn.GetQty().ToString();                          //"1";


                            inputctrl.gameObject.GetComponent <InputHandler>().target           = this.gameObject;
                            inputctrl.gameObject.GetComponent <InputHandler>().currentInputMode = InputHandler.InputInventoryQty;

                            inputctrl.contentType = InputField.ContentType.IntegerNumber;
                            inputctrl.Select();

                            WindowDetect.WaitingForInput = true;
                            Time.timeScale = 0.0f;
                            QuantityObj    = ObjectUsedOn;
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 4
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);
                }
            }
        }
    }
    void RightClickPickup()
    {
        ObjectInteraction ObjectUsedOn = UWCharacter.Instance.playerInventory.GetObjectIntAtSlot(slotIndex);//The object at the clicked slot
        bool DoNotPickup = false;

        if (CurrentObjectInHand != null)
        {
            if ((SlotCategory != CurrentObjectInHand.GetItemType()) && (SlotCategory != -1))
            {//Slot is not a general use on and This item type does not go in this slot.
                DoNotPickup = true;
            }
            //Eating food dropped in helm slot
            if (SlotCategory == HELM)
            {
                if (CurrentObjectInHand.GetItemType() == ObjectInteraction.FOOD)
                {
                    CurrentObjectInHand.Use();
                    DoNotPickup = true;
                    return;
                }
            }

            if (CurrentObjectInHand.IsStackable())
            {
                if (ObjectUsedOn != null)
                {
                    if (ObjectInteraction.CanMerge(ObjectUsedOn, CurrentObjectInHand))
                    {
                        //merge the items
                        ObjectInteraction.Merge(ObjectUsedOn, CurrentObjectInHand);
                        CurrentObjectInHand = null;
                        UWCharacter.Instance.playerInventory.Refresh();
                        return;
                    }
                }
            }
        }

        //Code for when I right click in pickup mode.
        if (UWCharacter.Instance.playerInventory.GetObjectAtSlot(slotIndex) != null)
        {//Special case for opening containers in pickup mode.
            if ((CurrentObjectInHand == null))
            {
                if (ObjectUsedOn.GetComponent <Container>() != null)
                {
                    if (ObjectUsedOn.GetComponent <Container>().isOpenOnPanel == true)
                    {
                        return;
                    }
                    CurrentObjectInHand = ObjectUsedOn.GetComponent <ObjectInteraction>();
                    if (this.slotIndex >= 11)
                    {
                        UWCharacter.Instance.playerInventory.currentContainer.RemoveItemFromContainer(UWCharacter.Instance.playerInventory.ContainerOffset + this.slotIndex - 11);
                    }
                    UWCharacter.Instance.playerInventory.ClearSlot(this.slotIndex);
                    return;
                }
            }
        }

        if (UWCharacter.Instance.playerInventory.GetObjectAtSlot(slotIndex) == null)//No object in slot
        {
            if (DoNotPickup == false)
            {
                if (Container.TestContainerRules(UWCharacter.Instance.playerInventory.currentContainer, slotIndex, false))
                {
                    UWCharacter.Instance.playerInventory.SetObjectAtSlot(slotIndex, CurrentObjectInHand);
                    CurrentObjectInHand = null;
                }
            }
        }
        else
        {
            bool ObjectActivated = false;
            //Get the object at the slot and test it's activation.

            //When right clicking only try to activate when an object in in the hand
            if (CurrentObjectInHand != null)
            {
                ObjectActivated = ObjectUsedOn.GetComponent <ObjectInteraction>().Use();
            }
            if (ObjectActivated == false)
            {//if nothing happened when I clicked on the object at the slot with something in hand.
                if (CurrentObjectInHand != null)
                {
                    if (DoNotPickup == false)
                    {
                        //TODO: Make sure this works with Equipment slots
                        //No effect occurred. Swap the two objects.
                        if (Container.TestContainerRules(UWCharacter.Instance.playerInventory.currentContainer, slotIndex, true))
                        {
                            UWCharacter.Instance.playerInventory.SwapObjects(ObjectUsedOn, slotIndex, CurrentObjectInHand);
                            UWCharacter.Instance.playerInventory.Refresh();
                        }
                    }
                }
                else
                {//Pick up the item at that slot.
                 //TODO: Make this work with Equipment slots
                    if (DoNotPickup == false)
                    {
                        ObjectInteraction objIntUsedOn = ObjectUsedOn.GetComponent <ObjectInteraction>();
                        if ((!objIntUsedOn.IsStackable()) || ((objIntUsedOn.IsStackable()) && (objIntUsedOn.GetQty() <= 1)))
                        {//Is either not a quant or is a quantity of 1
                            CurrentObjectInHand = ObjectUsedOn;
                            if (this.slotIndex >= 11)
                            {
                                UWCharacter.Instance.playerInventory.currentContainer.RemoveItemFromContainer(UWCharacter.Instance.playerInventory.ContainerOffset + this.slotIndex - 11);
                            }
                            UWCharacter.Instance.playerInventory.ClearSlot(this.slotIndex);
                        }
                        else
                        {
                            if (ConversationVM.InConversation == true)
                            {
                                //InventorySlot.TempLookAt = UWHUD.instance.MessageScroll.NewUIOUt.text;
                                //UWHUD.instance.MessageScroll.NewUIOUt.text = "";
                                UWHUD.instance.ConversationButtonParent.SetActive(false);
                                UWHUD.instance.MessageScroll.Set("Move how many?");
                                ConversationVM.EnteringQty = true;
                            }
                            else
                            {
                                UWHUD.instance.MessageScroll.Set("Move how many?");
                            }
                            InputField inputctrl = UWHUD.instance.InputControl;

                            inputctrl.gameObject.SetActive(true);
                            inputctrl.text = objIntUsedOn.GetQty().ToString();//"1";
                            inputctrl.gameObject.GetComponent <InputHandler>().target           = this.gameObject;
                            inputctrl.gameObject.GetComponent <InputHandler>().currentInputMode = InputHandler.InputInventoryQty;
                            inputctrl.contentType = InputField.ContentType.IntegerNumber;
                            inputctrl.Select();

                            WindowDetect.WaitingForInput = true;
                            Time.timeScale = 0.0f;
                            QuantityObj    = ObjectUsedOn;
                        }
                    }
                }
            }
        }
    }
    /// <summary>
    /// Code for when left clicking in pickup mode
    /// </summary>
    void LeftClickPickup()
    {
        ObjectInteraction ObjectUsedOn = UWCharacter.Instance.playerInventory.GetObjectIntAtSlot(slotIndex);
        bool DoNotPickup = false;

        if (CurrentObjectInHand != null)
        {
            //Special case Eating food dropped on helm slot
            if (SlotCategory == HELM)
            {
                if (CurrentObjectInHand.Eat())
                {//True is returned if some eating action has taken place.
                    DoNotPickup = true;
                    return;
                }
            }

            if ((SlotCategory != CurrentObjectInHand.GetItemType()) && (SlotCategory != -1))
            {//Slot is not a general use one and this item type does not go in this slot. Eg putting a sword on a ring slot
                DoNotPickup = true;
            }

            if (CurrentObjectInHand.IsStackable())
            {//Check if object is stackable and if so try and merge them together if the object being added is of the same type.
                if (ObjectUsedOn != null)
                {
                    if (ObjectInteraction.CanMerge(ObjectUsedOn, CurrentObjectInHand))
                    {
                        ObjectInteraction.Merge(ObjectUsedOn, CurrentObjectInHand);
                        CurrentObjectInHand = null;
                        UWCharacter.Instance.playerInventory.Refresh();
                        return;
                    }
                }
            }
        }


        if (ObjectUsedOn == null)//No object in slot -> add to the slot
        {
            if (DoNotPickup == false)
            {
                if (Container.TestContainerRules(UWCharacter.Instance.playerInventory.currentContainer, slotIndex, false))
                {
                    UWCharacter.Instance.playerInventory.SetObjectAtSlot(slotIndex, CurrentObjectInHand);
                    CurrentObjectInHand = null;
                }
            }
        }
        else
        {
            //Get the object at the slot and test if it is activated or effected by the object in the players hand
            if (ObjectUsedOn.Use() == false)
            {//if nothing happened when I clicked on the object at the slot.
                if (CurrentObjectInHand != null)
                {
                    //TODO: Make sure this works with Equipment slots
                    //No effect occurred. Swap the two objects.
                    if (DoNotPickup == false)
                    {
                        if (Container.TestContainerRules(UWCharacter.Instance.playerInventory.currentContainer, slotIndex, true))
                        {
                            UWCharacter.Instance.playerInventory.SwapObjects(ObjectUsedOn, slotIndex, CurrentObjectInHand);
                        }
                    }
                }
                else
                {//Pick up the item at that slot.
                 //TODO: Make this work with Equipment slots
                    CurrentObjectInHand = ObjectUsedOn;
                    if (this.slotIndex >= 11)
                    {
                        UWCharacter.Instance.playerInventory.currentContainer.RemoveItemFromContainer(UWCharacter.Instance.playerInventory.ContainerOffset + this.slotIndex - 11);
                    }
                    UWCharacter.Instance.playerInventory.ClearSlot(this.slotIndex);
                }
            }
        }
    }