コード例 #1
0
        public override bool Drop(Draggable dragged)
        {
            // Move item to end of inventory
            // TODO when this knows about contents, instead figure out index based on position?
            InventoryManager inventory   = GameController.Instance.inventory;
            DraggableItem    draggedItem = (DraggableItem)dragged;
            int index = IndexAtPosition(Input.mousePosition);

            if (draggedItem != null && draggedItem.itemBox != this)
            {
                Item item = draggedItem.itemBox.ContainedItem;
                if (draggedItem.itemBox is InventorySlot)
                {
                    return(inventory.MoveItem(item, index));
                }
                else if (draggedItem.itemBox is EquipmentSlotUI)
                {
                    EquipmentSlotUI slot = (EquipmentSlotUI)draggedItem.itemBox;
                    item = slot.equipmentSlot.Unequip();
                    if (item != null)
                    {
                        inventory.Add(item, index);
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #2
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);
                        }
                    }
                    GetComponentInParent <CharacterScreen>().DisplayCharacter(statChangeData);
                }
                else
                {
                    // TODO show it's not usable
                }
            }
        }
コード例 #3
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);
            }
        }
コード例 #4
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);
         }
     }
 }
コード例 #5
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
                }
            }
        }
コード例 #6
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);
            }
        }
コード例 #7
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);
                    }
                }
            }
        }
コード例 #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
             }
         }
     }
 }
コード例 #9
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);
            }
        }