From e359b5f9ef4cc692111c8597ab6533ba6480381f Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Wed, 10 Dec 2014 13:58:20 -0500 Subject: [PATCH] v0.2.3: artifact refactoring, pulled some display logic into superclass --- .../items/artifacts/AlchemistsToolkit.java | 4 +- .../items/artifacts/Artifact.java | 26 ++++++++++++ .../items/artifacts/CapeOfThorns.java | 42 ++++++------------- .../items/artifacts/ChaliceOfBlood.java | 2 +- .../items/artifacts/CloakOfShadows.java | 26 ++++-------- .../items/artifacts/DriedRose.java | 3 ++ .../items/artifacts/HornOfPlenty.java | 11 ++--- .../items/artifacts/MasterThievesArmband.java | 12 +----- .../items/artifacts/SandalsOfNature.java | 12 +----- .../items/artifacts/TalismanOfForesight.java | 12 ++---- .../items/artifacts/TimekeepersHourglass.java | 13 ++---- .../items/artifacts/UnstableSpellbook.java | 13 ++---- 12 files changed, 73 insertions(+), 103 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/AlchemistsToolkit.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/AlchemistsToolkit.java index c797a6926..943b9f116 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/AlchemistsToolkit.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/AlchemistsToolkit.java @@ -28,8 +28,8 @@ public class AlchemistsToolkit extends Artifact { name = "Alchemists Toolkit"; image = ItemSpriteSheet.ARTIFACT_TOOLKIT; + level = 0; levelCap = 10; - //charge, chargecap, partialcharge, and exp are unused. } public static final String AC_BREW = "BREW"; @@ -217,7 +217,7 @@ public class AlchemistsToolkit extends Artifact { public boolean tryCook(int count){ //this logic is handled inside the class with a variable so that it may be stored. - //to prevent manipulation where a player could keep trowing in 1-2 seeds until they get lucky. + //to prevent manipulation where a player could keep throwing in 1-2 seeds until they get lucky. if (seedsToPotion == 0){ if (Random.Int(30) < 10+level){ if (Random.Int(30) < level){ diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java index 61591af78..bbce27617 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java @@ -43,6 +43,8 @@ public class Artifact extends KindofMisc { //the maximum charge, varies per artifact, not all artifacts use this. protected int chargeCap = 0; + //used by some artifacts to keep track of duration of effects or cooldowns to use. + protected int cooldown = 0; public Artifact(){ @@ -179,6 +181,30 @@ public class Artifact extends KindofMisc { } } + @Override + public String status() { + + //display the current cooldown + if (cooldown != 0) + return Utils.format( "%d", cooldown ); + + //display as percent + if (chargeCap == 100) + return Utils.format( "%d%%", charge ); + + //display as #/# + if (chargeCap > 0) + return Utils.format( "%d/%d", charge, chargeCap ); + + //if there's no cap - + //- but there is charge anyway, display that charge + if (charge != 0) + return Utils.format( "%d", charge ); + + //otherwise, if there's no charge, return null. + return null; + } + @Override public Item random() { if (Random.Float() < 0.3f) { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CapeOfThorns.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CapeOfThorns.java index 81f546725..61ddfccb9 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CapeOfThorns.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CapeOfThorns.java @@ -6,7 +6,6 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlot; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; -import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; import com.watabou.utils.Random; /** @@ -17,22 +16,15 @@ public class CapeOfThorns extends Artifact { { name = "Cape of Thorns"; image = ItemSpriteSheet.ARTIFACT_CAPE; + level = 0; levelCap = 10; + charge = 0; chargeCap = 100; + cooldown = 0; + defaultAction = "NONE"; - //partialcharge is unused - } - - private int timer = 0; - - @Override - public String status() { - if (timer == 0) - return Utils.format("%d%%", charge); - else - return Utils.format("%d", timer); } @Override @@ -47,7 +39,7 @@ public class CapeOfThorns extends Artifact { "perhaps it has some of the DM-300's power?"; if (isEquipped( Dungeon.hero )) { desc += "\n\n"; - if (timer == 0) + if (cooldown == 0) desc += "The cape feels reassuringly heavy on your shoulders. You're not sure if it will directly " + "help you in a fight, but it seems to be gaining energy from the physical damage you take."; else @@ -58,21 +50,13 @@ public class CapeOfThorns extends Artifact { return desc; } - @Override - public String toString(){ - if (level > 0) - return Utils.format("%s+%d %d%%", name, level, charge); - else - return Utils.format("%s %d%%", name, charge); - } - public class Thorns extends ArtifactBuff{ @Override public boolean act(){ - if (timer > 0) { - timer--; - if (timer == 0) { + if (cooldown > 0) { + cooldown--; + if (cooldown == 0) { BuffIndicator.refreshHero(); GLog.w("Your Cape becomes inert again."); } @@ -83,17 +67,17 @@ public class CapeOfThorns extends Artifact { } public int proc(int damage, Char attacker){ - if (timer == 0){ + if (cooldown == 0){ charge += damage*(0.5+level*0.05); if (charge >= chargeCap){ charge = 0; - timer = 10+level; + cooldown = 10+level; GLog.p("Your Cape begins radiating energy, you feel protected!"); BuffIndicator.refreshHero(); } } - if (timer != 0){ + if (cooldown != 0){ int deflected = Random.NormalIntRange(0, damage); damage -= deflected; @@ -119,7 +103,7 @@ public class CapeOfThorns extends Artifact { @Override public int icon() { - if (timer == 0) + if (cooldown == 0) return BuffIndicator.NONE; else return BuffIndicator.THORNS; @@ -127,7 +111,7 @@ public class CapeOfThorns extends Artifact { @Override public void detach(){ - timer = 0; + cooldown = 0; charge = 0; super.detach(); } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/ChaliceOfBlood.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/ChaliceOfBlood.java index 4dedc6329..74b597599 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/ChaliceOfBlood.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/ChaliceOfBlood.java @@ -34,9 +34,9 @@ public class ChaliceOfBlood extends Artifact { { name = "Chalice of Blood"; image = ItemSpriteSheet.ARTIFACT_CHALICE1; + level = 0; levelCap = 10; - //charge & chargecap are unused } public static final String AC_PRICK = "PRICK"; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CloakOfShadows.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CloakOfShadows.java index 908b6e5a4..b971c651b 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CloakOfShadows.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CloakOfShadows.java @@ -10,7 +10,6 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlot; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; -import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; import com.watabou.noosa.audio.Sample; import com.watabou.noosa.tweeners.AlphaTweener; import com.watabou.utils.Bundle; @@ -25,11 +24,17 @@ public class CloakOfShadows extends Artifact { { name = "Cloak of Shadows"; image = ItemSpriteSheet.ARTIFACT_CLOAK; + level = 0; - levelCap = 15; - charge = level+5; - chargeCap = level+5; exp = 0; + levelCap = 15; + + charge = level+5; + partialCharge = 0; + chargeCap = level+5; + + cooldown = 0; + defaultAction = AC_STEALTH; bones = false; @@ -39,11 +44,6 @@ public class CloakOfShadows extends Artifact { public static final String AC_STEALTH = "STEALTH"; - private static final String TXT_CHARGE = "%d/%d"; - private static final String TXT_CD = "%d"; - - private int cooldown = 0; - @Override public ArrayList actions( Hero hero ) { ArrayList actions = super.actions( hero ); @@ -143,14 +143,6 @@ public class CloakOfShadows extends Artifact { return desc; } - @Override - public String status() { - if (cooldown == 0) - return Utils.format(TXT_CHARGE, charge, chargeCap); - else - return Utils.format(TXT_CD, cooldown); - } - //Note: cloak needs to bundle chargecap as it is dynamic. private static final String CHARGECAP = "chargecap"; private static final String STEALTHED = "stealthed"; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/DriedRose.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/DriedRose.java index adc54af13..19b66ed0c 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/DriedRose.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/DriedRose.java @@ -30,10 +30,13 @@ public class DriedRose extends Artifact { { name = "Dried Rose"; image = ItemSpriteSheet.ARTIFACT_ROSE1; + level = 0; levelCap = 10; + charge = 100; chargeCap = 100; + defaultAction = AC_SUMMON; } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/HornOfPlenty.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/HornOfPlenty.java index 908ee94cd..c59feba1d 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/HornOfPlenty.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/HornOfPlenty.java @@ -15,7 +15,6 @@ import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfRecharging import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; -import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; import com.watabou.noosa.audio.Sample; @@ -30,9 +29,12 @@ public class HornOfPlenty extends Artifact { { name = "Horn of Plenty"; image = ItemSpriteSheet.ARTIFACT_HORN1; + level = 0; levelCap = 30; + charge = 0; + partialCharge = 0; chargeCap = 10; defaultAction = AC_EAT; @@ -48,8 +50,6 @@ public class HornOfPlenty extends Artifact { protected String inventoryTitle = "Select a piece of food"; protected WndBag.Mode mode = WndBag.Mode.FOOD; - private static final String TXT_STATUS = "%d/%d"; - @Override public ArrayList actions( Hero hero ) { ArrayList actions = super.actions( hero ); @@ -147,11 +147,6 @@ public class HornOfPlenty extends Artifact { return desc; } - @Override - public String status() { - return Utils.format(TXT_STATUS, charge, chargeCap); - } - public class hornRecharge extends ArtifactBuff{ @Override diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/MasterThievesArmband.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/MasterThievesArmband.java index 1c3fbd352..9595cae97 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/MasterThievesArmband.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/MasterThievesArmband.java @@ -2,7 +2,6 @@ package com.shatteredpixel.shatteredpixeldungeon.items.artifacts; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; -import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; import com.watabou.utils.Random; /** @@ -13,22 +12,15 @@ public class MasterThievesArmband extends Artifact { { name = "Master Thieves' Armband"; image = ItemSpriteSheet.ARTIFACT_ARMBAND; + level = 0; levelCap = 10; + charge = 0; - //partialcharge and chargeCap are unused } private int exp = 0; - @Override - public String status() { - if (charge > 0) - return Utils.format("%d", charge); - else - return null; - } - @Override protected ArtifactBuff passiveBuff() { return new Thievery(); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/SandalsOfNature.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/SandalsOfNature.java index 846a5f4b5..00d2d218a 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/SandalsOfNature.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/SandalsOfNature.java @@ -12,7 +12,6 @@ import com.shatteredpixel.shatteredpixeldungeon.plants.Plant; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; -import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; import com.watabou.noosa.Camera; import com.watabou.utils.Bundle; @@ -28,10 +27,11 @@ public class SandalsOfNature extends Artifact { { name = "Sandals of Nature"; image = ItemSpriteSheet.ARTIFACT_SANDALS; + level = 0; levelCap = 3; + charge = 0; - //partialcharge, chargeCap and exp are unused defaultAction = AC_ROOT; } @@ -76,14 +76,6 @@ public class SandalsOfNature extends Artifact { } } - @Override - public String status() { - if (charge > 0) - return Utils.format("%d", charge); - else - return null; - } - @Override protected ArtifactBuff passiveBuff() { return new Naturalism(); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TalismanOfForesight.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TalismanOfForesight.java index 4033fe566..7e73b6a1c 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TalismanOfForesight.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TalismanOfForesight.java @@ -11,7 +11,6 @@ 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 java.util.ArrayList; @@ -24,10 +23,12 @@ public class TalismanOfForesight extends Artifact { { name = "Talisman of Foresight"; image = ItemSpriteSheet.ARTIFACT_TALISMAN; + level = 0; - levelCap = 10; - charge = 0; exp = 0; + levelCap = 10; + + charge = 0; partialCharge = 0; chargeCap = 100; @@ -77,11 +78,6 @@ public class TalismanOfForesight extends Artifact { } } - @Override - public String status() { - return Utils.format("%d%%", charge); - } - @Override protected ArtifactBuff passiveBuff() { return new Foresight(); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TimekeepersHourglass.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TimekeepersHourglass.java index 4633e4bfc..ea1328cf5 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TimekeepersHourglass.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TimekeepersHourglass.java @@ -12,7 +12,6 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite; 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; @@ -32,18 +31,19 @@ public class TimekeepersHourglass extends Artifact { "..."; { - name = "timekeeper's hourglass"; + name = "Timekeeper's Hourglass"; image = ItemSpriteSheet.ARTIFACT_HOURGLASS; level = 0; levelCap = 5; + charge = 10+level*2; + partialCharge = 0; chargeCap = 10+level*2; + defaultAction = AC_ACTIVATE; } - private static final String TXT_CHARGE = "%d/%d"; - public static final String AC_ACTIVATE = "ACTIVATE"; //keeps track of generated sandbags. @@ -113,11 +113,6 @@ 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"; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/UnstableSpellbook.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/UnstableSpellbook.java index f0fbdcab0..e7bb2c812 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/UnstableSpellbook.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/UnstableSpellbook.java @@ -15,7 +15,6 @@ 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.WndBag; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Bundle; @@ -31,21 +30,22 @@ public class UnstableSpellbook extends Artifact { //TODO: add display logic { - name = "unstable spellbook"; + name = "Unstable Spellbook"; image = ItemSpriteSheet.ARTIFACT_SPELLBOOK; level = 0; levelCap = 10; + charge = ((level/2)+1); + partialCharge = 0; chargeCap = ((level/2)+1); + defaultAction = AC_READ; } public static final String AC_READ = "READ"; public static final String AC_ADD = "ADD"; - private static final String TXT_CHARGE = "%d/%d"; - private final ArrayList scrolls = new ArrayList(); protected String inventoryTitle = "Select a scroll"; @@ -160,11 +160,6 @@ public class UnstableSpellbook extends Artifact { return desc; } - @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 SCROLLS = "scrolls";