From 4c8bcade389ce63a1bd1df0dc01ab70b78718bf6 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Tue, 14 Jun 2016 23:07:32 -0400 Subject: [PATCH] v0.4.0: lots of refactoring to on-upgrade logic --- .../actors/mobs/npcs/Blacksmith.java | 2 +- .../shatteredpixeldungeon/items/Item.java | 2 + .../items/armor/Armor.java | 37 ++++----- .../items/rings/Ring.java | 32 +------- .../items/scrolls/ScrollOfRemoveCurse.java | 4 +- .../items/scrolls/ScrollOfUpgrade.java | 81 ++++++++++++++++++- .../items/wands/Wand.java | 12 +-- .../items/weapon/Weapon.java | 35 ++++---- .../messages/items/items.properties | 5 +- 9 files changed, 121 insertions(+), 89 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Blacksmith.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Blacksmith.java index b587f45f7..1119ceb84 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Blacksmith.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Blacksmith.java @@ -189,7 +189,7 @@ public class Blacksmith extends NPC { if (first.isEquipped( Dungeon.hero )) { ((EquipableItem)first).doUnequip( Dungeon.hero, true ); } - first.upgrade(); + first.level(first.level()+1); //prevents on-upgrade effects like enchant/glyph removal GLog.p( Messages.get(ScrollOfUpgrade.class, "looks_better", first.name()) ); Dungeon.hero.spendAndNext( 2f ); Badges.validateItemLevelAquired( first ); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/Item.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/Item.java index a2952cf80..3d5200547 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/Item.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/Item.java @@ -273,6 +273,8 @@ public class Item implements Bundlable { public void level( int value ){ level = value; + + updateQuickslot(); } public Item upgrade() { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java index 846c2bdb9..9dad276e1 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java @@ -227,26 +227,11 @@ public class Armor extends EquipableItem { } public Item upgrade( boolean inscribe ) { - - if (glyph != null) { - if (inscribe && glyph.curse()){ - inscribe( Glyph.random() ); - } else if (!inscribe && Random.Float() > Math.pow(0.9, level())) { - if (!glyph.curse()) - GLog.w( Messages.get(Armor.class, "incompatible") ); - else if (cursedKnown) { - GLog.p(Messages.get(Item.class, "remove_curse")); - Dungeon.hero.sprite.emitter().start( ShadowParticle.UP, 0.05f, 10 ); - } - inscribe( null ); - } else if (!inscribe && glyph.curse() && cursed && cursedKnown){ - GLog.p( Messages.get(Item.class, "weaken_curse") ); - Dungeon.hero.sprite.emitter().start( ShadowParticle.UP, 0.05f, 10 ); - } - } else { - if (inscribe) { - inscribe( Glyph.random() ); - } + + if (inscribe && (glyph == null || glyph.curse())){ + inscribe( Glyph.random() ); + } else if (!inscribe && Random.Float() > Math.pow(0.9, level())){ + inscribe(null); } if (seal != null && seal.level() == 0) @@ -406,8 +391,16 @@ public class Armor extends EquipableItem { return inscribe( gl ); } - public boolean isInscribed() { - return glyph != null; + public boolean hasGlyph(Class type) { + return glyph != null && glyph.getClass() == type; + } + + public boolean hasGoodGlyph(){ + return glyph != null && !glyph.curse(); + } + + public boolean hasCurseGlyph(){ + return glyph != null && glyph.curse(); } @Override diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java index 697aed626..747200a00 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java @@ -127,28 +127,6 @@ public class Ring extends KindofMisc { } } - @Override - public Item upgrade() { - - if (cursed && cursedKnown) { - GLog.p( Messages.get(Item.class, "weaken_curse") ); - Dungeon.hero.sprite.emitter().start( ShadowParticle.UP, 0.05f, 10 ); - } - - super.upgrade(); - - if (buff != null) { - - Char owner = buff.target; - buff.detach(); - if ((buff = buff()) != null) { - buff.attachTo( owner ); - } - } - - return this; - } - public boolean isKnown() { return handler.isKnown( this ); } @@ -263,11 +241,6 @@ public class Ring extends KindofMisc { public class RingBuff extends Buff { - public int level; - public RingBuff() { - level = Ring.this.level(); - } - @Override public boolean attachTo( Char target ) { @@ -284,7 +257,6 @@ public class Ring extends KindofMisc { public boolean act() { if (!isIdentified() && --ticksToKnow <= 0) { - String gemName = name(); identify(); GLog.w( Messages.get(Ring.class, "identify", Ring.this.toString()) ); Badges.validateItemLevelAquired( Ring.this ); @@ -294,5 +266,9 @@ public class Ring extends KindofMisc { return true; } + + public int level(){ + return Ring.this.level(); + } } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfRemoveCurse.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfRemoveCurse.java index 03c8b86f8..f66f146f7 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfRemoveCurse.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfRemoveCurse.java @@ -68,7 +68,7 @@ public class ScrollOfRemoveCurse extends InventoryScroll { } if (item instanceof Weapon){ Weapon w = (Weapon) item; - if (w.enchantment != null && w.enchantment.curse()){ + if (w.hasCurseEnchant()){ w.enchant(null); w.cursed = false; procced = true; @@ -76,7 +76,7 @@ public class ScrollOfRemoveCurse extends InventoryScroll { } if (item instanceof Armor){ Armor a = (Armor) item; - if (a.glyph != null && a.glyph.curse()){ + if (a.hasCurseGlyph()){ a.inscribe(null); a.cursed = false; procced = true; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfUpgrade.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfUpgrade.java index 4346d41f3..5e8dc44d6 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfUpgrade.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfUpgrade.java @@ -21,9 +21,15 @@ package com.shatteredpixel.shatteredpixeldungeon.items.scrolls; import com.shatteredpixel.shatteredpixeldungeon.Badges; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; +import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShadowParticle; import com.shatteredpixel.shatteredpixeldungeon.items.Item; +import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor; +import com.shatteredpixel.shatteredpixeldungeon.items.rings.Ring; +import com.shatteredpixel.shatteredpixeldungeon.items.wands.Wand; +import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; @@ -40,10 +46,69 @@ public class ScrollOfUpgrade extends InventoryScroll { @Override protected void onItemSelected( Item item ) { - item.upgrade(); - upgrade( curUser ); - GLog.p( Messages.get(this, "looks_better", item.name()) ); + + //logic for telling the user when item properties change from upgrades + //...yes this is rather messy + if (item instanceof Weapon){ + Weapon w = (Weapon) item; + boolean wasCursed = w.cursed; + boolean hadCursedEnchant = w.hasCurseEnchant(); + boolean hadGoodEnchant = w.hasGoodEnchant(); + + w.upgrade(); + + if (hadCursedEnchant && !w.hasCurseEnchant()){ + removeCurse( Dungeon.hero ); + } else if (wasCursed && !w.cursed){ + weakenCurse( Dungeon.hero ); + } + if (hadGoodEnchant && !w.hasGoodEnchant()){ + GLog.w( Messages.get(Weapon.class, "incompatible") ); + } + + } else if (item instanceof Armor){ + Armor a = (Armor) item; + boolean wasCursed = a.cursed; + boolean hadCursedGlyph = a.hasCurseGlyph(); + boolean hadGoodGlyph = a.hasGoodGlyph(); + + a.upgrade(); + + if (hadCursedGlyph && a.glyph == null){ + removeCurse( Dungeon.hero ); + } else if (wasCursed && !a.cursed){ + weakenCurse( Dungeon.hero ); + } + if (hadGoodGlyph && !a.hasGoodGlyph()){ + GLog.w( Messages.get(Armor.class, "incompatible") ); + } + + } else if (item instanceof Wand) { + boolean wasCursed = item.cursed; + + item.upgrade(); + + if (wasCursed && !item.cursed){ + removeCurse( Dungeon.hero ); + } + + } else if (item instanceof Ring) { + boolean wasCursed = item.cursed; + + item.upgrade(); + + if (wasCursed && !item.cursed){ + if (item.level() < 1){ + weakenCurse( Dungeon.hero ); + } else { + removeCurse( Dungeon.hero ); + } + } + + } else { + item.upgrade(); + } Badges.validateItemLevelAquired( item ); } @@ -52,4 +117,14 @@ public class ScrollOfUpgrade extends InventoryScroll { hero.sprite.emitter().start( Speck.factory( Speck.UP ), 0.2f, 3 ); } + public static void weakenCurse( Hero hero ){ + GLog.p( Messages.get(ScrollOfUpgrade.class, "weaken_curse") ); + hero.sprite.emitter().start( ShadowParticle.UP, 0.05f, 5 ); + } + + public static void removeCurse( Hero hero ){ + GLog.p( Messages.get(ScrollOfUpgrade.class, "remove_curse") ); + hero.sprite.emitter().start( ShadowParticle.UP, 0.05f, 10 ); + } + } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/wands/Wand.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/wands/Wand.java index 7b60b8cf6..6c14c97d2 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/wands/Wand.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/wands/Wand.java @@ -186,17 +186,11 @@ public abstract class Wand extends Item { @Override public Item upgrade() { - boolean cursedPreUpgrade = cursed; - super.upgrade(); - if (cursedPreUpgrade && Random.Float() > Math.pow(0.9, level())){ - GLog.p( Messages.get(Item.class, "remove_curse") ); - Dungeon.hero.sprite.emitter().start( ShadowParticle.UP, 0.05f, 10 ); - } else { - cursed = cursedPreUpgrade; - } - + if (Random.Float() > Math.pow(0.9, level())) + cursed = false; + updateLevel(); curCharges = Math.min( curCharges + 1, maxCharges ); updateQuickslot(); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java index c62a1fcdc..3610437db 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java @@ -205,25 +205,11 @@ abstract public class Weapon extends KindOfWeapon { public abstract int STRReq(int lvl); public Item upgrade( boolean enchant ) { - if (enchantment != null) { - if (enchant && enchantment.curse()){ - enchant( Enchantment.random() ); - } else if (!enchant && Random.Float() > Math.pow(0.9, level())) { - if (!enchantment.curse()) - GLog.w( Messages.get(Weapon.class, "incompatible") ); - else { - GLog.p(Messages.get(Item.class, "remove_curse")); - Dungeon.hero.sprite.emitter().start( ShadowParticle.UP, 0.05f, 10 ); - } - enchant( null ); - } else if (!enchant && enchantment.curse() && cursed && cursedKnown){ - GLog.p( Messages.get(Item.class, "weaken_curse") ); - Dungeon.hero.sprite.emitter().start( ShadowParticle.UP, 0.05f, 10 ); - } - } else { - if (enchant) { - enchant( ); - } + + if (enchant && (enchantment == null || enchantment.curse())){ + enchant( Enchantment.random() ); + } else if (!enchant && Random.Float() > Math.pow(0.9, level())){ + enchant(null); } return super.upgrade(); @@ -275,8 +261,15 @@ abstract public class Weapon extends KindOfWeapon { return enchant( ench ); } - public boolean isEnchanted() { - return enchantment != null; + public boolean hasEnchant(Class type) { + return enchantment != null && enchantment.getClass() == type; + } + + public boolean hasGoodEnchant(){ + return enchantment != null && !enchantment.curse(); + } + + public boolean hasCurseEnchant(){ return enchantment != null && enchantment.curse(); } @Override diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/messages/items/items.properties b/src/com/shatteredpixel/shatteredpixeldungeon/messages/items/items.properties index 222a869fe..4b291f8fe 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/messages/items/items.properties +++ b/src/com/shatteredpixel/shatteredpixeldungeon/messages/items/items.properties @@ -620,7 +620,8 @@ items.scrolls.scrollofterror.desc=A flash of red light will overwhelm all creatu items.scrolls.scrollofupgrade.name=scroll of upgrade items.scrolls.scrollofupgrade.inv_title=Select an item to upgrade -items.scrolls.scrollofupgrade.looks_better=Your %s certainly looks better now. +items.scrollofupgrade.weaken_curse=The scroll of upgrade weakens the curse on your item. +items.scrollofupgrade.remove_curse=The scroll of upgrade cleanses the curse on your item! items.scrolls.scrollofupgrade.desc=This scroll will upgrade a single item, improving its quality. A wand will increase in power and number of charges, weapons and armor will deal and block more damage, and the effects of rings will intensify. This scroll is even able to sometimes dispel curse effects, though it is not as potent as a scroll of remove curse. @@ -997,8 +998,6 @@ items.item.ac_drop=DROP items.item.ac_throw=THROW items.item.rankings_desc=Killed by: %s items.item.curse=curse -items.item.weaken_curse=The curse on your item has been weakened. -items.item.remove_curse=The curse on your item has been erased! items.kindofmisc.unequip_title=Unequip one item items.kindofmisc.unequip_message=You can only wear two misc items at a time.