Ejemplo n.º 1
0
    private bool SwapItems(SlotScript from)
    {
        if (IsEmpty)
        {
            return(false);
        }
        if (from.MyItem.GetType() != MyItem.GetType() || from.MyCount + MyCount > MyItem.MyStackSize)
        {
            //copy all the items we need to swap from A
            ObservableStack <Item> tmpFrom = new ObservableStack <Item>(from.items);

            //clear slot A
            from.items.Clear();
            //all items from slot B and copy them into A
            from.AddItems(items);

            //clear B
            items.Clear();
            //move the items from A copy to B
            AddItems(tmpFrom);

            return(true);
        }
        return(false);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Swaps two items in the inventory
    /// </summary>
    /// <param name="from"></param>
    /// <returns></returns>
    private bool SwapItems(SlotScript from)
    {
        from.MyCover.enabled = false;
        if (IsEmpty)
        {
            return(false);
        }
        if (from.MyItem.GetType() != MyItem.GetType() || from.MyCount + MyCount > MyItem.MyStackSize)
        {
            //Copy all the items we need to swap from A
            ObservableStack <Item> tmpFrom = new ObservableStack <Item>(from.MyItems);

            //Clear Slot a
            from.MyItems.Clear();
            //All items from slot b and copy them into A
            from.AddItems(MyItems);

            //Clear B
            MyItems.Clear();
            //Move the items from ACopy to B
            AddItems(tmpFrom);

            return(true);
        }

        return(false);
    }
    private bool SwapItems(InventorySlots from)
    {
        if (IsEmpty)
        {
            return(false);
        }
        if (from.MyItem.GetType() != MyItem.GetType() || from.MyCount + MyCount > MyItem.StackSize)
        {
            //Copy all items from A
            ObservableStack <Item> tmpFrom = new ObservableStack <Item>(from.itemStack);
            Debug.Log("SLOT A COPIED TO B");
            //Clear slot A
            from.itemStack.Clear();
            Debug.Log("SLOT A CLEARED");

            //Copy from B and put in A
            from.AddItems(itemStack);

            //Clear B
            itemStack.Clear();

            //Move from the copy of A to B
            AddItems(tmpFrom);
            return(true);
        }
        return(false);
    }
Ejemplo n.º 4
0
    }//end of PutItemBack function

    private bool SwapItems(SlotScript from)
    {
        if (IsEmpty)
        {
            return(false);
        }

        if (from.MyItem.GetType() != MyItem.GetType() || from.MyCount + MyCount > MyItem.MyStackSize)
        {
            //copy all items need to be swap from slot A
            ObservableStack <Item> tmpFrom = new ObservableStack <Item>(from.items);

            //Clear the slot A
            from.items.Clear();

            //Take everything from slot B and copy it into A
            from.AddItems(items);

            //Clear B
            items.Clear();

            //Move from A to B
            AddItems(tmpFrom);
            return(true);
        }
        return(false);
    }// end of SwapItems function
Ejemplo n.º 5
0
    private bool SwapItems(SlotScript from)
    {
        if (IsEmpty)
        {
            return(false);
        }

        if (from.MyItem.GetType() != MyItem.GetType() || from.MyCount + MyCount > MyItem.MyStackSize)
        {
            //cópia de todos os itens
            ObservableStack <Item> tmpFrom = new ObservableStack <Item>(from.items);

            //limpa slot A
            from.items.Clear();
            //Todos os itens do slot B, copia para o slot A
            from.AddItems(items);

            //limpa slot B
            items.Clear();
            //Move os itens cópia do slot A para o slot B
            AddItems(tmpFrom);

            return(true);
        }

        return(false);
    }
        public ActionResult UpdateValue(ChangedDataItems[] changedValues)
        {
            /* some delay */
            System.Threading.Thread.Sleep(1000);

            String status = null;

            foreach (ChangedDataItems dataItem in changedValues)
            {
                MyItem item = GetList.First(i => i.Id == dataItem.key);

                /* some way to set a propery */
                PropertyInfo info = item.GetType().GetProperty(dataItem.field, BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty);


                if (info.CanWrite)
                {
                    info.SetValue(item, TypeDescriptor.GetConverter(info.PropertyType).ConvertFromString(dataItem.value), null);
                }
                else
                {
                    status = "Updating cannot be performed over a readonly field";
                    break;
                }
            }
            if (status == null)
            {
                status = "All fields successfully updated";
            }
            return(Content(status));
        }
