V0.2.0: Partially implemented Cloak of Shadows

This commit is contained in:
Evan Debenham 2014-08-25 17:09:40 -04:00
parent 43f32590df
commit 62d5ccebbd
3 changed files with 257 additions and 1 deletions

View File

@ -19,6 +19,7 @@ package com.shatteredpixel.shatteredpixeldungeon.actors.buffs;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.CloakofShadows;
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
public class Invisibility extends FlavourBuff { public class Invisibility extends FlavourBuff {
@ -56,5 +57,9 @@ public class Invisibility extends FlavourBuff {
if (buff != null && Dungeon.hero.visibleEnemies() > 0) { if (buff != null && Dungeon.hero.visibleEnemies() > 0) {
buff.detach(); buff.detach();
} }
CloakofShadows.cloakStealth cloakBuff = Dungeon.hero.buff( CloakofShadows.cloakStealth.class );
if (cloakBuff != null && Dungeon.hero.visibleEnemies() > 0) {
cloakBuff.detach();
}
} }
} }

View File

@ -1,13 +1,116 @@
package com.shatteredpixel.shatteredpixeldungeon.items.artifacts; 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.items.KindofMisc;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import java.util.ArrayList;
/** /**
* Created by Evan on 24/08/2014. * 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; 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<String> actions( Hero hero ) {
ArrayList<String> 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 {
}
} }

View File

@ -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<String> actions( Hero hero ) {
ArrayList<String> 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();
}
}
}