v2.4.0: improved code relating to swift equip and equip times generally

This commit is contained in:
Evan Debenham
2024-05-03 14:27:23 -04:00
parent 27b3c9c797
commit c9a3819d5a
4 changed files with 42 additions and 33 deletions
@@ -116,8 +116,8 @@ public abstract class EquipableItem extends Item {
Sample.INSTANCE.play( Assets.Sounds.CURSED ); Sample.INSTANCE.play( Assets.Sounds.CURSED );
} }
protected float time2equip( Hero hero ) { protected float timeToEquip( Hero hero ) {
return 1; return 1f;
} }
public abstract boolean doEquip( Hero hero ); public abstract boolean doEquip( Hero hero );
@@ -132,9 +132,9 @@ public abstract class EquipableItem extends Item {
} }
if (single) { if (single) {
hero.spendAndNext( time2equip( hero ) ); hero.spendAndNext( timeToEquip( hero ) );
} else { } else {
hero.spend( time2equip( hero ) ); hero.spend( timeToEquip( hero ) );
} }
slotOfUnequipped = Dungeon.quickslot.getSlot(this); slotOfUnequipped = Dungeon.quickslot.getSlot(this);
@@ -41,8 +41,6 @@ import com.watabou.utils.BArray;
import com.watabou.utils.PathFinder; import com.watabou.utils.PathFinder;
abstract public class KindOfWeapon extends EquipableItem { abstract public class KindOfWeapon extends EquipableItem {
protected static final float TIME_TO_EQUIP = 1f;
protected String hitSound = Assets.Sounds.HIT; protected String hitSound = Assets.Sounds.HIT;
protected float hitSoundPitch = 1f; protected float hitSoundPitch = 1f;
@@ -96,10 +94,24 @@ abstract public class KindOfWeapon extends EquipableItem {
public boolean isEquipped( Hero hero ) { public boolean isEquipped( Hero hero ) {
return hero.belongings.weapon() == this || hero.belongings.secondWep() == this; return hero.belongings.weapon() == this || hero.belongings.secondWep() == this;
} }
private static boolean isSwiftEquipping = false;
protected float timeToEquip( Hero hero ) {
return isSwiftEquipping ? 0f : super.timeToEquip(hero);
}
@Override @Override
public boolean doEquip( Hero hero ) { public boolean doEquip( Hero hero ) {
boolean wasInInv = hero.belongings.contains(this);
isSwiftEquipping = false;
if (hero.belongings.contains(this) && hero.hasTalent(Talent.SWIFT_EQUIP)){
if (hero.buff(Talent.SwiftEquipCooldown.class) == null
|| hero.buff(Talent.SwiftEquipCooldown.class).hasSecondUse()){
isSwiftEquipping = true;
}
}
detachAll( hero.belongings.backpack ); detachAll( hero.belongings.backpack );
if (hero.belongings.weapon == null || hero.belongings.weapon.doUnequip( hero, true )) { if (hero.belongings.weapon == null || hero.belongings.weapon.doUnequip( hero, true )) {
@@ -117,32 +129,36 @@ abstract public class KindOfWeapon extends EquipableItem {
GLog.n( Messages.get(KindOfWeapon.class, "equip_cursed") ); GLog.n( Messages.get(KindOfWeapon.class, "equip_cursed") );
} }
if (wasInInv && hero.hasTalent(Talent.SWIFT_EQUIP)) { hero.spendAndNext( timeToEquip(hero) );
if (isSwiftEquipping) {
GLog.i(Messages.get(this, "swift_equip"));
if (hero.buff(Talent.SwiftEquipCooldown.class) == null){ if (hero.buff(Talent.SwiftEquipCooldown.class) == null){
hero.spendAndNext(-time2equip(hero));
Buff.affect(hero, Talent.SwiftEquipCooldown.class, 19f) Buff.affect(hero, Talent.SwiftEquipCooldown.class, 19f)
.secondUse = hero.pointsInTalent(Talent.SWIFT_EQUIP) == 2; .secondUse = hero.pointsInTalent(Talent.SWIFT_EQUIP) == 2;
GLog.i(Messages.get(this, "swift_equip"));
} else if (hero.buff(Talent.SwiftEquipCooldown.class).hasSecondUse()) { } else if (hero.buff(Talent.SwiftEquipCooldown.class).hasSecondUse()) {
hero.spendAndNext(-time2equip(hero));
hero.buff(Talent.SwiftEquipCooldown.class).secondUse = false; hero.buff(Talent.SwiftEquipCooldown.class).secondUse = false;
GLog.i(Messages.get(this, "swift_equip"));
} else {
hero.spendAndNext(TIME_TO_EQUIP);
} }
} else { isSwiftEquipping = false;
hero.spendAndNext(TIME_TO_EQUIP);
} }
return true; return true;
} else { } else {
isSwiftEquipping = false;
collect( hero.belongings.backpack ); collect( hero.belongings.backpack );
return false; return false;
} }
} }
public boolean equipSecondary( Hero hero ){ public boolean equipSecondary( Hero hero ){
isSwiftEquipping = false;
if (hero.belongings.contains(this) && hero.hasTalent(Talent.SWIFT_EQUIP)){
if (hero.buff(Talent.SwiftEquipCooldown.class) == null
|| hero.buff(Talent.SwiftEquipCooldown.class).hasSecondUse()){
isSwiftEquipping = true;
}
}
boolean wasInInv = hero.belongings.contains(this); boolean wasInInv = hero.belongings.contains(this);
detachAll( hero.belongings.backpack ); detachAll( hero.belongings.backpack );
@@ -161,26 +177,21 @@ abstract public class KindOfWeapon extends EquipableItem {
GLog.n( Messages.get(KindOfWeapon.class, "equip_cursed") ); GLog.n( Messages.get(KindOfWeapon.class, "equip_cursed") );
} }
if (wasInInv && hero.hasTalent(Talent.SWIFT_EQUIP)) { hero.spendAndNext( timeToEquip(hero) );
if (isSwiftEquipping) {
GLog.i(Messages.get(this, "swift_equip"));
if (hero.buff(Talent.SwiftEquipCooldown.class) == null){ if (hero.buff(Talent.SwiftEquipCooldown.class) == null){
hero.spendAndNext(-time2equip(hero));
Buff.affect(hero, Talent.SwiftEquipCooldown.class, 19f) Buff.affect(hero, Talent.SwiftEquipCooldown.class, 19f)
.secondUse = hero.pointsInTalent(Talent.SWIFT_EQUIP) == 2; .secondUse = hero.pointsInTalent(Talent.SWIFT_EQUIP) == 2;
GLog.i(Messages.get(this, "swift_equip"));
} else if (hero.buff(Talent.SwiftEquipCooldown.class).hasSecondUse()) { } else if (hero.buff(Talent.SwiftEquipCooldown.class).hasSecondUse()) {
hero.spendAndNext(-time2equip(hero));
hero.buff(Talent.SwiftEquipCooldown.class).secondUse = false; hero.buff(Talent.SwiftEquipCooldown.class).secondUse = false;
GLog.i(Messages.get(this, "swift_equip"));
} else {
hero.spendAndNext(TIME_TO_EQUIP);
} }
} else { isSwiftEquipping = false;
hero.spendAndNext(TIME_TO_EQUIP);
} }
return true; return true;
} else { } else {
isSwiftEquipping = false;
collect( hero.belongings.backpack ); collect( hero.belongings.backpack );
return false; return false;
} }
@@ -35,8 +35,6 @@ import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
public abstract class KindofMisc extends EquipableItem { public abstract class KindofMisc extends EquipableItem {
private static final float TIME_TO_EQUIP = 1f;
@Override @Override
public boolean doEquip(final Hero hero) { public boolean doEquip(final Hero hero) {
@@ -153,7 +151,7 @@ public abstract class KindofMisc extends EquipableItem {
GLog.n( Messages.get(this, "equip_cursed", this) ); GLog.n( Messages.get(this, "equip_cursed", this) );
} }
hero.spendAndNext( TIME_TO_EQUIP ); hero.spendAndNext( timeToEquip(hero) );
return true; return true;
} }
@@ -219,7 +219,7 @@ public class Armor extends EquipableItem {
((HeroSprite)hero.sprite).updateArmor(); ((HeroSprite)hero.sprite).updateArmor();
activate(hero); activate(hero);
Talent.onItemEquipped(hero, this); Talent.onItemEquipped(hero, this);
hero.spendAndNext( time2equip( hero ) ); hero.spendAndNext( timeToEquip( hero ) );
return true; return true;
} else { } else {
@@ -256,8 +256,8 @@ public class Armor extends EquipableItem {
} }
@Override @Override
protected float time2equip( Hero hero ) { protected float timeToEquip(Hero hero ) {
return 2 / hero.speed(); return 2f / hero.speed();
} }
@Override @Override