|
@@ -7,83 +7,83 @@ import javax.swing.JOptionPane;
|
|
|
import org.leumasjaffe.charsheet.model.inventory.DDInventory;
|
|
import org.leumasjaffe.charsheet.model.inventory.DDInventory;
|
|
|
import org.leumasjaffe.charsheet.model.inventory.DDItem;
|
|
import org.leumasjaffe.charsheet.model.inventory.DDItem;
|
|
|
import org.leumasjaffe.charsheet.model.inventory.EquipmentSlot;
|
|
import org.leumasjaffe.charsheet.model.inventory.EquipmentSlot;
|
|
|
-import org.leumasjaffe.function.VoidVoidFunction;
|
|
|
|
|
import org.leumasjaffe.observer.ObserverDispatch;
|
|
import org.leumasjaffe.observer.ObserverDispatch;
|
|
|
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
|
|
|
-@RequiredArgsConstructor
|
|
|
|
|
-public class EquipItemHelper implements VoidVoidFunction {
|
|
|
|
|
- final InventoryPanel panel;
|
|
|
|
|
- final DDInventory inv;
|
|
|
|
|
- final DDItem item;
|
|
|
|
|
-
|
|
|
|
|
- public void apply() {
|
|
|
|
|
|
|
+public class EquipItemHelper {
|
|
|
|
|
+
|
|
|
|
|
+ public static void accept(final DDInventory inv, final DDItem item) {
|
|
|
if ( item.getUnequippedCount() == 0 ) { return; }
|
|
if ( item.getUnequippedCount() == 0 ) { return; }
|
|
|
- if ( inv.canEquip( item ) || getReplaceItem( item.getSlot() ) ) {
|
|
|
|
|
|
|
+ if ( inv.canEquip(item) || new Helper(inv).getReplaceItem(item.getSlot()) ) {
|
|
|
item.setCountEquipped(item.getCountEquipped() + 1);
|
|
item.setCountEquipped(item.getCountEquipped() + 1);
|
|
|
- inv.equipNext( item );
|
|
|
|
|
- ObserverDispatch.notifySubscribers(inv, panel);
|
|
|
|
|
|
|
+ inv.equipNext(item);
|
|
|
|
|
+ ObserverDispatch.notifySubscribers(inv, null);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private boolean getReplaceItem(final EquipmentSlot slot) {
|
|
|
|
|
- switch ( slot ) {
|
|
|
|
|
- case TWO_HANDS: return selectToReplaceAllOf( TWO_HANDS, MAIN_HAND, OFF_HAND );
|
|
|
|
|
- case ONE_HAND: return selectToReplaceOneOf( MAIN_HAND, OFF_HAND );
|
|
|
|
|
- case RING: return selectToReplaceOneOf( RING1, RING2 );
|
|
|
|
|
- default: return selectToReplace( slot );
|
|
|
|
|
|
|
+ @RequiredArgsConstructor
|
|
|
|
|
+ private static class Helper {
|
|
|
|
|
+ final DDInventory inv;
|
|
|
|
|
+
|
|
|
|
|
+ private boolean getReplaceItem(final EquipmentSlot slot) {
|
|
|
|
|
+ switch ( slot ) {
|
|
|
|
|
+ case TWO_HANDS: return selectToReplaceAllOf( TWO_HANDS, MAIN_HAND, OFF_HAND );
|
|
|
|
|
+ case ONE_HAND: return selectToReplaceOneOf( MAIN_HAND, OFF_HAND );
|
|
|
|
|
+ case RING: return selectToReplaceOneOf( RING1, RING2 );
|
|
|
|
|
+ default: return selectToReplace( slot );
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- private boolean selectToReplaceAllOf(final EquipmentSlot base,
|
|
|
|
|
- final EquipmentSlot slot1, final EquipmentSlot slot2) {
|
|
|
|
|
- final EquipItemPanel panel;
|
|
|
|
|
- if ( inv.getEquipment().get(slot1).getSlot() == base ) {
|
|
|
|
|
- panel = new EquipItemPanel("Do you want to replace the following item?",
|
|
|
|
|
- slot1, inv.getEquipment().get(slot1));
|
|
|
|
|
- } else {
|
|
|
|
|
- panel = new EquipItemPanel("Do you want to replace both of the following items?",
|
|
|
|
|
- new EquipItemPanel.Tuple(slot1, inv.getEquipment().get(slot1)),
|
|
|
|
|
- new EquipItemPanel.Tuple(slot2, inv.getEquipment().get(slot2)));
|
|
|
|
|
- }
|
|
|
|
|
- if ( JOptionPane.showConfirmDialog(null,
|
|
|
|
|
- panel, "Replace Equipped Item", JOptionPane.YES_NO_OPTION)
|
|
|
|
|
- == JOptionPane.YES_OPTION ) {
|
|
|
|
|
- inv.unequip( slot1 );
|
|
|
|
|
- inv.unequip( slot2 );
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+ private boolean selectToReplaceAllOf(final EquipmentSlot base,
|
|
|
|
|
+ final EquipmentSlot slot1, final EquipmentSlot slot2) {
|
|
|
|
|
+ final EquipItemPanel panel;
|
|
|
|
|
+ if ( inv.getEquipment().get(slot1).getSlot() == base ) {
|
|
|
|
|
+ panel = new EquipItemPanel("Do you want to replace the following item?",
|
|
|
|
|
+ slot1, inv.getEquipment().get(slot1));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ panel = new EquipItemPanel("Do you want to replace both of the following items?",
|
|
|
|
|
+ new EquipItemPanel.Tuple(slot1, inv.getEquipment().get(slot1)),
|
|
|
|
|
+ new EquipItemPanel.Tuple(slot2, inv.getEquipment().get(slot2)));
|
|
|
|
|
+ }
|
|
|
|
|
+ if ( JOptionPane.showConfirmDialog(null,
|
|
|
|
|
+ panel, "Replace Equipped Item", JOptionPane.YES_NO_OPTION)
|
|
|
|
|
+ == JOptionPane.YES_OPTION ) {
|
|
|
|
|
+ inv.unequip( slot1 );
|
|
|
|
|
+ inv.unequip( slot2 );
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- private boolean selectToReplaceOneOf(final EquipmentSlot slot1,
|
|
|
|
|
- final EquipmentSlot slot2) {
|
|
|
|
|
- final int choice = JOptionPane.showOptionDialog(null,
|
|
|
|
|
- new EquipItemPanel("Which of the following items would you like to replace?",
|
|
|
|
|
- new EquipItemPanel.Tuple(slot1, inv.getEquipment().get(slot1)),
|
|
|
|
|
- new EquipItemPanel.Tuple(slot2, inv.getEquipment().get(slot2))),
|
|
|
|
|
- "Replace Equipped Item", JOptionPane.YES_NO_CANCEL_OPTION,
|
|
|
|
|
- JOptionPane.QUESTION_MESSAGE, null,
|
|
|
|
|
- new String[] {"Cancel", slot1.toString(), slot2.toString()}, null );
|
|
|
|
|
- if ( choice == JOptionPane.YES_OPTION ) {
|
|
|
|
|
- inv.unequip( slot1 );
|
|
|
|
|
- return true;
|
|
|
|
|
- } else if ( choice == JOptionPane.NO_OPTION ) {
|
|
|
|
|
- inv.unequip( slot2 );
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+ private boolean selectToReplaceOneOf(final EquipmentSlot slot1,
|
|
|
|
|
+ final EquipmentSlot slot2) {
|
|
|
|
|
+ final int choice = JOptionPane.showOptionDialog(null,
|
|
|
|
|
+ new EquipItemPanel("Which of the following items would you like to replace?",
|
|
|
|
|
+ new EquipItemPanel.Tuple(slot1, inv.getEquipment().get(slot1)),
|
|
|
|
|
+ new EquipItemPanel.Tuple(slot2, inv.getEquipment().get(slot2))),
|
|
|
|
|
+ "Replace Equipped Item", JOptionPane.YES_NO_CANCEL_OPTION,
|
|
|
|
|
+ JOptionPane.QUESTION_MESSAGE, null,
|
|
|
|
|
+ new String[] {"Cancel", slot1.toString(), slot2.toString()}, null );
|
|
|
|
|
+ if ( choice == JOptionPane.YES_OPTION ) {
|
|
|
|
|
+ inv.unequip( slot1 );
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } else if ( choice == JOptionPane.NO_OPTION ) {
|
|
|
|
|
+ inv.unequip( slot2 );
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- private boolean selectToReplace(final EquipmentSlot slot) {
|
|
|
|
|
- if ( JOptionPane.showConfirmDialog(null,
|
|
|
|
|
- new EquipItemPanel("Do you want to replace the following item?", slot, inv.getEquipment().get(slot)),
|
|
|
|
|
- "Replace Equipped Item", JOptionPane.YES_NO_OPTION)
|
|
|
|
|
- == JOptionPane.YES_OPTION ) {
|
|
|
|
|
- inv.unequip( slot );
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+ private boolean selectToReplace(final EquipmentSlot slot) {
|
|
|
|
|
+ if ( JOptionPane.showConfirmDialog(null,
|
|
|
|
|
+ new EquipItemPanel("Do you want to replace the following item?", slot, inv.getEquipment().get(slot)),
|
|
|
|
|
+ "Replace Equipped Item", JOptionPane.YES_NO_OPTION)
|
|
|
|
|
+ == JOptionPane.YES_OPTION ) {
|
|
|
|
|
+ inv.unequip( slot );
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
- return false;
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|