//context: item was dropped on this slot. Ite might be equipment or another item slot public NoDropReason DropRestrictReasonItemSlot(InventoryItem item, ItemSlot other) { if (other is EquipmentUISlot) { if (InventoryView.instance.IsBattleMode && InventoryView.instance.CurrentActor.UsedAction() && InventoryView.instance.CurrentActor.UsedInteraction()) { return(NoDropReason.NO_ACTION_LEFT_FOR_UNEQUIP); } if (CurrentItem == null) { return(NoDropReason.NONE__CAN_ACTUALLY_DROP); } EquipmentUISlot otherSlot = other as EquipmentUISlot; //check if my item is compatible with the slot. if ((CurrentItem as Equipment).FittingSlotTypes.Contains(otherSlot.slotType)) { return(NoDropReason.NONE__CAN_ACTUALLY_DROP); } else { return(NoDropReason.CANT_UNEQUIP_TO_HERE); } } else { return(NoDropReason.NONE__CAN_ACTUALLY_DROP); } }
public NoDropReason DropRestrictReasonEquipSlot(InventoryItem i, ItemSlot dragging = null) { if (dragging == null) { dragging = currentlyDraggingSlot; } if (i is Equipment) { Equipment e = i as Equipment; if (EquipmentFits(e)) { if (InventoryView.instance.IsBattleMode) { if (InventoryView.instance.currentCharacter != BattleManager.instance.CurrentlyTakingTurn.CharSheet) { return(NoDropReason.NOT_YOUR_TURN); } else if (BattleManager.instance.CurrentlyTakingTurn.UsedInteraction() && BattleManager.instance.CurrentlyTakingTurn.UsedAction()) { return(NoDropReason.NO_ACTION_LEFT); } } if (dragging is EquipmentUISlot) { //check if currently dragging is EquipmentUISlot sl = dragging as EquipmentUISlot; if ((CurrentItem == null) || !sl.EquipmentFits(CurrentItem as Equipment)) { if (InventoryView.instance.currentCharacter.inventory.NoRoomLeft) { return(NoDropReason.NO_INVENTORY_SPACE); } } // EquipmentUISlot.NoDropReason reasonCantSwap = sl.DropRestrictReasonEquipSlot(CurrentItem, this); // if (reasonCantSwap != EquipmentUISlot.NoDropReason.NONE__CAN_ACTUALLY_DROP) { // if (InventoryView.instance.currentCharacter.inventory.NoRoomLeft) { // return NoDropReason.NO_INVENTORY_SPACE; // } // } } return(NoDropReason.NONE__CAN_ACTUALLY_DROP); } else { return(NoDropReason.NO_FIT); } } else { return(NoDropReason.NOT_EQUIPMENT); } }
/// <summary> /// Checks if the item slot dropped can be droppped, and acts accordingly. /// Look at ItemSlot subclass to find see what functionality this overrides, /// and if you are curious how the cursor is unset by the item dragged. /// </summary> /// <param name="self">Self.</param> public override void DroppedItem(OptButton self) { if (currentlyDraggingSlot != null) { bool updated = false; NoDropReason reason = DropRestrictReasonEquipSlot(currentlyDraggingSlot.CurrentItem, currentlyDraggingSlot); switch (reason) { case NoDropReason.NONE__CAN_ACTUALLY_DROP: //if battle mode... if (InventoryView.instance.IsBattleMode) { AT.Battle.Equip action = new AT.Battle.Equip(InventoryView.instance.CurrentActor); (action.ActionOptions [0] as ItemsOnPersonOption).chosenChoice = new InventoryItemChoice(currentlyDraggingSlot.CurrentItem); (action.ActionOptions [1] as EquipmentSlotTypeOption).chosenChoice = new EquipmentSlotTypeChoice(slotType); action.Perform(); if (CurrentItem != null) { InventoryItem swap = CurrentItem; SetInventoryItem(currentlyDraggingSlot.CurrentItem); currentlyDraggingSlot.SetInventoryItem(swap); } else { SetInventoryItem(currentlyDraggingSlot.CurrentItem); currentlyDraggingSlot.ClearItem(); } } else { if (CurrentItem != null) { if (currentlyDraggingSlot is EquipmentUISlot) { EquipmentUISlot sl = currentlyDraggingSlot as EquipmentUISlot; if (sl.EquipmentFits(CurrentItem as Equipment)) { InventoryItem swap = currentlyDraggingSlot.CurrentItem; currentlyDraggingSlot.SetInventoryItem(CurrentItem); SetInventoryItem(swap); } else { InventoryView.instance.inventoryDisplay.AddToInventory(CurrentItem); SetInventoryItem(currentlyDraggingSlot.CurrentItem); currentlyDraggingSlot.ClearItem(); } // //// // // SetInventoryItem (swap); } else { // InventoryItem swap = currentlyDraggingSlot.CurrentItem; // currentlyDraggingSlot.SetInventoryItem (CurrentItem); // InventoryView.instance.inventoryDisplay.AddToInventory (CurrentItem); InventoryItem swap = currentlyDraggingSlot.CurrentItem; currentlyDraggingSlot.SetInventoryItem(CurrentItem); SetInventoryItem(swap); } } else { //just set the state as needed directly SetInventoryItem(currentlyDraggingSlot.CurrentItem); currentlyDraggingSlot.ClearItem(); // InventoryView.instance.RefreshUi (); } } updated = true; break; case NoDropReason.NOT_EQUIPMENT: Debug.Log("you can't drop non-equipmnet on a equpment slot"); break; case NoDropReason.NO_FIT: Debug.Log((currentlyDraggingSlot.CurrentItem as Equipment).DefaultFitSlotType + " doesn't match " + slotType); break; case NoDropReason.NOT_YOUR_TURN: Debug.Log("Not your turn, my sone"); break; case NoDropReason.NO_ACTION_LEFT: Debug.Log("You can't act"); break; } if (updated && InventoryView.instance.IsBattleMode) { //in this case, the action takes care of syncing character stuff InventoryView.instance.RefreshUi(); } else { InventoryView.instance.RefreshCharacter(); } UIManager.instance.Tooltip.Hide(); } }
//This happens before the drag end happens. public virtual void DroppedItem(OptButton opt) { if (currentlyDraggingSlot != null) { bool updated = false; NoDropReason reason = DropRestrictReasonItemSlot(currentlyDraggingSlot.CurrentItem, currentlyDraggingSlot); switch (reason) { case NoDropReason.CANT_UNEQUIP_TO_HERE: Debug.Log("shit, can unequip here ni"); break; case NoDropReason.NO_ACTION_LEFT_FOR_UNEQUIP: Debug.Log("No action left my friend."); break; case NoDropReason.NONE__CAN_ACTUALLY_DROP: Debug.Log("You can drop!"); if (currentlyDraggingSlot is EquipmentUISlot) //slot is an equipment slot { EquipmentUISlot sl = currentlyDraggingSlot as EquipmentUISlot; if (InventoryView.instance.IsBattleMode) { //actions need to be performed... if (CurrentItem == null) { AT.Battle.Unequip action = BattleUnequip(sl.slotType); action.Perform(); } else { AT.Battle.Equip action = BattleEquip(CurrentItem, sl.slotType); action.Perform(); } InventoryView.instance.RefreshUi(); } else { //The state can just be set. if (CurrentItem == null) { // AT.Battle.Unequip action = BattleUnequip (sl.slotType); // Debug.Log("here, will unequp"); SetInventoryItem(currentlyDraggingSlot.CurrentItem); currentlyDraggingSlot.SetInventoryItem(null); } else { InventoryItem swap = CurrentItem; InventoryView.instance.currentCharacter.Unequip( (currentlyDraggingSlot as EquipmentUISlot).slotType, currentlyDraggingSlot.CurrentItem as Equipment); SetInventoryItem(currentlyDraggingSlot.CurrentItem); currentlyDraggingSlot.SetInventoryItem(swap); } InventoryView.instance.RefreshCharacter(); } } else ///TODO: add case for if the slot is a ground slot (only valid in battle) { InventoryItem swap = CurrentItem; SetInventoryItem(currentlyDraggingSlot.CurrentItem); currentlyDraggingSlot.SetInventoryItem(swap); InventoryView.instance.RefreshCharacter(); } break; } } }