Ejemplo n.º 1
0
        /// <summary>
        ///     Stacks the attached item onto the other item and returns true if it was stacked.
        /// </summary>
        /// <param name="other">The item that will act as the stack.</param>
        /// <returns>True if attached item was stacked onto other item, otherwise false.</returns>
        public bool AvoidSwap(ISwappable other)
        {
            // if the other swappable is an item
            if (other.GetType() == typeof(Item))
            {
                // cast the swappable to an item
                Item otherItem = (Item)other;

                // if the item types are the same we can potentially stack them
                if (otherItem.itemType == itemType)
                {
                    int remainder = stackItems(this, otherItem);
                    if (remainder == 0)
                    {
                        UnityEngine.Object.Destroy(Icon.gameObject);
                        return(true);
                    }
                    else
                    {
                        SubtractFromAmt(int.MaxValue);
                        AddToAmt(remainder);
                        return(true);
                    }
                }
                return(false);
            }
            Debug.Log("Avoid");
            return(true);
        }
Ejemplo n.º 2
0
 public void DestroyAttachedSwappable()
 {
     if (attachedSwappable != null)
     {
         attachedSwappable.OnDestroy();
         attachedSwappable = null;
     }
 }
Ejemplo n.º 3
0
 public void SetSwap(ISwappable <T> swapUnit1, ISwappable <T> swapUnit2)
 {
     // swap if the new one is not the same as the current one
     if (swapUnit1 != swapUnit2)
     {
         T temp = swapUnit1.SwapData;
         swapUnit1.SwapData = swapUnit2.SwapData;
         swapUnit2.SwapData = temp;
     }
 }
Ejemplo n.º 4
0
        public void SetAttachedSwappable(ISwappable _attachedSwappable)
        {
            attachedSwappable = _attachedSwappable;

            // set a new parent so it appears over all slots
            attachedSwappable.Icon.transform.SetParent(movementParent);

            // make sure it isn't clickable
            attachedSwappable.Icon.raycastTarget = false;
        }
 public void Swap(ISwappable swapWith)
 {
     if (base.ContainsKey(swapWith.OldKey))
     {
         base.Remove(swapWith.OldKey);
         this.Add(swapWith.AsNewPair());
     }
     else
     {
         throw new KeyNotFoundException(string.Format(ERR_MSG, swapWith.OldKey));
     }
 }
 public void Swap(string newKey, StringComparison comparison = CASESENSITIVE)
 {
     if (this.TryGetKvp(newKey, comparison, out KeyValuePair <string, object> foundKvp))
     {
         ISwappable iswap = DictionarySwap.New(newKey, foundKvp);
         this.Swap(iswap);
     }
     else
     {
         throw new KeyNotFoundException(string.Format(ERR_MSG, newKey));
     }
 }
Ejemplo n.º 7
0
 private void ReplaceParameters(ref SwappableDictionary swapd)
 {
     foreach (KeyValuePair <string, string> kvp in Opposites)
     {
         if (swapd.ContainsKey(kvp.Key))
         {
             bool       val  = !((SwitchParameter)swapd[kvp.Key]).ToBool();
             ISwappable swap = swapd.NewSwappable(kvp.Value, kvp.Key);
             swapd.Swap(swap);
             swapd[kvp.Value] = val;
         }
     }
 }
