/* * Pixel Dungeon * Copyright (C) 2012-2015 Oleg Dolya * * Shattered Pixel Dungeon * Copyright (C) 2014-2016 Evan Debenham * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see */ package com.shatteredpixel.shatteredpixeldungeon.items.scrolls; import com.shatteredpixel.shatteredpixeldungeon.Badges; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Blindness; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.ItemStatusHandler; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.UnstableSpellbook; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.watabou.utils.Bundle; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; public abstract class Scroll extends Item { public static final String AC_READ = "READ"; protected static final float TIME_TO_READ = 1f; protected int initials; private static final Class[] scrolls = { ScrollOfIdentify.class, ScrollOfMagicMapping.class, ScrollOfRecharging.class, ScrollOfRemoveCurse.class, ScrollOfTeleportation.class, ScrollOfUpgrade.class, ScrollOfRage.class, ScrollOfTerror.class, ScrollOfLullaby.class, ScrollOfMagicalInfusion.class, ScrollOfPsionicBlast.class, ScrollOfMirrorImage.class }; private static final HashMap runes = new HashMap() { { put("KAUNAN",ItemSpriteSheet.SCROLL_KAUNAN); put("SOWILO",ItemSpriteSheet.SCROLL_SOWILO); put("LAGUZ",ItemSpriteSheet.SCROLL_LAGUZ); put("YNGVI",ItemSpriteSheet.SCROLL_YNGVI); put("GYFU",ItemSpriteSheet.SCROLL_GYFU); put("RAIDO",ItemSpriteSheet.SCROLL_RAIDO); put("ISAZ",ItemSpriteSheet.SCROLL_ISAZ); put("MANNAZ",ItemSpriteSheet.SCROLL_MANNAZ); put("NAUDIZ",ItemSpriteSheet.SCROLL_NAUDIZ); put("BERKANAN",ItemSpriteSheet.SCROLL_BERKANAN); put("ODAL",ItemSpriteSheet.SCROLL_ODAL); put("TIWAZ",ItemSpriteSheet.SCROLL_TIWAZ); } }; private static ItemStatusHandler handler; private String rune; public boolean ownedByBook = false; { stackable = true; defaultAction = AC_READ; } @SuppressWarnings("unchecked") public static void initLabels() { handler = new ItemStatusHandler<>( (Class[])scrolls, runes ); } public static void save( Bundle bundle ) { handler.save( bundle ); } @SuppressWarnings("unchecked") public static void restore( Bundle bundle ) { handler = new ItemStatusHandler<>( (Class[])scrolls, runes, bundle ); } public Scroll() { super(); reset(); } @Override public void reset(){ super.reset(); image = handler.image( this ); rune = handler.label( this ); }; @Override public ArrayList actions( Hero hero ) { ArrayList actions = super.actions( hero ); actions.add( AC_READ ); return actions; } @Override public void execute( Hero hero, String action ) { super.execute( hero, action ); if (action.equals( AC_READ )) { if (hero.buff( Blindness.class ) != null) { GLog.w( Messages.get(this, "blinded") ); } else if (hero.buff(UnstableSpellbook.bookRecharge.class) != null && hero.buff(UnstableSpellbook.bookRecharge.class).isCursed() && !(this instanceof ScrollOfRemoveCurse)) { GLog.n( Messages.get(this, "cursed") ); } else { curUser = hero; curItem = detach( hero.belongings.backpack ); doRead(); } } } abstract protected void doRead(); protected void readAnimation() { curUser.spend( TIME_TO_READ ); curUser.busy(); ((HeroSprite)curUser.sprite).read(); } public boolean isKnown() { return handler.isKnown( this ); } public void setKnown() { if (!isKnown() && !ownedByBook) { handler.know( this ); } Badges.validateAllScrollsIdentified(); } @Override public Item identify() { setKnown(); return super.identify(); } public String rune() { return Messages.get(Scroll.class, rune); } @Override public String name() { return isKnown() ? name : Messages.get(this, "unknown_name", rune()); } @Override public String info() { return isKnown() ? desc() : Messages.get(this, "unknown_desc", rune()); } public Integer initials(){ return isKnown() ? initials : null; } @Override public boolean isUpgradable() { return false; } @Override public boolean isIdentified() { return isKnown(); } public static HashSet> getKnown() { return handler.known(); } public static HashSet> getUnknown() { return handler.unknown(); } public static boolean allKnown() { return handler.known().size() == scrolls.length; } @Override public int price() { return 15 * quantity; } }