V0.1.0 Partial Commit

changed package and application names to differentiate from main PD
release
This commit is contained in:
Evan Debenham
2014-08-03 14:46:22 -04:00
parent 65dd9c2dc0
commit aed303672a
474 changed files with 3468 additions and 3458 deletions
@@ -0,0 +1,263 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2014 Oleg Dolya
*
* 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 <http://www.gnu.org/licenses/>
*/
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;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.*;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
import com.shatteredpixel.shatteredpixeldungeon.items.food.Food;
import com.shatteredpixel.shatteredpixeldungeon.items.food.MysteryMeat;
import com.shatteredpixel.shatteredpixeldungeon.items.food.Pasty;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.*;
import com.shatteredpixel.shatteredpixeldungeon.items.rings.*;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.*;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.*;
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.Random;
public class Generator {
public static enum Category {
WEAPON ( 15, Weapon.class ),
ARMOR ( 10, Armor.class ),
POTION ( 50, Potion.class ),
SCROLL ( 40, Scroll.class ),
WAND ( 4, Wand.class ),
RING ( 2, Ring.class ),
SEED ( 5, Plant.Seed.class ),
FOOD ( 0, Food.class ),
GOLD ( 50, Gold.class );
public Class<?>[] classes;
public float[] probs;
public float prob;
public Class<? extends Item> superClass;
private Category( float prob, Class<? extends Item> superClass ) {
this.prob = prob;
this.superClass = superClass;
}
public static int order( Item item ) {
for (int i=0; i < values().length; i++) {
if (values()[i].superClass.isInstance( item )) {
return i;
}
}
return item instanceof Bag ? Integer.MAX_VALUE : Integer.MAX_VALUE - 1;
}
};
private static HashMap<Category,Float> categoryProbs = new HashMap<Generator.Category, Float>();
static {
Category.GOLD.classes = new Class<?>[]{
Gold.class };
Category.GOLD.probs = new float[]{ 1 };
Category.SCROLL.classes = new Class<?>[]{
ScrollOfIdentify.class,
ScrollOfTeleportation.class,
ScrollOfRemoveCurse.class,
ScrollOfUpgrade.class,
ScrollOfRecharging.class,
ScrollOfMagicMapping.class,
ScrollOfRage.class,
ScrollOfTerror.class,
ScrollOfLullaby.class,
ScrollOfWeaponUpgrade.class,
ScrollOfPsionicBlast.class,
ScrollOfMirrorImage.class };
Category.SCROLL.probs = new float[]{ 30, 10, 15, 0, 10, 15, 12, 8, 8, 0, 4, 6 };
Category.POTION.classes = new Class<?>[]{
PotionOfHealing.class,
PotionOfExperience.class,
PotionOfToxicGas.class,
PotionOfParalyticGas.class,
PotionOfLiquidFlame.class,
PotionOfLevitation.class,
PotionOfStrength.class,
PotionOfMindVision.class,
PotionOfPurity.class,
PotionOfInvisibility.class,
PotionOfMight.class,
PotionOfFrost.class };
Category.POTION.probs = new float[]{ 45, 4, 15, 10, 15, 10, 0, 20, 12, 10, 0, 10 };
Category.WAND.classes = new Class<?>[]{
WandOfTeleportation.class,
WandOfSlowness.class,
WandOfFirebolt.class,
WandOfRegrowth.class,
WandOfPoison.class,
WandOfBlink.class,
WandOfLightning.class,
WandOfAmok.class,
WandOfTelekinesis.class,
WandOfFlock.class,
WandOfMagicMissile.class,
WandOfDisintegration.class,
WandOfAvalanche.class };
Category.WAND.probs = new float[]{ 10, 10, 15, 6, 10, 11, 15, 10, 6, 10, 0, 5, 5 };
Category.WEAPON.classes = new Class<?>[]{
Dagger.class,
Knuckles.class,
Quarterstaff.class,
Spear.class,
Mace.class,
Sword.class,
Longsword.class,
BattleAxe.class,
WarHammer.class,
Glaive.class,
ShortSword.class,
Dart.class,
Javelin.class,
IncendiaryDart.class,
CurareDart.class,
Shuriken.class,
Boomerang.class,
Tamahawk.class };
Category.WEAPON.probs = new float[]{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1 };
Category.ARMOR.classes = new Class<?>[]{
ClothArmor.class,
LeatherArmor.class,
MailArmor.class,
ScaleArmor.class,
PlateArmor.class };
Category.ARMOR.probs = new float[]{ 1, 1, 1, 1, 1 };
Category.FOOD.classes = new Class<?>[]{
Food.class,
Pasty.class,
MysteryMeat.class };
Category.FOOD.probs = new float[]{ 4, 1, 0 };
Category.RING.classes = new Class<?>[]{
RingOfMending.class,
RingOfDetection.class,
RingOfShadows.class,
RingOfPower.class,
RingOfHerbalism.class,
RingOfAccuracy.class,
RingOfEvasion.class,
RingOfSatiety.class,
RingOfHaste.class,
RingOfElements.class,
RingOfHaggler.class,
RingOfThorns.class };
Category.RING.probs = new float[]{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 };
Category.SEED.classes = new Class<?>[]{
Firebloom.Seed.class,
Icecap.Seed.class,
Sorrowmoss.Seed.class,
Blindweed.Seed.class,
Sungrass.Seed.class,
Earthroot.Seed.class,
Fadeleaf.Seed.class,
Rotberry.Seed.class };
Category.SEED.probs = new float[]{ 1, 1, 1, 1, 1, 1, 1, 0 };
}
public static void reset() {
for (Category cat : Category.values()) {
categoryProbs.put( cat, cat.prob );
}
}
public static Item random() {
return random( Random.chances( categoryProbs ) );
}
public static Item random( Category cat ) {
try {
categoryProbs.put( cat, categoryProbs.get( cat ) / 2 );
switch (cat) {
case ARMOR:
return randomArmor();
case WEAPON:
return randomWeapon();
default:
return ((Item)cat.classes[Random.chances( cat.probs )].newInstance()).random();
}
} catch (Exception e) {
return null;
}
}
public static Item random( Class<? extends Item> cl ) {
try {
return ((Item)cl.newInstance()).random();
} catch (Exception e) {
return null;
}
}
public static Armor randomArmor() throws Exception {
int curStr = Hero.STARTING_STR + Dungeon.potionOfStrength;
Category cat = Category.ARMOR;
Armor a1 = (Armor)cat.classes[Random.chances( cat.probs )].newInstance();
Armor a2 = (Armor)cat.classes[Random.chances( cat.probs )].newInstance();
a1.random();
a2.random();
return Math.abs( curStr - a1.STR ) < Math.abs( curStr - a2.STR ) ? a1 : a2;
}
public static Weapon randomWeapon() throws Exception {
int curStr = Hero.STARTING_STR + Dungeon.potionOfStrength;
Category cat = Category.WEAPON;
Weapon w1 = (Weapon)cat.classes[Random.chances( cat.probs )].newInstance();
Weapon w2 = (Weapon)cat.classes[Random.chances( cat.probs )].newInstance();
w1.random();
w2.random();
return Math.abs( curStr - w1.STR ) < Math.abs( curStr - w2.STR ) ? w1 : w2;
}
}