v0.2.3: artifacts are now unique, also have better interaction with remains
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user