v2.0.0: impled better functionality for variable item default actions
This commit is contained in:
@@ -66,7 +66,7 @@ public class Item implements Bundlable {
|
|||||||
public static final String AC_DROP = "DROP";
|
public static final String AC_DROP = "DROP";
|
||||||
public static final String AC_THROW = "THROW";
|
public static final String AC_THROW = "THROW";
|
||||||
|
|
||||||
public String defaultAction;
|
protected String defaultAction;
|
||||||
public boolean usesTargeting;
|
public boolean usesTargeting;
|
||||||
|
|
||||||
//TODO should these be private and accessed through methods?
|
//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 ) {
|
public void execute( Hero hero ) {
|
||||||
execute( hero, defaultAction );
|
execute( hero, defaultAction() );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onThrow( int cell ) {
|
protected void onThrow( int cell ) {
|
||||||
|
|||||||
+9
-6
@@ -129,6 +129,15 @@ public class DriedRose extends Artifact {
|
|||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String defaultAction() {
|
||||||
|
if (ghost != null){
|
||||||
|
return AC_DIRECT;
|
||||||
|
} else {
|
||||||
|
return AC_SUMMON;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute( Hero hero, String action ) {
|
public void execute( Hero hero, String action ) {
|
||||||
|
|
||||||
@@ -357,8 +366,6 @@ public class DriedRose extends Artifact {
|
|||||||
ghostID = bundle.getInt( GHOSTID );
|
ghostID = bundle.getInt( GHOSTID );
|
||||||
droppedPetals = bundle.getInt( PETALS );
|
droppedPetals = bundle.getInt( PETALS );
|
||||||
|
|
||||||
if (ghostID != 0) defaultAction = AC_DIRECT;
|
|
||||||
|
|
||||||
if (bundle.contains(WEAPON)) weapon = (MeleeWeapon)bundle.get( WEAPON );
|
if (bundle.contains(WEAPON)) weapon = (MeleeWeapon)bundle.get( WEAPON );
|
||||||
if (bundle.contains(ARMOR)) armor = (Armor)bundle.get( ARMOR );
|
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
|
//rose does not charge while ghost hero is alive
|
||||||
if (ghost != null && !cursed && target.buff(MagicImmune.class) == null){
|
if (ghost != null && !cursed && target.buff(MagicImmune.class) == null){
|
||||||
defaultAction = AC_DIRECT;
|
|
||||||
|
|
||||||
//heals to full over 500 turns
|
//heals to full over 500 turns
|
||||||
LockedFloor lock = target.buff(LockedFloor.class);
|
LockedFloor lock = target.buff(LockedFloor.class);
|
||||||
@@ -402,8 +408,6 @@ public class DriedRose extends Artifact {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
defaultAction = AC_SUMMON;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LockedFloor lock = target.buff(LockedFloor.class);
|
LockedFloor lock = target.buff(LockedFloor.class);
|
||||||
@@ -757,7 +761,6 @@ public class DriedRose extends Artifact {
|
|||||||
rose.charge = 0;
|
rose.charge = 0;
|
||||||
rose.partialCharge = 0;
|
rose.partialCharge = 0;
|
||||||
rose.ghostID = -1;
|
rose.ghostID = -1;
|
||||||
rose.defaultAction = AC_SUMMON;
|
|
||||||
}
|
}
|
||||||
super.destroy();
|
super.destroy();
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-6
@@ -83,6 +83,17 @@ public class Blandfruit extends Food {
|
|||||||
return false;
|
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
|
@Override
|
||||||
public void execute( Hero hero, String action ) {
|
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 PotionOfExperience) potionGlow = new ItemSprite.Glowing( 0x404040 );
|
||||||
if (potionAttrib instanceof PotionOfHaste) potionGlow = new ItemSprite.Glowing( 0xCCBB00 );
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-21
@@ -192,26 +192,16 @@ public class Potion extends Item {
|
|||||||
image = handler.image(this);
|
image = handler.image(this);
|
||||||
color = handler.label(this);
|
color = handler.label(this);
|
||||||
}
|
}
|
||||||
setAction();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean collect( Bag container ) {
|
public String defaultAction() {
|
||||||
if (super.collect( container )){
|
|
||||||
setAction();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAction(){
|
|
||||||
if (isKnown() && mustThrowPots.contains(this.getClass())) {
|
if (isKnown() && mustThrowPots.contains(this.getClass())) {
|
||||||
defaultAction = AC_THROW;
|
return AC_THROW;
|
||||||
} else if (isKnown() &&canThrowPots.contains(this.getClass())){
|
} else if (isKnown() &&canThrowPots.contains(this.getClass())){
|
||||||
defaultAction = AC_CHOOSE;
|
return AC_CHOOSE;
|
||||||
} else {
|
} else {
|
||||||
defaultAction = AC_DRINK;
|
return AC_DRINK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,12 +325,6 @@ public class Potion extends Item {
|
|||||||
if (!isKnown()) {
|
if (!isKnown()) {
|
||||||
handler.know(this);
|
handler.know(this);
|
||||||
updateQuickslot();
|
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()) {
|
if (Dungeon.hero.isAlive()) {
|
||||||
|
|||||||
+3
-4
@@ -35,13 +35,12 @@ public abstract class Brew extends Potion {
|
|||||||
actions.remove( AC_DRINK );
|
actions.remove( AC_DRINK );
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAction() {
|
public String defaultAction() {
|
||||||
defaultAction = AC_THROW;
|
return AC_THROW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doThrow(Hero hero) {
|
public void doThrow(Hero hero) {
|
||||||
GameScene.selectCell(thrower);
|
GameScene.selectCell(thrower);
|
||||||
|
|||||||
-4
@@ -98,10 +98,6 @@ public class ExoticPotion extends Potion {
|
|||||||
if (!isKnown()) {
|
if (!isKnown()) {
|
||||||
handler.know(exoToReg.get(this.getClass()));
|
handler.know(exoToReg.get(this.getClass()));
|
||||||
updateQuickslot();
|
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -100,7 +100,7 @@ public class ScrollOfTransmutation extends InventoryScroll {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (slot != -1
|
if (slot != -1
|
||||||
&& result.defaultAction != null
|
&& result.defaultAction() != null
|
||||||
&& !Dungeon.quickslot.isNonePlaceholder(slot)
|
&& !Dungeon.quickslot.isNonePlaceholder(slot)
|
||||||
&& Dungeon.hero.belongings.contains(result)){
|
&& Dungeon.hero.belongings.contains(result)){
|
||||||
Dungeon.quickslot.setSlot(slot, result);
|
Dungeon.quickslot.setSlot(slot, result);
|
||||||
|
|||||||
+1
-1
@@ -38,7 +38,7 @@ public abstract class Runestone extends Item {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onThrow(int cell) {
|
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 );
|
super.onThrow( cell );
|
||||||
} else {
|
} else {
|
||||||
if (pressesCell) Dungeon.level.pressCell( cell );
|
if (pressesCell) Dungeon.level.pressCell( cell );
|
||||||
|
|||||||
@@ -539,7 +539,7 @@ public class InventoryPane extends Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selector == null && item.defaultAction != null){
|
if (selector == null && item.defaultAction() != null){
|
||||||
item.execute(Dungeon.hero);
|
item.execute(Dungeon.hero);
|
||||||
if (item.usesTargeting) {
|
if (item.usesTargeting) {
|
||||||
targetingSlot = this;
|
targetingSlot = this;
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ public class QuickSlotButton extends Button {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean itemSelectable(Item item) {
|
public boolean itemSelectable(Item item) {
|
||||||
return item.defaultAction != null;
|
return item.defaultAction() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ public class RightClickMenu extends Component {
|
|||||||
|
|
||||||
public RightClickMenu(Item item){
|
public RightClickMenu(Item item){
|
||||||
ArrayList<String> actions = item.actions(Dungeon.hero);
|
ArrayList<String> actions = item.actions(Dungeon.hero);
|
||||||
if (actions.remove(item.defaultAction)) {
|
if (actions.remove(item.defaultAction())) {
|
||||||
actions.add(0, item.defaultAction);
|
actions.add(0, item.defaultAction());
|
||||||
}
|
}
|
||||||
String[] options = actions.toArray(new String[0]);
|
String[] options = actions.toArray(new String[0]);
|
||||||
this.item = item;
|
this.item = item;
|
||||||
@@ -105,7 +105,7 @@ public class RightClickMenu extends Component {
|
|||||||
if (item != null){
|
if (item != null){
|
||||||
item.execute(Dungeon.hero, options[finalI]);
|
item.execute(Dungeon.hero, options[finalI]);
|
||||||
|
|
||||||
if (options[finalI].equals(item.defaultAction) && item.usesTargeting){
|
if (options[finalI].equals(item.defaultAction()) && item.usesTargeting){
|
||||||
InventoryPane.useTargeting();
|
InventoryPane.useTargeting();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,7 @@ public class RightClickMenu extends Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (item != null){
|
if (item != null){
|
||||||
if (options[i].equals(item.defaultAction)) {
|
if (options[i].equals(item.defaultAction())) {
|
||||||
buttons[i].textColor(Window.TITLE_COLOR);
|
buttons[i].textColor(Window.TITLE_COLOR);
|
||||||
}
|
}
|
||||||
buttons[i].text(item.actionName(options[i], Dungeon.hero));
|
buttons[i].text(item.actionName(options[i], Dungeon.hero));
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ public class Toolbar extends Component {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean itemSelectable(Item item) {
|
public boolean itemSelectable(Item item) {
|
||||||
return item.defaultAction != null;
|
return item.defaultAction() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -445,7 +445,7 @@ public class Toolbar extends Component {
|
|||||||
public void onSelect(int idx, boolean alt) {
|
public void onSelect(int idx, boolean alt) {
|
||||||
super.onSelect(idx, alt);
|
super.onSelect(idx, alt);
|
||||||
Item item = items.get(idx);
|
Item item = items.get(idx);
|
||||||
if (alt && item.defaultAction != null) {
|
if (alt && item.defaultAction() != null) {
|
||||||
item.execute(Dungeon.hero);
|
item.execute(Dungeon.hero);
|
||||||
} else {
|
} else {
|
||||||
Game.scene().addToFront(new WndUseItem(null, item));
|
Game.scene().addToFront(new WndUseItem(null, item));
|
||||||
|
|||||||
@@ -327,7 +327,7 @@ public class WndBag extends WndTabbed {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onLongClick() {
|
protected boolean onLongClick() {
|
||||||
if (selector == null && item.defaultAction != null) {
|
if (selector == null && item.defaultAction() != null) {
|
||||||
hide();
|
hide();
|
||||||
QuickSlotButton.set( item );
|
QuickSlotButton.set( item );
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+1
-1
@@ -73,7 +73,7 @@ public class WndQuickBag extends Window {
|
|||||||
ArrayList<Item> items = new ArrayList<>();
|
ArrayList<Item> items = new ArrayList<>();
|
||||||
|
|
||||||
for (Item i : bag == null ? Dungeon.hero.belongings : bag){
|
for (Item i : bag == null ? Dungeon.hero.belongings : bag){
|
||||||
if (i.defaultAction == null){
|
if (i.defaultAction() == null){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (i instanceof Bag) {
|
if (i instanceof Bag) {
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public class WndUseItem extends WndInfoItem {
|
|||||||
item.execute( Dungeon.hero, action );
|
item.execute( Dungeon.hero, action );
|
||||||
}
|
}
|
||||||
Item.updateQuickslot();
|
Item.updateQuickslot();
|
||||||
if (action == item.defaultAction && item.usesTargeting && owner == null){
|
if (action == item.defaultAction() && item.usesTargeting && owner == null){
|
||||||
InventoryPane.useTargeting();
|
InventoryPane.useTargeting();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,7 @@ public class WndUseItem extends WndInfoItem {
|
|||||||
buttons.add(btn);
|
buttons.add(btn);
|
||||||
add( btn );
|
add( btn );
|
||||||
|
|
||||||
if (action.equals(item.defaultAction)) {
|
if (action.equals(item.defaultAction())) {
|
||||||
btn.textColor( TITLE_COLOR );
|
btn.textColor( TITLE_COLOR );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user