From 15c4bd66b791f67392a1f015fb030f47e0d28d1a Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 5 Dec 2014 17:11:10 -0500 Subject: [PATCH] v0.2.3: further hourglass implementation --- .../actors/hero/Hero.java | 9 +++- .../items/artifacts/TimekeepersHourglass.java | 40 ++++++++++++++++- .../shatteredpixeldungeon/levels/Level.java | 45 ++++++++++++++----- 3 files changed, 80 insertions(+), 14 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java index 0ac385cdb..2785746d3 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java @@ -898,7 +898,10 @@ public class Hero extends Char { } @Override - public void damage( int dmg, Object src ) { + public void damage( int dmg, Object src ) { + if (buff(TimekeepersHourglass.timeStasis.class) != null) + return; + restoreHealth = false; if (!(src instanceof Hunger) && damageInterrupt) @@ -1123,6 +1126,10 @@ public class Hero extends Char { @Override public void add( Buff buff ) { + //TODO: test this, may break some things + if (buff(TimekeepersHourglass.timeStasis.class) != null) + return; + super.add( buff ); if (sprite != null) { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TimekeepersHourglass.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TimekeepersHourglass.java index 4d294dea3..2d075198d 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TimekeepersHourglass.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TimekeepersHourglass.java @@ -2,6 +2,8 @@ package com.shatteredpixel.shatteredpixeldungeon.items.artifacts; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.actors.Char; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Hunger; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; @@ -148,7 +150,33 @@ public class TimekeepersHourglass extends Artifact { } public class timeStasis extends ArtifactBuff { - //todo: add logic here + //todo: add visuals, test + + + @Override + public boolean attachTo(Char target) { + spend(charge*2); + ((Hero)target).spend(charge*2); + + Hunger hunger = target.buff(Hunger.class); + if (hunger != null && !hunger.isStarving()) + hunger.satisfy(charge*2); + + charge = 0; + + target.invisible++; + + QuickSlot.refresh(); + + return super.attachTo(target); + } + + @Override + public boolean act() { + target.invisible --; + detach(); + return true; + } } public class timeFreeze extends ArtifactBuff { @@ -156,6 +184,8 @@ public class TimekeepersHourglass extends Artifact { float partialTime = 0f; + ArrayList presses = new ArrayList(); + public boolean processTime(float time){ partialTime += time; @@ -174,8 +204,16 @@ public class TimekeepersHourglass extends Artifact { } + public void delayedPress(int cell){ + if (!presses.contains(cell)) + presses.add(cell); + } + @Override public void detach(){ + for (int cell : presses) + Dungeon.level.press(cell, null); + charge = 0; QuickSlot.refresh(); super.detach(); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java b/src/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java index 3bba8d058..094ff617d 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java @@ -44,6 +44,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.Stylus; import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.AlchemistsToolkit; +import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TimekeepersHourglass; import com.shatteredpixel.shatteredpixeldungeon.items.food.Blandfruit; import com.shatteredpixel.shatteredpixeldungeon.items.food.Food; import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion; @@ -661,6 +662,13 @@ public abstract class Level implements Bundlable { Chasm.heroFall( cell ); return; } + + TimekeepersHourglass.timeFreeze timeFreeze = null; + + if (ch != null) + timeFreeze = ch.buff(TimekeepersHourglass.timeFreeze.class); + + boolean frozen = timeFreeze != null; boolean trap = false; @@ -670,56 +678,56 @@ public abstract class Level implements Bundlable { GLog.i( TXT_HIDDEN_PLATE_CLICKS ); case Terrain.TOXIC_TRAP: trap = true; - ToxicTrap.trigger( cell, ch ); + if (!frozen) ToxicTrap.trigger( cell, ch ); break; case Terrain.SECRET_FIRE_TRAP: GLog.i( TXT_HIDDEN_PLATE_CLICKS ); case Terrain.FIRE_TRAP: trap = true; - FireTrap.trigger( cell, ch ); + if (!frozen) FireTrap.trigger( cell, ch ); break; case Terrain.SECRET_PARALYTIC_TRAP: GLog.i( TXT_HIDDEN_PLATE_CLICKS ); case Terrain.PARALYTIC_TRAP: trap = true; - ParalyticTrap.trigger( cell, ch ); + if (!frozen) ParalyticTrap.trigger( cell, ch ); break; case Terrain.SECRET_POISON_TRAP: GLog.i( TXT_HIDDEN_PLATE_CLICKS ); case Terrain.POISON_TRAP: trap = true; - PoisonTrap.trigger( cell, ch ); + if (!frozen) PoisonTrap.trigger( cell, ch ); break; case Terrain.SECRET_ALARM_TRAP: GLog.i( TXT_HIDDEN_PLATE_CLICKS ); case Terrain.ALARM_TRAP: trap = true; - AlarmTrap.trigger( cell, ch ); + if (!frozen) AlarmTrap.trigger( cell, ch ); break; case Terrain.SECRET_LIGHTNING_TRAP: GLog.i( TXT_HIDDEN_PLATE_CLICKS ); case Terrain.LIGHTNING_TRAP: trap = true; - LightningTrap.trigger( cell, ch ); + if (!frozen) LightningTrap.trigger( cell, ch ); break; case Terrain.SECRET_GRIPPING_TRAP: GLog.i( TXT_HIDDEN_PLATE_CLICKS ); case Terrain.GRIPPING_TRAP: trap = true; - GrippingTrap.trigger( cell, ch ); + if (!frozen) GrippingTrap.trigger( cell, ch ); break; case Terrain.SECRET_SUMMONING_TRAP: GLog.i( TXT_HIDDEN_PLATE_CLICKS ); case Terrain.SUMMONING_TRAP: trap = true; - SummoningTrap.trigger( cell, ch ); + if (!frozen) SummoningTrap.trigger( cell, ch ); break; case Terrain.HIGH_GRASS: @@ -741,13 +749,26 @@ public abstract class Level implements Bundlable { break; } - if (trap) { - Sample.INSTANCE.play( Assets.SND_TRAP ); - if (ch == Dungeon.hero) { + if (trap && !frozen) { + + if (Dungeon.visible[cell]) + Sample.INSTANCE.play( Assets.SND_TRAP ); + + if (ch == Dungeon.hero) Dungeon.hero.interrupt(); - } + set( cell, Terrain.INACTIVE_TRAP ); GameScene.updateMap( cell ); + + } else if (trap && frozen){ + + Sample.INSTANCE.play( Assets.SND_TRAP ); + + Level.set( cell, Terrain.discover( map[cell] ) ); + GameScene.updateMap( cell ); + + timeFreeze.delayedPress(cell); + } Plant plant = plants.get( cell );