From 4ddd16ee33f077db2270ec065f45cd5a7d36949f Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Wed, 22 Feb 2023 19:23:54 -0500 Subject: [PATCH] v2.0.0: cleaned up code references to equipped wep vs. attacking wep This fixes a bug with twin upgrades and primary weapon crossbow --- .../shatteredpixeldungeon/actors/Char.java | 2 +- .../actors/hero/Belongings.java | 7 ++++-- .../actors/hero/Hero.java | 23 ++++++++++--------- .../actors/hero/Talent.java | 4 ++-- .../actors/mobs/Mob.java | 6 ++--- .../items/rings/RingOfForce.java | 4 ++-- .../items/weapon/melee/MeleeWeapon.java | 9 ++------ 7 files changed, 27 insertions(+), 28 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java index 5fb4f2657..ccf4eef8a 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java @@ -329,7 +329,7 @@ public abstract class Char extends Actor { if (this instanceof Hero){ Hero h = (Hero)this; - if (h.belongings.weapon() instanceof MissileWeapon + if (h.belongings.attackingWeapon() instanceof MissileWeapon && h.subClass == HeroSubClass.SNIPER && !Dungeon.level.adjacent(h.pos, enemy.pos)){ dr = 0; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java index b6f18e784..68c869a09 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java @@ -94,11 +94,14 @@ public class Belongings implements Iterable { // we still want to access the raw equipped items in cases where effects should be ignored though, // such as when equipping something, showing an interface, or dealing with items from a dead hero - public KindOfWeapon weapon(){ - //no point in lost invent check, if it's assigned it must be usable + //normally the primary equipped weapon, but can also be a thrown weapon or an ability's weapon + public KindOfWeapon attackingWeapon(){ if (thrownWeapon != null) return thrownWeapon; if (abilityWeapon != null) return abilityWeapon; + return weapon(); + } + public KindOfWeapon weapon(){ boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; if (!lostInvent || (weapon != null && weapon.keptThoughLostInvent)){ return weapon; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java index 89dd435d5..a8bb5a090 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java @@ -401,7 +401,7 @@ public class Hero extends Char { @Override public void hitSound(float pitch) { if (!RingOfForce.fightingUnarmed(this)) { - belongings.weapon().hitSound(pitch); + belongings.attackingWeapon().hitSound(pitch); } else if (RingOfForce.getBuffedBonus(this, RingOfForce.Force.class) > 0) { //pitch deepens by 2.5% (additive) per point of strength, down to 75% super.hitSound( pitch * GameMath.gate( 0.75f, 1.25f - 0.025f*STR(), 1f) ); @@ -464,7 +464,7 @@ public class Hero extends Char { @Override public int attackSkill( Char target ) { - KindOfWeapon wep = belongings.weapon(); + KindOfWeapon wep = belongings.attackingWeapon(); float accuracy = 1; accuracy *= RingOfAccuracy.accuracyMultiplier( this ); @@ -577,7 +577,7 @@ public class Hero extends Char { @Override public int damageRoll() { - KindOfWeapon wep = belongings.weapon(); + KindOfWeapon wep = belongings.attackingWeapon(); int dmg; if (!RingOfForce.fightingUnarmed(this)) { @@ -597,7 +597,7 @@ public class Hero extends Char { } else { dmg = RingOfForce.damageRoll(this); if (RingOfForce.unarmedGetsWeaponEffects(this)){ - dmg = ((Weapon)belongings.weapon()).augment.damageFactor(dmg); + dmg = ((Weapon)belongings.attackingWeapon()).augment.damageFactor(dmg); } } @@ -653,10 +653,11 @@ public class Hero extends Char { @Override public boolean canSurpriseAttack(){ - if (belongings.weapon() == null || !(belongings.weapon() instanceof Weapon)) return true; - if (RingOfForce.fightingUnarmed(this)) return true; - if (STR() < ((Weapon)belongings.weapon()).STRReq()) return false; - if (belongings.weapon() instanceof Flail) return false; + KindOfWeapon w = belongings.attackingWeapon(); + if (!(w instanceof Weapon)) return true; + if (RingOfForce.fightingUnarmed(this)) return true; + if (STR() < ((Weapon)w).STRReq()) return false; + if (w instanceof Flail) return false; return super.canSurpriseAttack(); } @@ -671,7 +672,7 @@ public class Hero extends Char { return true; } - KindOfWeapon wep = Dungeon.hero.belongings.weapon(); + KindOfWeapon wep = Dungeon.hero.belongings.attackingWeapon(); if (wep != null){ return wep.canReach(this, enemy.pos); @@ -694,7 +695,7 @@ public class Hero extends Char { if (!RingOfForce.fightingUnarmed(this)) { - return delay * belongings.weapon().delayFactor( this ); + return delay * belongings.attackingWeapon().delayFactor( this ); } else { //Normally putting furor speed on unarmed attacks would be unnecessary @@ -1265,7 +1266,7 @@ public class Hero extends Char { damage = super.attackProc( enemy, damage ); //procs with weapon even in brawler's stance - KindOfWeapon wep = belongings.weapon(); + KindOfWeapon wep = belongings.attackingWeapon(); if (wep != null) damage = wep.proc( this, enemy, damage ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Talent.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Talent.java index a2dfb8be8..afbbfdbe3 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Talent.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Talent.java @@ -609,7 +609,7 @@ public enum Talent { } if (hero.hasTalent(Talent.FOLLOWUP_STRIKE)) { - if (hero.belongings.weapon() instanceof MissileWeapon) { + if (hero.belongings.attackingWeapon() instanceof MissileWeapon) { Buff.affect(enemy, FollowupStrikeTracker.class); } else if (enemy.buff(FollowupStrikeTracker.class) != null){ dmg += 1 + hero.pointsInTalent(FOLLOWUP_STRIKE); @@ -638,7 +638,7 @@ public enum Talent { } if (hero.hasTalent(DEADLY_FOLLOWUP)) { - if (hero.belongings.weapon() instanceof MissileWeapon) { + if (hero.belongings.attackingWeapon() instanceof MissileWeapon) { Buff.prolong(enemy, DeadlyFollowupTracker.class, 5f); } else if (enemy.buff(DeadlyFollowupTracker.class) != null){ dmg = Math.round(dmg * (1.0f + .08f*hero.pointsInTalent(DEADLY_FOLLOWUP))); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java index cb3a53f76..debf9a110 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java @@ -620,7 +620,7 @@ public abstract class Mob extends Char { public int defenseProc( Char enemy, int damage ) { if (enemy instanceof Hero - && ((Hero) enemy).belongings.weapon() instanceof MissileWeapon){ + && ((Hero) enemy).belongings.attackingWeapon() instanceof MissileWeapon){ Statistics.thrownAttacks++; Badges.validateHuntressUnlock(); } @@ -630,8 +630,8 @@ public abstract class Mob extends Char { Badges.validateRogueUnlock(); //TODO this is somewhat messy, it would be nicer to not have to manually handle delays here // playing the strong hit sound might work best as another property of weapon? - if (Dungeon.hero.belongings.weapon() instanceof SpiritBow.SpiritArrow - || Dungeon.hero.belongings.weapon() instanceof Dart){ + if (Dungeon.hero.belongings.attackingWeapon() instanceof SpiritBow.SpiritArrow + || Dungeon.hero.belongings.attackingWeapon() instanceof Dart){ Sample.INSTANCE.playDelayed(Assets.Sounds.HIT_STRONG, 0.125f); } else { Sample.INSTANCE.play(Assets.Sounds.HIT_STRONG); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfForce.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfForce.java index 83324d038..3068f9b85 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfForce.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfForce.java @@ -195,7 +195,7 @@ public class RingOfForce extends Ring { } public static boolean fightingUnarmed( Hero hero ){ - if (hero.belongings.weapon() == null){ + if (hero.belongings.attackingWeapon() == null){ return true; } if (hero.belongings.thrownWeapon != null || hero.belongings.abilityWeapon != null){ @@ -216,7 +216,7 @@ public class RingOfForce extends Ring { } public static boolean unarmedGetsWeaponEffects( Hero hero ){ - if (hero.belongings.weapon() == null){ + if (hero.belongings.attackingWeapon() == null){ return false; } BrawlersStance stance = hero.buff(BrawlersStance.class); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/melee/MeleeWeapon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/melee/MeleeWeapon.java index f514fdff3..fdaa7c57f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/melee/MeleeWeapon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/melee/MeleeWeapon.java @@ -251,13 +251,8 @@ public class MeleeWeapon extends Weapon { public int buffedLvl() { if (!evaluatingTwinUpgrades && isEquipped(Dungeon.hero) && Dungeon.hero.hasTalent(Talent.TWIN_UPGRADES)){ KindOfWeapon other = null; - if (Dungeon.hero.belongings.weapon != this) other = Dungeon.hero.belongings.weapon; - if (Dungeon.hero.belongings.secondWep != this) other = Dungeon.hero.belongings.secondWep; - - //need to manually check for lost inventory here - if (other instanceof MeleeWeapon && Dungeon.hero.buff(LostInventory.class) != null && !other.keptThoughLostInvent){ - other = null; - } + if (Dungeon.hero.belongings.weapon() != this) other = Dungeon.hero.belongings.weapon(); + if (Dungeon.hero.belongings.secondWep() != this) other = Dungeon.hero.belongings.secondWep(); if (other instanceof MeleeWeapon) { evaluatingTwinUpgrades = true;