v0.7.2: overhauled how items are IDed through use.

This commit is contained in:
Evan Debenham 2019-01-29 13:29:12 -05:00
parent 836782a0fc
commit 247cfc1f97
9 changed files with 127 additions and 63 deletions

View File

@ -79,6 +79,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.keys.IronKey;
import com.shatteredpixel.shatteredpixeldungeon.items.keys.Key; import com.shatteredpixel.shatteredpixeldungeon.items.keys.Key;
import com.shatteredpixel.shatteredpixeldungeon.items.keys.SkeletonKey; import com.shatteredpixel.shatteredpixeldungeon.items.keys.SkeletonKey;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion; 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.potions.PotionOfStrength;
import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfAccuracy; import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfAccuracy;
import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfEvasion; import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfEvasion;
@ -1210,7 +1211,7 @@ public class Hero extends Char {
return true; return true;
} }
public void earnExp( int exp ) { public void earnExp( int exp, Class source ) {
this.exp += exp; this.exp += exp;
float percent = exp/(float)maxExp(); float percent = exp/(float)maxExp();
@ -1227,6 +1228,12 @@ public class Hero extends Char {
Berserk berserk = buff(Berserk.class); Berserk berserk = buff(Berserk.class);
if (berserk != null) berserk.recover(percent); if (berserk != null) berserk.recover(percent);
if (source != PotionOfExperience.class) {
for (Item i : belongings) {
i.onHeroGainExp(percent, this);
}
}
boolean levelUp = false; boolean levelUp = false;
while (this.exp >= maxExp()) { while (this.exp >= maxExp()) {
this.exp -= maxExp(); this.exp -= maxExp();

View File

@ -584,7 +584,7 @@ public abstract class Mob extends Char {
if (exp > 0) { if (exp > 0) {
Dungeon.hero.sprite.showStatus(CharSprite.POSITIVE, Messages.get(this, "exp", exp)); Dungeon.hero.sprite.showStatus(CharSprite.POSITIVE, Messages.get(this, "exp", exp));
} }
Dungeon.hero.earnExp(exp); Dungeon.hero.earnExp(exp, getClass());
} }
} }
} }

View File

@ -367,6 +367,10 @@ public class Item implements Bundlable {
return this; return this;
} }
public void onHeroGainExp( float levelPercent, Hero hero ){
//do nothing by default
}
public static void evoke( Hero hero ) { public static void evoke( Hero hero ) {
hero.sprite.emitter().burst( Speck.factory( Speck.EVOKE ), 5 ); hero.sprite.emitter().burst( Speck.factory( Speck.EVOKE ), 5 );
} }

View File

