package net.sourceforge.pain.logic.event.deploy;
import net.sourceforge.pain.logic.*;
import net.sourceforge.pain.logic.affect.*;
import net.sourceforge.pain.logic.fn.*;
import net.sourceforge.pain.util.*;
import net.sourceforge.pain.db.*;
import net.sourceforge.pain.data.*;
import net.sourceforge.pain.data.prototype.*;
import net.sourceforge.pain.data.type.*;
import net.sourceforge.pain.*;
import java.util.*;
/**
* User: fmike Date: Mar 10, 2004 Time: 2:28:44 AM
* This event is generated during new database creation
* Event impl should create initial world image.
* Note: Core is not initialized yet, and plugins are not loaded
* during this event call.
* <p/>
*/
public class CreateInitialWorldEvent implements Event {
public Object processEvent(Object param) throws Exception {
final PainDB db = Core.getDB();
World world = Core.getWorld();
world.setName("PAiN world");
Race hr = (Race) ObjectFactory.create(Race.class);
hr.setName("Human");
world.getRaces().add(hr);
Race dr = (Race) ObjectFactory.create(Race.class);
dr.setName("Dwarf");
world.getRaces().add(dr);
Race er = (Race) ObjectFactory.create(Race.class);
er.setName("Elf");
world.getRaces().add(er);
Log.info("Creating areas and rooms");
// SpaceGroup sg = (SpaceGroup) ObjectFactory.create(SpaceGroup.class);
ResetGroup rg = (ResetGroup) ObjectFactory.create(ResetGroup.class);
rg.setGroupInfo("Initial Reset Group");
rg.setGroupId("initial");
// rg.setResetPeriod(Time.PULSE_PER_SCD * 15);
rg.setResetPeriod(Time.PULSE_PER_MIN * 3);
world.getResetGroupRegistry().registerResetGroup(rg);
// PrototypeInfo prot = (PrototypeInfo) sg.addRole(PrototypeInfo.class);
// prot.setVnum("area:1");
// prot.setAuthor("PAiN engine");
//creating 2 rooms
IndexedSpace indexedSpace1 = (IndexedSpace) ObjectFactory.create(IndexedSpace.class);
indexedSpace1.setSpaceUniqueId("first");
world.getIndexedSpacesRegistry().registerSpace(indexedSpace1);
Space space1 = indexedSpace1.asSpace();
Room room1 = (Room) space1.addRole(Room.class);
// PrototypeInfo prot = (PrototypeInfo) space1.addRole(PrototypeInfo.class);
space1.setName("The Void");
space1.setDesc("You are suspended in cool electric space above a translucent plain. You feel\n" +
"synesthesia invading your nerves and reshuffling your senses. The sky is the\n" +
"same obsidian color as the ground and you can't find a horizon.");
space1.setCapacity(Integer.MAX_VALUE);
// prot.setVnum("room:1");
// prot.setName(space1.getName());
// prot.setDesc("First room in the world.");
// prot.setAuthor("PAiN engine.");
IndexedSpace indexedSpace2 = (IndexedSpace) ObjectFactory.create(IndexedSpace.class);
indexedSpace2.setSpaceUniqueId("second");
world.getIndexedSpacesRegistry().registerSpace(indexedSpace2);
Space space2 = indexedSpace2.asSpace();
Room room2 = (Room) space2.addRole(Room.class);
// PrototypeInfo prot2 = (PrototypeInfo) space2.addRole(PrototypeInfo.class);
space2.setName("The Void");
space2.setDesc("You are suspended in cool electric space above a translucent plain. You feel\n" +
"synesthesia invading your nerves and reshuffling your senses. The sky is the\n" +
"same obsidian color as the ground and you can't find a horizon.");
space2.setCapacity(Integer.MAX_VALUE);
// prot2.setVnum("room:2");
// prot2.setName(space2.getName());
// prot2.setDesc("Second room in the world.");
// prot2.setAuthor("PAiN engine.");
//binding space exits
Exit exitRoom1ToRoom2 = (Exit) ObjectFactory.create(Exit.class);
exitRoom1ToRoom2.setTargetRoom(room2);
exitRoom1ToRoom2.setMoveConst(1);
room1.setExit(Room.DIR_NORTH, exitRoom1ToRoom2);
Exit exitRoom2ToRoom1 = (Exit) ObjectFactory.create(Exit.class);
exitRoom2ToRoom1.setTargetRoom(room1);
exitRoom2ToRoom1.setMoveConst(1);
room2.setExit(Room.DIR_SOUTH, exitRoom2ToRoom1);
world.setDefaultBirthSpace(space1);
Log.info("Creating GOD");
Player gp = (Player) ObjectFactory.create(Player.class);
gp.setLogin("god");
gp.setPassword("god");
gp.setQuitSpace(space1);
gp.addRole(Builder.class);
world.getPlayersRegistry().addPlayer(gp);
Interactive gi = gp.asInteractive();
gi.setName("God");
gi.setDesc("God");
gi.setTargetList(new String[]{"god", "creator"});
RelocateFn.addToSpace(space1, gp.asLocated());
Mobile m = (Mobile) gp.addRole(Mobile.class);
m.setMaxMoves(1000);
m.setMoves(1000);
Creature creature = (Creature) gp.addRole(Creature.class);
Space inventory = (Space) ObjectFactory.create(Space.class);
inventory.setCapacity(Integer.MAX_VALUE);
inventory.setName("Inventory");
inventory.setDesc("Inside inventory");
creature.setInventory(inventory);
creature.setMaxHitPoints(1000);
creature.setHitPoints(1000);
ImmortalityAffect.makeImmortal(creature);
// granting comands to 'god':
Set granted = gp.getGrantedCommands();
granted.add("_all"); // special keyword, all commands allowed
Log.info("Creating thing!");
Physical tp = (Physical) ObjectFactory.create(Physical.class);
tp.setSize(10);
tp.setWeight(20);
tp.setAppearanceDesc("small stone");
Interactive ti = tp.asInteractive();
ti.setName("small stone");
ti.setDesc("small stone");
ti.setTargetList(new String[]{"stone", "small"});
RelocateFn.addToSpace(space1, ti.asLocated());
// create new player proto
PrototypeInfo p = (PrototypeInfo) ObjectFactory.create(PrototypeInfo.class);
p.setVnum("player");
p.setName("New players prototype");
p.setAuthor("god");
PhysicalPrototype pp = (PhysicalPrototype) p.addRole(PhysicalPrototype.class);
pp.setAppearanceDesc("You see nothing special about him");
pp.setSize(1);
pp.setWeight(1);
ReceptivePrototype rp = (ReceptivePrototype) p.getRole(ReceptivePrototype.class);
rp.setCanFeel(true);
rp.setCanHear(true);
rp.setCanSee(true);
InteractivePrototype ip = (InteractivePrototype) p.getRole(InteractivePrototype.class);
ip.setDesc("human");
ip.setTargetList(new String[]{"man", "human", "creature"});
MobilePrototype mp = (MobilePrototype) p.addRole(MobilePrototype.class);
mp.setMovePointsDice(new Dice(10, 10, 50));
CreaturePrototype cp = (CreaturePrototype) p.addRole(CreaturePrototype.class);
cp.setHPDice(new Dice(10, 10, 10));
cp.setSex(CreaturePrototype.SEX_EITHER);
cp.setRace(hr);
PrototypeInfo invInfo = (PrototypeInfo) ObjectFactory.create(PrototypeInfo.class);
invInfo.setName("default inventory prototype");
invInfo.setVnum("inventory0");
SpacePrototype invProto = (SpacePrototype) invInfo.addRole(SpacePrototype.class);
invProto.setSpaceName("Inventory");
invProto.setSpaceDesc("");
invProto.setCapacity(Integer.MAX_VALUE);
cp.setInventoryPrototype(invProto);
world.getPrototypesRegistry().registerPrototype(invInfo);
world.getPrototypesRegistry().registerPrototype(p);
// gui tool admins
world.getGuiToolAdmins().add(new GuiToolAdmin(db, "admin", "admin"));
Log.info("world created!");
return null;
}
}