From 62d5ccebbd529443c22a6f91a5d527eba3df62b5 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Mon, 25 Aug 2014 17:09:40 -0400 Subject: [PATCH] V0.2.0: Partially implemented Cloak of Shadows --- .../actors/buffs/Invisibility.java | 5 + .../items/artifacts/Artifact.java | 105 ++++++++++++- .../items/artifacts/CloakofShadows.java | 148 ++++++++++++++++++ 3 files changed, 257 insertions(+), 1 deletion(-) create mode 100644 src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CloakofShadows.java diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Invisibility.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Invisibility.java index b9938431b..084db1333 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Invisibility.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Invisibility.java @@ -19,6 +19,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.ui.BuffIndicator; public class Invisibility extends FlavourBuff { @@ -56,5 +57,9 @@ public class Invisibility extends FlavourBuff { if (buff != null && Dungeon.hero.visibleEnemies() > 0) { buff.detach(); } + CloakofShadows.cloakStealth cloakBuff = Dungeon.hero.buff( CloakofShadows.cloakStealth.class ); + if (cloakBuff != null && Dungeon.hero.visibleEnemies() > 0) { + cloakBuff.detach(); + } } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java index 5ce1eae6e..b876dcc07 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java @@ -1,13 +1,116 @@ package com.shatteredpixel.shatteredpixeldungeon.items.artifacts; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.actors.Char; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; +import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.items.KindofMisc; +import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; + +import java.util.ArrayList; /** * Created by Evan on 24/08/2014. */ -public abstract class Artifact extends KindofMisc { +public class Artifact extends KindofMisc { private static final float TIME_TO_EQUIP = 1f; + protected Buff passiveBuff; + protected Buff activeBuff; + protected int level = 0; + protected int charge = 0; + protected int chargeCap; + + + public Artifact(){ + super(); + } + + @Override + public ArrayList actions( Hero hero ) { + ArrayList actions = super.actions( hero ); + actions.add( isEquipped( hero ) ? AC_UNEQUIP : AC_EQUIP ); + return actions; + } + + @Override + public boolean doEquip( Hero hero ) { + + if (hero.belongings.misc1 != null && hero.belongings.misc2 != null) { + + GLog.w("you can only wear 2 rings at a time"); + return false; + + } else { + + if (hero.belongings.misc1 == null) { + hero.belongings.misc1 = this; + } else { + //TODO: decide if I want player to equip two of the same artifact, change logic here accordingly + hero.belongings.misc2 = this; + } + + detach( hero.belongings.backpack ); + + activate( hero ); + + hero.spendAndNext( TIME_TO_EQUIP ); + return true; + + } + + } + + public void activate( Char ch ) { + passiveBuff = passiveBuff(); + passiveBuff.attachTo(ch); + } + + @Override + public boolean doUnequip( Hero hero, boolean collect ) { + + if (hero.belongings.misc1 == this) { + hero.belongings.misc1 = null; + } else { + hero.belongings.misc2 = null; + } + + hero.remove(passiveBuff); + passiveBuff = null; + + hero.spendAndNext( TIME_TO_EQUIP ); + + if (collect && !collect( hero.belongings.backpack )) { + Dungeon.level.drop( this, hero.pos ); + } + + return true; + } + + @Override + public boolean isEquipped( Hero hero ) { + return hero.belongings.misc1 == this || hero.belongings.misc2 == this; + } + + @Override + public boolean isUpgradable() { + return false; + } + + @Override + public boolean isIdentified() { + return true; + } + + protected ArtifactBuff passiveBuff() { + return null; + } + + protected ArtifactBuff activeBuff() {return null; } + + public class ArtifactBuff extends Buff { + + } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CloakofShadows.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CloakofShadows.java new file mode 100644 index 000000000..5bbcd07c0 --- /dev/null +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CloakofShadows.java @@ -0,0 +1,148 @@ +package com.shatteredpixel.shatteredpixeldungeon.items.artifacts; + + +import com.shatteredpixel.shatteredpixeldungeon.Assets; +import com.shatteredpixel.shatteredpixeldungeon.actors.Char; +import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; +import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; +import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator; +import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; +import com.watabou.noosa.audio.Sample; + +import java.util.ArrayList; + +/** + * Created by debenhame on 25/08/2014. + */ +public class CloakofShadows extends Artifact { + //TODO: add requirements for entering stealth, add levelling mechanic, add bundle support, add polish + + { + name = "Cloak of Shadows"; + image = ItemSpriteSheet.ARTIFACT_CLOAK; + } + + private boolean stealthed = false; + + public static final String AC_STEALTH = "STEALTH"; + + private static final String TXT_STATUS = "%d/%d"; + + @Override + public ArrayList actions( Hero hero ) { + ArrayList actions = super.actions( hero ); + if (isEquipped( hero ) && charge > 0) + actions.add(AC_STEALTH); + return actions; + } + + @Override + public void execute( Hero hero, String action ) { + if (action.equals( AC_STEALTH )) { + + if (!stealthed){ + stealthed = true; + Sample.INSTANCE.play( Assets.SND_MELD ); + activeBuff = activeBuff(); + activeBuff.attachTo(hero); + } else { + stealthed = false; + hero.remove(activeBuff); + activeBuff = null; + } + + } else { + + super.execute(hero, action); + + } + } + + @Override + protected ArtifactBuff passiveBuff() { + return new cloakRecharge(); + } + + @Override + protected ArtifactBuff activeBuff( ) { + return new cloakStealth(); + } + + @Override + public String desc() { + //TODO: add description + return "Need to add a description."; + } + + @Override + public String status() { + return Utils.format(TXT_STATUS, charge, level+4); + } + + @Override + public String toString() { + return super.toString() + " (" + status() + ")" ; + } + + public class cloakRecharge extends ArtifactBuff{ + int partialCharge = 0; + @Override + public boolean act() { + if (charge < level+4) { + if (!stealthed) + partialCharge += (level + 4) / 300; + + if (partialCharge >= 100) { + charge++; + partialCharge -= 100; + } + } else + partialCharge = 0; + + spend( TICK ); + + return true; + } + + } + + public class cloakStealth extends ArtifactBuff{ + @Override + public int icon() { + return BuffIndicator.INVISIBLE; + } + + @Override + public boolean attachTo( Char target ) { + if (super.attachTo( target )) { + target.invisible++; + return true; + } else { + return false; + } + } + + @Override + public boolean act(){ + charge--; + if (charge <= 0) + detach(); + + spend( TICK ); + + return true; + } + + @Override + public String toString() { + return "Cloaked"; + } + + @Override + public void detach() { + target.invisible--; + stealthed = false; + super.detach(); + } + } +}