v2.2.0: fixed various cases where the pickaxe could be lost, softlocking

This commit is contained in:
Evan Debenham
2023-09-29 12:54:48 -04:00
parent 736bd37c8d
commit 385ab558fd
12 changed files with 43 additions and 27 deletions
@@ -103,7 +103,7 @@ public class Belongings implements Iterable<Item> {
public KindOfWeapon weapon(){ public KindOfWeapon weapon(){
boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null;
if (!lostInvent || (weapon != null && weapon.keptThoughLostInvent)){ if (!lostInvent || (weapon != null && weapon.keptThroughLostInventory())){
return weapon; return weapon;
} else { } else {
return null; return null;
@@ -112,7 +112,7 @@ public class Belongings implements Iterable<Item> {
public Armor armor(){ public Armor armor(){
boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null;
if (!lostInvent || (armor != null && armor.keptThoughLostInvent)){ if (!lostInvent || (armor != null && armor.keptThroughLostInventory())){
return armor; return armor;
} else { } else {
return null; return null;
@@ -121,7 +121,7 @@ public class Belongings implements Iterable<Item> {
public Artifact artifact(){ public Artifact artifact(){
boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null;
if (!lostInvent || (artifact != null && artifact.keptThoughLostInvent)){ if (!lostInvent || (artifact != null && artifact.keptThroughLostInventory())){
return artifact; return artifact;
} else { } else {
return null; return null;
@@ -130,7 +130,7 @@ public class Belongings implements Iterable<Item> {
public KindofMisc misc(){ public KindofMisc misc(){
boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null;
if (!lostInvent || (misc != null && misc.keptThoughLostInvent)){ if (!lostInvent || (misc != null && misc.keptThroughLostInventory())){
return misc; return misc;
} else { } else {
return null; return null;
@@ -139,7 +139,7 @@ public class Belongings implements Iterable<Item> {
public Ring ring(){ public Ring ring(){
boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null;
if (!lostInvent || (ring != null && ring.keptThoughLostInvent)){ if (!lostInvent || (ring != null && ring.keptThroughLostInventory())){
return ring; return ring;
} else { } else {
return null; return null;
@@ -148,7 +148,7 @@ public class Belongings implements Iterable<Item> {
public KindOfWeapon secondWep(){ public KindOfWeapon secondWep(){
boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null;
if (!lostInvent || (secondWep != null && secondWep.keptThoughLostInvent)){ if (!lostInvent || (secondWep != null && secondWep.keptThroughLostInventory())){
return secondWep; return secondWep;
} else { } else {
return null; return null;
@@ -236,7 +236,7 @@ public class Belongings implements Iterable<Item> {
for (Item item : this) { for (Item item : this) {
if (itemClass.isInstance( item )) { if (itemClass.isInstance( item )) {
if (!lostInvent || item.keptThoughLostInvent) { if (!lostInvent || item.keptThroughLostInventory()) {
return (T) item; return (T) item;
} }
} }
@@ -252,7 +252,7 @@ public class Belongings implements Iterable<Item> {
for (Item item : this) { for (Item item : this) {
if (itemClass.isInstance( item )) { if (itemClass.isInstance( item )) {
if (!lostInvent || item.keptThoughLostInvent) { if (!lostInvent || item.keptThroughLostInventory()) {
result.add((T) item); result.add((T) item);
} }
} }
@@ -267,7 +267,7 @@ public class Belongings implements Iterable<Item> {
for (Item item : this) { for (Item item : this) {
if (contains == item) { if (contains == item) {
if (!lostInvent || item.keptThoughLostInvent) { if (!lostInvent || item.keptThroughLostInventory()) {
return true; return true;
} }
} }
@@ -282,7 +282,7 @@ public class Belongings implements Iterable<Item> {
for (Item item : this) { for (Item item : this) {
if (similar != item && similar.isSimilar(item)) { if (similar != item && similar.isSimilar(item)) {
if (!lostInvent || item.keptThoughLostInvent) { if (!lostInvent || item.keptThroughLostInventory()) {
return item; return item;
} }
} }
@@ -298,7 +298,7 @@ public class Belongings implements Iterable<Item> {
for (Item item : this) { for (Item item : this) {
if (item != similar && similar.isSimilar(item)) { if (item != similar && similar.isSimilar(item)) {
if (!lostInvent || item.keptThoughLostInvent) { if (!lostInvent || item.keptThroughLostInventory()) {
result.add(item); result.add(item);
} }
} }
@@ -2351,15 +2351,15 @@ public class Hero extends Char {
for (Item i : belongings){ for (Item i : belongings){
if (i instanceof EquipableItem && i.isEquipped(this)){ if (i instanceof EquipableItem && i.isEquipped(this)){
((EquipableItem) i).activate(this); ((EquipableItem) i).activate(this);
} else if (i instanceof CloakOfShadows && i.keptThoughLostInvent && hasTalent(Talent.LIGHT_CLOAK)){ } else if (i instanceof CloakOfShadows && i.keptThroughLostInventory() && hasTalent(Talent.LIGHT_CLOAK)){
((CloakOfShadows) i).activate(this); ((CloakOfShadows) i).activate(this);
} else if (i instanceof Wand && i.keptThoughLostInvent){ } else if (i instanceof Wand && i.keptThroughLostInventory()){
if (holster != null && holster.contains(i)){ if (holster != null && holster.contains(i)){
((Wand) i).charge(this, MagicalHolster.HOLSTER_SCALE_FACTOR); ((Wand) i).charge(this, MagicalHolster.HOLSTER_SCALE_FACTOR);
} else { } else {
((Wand) i).charge(this); ((Wand) i).charge(this);
} }
} else if (i instanceof MagesStaff && i.keptThoughLostInvent){ } else if (i instanceof MagesStaff && i.keptThroughLostInventory()){
((MagesStaff) i).applyWandChargeBuff(this); ((MagesStaff) i).applyWandChargeBuff(this);
} }
} }
@@ -431,7 +431,7 @@ public enum Talent {
if (talent == LIGHT_CLOAK && hero.heroClass == HeroClass.ROGUE){ if (talent == LIGHT_CLOAK && hero.heroClass == HeroClass.ROGUE){
for (Item item : Dungeon.hero.belongings.backpack){ for (Item item : Dungeon.hero.belongings.backpack){
if (item instanceof CloakOfShadows){ if (item instanceof CloakOfShadows){
if (hero.buff(LostInventory.class) == null || item.keptThoughLostInvent) { if (hero.buff(LostInventory.class) == null || item.keptThroughLostInventory()) {
((CloakOfShadows) item).activate(Dungeon.hero); ((CloakOfShadows) item).activate(Dungeon.hero);
} }
} }
@@ -127,7 +127,7 @@ public abstract class EquipableItem extends Item {
if (cursed if (cursed
&& hero.buff(MagicImmune.class) == null && hero.buff(MagicImmune.class) == null
&& (hero.buff(LostInventory.class) == null || keptThoughLostInvent)) { && (hero.buff(LostInventory.class) == null || keptThroughLostInventory())) {
GLog.w(Messages.get(EquipableItem.class, "unequip_cursed")); GLog.w(Messages.get(EquipableItem.class, "unequip_cursed"));
return false; return false;
} }
@@ -89,6 +89,7 @@ public class Item implements Bundlable {
public boolean unique = false; public boolean unique = false;
// These items are preserved even if the hero's inventory is lost via unblessed ankh // These items are preserved even if the hero's inventory is lost via unblessed ankh
// this is largely set by the resurrection window, items can override this to always be kept
public boolean keptThoughLostInvent = false; public boolean keptThoughLostInvent = false;
// whether an item can be included in heroes remains // whether an item can be included in heroes remains
@@ -140,6 +141,10 @@ public class Item implements Bundlable {
keptThoughLostInvent = false; keptThoughLostInvent = false;
} }
public boolean keptThroughLostInventory(){
return keptThoughLostInvent;
}
public void doThrow( Hero hero ) { public void doThrow( Hero hero ) {
GameScene.selectCell(thrower); GameScene.selectCell(thrower);
} }
@@ -50,7 +50,7 @@ public class LostBackpack extends Item {
MagicalHolster holster = hero.belongings.getItem(MagicalHolster.class); MagicalHolster holster = hero.belongings.getItem(MagicalHolster.class);
for (Item i : hero.belongings){ for (Item i : hero.belongings){
if (i.keptThoughLostInvent){ if (i.keptThroughLostInventory()){
i.keptThoughLostInvent = false; //don't reactivate, was previously activated i.keptThoughLostInvent = false; //don't reactivate, was previously activated
} else { } else {
if (i instanceof EquipableItem && i.isEquipped(hero)){ if (i instanceof EquipableItem && i.isEquipped(hero)){
@@ -168,7 +168,7 @@ public class Bag extends Item implements Iterable<Item> {
public boolean canHold( Item item ){ public boolean canHold( Item item ){
if (!loading && owner != null && owner.buff(LostInventory.class) != null if (!loading && owner != null && owner.buff(LostInventory.class) != null
&& !item.keptThoughLostInvent){ && !item.keptThroughLostInventory()){
return false; return false;
} }
@@ -41,6 +41,7 @@ import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MeleeWeapon; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MeleeWeapon;
import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
import com.shatteredpixel.shatteredpixeldungeon.levels.MiningLevel;
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain; import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
@@ -88,6 +89,10 @@ public class Pickaxe extends MeleeWeapon {
if (Blacksmith.Quest.oldMiningQuest()) { if (Blacksmith.Quest.oldMiningQuest()) {
actions.add(AC_MINE); actions.add(AC_MINE);
} }
if (Dungeon.level instanceof MiningLevel){
actions.remove(AC_DROP);
actions.remove(AC_THROW);
}
return actions; return actions;
} }
@@ -166,6 +171,12 @@ public class Pickaxe extends MeleeWeapon {
return super.proc( attacker, defender, damage ); return super.proc( attacker, defender, damage );
} }
@Override
public boolean keptThroughLostInventory() {
//pickaxe is always kept when it's needed for the mining level
return super.keptThroughLostInventory() || Dungeon.level instanceof MiningLevel;
}
@Override @Override
public String defaultAction() { public String defaultAction() {
if (Dungeon.hero.heroClass == HeroClass.DUELIST && isEquipped(Dungeon.hero)){ if (Dungeon.hero.heroClass == HeroClass.DUELIST && isEquipped(Dungeon.hero)){
@@ -365,13 +365,13 @@ public class InventoryPane extends Component {
b.enable(lastEnabled b.enable(lastEnabled
&& !(b.item() instanceof WndBag.Placeholder) && !(b.item() instanceof WndBag.Placeholder)
&& (selector == null || selector.itemSelectable(b.item())) && (selector == null || selector.itemSelectable(b.item()))
&& (!lostInvent || b.item().keptThoughLostInvent)); && (!lostInvent || b.item().keptThroughLostInventory()));
} }
for (InventorySlot b : bagItems){ for (InventorySlot b : bagItems){
b.enable(lastEnabled b.enable(lastEnabled
&& b.item() != null && b.item() != null
&& (selector == null || selector.itemSelectable(b.item())) && (selector == null || selector.itemSelectable(b.item()))
&& (!lostInvent || b.item().keptThoughLostInvent)); && (!lostInvent || b.item().keptThroughLostInventory()));
} }
for (BagButton b : bags){ for (BagButton b : bags){
b.enable(lastEnabled); b.enable(lastEnabled);
@@ -455,13 +455,13 @@ public class InventoryPane extends Component {
b.enable(lastEnabled b.enable(lastEnabled
&& !(b.item() instanceof WndBag.Placeholder) && !(b.item() instanceof WndBag.Placeholder)
&& (selector == null || selector.itemSelectable(b.item())) && (selector == null || selector.itemSelectable(b.item()))
&& (!lostInvent || b.item().keptThoughLostInvent)); && (!lostInvent || b.item().keptThroughLostInventory()));
} }
for (InventorySlot b : bagItems){ for (InventorySlot b : bagItems){
b.enable(lastEnabled b.enable(lastEnabled
&& b.item() != null && b.item() != null
&& (selector == null || selector.itemSelectable(b.item())) && (selector == null || selector.itemSelectable(b.item()))
&& (!lostInvent || b.item().keptThoughLostInvent)); && (!lostInvent || b.item().keptThroughLostInventory()));
} }
for (BagButton b : bags){ for (BagButton b : bags){
b.enable(lastEnabled); b.enable(lastEnabled);
@@ -102,7 +102,7 @@ public class InventorySlot extends ItemSlot {
if (item.name() == null) { if (item.name() == null) {
enable( false ); enable( false );
} else if (Dungeon.hero.buff(LostInventory.class) != null } else if (Dungeon.hero.buff(LostInventory.class) != null
&& !item.keptThoughLostInvent){ && !item.keptThroughLostInventory()){
enable(false); enable(false);
} }
} else { } else {
@@ -302,7 +302,7 @@ public class QuickSlotButton extends Button {
private void enableSlot() { private void enableSlot() {
slot.enable(Dungeon.quickslot.isNonePlaceholder( slotNum ) slot.enable(Dungeon.quickslot.isNonePlaceholder( slotNum )
&& (Dungeon.hero.buff(LostInventory.class) == null || Dungeon.quickslot.getItem(slotNum).keptThoughLostInvent)); && (Dungeon.hero.buff(LostInventory.class) == null || Dungeon.quickslot.getItem(slotNum).keptThroughLostInventory()));
} }
public void slotMargins( int left, int top, int right, int bottom){ public void slotMargins( int left, int top, int right, int bottom){
@@ -128,7 +128,7 @@ public class Toolbar extends Component {
Item item = Dungeon.quickslot.getItem(i); Item item = Dungeon.quickslot.getItem(i);
if (item != null && !Dungeon.quickslot.isPlaceholder(i) && if (item != null && !Dungeon.quickslot.isPlaceholder(i) &&
(Dungeon.hero.buff(LostInventory.class) == null || item.keptThoughLostInvent)){ (Dungeon.hero.buff(LostInventory.class) == null || item.keptThroughLostInventory())){
slotNames[i] = Messages.titleCase(item.name()); slotNames[i] = Messages.titleCase(item.name());
slotIcons[i] = new ItemSprite(item); slotIcons[i] = new ItemSprite(item);
} else { } else {
@@ -154,7 +154,7 @@ public class Toolbar extends Component {
Item item = Dungeon.quickslot.getItem(idx); Item item = Dungeon.quickslot.getItem(idx);
if (item == null || Dungeon.quickslot.isPlaceholder(idx) if (item == null || Dungeon.quickslot.isPlaceholder(idx)
|| (Dungeon.hero.buff(LostInventory.class) != null && !item.keptThoughLostInvent) || (Dungeon.hero.buff(LostInventory.class) != null && !item.keptThroughLostInventory())
|| alt){ || alt){
//TODO would be nice to use a radial menu for this too //TODO would be nice to use a radial menu for this too
// Also a bunch of code could be moved out of here into subclasses of RadialMenu // Also a bunch of code could be moved out of here into subclasses of RadialMenu
@@ -420,7 +420,7 @@ public class Toolbar extends Component {
for(Item i : bag.items){ for(Item i : bag.items){
if (i instanceof Bag) items.remove(i); if (i instanceof Bag) items.remove(i);
if (Dungeon.hero.buff(LostInventory.class) != null && !i.keptThoughLostInvent) items.remove(i); if (Dungeon.hero.buff(LostInventory.class) != null && !i.keptThroughLostInventory()) items.remove(i);
} }
if (idx == 0){ if (idx == 0){