From 9d11fb8069b3a104128b43abefa4c3ff7a1aed53 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Thu, 12 Oct 2023 14:43:02 -0400 Subject: [PATCH] v2.2.0: quests now use the deck system for their equipment loot --- .../actors/mobs/npcs/Blacksmith.java | 56 +++++++++++++++++++ .../actors/mobs/npcs/Ghost.java | 2 +- .../actors/mobs/npcs/Imp.java | 2 +- .../actors/mobs/npcs/Wandmaker.java | 14 +++-- .../items/Generator.java | 1 + .../windows/WndBlacksmith.java | 35 ++---------- 6 files changed, 73 insertions(+), 37 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Blacksmith.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Blacksmith.java index 37a19b75c..51911ad31 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Blacksmith.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Blacksmith.java @@ -26,9 +26,12 @@ import com.shatteredpixel.shatteredpixeldungeon.Statistics; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.AscensionChallenge; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; +import com.shatteredpixel.shatteredpixeldungeon.items.Generator; import com.shatteredpixel.shatteredpixeldungeon.items.Item; +import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor; import com.shatteredpixel.shatteredpixeldungeon.items.quest.DarkGold; import com.shatteredpixel.shatteredpixeldungeon.items.quest.Pickaxe; +import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon; import com.shatteredpixel.shatteredpixeldungeon.journal.Notes; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.quest.BlacksmithRoom; @@ -44,6 +47,7 @@ import com.watabou.utils.Callback; import com.watabou.utils.Random; import java.util.ArrayList; +import java.util.Collection; public class Blacksmith extends NPC { @@ -269,6 +273,9 @@ public class Blacksmith extends NPC { public static int hardens; public static int upgrades; public static int smiths; + + //pre-generate these so they are consistent between seeds + public static ArrayList smithRewards; public static void reset() { type = 0; @@ -286,6 +293,8 @@ public class Blacksmith extends NPC { hardens = 0; upgrades = 0; smiths = 0; + + smithRewards = null; } private static final String NODE = "blacksmith"; @@ -305,6 +314,7 @@ public class Blacksmith extends NPC { private static final String HARDENS = "hardens"; private static final String UPGRADES = "upgrades"; private static final String SMITHS = "smiths"; + private static final String SMITH_REWARDS = "smith_rewards"; public static void storeInBundle( Bundle bundle ) { @@ -327,6 +337,8 @@ public class Blacksmith extends NPC { node.put( HARDENS, hardens ); node.put( UPGRADES, upgrades ); node.put( SMITHS, smiths ); + + if (smithRewards != null) node.put( SMITH_REWARDS, smithRewards ); } bundle.put( NODE, node ); @@ -361,6 +373,10 @@ public class Blacksmith extends NPC { upgrades = node.getInt( UPGRADES ); smiths = node.getInt( SMITHS ); + if (node.contains( SMITH_REWARDS )){ + smithRewards = new ArrayList<>((Collection) ((Collection) node.getCollection( SMITH_REWARDS ))); + } + } else { reset(); } @@ -378,11 +394,51 @@ public class Blacksmith extends NPC { alternative = false; given = false; + generateRewards( true ); } return rooms; } + public static void generateRewards( boolean useDecks ){ + smithRewards = new ArrayList<>(); + smithRewards.add(Generator.randomWeapon(3, useDecks)); + smithRewards.add(Generator.randomWeapon(3, useDecks)); + ArrayList toUndo = new ArrayList<>(); + while (smithRewards.get(0).getClass() == smithRewards.get(1).getClass()) { + if (useDecks) toUndo.add(smithRewards.get(1)); + smithRewards.remove(1); + smithRewards.add(Generator.randomWeapon(3, useDecks)); + } + for (Item i : toUndo){ + Generator.undoDrop(i); + } + smithRewards.add(Generator.randomArmor(3)); + + //15%:+0, 55%:+1, 20%:+2, 5%:+3 + int rewardLevel; + float itemLevelRoll = Random.Float(); + if (itemLevelRoll < 0.2f){ + rewardLevel = 0; + } else if (itemLevelRoll < 0.75f){ + rewardLevel = 1; + } else if (itemLevelRoll < 0.95f){ + rewardLevel = 2; + } else { + rewardLevel = 3; + } + + for (Item i : smithRewards){ + i.level(rewardLevel); + if (i instanceof Weapon) { + ((Weapon) i).enchant(null); + } else if (i instanceof Armor){ + ((Armor) i).inscribe(null); + } + i.cursed = false; + } + } + public static int Type(){ return type; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Ghost.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Ghost.java index ffca7e849..49fcbcc3b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Ghost.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Ghost.java @@ -325,7 +325,7 @@ public class Ghost extends NPC { } //50%:tier2, 30%:tier3, 15%:tier4, 5%:tier5 int wepTier = Random.chances(new float[]{0, 0, 10, 6, 3, 1}); - weapon = (Weapon) Generator.randomUsingDefaults(Generator.wepTiers[wepTier - 1]); + weapon = (Weapon) Generator.random(Generator.wepTiers[wepTier - 1]); //clear weapon's starting properties weapon.level(0); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Imp.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Imp.java index 2b0b1973c..3a0cc1eb8 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Imp.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Imp.java @@ -236,7 +236,7 @@ public class Imp extends NPC { given = false; do { - reward = (Ring)Generator.randomUsingDefaults( Generator.Category.RING ); + reward = (Ring)Generator.random( Generator.Category.RING ); } while (reward.cursed); reward.upgrade( 2 ); reward.cursed = true; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Wandmaker.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Wandmaker.java index 0b5bc30ae..314370c63 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Wandmaker.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Wandmaker.java @@ -317,13 +317,19 @@ public class Wandmaker extends NPC { spawned = true; given = false; - wand1 = (Wand) Generator.randomUsingDefaults(Generator.Category.WAND); + wand1 = (Wand) Generator.random(Generator.Category.WAND); wand1.cursed = false; wand1.upgrade(); - do { - wand2 = (Wand) Generator.randomUsingDefaults(Generator.Category.WAND); - } while (wand2.getClass().equals(wand1.getClass())); + wand2 = (Wand) Generator.random(Generator.Category.WAND); + ArrayList toUndo = new ArrayList<>(); + while (wand2.getClass() == wand1.getClass()) { + toUndo.add(wand2); + wand2 = (Wand) Generator.random(Generator.Category.WAND); + } + for (Item i :toUndo){ + Generator.undoDrop(i); + } wand2.cursed = false; wand2.upgrade(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Generator.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Generator.java index 1814f7e61..38f128a24 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Generator.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Generator.java @@ -537,6 +537,7 @@ public class Generator { } //reverts changes to drop chances generates by this item + //equivalent of shuffling the card back into the deck, does not preserve order! public static void undoDrop(Item item){ for (Category cat : Category.values()){ if (item.getClass().isAssignableFrom(cat.superClass)){ diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBlacksmith.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBlacksmith.java index f5fd84316..bc8fc6c65 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBlacksmith.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBlacksmith.java @@ -30,7 +30,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Blacksmith; import com.shatteredpixel.shatteredpixeldungeon.items.BrokenSeal; import com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem; -import com.shatteredpixel.shatteredpixeldungeon.items.Generator; import com.shatteredpixel.shatteredpixeldungeon.items.Gold; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor; @@ -47,7 +46,6 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock; import com.shatteredpixel.shatteredpixeldungeon.ui.Window; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.watabou.noosa.audio.Sample; -import com.watabou.utils.Random; import java.util.ArrayList; @@ -438,10 +436,6 @@ public class WndBlacksmith extends Window { private static final int BTN_GAP = 5; private static final int GAP = 2; - Item[] rewards = new Item[3]; - - int rewardLevel; - public WndSmith( Blacksmith troll, Hero hero ){ super(); @@ -458,35 +452,13 @@ public class WndBlacksmith extends Window { message.setPos(0, titlebar.bottom() + GAP); add( message ); - rewards[0] = Generator.randomWeapon(3, true); - do { - rewards[1] = Generator.randomWeapon(3, true); - } while (rewards[0].getClass() == rewards[1].getClass()); - rewards[2] = Generator.randomArmor(3); - - //15%:+0, 55%:+1, 20%:+2, 5%:+3 - float itemLevelRoll = Random.Float(); - if (itemLevelRoll < 0.2f){ - rewardLevel = 0; - } else if (itemLevelRoll < 0.75f){ - rewardLevel = 1; - } else if (itemLevelRoll < 0.95f){ - rewardLevel = 2; - } else { - rewardLevel = 3; + if (Blacksmith.Quest.smithRewards == null || Blacksmith.Quest.smithRewards.isEmpty()){ + Blacksmith.Quest.generateRewards(false); } int count = 0; - for (Item i : rewards){ + for (Item i : Blacksmith.Quest.smithRewards){ count++; - i.level(rewardLevel); - if (i instanceof Weapon) { - ((Weapon) i).enchant(null); - } else if (i instanceof Armor){ - ((Armor) i).inscribe(null); - } - i.cursed = false; - ItemButton btnReward = new ItemButton(){ @Override protected void onClick() { @@ -526,6 +498,7 @@ public class WndBlacksmith extends Window { Dungeon.level.drop( item, Dungeon.hero.pos ).sprite.drop(); } WndSmith.this.hide(); + Blacksmith.Quest.smithRewards = null; } }; btnConfirm.setRect(0, height+2, width/2-1, 16);