From 66d40e3acec08259dc41e8e21fa23e7cde569bd5 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Tue, 24 Jul 2018 23:09:33 -0400 Subject: [PATCH] v0.7.0: implemented scroll of passage and refined scroll of enchantment note that enchant probability have been adjusted slightly --- .../items/armor/Armor.java | 60 ++++++++++++------ .../items/scrolls/exotic/ExoticScroll.java | 8 +-- .../scrolls/exotic/ScrollOfEnchantment.java | 48 ++++++++------ .../items/scrolls/exotic/ScrollOfPassage.java | 59 ++++++++++++++++++ .../items/weapon/Weapon.java | 62 +++++++++++++------ .../messages/items/items.properties | 10 ++- 6 files changed, 185 insertions(+), 62 deletions(-) create mode 100644 core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/exotic/ScrollOfPassage.java diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java index c91d9357b..6a3f216ce 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java @@ -67,6 +67,7 @@ import com.watabou.utils.Bundle; import com.watabou.utils.Random; import java.util.ArrayList; +import java.util.Arrays; public class Armor extends EquipableItem { @@ -498,10 +499,7 @@ public class Armor extends EquipableItem { public Armor inscribe() { Class oldGlyphClass = glyph != null ? glyph.getClass() : null; - Glyph gl = Glyph.random(); - while (gl.getClass() == oldGlyphClass) { - gl = Armor.Glyph.random(); - } + Glyph gl = Glyph.random( oldGlyphClass ); return inscribe( gl ); } @@ -543,9 +541,9 @@ public class Armor extends EquipableItem { Affection.class, AntiMagic.class, Thorns.class }; private static final float[] typeChances = new float[]{ - 40, //10 each - 30, // 5 each - 6 // 2 each + 50, //12.5% each + 40, //6.67% each + 10 //3.33% each }; private static final Class[] curses = new Class[]{ @@ -585,21 +583,27 @@ public class Armor extends EquipableItem { public abstract ItemSprite.Glowing glowing(); @SuppressWarnings("unchecked") - public static Glyph random() { + public static Glyph random( Class ... toIgnore ) { switch(Random.chances(typeChances)){ case 0: default: - return randomCommon(); + return randomCommon( toIgnore ); case 1: - return randomUncommon(); + return randomUncommon( toIgnore ); case 2: - return randomRare(); + return randomRare( toIgnore ); } } @SuppressWarnings("unchecked") - public static Glyph randomCommon(){ + public static Glyph randomCommon( Class ... toIgnore ){ try { - return ((Class)Random.oneOf(common)).newInstance(); + ArrayList> glyphs = new ArrayList<>(Arrays.asList(common)); + glyphs.removeAll(Arrays.asList(toIgnore)); + if (glyphs.isEmpty()) { + return random(); + } else { + return (Glyph) Random.element(glyphs).newInstance(); + } } catch (Exception e) { ShatteredPixelDungeon.reportException(e); return null; @@ -607,9 +611,15 @@ public class Armor extends EquipableItem { } @SuppressWarnings("unchecked") - public static Glyph randomUncommon(){ + public static Glyph randomUncommon( Class ... toIgnore ){ try { - return ((Class)Random.oneOf(uncommon)).newInstance(); + ArrayList> glyphs = new ArrayList<>(Arrays.asList(uncommon)); + glyphs.removeAll(Arrays.asList(toIgnore)); + if (glyphs.isEmpty()) { + return random(); + } else { + return (Glyph) Random.element(glyphs).newInstance(); + } } catch (Exception e) { ShatteredPixelDungeon.reportException(e); return null; @@ -617,9 +627,15 @@ public class Armor extends EquipableItem { } @SuppressWarnings("unchecked") - public static Glyph randomRare(){ + public static Glyph randomRare( Class ... toIgnore ){ try { - return ((Class)Random.oneOf(rare)).newInstance(); + ArrayList> glyphs = new ArrayList<>(Arrays.asList(rare)); + glyphs.removeAll(Arrays.asList(toIgnore)); + if (glyphs.isEmpty()) { + return random(); + } else { + return (Glyph) Random.element(glyphs).newInstance(); + } } catch (Exception e) { ShatteredPixelDungeon.reportException(e); return null; @@ -627,9 +643,15 @@ public class Armor extends EquipableItem { } @SuppressWarnings("unchecked") - public static Glyph randomCurse(){ + public static Glyph randomCurse( Class ... toIgnore ){ try { - return ((Class)Random.oneOf(curses)).newInstance(); + ArrayList> glyphs = new ArrayList<>(Arrays.asList(curses)); + glyphs.removeAll(Arrays.asList(toIgnore)); + if (glyphs.isEmpty()) { + return random(); + } else { + return (Glyph) Random.element(glyphs).newInstance(); + } } catch (Exception e) { ShatteredPixelDungeon.reportException(e); return null; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/exotic/ExoticScroll.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/exotic/ExoticScroll.java index 81556092e..7176cb48f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/exotic/ExoticScroll.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/exotic/ExoticScroll.java @@ -78,14 +78,14 @@ public abstract class ExoticScroll extends Scroll { regToExo.put(ScrollOfMagicMapping.class, ScrollOfForesight.class); exoToReg.put(ScrollOfForesight.class, ScrollOfMagicMapping.class); - //TODO - - regToExo.put(ScrollOfTeleportation.class, ScrollOfPetrification.class); - exoToReg.put(ScrollOfPetrification.class, ScrollOfTeleportation.class); + regToExo.put(ScrollOfTeleportation.class, ScrollOfPassage.class); + exoToReg.put(ScrollOfPassage.class, ScrollOfTeleportation.class); regToExo.put(ScrollOfRetribution.class, ScrollOfPsionicBlast.class); exoToReg.put(ScrollOfPsionicBlast.class, ScrollOfRetribution.class); + //TODO + regToExo.put(ScrollOfMirrorImage.class, ScrollOfPetrification.class); exoToReg.put(ScrollOfPetrification.class, ScrollOfMirrorImage.class); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/exotic/ScrollOfEnchantment.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/exotic/ScrollOfEnchantment.java index b75e96c51..d01e5ae40 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/exotic/ScrollOfEnchantment.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/exotic/ScrollOfEnchantment.java @@ -21,13 +21,17 @@ package com.shatteredpixel.shatteredpixeldungeon.items.scrolls.exotic; +import com.shatteredpixel.shatteredpixeldungeon.Assets; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility; import com.shatteredpixel.shatteredpixeldungeon.effects.Enchanting; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon; +import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions; +import com.watabou.noosa.audio.Sample; public class ScrollOfEnchantment extends ExoticScroll { @@ -39,10 +43,12 @@ public class ScrollOfEnchantment extends ExoticScroll { public void doRead() { setKnown(); - GameScene.selectItem( itemSelector, WndBag.Mode.ENCHANTABLE, "TODO" ); + curItem = this; + + GameScene.selectItem( itemSelector, WndBag.Mode.ENCHANTABLE, Messages.get(this, "inv_title")); } - protected static WndBag.Listener itemSelector = new WndBag.Listener() { + protected WndBag.Listener itemSelector = new WndBag.Listener() { @Override public void onSelect(final Item item) { @@ -50,24 +56,27 @@ public class ScrollOfEnchantment extends ExoticScroll { final Weapon.Enchantment enchants[] = new Weapon.Enchantment[3]; - enchants[0] = Weapon.Enchantment.randomCommon(); - enchants[1] = Weapon.Enchantment.randomUncommon(); - do { - enchants[2] = Weapon.Enchantment.random(); - } while (enchants[2].getClass() == enchants[0].getClass() || - enchants[1].getClass() == enchants[0].getClass()); + Class existing = ((Weapon) item).enchantment != null ? ((Weapon) item).enchantment.getClass() : null; + enchants[0] = Weapon.Enchantment.randomCommon( existing ); + enchants[1] = Weapon.Enchantment.randomUncommon( existing ); + enchants[2] = Weapon.Enchantment.random( existing, enchants[0].getClass(), enchants[1].getClass()); - GameScene.show(new WndOptions("title", "body", + GameScene.show(new WndOptions(Messages.titleCase(ScrollOfEnchantment.this.name()), + Messages.get(ScrollOfEnchantment.class, "weapon"), enchants[0].name(), enchants[1].name(), enchants[2].name(), - "cancel"){ + Messages.get(ScrollOfEnchantment.class, "cancel")){ @Override protected void onSelect(int index) { if (index < 3) { ((Weapon) item).enchant(enchants[index]); //TODO text + ((ScrollOfEnchantment)curItem).readAnimation(); + + Sample.INSTANCE.play( Assets.SND_READ ); + Invisibility.dispel(); Enchanting.show(curUser, item); } } @@ -77,24 +86,27 @@ public class ScrollOfEnchantment extends ExoticScroll { final Armor.Glyph glyphs[] = new Armor.Glyph[3]; - glyphs[0] = Armor.Glyph.randomCommon(); - glyphs[1] = Armor.Glyph.randomUncommon(); - do { - glyphs[2] = Armor.Glyph.random(); - } while (glyphs[2].getClass() == glyphs[0].getClass() || - glyphs[1].getClass() == glyphs[0].getClass()); + Class existing = ((Armor) item).glyph != null ? ((Armor) item).glyph.getClass() : null; + glyphs[0] = Armor.Glyph.randomCommon( existing ); + glyphs[1] = Armor.Glyph.randomUncommon( existing ); + glyphs[2] = Armor.Glyph.random( existing, glyphs[0].getClass(), glyphs[1].getClass()); - GameScene.show(new WndOptions("title", "body", + GameScene.show(new WndOptions(Messages.titleCase(ScrollOfEnchantment.this.name()), + Messages.get(ScrollOfEnchantment.class, "armor"), glyphs[0].name(), glyphs[1].name(), glyphs[2].name(), - "cancel"){ + Messages.get(ScrollOfEnchantment.class, "cancel")){ @Override protected void onSelect(int index) { if (index < 3) { ((Armor) item).inscribe(glyphs[index]); //TODO text + ((ScrollOfEnchantment)curItem).readAnimation(); + + Sample.INSTANCE.play( Assets.SND_READ ); + Invisibility.dispel(); Enchanting.show(curUser, item); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/exotic/ScrollOfPassage.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/exotic/ScrollOfPassage.java new file mode 100644 index 000000000..47ef94aed --- /dev/null +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/exotic/ScrollOfPassage.java @@ -0,0 +1,59 @@ +/* + * Pixel Dungeon + * Copyright (C) 2012-2015 Oleg Dolya + * + * Shattered Pixel Dungeon + * Copyright (C) 2014-2018 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.exotic; + +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; +import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TimekeepersHourglass; +import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTeleportation; +import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; +import com.shatteredpixel.shatteredpixeldungeon.scenes.InterlevelScene; +import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; +import com.watabou.noosa.Game; + +public class ScrollOfPassage extends ExoticScroll { + + { + initials = 8; + } + + @Override + public void doRead() { + + setKnown(); + + if (Dungeon.bossLevel()) { + + GLog.w( Messages.get(ScrollOfTeleportation.class, "no_tele") ); + return; + + } + + Buff buff = Dungeon.hero.buff(TimekeepersHourglass.timeFreeze.class); + if (buff != null) buff.detach(); + + InterlevelScene.mode = InterlevelScene.Mode.RETURN; + InterlevelScene.returnDepth = Math.max(1, (Dungeon.depth - 1 - (Dungeon.depth-2)%5)); + InterlevelScene.returnPos = -1; + Game.switchScene( InterlevelScene.class ); + } +} diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java index 7d805c931..2bced42cd 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java @@ -58,6 +58,9 @@ import com.watabou.utils.Bundlable; import com.watabou.utils.Bundle; import com.watabou.utils.Random; +import java.util.ArrayList; +import java.util.Arrays; + abstract public class Weapon extends KindOfWeapon { private static final int HITS_TO_KNOW = 20; @@ -242,10 +245,7 @@ abstract public class Weapon extends KindOfWeapon { public Weapon enchant() { Class oldEnchantment = enchantment != null ? enchantment.getClass() : null; - Enchantment ench = Enchantment.random(); - while (ench.getClass() == oldEnchantment) { - ench = Enchantment.random(); - } + Enchantment ench = Enchantment.random( oldEnchantment ); return enchant( ench ); } @@ -281,9 +281,9 @@ abstract public class Weapon extends KindOfWeapon { Grim.class, Stunning.class, Vampiric.class}; private static final float[] typeChances = new float[]{ - 40, //10 each - 30, // 5 each - 6 // 2 each + 50, //12.5% each + 40, //6.67% each + 10 //3.33% each }; private static final Class[] curses = new Class[]{ @@ -324,21 +324,27 @@ abstract public class Weapon extends KindOfWeapon { public abstract ItemSprite.Glowing glowing(); @SuppressWarnings("unchecked") - public static Enchantment random() { + public static Enchantment random( Class ... toIgnore ) { switch(Random.chances(typeChances)){ case 0: default: - return randomCommon(); + return randomCommon( toIgnore ); case 1: - return randomUncommon(); + return randomUncommon( toIgnore ); case 2: - return randomRare(); + return randomRare( toIgnore ); } } @SuppressWarnings("unchecked") - public static Enchantment randomCommon() { + public static Enchantment randomCommon( Class ... toIgnore ) { try { - return ((Class)Random.oneOf(common)).newInstance(); + ArrayList> enchants = new ArrayList<>(Arrays.asList(common)); + enchants.removeAll(Arrays.asList(toIgnore)); + if (enchants.isEmpty()) { + return random(); + } else { + return (Enchantment) Random.element(enchants).newInstance(); + } } catch (Exception e) { ShatteredPixelDungeon.reportException(e); return null; @@ -346,9 +352,15 @@ abstract public class Weapon extends KindOfWeapon { } @SuppressWarnings("unchecked") - public static Enchantment randomUncommon() { + public static Enchantment randomUncommon( Class ... toIgnore ) { try { - return ((Class)Random.oneOf(uncommon)).newInstance(); + ArrayList> enchants = new ArrayList<>(Arrays.asList(uncommon)); + enchants.removeAll(Arrays.asList(toIgnore)); + if (enchants.isEmpty()) { + return random(); + } else { + return (Enchantment) Random.element(enchants).newInstance(); + } } catch (Exception e) { ShatteredPixelDungeon.reportException(e); return null; @@ -356,9 +368,15 @@ abstract public class Weapon extends KindOfWeapon { } @SuppressWarnings("unchecked") - public static Enchantment randomRare() { + public static Enchantment randomRare( Class ... toIgnore ) { try { - return ((Class)Random.oneOf(rare)).newInstance(); + ArrayList> enchants = new ArrayList<>(Arrays.asList(rare)); + enchants.removeAll(Arrays.asList(toIgnore)); + if (enchants.isEmpty()) { + return random(); + } else { + return (Enchantment) Random.element(enchants).newInstance(); + } } catch (Exception e) { ShatteredPixelDungeon.reportException(e); return null; @@ -366,9 +384,15 @@ abstract public class Weapon extends KindOfWeapon { } @SuppressWarnings("unchecked") - public static Enchantment randomCurse(){ + public static Enchantment randomCurse( Class ... toIgnore ){ try { - return ((Class)Random.oneOf(curses)).newInstance(); + ArrayList> enchants = new ArrayList<>(Arrays.asList(curses)); + enchants.removeAll(Arrays.asList(toIgnore)); + if (enchants.isEmpty()) { + return random(); + } else { + return (Enchantment) Random.element(enchants).newInstance(); + } } catch (Exception e) { ShatteredPixelDungeon.reportException(e); return null; diff --git a/core/src/main/resources/com/shatteredpixel/shatteredpixeldungeon/messages/items/items.properties b/core/src/main/resources/com/shatteredpixel/shatteredpixeldungeon/messages/items/items.properties index a02dd700d..620257239 100644 --- a/core/src/main/resources/com/shatteredpixel/shatteredpixeldungeon/messages/items/items.properties +++ b/core/src/main/resources/com/shatteredpixel/shatteredpixeldungeon/messages/items/items.properties @@ -802,8 +802,11 @@ items.scrolls.exotic.scrollofdivination.desc=This scroll will permanently identi items.scrolls.exotic.scrollofdivination$wnddivination.desc=Your scroll of divination has identified the following items: items.scrolls.exotic.scrollofenchantment.name=scroll of enchantment -items.scrolls.exotic.scrollofenchantment.inv_title=enchant an item -items.scrolls.exotic.scrollofenchantment.desc= +items.scrolls.exotic.scrollofenchantment.inv_title=Enchant an item +items.scrolls.exotic.scrollofenchantment.weapon=Select an enchantment to apply to your weapon. +items.scrolls.exotic.scrollofenchantment.armor=Select a glyph to apply to your armor. +items.scrolls.exotic.scrollofenchantment.cancel=cancel +items.scrolls.exotic.scrollofenchantment.desc=This scroll will infuse a weapon or armor with powerful magical energy. The reader even has some degree of control over which magic is imbued. items.scrolls.exotic.scrollofforesight.name=scroll of foresight items.scrolls.exotic.scrollofforesight.desc=When this scroll is read, detail of nearby terrain will be constantly fed to the reader's mind in crystal clarity. For the duration of this effect, searching will not be necessary, as the reader will automatically detect everything within their search radius. @@ -811,6 +814,9 @@ items.scrolls.exotic.scrollofforesight.desc=When this scroll is read, detail of items.scrolls.exotic.scrollofmysticalenergy.name=scroll of mystical energy items.scrolls.exotic.scrollofmysticalenergy.desc= +items.scrolls.exotic.scrollofpassage.name=scroll of passage +items.scrolls.exotic.scrollofpassage.desc=The spell on this parchment instantly transports the reader to the nearest region entrance above them. Very handy for quickly getting to a shop. + items.scrolls.exotic.scrollofpetrification.name=scroll of petrification items.scrolls.exotic.scrollofpetrification.desc=A flash of red light will overwhelm all creatures in your field of view with such great terror that they will be frozen on the spot.