From 4d91ba2a245aca45fb20dcd5e16e2f6a31cf54f1 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Mon, 1 Jan 2018 03:47:06 -0500 Subject: [PATCH] v0.6.3: improved visibility and logic for missile weapon degradation --- .../items/weapon/missiles/Boomerang.java | 9 +- .../items/weapon/missiles/Dart.java | 7 +- .../items/weapon/missiles/Javelin.java | 5 -- .../items/weapon/missiles/MissileWeapon.java | 86 +++++++++++-------- .../items/weapon/missiles/Shuriken.java | 5 -- .../items/weapon/missiles/Tamahawk.java | 5 -- .../messages/items/items.properties | 9 +- 7 files changed, 61 insertions(+), 65 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Boomerang.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Boomerang.java index 0a01a8f86..1113c818c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Boomerang.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Boomerang.java @@ -42,8 +42,6 @@ public class Boomerang extends MissileWeapon { unique = true; bones = false; - //does not use durability - durability = -1; } @Override @@ -90,7 +88,12 @@ public class Boomerang extends MissileWeapon { return this; } - + + @Override + protected float durabilityPerUse() { + return 0; + } + @Override public void rangedHit( Char enemy ) { circleBack(enemy.pos, curUser); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Dart.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Dart.java index 6d2450e77..b8bd14e17 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Dart.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Dart.java @@ -36,8 +36,6 @@ public class Dart extends MissileWeapon { bones = false; //Finding them in bones would be semi-frequent and disappointing. - //does not use durability - durability = -1; } @Override @@ -55,6 +53,11 @@ public class Dart extends MissileWeapon { return 10; } + @Override + protected float durabilityPerUse() { + return 0; + } + @Override protected void rangedHit(Char enemy) { if (enemy.isAlive()) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Javelin.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Javelin.java index 96f3129aa..70eaa921f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Javelin.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Javelin.java @@ -64,11 +64,6 @@ public class Javelin extends MissileWeapon { return super.proc( attacker, defender, damage ); } - @Override - protected void reduceDurability() { - durability -= 10; - } - @Override public Item random() { quantity = Random.Int( 5, 15 ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java index d237e0bdb..3a1e942b5 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java @@ -30,12 +30,10 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.SnipersMark; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroClass; import com.shatteredpixel.shatteredpixeldungeon.items.Item; -import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfSharpshooting; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.enchantments.Projecting; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.watabou.utils.Bundle; -import com.watabou.utils.Random; import java.util.ArrayList; @@ -49,8 +47,11 @@ abstract public class MissileWeapon extends Weapon { usesTargeting = true; } - //weapons which don't use durability should set it to -1 - protected float durability = 100; + protected static final float MAX_DURABILITY = 100; + protected float durability = MAX_DURABILITY; + + //used to reduce durability from the source weapon stack, rather than the one being thrown. + protected MissileWeapon parent; @Override public ArrayList actions( Hero hero ) { @@ -73,6 +74,7 @@ abstract public class MissileWeapon extends Weapon { protected void onThrow( int cell ) { Char enemy = Actor.findChar( cell ); if (enemy == null || enemy == curUser) { + parent = null; super.onThrow( cell ); } else { if (!curUser.shoot( enemy, this )) { @@ -108,49 +110,50 @@ abstract public class MissileWeapon extends Weapon { return delay; } - protected void rangedHit(Char enemy ){ - reduceDurability(); + protected void rangedHit( Char enemy ){ + //if this weapon was thrown from a source stack, degrade that stack. + //unless a weapon is about to break, then break the one being thrown + if (parent != null){ + if (parent.durability <= parent.durabilityPerUse()){ + durability = 0; + parent.durability = MAX_DURABILITY; + } else { + parent.durability -= parent.durabilityPerUse(); + } + parent = null; + } else { + durability -= durabilityPerUse(); + } if (durability > 0){ - if (enemy.isAlive()) - Buff.affect(enemy, PinCushion.class).stick(this); - else - Dungeon.level.drop( this, enemy.pos).sprite.drop(); + if (enemy.isAlive()) Buff.affect(enemy, PinCushion.class).stick(this); + else Dungeon.level.drop( this, enemy.pos).sprite.drop(); } } - protected void reduceDurability(){ - //do nothing by default + protected void rangedMiss( int cell ) { + parent = null; + super.onThrow(cell); } - protected void rangedMiss(int cell ) { - 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)) - super.onThrow( cell ); - } - - @Override - public Item random() { - if (durability != -1) durability = Random.NormalIntRange(70, 100); - return this; + protected float durabilityPerUse(){ + return MAX_DURABILITY/10f; } @Override public void reset() { super.reset(); - durability = 100; + durability = MAX_DURABILITY; } @Override public Item merge(Item other) { super.merge(other); - if (isSimilar(other) && durability != -1) { + if (isSimilar(other)) { durability += ((MissileWeapon)other).durability; - durability -= 100; + durability -= MAX_DURABILITY; while (durability <= 0){ quantity -= 1; - durability += 100; + durability += MAX_DURABILITY; } } return this; @@ -160,14 +163,23 @@ abstract public class MissileWeapon extends Weapon { public Item split(int amount) { Item split = super.split(amount); - //the split item will retain lost durability - if (split != null && durability != -1){ - durability = 100; + //unless the thrown weapon will break, split off a max durability item and + //have it reduce the durability of the main stack. Cleaner to the player this way + if (split != null){ + MissileWeapon m = (MissileWeapon)split; + m.durability = MAX_DURABILITY; + m.parent = this; } return split; } + @Override + public boolean doPickUp(Hero hero) { + parent = null; + return super.doPickUp(hero); + } + @Override public boolean isUpgradable() { return false; @@ -206,13 +218,11 @@ abstract public class MissileWeapon extends Weapon { info += "\n\n" + Messages.get(this, "durability"); - //weapons which don't use durability should set it to -1, and have their own text - if (durability >= 100) info += "\n\n" + Messages.get(this, "dur_100"); - else if (durability >= 80) info += "\n\n" + Messages.get(this, "dur_80"); - else if (durability >= 60) info += "\n\n" + Messages.get(this, "dur_60"); - else if (durability >= 40) info += "\n\n" + Messages.get(this, "dur_40"); - else if (durability >= 20) info += "\n\n" + Messages.get(this, "dur_20"); - else if (durability >= 0) info += "\n\n" + Messages.get(this, "dur_0"); + if (durabilityPerUse() > 0){ + info += " " + Messages.get(this, "uses_left", + (int)Math.ceil(durability/durabilityPerUse()), + (int)Math.ceil(MAX_DURABILITY/durabilityPerUse())); + } return info; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Shuriken.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Shuriken.java index d8ee27a72..6776f22c4 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Shuriken.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Shuriken.java @@ -57,11 +57,6 @@ public class Shuriken extends MissileWeapon { quantity = number; } - @Override - protected void reduceDurability() { - durability -= 10; - } - @Override public Item random() { quantity = Random.Int( 5, 15 ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Tamahawk.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Tamahawk.java index 49e95dc5c..322880a38 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Tamahawk.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Tamahawk.java @@ -65,11 +65,6 @@ public class Tamahawk extends MissileWeapon { return super.proc( attacker, defender, damage ); } - @Override - protected void reduceDurability() { - durability -= 10; - } - @Override public Item random() { quantity = Random.Int( 5, 12 ); diff --git a/core/src/main/resources/com/shatteredpixel/shatteredpixeldungeon/messages/items/items.properties b/core/src/main/resources/com/shatteredpixel/shatteredpixeldungeon/messages/items/items.properties index 1f2c4c987..ead7c0b2a 100644 --- a/core/src/main/resources/com/shatteredpixel/shatteredpixeldungeon/messages/items/items.properties +++ b/core/src/main/resources/com/shatteredpixel/shatteredpixeldungeon/messages/items/items.properties @@ -945,13 +945,8 @@ items.weapon.missiles.javelin.desc=This length of metal is weighted to keep the items.weapon.missiles.missileweapon.stats=This missile weapon deals _%1$d-%2$d damage_ and requires _%3$d strength_ to use properly. items.weapon.missiles.missileweapon.distance=This weapon is designed to be used at a distance, it is much less accurate at melee range. -items.weapon.missiles.missileweapon.durability=Missile weapons will wear out and break as they are used. You will automatically combine parts so that only the first weapon in a stack is worn. -items.weapon.missiles.missileweapon.dur_100=The first weapon is in _perfect condition._ -items.weapon.missiles.missileweapon.dur_80=The first weapon is in _excellent condition._ -items.weapon.missiles.missileweapon.dur_60=The first weapon is in _good condition._ -items.weapon.missiles.missileweapon.dur_40=The first weapon is in _fair condition._ -items.weapon.missiles.missileweapon.dur_20=The first weapon is in _poor condition._ -items.weapon.missiles.missileweapon.dur_0=The first weapon is in _terrible condition._ +items.weapon.missiles.missileweapon.durability=Missile weapons will wear out and break as they are used. +items.weapon.missiles.missileweapon.uses_left=This stack of weapons has _%d/%d_ uses left before one breaks. items.weapon.missiles.shuriken.name=shuriken items.weapon.missiles.shuriken.desc=Star-shaped pieces of metal with razor-sharp blades do significant damage when they hit a target. They can be thrown at very high rate.