v0.2.3: artifacts are now unique, also have better interaction with remains
This commit is contained in:
parent
e58df1bc9c
commit
567f80a689
|
@ -18,8 +18,10 @@
|
|||
package com.shatteredpixel.shatteredpixeldungeon;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Generator;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Gold;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.Artifact;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.MissileWeapon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlot;
|
||||
import com.watabou.noosa.Game;
|
||||
|
@ -143,6 +145,22 @@ public class Bones {
|
|||
if (depth == Dungeon.depth && Dungeon.challenges == 0) {
|
||||
Game.instance.deleteFile( BONES_FILE );
|
||||
depth = 0;
|
||||
|
||||
if (item instanceof Artifact){
|
||||
if (Generator.removeArtifact((Artifact)item)) {
|
||||
try {
|
||||
item = item.getClass().newInstance();
|
||||
item.cursed = true;
|
||||
item.cursedKnown = true;
|
||||
|
||||
return item;
|
||||
} catch (Exception e) {
|
||||
return new Gold(Random.NormalIntRange(150, 250));
|
||||
}
|
||||
} else {
|
||||
return new Gold(Random.NormalIntRange(150, 250));
|
||||
}
|
||||
}
|
||||
|
||||
if (item.isUpgradable()) {
|
||||
item.cursed = true;
|
||||
|
|
|
@ -29,6 +29,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.ConfusionGas;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Fire;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.ParalyticGas;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.ToxicGas;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Generator;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfLevitation;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfLiquidFlame;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfParalyticGas;
|
||||
|
@ -160,6 +161,8 @@ public class Dungeon {
|
|||
|
||||
challenges = ShatteredPixelDungeon.challenges();
|
||||
|
||||
Generator.initArtifacts();
|
||||
|
||||
Actor.clear();
|
||||
|
||||
PathFinder.setMapSize( Level.WIDTH, Level.HEIGHT );
|
||||
|
@ -484,6 +487,7 @@ public class Dungeon {
|
|||
|
||||
Statistics.storeInBundle( bundle );
|
||||
Journal.storeInBundle( bundle );
|
||||
Generator.storeInBundle( bundle );
|
||||
|
||||
if (quickslot instanceof Class) {
|
||||
bundle.put( QUICKSLOT, ((Class<?>)quickslot).getName() );
|
||||
|
@ -619,6 +623,7 @@ public class Dungeon {
|
|||
|
||||
Statistics.restoreFromBundle( bundle );
|
||||
Journal.restoreFromBundle( bundle );
|
||||
Generator.restoreFromBundle( bundle );
|
||||
}
|
||||
|
||||
public static Level loadLevel( HeroClass cl ) throws IOException {
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
*/
|
||||
package com.shatteredpixel.shatteredpixeldungeon.items;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Wandmaker.Rotberry;
|
||||
|
@ -36,8 +34,13 @@ import com.shatteredpixel.shatteredpixeldungeon.items.weapon.*;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.*;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.*;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.plants.*;
|
||||
import com.watabou.utils.Bundle;
|
||||
import com.watabou.utils.Random;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Generator {
|
||||
|
||||
public static enum Category {
|
||||
|
@ -47,7 +50,7 @@ public class Generator {
|
|||
SCROLL ( 400, Scroll.class ),
|
||||
WAND ( 40, Wand.class ),
|
||||
RING ( 15, Ring.class ),
|
||||
ARTIFACT( 20, Artifact.class),
|
||||
ARTIFACT( 20, Artifact.class),
|
||||
SEED ( 50, Plant.Seed.class ),
|
||||
FOOD ( 0, Food.class ),
|
||||
GOLD ( 500, Gold.class );
|
||||
|
@ -222,6 +225,10 @@ public class Generator {
|
|||
return randomArmor();
|
||||
case WEAPON:
|
||||
return randomWeapon();
|
||||
case ARTIFACT:
|
||||
Item item = randomArtifact();
|
||||
//if we're out of artifacts, return a ring instead.
|
||||
return item != null ? item : random(Category.RING);
|
||||
default:
|
||||
return ((Item)cat.classes[Random.chances( cat.probs )].newInstance()).random();
|
||||
}
|
||||
|
@ -290,4 +297,73 @@ public class Generator {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//enforces uniqueness of artifacts throughout a run.
|
||||
public static Artifact randomArtifact() {
|
||||
|
||||
try {
|
||||
Category cat = Category.ARTIFACT;
|
||||
int i = Random.chances( cat.probs );
|
||||
|
||||
//if no artifacts are left, return null
|
||||
if (i == -1){
|
||||
return null;
|
||||
}
|
||||
|
||||
Artifact artifact = (Artifact)cat.classes[i].newInstance();
|
||||
|
||||
//remove the chance of spawning this artifact.
|
||||
cat.probs[i] = 0;
|
||||
spawnedArtifacts.add(cat.classes[i].getSimpleName());
|
||||
|
||||
return artifact;
|
||||
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean removeArtifact(Artifact artifact) {
|
||||
if (spawnedArtifacts.contains(artifact.getClass().getSimpleName()))
|
||||
return false;
|
||||
|
||||
Category cat = Category.ARTIFACT;
|
||||
for (int i = 0; i < cat.classes.length; i++)
|
||||
if (cat.classes[i].equals(artifact.getClass())) {
|
||||
cat.probs[i] = 0;
|
||||
spawnedArtifacts.add(artifact.getClass().getSimpleName());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//resets artifact probabilities, for new dungeons
|
||||
public static void initArtifacts() {
|
||||
Category.ARTIFACT.probs = new float[]{ 0, 1, 1, 1, 0, 1, 1 };
|
||||
spawnedArtifacts = new ArrayList<String>();
|
||||
}
|
||||
|
||||
private static ArrayList<String> spawnedArtifacts = new ArrayList<String>();
|
||||
|
||||
private static final String ARTIFACTS = "artifacts";
|
||||
|
||||
//used to store information on which artifacts have been spawned.
|
||||
public static void storeInBundle(Bundle bundle) {
|
||||
bundle.put( ARTIFACTS, spawnedArtifacts.toArray(new String[spawnedArtifacts.size()]));
|
||||
}
|
||||
|
||||
public static void restoreFromBundle(Bundle bundle) {
|
||||
initArtifacts();
|
||||
|
||||
if (bundle.contains(ARTIFACTS)) {
|
||||
Collections.addAll(spawnedArtifacts, bundle.getStringArray(ARTIFACTS));
|
||||
Category cat = Category.ARTIFACT;
|
||||
|
||||
for (String artifact : spawnedArtifacts)
|
||||
for (int i = 0; i < cat.classes.length; i++)
|
||||
if (cat.classes[i].getSimpleName().equals(artifact))
|
||||
cat.probs[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user