|
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:
<span class='string'>"""</span> <span class='keyword'></span>File<span class='keyword'></span>: <span class='keyword'></span>orc_inv<span class='keyword'></span>.<span class='keyword'></span>py<span class='keyword'></span><br><span class='keyword'></span>Orc<span class='keyword'></span> <span class='keyword'></span>auto<span class='keyword'></span>-<span class='keyword'></span>inventory<span class='keyword'></span> <span class='keyword'></span>generator<span class='keyword'></span>.<br><br><span class='keyword'></span>Author<span class='keyword'></span>: <span class='keyword'></span>Steve<span class='keyword'></span> <span class='keyword'></span>Yegge<span class='keyword'></span>, <span class='keyword'></span>June<span class='keyword'></span> <span class='keyword'></span>10<span class='keyword'></span>, <span class='keyword'></span>2001<span class='keyword'></span><br><span class='keyword'></span>Copyright<span class='keyword'></span> � <span class='keyword'></span>2003<span class='keyword'></span>, <span class='keyword'></span>Cabochon<span class='keyword'></span> <span class='keyword'></span>Technologies<span class='keyword'></span>, <span class='keyword'></span>Inc<span class='keyword'></span>.<br><br><span class='string'>"""</span><br><br><span class='keyword'></span>from<span class='keyword'></span> <span class='keyword'></span>wyvern<span class='keyword'></span>.<span class='keyword'></span>lib<span class='keyword'></span> <span class='keyword'></span>import<span class='keyword'></span> *<br><span class='keyword'></span>from<span class='keyword'></span> <span class='keyword'></span>wyvern<span class='keyword'></span>.<span class='keyword'></span>kernel<span class='keyword'></span>.<span class='keyword'></span>monsters<span class='keyword'></span> <span class='keyword'></span>import<span class='keyword'></span> <span class='keyword'></span>InvGenerator<span class='keyword'></span><br><br><span class='keyword'>class</span> <span class='function'>orc_inv</span>(InvGenerator):<br><br><span class='comment'> # generates the inventory for an orc</span><br> #<br><span class='comment'> # Pass: the orc to create inventory for</span><br><span class='comment'> # Return: nothing, but puts the items</span><br><span class='comment'> # into the orc's inventory</span><br> #<br> <span class='keyword'>def</span> <span class='function'>generate</span>(self, mon):<br><br> <span class='keyword'></span>inv<span class='keyword'></span> = <span class='keyword'></span>mon<span class='keyword'></span>.<span class='keyword'></span>getInventory<span class='keyword'></span>()<br><br><span class='comment'> # Add misc armor - we re-roll for each piece, so each orc</span><br><span class='comment'> # has a 25% chance of having chainmail, 25% of a shield, etc.</span><br><span class='comment'> # Any given orc can have from zero to four pieces of armor.</span><br><br> <span class='keyword'></span>if<span class='keyword'></span> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>roll<span class='keyword'></span>() < <span class='keyword'></span>25<span class='keyword'></span>:<br> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>addItem<span class='keyword'></span> ( <span class='keyword'></span>inv<span class='keyword'></span>, <span class='string'>"<span class='keyword'></span>armor<span class='keyword'></span>/<span class='keyword'></span>armor<span class='keyword'></span>/<span class='keyword'></span>orcish_chainmail<span class='keyword'></span>"</span> )<br> <span class='keyword'></span>if<span class='keyword'></span> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>roll<span class='keyword'></span>() < <span class='keyword'></span>25<span class='keyword'></span>:<br> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>addItem<span class='keyword'></span> ( <span class='keyword'></span>inv<span class='keyword'></span>, <span class='string'>"<span class='keyword'></span>armor<span class='keyword'></span>/<span class='keyword'></span>shield<span class='keyword'></span>/<span class='keyword'></span>orc_shield<span class='keyword'></span>"</span> )<br> <span class='keyword'></span>if<span class='keyword'></span> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>roll<span class='keyword'></span>() < <span class='keyword'></span>25<span class='keyword'></span>:<br> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>addItem<span class='keyword'></span> ( <span class='keyword'></span>inv<span class='keyword'></span>, <span class='string'>"<span class='keyword'></span>armor<span class='keyword'></span>/<span class='keyword'></span>boots<span class='keyword'></span>/<span class='keyword'></span>orcish_boots<span class='keyword'></span>"</span> )<br> <span class='keyword'></span>if<span class='keyword'></span> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>roll<span class='keyword'></span>() < <span class='keyword'></span>25<span class='keyword'></span>:<br> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>addItem<span class='keyword'></span> ( <span class='keyword'></span>inv<span class='keyword'></span>, <span class='string'>"<span class='keyword'></span>armor<span class='keyword'></span>/<span class='keyword'></span>helmet<span class='keyword'></span>/<span class='keyword'></span>helmet<span class='keyword'></span>"</span> )<br><br><span class='comment'> # we'll choose one weapon, so we only do one roll</span><br> <span class='keyword'></span>w<span class='keyword'></span> = <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>roll<span class='keyword'></span>();<br><br><span class='comment'> # 5% chance for a spear</span><br> <span class='keyword'></span>if<span class='keyword'></span> <span class='keyword'></span>w<span class='keyword'></span> < <span class='keyword'></span>5<span class='keyword'></span>:<br> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>addItem<span class='keyword'></span> ( <span class='keyword'></span>inv<span class='keyword'></span>, <span class='string'>"<span class='keyword'></span>weapons<span class='keyword'></span>/<span class='keyword'></span>orcish_spear<span class='keyword'></span>"</span> )<br><br><span class='comment'> # 45% chance for an axe</span><br> <span class='keyword'></span>elif<span class='keyword'></span> <span class='keyword'></span>w<span class='keyword'></span> < <span class='keyword'></span>50<span class='keyword'></span>:<br> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>addItem<span class='keyword'></span> ( <span class='keyword'></span>inv<span class='keyword'></span>, <span class='string'>"<span class='keyword'></span>weapons<span class='keyword'></span>/<span class='keyword'></span>stone_axe<span class='keyword'></span>"</span> )<br><br><span class='comment'> # 25% chance for a bow and arrows</span><br> <span class='keyword'></span>elif<span class='keyword'></span> <span class='keyword'></span>w<span class='keyword'></span> < <span class='keyword'></span>75<span class='keyword'></span>:<br> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>addItem<span class='keyword'></span> ( <span class='keyword'></span>inv<span class='keyword'></span>, <span class='string'>"<span class='keyword'></span>weapons<span class='keyword'></span>/<span class='keyword'></span>orcish_bow<span class='keyword'></span>"</span> )<br> <span class='keyword'></span>arrows<span class='keyword'></span> = <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>cloneItem<span class='keyword'></span> ( <span class='string'>"<span class='keyword'></span>weapons<span class='keyword'></span>/<span class='keyword'></span>arrow<span class='keyword'></span>"</span> )<br> <span class='keyword'></span>arrows<span class='keyword'></span>.<span class='keyword'></span>setQuantity<span class='keyword'></span> ( <span class='keyword'></span>Range<span class='keyword'></span>.<span class='keyword'></span>randomValue<span class='keyword'></span> ( <span class='keyword'></span>10<span class='keyword'></span>, <span class='keyword'></span>20<span class='keyword'></span> ))<br> <span class='keyword'></span>try<span class='keyword'></span>:<br> <span class='keyword'></span>inv<span class='keyword'></span>.<span class='keyword'></span>add<span class='keyword'></span> ( <span class='keyword'></span>arrows<span class='keyword'></span> )<br> <span class='keyword'></span>except<span class='keyword'></span> <span class='keyword'></span>Exception<span class='keyword'></span>, <span class='keyword'></span>xc<span class='keyword'></span>:<br> <span class='keyword'></span>Kernel<span class='keyword'></span>.<span class='keyword'></span>fine<span class='keyword'></span> ( <span class='string'>"<span class='keyword'></span>wiz<span class='keyword'></span>/<span class='keyword'></span>rhialto<span class='keyword'></span>/<span class='keyword'></span>python<span class='keyword'></span>/<span class='keyword'></span>orc_inv<span class='keyword'></span>"</span>,<br> <span class='string'>"<span class='keyword'></span>generate<span class='keyword'></span>"</span>,<br> <span class='string'>"<span class='keyword'></span>Couldn<span class='keyword'></span>'<span class='keyword'></span>t<span class='keyword'></span> <span class='keyword'></span>add<span class='keyword'></span> <span class='keyword'></span>arrows<span class='keyword'></span>: "</span> + <span class='keyword'></span>str<span class='keyword'></span>(<span class='keyword'></span>xc<span class='keyword'></span>))<br><br><span class='comment'> # 20% chance for an orcish scimitar</span><br> <span class='keyword'></span>elif<span class='keyword'></span> <span class='keyword'></span>w<span class='keyword'></span> < <span class='keyword'></span>95<span class='keyword'></span>:<br> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>addItem<span class='keyword'></span> ( <span class='keyword'></span>inv<span class='keyword'></span>, <span class='string'>"<span class='keyword'></span>weapons<span class='keyword'></span>/<span class='keyword'></span>orcish_scimitar<span class='keyword'></span>"</span> )<br><br><span class='comment'> # 5% chance for a broadsword</span><br> <span class='keyword'></span>else<span class='keyword'></span>:<br> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>addItem<span class='keyword'></span> ( <span class='keyword'></span>inv<span class='keyword'></span>, <span class='string'>"<span class='keyword'></span>weapons<span class='keyword'></span>/<span class='keyword'></span>broadsword<span class='keyword'></span>"</span> )<br><br><br><span class='comment'> # 30% chance of random treasure:</span><br><span class='comment'> # 20% chance for random level 1 treasure</span><br><span class='comment'> # 10% chance for random level 2 treasure</span><br> <span class='keyword'></span>t<span class='keyword'></span> = <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>roll<span class='keyword'></span>();<br> <span class='keyword'></span>if<span class='keyword'></span> <span class='keyword'></span>t<span class='keyword'></span> < <span class='keyword'></span>20<span class='keyword'></span>:<br> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>randomItem<span class='keyword'></span> ( <span class='keyword'></span>inv<span class='keyword'></span>, <span class='string'>"<span class='keyword'></span>random<span class='keyword'></span>/<span class='keyword'></span>treasure<span class='keyword'></span>/<span class='keyword'></span>random_treasure<span class='keyword'></span>"</span>, <span class='keyword'></span>1<span class='keyword'></span> )<br> <span class='keyword'></span>elif<span class='keyword'></span> <span class='keyword'></span>t<span class='keyword'></span> < <span class='keyword'></span>30<span class='keyword'></span>:<br> <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>randomItem<span class='keyword'></span> ( <span class='keyword'></span>inv<span class='keyword'></span>, <span class='string'>"<span class='keyword'></span>random<span class='keyword'></span>/<span class='keyword'></span>treasure<span class='keyword'></span>/<span class='keyword'></span>random_treasure<span class='keyword'></span>"</span>, <span class='keyword'></span>2<span class='keyword'></span> )</<span class='keyword'></span>pre<span class='keyword'></span>>
|
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.
|