v0.6.1: refactoring to limited drops now that they are more flexible

This commit is contained in:
Evan Debenham 2017-07-25 23:49:55 -04:00 committed by Evan Debenham
parent 67d39b856f
commit 92349dfbb1
13 changed files with 85 additions and 84 deletions

View File

@ -80,32 +80,32 @@ public class Dungeon {
//enum of items which have limited spawns, records how many have spawned
//could all be their own separate numbers, but this allows iterating, much nicer for bundling/initializing.
public static enum limitedDrops{
public static enum LimitedDrops {
//limited world drops
strengthPotions,
upgradeScrolls,
arcaneStyli,
STRENGTH_POTIONS,
UPGRADE_SCROLLS,
ARCANE_STYLI,
//all unlimited health potion sources (except guards, which are at the bottom.
swarmHP,
batHP,
warlockHP,
scorpioHP,
cookingHP,
//blandfruit, which can technically be an unlimited health potion source
blandfruitSeed,
//Health potion sources
//enemies
SWARM_HP,
GUARD_HP,
BAT_HP,
WARLOCK_HP,
SCORPIO_HP,
//alchemy
COOKING_HP,
BLANDFRUIT_SEED,
//doesn't use Generator, so we have to enforce one armband drop here
armband,
THIEVES_ARMBAND,
//containers
dewVial,
seedBag,
scrollBag,
potionBag,
wandBag,
guardHP;
DEW_VIAL,
SEED_POUCH,
SCROLL_HOLDER,
POTION_BANDOLIER,
WAND_HOLSTER;
public int count = 0;
@ -118,19 +118,19 @@ public class Dungeon {
}
public static void reset(){
for (limitedDrops lim : values()){
for (LimitedDrops lim : values()){
lim.count = 0;
}
}
public static void store( Bundle bundle ){
for (limitedDrops lim : values()){
for (LimitedDrops lim : values()){
bundle.put(lim.name(), lim.count);
}
}
public static void restore( Bundle bundle ){
for (limitedDrops lim : values()){
for (LimitedDrops lim : values()){
if (bundle.contains(lim.name())){
lim.count = bundle.getInt(lim.name());
} else {
@ -141,22 +141,22 @@ public class Dungeon {
//for saves prior to 0.6.1
public static void legacyRestore( int[] counts ){
strengthPotions.count = counts[0];
upgradeScrolls.count = counts[1];
arcaneStyli.count = counts[2];
swarmHP.count = counts[3];
batHP.count = counts[4];
warlockHP.count = counts[5];
scorpioHP.count = counts[6];
cookingHP.count = counts[7];
blandfruitSeed.count = counts[8];
armband.count = counts[9];
dewVial.count = counts[10];
seedBag.count = counts[11];
scrollBag.count = counts[12];
potionBag.count = counts[13];
wandBag.count = counts[14];
guardHP.count = counts[15];
STRENGTH_POTIONS.count = counts[0];
UPGRADE_SCROLLS.count = counts[1];
ARCANE_STYLI.count = counts[2];
SWARM_HP.count = counts[3];
BAT_HP.count = counts[4];
WARLOCK_HP.count = counts[5];
SCORPIO_HP.count = counts[6];
COOKING_HP.count = counts[7];
BLANDFRUIT_SEED.count = counts[8];
THIEVES_ARMBAND.count = counts[9];
DEW_VIAL.count = counts[10];
SEED_POUCH.count = counts[11];
SCROLL_HOLDER.count = counts[12];
POTION_BANDOLIER.count = counts[13];
WAND_HOLSTER.count = counts[14];
GUARD_HP.count = counts[15];
}
}
@ -213,7 +213,7 @@ public class Dungeon {
droppedItems = new SparseArray<ArrayList<Item>>();
for (limitedDrops a : limitedDrops.values())
for (LimitedDrops a : LimitedDrops.values())
a.count = 0;
chapters = new HashSet<Integer>();
@ -398,7 +398,7 @@ public class Dungeon {
public static boolean posNeeded() {
//2 POS each floor set
int posLeftThisSet = 2 - (limitedDrops.strengthPotions.count - (depth / 5) * 2);
int posLeftThisSet = 2 - (LimitedDrops.STRENGTH_POTIONS.count - (depth / 5) * 2);
if (posLeftThisSet <= 0) return false;
int floorThisSet = (depth % 5);
@ -414,7 +414,7 @@ public class Dungeon {
public static boolean souNeeded() {
//3 SOU each floor set
int souLeftThisSet = 3 - (limitedDrops.upgradeScrolls.count - (depth / 5) * 3);
int souLeftThisSet = 3 - (LimitedDrops.UPGRADE_SCROLLS.count - (depth / 5) * 3);
if (souLeftThisSet <= 0) return false;
int floorThisSet = (depth % 5);
@ -424,7 +424,7 @@ public class Dungeon {
public static boolean asNeeded() {
//1 AS each floor set
int asLeftThisSet = 1 - (limitedDrops.arcaneStyli.count - (depth / 5));
int asLeftThisSet = 1 - (LimitedDrops.ARCANE_STYLI.count - (depth / 5));
if (asLeftThisSet <= 0) return false;
int floorThisSet = (depth % 5);
@ -453,8 +453,6 @@ public class Dungeon {
private static final String DROPPED = "dropped%d";
private static final String LEVEL = "level";
private static final String LIMDROPS = "limiteddrops";
private static final String DV = "dewVial";
private static final String WT = "transmutation";
private static final String CHAPTERS = "chapters";
private static final String QUESTS = "quests";
private static final String BADGES = "badges";
@ -504,7 +502,7 @@ public class Dungeon {
quickslot.storePlaceholders( bundle );
Bundle limDrops = new Bundle();
limitedDrops.store( limDrops );
LimitedDrops.store( limDrops );
bundle.put ( LIMDROPS, limDrops );
int count = 0;
@ -609,9 +607,9 @@ public class Dungeon {
if (fullLoad) {
if( version <= 199 ){
limitedDrops.legacyRestore( bundle.getIntArray(LIMDROPS) );
LimitedDrops.legacyRestore( bundle.getIntArray(LIMDROPS) );
} else {
limitedDrops.restore( bundle.getBundle(LIMDROPS) );
LimitedDrops.restore( bundle.getBundle(LIMDROPS) );
}
chapters = new HashSet<Integer>();

View File

@ -81,13 +81,13 @@ public class Bat extends Mob {
@Override
public void die( Object cause ){
//sets drop chance
lootChance = 1f/((6 + Dungeon.limitedDrops.batHP.count ));
lootChance = 1f/((6 + Dungeon.LimitedDrops.BAT_HP.count ));
super.die( cause );
}
@Override
protected Item createLoot(){
Dungeon.limitedDrops.batHP.count++;
Dungeon.LimitedDrops.BAT_HP.count++;
return super.createLoot();
}

View File

@ -156,8 +156,8 @@ public class Guard extends Mob {
//otherwise, we may drop a health potion. overall chance is 7/(8 * (7 + potions dropped))
//with 0 potions dropped that simplifies to 1/8
} else {
if (Random.Int(7 + Dungeon.limitedDrops.guardHP.count) < 7){
Dungeon.limitedDrops.guardHP.drop();
if (Random.Int(7 + Dungeon.LimitedDrops.GUARD_HP.count) < 7){
Dungeon.LimitedDrops.GUARD_HP.drop();
return new PotionOfHealing();
}
}

View File

@ -97,8 +97,8 @@ public class Scorpio extends Mob {
@Override
protected Item createLoot() {
//5/count+5 total chance of getting healing, failing the 2nd roll drops mystery meat instead.
if (Random.Int( 5 + Dungeon.limitedDrops.scorpioHP.count ) <= 4) {
Dungeon.limitedDrops.scorpioHP.count++;
if (Random.Int( 5 + Dungeon.LimitedDrops.SCORPIO_HP.count ) < 5) {
Dungeon.LimitedDrops.SCORPIO_HP.count++;
return (Item)loot;
} else {
return new MysteryMeat();

View File

@ -141,13 +141,13 @@ public class Swarm extends Mob {
@Override
public void die( Object cause ){
//sets drop chance
lootChance = 1f/((6 + 2*Dungeon.limitedDrops.swarmHP.count ) * (generation+1) );
lootChance = 1f/((6 + 2* Dungeon.LimitedDrops.SWARM_HP.count ) * (generation+1) );
super.die( cause );
}
@Override
protected Item createLoot(){
Dungeon.limitedDrops.swarmHP.count++;
Dungeon.LimitedDrops.SWARM_HP.count++;
return super.createLoot();
}
}

View File

@ -105,8 +105,8 @@ public class Thief extends Mob {
@Override
protected Item createLoot(){
if (!Dungeon.limitedDrops.armband.dropped()) {
Dungeon.limitedDrops.armband.drop();
if (!Dungeon.LimitedDrops.THIEVES_ARMBAND.dropped()) {
Dungeon.LimitedDrops.THIEVES_ARMBAND.drop();
return new MasterThievesArmband().identify();
} else
return new Gold(Random.NormalIntRange(100, 250));

View File

@ -135,10 +135,10 @@ public class Warlock extends Mob implements Callback {
if (loot instanceof PotionOfHealing){
//count/10 chance of not dropping potion
if (Random.Int(10)-Dungeon.limitedDrops.warlockHP.count < 0){
if ((Random.Int(10) - Dungeon.LimitedDrops.WARLOCK_HP.count) < 0){
return null;
} else
Dungeon.limitedDrops.warlockHP.count++;
Dungeon.LimitedDrops.WARLOCK_HP.count++;
}

View File

@ -443,11 +443,14 @@ public class Heap implements Bundlable {
if (Random.Int(1000/bonus) == 0)
return new PotionOfExperience();
while (potion instanceof PotionOfHealing && Random.Int(10) < Dungeon.limitedDrops.cookingHP.count)
potion = Generator.random( Generator.Category.POTION );
while (potion instanceof PotionOfHealing
&& Random.Int(10) < Dungeon.LimitedDrops.COOKING_HP.count) {
potion = Generator.random(Generator.Category.POTION);
}
if (potion instanceof PotionOfHealing)
Dungeon.limitedDrops.cookingHP.count++;
if (potion instanceof PotionOfHealing) {
Dungeon.LimitedDrops.COOKING_HP.count++;
}
return potion;

View File

@ -130,9 +130,9 @@ public class WandOfRegrowth extends Wand {
Plant.Seed seed = (Plant.Seed) Generator.random(Generator.Category.SEED);
if (seed instanceof BlandfruitBush.Seed) {
if (Random.Int(15) - Dungeon.limitedDrops.blandfruitSeed.count >= 0) {
if (Random.Int(15) - Dungeon.LimitedDrops.BLANDFRUIT_SEED.count >= 0) {
floor.plant(seed, cells.next());
Dungeon.limitedDrops.blandfruitSeed.count++;
Dungeon.LimitedDrops.BLANDFRUIT_SEED.count++;
}
} else
floor.plant(seed, cells.next());

View File

@ -104,9 +104,9 @@ public class SewerLevel extends RegularLevel {
@Override
protected void createItems() {
if (!Dungeon.limitedDrops.dewVial.dropped()) {
if (!Dungeon.LimitedDrops.DEW_VIAL.dropped()) {
addItemToSpawn( new DewVial() );
Dungeon.limitedDrops.dewVial.drop();
Dungeon.LimitedDrops.DEW_VIAL.drop();
}
Ghost.Quest.spawn( this );

View File

@ -69,9 +69,9 @@ public class HighGrass {
Item seed = Generator.random(Generator.Category.SEED);
if (seed instanceof BlandfruitBush.Seed) {
if (Random.Int(15) - Dungeon.limitedDrops.blandfruitSeed.count >= 0) {
if (Random.Int(15) - Dungeon.LimitedDrops.BLANDFRUIT_SEED.count >= 0) {
level.drop(seed, pos).sprite.drop();
Dungeon.limitedDrops.blandfruitSeed.count++;
Dungeon.LimitedDrops.BLANDFRUIT_SEED.count++;
}
} else
level.drop(seed, pos).sprite.drop();

View File

@ -300,32 +300,32 @@ public class ShopRoom extends SpecialRoom {
//count up items in the main bag, for bags which haven't yet been dropped.
for (Item item : pack.backpack.items) {
if (!Dungeon.limitedDrops.seedBag.dropped() && item instanceof Plant.Seed)
if (!Dungeon.LimitedDrops.SEED_POUCH.dropped() && item instanceof Plant.Seed)
seeds++;
else if (!Dungeon.limitedDrops.scrollBag.dropped() && item instanceof Scroll)
else if (!Dungeon.LimitedDrops.SCROLL_HOLDER.dropped() && item instanceof Scroll)
scrolls++;
else if (!Dungeon.limitedDrops.potionBag.dropped() && item instanceof Potion)
else if (!Dungeon.LimitedDrops.POTION_BANDOLIER.dropped() && item instanceof Potion)
potions++;
else if (!Dungeon.limitedDrops.wandBag.dropped() && item instanceof Wand)
else if (!Dungeon.LimitedDrops.WAND_HOLSTER.dropped() && item instanceof Wand)
wands++;
}
//then pick whichever valid bag has the most items available to put into it.
//note that the order here gives a perference if counts are otherwise equal
if (seeds >= scrolls && seeds >= potions && seeds >= wands && !Dungeon.limitedDrops.seedBag.dropped()) {
Dungeon.limitedDrops.seedBag.drop();
if (seeds >= scrolls && seeds >= potions && seeds >= wands && !Dungeon.LimitedDrops.SEED_POUCH.dropped()) {
Dungeon.LimitedDrops.SEED_POUCH.drop();
return new SeedPouch();
} else if (scrolls >= potions && scrolls >= wands && !Dungeon.limitedDrops.scrollBag.dropped()) {
Dungeon.limitedDrops.scrollBag.drop();
} else if (scrolls >= potions && scrolls >= wands && !Dungeon.LimitedDrops.SCROLL_HOLDER.dropped()) {
Dungeon.LimitedDrops.SCROLL_HOLDER.drop();
return new ScrollHolder();
} else if (potions >= wands && !Dungeon.limitedDrops.potionBag.dropped()) {
Dungeon.limitedDrops.potionBag.drop();
} else if (potions >= wands && !Dungeon.LimitedDrops.POTION_BANDOLIER.dropped()) {
Dungeon.LimitedDrops.POTION_BANDOLIER.drop();
return new PotionBandolier();
} else if (!Dungeon.limitedDrops.wandBag.dropped()) {
Dungeon.limitedDrops.wandBag.drop();
} else if (!Dungeon.LimitedDrops.WAND_HOLSTER.dropped()) {
Dungeon.LimitedDrops.WAND_HOLSTER.drop();
return new WandHolster();
}

View File

@ -89,9 +89,9 @@ public abstract class Plant implements Bundlable {
Item seed = Generator.random(Generator.Category.SEED);
if (seed instanceof BlandfruitBush.Seed) {
if (Random.Int(15) - Dungeon.limitedDrops.blandfruitSeed.count >= 0) {
if (Random.Int(15) - Dungeon.LimitedDrops.BLANDFRUIT_SEED.count >= 0) {
Dungeon.level.drop(seed, pos).sprite.drop();
Dungeon.limitedDrops.blandfruitSeed.count++;
Dungeon.LimitedDrops.BLANDFRUIT_SEED.count++;
}
} else
Dungeon.level.drop(seed, pos).sprite.drop();