v0.2.3: implemented Unstable Spellbook upgrade logic
This commit is contained in:
parent
3043e88979
commit
7532ad91cb
|
@ -1,20 +1,30 @@
|
||||||
package com.shatteredpixel.shatteredpixeldungeon.items.artifacts;
|
package com.shatteredpixel.shatteredpixeldungeon.items.artifacts;
|
||||||
|
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Blindness;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.Generator;
|
import com.shatteredpixel.shatteredpixeldungeon.items.Generator;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll;
|
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfPsionicBlast;
|
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfPsionicBlast;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlot;
|
import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlot;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
|
||||||
|
import com.watabou.noosa.audio.Sample;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
|
import com.watabou.utils.Random;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by debenhame on 26/11/2014.
|
* Created by debenhame on 26/11/2014.
|
||||||
*/
|
*/
|
||||||
public class UnstableSpellbook extends Artifact {
|
public class UnstableSpellbook extends Artifact {
|
||||||
//TODO: add levelling logic, polish, bugfixes
|
//TODO: add display logic
|
||||||
|
|
||||||
{
|
{
|
||||||
name = "unstable spellbook";
|
name = "unstable spellbook";
|
||||||
|
@ -28,28 +38,57 @@ public class UnstableSpellbook extends Artifact {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String AC_READ = "READ";
|
public static final String AC_READ = "READ";
|
||||||
|
public static final String AC_ADD = "ADD";
|
||||||
|
|
||||||
|
private final ArrayList<String> scrolls = new ArrayList<String>();
|
||||||
|
|
||||||
|
protected String inventoryTitle = "Select a scroll";
|
||||||
|
protected WndBag.Mode mode = WndBag.Mode.SCROLL;
|
||||||
|
|
||||||
|
public UnstableSpellbook() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
Class<?>[] scrollClasses = Generator.Category.SCROLL.classes;
|
||||||
|
float[] probs = Generator.Category.SCROLL.probs;
|
||||||
|
int i = Random.chances(probs);
|
||||||
|
|
||||||
|
while (i != -1){
|
||||||
|
scrolls.add(scrollClasses[i].getSimpleName());
|
||||||
|
probs[i] = 0;
|
||||||
|
|
||||||
|
i = Random.chances(probs);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<String> actions( Hero hero ) {
|
public ArrayList<String> actions( Hero hero ) {
|
||||||
ArrayList<String> actions = super.actions( hero );
|
ArrayList<String> actions = super.actions( hero );
|
||||||
if (isEquipped( hero ) && charge > 0)
|
if (isEquipped( hero ) && charge > 0)
|
||||||
actions.add(AC_READ);
|
actions.add(AC_READ);
|
||||||
|
if (level < levelCap )
|
||||||
|
actions.add(AC_ADD);
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute( Hero hero, String action ) {
|
public void execute( Hero hero, String action ) {
|
||||||
if (action.equals( AC_READ)) {
|
if (action.equals( AC_READ)) {
|
||||||
charge --;
|
|
||||||
|
|
||||||
Scroll scroll = null;
|
if (hero.buff( Blindness.class ) != null) GLog.w("You cannot read from the book while blinded.");
|
||||||
do {
|
else {
|
||||||
scroll = (Scroll) Generator.random(Generator.Category.SCROLL);
|
charge--;
|
||||||
} while (scroll != null && scroll instanceof ScrollOfPsionicBlast);
|
|
||||||
|
|
||||||
//TODO: prevent scrolls from being IDed here, consider merging functionality with potion's ownedByFruit if possible.
|
Scroll scroll;
|
||||||
scroll.execute(hero, AC_READ);
|
do {
|
||||||
|
scroll = (Scroll) Generator.random(Generator.Category.SCROLL);
|
||||||
|
} while (scroll != null && scroll instanceof ScrollOfPsionicBlast);
|
||||||
|
|
||||||
|
scroll.ownedByBook = true;
|
||||||
|
scroll.execute(hero, AC_READ);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (action.equals( AC_ADD )) {
|
||||||
|
GameScene.selectItem(itemSelector, mode, inventoryTitle);
|
||||||
} else
|
} else
|
||||||
super.execute( hero, action );
|
super.execute( hero, action );
|
||||||
}
|
}
|
||||||
|
@ -62,6 +101,11 @@ public class UnstableSpellbook extends Artifact {
|
||||||
@Override
|
@Override
|
||||||
public Item upgrade() {
|
public Item upgrade() {
|
||||||
chargeCap = (int)((level*0.4)+1);
|
chargeCap = (int)((level*0.4)+1);
|
||||||
|
|
||||||
|
//for artifact transmutation.
|
||||||
|
if (scrolls.size() > (levelCap-level))
|
||||||
|
scrolls.remove(0);
|
||||||
|
|
||||||
return super.upgrade();
|
return super.upgrade();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,17 +116,21 @@ public class UnstableSpellbook extends Artifact {
|
||||||
|
|
||||||
//needs to bundle chargecap as it is dynamic.
|
//needs to bundle chargecap as it is dynamic.
|
||||||
private static final String CHARGECAP = "chargecap";
|
private static final String CHARGECAP = "chargecap";
|
||||||
|
private static final String SCROLLS = "scrolls";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void storeInBundle( Bundle bundle ) {
|
public void storeInBundle( Bundle bundle ) {
|
||||||
super.storeInBundle(bundle);
|
super.storeInBundle(bundle);
|
||||||
bundle.put( CHARGECAP, chargeCap );
|
bundle.put( CHARGECAP, chargeCap );
|
||||||
|
bundle.put( SCROLLS, scrolls.toArray(new String[scrolls.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void restoreFromBundle( Bundle bundle ) {
|
public void restoreFromBundle( Bundle bundle ) {
|
||||||
super.restoreFromBundle(bundle);
|
super.restoreFromBundle(bundle);
|
||||||
chargeCap = bundle.getInt( CHARGECAP );
|
chargeCap = bundle.getInt( CHARGECAP );
|
||||||
|
scrolls.clear();
|
||||||
|
Collections.addAll(scrolls, bundle.getStringArray(SCROLLS));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class bookRecharge extends ArtifactBuff{
|
public class bookRecharge extends ArtifactBuff{
|
||||||
|
@ -109,5 +157,30 @@ public class UnstableSpellbook extends Artifact {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected WndBag.Listener itemSelector = new WndBag.Listener() {
|
||||||
|
@Override
|
||||||
|
public void onSelect(Item item) {
|
||||||
|
if (item != null && item instanceof Scroll && item.isIdentified()){
|
||||||
|
String scroll = item.getClass().getSimpleName();
|
||||||
|
Hero hero = Dungeon.hero;
|
||||||
|
for (int i = 0; ( i <= 1 && i < scrolls.size() ); i++){
|
||||||
|
if (scrolls.get(i).equals(scroll)){
|
||||||
|
hero.sprite.operate( hero.pos );
|
||||||
|
hero.busy();
|
||||||
|
hero.spend( 2f );
|
||||||
|
Sample.INSTANCE.play(Assets.SND_BURNING);
|
||||||
|
|
||||||
|
scrolls.remove(i);
|
||||||
|
item.detach(hero.belongings.backpack);
|
||||||
|
|
||||||
|
upgrade();
|
||||||
|
GLog.i("You infuse the scroll's energy into the book.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item != null)
|
||||||
|
GLog.w("You are unable to add this scroll to the book.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,6 @@
|
||||||
*/
|
*/
|
||||||
package com.shatteredpixel.shatteredpixeldungeon.items.scrolls;
|
package com.shatteredpixel.shatteredpixeldungeon.items.scrolls;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.Badges;
|
import com.shatteredpixel.shatteredpixeldungeon.Badges;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Blindness;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Blindness;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
|
||||||
|
@ -29,6 +26,9 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
public abstract class Scroll extends Item {
|
public abstract class Scroll extends Item {
|
||||||
|
|
||||||
private static final String TXT_BLINDED = "You can't read a scroll while blinded";
|
private static final String TXT_BLINDED = "You can't read a scroll while blinded";
|
||||||
|
@ -70,6 +70,8 @@ public abstract class Scroll extends Item {
|
||||||
private static ItemStatusHandler<Scroll> handler;
|
private static ItemStatusHandler<Scroll> handler;
|
||||||
|
|
||||||
private String rune;
|
private String rune;
|
||||||
|
|
||||||
|
public boolean ownedByBook = false;
|
||||||
|
|
||||||
{
|
{
|
||||||
stackable = true;
|
stackable = true;
|
||||||
|
@ -134,7 +136,7 @@ public abstract class Scroll extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKnown() {
|
public void setKnown() {
|
||||||
if (!isKnown()) {
|
if (!isKnown() && !ownedByBook) {
|
||||||
handler.know( this );
|
handler.know( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.bags.SeedPouch;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.bags.WandHolster;
|
import com.shatteredpixel.shatteredpixeldungeon.items.bags.WandHolster;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.food.Food;
|
import com.shatteredpixel.shatteredpixeldungeon.items.food.Food;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
|
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.wands.Wand;
|
import com.shatteredpixel.shatteredpixeldungeon.items.wands.Wand;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MeleeWeapon;
|
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MeleeWeapon;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.Boomerang;
|
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.Boomerang;
|
||||||
|
@ -61,7 +62,8 @@ public class WndBag extends WndTabbed {
|
||||||
WAND,
|
WAND,
|
||||||
SEED,
|
SEED,
|
||||||
FOOD,
|
FOOD,
|
||||||
POTION
|
POTION,
|
||||||
|
SCROLL
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static final int COLS = 4;
|
protected static final int COLS = 4;
|
||||||
|
@ -353,6 +355,7 @@ public class WndBag extends WndTabbed {
|
||||||
mode == Mode.SEED && (item instanceof Seed) ||
|
mode == Mode.SEED && (item instanceof Seed) ||
|
||||||
mode == Mode.FOOD && (item instanceof Food) ||
|
mode == Mode.FOOD && (item instanceof Food) ||
|
||||||
mode == Mode.POTION && (item instanceof Potion) ||
|
mode == Mode.POTION && (item instanceof Potion) ||
|
||||||
|
mode == Mode.SCROLL && (item instanceof Scroll) ||
|
||||||
mode == Mode.ALL
|
mode == Mode.ALL
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user