From 5bf2d72a90cc5ab60f4b8da782fa5b0db6032bbd Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Mon, 8 Dec 2014 17:10:39 -0500 Subject: [PATCH] v0.2.3: implementation on timekeepers hourglass (almost done!) --- .../actors/hero/Hero.java | 8 +++ .../items/LloydsBeacon.java | 15 +++-- .../items/artifacts/TimekeepersHourglass.java | 60 ++++++++++++++++--- .../shatteredpixeldungeon/levels/Level.java | 3 +- .../levels/features/Chasm.java | 5 ++ 5 files changed, 77 insertions(+), 14 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java index aa65eec91..6c9117892 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java @@ -749,6 +749,10 @@ public class Hero extends Char { if (hunger != null && !hunger.isStarving()) { hunger.satisfy( -Hunger.STARVING / 10 ); } + + Buff buff = buff(TimekeepersHourglass.timeFreeze.class); + if (buff != null) + buff.detach(); InterlevelScene.mode = InterlevelScene.Mode.DESCEND; Game.switchScene( InterlevelScene.class ); @@ -789,6 +793,10 @@ public class Hero extends Char { hunger.satisfy( -Hunger.STARVING / 10 ); } + Buff buff = buff(TimekeepersHourglass.timeFreeze.class); + if (buff != null) + buff.detach(); + InterlevelScene.mode = InterlevelScene.Mode.ASCEND; Game.switchScene( InterlevelScene.class ); } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/LloydsBeacon.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/LloydsBeacon.java index bf1449502..ccdc59c2c 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/LloydsBeacon.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/LloydsBeacon.java @@ -17,14 +17,12 @@ */ package com.shatteredpixel.shatteredpixeldungeon.items; -import java.util.ArrayList; - -import com.watabou.noosa.Game; -import com.watabou.noosa.audio.Sample; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; +import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TimekeepersHourglass; import com.shatteredpixel.shatteredpixeldungeon.items.wands.WandOfBlink; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.scenes.InterlevelScene; @@ -32,8 +30,12 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite.Glowing; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; +import com.watabou.noosa.Game; +import com.watabou.noosa.audio.Sample; import com.watabou.utils.Bundle; +import java.util.ArrayList; + public class LloydsBeacon extends Item { private static final String TXT_PREVENTING = @@ -135,6 +137,11 @@ public class LloydsBeacon extends Item { Dungeon.level.press( returnPos, hero ); Dungeon.observe(); } else { + + Buff buff = Dungeon.hero.buff(TimekeepersHourglass.timeFreeze.class); + if (buff != null) + buff.detach(); + InterlevelScene.mode = InterlevelScene.Mode.RETURN; InterlevelScene.returnDepth = returnDepth; InterlevelScene.returnPos = returnPos; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TimekeepersHourglass.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TimekeepersHourglass.java index 5607791c8..4633e4bfc 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TimekeepersHourglass.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TimekeepersHourglass.java @@ -37,8 +37,8 @@ public class TimekeepersHourglass extends Artifact { level = 0; levelCap = 5; - charge = 5+level; - chargeCap = 5+level; + charge = 10+level*2; + chargeCap = 10+level*2; defaultAction = AC_ACTIVATE; } @@ -85,6 +85,13 @@ public class TimekeepersHourglass extends Artifact { super.execute(hero, action); } + @Override + public void activate(Char ch) { + super.activate(ch); + if (activeBuff != null) + activeBuff.attachTo(ch); + } + @Override protected ArtifactBuff passiveBuff() { return new hourglassRecharge(); @@ -92,7 +99,7 @@ public class TimekeepersHourglass extends Artifact { @Override public Item upgrade() { - chargeCap++; + chargeCap+= 2; //for artifact transmutation. while (level+1 > sandBags) @@ -115,12 +122,14 @@ public class TimekeepersHourglass extends Artifact { //needs to bundle chargecap as it is dynamic. private static final String CHARGECAP = "chargecap"; private static final String SANDBAGS = "sandbags"; + private static final String BUFF = "buff"; @Override public void storeInBundle( Bundle bundle ) { super.storeInBundle(bundle); bundle.put( CHARGECAP, chargeCap ); bundle.put( SANDBAGS, sandBags ); + bundle.put( BUFF , activeBuff ); } @Override @@ -128,13 +137,14 @@ public class TimekeepersHourglass extends Artifact { super.restoreFromBundle(bundle); chargeCap = bundle.getInt( CHARGECAP ); sandBags = bundle.getInt( SANDBAGS ); + activeBuff = (ArtifactBuff)bundle.get( BUFF ); } public class hourglassRecharge extends ArtifactBuff { @Override public boolean act() { if (charge < chargeCap) { - partialCharge += 1 / (40f - (chargeCap - charge)*3f); + partialCharge += 1 / (60f - (chargeCap - charge)*2f); if (partialCharge >= 1) { partialCharge --; @@ -160,12 +170,13 @@ public class TimekeepersHourglass extends Artifact { @Override public boolean attachTo(Char target) { - spend(charge*2); - ((Hero)target).spendAndNext(charge*2); + spend(charge); + ((Hero)target).spendAndNext(charge); + //shouldn't punish the player for going into stasis frequently Hunger hunger = target.buff(Hunger.class); if (hunger != null && !hunger.isStarving()) - hunger.satisfy(charge*2); + hunger.satisfy(charge); charge = 0; @@ -182,10 +193,15 @@ public class TimekeepersHourglass extends Artifact { detach(); return true; } + + @Override + public void detach() { + super.detach(); + Dungeon.observe(); + } } public class timeFreeze extends ArtifactBuff { - //todo: add visual effects float partialTime = 0f; @@ -194,7 +210,7 @@ public class TimekeepersHourglass extends Artifact { public boolean processTime(float time){ partialTime += time; - while (partialTime >= 1){ + while (partialTime >= 1f){ partialTime --; charge --; } @@ -234,6 +250,32 @@ public class TimekeepersHourglass extends Artifact { QuickSlot.refresh(); super.detach(); } + + private static final String PRESSES = "presses"; + private static final String PARTIALTIME = "partialtime"; + + @Override + public void storeInBundle(Bundle bundle) { + super.storeInBundle(bundle); + + int[] values = new int[presses.size()]; + for (int i = 0; i < values.length; i ++) + values[i] = presses.get(i); + bundle.put( PRESSES , values ); + + bundle.put( PARTIALTIME , partialTime ); + } + + @Override + public void restoreFromBundle(Bundle bundle) { + super.restoreFromBundle(bundle); + + int[] values = bundle.getIntArray( PRESSES ); + for (int i = 0; i < values.length; i ++) + presses.add(values[i]); + + partialTime = bundle.getFloat( PARTIALTIME ); + } } public static class sandBag extends Item { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java b/src/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java index 909f844f9..a430d77b2 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java @@ -847,7 +847,8 @@ public abstract class Level implements Bundlable { int cx = c.pos % WIDTH; int cy = c.pos / WIDTH; - boolean sighted = c.buff( Blindness.class ) == null && c.buff( Shadows.class ) == null && c.isAlive(); + boolean sighted = c.buff( Blindness.class ) == null && c.buff( Shadows.class ) == null + && c.buff( TimekeepersHourglass.timeStasis.class ) == null && c.isAlive(); if (sighted) { ShadowCaster.castShadow( cx, cy, fieldOfView, c.viewDistance ); } else { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/levels/features/Chasm.java b/src/com/shatteredpixel/shatteredpixeldungeon/levels/features/Chasm.java index bba605c9d..8ecc4da4b 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/levels/features/Chasm.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/levels/features/Chasm.java @@ -17,6 +17,7 @@ */ package com.shatteredpixel.shatteredpixeldungeon.levels.features; +import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TimekeepersHourglass; import com.watabou.noosa.Camera; import com.watabou.noosa.Game; import com.watabou.noosa.audio.Sample; @@ -67,6 +68,10 @@ public class Chasm { jumpConfirmed = false; Sample.INSTANCE.play( Assets.SND_FALLING ); + + Buff buff = Dungeon.hero.buff(TimekeepersHourglass.timeFreeze.class); + if (buff != null) + buff.detach(); if (Dungeon.hero.isAlive()) { Dungeon.hero.interrupt();