Objects
From Multiverse
Contents |
Multiverse objects
The Multiverse object API is defined in the multiverse.server.objects package. In this package, multiverse.server.objects.Entity is the base class for all persistent objects. All Entity objects have a unique object ID (OID). When you instantiate an Entity, the OID Manager guarantees uniqueness by getting an unallocated ID from the database.
The multiverse.server.objects.MVObject class is dervied from Entity, and defines properties and methods of an objects that can be displayed in a game world, such as items, mobs, structures, and so on.
The MARS object API is defined in the multiverse.mars.objects package.
Object templates
Starting with version 1.5, the type-specific templates (ItemTemplate, MobTemplate, and so on) are no longer available.
Instead, use Template for all templates.
The following Python code illustrates a template for a human female PC:
tmpl = Template("Human Female Leather")
tmpl.put(WorldManagerClient.NAMESPACE,
WorldManagerClient.TEMPL_DISPLAY_CONTEXT,
human_female_base_DC)
tmpl.put(WorldManagerClient.NAMESPACE,
WorldManagerClient.TEMPL_OBJECT_TYPE,
ObjectTypes.mob)
tmpl.put(InventoryClient.NAMESPACE, InventoryClient.TEMPL_ITEMS,
"*Leather Tunic; *Leather Pants; *Leather Boots")
ObjectManagerClient.registerTemplate(tmpl)
Mob templates
The following Python code from multiverse/config/sampleworld/templates.py illustrates using a mob template:
tmpl = Template("Wolf")
tmpl.put(WorldManagerClient.NAMESPACE,
WorldManagerClient.TEMPL_DISPLAY_CONTEXT,
DisplayContext("wolf.mesh", True))
tmpl.put(WorldManagerClient.NAMESPACE, WorldManagerClient.TEMPL_OBJECT_TYPE, ObjectTypes.mob)
tmpl.put(InventoryClient.NAMESPACE, InventoryClient.TEMPL_ITEMS, "Wolf Skin; Wolf Bones")
tmpl.put(CombatClient.NAMESPACE, "strength", MarsStat("strength", 20))
tmpl.put(CombatClient.NAMESPACE, "dexterity", MarsStat("dexterity", 20))
tmpl.put(CombatClient.NAMESPACE, "wisdom", MarsStat("wisdom", 20))
tmpl.put(CombatClient.NAMESPACE, "intelligence", MarsStat("intelligence", 20))
tmpl.put(CombatClient.NAMESPACE, "stamina", MarsStat("stamina", int(int(20)*1.5)))
tmpl.put(CombatClient.NAMESPACE, "stamina-max", MarsStat("stamina-max", int(int(20)*1.5)))
tmpl.put(CombatClient.NAMESPACE, "mana", MarsStat("mana", int(20)*2))
tmpl.put(CombatClient.NAMESPACE, "mana-max", MarsStat("mana-max", int(20)* 2))
tmpl.put(CombatClient.NAMESPACE, "health", MarsStat("health", int(20) * 2))
tmpl.put(CombatClient.NAMESPACE, "health-max", MarsStat("health-max", int(20)*2))
tmpl.put(CombatClient.NAMESPACE, "experience", MarsStat("experience", 0))
tmpl.put(CombatClient.NAMESPACE, "level", MarsStat("level", 1))
tmpl.put(CombatClient.NAMESPACE, CombatInfo.COMBAT_PROP_AUTOATTACK_ABILITY, "attack ability")
tmpl.put(CombatClient.NAMESPACE, CombatInfo.COMBAT_PROP_REGEN_EFFECT, "regen effect")
tmpl.put(CombatClient.NAMESPACE, "attackable", Boolean(True))
tmpl.put(CombatClient.NAMESPACE, "combat.mobflag", Boolean(True))
tmpl.put(CombatClient.NAMESPACE, "kill_exp", 10);
tmpl.put(WorldManagerClient.NAMESPACE, "clickCommand", "/click")
ObjectManagerClient.registerTemplate(tmpl)
Notice the line:
tmpl.put(CombatClient.NAMESPACE, "attackable", Boolean(True))
This method call makes the mob attackable. By default, objects (such as mobs and players) are not attackable. Use a similar line to make a player character attackable.
Containership
You can define objects such that they can contain other objects. An object has a property that identifies its container (if any). In MARS, only mobs and items have the concept of inventory, for example bag number and slot number within the bag.
The multiverse.server.objects.Bag class defines an Entity that can contain objects. A Bag contains a number of slots; each slot can contain an item. Set the number of slots with the setNumSlots() method, or in the Bag constructor.
Use addItem() to add items to a bag and removeItem() to remove items; each of these methods takes an object ID as argument.
Spawn generators
Spawn generators create mobs within a given radius of a specified location. They are implemented in the class multiverse.mars.objects.SpawnGenerator.
The following Python code illustrates how to use a spawn generator. This code is usually placed in the world-specific mobserver.py, for example Multiverse/config/sampleworld/mobserver.py:
class ZombieFactory (ObjectFactory):
def makeObject(self, spawnData, instanceOid, loc):
obj = ObjectFactory.makeObject(self, spawnData, instanceOid, loc)
zombieLoc = InstanceClient.getMarkerPoint(instanceOid, "zombiemarker")
behav = PatrolBehavior()
behav.addWaypoint(zombieLoc)
behav.addWaypoint(loc)
obj.addBehavior(BaseBehavior())
obj.addBehavior(behav)
obj.addBehavior(CombatBehavior())
return obj
ObjectFactory.register("ZombieFactory", ZombieFactory("Zombie"))
Create spawn generators when you load or create an instance. For example, here is code from multiverse/config/sampleworld/instance_load.py to create the zombie spawn generator:
instance = Instance.current()
instanceOid = Instance.currentOid()
...
zombieMarker = instance.getMarker("zombiemarker").clone()
zombieMarker.getPoint().setY(0)
spawnData = SpawnData()
spawnData.setFactoryName("ZombieFactory")
spawnData.setInstanceOid(Long(instanceOid))
spawnData.setLoc(zombieMarker.getPoint())
spawnData.setNumSpawns(2)
spawnData.setSpawnRadius(30000)
spawnData.setRespawnTime(60000)
spawnData.setCorpseDespawnTime(30000)
MobManagerClient.createSpawnGenerator(spawnData)