Ejemplo n.º 7
0
    private bool SwapItems(SlotScript from)
    {
        if (IsEmpty)
        {
            return(false);
        }
        if (from.MyItem.GetType() != MyItem.GetType() || from.MyCount + MyCount > MyItem.MyStackSize)
        {
            //kopija itema iz slota A
            ObservableStack <Item> tmpFrom = new ObservableStack <Item>(from.MyItems);

            //ocisti slot A
            from.MyItems.Clear();
            //uzmemo sve iteme iz slota B i kopira ih u slot A
            from.AddItems(MyItems);

            //ocisti slot B
            MyItems.Clear();
            //premjesti iteme iz Atmp u B
            AddItems(tmpFrom);

            return(true);
        }

        return(false);
    }
Ejemplo n.º 8
0
    /// <summary>
    /// Places a stack of items in a new slot of the bags or tries to stack them if they are of the same type
    /// </summary>
    /// <param name="newItems"></param>
    /// <returns></returns>
    public bool AddItems(ObservableStack <Item> newItems)
    {
        // if the slot is empty or if the slot has items of the same type
        if (IsEmpty || newItems.Peek().GetType() == MyItem.GetType())
        {
            // how many items do I have in my hand?
            int count = newItems.Count;

            // for each of the items I have in my hand
            for (int i = 0; i < count; i++)
            {
                // if the stack is full
                if (IsFull)
                {
                    // then stop trying to add items to it
                    return(false);
                }

                // if its not full then add the current iteration of the items in my hand
                AddItem(newItems.Pop());
            }

            // we managed to get through all the items and we have no more items in our hand
            return(true);
        }

        // this slot is not empty or the things there are not of the same type so the function cannot do anything
        return(false);
    }
Ejemplo n.º 9
0
    private bool SwapItems(SlotScript from)
    {
        if (IsEmpty)
        {
            return(false);
        }
        if (from.MyItem.GetType() != MyItem.GetType() || from.MyCount + MyCount > MyItem.MyStackSize)
        {
            // Copy all the items we need to swap from slot A
            ObservableStack <Item> tmpFrom = new ObservableStack <Item>(from.MyItems);

            // Clear slot A
            from.MyItems.Clear();
            from.rarityFrame.enabled = false;

            // Take all items from Slot B and copy them into slot A
            from.AddItems(MyItems);

            // Clear slot B
            MyItems.Clear();

            // Move the items from Copy A to B
            AddItems(tmpFrom);

            return(true);
        }

        return(false);
    }
Ejemplo n.º 10
0
 //Merges two stacks of the same items
 private bool MergeItems(SlotScript from)
 {
     if (IsEmpty)
     {
         return(false);
     }
     if (from.MyItem.GetType() == MyItem.GetType() && !IsFull)
     {
         //How many free slots are available in the stack
         int free = MyItem.MyStackSize - MyCount;
         for (int i = 0; i < free; i++)
         {
             AddItem(from.items.Pop());
         }
         return(true);
     }
     return(false);
 }
Ejemplo n.º 11
0
    private bool SwapItems(SlotScript from)
    {
        if (IsEmpty)
        {
            return(false);
        }

        if (from.MyItem.GetType() != MyItem.GetType() || from.IsFull || IsFull)
        {
            ObservableStack <Item> tmpFrom = new ObservableStack <Item>(from.MyItems);
            from.MyItems.Clear();
            from.AddItems(MyItems);
            MyItems.Clear();
            AddItems(tmpFrom);
            return(true);
        }
        return(false);
    }
Ejemplo n.º 12
0
    public bool AddItems(ObservableStack <Item> newItems)
    {
        if (IsEmpty || newItems.Peek().GetType() == MyItem.GetType())
        {
            int count = newItems.Count;

            for (int i = 0; i < count; i++)
            {
                if (IsFull)
                {
                    return(false);
                }
                AddItem(newItems.Pop());
            }
            return(true);
        }
        return(false);
    }
    public bool AddItems(ObservableStack <Item> newItems)
    {
        if (IsEmpty || newItems.Peek().GetType() == MyItem.GetType())
        {
            int count = newItems.Count;

            for (int i = 0; i < count; i++)
            {
                if (IsFull)
                {
                    Debug.Log("The slot is full");
                    return(false);
                }
                AddItem(newItems.Pop()); //puts all items in the slot if its not full
            }
            return(true);
        }
        return(false);
    }
Ejemplo n.º 14
0
    private bool MergeItems(SlotScript from)
    {
        if (IsEmpty)
        {
            return(false);
        }

        if (from.MyItem.GetType() != MyItem.GetType() && !IsFull)
        {
            int free = MyItem.MyStackSize - MyCount;

            for (int i = 0; i < free; i++)
            {
                AddItem(from.MyItems.Pop());
            }
            return(true);
        }
        return(false);
    }
