From 912fd447d01adc8145211e23281e749fd9e20077 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Wed, 15 Jun 2016 03:03:27 -0400 Subject: [PATCH] v0.4.0: refactoring for enchant/glyph referencing --- .../actors/buffs/Burning.java | 3 +-- .../shatteredpixeldungeon/actors/hero/Hero.java | 16 +++++++--------- .../shatteredpixeldungeon/items/Stylus.java | 2 +- .../shatteredpixeldungeon/items/armor/Armor.java | 4 ++-- .../items/rings/RingOfEvasion.java | 8 ++++---- .../items/scrolls/ScrollOfUpgrade.java | 2 +- .../items/weapon/Weapon.java | 4 ++-- .../items/weapon/melee/MeleeWeapon.java | 4 ++-- .../items/weapon/missiles/MissileWeapon.java | 2 +- .../levels/features/HighGrass.java | 3 +-- .../shatteredpixeldungeon/windows/WndBag.java | 4 ++-- 11 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Burning.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Burning.java index c921200a2..bf6b61129 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Burning.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Burning.java @@ -83,8 +83,7 @@ public class Burning extends Buff implements Hero.Doom { Hero hero = (Hero)target; - if (hero.belongings.armor != null && hero.belongings.armor.glyph != null - && hero.belongings.armor.glyph instanceof Brimstone){ + if (hero.belongings.armor != null && hero.belongings.armor.hasGlyph(Brimstone.class)){ int heal = hero.belongings.armor.level()/2; if (heal > 0 && hero.HP < hero.HT) { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java index 617626c8b..35b921237 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java @@ -295,8 +295,7 @@ public class Hero extends Char { bonus = 0; if (heroClass == HeroClass.ROGUE) bonus += -aEnc; - if (belongings.armor != null && belongings.armor.glyph != null - && belongings.armor.glyph instanceof Swiftness) + if (belongings.armor != null && belongings.armor.hasGlyph(Swiftness.class)) bonus += 5 + belongings.armor.level()*1.5f; return Math.round((defenseSkill + bonus) * evasion); @@ -355,11 +354,11 @@ public class Hero extends Char { Armor armor = belongings.armor; - if (armor != null && armor.glyph != null){ + if (armor != null){ - if (armor.glyph instanceof Swiftness) { + if (armor.hasGlyph(Swiftness.class)) { speed *= (1.1f + 0.01f * belongings.armor.level()); - } else if (armor.glyph instanceof Flow && Level.water[pos]){ + } else if (armor.hasGlyph(Flow.class) && Level.water[pos]){ speed *= (1.5f + 0.05f * belongings.armor.level()); } } @@ -958,8 +957,8 @@ public class Hero extends Char { dmg = (int)Math.ceil((float)dmg * Math.pow(0.9, tenacity*((float)(HT - HP)/HT))); //TODO improve this when I have proper damage source logic - if (belongings.armor != null && belongings.armor.glyph != null - && belongings.armor.glyph instanceof AntiMagic && RingOfElements.FULL.contains(src.getClass())){ + if (belongings.armor != null && belongings.armor.hasGlyph(AntiMagic.class) + && RingOfElements.FULL.contains(src.getClass())){ dmg -= Random.IntRange(0, belongings.armor.DR()/2); } @@ -1235,8 +1234,7 @@ public class Hero extends Char { for (Buff buff : buffs( RingOfEvasion.Evasion.class )) { stealth += ((RingOfEvasion.Evasion)buff).effectiveLevel; } - if (belongings.armor != null && belongings.armor.glyph != null - && belongings.armor.glyph instanceof Obfuscation){ + if (belongings.armor != null && belongings.armor.hasGlyph(Obfuscation.class)){ stealth += belongings.armor.level(); } return stealth; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/Stylus.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/Stylus.java index fe37eb91b..5eb312529 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/Stylus.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/Stylus.java @@ -83,7 +83,7 @@ public class Stylus extends Item { if (!armor.isIdentified() ){ GLog.w( Messages.get(this, "identify")); return; - } else if (armor.cursed || (armor.glyph != null && armor.glyph.curse())){ + } else if (armor.cursed || armor.hasCurseGlyph()){ GLog.w( Messages.get(this, "cursed")); return; } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java index 9dad276e1..67befa276 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java @@ -355,10 +355,10 @@ public class Armor extends EquipableItem { @Override public int price() { int price = 10 * (1 << (tier - 1)); - if (glyph != null) { + if (hasCurseGlyph()) { price *= 1.5; } - if (cursed && cursedKnown) { + if (cursedKnown && (cursed || hasCurseGlyph())) { price /= 2; } if (levelKnown) { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfEvasion.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfEvasion.java index 6e1c53342..4bffbbd64 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfEvasion.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfEvasion.java @@ -40,7 +40,7 @@ public class RingOfEvasion extends Ring { public boolean attachTo( Char target ) { pos = target.pos; - effectiveLevel = Math.min(0, level); + effectiveLevel = Math.min(0, level()); return super.attachTo(target); } @@ -56,12 +56,12 @@ public class RingOfEvasion extends Ring { } } - if (level < 1){ - effectiveLevel = level; + if (level() < 1){ + effectiveLevel = level(); } else if (seen) { effectiveLevel = Math.max(effectiveLevel - 1, 0); } else { - effectiveLevel = Math.min(effectiveLevel + 1, level); + effectiveLevel = Math.min(effectiveLevel + 1, level()); } return super.act(); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfUpgrade.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfUpgrade.java index 5e8dc44d6..bc71824e3 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfUpgrade.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfUpgrade.java @@ -75,7 +75,7 @@ public class ScrollOfUpgrade extends InventoryScroll { a.upgrade(); - if (hadCursedGlyph && a.glyph == null){ + if (hadCursedGlyph && !a.hasCurseGlyph()){ removeCurse( Dungeon.hero ); } else if (wasCursed && !a.cursed){ weakenCurse( Dungeon.hero ); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java index 3610437db..bb67b2c42 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java @@ -141,7 +141,7 @@ abstract public class Weapon extends KindOfWeapon { int encumbrance = STRReq() - hero.STR(); - if (enchantment instanceof Wayward) + if (hasEnchant(Wayward.class)) encumbrance = Math.max(3, encumbrance+3); float ACC = this.ACC; @@ -180,7 +180,7 @@ abstract public class Weapon extends KindOfWeapon { @Override public int reachFactor(Hero hero) { - return enchantment instanceof Projecting ? RCH+1 : RCH; + return hasEnchant(Projecting.class) ? RCH+1 : RCH; } @Override diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/melee/MeleeWeapon.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/melee/MeleeWeapon.java index a5b6f93c0..84a741650 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/melee/MeleeWeapon.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/melee/MeleeWeapon.java @@ -106,10 +106,10 @@ public class MeleeWeapon extends Weapon { @Override public int price() { int price = 20 * (1 << (tier - 1)); - if (enchantment != null) { + if (hasGoodEnchant()) { price *= 1.5; } - if (cursed && cursedKnown) { + if (cursedKnown && (cursed || hasCurseEnchant())) { price /= 2; } if (levelKnown) { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java index 3b0bca4cd..5806337aa 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java @@ -58,7 +58,7 @@ abstract public class MissileWeapon extends Weapon { protected int throwPos(Hero user, int dst) { int defaultPos = super.throwPos(user, dst); if (defaultPos == dst) return dst; - else if (enchantment instanceof Projecting){ + else if (hasEnchant(Projecting.class)){ Ballistica ProjectingTrajectory = new Ballistica( user.pos, dst, Ballistica.STOP_TARGET ); if (ProjectingTrajectory.dist <= 4) return ProjectingTrajectory.collisionPos; else return super.throwPos(user, dst); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/levels/features/HighGrass.java b/src/com/shatteredpixel/shatteredpixeldungeon/levels/features/HighGrass.java index fa9dc3ef8..c05e37251 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/levels/features/HighGrass.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/levels/features/HighGrass.java @@ -96,8 +96,7 @@ public class HighGrass { } //Camouflage - if (hero.belongings.armor != null && hero.belongings.armor.glyph != null - && hero.belongings.armor.glyph instanceof Camouflage){ + if (hero.belongings.armor != null && hero.belongings.armor.hasGlyph(Camouflage.class)){ Buff.affect(hero, Camouflage.Camo.class).set(3 + hero.belongings.armor.level()); leaves += 4; } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java b/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java index 5ee19994d..75d2cfd28 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java @@ -386,11 +386,11 @@ public class WndBag extends WndTabbed { if (!active && mode == Mode.UNIDED_OR_CURSED){ if (item instanceof Weapon){ Weapon w = (Weapon) item; - enable(w.enchantment != null && w.enchantment.curse()); + enable(w.hasCurseEnchant()); } if (item instanceof Armor){ Armor a = (Armor) item; - enable(a.glyph != null && a.glyph.curse()); + enable(a.hasCurseGlyph()); } } }