v2.0.0: impled better functionality for variable item default actions

This commit is contained in:
Evan Debenham
2022-11-08 15:03:22 -05:00
parent a63206a98a
commit f548aebcd8
15 changed files with 49 additions and 57 deletions

View File

@@ -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 ) {

View File

@@ -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();
}

View File

@@ -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;
}

View File

@@ -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()) {

View File

@@ -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);

View File

@@ -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();
}
}

View File

@@ -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);

View File

@@ -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 );

View File

@@ -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;

View File

@@ -247,7 +247,7 @@ public class QuickSlotButton extends Button {
@Override
public boolean itemSelectable(Item item) {
return item.defaultAction != null;
return item.defaultAction() != null;
}
@Override

View File

@@ -52,8 +52,8 @@ public class RightClickMenu extends Component {
public RightClickMenu(Item item){
ArrayList<String> 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));

View File

@@ -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));

View File

@@ -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;

View File

@@ -73,7 +73,7 @@ public class WndQuickBag extends Window {
ArrayList<Item> 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) {

View File

@@ -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 );
}