|
|
You can write classes to generate custom inventories for your
monsters. All you need to do is write a python class that
inherits from wyvern.kernel.monsters.InvGenerator, and override
the generate() method.
Here's an example orc, wiz/rhialto/orc.arch, that uses a
custom inventory. You set the name of your python class
in a string property called "auto-inv":
<!-- an orc that uses our own inventory generator -->
<arch path="monsters/goblin/orc">
<string name="auto-inv" value="wiz/rhialto/python/orc_inv.py"/>
<!-- corpse-chance set to 100% while we're testing it -->
<int name="corpse-chance" value="100"/>
</arch>
|
Here's the python class that generates the Orc inventory:
""" File: orc_inv.py Orc auto-inventory generator.
Author: Steve Yegge, June 10, 2001 Copyright © 2003, Cabochon Technologies, Inc.
"""
from wyvern.lib import * from wyvern.kernel.monsters import InvGenerator
class orc_inv(InvGenerator):
#
# def generate(self, mon):
inv = mon.getInventory()
if self.roll() < 25: self.addItem ( inv, "armor/armor/orcish_chainmail" ) if self.roll() < 25: self.addItem ( inv, "armor/shield/orc_shield" ) if self.roll() < 25: self.addItem ( inv, "armor/boots/orcish_boots" ) if self.roll() < 25: self.addItem ( inv, "armor/helmet/helmet" )
w = self.roll();
if w < 5: self.addItem ( inv, "weapons/orcish_spear" )
elif w < 50: self.addItem ( inv, "weapons/stone_axe" )
elif w < 75: self.addItem ( inv, "weapons/orcish_bow" ) arrows = self.cloneItem ( "weapons/arrow" ) arrows.setQuantity ( Range.randomValue ( 10, 20 )) try: inv.add ( arrows ) except Exception, xc: Kernel.fine ( "wiz/rhialto/python/orc_inv", "generate", "Couldn't add arrows: " + str(xc))
elif w < 95: self.addItem ( inv, "weapons/orcish_scimitar" )
else: self.addItem ( inv, "weapons/broadsword" )
t = self.roll(); if t < 20: self.randomItem ( inv, "random/treasure/random_treasure", 1 ) elif t < 30: self.randomItem ( inv, "random/treasure/random_treasure", 2 )pre>
|
This class, orc_inv, inherits from
wyvern.kernel.monsters.InvGenerator.
InvGenerator provides some useful functions:
- roll: Rolls a random percentage
from 1 to 100.
- addItem: Takes an archetype path
(as a string), clones it, and sticks it in the passed
inventory.
- cloneItem: Clones an item from
its archetype path. You do this when you want to change
the properties on the cloned item before putting it in
the monster's inventory.
In the example above, we set the arrow quantity from
10 to 20 arrows, if orc is getting some arrows.
- randomItem: clones a random
archetype with the specified level.
That's pretty much all there is to it! If you know a little
Jython, you can put anything you want into a monster's inventory.
|