diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java index 804683fe9..70d0818c5 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java @@ -79,6 +79,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.keys.IronKey; import com.shatteredpixel.shatteredpixeldungeon.items.keys.Key; import com.shatteredpixel.shatteredpixeldungeon.items.keys.SkeletonKey; import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion; +import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfExperience; import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfStrength; import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfAccuracy; import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfEvasion; @@ -1210,7 +1211,7 @@ public class Hero extends Char { return true; } - public void earnExp( int exp ) { + public void earnExp( int exp, Class source ) { this.exp += exp; float percent = exp/(float)maxExp(); @@ -1227,6 +1228,12 @@ public class Hero extends Char { Berserk berserk = buff(Berserk.class); if (berserk != null) berserk.recover(percent); + if (source != PotionOfExperience.class) { + for (Item i : belongings) { + i.onHeroGainExp(percent, this); + } + } + boolean levelUp = false; while (this.exp >= maxExp()) { this.exp -= maxExp(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java index 961245070..6997a797c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java @@ -584,7 +584,7 @@ public abstract class Mob extends Char { if (exp > 0) { Dungeon.hero.sprite.showStatus(CharSprite.POSITIVE, Messages.get(this, "exp", exp)); } - Dungeon.hero.earnExp(exp); + Dungeon.hero.earnExp(exp, getClass()); } } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Item.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Item.java index 6a4307774..81fad3ec5 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Item.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Item.java @@ -367,6 +367,10 @@ public class Item implements Bundlable { return this; } + public void onHeroGainExp( float levelPercent, Hero hero ){ + //do nothing by default + } + public static void evoke( Hero hero ) { hero.sprite.emitter().burst( Speck.factory( Speck.EVOKE ), 5 ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java index 36c1fae3d..d21187c7c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java @@ -71,8 +71,6 @@ import java.util.Arrays; public class Armor extends EquipableItem { - private static final int HITS_TO_KNOW = 10; - protected static final String AC_DETACH = "DETACH"; public enum Augment { @@ -103,13 +101,13 @@ public class Armor extends EquipableItem { public int tier; - private int hitsToKnow = HITS_TO_KNOW; + private float levelsToID = 1; public Armor( int tier ) { this.tier = tier; } - private static final String UNFAMILIRIARITY = "unfamiliarity"; + private static final String LEVELS_TO_ID = "levels_to_ID"; private static final String GLYPH = "glyph"; private static final String SEAL = "seal"; private static final String AUGMENT = "augment"; @@ -117,7 +115,7 @@ public class Armor extends EquipableItem { @Override public void storeInBundle( Bundle bundle ) { super.storeInBundle( bundle ); - bundle.put( UNFAMILIRIARITY, hitsToKnow ); + bundle.put( LEVELS_TO_ID, levelsToID ); bundle.put( GLYPH, glyph ); bundle.put( SEAL, seal); bundle.put( AUGMENT, augment); @@ -126,9 +124,15 @@ public class Armor extends EquipableItem { @Override public void restoreFromBundle( Bundle bundle ) { super.restoreFromBundle(bundle); - hitsToKnow = bundle.getInt( UNFAMILIRIARITY ); + levelsToID = bundle.getFloat( LEVELS_TO_ID ); inscribe((Glyph) bundle.get(GLYPH)); seal = (BrokenSeal)bundle.get(SEAL); + + //pre-0.7.2 saves + if (bundle.contains( "unfamiliarity" )){ + levelsToID = bundle.getInt( "unfamiliarity" ) / 10f; + } + //pre-0.6.5 saves if (bundle.contains(AUGMENT)) augment = bundle.getEnum(AUGMENT, Augment.class); } @@ -358,18 +362,26 @@ public class Armor extends EquipableItem { damage = glyph.proc( this, attacker, defender, damage ); } - if (!levelKnown && defender instanceof Hero) { - if (--hitsToKnow <= 0) { - identify(); - GLog.w( Messages.get(Armor.class, "identify") ); - Badges.validateItemLevelAquired( this ); - } - } - return damage; } - - + + @Override + public void onHeroGainExp(float levelPercent, Hero hero) { + if (levelKnown || !isEquipped(hero)) return; + levelsToID -= levelPercent; + if (levelsToID <= 0){ + identify(); + GLog.p( Messages.get(Armor.class, "identify") ); + Badges.validateItemLevelAquired( this ); + } + } + + @Override + public Item identify() { + levelsToID = 0; + return super.identify(); + } + @Override public String name() { return glyph != null && (cursedKnown || !glyph.curse()) ? glyph.name( super.name() ) : super.name(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfExperience.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfExperience.java index 469156783..a5dc6f9ed 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfExperience.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfExperience.java @@ -34,7 +34,7 @@ public class PotionOfExperience extends Potion { @Override public void apply( Hero hero ) { setKnown(); - hero.earnExp( hero.maxExp() ); + hero.earnExp( hero.maxExp(), getClass() ); } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java index a7ba24210..6a58175e3 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java @@ -81,7 +81,7 @@ public class Ring extends KindofMisc { private String gem; - private int ticksToKnow = TICKS_TO_KNOW; + private float levelsToID = 1; @SuppressWarnings("unchecked") public static void initGems() { @@ -211,6 +211,7 @@ public class Ring extends KindofMisc { @Override public Item identify() { setKnown(); + levelsToID = 0; return super.identify(); } @@ -271,19 +272,22 @@ public class Ring extends KindofMisc { return null; } - private static final String UNFAMILIRIARITY = "unfamiliarity"; + private static final String LEVELS_TO_ID = "levels_to_ID"; @Override public void storeInBundle( Bundle bundle ) { super.storeInBundle( bundle ); - bundle.put( UNFAMILIRIARITY, ticksToKnow ); + bundle.put( LEVELS_TO_ID, levelsToID ); } @Override public void restoreFromBundle( Bundle bundle ) { super.restoreFromBundle( bundle ); - if ((ticksToKnow = bundle.getInt( UNFAMILIRIARITY )) == 0) { - ticksToKnow = TICKS_TO_KNOW; + levelsToID = bundle.getFloat( LEVELS_TO_ID ); + + //pre-0.7.2 saves + if (bundle.contains( "unfamiliarity" )){ + levelsToID = bundle.getInt( "unfamiliarity" ) / 200f; } //pre-0.6.1 saves @@ -291,6 +295,16 @@ public class Ring extends KindofMisc { upgrade(-level()); } } + + public void onHeroGainExp( float levelPercent, Hero hero ){ + if (!isIdentified() || !isEquipped(hero)) return; + levelsToID -= levelPercent; + if (levelsToID <= 0){ + identify(); + GLog.p( Messages.get(Ring.class, "identify", toString()) ); + Badges.validateItemLevelAquired( this ); + } + } public static int getBonus(Char target, Class type){ int bonus = 0; @@ -313,12 +327,6 @@ public class Ring extends KindofMisc { @Override public boolean act() { - if (!isIdentified() && --ticksToKnow <= 0) { - identify(); - GLog.w( Messages.get(Ring.class, "identify", Ring.this.toString()) ); - Badges.validateItemLevelAquired( Ring.this ); - } - spend( TICK ); return true; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/Wand.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/Wand.java index 3e5a16200..b30cabdbd 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/Wand.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/Wand.java @@ -22,6 +22,7 @@ package com.shatteredpixel.shatteredpixeldungeon.items.wands; import com.shatteredpixel.shatteredpixeldungeon.Assets; +import com.shatteredpixel.shatteredpixeldungeon.Badges; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; @@ -71,6 +72,10 @@ public abstract class Wand extends Item { private boolean curChargeKnown = false; protected int usagesToKnow = USAGES_TO_KNOW; + private float levelsToID = 1; + //wands can't be equipped, so the player needs to use them in addition to gaining exp + //takes 5 charges spent, giving 15% exp gain each, plus 25% given right away + private float levelsToIDAvailable = 0.25f; protected int collisionProperties = Ballistica.MAGIC_BOLT; @@ -170,7 +175,8 @@ public abstract class Wand extends Item { @Override public Item identify() { - + + levelsToID = levelsToIDAvailable = 0; curChargeKnown = true; super.identify(); @@ -178,6 +184,17 @@ public abstract class Wand extends Item { return this; } + + public void onHeroGainExp( float levelPercent, Hero hero ){ + if (isIdentified()) return; + levelsToID -= Math.min(levelsToIDAvailable, levelPercent); + levelsToIDAvailable = Math.max(0, levelsToIDAvailable - levelPercent); + if (levelsToID <= 0){ + identify(); + GLog.p( Messages.get(Wand.class, "identify", name()) ); + Badges.validateItemLevelAquired( this ); + } + } @Override public String info() { @@ -269,15 +286,12 @@ public abstract class Wand extends Item { } protected void wandUsed() { - usagesToKnow -= cursed ? 1 : chargesPerCast(); + if (!isIdentified()) levelsToIDAvailable += 0.15f * (cursed ? 1 : chargesPerCast()); + curCharges -= cursed ? 1 : chargesPerCast(); - if (!isIdentified() && usagesToKnow <= 0) { - identify(); - GLog.w( Messages.get(Wand.class, "identify", name()) ); - } else { - if (curUser.heroClass == HeroClass.MAGE) levelKnown = true; - updateQuickslot(); - } + + if (curUser.heroClass == HeroClass.MAGE) levelKnown = true; + updateQuickslot(); curUser.spendAndNext( TIME_TO_ZAP ); } @@ -323,15 +337,17 @@ public abstract class Wand extends Item { return price; } - private static final String UNFAMILIRIARITY = "unfamiliarity"; - private static final String CUR_CHARGES = "curCharges"; - private static final String CUR_CHARGE_KNOWN = "curChargeKnown"; - private static final String PARTIALCHARGE = "partialCharge"; + private static final String LEVELS_TO_ID = "levels_to_ID"; + private static final String LEVELS_TO_ID_AVA = "levels_to_ID_available"; + private static final String CUR_CHARGES = "curCharges"; + private static final String CUR_CHARGE_KNOWN = "curChargeKnown"; + private static final String PARTIALCHARGE = "partialCharge"; @Override public void storeInBundle( Bundle bundle ) { super.storeInBundle( bundle ); - bundle.put( UNFAMILIRIARITY, usagesToKnow ); + bundle.put( LEVELS_TO_ID, levelsToID ); + bundle.put( LEVELS_TO_ID_AVA, levelsToIDAvailable ); bundle.put( CUR_CHARGES, curCharges ); bundle.put( CUR_CHARGE_KNOWN, curChargeKnown ); bundle.put( PARTIALCHARGE , partialCharge ); @@ -340,8 +356,13 @@ public abstract class Wand extends Item { @Override public void restoreFromBundle( Bundle bundle ) { super.restoreFromBundle( bundle ); - if ((usagesToKnow = bundle.getInt( UNFAMILIRIARITY )) == 0) { - usagesToKnow = USAGES_TO_KNOW; + levelsToID = bundle.getFloat( LEVELS_TO_ID ); + levelsToIDAvailable = bundle.getFloat( LEVELS_TO_ID_AVA ); + + //pre-0.7.2 saves + if (bundle.contains( "unfamiliarity" )){ + levelsToID = bundle.getInt( "unfamiliarity" ) / 20f; + levelsToIDAvailable = levelsToID; } curCharges = bundle.getInt( CUR_CHARGES ); curChargeKnown = bundle.getBoolean( CUR_CHARGE_KNOWN ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfCorruption.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfCorruption.java index 1e15f8aa8..163df91df 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfCorruption.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfCorruption.java @@ -233,9 +233,9 @@ public class WandOfCorruption extends Wand { Statistics.qualifiedForNoKilling = false; if (enemy.EXP > 0 && curUser.lvl <= enemy.maxLvl) { curUser.sprite.showStatus(CharSprite.POSITIVE, Messages.get(enemy, "exp", enemy.EXP)); - curUser.earnExp(enemy.EXP); + curUser.earnExp(enemy.EXP, enemy.getClass()); } else { - curUser.earnExp(0); + curUser.earnExp(0, enemy.getClass()); } enemy.rollToDropLoot(); } else { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java index 782e9a872..d24b8c9f6 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java @@ -22,7 +22,6 @@ package com.shatteredpixel.shatteredpixeldungeon.items.weapon; import com.shatteredpixel.shatteredpixeldungeon.Badges; -import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.MagicImmune; @@ -93,7 +92,7 @@ abstract public class Weapon extends KindOfWeapon { public Augment augment = Augment.NONE; - private int hitsToKnow = HITS_TO_KNOW; + private float levelsToID = 1; public Enchantment enchantment; @@ -103,26 +102,34 @@ abstract public class Weapon extends KindOfWeapon { if (enchantment != null && attacker.buff(MagicImmune.class) == null) { damage = enchantment.proc( this, attacker, defender, damage ); } - - if (!levelKnown && attacker == Dungeon.hero) { - if (--hitsToKnow <= 0) { - identify(); - GLog.i( Messages.get(Weapon.class, "identify") ); - Badges.validateItemLevelAquired( this ); - } - } return damage; } + + public void onHeroGainExp( float levelPercent, Hero hero ){ + if (levelKnown || !isEquipped(hero)) return; + levelsToID -= levelPercent; + if (levelsToID <= 0){ + identify(); + GLog.p( Messages.get(Weapon.class, "identify") ); + Badges.validateItemLevelAquired( this ); + } + } + + @Override + public Item identify() { + levelsToID = 0; + return super.identify(); + } - private static final String UNFAMILIRIARITY = "unfamiliarity"; - private static final String ENCHANTMENT = "enchantment"; - private static final String AUGMENT = "augment"; + private static final String LEVELS_TO_ID = "levels_to_ID"; + private static final String ENCHANTMENT = "enchantment"; + private static final String AUGMENT = "augment"; @Override public void storeInBundle( Bundle bundle ) { super.storeInBundle( bundle ); - bundle.put( UNFAMILIRIARITY, hitsToKnow ); + bundle.put( LEVELS_TO_ID, levelsToID ); bundle.put( ENCHANTMENT, enchantment ); bundle.put( AUGMENT, augment ); } @@ -130,9 +137,14 @@ abstract public class Weapon extends KindOfWeapon { @Override public void restoreFromBundle( Bundle bundle ) { super.restoreFromBundle( bundle ); - hitsToKnow = bundle.getInt( UNFAMILIRIARITY ); + levelsToID = bundle.getFloat( LEVELS_TO_ID ); enchantment = (Enchantment)bundle.get( ENCHANTMENT ); + //pre-0.7.2 saves + if (bundle.contains( "unfamiliarity" )){ + levelsToID = bundle.getInt( "unfamiliarity" ) / 20f; + } + //pre-0.6.5 saves if (bundle.contains( "imbue" )){ String imbue = bundle.getString( "imbue" );