diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Item.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Item.java index 1911ee6a2..40c74e7c2 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Item.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Item.java @@ -66,7 +66,7 @@ public class Item implements Bundlable { public static final String AC_DROP = "DROP"; public static final String AC_THROW = "THROW"; - public String defaultAction; + protected String defaultAction; public boolean usesTargeting; //TODO should these be private and accessed through methods? @@ -163,9 +163,14 @@ public class Item implements Bundlable { } } + + //can be overridden if default action is variable + public String defaultAction(){ + return defaultAction; + } public void execute( Hero hero ) { - execute( hero, defaultAction ); + execute( hero, defaultAction() ); } protected void onThrow( int cell ) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/DriedRose.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/DriedRose.java index a21837c48..92c82f6f3 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/DriedRose.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/DriedRose.java @@ -129,6 +129,15 @@ public class DriedRose extends Artifact { return actions; } + @Override + public String defaultAction() { + if (ghost != null){ + return AC_DIRECT; + } else { + return AC_SUMMON; + } + } + @Override public void execute( Hero hero, String action ) { @@ -357,8 +366,6 @@ public class DriedRose extends Artifact { ghostID = bundle.getInt( GHOSTID ); droppedPetals = bundle.getInt( PETALS ); - if (ghostID != 0) defaultAction = AC_DIRECT; - if (bundle.contains(WEAPON)) weapon = (MeleeWeapon)bundle.get( WEAPON ); if (bundle.contains(ARMOR)) armor = (Armor)bundle.get( ARMOR ); } @@ -385,7 +392,6 @@ public class DriedRose extends Artifact { //rose does not charge while ghost hero is alive if (ghost != null && !cursed && target.buff(MagicImmune.class) == null){ - defaultAction = AC_DIRECT; //heals to full over 500 turns LockedFloor lock = target.buff(LockedFloor.class); @@ -402,8 +408,6 @@ public class DriedRose extends Artifact { } return true; - } else { - defaultAction = AC_SUMMON; } LockedFloor lock = target.buff(LockedFloor.class); @@ -757,7 +761,6 @@ public class DriedRose extends Artifact { rose.charge = 0; rose.partialCharge = 0; rose.ghostID = -1; - rose.defaultAction = AC_SUMMON; } super.destroy(); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/food/Blandfruit.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/food/Blandfruit.java index 9bdee99ee..9b06c9000 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/food/Blandfruit.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/food/Blandfruit.java @@ -83,6 +83,17 @@ public class Blandfruit extends Food { return false; } + @Override + public String defaultAction() { + if (potionAttrib == null){ + return null; + } else if (potionAttrib.defaultAction().equals(Potion.AC_DRINK)) { + return AC_EAT; + } else { + return potionAttrib.defaultAction(); + } + } + @Override public void execute( Hero hero, String action ) { @@ -173,12 +184,6 @@ public class Blandfruit extends Food { if (potionAttrib instanceof PotionOfExperience) potionGlow = new ItemSprite.Glowing( 0x404040 ); if (potionAttrib instanceof PotionOfHaste) potionGlow = new ItemSprite.Glowing( 0xCCBB00 ); - potionAttrib.setAction(); - defaultAction = potionAttrib.defaultAction; - if (defaultAction.equals(Potion.AC_DRINK)){ - defaultAction = AC_EAT; - } - return this; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/Potion.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/Potion.java index b11754c5e..45822c93d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/Potion.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/Potion.java @@ -192,26 +192,16 @@ public class Potion extends Item { image = handler.image(this); color = handler.label(this); } - setAction(); } - + @Override - public boolean collect( Bag container ) { - if (super.collect( container )){ - setAction(); - return true; - } else { - return false; - } - } - - public void setAction(){ + public String defaultAction() { if (isKnown() && mustThrowPots.contains(this.getClass())) { - defaultAction = AC_THROW; + return AC_THROW; } else if (isKnown() &&canThrowPots.contains(this.getClass())){ - defaultAction = AC_CHOOSE; + return AC_CHOOSE; } else { - defaultAction = AC_DRINK; + return AC_DRINK; } } @@ -335,12 +325,6 @@ public class Potion extends Item { if (!isKnown()) { handler.know(this); updateQuickslot(); - Potion p = Dungeon.hero.belongings.getItem(getClass()); - if (p != null) p.setAction(); - if (ExoticPotion.regToExo.get(getClass()) != null) { - p = Dungeon.hero.belongings.getItem(ExoticPotion.regToExo.get(getClass())); - if (p != null) p.setAction(); - } } if (Dungeon.hero.isAlive()) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/brews/Brew.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/brews/Brew.java index 3a58103dc..03ab82803 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/brews/Brew.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/brews/Brew.java @@ -35,13 +35,12 @@ public abstract class Brew extends Potion { actions.remove( AC_DRINK ); return actions; } - + @Override - public void setAction() { - defaultAction = AC_THROW; + public String defaultAction() { + return AC_THROW; } - @Override public void doThrow(Hero hero) { GameScene.selectCell(thrower); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/exotic/ExoticPotion.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/exotic/ExoticPotion.java index 0fb1e7ebc..5fea3287f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/exotic/ExoticPotion.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/exotic/ExoticPotion.java @@ -98,10 +98,6 @@ public class ExoticPotion extends Potion { if (!isKnown()) { handler.know(exoToReg.get(this.getClass())); updateQuickslot(); - Potion p = Dungeon.hero.belongings.getItem(getClass()); - if (p != null) p.setAction(); - p = Dungeon.hero.belongings.getItem(exoToReg.get(this.getClass())); - if (p != null) p.setAction(); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfTransmutation.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfTransmutation.java index 70b27b76c..51025d607 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfTransmutation.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfTransmutation.java @@ -100,7 +100,7 @@ public class ScrollOfTransmutation extends InventoryScroll { } } if (slot != -1 - && result.defaultAction != null + && result.defaultAction() != null && !Dungeon.quickslot.isNonePlaceholder(slot) && Dungeon.hero.belongings.contains(result)){ Dungeon.quickslot.setSlot(slot, result); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/stones/Runestone.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/stones/Runestone.java index f2f861a1b..eaba7845e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/stones/Runestone.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/stones/Runestone.java @@ -38,7 +38,7 @@ public abstract class Runestone extends Item { @Override protected void onThrow(int cell) { - if (Dungeon.level.pit[cell] || !defaultAction.equals(AC_THROW)){ + if (Dungeon.level.pit[cell] || !defaultAction().equals(AC_THROW)){ super.onThrow( cell ); } else { if (pressesCell) Dungeon.level.pressCell( cell ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/InventoryPane.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/InventoryPane.java index 4fdc479c1..6b8ab6e19 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/InventoryPane.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/InventoryPane.java @@ -539,7 +539,7 @@ public class InventoryPane extends Component { return; } - if (selector == null && item.defaultAction != null){ + if (selector == null && item.defaultAction() != null){ item.execute(Dungeon.hero); if (item.usesTargeting) { targetingSlot = this; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java index e4cc6b887..0bde74cc8 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java @@ -247,7 +247,7 @@ public class QuickSlotButton extends Button { @Override public boolean itemSelectable(Item item) { - return item.defaultAction != null; + return item.defaultAction() != null; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/RightClickMenu.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/RightClickMenu.java index 8398ac0ba..e25572a2a 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/RightClickMenu.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/RightClickMenu.java @@ -52,8 +52,8 @@ public class RightClickMenu extends Component { public RightClickMenu(Item item){ ArrayList actions = item.actions(Dungeon.hero); - if (actions.remove(item.defaultAction)) { - actions.add(0, item.defaultAction); + if (actions.remove(item.defaultAction())) { + actions.add(0, item.defaultAction()); } String[] options = actions.toArray(new String[0]); this.item = item; @@ -105,7 +105,7 @@ public class RightClickMenu extends Component { if (item != null){ item.execute(Dungeon.hero, options[finalI]); - if (options[finalI].equals(item.defaultAction) && item.usesTargeting){ + if (options[finalI].equals(item.defaultAction()) && item.usesTargeting){ InventoryPane.useTargeting(); } } @@ -115,7 +115,7 @@ public class RightClickMenu extends Component { } }; if (item != null){ - if (options[i].equals(item.defaultAction)) { + if (options[i].equals(item.defaultAction())) { buttons[i].textColor(Window.TITLE_COLOR); } buttons[i].text(item.actionName(options[i], Dungeon.hero)); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java index 65bb125ec..dfdf4279d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java @@ -166,7 +166,7 @@ public class Toolbar extends Component { @Override public boolean itemSelectable(Item item) { - return item.defaultAction != null; + return item.defaultAction() != null; } @Override @@ -445,7 +445,7 @@ public class Toolbar extends Component { public void onSelect(int idx, boolean alt) { super.onSelect(idx, alt); Item item = items.get(idx); - if (alt && item.defaultAction != null) { + if (alt && item.defaultAction() != null) { item.execute(Dungeon.hero); } else { Game.scene().addToFront(new WndUseItem(null, item)); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java index 0a6b20c00..9d513ae7d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java @@ -327,7 +327,7 @@ public class WndBag extends WndTabbed { @Override protected boolean onLongClick() { - if (selector == null && item.defaultAction != null) { + if (selector == null && item.defaultAction() != null) { hide(); QuickSlotButton.set( item ); return true; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndQuickBag.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndQuickBag.java index d01828862..9734f517d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndQuickBag.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndQuickBag.java @@ -73,7 +73,7 @@ public class WndQuickBag extends Window { ArrayList items = new ArrayList<>(); for (Item i : bag == null ? Dungeon.hero.belongings : bag){ - if (i.defaultAction == null){ + if (i.defaultAction() == null){ continue; } if (i instanceof Bag) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndUseItem.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndUseItem.java index 15abe18dd..0369d7b42 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndUseItem.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndUseItem.java @@ -55,7 +55,7 @@ public class WndUseItem extends WndInfoItem { item.execute( Dungeon.hero, action ); } Item.updateQuickslot(); - if (action == item.defaultAction && item.usesTargeting && owner == null){ + if (action == item.defaultAction() && item.usesTargeting && owner == null){ InventoryPane.useTargeting(); } } @@ -64,7 +64,7 @@ public class WndUseItem extends WndInfoItem { buttons.add(btn); add( btn ); - if (action.equals(item.defaultAction)) { + if (action.equals(item.defaultAction())) { btn.textColor( TITLE_COLOR ); }