v0.4.0: lots of refactoring to on-upgrade logic

This commit is contained in:
Evan Debenham 2016-06-14 23:07:32 -04:00 committed by Evan Debenham
parent 9f65ff4e5b
commit 4c8bcade38
9 changed files with 121 additions and 89 deletions

View File

@ -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 );

View File

@ -273,6 +273,8 @@ public class Item implements Bundlable {
public void level( int value ){
level = value;
updateQuickslot();
}
public Item upgrade() {

View File

@ -228,25 +228,10 @@ 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<?extends Glyph> type) {
return glyph != null && glyph.getClass() == type;
}
public boolean hasGoodGlyph(){
return glyph != null && !glyph.curse();
}
public boolean hasCurseGlyph(){
return glyph != null && glyph.curse();
}
@Override

View File

@ -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();
}
}
}

View File

@ -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;

View File

@ -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 );
}
}

View File

@ -186,16 +186,10 @@ 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 );

View File

@ -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<?extends Enchantment> type) {
return enchantment != null && enchantment.getClass() == type;
}
public boolean hasGoodEnchant(){
return enchantment != null && !enchantment.curse();
}
public boolean hasCurseEnchant(){ return enchantment != null && enchantment.curse();
}
@Override

View File

@ -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.