Ejemplo n.º 1
0
        // If item dropped, uses it on character
        public override bool Drop(Draggable dragged)
        {
            DraggableItem item = (DraggableItem)dragged;

            if (item != null)
            {
                // TODO check item is usable?
                return(GameController.Instance.inventory.Use(item.itemBox.ContainedItem, ContainedCharacter));
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
 protected override void OnHoverEnter(Draggable dragged)
 {
     // Shows changes from equipping item
     if (dragged is DraggableItem)
     {
         DraggableItem di = (DraggableItem)dragged;
         if (di.itemBox is InventorySlot)
         {
             StatDisplay.StatChangeData statChangeData = new StatDisplay.StatChangeData();
             statChangeData.ItemToUse = di.itemBox.ContainedItem;
             statChangeData.ApplyItemEffects(di.itemBox.ContainedItem);
             //HACK
             GetComponentInParent <CharacterScreen>().DisplayCharacter(statChangeData);
         }
     }
 }
Ejemplo n.º 3
0
        public void OnPointerEnter(PointerEventData eventData)
        {
            Draggable dragged = Draggable.CurrentDragged;

            if (dragged != null && dragged.gameObject != this.gameObject)
            {
                // maybe should also remember dragged object? Not sure how that case would happen though
                hovering = true;
                OnHoverEnter(dragged);
                if (ConsumeHover(dragged))
                {
                    eventData.Use();
                    // TODO figure out if this works or is needed
                }
            }
        }
Ejemplo n.º 4
0
        protected override void OnHoverEnter(Draggable dragged)
        {
            //TODO popup showing effect?
            DraggableItem item = (DraggableItem)dragged;

            if (item != null)
            {
                Item containedItem = item.itemBox.ContainedItem;
                if (containedItem.IsUsable(character))
                {
                    StatDisplay.StatChangeData statChangeData = new StatDisplay.StatChangeData();
                    statChangeData.ItemToUse = containedItem;
                    statChangeData.ApplyItemEffects(containedItem);
                    if (containedItem is Equipment)
                    {
                        if (((Equipment)containedItem).equipmentType == Equipment.EquipmentType.Weapon)
                        {
                            statChangeData.ApplyItemEffects(character.weapon.equippedItem, true);
                        }
                    }

                    ResetHealBars();

                    if (statChangeData != null)
                    {
                        float hpChange;
                        float mpChange;
                        if (statChangeData.changes.TryGetValue(RPGStats.Stats.Hp, out hpChange))
                        {
                            characterPortrait.HPRegenBar.Init(hpChange + character.Hp, character.hpStat);
                        }
                        if (statChangeData.changes.TryGetValue(RPGStats.Stats.Mp, out mpChange))
                        {
                            characterPortrait.MPRegenBar.Init(mpChange + character.Mp, character.mpStat);
                        }
                    }
                }
                else
                {
                    // TODO show it's not usable
                }
            }
        }
Ejemplo n.º 5
0
        public override bool Drop(Draggable dragged)
        {
            // If item from another itembox, swap items
            DraggableItem draggedItem = (DraggableItem)dragged;

            if (draggedItem != null && draggedItem.itemBox != this)
            {
                List <Item> inventory = GameController.Instance.inventory.playerInventory;
                int         myIndex   = inventory.IndexOf(ContainedItem);
                Item        theirItem = draggedItem.itemBox.ContainedItem;

                if (draggedItem.itemBox is InventorySlot)
                {
                    // If from inventory, swap positions
                    InventorySlot theirSlot = (InventorySlot)draggedItem.itemBox;
                    return(GameController.Instance.inventory.SwapItems(ContainedItem, theirItem));
                }
                else if (draggedItem.itemBox is EquipmentSlotUI)
                {
                    // If from equipment, unequip item and insert before this
                    EquipmentSlotUI theirSlot = (EquipmentSlotUI)draggedItem.itemBox;
                    theirItem = theirSlot.equipmentSlot.Unequip();
                    if (theirItem != null)
                    {
                        GameController.Instance.inventory.Add(theirItem, myIndex);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 6
0
        protected override void OnHoverEnter(Draggable dragged)
        {
            //HACK checking if in character screen
            CharacterScreen screen = GetComponentInParent <CharacterScreen>();

            if (screen != null)
            {
                if (dragged is DraggableItem)
                {
                    DraggableItem di = (DraggableItem)dragged;
                    if (di.itemBox is EquipmentSlotUI)
                    {
                        StatDisplay.StatChangeData statChangeData = new StatDisplay.StatChangeData();
                        statChangeData.ItemToUse = di.itemBox.ContainedItem;
                        statChangeData.ApplyItemEffects(di.itemBox.ContainedItem, true);
                        screen.DisplayCharacter(statChangeData);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public virtual void OnEndDrag(PointerEventData eventData)
        {
            if (dragging)
            {
                dragging       = false;
                CurrentDragged = null;
                bool dropped = false;
                foreach (DragTarget target in GetDragTargetsUnderMouse())
                {
                    if (!dropped)
                    {
                        dropped = target.Drop(this);
                    }
                    target.DragReleased();
                }

                transform.position = originalPos;
                cg.blocksRaycasts  = true;
                transform.SetParent(container.transform);
            }
        }
Ejemplo n.º 8
0
 protected override void OnHoverEnter(Draggable dragged)
 {
     // Shows stat changes from removing this item and adding another
     if (dragged is DraggableItem)
     {
         DraggableItem di = (DraggableItem)dragged;
         if (di.itemBox is InventorySlot)
         {
             if (equipmentSlot.CanEquip(di.itemBox.ContainedItem as Equipment))
             {
                 StatDisplay.StatChangeData statChangeData = new StatDisplay.StatChangeData();
                 statChangeData.ItemToUse = di.itemBox.ContainedItem;
                 statChangeData.ApplyItemEffects(di.itemBox.ContainedItem);
                 // remove this item
                 statChangeData.ApplyItemEffects(ContainedItem, true);
                 GetComponentInParent <CharacterScreen>().DisplayCharacter(statChangeData);
             }
             else
             {
                 // TODO show item can't be equipped in this slot
             }
         }
     }
 }
Ejemplo n.º 9
0
 protected override void OnHoverEnter(Draggable dragged)
 {
 }
Ejemplo n.º 10
0
 public abstract bool Drop(Draggable dragged);
Ejemplo n.º 11
0
 protected abstract void OnHoverEnter(Draggable dragged);
Ejemplo n.º 12
0
        //TODO add arguments

        // maybe doesn't work now pointer enter used?
        public virtual bool ConsumeHover(Draggable dragged)
        {
            return(true);
        }
Ejemplo n.º 13
0
        public override bool Drop(Draggable dragged)
        {
            // If item from another itembox, swap items

            DraggableItem draggedItem = (DraggableItem)dragged;

            if (draggedItem != null && draggedItem.itemBox != this)
            {
                // Check type of dragged item
                Equipment theirItem = draggedItem.itemBox.ContainedItem as Equipment;
                if (theirItem == null)
                {
                    return(false);
                }

                if (draggedItem.itemBox is InventorySlot)
                {
                    // If from inventory unequip this and equip theirs
                    // Note: both will end up at end, not bothering with that since
                    // equipment slots will be changed later
                    if (equipmentSlot.CanEquip(theirItem))
                    {
                        Equipment myItem = equipmentSlot.Unequip();
                        equipmentSlot.Equip(theirItem);
                        if (myItem != null)
                        {
                            GameController.Instance.inventory.Replace(theirItem, myItem);
                        }
                        else
                        {
                            GameController.Instance.inventory.Discard(theirItem);
                        }
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (draggedItem.itemBox is EquipmentSlotUI)
                {
                    //  if both rings, swap rings
                    EquipmentSlotUI otherUI   = (EquipmentSlotUI)draggedItem.itemBox;
                    EquipmentSlot   theirSlot = otherUI.equipmentSlot;
                    if (theirSlot.character == equipmentSlot.character)
                    {
                        if (equipmentSlot.SwapItem(theirSlot))
                        {
                            ContainedItem         = equipmentSlot.equippedItem;
                            otherUI.ContainedItem = theirSlot.equippedItem;
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }