CreateInitialWorldEvent.java
mudlibs/tinylib/src/net/sourceforge/pain/tinylib/logic/event/deploy/CreateInitialWorldEvent.java · 6.8 KB
From the archive pain_0_45.tgz
Download the archive « Back to the archive contents
package net.sourceforge.pain.tinylib.logic.event.deploy;
import net.sourceforge.pain.*;
import net.sourceforge.pain.data.*;
import net.sourceforge.pain.data.role.*;
import net.sourceforge.pain.logic.*;
import net.sourceforge.pain.tinylib.*;
import net.sourceforge.pain.tinylib.data.*;
import net.sourceforge.pain.tinylib.data.prototype.*;
import net.sourceforge.pain.tinylib.data.type.*;
import net.sourceforge.pain.tinylib.logic.affect.*;
import net.sourceforge.pain.tinylib.logic.fn.*;
import net.sourceforge.pain.util.*;
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 {
World world = Mudlib.getWorld();
world.setName("PAiN world");
Race hr = (Race) ObjectFactory.createRaw(Race.class);
hr.setName("Human");
world.getRaces().add(hr);
Race dr = (Race) ObjectFactory.createRaw(Race.class);
dr.setName("Dwarf");
world.getRaces().add(dr);
Race er = (Race) ObjectFactory.createRaw(Race.class);
er.setName("Elf");
world.getRaces().add(er);
Log.info("Creating areas and rooms");
SpaceGroup area = (SpaceGroup) ObjectFactory.createRaw(SpaceGroup.class);
area.setName("Initial Area");
ResetGroup rg = (ResetGroup) area.addRole(ResetGroup.class);
rg.setGroupInfo("Initial Area Reset Group");
rg.setGroupId("initial");
rg.setResetPeriod(Pulse.PULSE_PER_MIN * 3);
//creating 2 rooms
Room room1 = (Room) ObjectFactory.createRaw(Room.class);
room1.setRoomUniqueId("first");
world.getRoomsRegistry().registerRoom(room1);
Space space1 = room1.asSpace();
area.addSpace(space1);
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);
Room room2 = (Room) ObjectFactory.createRaw(Room.class);
room2.setRoomUniqueId("second");
world.getRoomsRegistry().registerRoom(room2);
Space space2 = room2.asSpace();
area.addSpace(space2);
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);
//binding space exits
Exit exitRoom1ToRoom2 = (Exit) ObjectFactory.createRaw(Exit.class);
exitRoom1ToRoom2.setTargetRoom(room2);
exitRoom1ToRoom2.setMoveConst(1);
room1.setExit(Room.DIR_NORTH, exitRoom1ToRoom2);
Exit exitRoom2ToRoom1 = (Exit) ObjectFactory.createRaw(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.createRaw(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());
Creature creature = (Creature) gp.addRole(Creature.class);
Space inventory = (Space) ObjectFactory.createRaw(Space.class);
inventory.setCapacity(Integer.MAX_VALUE);
inventory.setName("Inventory");
inventory.setDesc("Inside inventory");
creature.setInventory(inventory);
creature.setMaxHitPoints(1000);
creature.setHitPoints(1000);
creature.setMaxMoves(1000);
creature.setMoves(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.createRaw(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.createRaw(PrototypeInfo.class);
p.setVnum("player");
p.setName("New players prototype");
p.setAuthor("god");
CreaturePrototype cp = (CreaturePrototype) p.addRole(CreaturePrototype.class);
cp.setHPDice(new Dice(10, 10, 10));
cp.setSex(CreaturePrototype.SEX_EITHER);
cp.setRace(hr);
cp.setMovePointsDice(new Dice(10, 10, 50));
PhysicalPrototype pp = (PhysicalPrototype) p.getRole(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"});
PrototypeInfo invInfo = (PrototypeInfo) ObjectFactory.createRaw(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);
Log.info("world created!");
return null;
}
}