v2.0.0: cleaned up code references to equipped wep vs. attacking wep

This fixes a bug with twin upgrades and primary weapon crossbow
This commit is contained in:
Evan Debenham
2023-02-22 19:23:54 -05:00
parent 874415230c
commit 4ddd16ee33
7 changed files with 27 additions and 28 deletions
@@ -329,7 +329,7 @@ public abstract class Char extends Actor {
if (this instanceof Hero){ if (this instanceof Hero){
Hero h = (Hero)this; Hero h = (Hero)this;
if (h.belongings.weapon() instanceof MissileWeapon if (h.belongings.attackingWeapon() instanceof MissileWeapon
&& h.subClass == HeroSubClass.SNIPER && h.subClass == HeroSubClass.SNIPER
&& !Dungeon.level.adjacent(h.pos, enemy.pos)){ && !Dungeon.level.adjacent(h.pos, enemy.pos)){
dr = 0; dr = 0;
@@ -94,11 +94,14 @@ public class Belongings implements Iterable<Item> {
// we still want to access the raw equipped items in cases where effects should be ignored though, // 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 // such as when equipping something, showing an interface, or dealing with items from a dead hero
public KindOfWeapon weapon(){ //normally the primary equipped weapon, but can also be a thrown weapon or an ability's weapon
//no point in lost invent check, if it's assigned it must be usable public KindOfWeapon attackingWeapon(){
if (thrownWeapon != null) return thrownWeapon; if (thrownWeapon != null) return thrownWeapon;
if (abilityWeapon != null) return abilityWeapon; if (abilityWeapon != null) return abilityWeapon;
return weapon();
}
public KindOfWeapon weapon(){
boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null;
if (!lostInvent || (weapon != null && weapon.keptThoughLostInvent)){ if (!lostInvent || (weapon != null && weapon.keptThoughLostInvent)){
return weapon; return weapon;
@@ -401,7 +401,7 @@ public class Hero extends Char {
@Override @Override
public void hitSound(float pitch) { public void hitSound(float pitch) {
if (!RingOfForce.fightingUnarmed(this)) { if (!RingOfForce.fightingUnarmed(this)) {
belongings.weapon().hitSound(pitch); belongings.attackingWeapon().hitSound(pitch);
} else if (RingOfForce.getBuffedBonus(this, RingOfForce.Force.class) > 0) { } else if (RingOfForce.getBuffedBonus(this, RingOfForce.Force.class) > 0) {
//pitch deepens by 2.5% (additive) per point of strength, down to 75% //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) ); super.hitSound( pitch * GameMath.gate( 0.75f, 1.25f - 0.025f*STR(), 1f) );
@@ -464,7 +464,7 @@ public class Hero extends Char {
@Override @Override
public int attackSkill( Char target ) { public int attackSkill( Char target ) {
KindOfWeapon wep = belongings.weapon(); KindOfWeapon wep = belongings.attackingWeapon();
float accuracy = 1; float accuracy = 1;
accuracy *= RingOfAccuracy.accuracyMultiplier( this ); accuracy *= RingOfAccuracy.accuracyMultiplier( this );
@@ -577,7 +577,7 @@ public class Hero extends Char {
@Override @Override
public int damageRoll() { public int damageRoll() {
KindOfWeapon wep = belongings.weapon(); KindOfWeapon wep = belongings.attackingWeapon();
int dmg; int dmg;
if (!RingOfForce.fightingUnarmed(this)) { if (!RingOfForce.fightingUnarmed(this)) {
@@ -597,7 +597,7 @@ public class Hero extends Char {
} else { } else {
dmg = RingOfForce.damageRoll(this); dmg = RingOfForce.damageRoll(this);
if (RingOfForce.unarmedGetsWeaponEffects(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 @Override
public boolean canSurpriseAttack(){ public boolean canSurpriseAttack(){
if (belongings.weapon() == null || !(belongings.weapon() instanceof Weapon)) return true; KindOfWeapon w = belongings.attackingWeapon();
if (RingOfForce.fightingUnarmed(this)) return true; if (!(w instanceof Weapon)) return true;
if (STR() < ((Weapon)belongings.weapon()).STRReq()) return false; if (RingOfForce.fightingUnarmed(this)) return true;
if (belongings.weapon() instanceof Flail) return false; if (STR() < ((Weapon)w).STRReq()) return false;
if (w instanceof Flail) return false;
return super.canSurpriseAttack(); return super.canSurpriseAttack();
} }
@@ -671,7 +672,7 @@ public class Hero extends Char {
return true; return true;
} }
KindOfWeapon wep = Dungeon.hero.belongings.weapon(); KindOfWeapon wep = Dungeon.hero.belongings.attackingWeapon();
if (wep != null){ if (wep != null){
return wep.canReach(this, enemy.pos); return wep.canReach(this, enemy.pos);
@@ -694,7 +695,7 @@ public class Hero extends Char {
if (!RingOfForce.fightingUnarmed(this)) { if (!RingOfForce.fightingUnarmed(this)) {
return delay * belongings.weapon().delayFactor( this ); return delay * belongings.attackingWeapon().delayFactor( this );
} else { } else {
//Normally putting furor speed on unarmed attacks would be unnecessary //Normally putting furor speed on unarmed attacks would be unnecessary
@@ -1265,7 +1266,7 @@ public class Hero extends Char {
damage = super.attackProc( enemy, damage ); damage = super.attackProc( enemy, damage );
//procs with weapon even in brawler's stance //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 ); if (wep != null) damage = wep.proc( this, enemy, damage );
@@ -609,7 +609,7 @@ public enum Talent {
} }
if (hero.hasTalent(Talent.FOLLOWUP_STRIKE)) { if (hero.hasTalent(Talent.FOLLOWUP_STRIKE)) {
if (hero.belongings.weapon() instanceof MissileWeapon) { if (hero.belongings.attackingWeapon() instanceof MissileWeapon) {
Buff.affect(enemy, FollowupStrikeTracker.class); Buff.affect(enemy, FollowupStrikeTracker.class);
} else if (enemy.buff(FollowupStrikeTracker.class) != null){ } else if (enemy.buff(FollowupStrikeTracker.class) != null){
dmg += 1 + hero.pointsInTalent(FOLLOWUP_STRIKE); dmg += 1 + hero.pointsInTalent(FOLLOWUP_STRIKE);
@@ -638,7 +638,7 @@ public enum Talent {
} }
if (hero.hasTalent(DEADLY_FOLLOWUP)) { if (hero.hasTalent(DEADLY_FOLLOWUP)) {
if (hero.belongings.weapon() instanceof MissileWeapon) { if (hero.belongings.attackingWeapon() instanceof MissileWeapon) {
Buff.prolong(enemy, DeadlyFollowupTracker.class, 5f); Buff.prolong(enemy, DeadlyFollowupTracker.class, 5f);
} else if (enemy.buff(DeadlyFollowupTracker.class) != null){ } else if (enemy.buff(DeadlyFollowupTracker.class) != null){
dmg = Math.round(dmg * (1.0f + .08f*hero.pointsInTalent(DEADLY_FOLLOWUP))); dmg = Math.round(dmg * (1.0f + .08f*hero.pointsInTalent(DEADLY_FOLLOWUP)));
@@ -620,7 +620,7 @@ public abstract class Mob extends Char {
public int defenseProc( Char enemy, int damage ) { public int defenseProc( Char enemy, int damage ) {
if (enemy instanceof Hero if (enemy instanceof Hero
&& ((Hero) enemy).belongings.weapon() instanceof MissileWeapon){ && ((Hero) enemy).belongings.attackingWeapon() instanceof MissileWeapon){
Statistics.thrownAttacks++; Statistics.thrownAttacks++;
Badges.validateHuntressUnlock(); Badges.validateHuntressUnlock();
} }
@@ -630,8 +630,8 @@ public abstract class Mob extends Char {
Badges.validateRogueUnlock(); Badges.validateRogueUnlock();
//TODO this is somewhat messy, it would be nicer to not have to manually handle delays here //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? // playing the strong hit sound might work best as another property of weapon?
if (Dungeon.hero.belongings.weapon() instanceof SpiritBow.SpiritArrow if (Dungeon.hero.belongings.attackingWeapon() instanceof SpiritBow.SpiritArrow
|| Dungeon.hero.belongings.weapon() instanceof Dart){ || Dungeon.hero.belongings.attackingWeapon() instanceof Dart){
Sample.INSTANCE.playDelayed(Assets.Sounds.HIT_STRONG, 0.125f); Sample.INSTANCE.playDelayed(Assets.Sounds.HIT_STRONG, 0.125f);
} else { } else {
Sample.INSTANCE.play(Assets.Sounds.HIT_STRONG); Sample.INSTANCE.play(Assets.Sounds.HIT_STRONG);
@@ -195,7 +195,7 @@ public class RingOfForce extends Ring {
} }
public static boolean fightingUnarmed( Hero hero ){ public static boolean fightingUnarmed( Hero hero ){
if (hero.belongings.weapon() == null){ if (hero.belongings.attackingWeapon() == null){
return true; return true;
} }
if (hero.belongings.thrownWeapon != null || hero.belongings.abilityWeapon != null){ if (hero.belongings.thrownWeapon != null || hero.belongings.abilityWeapon != null){
@@ -216,7 +216,7 @@ public class RingOfForce extends Ring {
} }
public static boolean unarmedGetsWeaponEffects( Hero hero ){ public static boolean unarmedGetsWeaponEffects( Hero hero ){
if (hero.belongings.weapon() == null){ if (hero.belongings.attackingWeapon() == null){
return false; return false;
} }
BrawlersStance stance = hero.buff(BrawlersStance.class); BrawlersStance stance = hero.buff(BrawlersStance.class);
@@ -251,13 +251,8 @@ public class MeleeWeapon extends Weapon {
public int buffedLvl() { public int buffedLvl() {
if (!evaluatingTwinUpgrades && isEquipped(Dungeon.hero) && Dungeon.hero.hasTalent(Talent.TWIN_UPGRADES)){ if (!evaluatingTwinUpgrades && isEquipped(Dungeon.hero) && Dungeon.hero.hasTalent(Talent.TWIN_UPGRADES)){
KindOfWeapon other = null; KindOfWeapon other = null;
if (Dungeon.hero.belongings.weapon != this) other = Dungeon.hero.belongings.weapon; if (Dungeon.hero.belongings.weapon() != this) other = Dungeon.hero.belongings.weapon();
if (Dungeon.hero.belongings.secondWep != this) other = Dungeon.hero.belongings.secondWep; 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 (other instanceof MeleeWeapon) { if (other instanceof MeleeWeapon) {
evaluatingTwinUpgrades = true; evaluatingTwinUpgrades = true;