diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java index c93d73f35..34bb35533 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java @@ -150,10 +150,21 @@ public class Belongings implements Iterable { return null; } + public boolean contains( Item contains ){ + + for (Item item : this) { + if (contains == item ) { + return true; + } + } + + return false; + } + public Item getSimilar( Item similar ){ for (Item item : this) { - if (similar.isSimilar(item)) { + if (similar != item && similar.isSimilar(item)) { return item; } } @@ -165,7 +176,7 @@ public class Belongings implements Iterable { ArrayList result = new ArrayList<>(); for (Item item : this) { - if (similar.isSimilar(item)) { + if (item != similar && similar.isSimilar(item)) { result.add(item); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Blacksmith.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Blacksmith.java index a92c6bc30..28295e8bf 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Blacksmith.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Blacksmith.java @@ -33,6 +33,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor; import com.shatteredpixel.shatteredpixeldungeon.items.quest.DarkGold; import com.shatteredpixel.shatteredpixeldungeon.items.quest.Pickaxe; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfUpgrade; +import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.MissileWeapon; import com.shatteredpixel.shatteredpixeldungeon.journal.Notes; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.BlacksmithRoom; @@ -149,7 +150,7 @@ public class Blacksmith extends NPC { public static String verify( Item item1, Item item2 ) { - if (item1 == item2) { + if (item1 == item2 && (item1.quantity() == 1 && item2.quantity() == 1)) { return Messages.get(Blacksmith.class, "same_item"); } @@ -194,14 +195,20 @@ public class Blacksmith extends NPC { if (first.isEquipped( Dungeon.hero )) { ((EquipableItem)first).doUnequip( Dungeon.hero, true ); } + if (first instanceof MissileWeapon && first.quantity() > 1){ + first = first.split(1); + } first.level(first.level()+1); //prevents on-upgrade effects like enchant/glyph removal + if (first instanceof MissileWeapon && !Dungeon.hero.belongings.contains(first)) { + first.collect(); + } Dungeon.hero.spendAndNext( 2f ); Badges.validateItemLevelAquired( first ); if (second.isEquipped( Dungeon.hero )) { ((EquipableItem)second).doUnequip( Dungeon.hero, false ); } - second.detachAll( Dungeon.hero.belongings.backpack ); + second.detach( Dungeon.hero.belongings.backpack ); if (second instanceof Armor){ BrokenSeal seal = ((Armor) second).checkSeal(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/spells/MagicalInfusion.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/spells/MagicalInfusion.java index 126a614b2..474e779fe 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/spells/MagicalInfusion.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/spells/MagicalInfusion.java @@ -28,6 +28,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfUpgrade; import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfEnchantment; +import com.shatteredpixel.shatteredpixeldungeon.items.weapon.SpiritBow; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; @@ -44,10 +45,15 @@ public class MagicalInfusion extends InventorySpell { @Override protected void onItemSelected( Item item ) { - if (item instanceof Weapon) - ((Weapon)item).upgrade(true); - else - ((Armor)item).upgrade(true); + if (item instanceof SpiritBow){ + if (((SpiritBow) item).enchantment == null){ + ((Weapon)item).enchant(); + } + } else if (item instanceof Weapon) { + ((Weapon) item).upgrade(true); + } else { + ((Armor) item).upgrade(true); + } GLog.p( Messages.get(this, "infuse", item.name()) ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java index 56e5bb855..b2adcf1ff 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java @@ -96,24 +96,32 @@ abstract public class MissileWeapon extends Weapon { } @Override + //FIXME some logic here assumes the items are in the player's inventory. Might need to adjust public Item upgrade() { if (!bundleRestoring) { if (quantity > 1) { - MissileWeapon left = (MissileWeapon) split(quantity - 1); - left.parent = null; + MissileWeapon upgraded = (MissileWeapon) split(1); + upgraded.parent = null; - super.upgrade(); + upgraded = (MissileWeapon) upgraded.upgrade(); - //deal with full inventory. - if (!left.collect()) { - Dungeon.level.drop(left, Dungeon.hero.pos); + //try to put the upgraded into inventory, if it didn't already merge + if (upgraded.quantity() == 1 && !upgraded.collect()) { + Dungeon.level.drop(upgraded, Dungeon.hero.pos); } + return upgraded; } else { + durability = MAX_DURABILITY; super.upgrade(); + + Item similar = Dungeon.hero.belongings.getSimilar(this); + if (similar != null){ + detach(Dungeon.hero.belongings.backpack); + return similar.merge(this); + } + return this; } - durability = MAX_DURABILITY; - return this; } else { return super.upgrade(); }