From 3d55729861bfb7c0043f2fc09e64ead44df7d71c Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 5 Dec 2014 03:25:58 -0500 Subject: [PATCH] v0.2.3: more implementation on hourglass --- .../actors/buffs/Invisibility.java | 6 ++ .../actors/hero/Hero.java | 5 +- .../items/artifacts/TimekeepersHourglass.java | 66 ++++++++++++++++++- 3 files changed, 74 insertions(+), 3 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Invisibility.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Invisibility.java index 86b95e842..dd5ae4683 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Invisibility.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Invisibility.java @@ -20,6 +20,7 @@ package com.shatteredpixel.shatteredpixeldungeon.actors.buffs; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.CloakOfShadows; +import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TimekeepersHourglass; import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator; public class Invisibility extends FlavourBuff { @@ -63,5 +64,10 @@ public class Invisibility extends FlavourBuff { cloakBuff.act(); cloakBuff.detach(); } + //this isn't a form of invisibilty, but it is meant to dispel at the same time as it. + TimekeepersHourglass.timeFreeze timeFreeze = Dungeon.hero.buff( TimekeepersHourglass.timeFreeze.class ); + if (timeFreeze != null && Dungeon.hero.visibleEnemies() > 0) { + timeFreeze.detach(); + } } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java index c629ce015..0ac385cdb 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java @@ -254,6 +254,7 @@ public class Hero extends Char { rangedWeapon = wep; boolean result = attack( enemy ); + Invisibility.dispel(); rangedWeapon = null; return result; @@ -378,7 +379,9 @@ public class Hero extends Char { @Override public void spend( float time ) { - super.spend( time ); + TimekeepersHourglass.timeFreeze buff = buff(TimekeepersHourglass.timeFreeze.class); + if (!(buff != null && buff.processTime(time))) + super.spend( time ); }; public void spendAndNext( float time ) { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TimekeepersHourglass.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TimekeepersHourglass.java index 0ac2f73f0..4d294dea3 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TimekeepersHourglass.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TimekeepersHourglass.java @@ -1,11 +1,15 @@ package com.shatteredpixel.shatteredpixeldungeon.items.artifacts; import com.shatteredpixel.shatteredpixeldungeon.Assets; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.items.Item; +import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlot; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; +import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; +import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Bundle; @@ -17,6 +21,12 @@ import java.util.ArrayList; public class TimekeepersHourglass extends Artifact { //TODO: string, effect implementation. + private static final String TXT_HGLASS = "Timekeeper's Hourglass"; + private static final String TXT_STASIS = "Put myself in stasis"; + private static final String TXT_FREEZE = "Freeze time around me"; + private static final String TXT_DESC = + "..."; + { name = "timekeeper's hourglass"; image = ItemSpriteSheet.ARTIFACT_HOURGLASS; @@ -28,6 +38,8 @@ public class TimekeepersHourglass extends Artifact { defaultAction = AC_ACTIVATE; } + private static final String TXT_CHARGE = "%d/%d"; + public static final String AC_ACTIVATE = "ACTIVATE"; //keeps track of generated sandbags. @@ -44,7 +56,24 @@ public class TimekeepersHourglass extends Artifact { @Override public void execute( Hero hero, String action ) { if (action.equals(AC_ACTIVATE)){ - //todo: add logic here + GameScene.show( + new WndOptions(TXT_HGLASS, TXT_STASIS, TXT_FREEZE, TXT_DESC) { + @Override + protected void onSelect(int index) { + if (index == 0){ + GLog.i("WIP"); + } else if (index == 1){ + GLog.i("everything around you slows to a halt."); + GameScene.flash( 0xFFFFFF ); + Sample.INSTANCE.play( Assets.SND_BLAST ); + + activeBuff = new timeFreeze(); + activeBuff.attachTo(Dungeon.hero); + } + + }; + } + ); } else super.execute(hero, action); } @@ -70,6 +99,12 @@ public class TimekeepersHourglass extends Artifact { return ""; } + @Override + public String status() { + return Utils.format(TXT_CHARGE, charge, chargeCap); + } + + //needs to bundle chargecap as it is dynamic. private static final String CHARGECAP = "chargecap"; private static final String SANDBAGS = "sandbags"; @@ -117,7 +152,34 @@ public class TimekeepersHourglass extends Artifact { } public class timeFreeze extends ArtifactBuff { - //todo: add logic here + //todo: add visual effects + + float partialTime = 0f; + + public boolean processTime(float time){ + partialTime += time; + + while (partialTime >= 1){ + partialTime --; + charge --; + } + + QuickSlot.refresh(); + + if (charge <= 0){ + detach(); + return false; + } else + return true; + + } + + @Override + public void detach(){ + charge = 0; + QuickSlot.refresh(); + super.detach(); + } } public static class sandBag extends Item {