@ -71,8 +71,6 @@ import java.util.Arrays;
public class Armor extends EquipableItem { public class Armor extends EquipableItem {
private static final int HITS_TO_KNOW = 10;
protected static final String AC_DETACH = "DETACH"; protected static final String AC_DETACH = "DETACH";
public enum Augment { public enum Augment {
@ -103,13 +101,13 @@ public class Armor extends EquipableItem {
public int tier; public int tier;
private int hitsToKnow = HITS_TO_KNOW; private float levelsToID = 1;
public Armor( int tier ) { public Armor( int tier ) {
this.tier = 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 GLYPH = "glyph";
private static final String SEAL = "seal"; private static final String SEAL = "seal";
private static final String AUGMENT = "augment"; private static final String AUGMENT = "augment";
@ -117,7 +115,7 @@ public class Armor extends EquipableItem {
@Override @Override
public void storeInBundle( Bundle bundle ) { public void storeInBundle( Bundle bundle ) {
super.storeInBundle( bundle ); super.storeInBundle( bundle );
bundle.put( UNFAMILIRIARITY, hitsToKnow ); bundle.put( LEVELS_TO_ID, levelsToID );
bundle.put( GLYPH, glyph ); bundle.put( GLYPH, glyph );
bundle.put( SEAL, seal); bundle.put( SEAL, seal);
bundle.put( AUGMENT, augment); bundle.put( AUGMENT, augment);
@ -126,9 +124,15 @@ public class Armor extends EquipableItem {
@Override @Override
public void restoreFromBundle( Bundle bundle ) { public void restoreFromBundle( Bundle bundle ) {
super.restoreFromBundle(bundle); super.restoreFromBundle(bundle);
hitsToKnow = bundle.getInt( UNFAMILIRIARITY ); levelsToID = bundle.getFloat( LEVELS_TO_ID );
inscribe((Glyph) bundle.get(GLYPH)); inscribe((Glyph) bundle.get(GLYPH));
seal = (BrokenSeal)bundle.get(SEAL); seal = (BrokenSeal)bundle.get(SEAL);
//pre-0.7.2 saves
if (bundle.contains( "unfamiliarity" )){
levelsToID = bundle.getInt( "unfamiliarity" ) / 10f;
}
//pre-0.6.5 saves //pre-0.6.5 saves
if (bundle.contains(AUGMENT)) augment = bundle.getEnum(AUGMENT, Augment.class); if (bundle.contains(AUGMENT)) augment = bundle.getEnum(AUGMENT, Augment.class);
} }
@ -358,17 +362,25 @@ public class Armor extends EquipableItem {
damage = glyph.proc( this, attacker, defender, damage ); 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; 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 @Override
public String name() { public String name() {

View File

@ -34,7 +34,7 @@ public class PotionOfExperience extends Potion {
@Override @Override
public void apply( Hero hero ) { public void apply( Hero hero ) {
setKnown(); setKnown();
hero.earnExp( hero.maxExp() ); hero.earnExp( hero.maxExp(), getClass() );
} }
@Override @Override

View File

@ -81,7 +81,7 @@ public class Ring extends KindofMisc {
private String gem; private String gem;
private int ticksToKnow = TICKS_TO_KNOW; private float levelsToID = 1;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static void initGems() { public static void initGems() {
@ -211,6 +211,7 @@ public class Ring extends KindofMisc {
@Override @Override
public Item identify() { public Item identify() {
setKnown(); setKnown();
levelsToID = 0;
return super.identify(); return super.identify();
} }
@ -271,19 +272,22 @@ public class Ring extends KindofMisc {
return null; return null;
} }
private static final String UNFAMILIRIARITY = "unfamiliarity"; private static final String LEVELS_TO_ID = "levels_to_ID";
@Override @Override
public void storeInBundle( Bundle bundle ) { public void storeInBundle( Bundle bundle ) {
super.storeInBundle( bundle ); super.storeInBundle( bundle );
bundle.put( UNFAMILIRIARITY, ticksToKnow ); bundle.put( LEVELS_TO_ID, levelsToID );
} }
@Override @Override
public void restoreFromBundle( Bundle bundle ) { public void restoreFromBundle( Bundle bundle ) {
super.restoreFromBundle( bundle ); super.restoreFromBundle( bundle );
if ((ticksToKnow = bundle.getInt( UNFAMILIRIARITY )) == 0) { levelsToID = bundle.getFloat( LEVELS_TO_ID );
ticksToKnow = TICKS_TO_KNOW;
//pre-0.7.2 saves
if (bundle.contains( "unfamiliarity" )){
levelsToID = bundle.getInt( "unfamiliarity" ) / 200f;
} }
//pre-0.6.1 saves //pre-0.6.1 saves
@ -292,6 +296,16 @@ public class Ring extends KindofMisc {
} }
} }
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<?extends RingBuff> type){ public static int getBonus(Char target, Class<?extends RingBuff> type){
int bonus = 0; int bonus = 0;
for (RingBuff buff : target.buffs(type)) { for (RingBuff buff : target.buffs(type)) {
@ -313,12 +327,6 @@ public class Ring extends KindofMisc {
@Override @Override
public boolean act() { public boolean act() {
if (!isIdentified() && --ticksToKnow <= 0) {
identify();
GLog.w( Messages.get(Ring.class, "identify", Ring.this.toString()) );
Badges.validateItemLevelAquired( Ring.this );
}
spend( TICK ); spend( TICK );
return true; return true;

View File

@ -22,6 +22,7 @@
package com.shatteredpixel.shatteredpixeldungeon.items.wands; package com.shatteredpixel.shatteredpixeldungeon.items.wands;
import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
@ -71,6 +72,10 @@ public abstract class Wand extends Item {
private boolean curChargeKnown = false; private boolean curChargeKnown = false;
protected int usagesToKnow = USAGES_TO_KNOW; 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; protected int collisionProperties = Ballistica.MAGIC_BOLT;
@ -171,6 +176,7 @@ public abstract class Wand extends Item {
@Override @Override
public Item identify() { public Item identify() {
levelsToID = levelsToIDAvailable = 0;
curChargeKnown = true; curChargeKnown = true;
super.identify(); super.identify();
@ -179,6 +185,17 @@ public abstract class Wand extends Item {
return this; 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 @Override
public String info() { public String info() {
String desc = desc(); String desc = desc();
@ -269,15 +286,12 @@ public abstract class Wand extends Item {
} }
protected void wandUsed() { protected void wandUsed() {
usagesToKnow -= cursed ? 1 : chargesPerCast(); if (!isIdentified()) levelsToIDAvailable += 0.15f * (cursed ? 1 : chargesPerCast());
curCharges -= cursed ? 1 : chargesPerCast(); curCharges -= cursed ? 1 : chargesPerCast();
if (!isIdentified() && usagesToKnow <= 0) {
identify(); if (curUser.heroClass == HeroClass.MAGE) levelKnown = true;
GLog.w( Messages.get(Wand.class, "identify", name()) ); updateQuickslot();
} else {
if (curUser.heroClass == HeroClass.MAGE) levelKnown = true;
updateQuickslot();
}
curUser.spendAndNext( TIME_TO_ZAP ); curUser.spendAndNext( TIME_TO_ZAP );
} }
@ -323,15 +337,17 @@ public abstract class Wand extends Item {
return price; return price;
} }
private static final String UNFAMILIRIARITY = "unfamiliarity"; private static final String LEVELS_TO_ID = "levels_to_ID";
private static final String CUR_CHARGES = "curCharges"; private static final String LEVELS_TO_ID_AVA = "levels_to_ID_available";
private static final String CUR_CHARGE_KNOWN = "curChargeKnown"; private static final String CUR_CHARGES = "curCharges";
private static final String PARTIALCHARGE = "partialCharge"; private static final String CUR_CHARGE_KNOWN = "curChargeKnown";
private static final String PARTIALCHARGE = "partialCharge";
@Override @Override
public void storeInBundle( Bundle bundle ) { public void storeInBundle( Bundle bundle ) {
super.storeInBundle( 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_CHARGES, curCharges );
bundle.put( CUR_CHARGE_KNOWN, curChargeKnown ); bundle.put( CUR_CHARGE_KNOWN, curChargeKnown );
bundle.put( PARTIALCHARGE , partialCharge ); bundle.put( PARTIALCHARGE , partialCharge );
@ -340,8 +356,13 @@ public abstract class Wand extends Item {
@Override @Override
public void restoreFromBundle( Bundle bundle ) { public void restoreFromBundle( Bundle bundle ) {
super.restoreFromBundle( bundle ); super.restoreFromBundle( bundle );
if ((usagesToKnow = bundle.getInt( UNFAMILIRIARITY )) == 0) { levelsToID = bundle.getFloat( LEVELS_TO_ID );
usagesToKnow = USAGES_TO_KNOW; 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 ); curCharges = bundle.getInt( CUR_CHARGES );
curChargeKnown = bundle.getBoolean( CUR_CHARGE_KNOWN ); curChargeKnown = bundle.getBoolean( CUR_CHARGE_KNOWN );

View File

@ -233,9 +233,9 @@ public class WandOfCorruption extends Wand {
Statistics.qualifiedForNoKilling = false; Statistics.qualifiedForNoKilling = false;
if (enemy.EXP > 0 && curUser.lvl <= enemy.maxLvl) { if (enemy.EXP > 0 && curUser.lvl <= enemy.maxLvl) {
curUser.sprite.showStatus(CharSprite.POSITIVE, Messages.get(enemy, "exp", enemy.EXP)); curUser.sprite.showStatus(CharSprite.POSITIVE, Messages.get(enemy, "exp", enemy.EXP));
curUser.earnExp(enemy.EXP); curUser.earnExp(enemy.EXP, enemy.getClass());
} else { } else {
curUser.earnExp(0); curUser.earnExp(0, enemy.getClass());
} }
enemy.rollToDropLoot(); enemy.rollToDropLoot();
} else { } else {

View File

@ -22,7 +22,6 @@
package com.shatteredpixel.shatteredpixeldungeon.items.weapon; package com.shatteredpixel.shatteredpixeldungeon.items.weapon;
import com.shatteredpixel.shatteredpixeldungeon.Badges; import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.MagicImmune; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.MagicImmune;
@ -93,7 +92,7 @@ abstract public class Weapon extends KindOfWeapon {
public Augment augment = Augment.NONE; public Augment augment = Augment.NONE;
private int hitsToKnow = HITS_TO_KNOW; private float levelsToID = 1;
public Enchantment enchantment; public Enchantment enchantment;
@ -104,25 +103,33 @@ abstract public class Weapon extends KindOfWeapon {
damage = enchantment.proc( this, attacker, defender, damage ); 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; return damage;
} }
private static final String UNFAMILIRIARITY = "unfamiliarity"; public void onHeroGainExp( float levelPercent, Hero hero ){
private static final String ENCHANTMENT = "enchantment"; if (levelKnown || !isEquipped(hero)) return;
private static final String AUGMENT = "augment"; 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 LEVELS_TO_ID = "levels_to_ID";
private static final String ENCHANTMENT = "enchantment";
private static final String AUGMENT = "augment";
@Override @Override
public void storeInBundle( Bundle bundle ) { public void storeInBundle( Bundle bundle ) {
super.storeInBundle( bundle ); super.storeInBundle( bundle );
bundle.put( UNFAMILIRIARITY, hitsToKnow ); bundle.put( LEVELS_TO_ID, levelsToID );
bundle.put( ENCHANTMENT, enchantment ); bundle.put( ENCHANTMENT, enchantment );
bundle.put( AUGMENT, augment ); bundle.put( AUGMENT, augment );
} }
@ -130,9 +137,14 @@ abstract public class Weapon extends KindOfWeapon {
@Override @Override
public void restoreFromBundle( Bundle bundle ) { public void restoreFromBundle( Bundle bundle ) {
super.restoreFromBundle( bundle ); super.restoreFromBundle( bundle );
hitsToKnow = bundle.getInt( UNFAMILIRIARITY ); levelsToID = bundle.getFloat( LEVELS_TO_ID );
enchantment = (Enchantment)bundle.get( ENCHANTMENT ); enchantment = (Enchantment)bundle.get( ENCHANTMENT );
//pre-0.7.2 saves
if (bundle.contains( "unfamiliarity" )){
levelsToID = bundle.getInt( "unfamiliarity" ) / 20f;
}
//pre-0.6.5 saves //pre-0.6.5 saves
if (bundle.contains( "imbue" )){ if (bundle.contains( "imbue" )){
String imbue = bundle.getString( "imbue" ); String imbue = bundle.getString( "imbue" );