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

View File

@@ -116,8 +116,8 @@ public abstract class EquipableItem extends Item {
Sample.INSTANCE.play( Assets.Sounds.CURSED );
}
protected float time2equip( Hero hero ) {
return 1;
protected float timeToEquip( Hero hero ) {
return 1f;
}
public abstract boolean doEquip( Hero hero );
@@ -132,9 +132,9 @@ public abstract class EquipableItem extends Item {
}
if (single) {
hero.spendAndNext( time2equip( hero ) );
hero.spendAndNext( timeToEquip( hero ) );
} else {
hero.spend( time2equip( hero ) );
hero.spend( timeToEquip( hero ) );
}
slotOfUnequipped = Dungeon.quickslot.getSlot(this);

View File

@@ -41,8 +41,6 @@ import com.watabou.utils.BArray;
import com.watabou.utils.PathFinder;
abstract public class KindOfWeapon extends EquipableItem {
protected static final float TIME_TO_EQUIP = 1f;
protected String hitSound = Assets.Sounds.HIT;
protected float hitSoundPitch = 1f;
@@ -96,10 +94,24 @@ abstract public class KindOfWeapon extends EquipableItem {
public boolean isEquipped( Hero hero ) {
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
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 );
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") );
}
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){
hero.spendAndNext(-time2equip(hero));
Buff.affect(hero, Talent.SwiftEquipCooldown.class, 19f)
.secondUse = hero.pointsInTalent(Talent.SWIFT_EQUIP) == 2;
GLog.i(Messages.get(this, "swift_equip"));
} else if (hero.buff(Talent.SwiftEquipCooldown.class).hasSecondUse()) {
hero.spendAndNext(-time2equip(hero));
hero.buff(Talent.SwiftEquipCooldown.class).secondUse = false;
GLog.i(Messages.get(this, "swift_equip"));
} else {
hero.spendAndNext(TIME_TO_EQUIP);
}
} else {
hero.spendAndNext(TIME_TO_EQUIP);
isSwiftEquipping = false;
}
return true;
} else {
isSwiftEquipping = false;
collect( hero.belongings.backpack );
return false;
}
}
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);
detachAll( hero.belongings.backpack );
@@ -161,26 +177,21 @@ abstract public class KindOfWeapon extends EquipableItem {
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){
hero.spendAndNext(-time2equip(hero));
Buff.affect(hero, Talent.SwiftEquipCooldown.class, 19f)
.secondUse = hero.pointsInTalent(Talent.SWIFT_EQUIP) == 2;
GLog.i(Messages.get(this, "swift_equip"));
} else if (hero.buff(Talent.SwiftEquipCooldown.class).hasSecondUse()) {
hero.spendAndNext(-time2equip(hero));
hero.buff(Talent.SwiftEquipCooldown.class).secondUse = false;
GLog.i(Messages.get(this, "swift_equip"));
} else {
hero.spendAndNext(TIME_TO_EQUIP);
}
} else {
hero.spendAndNext(TIME_TO_EQUIP);
isSwiftEquipping = false;
}
return true;
} else {
isSwiftEquipping = false;
collect( hero.belongings.backpack );
return false;
}

View File

@@ -35,8 +35,6 @@ import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
public abstract class KindofMisc extends EquipableItem {
private static final float TIME_TO_EQUIP = 1f;
@Override
public boolean doEquip(final Hero hero) {
@@ -153,7 +151,7 @@ public abstract class KindofMisc extends EquipableItem {
GLog.n( Messages.get(this, "equip_cursed", this) );
}
hero.spendAndNext( TIME_TO_EQUIP );
hero.spendAndNext( timeToEquip(hero) );
return true;
}

View File

@@ -219,7 +219,7 @@ public class Armor extends EquipableItem {
((HeroSprite)hero.sprite).updateArmor();
activate(hero);
Talent.onItemEquipped(hero, this);
hero.spendAndNext( time2equip( hero ) );
hero.spendAndNext( timeToEquip( hero ) );
return true;
} else {
@@ -256,8 +256,8 @@ public class Armor extends EquipableItem {
}
@Override
protected float time2equip( Hero hero ) {
return 2 / hero.speed();
protected float timeToEquip(Hero hero ) {
return 2f / hero.speed();
}
@Override