v3.2.0: fixed exploits with thrown weapon upgrading and shops

This commit is contained in:
Evan Debenham
2025-07-26 21:42:36 -04:00
parent 60b825a6ef
commit fefb148f63
3 changed files with 26 additions and 4 deletions

View File

@@ -36,6 +36,7 @@ import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ElmoParticle;
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.MissileWeapon;
import com.shatteredpixel.shatteredpixeldungeon.journal.Notes;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
@@ -265,6 +266,9 @@ public class Shopkeeper extends NPC {
Item returned = buybackItems.remove(index-2);
Dungeon.gold -= returned.value();
Statistics.goldCollected -= returned.value();
if (returned instanceof MissileWeapon && returned.isUpgradable()){
Dungeon.hero.buff(MissileWeapon.UpgradedSetTracker.class).levelThresholds.put(((MissileWeapon) returned).setID, returned.level());
}
if (!returned.doPickUp(Dungeon.hero)){
Dungeon.level.drop(returned, Dungeon.hero.pos);
}

View File

@@ -769,7 +769,7 @@ abstract public class MissileWeapon extends Weapon {
return true;
}
public static final String SET_IDD = "set_ids";
public static final String SET_IDS = "set_ids";
public static final String SET_LEVELS = "set_levels";
@Override
@@ -783,14 +783,14 @@ abstract public class MissileWeapon extends Weapon {
levels[i] = levelThresholds.get(ID);
i++;
}
bundle.put(SET_IDD, IDs);
bundle.put(SET_IDS, IDs);
bundle.put(SET_LEVELS, levels);
}
@Override
public void restoreFromBundle(Bundle bundle) {
super.restoreFromBundle(bundle);
long[] IDs = bundle.getLongArray(SET_IDD);
long[] IDs = bundle.getLongArray(SET_IDS);
int[] levels = bundle.getIntArray(SET_LEVELS);
levelThresholds.clear();
for (int i = 0; i <IDs.length; i++){

View File

@@ -24,6 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.windows;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Shopkeeper;
@@ -32,13 +33,17 @@ import com.shatteredpixel.shatteredpixeldungeon.items.Gold;
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.MasterThievesArmband;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.MissileWeapon;
import com.shatteredpixel.shatteredpixeldungeon.journal.Catalog;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.ui.CurrencyIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
public class WndTradeItem extends WndInfoItem {
@@ -70,7 +75,16 @@ public class WndTradeItem extends WndInfoItem {
}
final Shopkeeper finalShop = shop;
if (item.quantity() == 1) {
if (item.quantity() == 1 || (item instanceof MissileWeapon && item.isUpgradable())) {
if (item instanceof MissileWeapon && ((MissileWeapon) item).extraThrownLeft){
RenderedTextBlock warn = PixelScene.renderTextBlock(Messages.get(WndUpgrade.class, "thrown_dust"), 6);
warn.hardlight(CharSprite.WARNING);
warn.maxWidth(this.width);
warn.setPos(0, pos + GAP);
add(warn);
pos = warn.bottom();
}
RedButton btnSell = new RedButton( Messages.get(this, "sell", item.value()) ) {
@Override
@@ -230,6 +244,10 @@ public class WndTradeItem extends WndInfoItem {
}
item.detachAll( hero.belongings.backpack );
if (item instanceof MissileWeapon && item.isUpgradable()){
Buff.affect(hero, MissileWeapon.UpgradedSetTracker.class).levelThresholds.put(((MissileWeapon) item).setID, Integer.MAX_VALUE);
}
//selling items in the sell interface doesn't spend time
hero.spend(-hero.cooldown());