Ejemplo n.º 8
0
        private bool CompareSwappables(ISwappable exp1, BinaryOperator exp2)
        {
            if ((exp1 as BinaryOperator).Left is ISwappable || (exp1 as BinaryOperator).Right is ISwappable)
            {
                return(SwappableCompareAlgorithem(exp1, exp2));
            }
            else if (CompareSides(exp1 as BinaryOperator, exp2) || CompareSides(exp1.Swap().Reduce() as BinaryOperator, exp2))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 9
0
        private void OpenSellPanel()
        {
            // get the swappable attached to the mouse
            ISwappable swappable = swapManager.GetAttachedSwappable();

            // if there is a swappable and its an item
            if (swappable != null && swappable.GetType() == typeof(Item))
            {
                // open the sell panel with that item.
                Item item = (Item)swappable;
                Shop.OpenSellPanel(item);

                // return the attached item back to its slot
                swapManager.StopSwap();
            }
        }
Ejemplo n.º 10
0
        private bool SwappableCompareAlgorithem(ISwappable exp1, BinaryOperator exp2)
        {
            BinaryOperator modified = (exp1 as BinaryOperator).Clone() as BinaryOperator;

            if (modified.ToStringParent() == exp2.ToStringParent())
            {
                return(true);
            }

            //Transforms modified until modified == exp2 or modified == exp1
            //When modified == exp2 then exp1s result is the same as exp2, aka they are the same
            //When modified == exp1 then the loop is done, and it found no matching trees.
            do
            {
                //First, transform modified.
                modified = (modified as ISwappable).Transform();

                if (modified.ToStringParent() == exp2.ToStringParent())
                {
                    return(true);
                }

                //Second, swap one of the swappable sides.
                if (modified.Left is ISwappable)
                {
                    modified.Left = (modified.Left as ISwappable).Swap();

                    if (modified.ToStringParent() == exp2.ToStringParent())
                    {
                        return(true);
                    }
                }
                else if (modified.Right is ISwappable)
                {
                    modified.Right = (modified.Right as ISwappable).Swap();

                    if (modified.ToStringParent() == exp2.ToStringParent())
                    {
                        return(true);
                    }
                }
            } while (!(modified.ToStringParent() == exp1.ToStringParent()));

            return(false);
        }
Ejemplo n.º 11
0
        /// <summary>
        ///     Swaps the positions of 1-2 item <see cref="Image"/>'s in the inventory UI.
        ///     <para>
        ///         If there is an empty slot that can hold an item, other is null and a slotHandler must be given.
        ///     </para>
        /// </summary>
        /// <param name="otherSlotIndex">The slot index of the other item</param>
        /// <param name="other">The other item that will be swapped with the <see cref="attachedSwappable"/></param>
        /// <param name="slotHandler">Used to move the attached item to the correct empty slot</param>
        public void SwapPositions(int otherSlotIndex, ISwappable other, SlotsHandler slotHandler = null)
        {
            if (other != null)
            {
                if (attachedSwappable.AvoidSwap(other))
                {
                    return;
                }

                SlotsHandler attachedSlotHandler = attachedSwappable.SlotsHandler;

                // move other swappable to the attached swappables slot
                int temp_idx = attachedSwappable.SlotIndex;
                other.SlotIndex = attachedSwappable.SlotIndex;
                attachedSlotHandler.MoveImageToSlot(other.Icon.gameObject, temp_idx);

                // move attached swappable to the other swappables slot
                attachedSwappable.SlotIndex = otherSlotIndex;
                other.SlotsHandler.MoveImageToSlot(attachedSwappable.Icon.gameObject, otherSlotIndex);

                // swap which slot handler they will reference
                SlotsHandler temp_slots = attachedSlotHandler;
                attachedSwappable.SlotsHandler = other.SlotsHandler;
                other.SlotsHandler             = temp_slots;
            }
            else
            {
                // move attached swappable to the empty slot
                attachedSwappable.SlotIndex = otherSlotIndex;
                slotHandler.MoveImageToSlot(attachedSwappable.Icon.gameObject, otherSlotIndex);


                // assign the slot handler of the empty slot to the attached swappable.
                attachedSwappable.SlotsHandler = slotHandler;
            }

            ResetAttachedSwappable();
        }
Ejemplo n.º 12
0
 public void SetSwappable(ISwappable swappable) => Swappable = swappable;
Ejemplo n.º 13
0
 private void ResetAttachedSwappable()
 {
     // make it clickable again
     attachedSwappable.Icon.raycastTarget = true;
     attachedSwappable = null;
 }