Beispiel #1
0
        /// <summary>
        /// Initializes the itemSlot with an item, creating an itemDisplay
        /// Only used for item creation on eventDisplays, hence the itemSlot type can be defaulted to "any",
        /// reverting "shop" type itemSlots
        /// </summary>
        /// <param name="newItem"> Item object </param>
        public void PlaceItem(Item newItem)
        {
            itemSlotType = ItemConstants.ANY;

            if (newItem != null)
            {
                SetVisible(true);

                GameObject newItemDisplay = Instantiate(itemDisplayPrefab);
                currentItemDisplay = newItemDisplay.GetComponent <ItemDisplay>();
                currentItemDisplay.Init(newItem);
                currentItemDisplay.parentSlot = this;

                newItemDisplay.transform.SetParent(this.transform, false);
                // hide the defaultSprite if it shows
                defaultSpriteRenderer.color = new Color(defaultSpriteRenderer.color.r, defaultSpriteRenderer.color.g, defaultSpriteRenderer.color.b, 0);


                t.SetImageDisplayBackgroundWidth(imgBackground.rectTransform.sizeDelta.x);
                SetTooltipText();
            }
            else
            {
                // show the default sprite if nothing is in the slot (assuming there is a default sprite)
                defaultSpriteRenderer.color = new Color(defaultSpriteRenderer.color.r, defaultSpriteRenderer.color.g, defaultSpriteRenderer.color.b, 255);
                SetVisible(true);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Shows the item being displayed, so that if partyMembers switch,
        /// instead of itemDisplays needing to be re-instantiated, the itemDisplayed can be hidden and displayed
        /// </summary>
        /// <remark>
        /// Assumes that there is already an item in the slot
        /// </remark>
        /// <param name="id"> ItemDisplay to show </param>
        public void ShowItem(ItemDisplay id)
        {
            currentItemDisplay = id;
            currentItemDisplay.gameObject.SetActive(true);
            SetTooltipText();

            defaultSpriteRenderer.color = new Color(defaultSpriteRenderer.color.r, defaultSpriteRenderer.color.g, defaultSpriteRenderer.color.b, 0);
        }
Beispiel #3
0
 /// <summary>
 /// Destroys the currently displayed item
 /// </summary>
 public void ClearItem()
 {
     if (currentItemDisplay != null)
     {
         Destroy(currentItemDisplay.gameObject);
         currentItemDisplay = null;
     }
 }
Beispiel #4
0
        /// <summary>
        /// Hides the item being displayed, so that if partyMembers switch,
        /// instead of itemDisplays needing to be re-instantiated, the itemDisplayed can be hidden and displayed
        /// </summary>
        public void HideItem()
        {
            currentItemDisplay.gameObject.SetActive(false);
            currentItemDisplay = null;
            SetTooltipText();

            defaultSpriteRenderer.color = new Color(defaultSpriteRenderer.color.r, defaultSpriteRenderer.color.g, defaultSpriteRenderer.color.b, 255);
        }
Beispiel #5
0
 /// <summary>
 /// Called when player tries to sell an item via shift click
 /// </summary>
 /// <param name="id"></param>
 public void SellItem(ItemDisplay id)
 {
     for (int i = 0; i < itemSlots.Length; i++)
     {
         if (itemSlots[i].currentItemDisplay == null)
         {
             if (itemSlots[i].TryShopTransaction(id) == true)
             {
                 itemSlots[i].PlaceItem(id, true);
                 break;
             }
         }
     }
 }
Beispiel #6
0
        /// <summary>
        /// Places an item in a spare itemSlot
        /// </summary>
        /// <param name="id"> ItemDisplay </param>
        /// <returns> True if possible, false otherwise </returns>
        public bool PlaceItem(ItemDisplay id, bool direct = false)
        {
            if (maxSpare > numSpareFull)
            {
                for (int i = 0; i < spare.Length; i++)
                {
                    if (spare[i].currentItemDisplay == null)
                    {
                        spare[i].PlaceItem(id, direct);
                        break;
                    }
                }

                return(true);
            }

            return(false);
        }
Beispiel #7
0
        /// <summary>
        /// Initializes the itemSlot with an itemDisplay
        /// </summary>
        /// <param name="newItemDisplay"></param>
        public void PlaceItem(ItemDisplay newItemDisplay, bool direct = false)
        {
            currentItemDisplay            = newItemDisplay;
            currentItemDisplay.parentSlot = this;
            currentItemDisplay.transform.SetParent(this.transform, false);          // position item placed in the middle of the slot
            currentItemDisplay.transform.localPosition = new Vector3(0f, 0f, 0f);

            t.SetImageDisplayBackgroundWidth(imgBackground.rectTransform.sizeDelta.x);
            SetTooltipText();

            if (itemSlotSubType != ItemConstants.ANY)      // bad way to determine if its a partyMember's equippable slot
            {
                defaultSpriteRenderer.color = new Color(defaultSpriteRenderer.color.r, defaultSpriteRenderer.color.g, defaultSpriteRenderer.color.b, 0);
                if (itemSlotType == ItemConstants.GEAR)
                {
                    PartyManager.instance.EquipGear(newItemDisplay, itemSlotSubType);
                }
                if (itemSlotType == ItemConstants.CANDLE)
                {
                    PartyManager.instance.EquipCandle(newItemDisplay, itemSlotSubType);
                    CandlesPanel candlesPanel = (CandlesPanel)parentPanel;
                    candlesPanel.SetUsable(itemSlotSubType[0] - '0');
                }
            }
            else
            {
                if (newItemDisplay.type == ItemConstants.CANDLE)
                {
                    newItemDisplay.displayedCandle.SetActive(false);    // for candles, if placed in a non-active slot, update the sprite
                }
                parentPanel.PlaceItem();
            }

            if (parentPanel.GetPanelName() == PanelConstants.EVENTDISPLAY || parentPanel.GetPanelName() == PanelConstants.REWARDSPANEL)    // item is being placed in an eventDisplay or rewardsPanel
            {
                EventManager.instance.UpdateTakeAll();
            }


            if (direct == false && UIManager.instance.hoveredItemSlot == this)
            {
                t.SetVisible(true);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Initializes the item slot with a new item, creating an item display
        /// Used for the gearPanel to instantly show partyMember's equipped items when switching between partyMembers
        /// TODO: When loading is enabled, placeItemInstant will have to update numSparefull, or there must be a method that does so
        /// </summary>
        /// <param name="newItem"> Item data </param>
        public void PlaceItemInstant(Item newItem)
        {
            if (newItem != null)
            {
                GameObject newItemDisplay = Instantiate(itemDisplayPrefab);
                currentItemDisplay = newItemDisplay.GetComponent <ItemDisplay>();
                currentItemDisplay.InitInstant(newItem);
                currentItemDisplay.parentSlot = this;

                newItemDisplay.transform.SetParent(this.transform, false);
                // hide the defaultSprite if it shows
                defaultSpriteRenderer.color = new Color(defaultSpriteRenderer.color.r, defaultSpriteRenderer.color.g, defaultSpriteRenderer.color.b, 0);

                newItem.CalculateWAXValue();
                t.SetImageDisplayBackgroundWidth(imgBackground.rectTransform.sizeDelta.x);
                SetTooltipText();

                if (itemSlotSubType != ItemConstants.ANY)      // bad way to determine if its a partyMember's equippable slot
                {
                    defaultSpriteRenderer.color = new Color(defaultSpriteRenderer.color.r, defaultSpriteRenderer.color.g, defaultSpriteRenderer.color.b, 0);
                    if (itemSlotType == ItemConstants.GEAR)
                    {
                        PartyManager.instance.EquipGear(newItemDisplay.GetComponent <ItemDisplay>(), itemSlotSubType);
                    }
                    if (itemSlotType == ItemConstants.CANDLE)
                    {
                        PartyManager.instance.EquipCandle(newItemDisplay.GetComponent <ItemDisplay>(), itemSlotSubType);
                        CandlesPanel candlesPanel = (CandlesPanel)parentPanel;
                        candlesPanel.SetUsable(itemSlotSubType[0] - '0');
                    }
                }
            }
            else
            {
                defaultSpriteRenderer.color = new Color(defaultSpriteRenderer.color.r, defaultSpriteRenderer.color.g, defaultSpriteRenderer.color.b, 255);
                t.SetImageDisplayBackgroundWidth(imgBackground.rectTransform.sizeDelta.x);
                SetTooltipText();
            }
        }
Beispiel #9
0
        /// <summary>
        /// Attempts a shop transaction, completing the transaction if the player can afford it
        /// </summary>
        /// <param name="newItemDisplay"> Item being placed into the slot (i.e. selling or trading), can be null if only buying</param>
        /// <returns> true if transaction is succesful, false otherwise</returns>
        public bool TryShopTransaction(ItemDisplay newItemDisplay = null)
        {
            if (currentItemDisplay == null)
            {
                if (newItemDisplay == null)     // clicking on an empty slot with nothing in hand
                {
                    return(false);
                }

                // selling
                PartyManager.instance.AddWAX(newItemDisplay.GetWAXValueNoMultiplier());

                return(true);
            }
            else
            {
                if (newItemDisplay == null)     // buying
                {
                    if (PartyManager.instance.WAX - currentItemDisplay.GetWAXValueShop() >= 0)
                    {
                        PartyManager.instance.LoseWAX(currentItemDisplay.GetWAXValueShop());
                        return(true);
                    }

                    return(false);
                }
                else    // trading
                {
                    if ((PartyManager.instance.WAX + newItemDisplay.GetWAXValue()) - currentItemDisplay.GetWAXValueShop() >= 0)
                    {
                        PartyManager.instance.AddWAX(newItemDisplay.GetWAXValueNoMultiplier());
                        PartyManager.instance.LoseWAX(currentItemDisplay.GetWAXValueShop());
                        return(true);
                    }

                    return(false);
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Checks if an itemDisplay of a type can be placed inside this slot
        /// </summary>
        /// <param name="i"> ItemDisplay to check </param>
        /// <returns> True if accepted, false otherwise </returns>
        public bool CheckCorrectItemType(ItemDisplay id)
        {
            if (itemSlotType == ItemConstants.ANY)
            {
                return(true);
            }
            else if (id.type == itemSlotType && (id.subType == itemSlotSubType || itemSlotSubType == "0" || itemSlotSubType == "1" || itemSlotSubType == "2" || itemSlotSubType == ItemConstants.ANY))
            {
                if (id.className != ClassConstants.ANY && itemSlotSubType != ItemConstants.ANY)
                {
                    if (id.className == PartyManager.instance.GetActivePartyMember().className)
                    {
                        return(true);
                    }
                }
                else
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #11
0
        /// <summary>
        /// Returns a random item currently displayed by the eventDisplay
        /// </summary>
        /// <returns> An item if possible, null otherwise </returns>
        public Item GetRandomItem()
        {
            List <ItemDisplay> ids = new List <ItemDisplay>();

            foreach (ItemSlot i in itemSlots)
            {
                if (i.currentItemDisplay != null)
                {
                    ids.Add(i.currentItemDisplay);
                }
            }

            if (ids.Count != 0)
            {
                ItemDisplay id = ids[Random.Range(0, ids.Count)];
                if (id.type == ItemConstants.CONSUMABLE)
                {
                    return(id.displayedConsumable);
                }
                if (id.type == ItemConstants.GEAR)
                {
                    return(id.displayedGear);
                }
                else if (id.type == ItemConstants.CANDLE)
                {
                    return(id.displayedCandle);
                }
                else    // Special
                {
                    return(id.displayedSpecial);
                }
            }
            else
            {
                return(null);
            }
        }
Beispiel #12
0
        /// <summary>
        /// Takes the item from the item slot
        /// </summary>
        /// <param name="direct"> Flag for if the item will be taken directly from the itemslot with no dragging </param>
        public void TakeItem(bool direct = false)
        {
            if (currentItemDisplay != null && isTakeable == true)
            {
                bool itemTaken = false;

                if (currentItemDisplay.type == ItemConstants.CONSUMABLE)    // consumable items are used on click
                {
                    string[] effects = currentItemDisplay.GetEffects();
                    int[]    amounts = currentItemDisplay.GetValues();
                    for (int i = 0; i < effects.Length; i++)
                    {
                        if (effects[i] == "EXP")
                        {
                            PartyManager.instance.AddEXP(amounts[i]);
                        }
                        else if (effects[i] == "HP")
                        {
                            StartCoroutine(PartyManager.instance.ChangeHPAll(amounts[i]));
                        }
                        else if (effects[i] == "MP")
                        {
                            PartyManager.instance.ChangeMPAll(amounts[i]);
                        }
                        else if (effects[i] == "WAX")
                        {
                            PartyManager.instance.AddWAX(amounts[i]);
                        }
                        else if (effects[i] != "none")   // status effects
                        {
                            PartyManager.instance.AddStatusEffect((StatusEffectConstant)Enum.Parse(typeof(StatusEffectConstant), effects[i]), amounts[i]);
                        }
                    }
                    itemTaken = true;
                    Destroy(currentItemDisplay.gameObject);
                }
                else    // non-consumable items must be dragged into the user's inventory, or placed directly via button

                /*
                 *  Item taken directly from an eventsDisplay/rewardsPanel via the "take all" button
                 *  resulting in the item being placed in the corresponding panel if there's room
                 */
                {
                    if (direct == true)
                    {
                        Panel targetPanel = EventManager.instance.GetTargetPanel(currentItemDisplay.type);

                        if (targetPanel == parentPanel)     // selling from a panel via shift click
                        {
                            EventDisplay ed = EventManager.instance.TryPlaceItem();
                            if (ed != null)
                            {
                                ed.SellItem(currentItemDisplay);
                                itemTaken = true;
                            }
                        }
                        else if (currentItemDisplay.type == ItemConstants.GEAR)
                        {
                            GearPanel gearPanel = (GearPanel)targetPanel;
                            if (gearPanel.PlaceItem(currentItemDisplay, direct))
                            {
                                itemTaken = true;
                            }
                        }
                        else if (currentItemDisplay.type == ItemConstants.CANDLE)
                        {
                            CandlesPanel candlesPanel = (CandlesPanel)targetPanel;
                            if (candlesPanel.PlaceItem(currentItemDisplay, direct))
                            {
                                itemTaken = true;
                            }
                        }
                        else if (currentItemDisplay.type == ItemConstants.SPECIAL)
                        {
                            SpecialPanel specialPanel = (SpecialPanel)targetPanel;
                            if (specialPanel.PlaceItem(currentItemDisplay, direct))
                            {
                                itemTaken = true;
                            }
                        }
                    }
                    else
                    {
                        UIManager.instance.heldItemDisplay = currentItemDisplay;
                        UIManager.instance.StartDragItem();
                        UIManager.instance.panelButtonsEnabled = false;
                        itemTaken = true;
                    }
                }

                if (itemTaken)      // if item is taken, update the itemSlot
                {
                    currentItemDisplay          = null;
                    defaultSpriteRenderer.color = new Color(defaultSpriteRenderer.color.r, defaultSpriteRenderer.color.g, defaultSpriteRenderer.color.b, 255);
                    t.SetVisible(false);
                    SetTooltipText();

                    if (parentPanel.GetPanelName() == PanelConstants.GEARPANEL)
                    {
                        if (itemSlotSubType == ItemConstants.ANY)       // gearPanel updates to have more free spare itemSlots
                        {
                            GearPanel gearPanel = (GearPanel)parentPanel;
                            gearPanel.TakeItem();
                        }
                        else    // item was unequipped from partyMember
                        {
                            PartyManager.instance.UnequipGear(itemSlotSubType);
                        }
                    }
                    else if (parentPanel.GetPanelName() == PanelConstants.CANDLESPANEL)
                    {
                        CandlesPanel candlesPanel = (CandlesPanel)parentPanel;

                        if (itemSlotSubType == ItemConstants.ANY)       // candlesPanel updates to have more free spare itemSlots
                        {
                            candlesPanel.TakeItem();
                        }
                        else    // item was unequipped from partyMember
                        {
                            PartyManager.instance.UnequipCandle(itemSlotSubType);
                            candlesPanel.SetUsable(itemSlotSubType[0] - '0');
                        }
                    }
                    else if (parentPanel.GetPanelName() == PanelConstants.SPECIALPANEL)
                    {
                        SpecialPanel specialPanel = (SpecialPanel)parentPanel;
                        if (itemSlotSubType == ItemConstants.ANY)       // specialPanel updates to have more free spare itemSlots
                        {
                            specialPanel.TakeItem();
                        }
                    }
                    else if (UIManager.instance.heldItemDisplay != null)
                    {
                        EventManager.instance.OpenItemPanel(UIManager.instance.heldItemDisplay);
                        parentPanel.TakeItem();
                        EventManager.instance.UpdateTakeAll();
                    }
                    else
                    {
                        parentPanel.TakeItem();
                        EventManager.instance.UpdateTakeAll();
                    }
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// On click function
        /// </summary>
        public void OnClick()
        {
            if (itemSlotType == "shop")
            {
                if (UIManager.instance.heldItemDisplay != null)
                {
                    if (TryShopTransaction(UIManager.instance.heldItemDisplay) == true)
                    {
                        if (currentItemDisplay != null)
                        {
                            ItemDisplay temp = UIManager.instance.heldItemDisplay;
                            UIManager.instance.heldItemDisplay = null;

                            TakeItem();

                            temp.EndDragItem();
                            PlaceItem(temp);
                        }
                        else
                        {
                            UIManager.instance.heldItemDisplay.EndDragItem();
                            PlaceItem(UIManager.instance.heldItemDisplay);
                            UIManager.instance.heldItemDisplay     = null;
                            UIManager.instance.panelButtonsEnabled = true;
                        }
                    }
                }
                else
                {
                    if (TryShopTransaction() == true)
                    {
                        TakeItem();
                    }
                }
            }
            else
            {
                if (UIManager.instance.heldItemDisplay != null)
                {
                    if (CheckCorrectItemType(UIManager.instance.heldItemDisplay) == true)
                    {
                        if (currentItemDisplay != null)
                        {
                            ItemDisplay temp = UIManager.instance.heldItemDisplay;
                            UIManager.instance.heldItemDisplay = null;

                            TakeItem();

                            temp.EndDragItem();
                            PlaceItem(temp);
                        }
                        else
                        {
                            UIManager.instance.heldItemDisplay.EndDragItem();
                            PlaceItem(UIManager.instance.heldItemDisplay);
                            UIManager.instance.heldItemDisplay     = null;
                            UIManager.instance.panelButtonsEnabled = true;
                        }
                    }
                }
                else if (currentItemDisplay != null)
                {
                    if (UIManager.instance.inShop == true && Input.GetButton("Shift") == true)      // shift click sell
                    {
                        TakeItem(true);
                    }
                    else
                    {
                        TakeItem();
                    }
                }
            }
        }