From 6e9cc9dd695bac86d3a14c160b4de3a925862940 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sun, 14 Sep 2014 18:38:23 -0400 Subject: [PATCH] V0.2.0: Fully implemented Talisman of Foresight --- .../actors/hero/Hero.java | 6 + .../items/artifacts/TalismanOfForesight.java | 153 +++++++++++++++++- .../ui/BuffIndicator.java | 1 + 3 files changed, 153 insertions(+), 7 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java index 364293e82..f1a74314b 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java @@ -23,6 +23,7 @@ import java.util.HashSet; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Drowsy; import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.CapeOfThorns; +import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TalismanOfForesight; import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfForce; import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfFuror; import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfSharpshooting; @@ -1292,6 +1293,8 @@ public class Hero extends Char { if (by >= Level.HEIGHT) { by = Level.HEIGHT - 1; } + + TalismanOfForesight.Foresight foresight = buff( TalismanOfForesight.Foresight.class ); for (int y = ay; y <= by; y++) { for (int x = ax, p = ax + y * Level.WIDTH; x <= bx; x++, p++) { @@ -1315,6 +1318,9 @@ public class Hero extends Char { ScrollOfMagicMapping.discover( p ); smthFound = true; + + if (foresight != null) + foresight.charge(); } } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TalismanOfForesight.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TalismanOfForesight.java index 25884ea6e..4b83ff96f 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TalismanOfForesight.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TalismanOfForesight.java @@ -1,30 +1,83 @@ package com.shatteredpixel.shatteredpixeldungeon.items.artifacts; +import com.shatteredpixel.shatteredpixeldungeon.Assets; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Awareness; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; +import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; +import com.shatteredpixel.shatteredpixeldungeon.effects.CheckedCell; +import com.shatteredpixel.shatteredpixeldungeon.effects.SpellSprite; +import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfMagicMapping; +import com.shatteredpixel.shatteredpixeldungeon.levels.Level; +import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain; +import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; +import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator; +import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; +import com.watabou.noosa.audio.Sample; +import com.watabou.utils.Random; + +import java.util.ArrayList; /** * Created by debenhame on 08/09/2014. */ public class TalismanOfForesight extends Artifact { - //TODO: actual implementation, i'm going to need to test this one as I write it. + //TODO: polish. { name = "Talisman of Foresight"; image = ItemSpriteSheet.ARTIFACT_TALISMAN; level = 0; levelCap = 10; - charge = 0; + charge = 98; exp = 0; - //partialcharge and chargeCap are unused + partialCharge = 0; + chargeCap = 100; + } + + public static final String AC_SCRY = "SCRY"; + + @Override + public ArrayList actions( Hero hero ) { + ArrayList actions = super.actions( hero ); + if (isEquipped( hero ) && charge == 100) + actions.add(AC_SCRY); + return actions; + } + + @Override + public void execute( Hero hero, String action ) { + super.execute(hero, action); + if (action.equals(AC_SCRY)){ + hero.sprite.operate( hero.pos ); + hero.busy(); + Sample.INSTANCE.play( Assets.SND_BEACON ); + charge = 0; + for (int i=0; i < Level.LENGTH; i++) { + + int terr = Dungeon.level.map[i]; + if ((Terrain.flags[terr] & Terrain.SECRET) != 0) { + + //Level.set( i, Terrain.discover( terr ) ); + GameScene.updateMap( i ); + + if (Dungeon.visible[i]) { + GameScene.discoverTile( i, terr ); + } + } + } + + Buff.affect(hero, Awareness.class, Awareness.DURATION); + Dungeon.observe(); + + } } @Override public String status() { - if (charge > 0) - return Utils.format("%d", charge); - else - return null; + return Utils.format("%d%%", charge); } @Override @@ -39,6 +92,92 @@ public class TalismanOfForesight extends Artifact { } public class Foresight extends ArtifactBuff{ + private int warn = 0; + @Override + public boolean act() { + spend( TICK ); + + boolean smthFound = false; + + int distance = 3; + + int cx = target.pos % Level.WIDTH; + int cy = target.pos / Level.WIDTH; + int ax = cx - distance; + if (ax < 0) { + ax = 0; + } + int bx = cx + distance; + if (bx >= Level.WIDTH) { + bx = Level.WIDTH - 1; + } + int ay = cy - distance; + if (ay < 0) { + ay = 0; + } + int by = cy + distance; + if (by >= Level.HEIGHT) { + by = Level.HEIGHT - 1; + } + + for (int y = ay; y <= by; y++) { + for (int x = ax, p = ax + y * Level.WIDTH; x <= bx; x++, p++) { + + if (Dungeon.visible[p] && Level.secret[p] && Dungeon.level.map[p] != Terrain.SECRET_DOOR) + smthFound = true; + } + } + + if (smthFound == true){ + if (warn == 0){ + GLog.w("You feel uneasy."); + if (target instanceof Hero){ + ((Hero)target).interrupt(); + } + } + warn = 3; + } else { + if (warn > 0){ + warn --; + } + } + BuffIndicator.refreshHero(); + + //fully charges in 2400 turns at lvl=0, scaling to 800 turns at lvl = 10. + partialCharge += (1f/24) + (((float)level)/80); + + + if (partialCharge > 1 && charge < 100){ + partialCharge--; + charge++; + } else if (charge >= 100) + partialCharge = 0; + + return true; + } + + public void charge(){ + charge = Math.min(charge+6, chargeCap); + exp++; + if (exp >= 5) { + upgrade(); + GLog.p("Your Talisman grows stronger!"); + exp -= 5; + } + } + + @Override + public String toString() { + return "Foresight"; + } + + @Override + public int icon() { + if (warn == 0) + return BuffIndicator.NONE; + else + return BuffIndicator.FORESIGHT; + } } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/BuffIndicator.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/BuffIndicator.java index adb11e43c..f8bc02af5 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/BuffIndicator.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/BuffIndicator.java @@ -65,6 +65,7 @@ public class BuffIndicator extends Component { public static final int DROWSY = 29; public static final int MAGIC_SLEEP = 30; public static final int THORNS = 31; + public static final int FORESIGHT = 32; public static final int SIZE = 7;