v0.3.4: moved recharging into its own class

This commit is contained in:
Evan Debenham 2015-12-28 04:08:25 -05:00 committed by Evan Debenham
parent 2c0cd939f0
commit b079aad640
9 changed files with 69 additions and 43 deletions

View File

@ -0,0 +1,54 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2015 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.actors.buffs;
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
public class Recharging extends FlavourBuff {
@Override
public int icon() {
return BuffIndicator.RECHARGING;
}
@Override
public String toString() {
return "Recharging";
}
//want to process partial turns for this buff, and not count it when it's expiring.
//firstly, if this buff has half a turn left, should give out half the benefit.
//secondly, recall that buffs execute in random order, so this can cause a problem where we can't simply check
//if this buff is still attached, must instead directly check its remaining time, and act accordingly.
//otherwise this causes inconsistent behaviour where this may detach before, or after, a wand charger acts.
public float remainder() {
return Math.min(1f, this.cooldown());
}
@Override
public String desc() {
return "Energy is coursing through you, improving the rate that your wands and staffs charge.\n" +
"\n" +
"Each turn this buff will increase current charge by one quarter, in addition to regular recharge. \n" +
"\n" +
"The recharging will last for " + dispTurns() + ".";
}
}

View File

@ -27,6 +27,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Hunger; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Hunger;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LockedFloor; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LockedFloor;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Recharging;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.effects.SpellSprite; import com.shatteredpixel.shatteredpixeldungeon.effects.SpellSprite;
@ -100,7 +101,7 @@ public class HornOfPlenty extends Artifact {
break; break;
case MAGE: case MAGE:
//1 charge //1 charge
Buff.affect( hero, ScrollOfRecharging.Recharging.class, 4f ); Buff.affect( hero, Recharging.class, 4f );
ScrollOfRecharging.charge(hero); ScrollOfRecharging.charge(hero);
break; break;
case ROGUE: case ROGUE:

View File

@ -32,6 +32,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.FireImbue;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Hunger; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Hunger;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Poison; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Poison;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Recharging;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.ToxicImbue; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.ToxicImbue;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Weakness; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Weakness;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
@ -161,7 +162,7 @@ public class Blandfruit extends Food {
break; break;
case MAGE: case MAGE:
//1 charge //1 charge
Buff.affect(hero, ScrollOfRecharging.Recharging.class, 4f); Buff.affect(hero, Recharging.class, 4f);
ScrollOfRecharging.charge(hero); ScrollOfRecharging.charge(hero);
break; break;
case ROGUE: case ROGUE:

View File

@ -25,6 +25,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.Statistics; import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Hunger; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Hunger;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Recharging;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.effects.SpellSprite; import com.shatteredpixel.shatteredpixeldungeon.effects.SpellSprite;
@ -80,7 +81,7 @@ public class Food extends Item {
break; break;
case MAGE: case MAGE:
//1 charge //1 charge
Buff.affect( hero, ScrollOfRecharging.Recharging.class, 4f ); Buff.affect( hero, Recharging.class, 4f );
ScrollOfRecharging.charge( hero ); ScrollOfRecharging.charge( hero );
break; break;
case ROGUE: case ROGUE:

View File

@ -22,6 +22,7 @@ package com.shatteredpixel.shatteredpixeldungeon.items.food;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Hunger; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Hunger;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Recharging;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfRecharging; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfRecharging;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
@ -86,7 +87,7 @@ public class Pasty extends Food {
case NONE: default: case NONE: default:
break; //do nothing extra break; //do nothing extra
case XMAS: case XMAS:
Buff.affect( hero, ScrollOfRecharging.Recharging.class, 2f ); //half of a charge Buff.affect( hero, Recharging.class, 2f ); //half of a charge
ScrollOfRecharging.charge( hero ); ScrollOfRecharging.charge( hero );
break; break;
} }

View File

@ -21,8 +21,7 @@
package com.shatteredpixel.shatteredpixeldungeon.items.scrolls; package com.shatteredpixel.shatteredpixeldungeon.items.scrolls;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.FlavourBuff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Recharging;
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility;
@ -71,36 +70,4 @@ public class ScrollOfRecharging extends Scroll {
public int price() { public int price() {
return isKnown() ? 40 * quantity : super.price(); return isKnown() ? 40 * quantity : super.price();
} }
public static class Recharging extends FlavourBuff {
@Override
public int icon() {
return BuffIndicator.RECHARGING;
}
@Override
public String toString() {
return "Recharging";
}
//want to process partial turns for this buff, and not count it when it's expiring.
//firstly, if this buff has half a turn left, should give out half the benefit.
//secondly, recall that buffs execute in random order, so this can cause a problem where we can't simply check
//if this buff is still attached, must instead directly check its remaining time, and act accordingly.
//otherwise this causes inconsistent behaviour where this may detach before, or after, a wand charger acts.
public float remainder() {
return Math.min(1f, this.cooldown());
}
@Override
public String desc() {
return "Energy is coursing through you, improving the rate that your wands and staffs charge.\n" +
"\n" +
"Each turn this buff will increase current charge by one quarter, in addition to regular recharge. \n" +
"\n" +
"The recharging will last for " + dispTurns() + ".";
}
}
} }

View File

@ -34,6 +34,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.ToxicGas;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Burning; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Burning;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Frost; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Frost;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Recharging;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mimic; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mimic;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
@ -275,7 +276,7 @@ public class CursedWand {
//shock and recharge //shock and recharge
case 3: case 3:
new LightningTrap().set( user.pos ).activate(); new LightningTrap().set( user.pos ).activate();
Buff.prolong(user, ScrollOfRecharging.Recharging.class, 20f); Buff.prolong(user, Recharging.class, 20f);
ScrollOfRecharging.charge(user); ScrollOfRecharging.charge(user);
SpellSprite.show(user, SpellSprite.CHARGE); SpellSprite.show(user, SpellSprite.CHARGE);
wand.wandUsed(); wand.wandUsed();

View File

@ -24,10 +24,10 @@ import java.util.ArrayList;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LockedFloor; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LockedFloor;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Recharging;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.SoulMark; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.SoulMark;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroClass; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroClass;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroSubClass; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroSubClass;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfRecharging;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MagesStaff; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MagesStaff;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Assets;
@ -431,7 +431,7 @@ public abstract class Wand extends Item {
if (lock == null || lock.regenOn()) if (lock == null || lock.regenOn())
partialCharge += 1f/turnsToCharge; partialCharge += 1f/turnsToCharge;
ScrollOfRecharging.Recharging bonus = target.buff(ScrollOfRecharging.Recharging.class); Recharging bonus = target.buff(Recharging.class);
if (bonus != null && bonus.remainder() > 0f){ if (bonus != null && bonus.remainder() > 0f){
partialCharge += CHARGE_BUFF_BONUS * bonus.remainder(); partialCharge += CHARGE_BUFF_BONUS * bonus.remainder();
} }

View File

@ -23,8 +23,8 @@ package com.shatteredpixel.shatteredpixeldungeon.items.wands;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Recharging;
import com.shatteredpixel.shatteredpixeldungeon.effects.SpellSprite; import com.shatteredpixel.shatteredpixeldungeon.effects.SpellSprite;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfRecharging;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MagesStaff; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MagesStaff;
import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica; import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
@ -55,7 +55,7 @@ public class WandOfMagicMissile extends Wand {
public void onHit(MagesStaff staff, Char attacker, Char defender, int damage) { public void onHit(MagesStaff staff, Char attacker, Char defender, int damage) {
//gain 1 turn of recharging buff per level of the wand. //gain 1 turn of recharging buff per level of the wand.
if (level() > 0) { if (level() > 0) {
Buff.prolong( attacker, ScrollOfRecharging.Recharging.class, (float)staff.level()); Buff.prolong( attacker, Recharging.class, (float)staff.level());
SpellSprite.show(attacker, SpellSprite.CHARGE); SpellSprite.show(attacker, SpellSprite.CHARGE);
} }
} }