From 16a3e5932b640b673a53f7d4b474258d08e0e4e2 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Wed, 15 Jun 2016 10:51:22 -0400 Subject: [PATCH] v0.4.0: refactor to ring logic --- .../actors/hero/Hero.java | 44 ++++-------------- .../actors/mobs/Mob.java | 11 +---- .../items/rings/Ring.java | 9 ++++ .../items/rings/RingOfElements.java | 4 +- .../items/rings/RingOfEvasion.java | 15 +++--- .../items/rings/RingOfForce.java | 6 +-- .../items/rings/RingOfMight.java | 46 +++++++++++++++++++ .../items/weapon/Weapon.java | 10 +--- .../items/weapon/missiles/MissileWeapon.java | 9 +--- .../shatteredpixeldungeon/levels/Level.java | 5 +- .../levels/RegularLevel.java | 6 +-- 11 files changed, 84 insertions(+), 81 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java index 35b921237..939a497f3 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java @@ -176,9 +176,7 @@ public class Hero extends Char { public int STR() { int STR = this.STR; - for (Buff buff : buffs(RingOfMight.Might.class)) { - STR += ((RingOfMight.Might)buff).level; - } + STR += RingOfMight.getBonus(this, RingOfMight.Might.class); return weakened ? STR - 2 : STR; } @@ -276,10 +274,7 @@ public class Hero extends Char { @Override public int defenseSkill( Char enemy ) { - int bonus = 0; - for (Buff buff : buffs( RingOfEvasion.Evasion.class )) { - bonus += ((RingOfEvasion.Evasion)buff).effectiveLevel; - } + int bonus = RingOfEvasion.getBonus(this, RingOfEvasion.Evasion.class); float evasion = (float)Math.pow( 1.15, bonus ); if (paralysed > 0) { @@ -318,10 +313,7 @@ public class Hero extends Char { public int damageRoll() { KindOfWeapon wep = rangedWeapon != null ? rangedWeapon : belongings.weapon; int dmg; - int bonus = 0; - for (Buff buff : buffs( RingOfForce.Force.class )) { - bonus += ((RingOfForce.Force)buff).level; - } + int bonus = RingOfForce.getBonus(this, RingOfForce.Force.class); if (wep != null) { dmg = wep.damageRoll( this ) + bonus; @@ -344,10 +336,7 @@ public class Hero extends Char { float speed = super.speed(); - int hasteLevel = 0; - for (Buff buff : buffs( RingOfHaste.Haste.class )) { - hasteLevel += ((RingOfHaste.Haste)buff).level; - } + int hasteLevel = RingOfHaste.getBonus(this, RingOfHaste.Haste.class); if (hasteLevel != 0) speed *= Math.pow(1.2, hasteLevel); @@ -419,10 +408,7 @@ public class Hero extends Char { //Normally putting furor speed on unarmed attacks would be unnecessary //But there's going to be that one guy who gets a furor+force ring combo //This is for that one guy, you shall get your fists of fury! - int bonus = 0; - for (Buff buff : buffs(RingOfFuror.Furor.class)) { - bonus += ((RingOfFuror.Furor)buff).level; - } + int bonus = RingOfFuror.getBonus(this, RingOfFuror.Furor.class); return (float)(0.25 + (1 - 0.25)*Math.pow(0.8, bonus)); } } @@ -949,10 +935,7 @@ public class Hero extends Char { dmg = thorns.proc(dmg, (src instanceof Char ? (Char)src : null), this); } - int tenacity = 0; - for (Buff buff : buffs(RingOfTenacity.Tenacity.class)) { - tenacity += ((RingOfTenacity.Tenacity)buff).level; - } + int tenacity = RingOfTenacity.getBonus(this, RingOfTenacity.Tenacity.class); if (tenacity != 0) //(HT - HP)/HT = heroes current % missing health. dmg = (int)Math.ceil((float)dmg * Math.pow(0.9, tenacity*((float)(HT - HP)/HT))); @@ -1201,11 +1184,7 @@ public class Hero extends Char { GLog.w(msg); } - if (buff instanceof RingOfMight.Might) { - if (((RingOfMight.Might) buff).level > 0) { - HT += ((RingOfMight.Might) buff).level * 5; - } - } else if (buff instanceof Paralysis || buff instanceof Vertigo) { + if (buff instanceof Paralysis || buff instanceof Vertigo) { interrupt(); } @@ -1217,14 +1196,7 @@ public class Hero extends Char { @Override public void remove( Buff buff ) { super.remove( buff ); - - if (buff instanceof RingOfMight.Might){ - if (((RingOfMight.Might)buff).level > 0){ - HT -= ((RingOfMight.Might) buff).level * 5; - HP = Math.min(HT, HP); - } - } - + BuffIndicator.refreshHero(); } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java index 7cd8ff13e..100b2340a 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java @@ -342,10 +342,7 @@ public abstract class Mob extends Char { boolean seen = enemySeen || (enemy == Dungeon.hero && Dungeon.hero.encumbered()); if (seen && paralysed == 0) { int defenseSkill = this.defenseSkill; - int penalty = 0; - for (Buff buff : enemy.buffs(RingOfAccuracy.Accuracy.class)) { - penalty += ((RingOfAccuracy.Accuracy) buff).level; - } + int penalty = RingOfAccuracy.getBonus(enemy, RingOfAccuracy.Accuracy.class); if (penalty != 0 && enemy == Dungeon.hero) defenseSkill *= Math.pow(0.75, penalty); return defenseSkill; @@ -448,11 +445,7 @@ public abstract class Mob extends Char { super.die( cause ); float lootChance = this.lootChance; - int bonus = 0; - for (Buff buff : Dungeon.hero.buffs(RingOfWealth.Wealth.class)) { - bonus += ((RingOfWealth.Wealth) buff).level; - } - + int bonus = RingOfWealth.getBonus(Dungeon.hero, RingOfWealth.Wealth.class); lootChance *= Math.pow(1.1, bonus); if (Random.Float() < lootChance && Dungeon.hero.lvl <= maxLvl + 2) { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java index 747200a00..365b781f6 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java @@ -239,6 +239,14 @@ public class Ring extends KindofMisc { } } + public static int getBonus(Char target, Class type){ + int bonus = 0; + for (RingBuff buff : target.buffs(type)) { + bonus += buff.level(); + } + return bonus; + } + public class RingBuff extends Buff { @Override @@ -270,5 +278,6 @@ public class Ring extends KindofMisc { public int level(){ return Ring.this.level(); } + } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfElements.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfElements.java index 88ecc614f..38f0faca1 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfElements.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfElements.java @@ -54,7 +54,7 @@ public class RingOfElements extends Ring { public class Resistance extends RingBuff { public HashSet> resistances() { - if (Random.Int( level + 2 ) >= 2) { + if (Random.Int( level() + 2 ) >= 2) { return FULL; } else { return EMPTY; @@ -62,7 +62,7 @@ public class RingOfElements extends Ring { } public float durationFactor() { - return level < 0 ? 1 : (1 + 0.5f * level) / (1 + level); + return level() < 0 ? 1 : (1 + 0.5f * level()) / (1 + level()); } } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfEvasion.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfEvasion.java index 4bffbbd64..580431b4e 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfEvasion.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfEvasion.java @@ -34,13 +34,11 @@ public class RingOfEvasion extends Ring { //yup, the only ring in the game with logic inside of its class public class Evasion extends RingBuff { public int effectiveLevel; - private int pos; @Override public boolean attachTo( Char target ) { - pos = target.pos; - effectiveLevel = Math.min(0, level()); + effectiveLevel = Math.min(0, RingOfEvasion.this.level()); return super.attachTo(target); } @@ -56,15 +54,20 @@ public class RingOfEvasion extends Ring { } } - if (level() < 1){ - effectiveLevel = level(); + if (RingOfEvasion.this.level() < 1){ + effectiveLevel = RingOfEvasion.this.level(); } else if (seen) { effectiveLevel = Math.max(effectiveLevel - 1, 0); } else { - effectiveLevel = Math.min(effectiveLevel + 1, level()); + effectiveLevel = Math.min(effectiveLevel + 1, RingOfEvasion.this.level()); } return super.act(); } + + @Override + public int level() { + return effectiveLevel; + } } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfForce.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfForce.java index 6215dd9d2..c86c76527 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfForce.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfForce.java @@ -21,7 +21,6 @@ package com.shatteredpixel.shatteredpixeldungeon.items.rings; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; -import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.watabou.utils.Random; @@ -38,10 +37,7 @@ public class RingOfForce extends Ring { } public static int damageRoll( Hero hero ){ - int level = 0; - for (Buff buff : hero.buffs( RingOfForce.Force.class )) { - level += ((RingOfForce.Force)buff).level; - } + int level = getBonus(hero, Force.class); float tier = tier(hero.STR()); return Random.NormalIntRange(min(level, tier), max(level, tier)); } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfMight.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfMight.java index fe4b10cdc..c20f0da4b 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfMight.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfMight.java @@ -21,8 +21,54 @@ package com.shatteredpixel.shatteredpixeldungeon.items.rings; +import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; +import com.shatteredpixel.shatteredpixeldungeon.items.Item; + public class RingOfMight extends Ring { + @Override + public boolean doEquip(Hero hero) { + if (super.doEquip(hero)){ + hero.HT += level()*5; + return true; + } else { + return false; + } + } + + @Override + public boolean doUnequip(Hero hero, boolean collect, boolean single) { + + if (super.doUnequip(hero, collect, single)){ + hero.HT -= level()*5; + hero.HP = Math.min(hero.HP, hero.HT); + return false; + } else { + return false; + } + + } + + @Override + public Item upgrade() { + if (buff != null && buff.target != null){ + buff.target.HT += 5; + } + return super.upgrade(); + } + + @Override + public void level(int value) { + if (buff != null && buff.target != null){ + buff.target.HT -= level()*5; + } + super.level(value); + if (buff != null && buff.target != null){ + buff.target.HT += level()*5; + buff.target.HP = Math.min(buff.target.HP, buff.target.HT); + } + } + @Override protected RingBuff buff( ) { return new Might(); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java index bb67b2c42..1cc7ef571 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java @@ -147,10 +147,7 @@ abstract public class Weapon extends KindOfWeapon { float ACC = this.ACC; if (this instanceof MissileWeapon) { - int bonus = 0; - for (Buff buff : hero.buffs(RingOfSharpshooting.Aim.class)) { - bonus += ((RingOfSharpshooting.Aim)buff).level; - } + int bonus = RingOfSharpshooting.getBonus(hero, RingOfSharpshooting.Aim.class); ACC *= (float)(Math.pow(1.1, bonus)); } @@ -167,10 +164,7 @@ abstract public class Weapon extends KindOfWeapon { float DLY = imbue.delayFactor(this.DLY); - int bonus = 0; - for (Buff buff : hero.buffs(RingOfFuror.Furor.class)) { - bonus += ((RingOfFuror.Furor)buff).level; - } + int bonus = RingOfFuror.getBonus(hero, RingOfFuror.Furor.class); DLY = (float)(0.25 + (DLY - 0.25)*Math.pow(0.8, bonus)); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java index 5806337aa..e2f394667 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java @@ -79,10 +79,8 @@ abstract public class MissileWeapon extends Weapon { if (!curUser.shoot( enemy, this )) { miss( cell ); } else if (!(this instanceof Boomerang)){ - int bonus = 0; - for (Buff buff : curUser.buffs(RingOfSharpshooting.Aim.class)) - bonus += ((RingOfSharpshooting.Aim)buff).level; + int bonus = RingOfSharpshooting.getBonus(curUser, RingOfSharpshooting.Aim.class); if (curUser.heroClass == HeroClass.HUNTRESS && enemy.buff(PinCushion.class) == null) bonus += 3; @@ -99,10 +97,7 @@ abstract public class MissileWeapon extends Weapon { } protected void miss( int cell ) { - int bonus = 0; - for (Buff buff : curUser.buffs(RingOfSharpshooting.Aim.class)) { - bonus += ((RingOfSharpshooting.Aim)buff).level; - } + int bonus = RingOfSharpshooting.getBonus(curUser, RingOfSharpshooting.Aim.class); //degraded ring of sharpshooting will even make missed shots break. if (Random.Float() < Math.pow(0.6, -bonus)) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java b/src/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java index 48005ed69..033f041dd 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java @@ -211,10 +211,7 @@ public abstract class Level implements Bundlable { Dungeon.limitedDrops.arcaneStyli.count++; } - int bonus = 0; - for (Buff buff : Dungeon.hero.buffs(RingOfWealth.Wealth.class)) { - bonus += ((RingOfWealth.Wealth) buff).level; - } + int bonus = RingOfWealth.getBonus(Dungeon.hero, RingOfWealth.Wealth.class); if (Random.Float() > Math.pow(0.95, bonus)){ if (Random.Int(2) == 0) addItemToSpawn( new ScrollOfMagicalInfusion() ); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java b/src/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java index 691a0ed93..a90fd8fd8 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java @@ -663,10 +663,8 @@ public abstract class RegularLevel extends Level { protected void createItems() { int nItems = 3; - int bonus = 0; - for (Buff buff : Dungeon.hero.buffs(RingOfWealth.Wealth.class)) { - bonus += ((RingOfWealth.Wealth) buff).level; - } + int bonus = RingOfWealth.getBonus(Dungeon.hero, RingOfWealth.Wealth.class); + //just incase someone gets a ridiculous ring, cap this at 80% bonus = Math.min(bonus, 10); while (Random.Float() < (0.3f + bonus*0.05f)) {