Ejemplo n.º 15
0
    }//end of AddItem function

    public bool AddItems(ObservableStack <Item> newItems)
    {
        if (IsEmpty || newItems.Peek().GetType() == MyItem.GetType())   //check for empty slot or items are same type

        {
            int count = newItems.Count;     //if the above condition matches set the count of items

            for (int i = 0; i < count; i++) // take all the item one by one and put it in the new slot
            {
                if (IsFull)
                {
                    return(false);
                }//end of if inside for loop

                AddItem(newItems.Pop());
            } //end of for
            return(true);
        }     //end of if
        return(false);
    }         //end of the function Additems
Ejemplo n.º 16
0
    private bool SwapItems(SlotScript from)
    {
        if (IsEmpty)
        {
            return(false);
        }
        if ((from.MyItem.GetType() != MyItem.GetType()) || (from.MyCount + MyCount > MyItem.MyStackSize))
        {
            ObservableStack <Item> tmpFrom = new ObservableStack <Item>(from.items);

            from.items.Clear();
            from.AddItems(items);

            items.Clear();
            AddItems(tmpFrom);

            return(true);
        }
        return(false);
    }
Ejemplo n.º 17
0
    }// end of SwapItems function

    private bool MergeItems(SlotScript from)
    {
        if (IsEmpty)
        {
            return(false);
        }

        if (from.MyItem.GetType() == MyItem.GetType() && !IsFull)
        {
            //calculate the free slot
            int free = MyItem.MyStackSize - MyCount;

            for (int i = 0; i < free; i++)
            {
                AddItem(from.items.Pop());
            }//end of the for loop

            return(true);
        } //end of the second if
        return(false);
    }     //end of MergeItems function
Ejemplo n.º 18
0
    private bool SwapItems(SlotScript from)
    {
        from.MyCover.enabled = false;
        if (IsEmpty)
        {
            return(false);
        }

        if (from.MyItem.GetType() != MyItem.GetType() || from.MyCount + MyCount > MyItem.MyStackSize)
        {
            ObservableStack <Item> tmpFrom = new ObservableStack <Item>(from.MyItems);

            from.MyItems.Clear();
            from.AddItems(MyItems);

            MyItems.Clear();
            AddItems(tmpFrom);

            return(true);
        }
        return(false);
    }
    private bool MergeItems(InventorySlots from)
    {
        /*
         * MergeItems will be checked only by the pointer
         */
        Debug.Log("MergeItems have been called");
        if (IsEmpty)
        {
            return(false);
        }
        if (from.MyItem.GetType() == MyItem.GetType() && !IsFull)
        {
            //How many free slots are there
            int freeSpace = MyItem.StackSize - MyCount;

            for (int i = 0; i < freeSpace; i++)
            {
                AddItem(from.itemStack.Pop());
            }
            return(true);
        }
        return(false);
    }
Ejemplo n.º 20
0
        public ActionResult UpdateValue(Int32 key, String field, String value)
        {
            /* some delay */
            System.Threading.Thread.Sleep(1000);

            MyItem item = GetList.First(i => i.Id == key);

            /* some way to set a propery */
            PropertyInfo info = item.GetType().GetProperty(field, BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty);

            String status;

            if (info.CanWrite)
            {
                info.SetValue(item, TypeDescriptor.GetConverter(info.PropertyType).ConvertFromString(value), null);
                status = String.Format("Field: <b>{0}</b> is updated with the <i>{1}</i> value", field, value);
            }
            else
            {
                status = "Updating cannot be performed over a readonly field";
            }

            return(Content(status));
        }
Ejemplo n.º 21
0
    private bool SwapItems(SlotScript from)
    {
        if (IsEmpty)
        {
            return(false);
        }

        // if the item im moving is different from the item(s) in this slot
        // or if the count of items in my hand plus the items in this slot is larger than the total stacksize allowed
        if (from.MyItem.GetType() != MyItem.GetType() || from.MyCount + MyCount > MyItem.MyStackSize)
        {
            // copy all the items we need to swap from A
            ObservableStack <Item> tmpFrom = new ObservableStack <Item>(from.MyItems);

            // clear slot A
            from.MyItems.Clear();
            // take all items from slot B and copy them into A
            from.AddItems(MyItems);

            // Clear slot B
            MyItems.Clear();
            // Adding the items we originally copied into this slot
            AddItems(tmpFrom);

            Debug.Log("from slotting");

            if (showingToolTip)
            {
                UiManager.instance.RefreshToolTip(MyItem);
            }

            return(true);
        }

        return(false);
    }
    public bool SwapItems(SlotScript from)
    {
        if (IsEmpty)
        {
            return(false);
        }

        int x = from.MyCount + MyCount;

        if (from.MyItem.GetType() != MyItem.GetType() || x > MyItem.MyStackSize)
        {
            ObservableStack <Item> tmpFrom = new ObservableStack <Item>(from.MyItems);

            from.MyItems.Clear();
            from.AddItems(MyItems);

            MyItems.Clear();
            AddItems(tmpFrom);

            return(true);
        }

        return(false);
    }