/** * If an item is dropped on this slot, check if it is an EquipmentItem * AND it is the proper EquipmentType * if so, equip it and return the previously equipped item (to be dragged) * * Otherwise, return null * **/ public override DraggableItem ItemDropped(DraggableItem item) { EquipmentItem equipmentItem = item.GetComponent <EquipmentItem>(); if (equipmentItem != null && equipmentItem.equipmentType == equipmentType) { EquipmentItem tmpEquipmentItem = equipment.Unequip(equipmentType); equipment.Equip(equipmentType, item.GetComponent <EquipmentItem>()); return(tmpEquipmentItem); } return(item); }
/** * On MouseUp, we check to see if there's currently an item * being dragged. If there is, we drop it into this slot. * **/ public override bool ItemDropped(DraggableItem item) { if (item.GetComponent <InventoryItem>() != null) { inventory[inventoryPosition.x, inventoryPosition.y] = item.gameObject; return(true); } return(false); }
/** * When an item is dropped on the slot, verify that it's * an ActionItem and place it in items[] **/ public override bool ItemDropped(DraggableItem item) { ActionItem actionItem = item.GetComponent <ActionItem>(); if (actionItem != null) { items[position] = actionItem; return(true); } return(false); }
/** * When an item is dropped on this slot, swap * it with the one currently in this place * **/ public override DraggableItem ItemDropped(DraggableItem item) { if (item.GetComponent <ActionItem>() != null) { // if this is a stackable item, try and stack it // this works but it's _really_ ugly // TODO: maybe there should be a helper that will attempt // this as opposed to implementing it on anything that // requires stackable items. StackableInventoryItem stackableSelf = this.item.GetComponent <StackableInventoryItem>(); StackableInventoryItem stackableItem = item.GetComponent <StackableInventoryItem>(); if (stackableSelf != null && stackableItem != null) { // if we're dragging a single item and dropping it on a max stack // that means we should swap these // TODO: check stack types? if (stackableItem.GetCount() == 1 && stackableSelf.GetCount() == stackableSelf.maxCount) { items[position] = item.GetComponent <ActionItem>(); return(this.item.GetComponent <DraggableItem>()); } else { StackableInventoryItem remainder = stackableSelf.AddStackableInventoryItems(stackableItem); if (remainder != null) { return(remainder); } } } else { items[position] = item.GetComponent <ActionItem>(); return(this.item.GetComponent <DraggableItem>()); } } return(null); }
/** * When an item is dropped on this slot, we'll check to * see if that item is an EquipmentItem and if it matches * this slot's type. * * Currently does not swap out equipment of different types. * **/ public override bool ItemDropped(DraggableItem item) { EquipmentItem equipmentItem = item.GetComponent <EquipmentItem>(); if (equipmentItem != null && equipmentItem.equipmentType == equipmentType) { if (equipment.IsSlotFree(equipmentType)) { equipment.Equip(equipmentType, equipmentItem); return(true); } } return(false); }
/** * An item was dropped on this slot. Swap it with the * item currently in that position and return it or * stack it if it's a stackable item * **/ public override DraggableItem ItemDropped(DraggableItem item) { if (item.GetComponent <InventoryItem>() != null) { StackableInventoryItem stackableItem = item.GetComponent <StackableInventoryItem>(); StackableInventoryItem stackableSelf = this.item.GetComponent <StackableInventoryItem>(); // if this is a stackable item, stack it if (stackableItem != null && stackableSelf != null) { if (!stackableSelf.IsMaxed()) { return(stackableSelf.AddStackableInventoryItems(stackableItem)); } } // otherwise, swap it GameObject tmpInventoryItem = inventory[inventoryPosition.x, inventoryPosition.y]; inventory[inventoryPosition.x, inventoryPosition.y] = item.gameObject; return(tmpInventoryItem.GetComponent <InventoryItem>()); } return(null); }