New item: magic pet's whistle.

Why this item:
    In some cases pets may get angry at their owner and attack him.
    This whistle intends to give the player a chance to make his pets friendly again.
    This won't prevent the pet from getting angry again for whatever reason, which
    is ok.

Including: archetype, image, treasure list (for the whistle inventory to work 
           properly), python script which makes the "real work".

Hope to add a map soon to make this available to the players.

A    maps/trunk/python/items/magic_whistle.py
A    arch/trunk/misc/magic_whistle.trs
A    arch/trunk/misc/magic_whistle.arc
AM   arch/trunk/misc/magic_whistle.base.111.png


git-svn-id: svn://svn.code.sf.net/p/crossfire/code/maps/trunk@18827 282e977c-c81d-0410-88c4-b93c2d0d6712
master
kstenger 2013-07-23 18:56:37 +00:00
parent b5768561fd
commit a253caa600
1 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,46 @@
import Crossfire
import random
def tame_angry_pets():
"""
Look for pets (monsters owned by the player) who are not marked as friendly.
Then try to re-pet them with a 1 in 10 change to fail.
Some pets miss their Friendly flag only, others also miss the IsPet property.
Others also have the wrong value for attack_movement which should be PETMOVE for pets.
"""
#Didn't find a way to access this constant from the Crossfire library. Is there?
PETMOVE = 16
player = Crossfire.WhoIsActivator()
if player.Type != Crossfire.Type.PLAYER:
return
Crossfire.SetReturnValue( 1 )
fizzle = True
#Can't do this check by looking at the FriendlyList because we are looking for
#those pets who are *not* in that list. So check for the monsters in the same map
#as the player, owned by it, and yet not friendly.
#Is there a better way than checking all _items_ in the map?
for w in range(player.Map.Width):
for h in range(player.Map.Height):
obj = player.Map.ObjectAt(w,h)
while obj != None:
if obj.Monster and obj.Owner == player and not obj.Friendly: #angry pet
fizzle = False
if random.randint(0,9): #tame
obj.Friendly = True
if not obj.IsPet:
obj.IsPet = True
if obj.AttackMovement != PETMOVE:
obj.AttackMovement = PETMOVE
player.Write( 'Your %s looks at you tenderly, fearless at your enemies.' % obj.Name )
else: #fail
player.Write( 'Your %s is still angry with you.' % obj.Name )
obj = obj.Above
if fizzle:
player.Write('Fzzzzzzzz...')
tame_angry_pets()