Thursday, December 14, 2006 - Posts

Multiverse - MARS, levels and more

Dragon asked if it is possible to pick and choose elements from Multiverse's MARS object library (a collection of classes which implement a basic graphical DIKU).

Each plug-in of the MARS library is loaded separately, so there is a degree of granularity there: you could replace the objects library (multiverse.mars.objects) with your own, if you so desired (big job, though!).  Similarly, the skills and abilities classes can be extended or replaced.

For instance, if you want to have a priest class who heals for 7 to 10 points per level, you could use the Mars.EffectManager to register an ability thus:

effect = new HealEffect("heal effect");
effect.setMinInstantHeal(7*iCharLevel);
effect.setMaxInstantHeal(10*iCharLevel);

[edit - on reflection, there are better places to do the scaling!]

But you could just as easily alter that code to make it flat-rate, by removing level in the calcs altogether.  That would be a hybrid.  Similarly, you could choose to extent the library with your own variation.  Or in the .py configuration file that loads the server plugins you could simply replace the skills and abilities library with your own version.  This file is pretty key to extending the functionality, and that's where I put my own "Hello World" plugin.

So yes, it seems pretty easy to swap functionality in and out, so long as you're happy messing around with Java.

Multiverse - Part 2

I've been playing around with Multiverse some more, specifically with the server plug-ins and configuration.

On further investigation, it turns out that I overstated the work required of a would-be game-developer in my last post.  While it is true that you have complete flexibility in the ruleset and background mechanics of your game, there is also an "easy-mode" option in the event that you're planning on using a diku-type setup.

Multiverse comes with a server plug-in called MARS (Multiverse Agnostic Rule System).  It comprises a bunch of Java packages (multiverse.mars.*) that implement a basic Diku model, with hit points, spawn generators, item and mob templates, down to the detailed level of providing, for instance, an inventory template of 5 bags with 16 slots each.

So here's an example of using Python, Multiverse and MARS to create a spawn-point where Rabid Rabbits, for instance, will appear.  I normally use kinda-hungarian notation, btw, but Multiverse coding practises seem different, and I'm sticking to them for now.

Beforehand, create your RabbitFactory class, which inherits from the ObjectFactory class.  This will spawn the little beggars.  Now, you use it to create the rabbitFactory instance, and then to create a SpawnGenerator instance which uses your rabbitFactory instance to churn out the evil rabid bunnies:

rabbitFactory = RabbitFactory("Rabbit")
rabbitSpawnGen = SpawnGenerator("rabbit generator")
rabbitSpawnGen.setObjectFactory(rabbitFactory)

Next, tell the spawn generator where it is going to pop the relevant members of the family leporidae into existence (you've already defined rabbitLoc's co-ordinates elewhere):

rabbitSpawnGen.setLoc(rabbitLoc)

Easy, innit?  Next, say how many you want to appear at a time (20.. they breed fast), how far from the spawn point they can appear, and a suitably fast respawn rate:

rabbitSpawnGen.setNumSpawns(20)
rabbitSpawnGen.setSpawnRadius(3000)
rabbitSpawnGen.setRespawnTime(10000)

And that's it, but for the all-important Robot Wars-style Activate:

rabbitSpawnGen.activate()

And that's it.  You're now over-straining your server resources by spawning rabbits at a fairly unholy rate.  If you wanted to play early-era Ultima Online-type ecology games, you could alter the RabbitFactory class fairly simply to, for instance, only spawn more rabbits if two or more rabbits are extant at the spawn-point.

Some tasks are trickier than others, of course, but even the more detailed templates, such as that for a mob, are still fairly straightforward to use.  There are just more properties to set: rabbit.setAttackable(true), for instance; or rabbit.setStrength(100), which would be an evil little bugger with pointy, pointy teeth:

Sweet.

And just imagine, you've just spawned 20 of them.  Hopefully in a newbie zone just outside the city gates.  Call them the Bunnies of Arugal.