Update of /cvsroot/wpdev/xmlscripts/scripts/wolfpack/magic
In directory sc8-pr-cvs1:/tmp/cvs-serv31082/wolfpack/magic
Added Files:
__init__.py circle1.py spell.py utilities.py
Log Message:
Changed scripts to resemble changes in wolfpack.registerglobal and wolfpack.registercommand
Added barebone for new magic system.
--- NEW FILE: __init__.py ---
#===============================================================#
# ) (\_ | WOLFPACK 13.0.0 Scripts #
# (( _/{ "-; | Created by: Correa #
# )).-' {{ ;'` | Revised by: #
# ( ( ;._ \\ ctr | Last Modification: Created #
#===============================================================#
# Main Magic Script #
#===============================================================#
from wolfpack.consts import *
from wolfpack.magic.utilities import *
from wolfpack.magic.spell import *
import wolfpack
# Spell Registry
spells = {}
# Register spell information in the global registry
def registerspell( id, spell ):
global spells
if spells.has_key( id ):
return
spells[ id ] = spell
#
# Set up our global hook on script load
#
def onLoad():
wolfpack.registerglobal( EVENT_CASTSPELL, "wolfpack.magic" )
#
# A Spell has been Selected from our SpellBook
# This part of the code has to be npc safe!
#
# Mode: 0 = Book
def castSpell( char, spell, mode = 0, args = [] ):
if char.dead:
return
socket = char.socket
eventlist = char.events
if not spells.has_key( spell ):
if socket:
socket.log( LOG_ERROR, "Trying to cast unknown spell: %d\n" % spell )
socket.sysmessage( 'ERROR: Unknown Spell' )
return
# We are frozen
if char.frozen:
char.message( 502643 )
return
# We are already casting a spell
if 'wolfpack.magic' in eventlist or ( socket and socket.hastag( 'cast_target' ) ):
char.message( 502642 )
return
# If we are using a spellbook to cast, check if we do have
# the spell in our spellbook (0-based index)
if mode == 0 and not hasSpell( char, spell - 1 ):
char.message( "You don't know the spell you want to cast." )
return
# Are the requirements met?
spell = spells[ spell ]
if not spell.checkrequirements( char, mode ):
return
# Unhide the Caster
if char.hidden:
char.hidden = 0
char.update()
if spell.mantra:
char.say( spell.mantra )
# Precasting
char.events = [ 'wolfpack.magic' ] + eventlist
char.action( ANIM_CASTAREA )
char.addtimer( spell.calcdelay(), 'wolfpack.magic.callback', [ spell.spellid, mode ], 0, 0, "cast_delay" )
def callback( char, args ):
eventlist = char.events
eventlist.remove( 'wolfpack.magic' )
char.events = eventlist
if char.socket:
char.socket.settag( 'cast_target', 1 )
char.socket.attachtarget( 'wolfpack.magic.target_response', args, 'wolfpack.magic.target_cancel', 'wolfpack.magic.target_timeout', 8000 ) # Don't forget the timeout later on
else:
# Callback to the NPC AI ??
pass
# Target Cancel
def target_cancel( char ):
if char.hastag( 'cast_target' ):
char.deltag( 'cast_target' )
# Target Timeout
def target_timeout( char ):
char.message( 'You loose your concentration.' )
fizzle( char )
# Target Response
def target_response( char, args, target ):
# No more npc saftey from here
if not char.socket.hastag( 'cast_target' ):
return
char.socket.deltag( 'cast_target' )
spell = spells[ args[0] ]
mode = args[1]
# Char Targets
if target.char and ( spell.validtarget == TARGET_IGNORE or spell.validtarget == TARGET_CHAR ):
spell.target( char, mode, TARGET_CHAR, target.char )
# Item Target
elif target.item and ( spell.validtarget == TARGET_IGNORE or spell.validtarget == TARGET_ITEM ):
spell.target( char, mode, TARGET_ITEM, target.item )
# Ground Target
else:
char.message( 501857 )
def onCastSpell( char, spell ):
castSpell( char, spell )
# These Events happen for characters who are casting a spell right now
def onDamage( char, type, amount, source ):
char.message( 500641 )
fizzle( char )
def onWalk( char, direction, sequence ):
running = direction & 0x80
direction &= 0x7F
# Just turning
if direction != char.direction:
return
char.message( 500641 )
fizzle( char )
def onWarModeToggle( char, warmode ):
char.message( 500641 )
fizzle( char )
def onLogin( char ):
fizzle( char )
--- NEW FILE: circle1.py ---
from wolfpack.magic import registerspell
from wolfpack.magic.spell import Spell
from wolfpack.magic.utilities import *
class Clumsy ( Spell ):
def __init__( self ):
self.mana = 0
self.reagents = {}
self.valid_targets = TARGET_CHAR
self.spellid = 1
self.circle = 1
self.mantra = 'In Jux Sanct'
def target( self, char, mode, targettype, target ):
char.message( 'You targetted something' )
pass
# Register the spells in this module (wolfpack.magic.circle1)
def onLoad():
Clumsy().register()
pass
--- NEW FILE: spell.py ---
import wolfpack.magic
from wolfpack.magic.utilities import *
# Recursive Function for counting reagents
def countReagents( item, items ):
for key in items.keys():
if key == item.id and item.color == 0:
items[ key ] = max( 0, items[ key ] - item.amount )
return items # Reagents normally dont have content
for subitem in item.content:
items = countReagents( subitem, items )
return items
# Basic Spell Class
class Spell:
mana = 0
circle = 0
reagents = {}
validtarget = TARGET_IGNORE
spellid = None
mantra = None
# Static Method
def register( self ):
if not self.spellid:
raise Exception, 'Trying to register a spell with an unset id: ' + str( self.__class__.__name__ )
wolfpack.magic.registerspell( self.spellid, self )
def __init__( self ):
pass
def calcdelay( self ):
return 250 + ( 250 * self.circle )
def checkrequirements( self, char, mode ):
if mode == MODE_BOOK:
# Check for Mana
if char.mana < self.mana:
char.message( 502625 )
return 0
# Check for Reagents
if len( self.reagents ) > 0:
items = countReagents( char.getbackpack(), self.reagents )
for item in items.keys():
if items[ item ] > 0:
char.message( 502630 )
return 0
return 1
def consumerequirements( self, char, mode ):
return 0
def target( self, char, mode, targettype, target ):
return 0
--- NEW FILE: utilities.py ---
import spellbook
TARGET_CHAR = 1
TARGET_ITEM = 2
TARGET_GROUND = 3
TARGET_IGNORE = 4
REAGENT_BLACKPEARL = 0xf7a
REAGENT_BLOODMOSS = 0xf7b
REAGENT_GARLIC = 0xf84
REAGENT_GINSENG = 0xf85
REAGENT_MANDRAKE = 0xf86
REAGENT_NIGHTSHADE = 0xf88
REAGENT_SULFURASH = 0xf8c
REAGENT_SPIDERSILK = 0xf8d
MODE_BOOK = 0
MODE_SCROLL = 1
MODE_WAND = 2
def fizzle( char ):
# Remove a possible timer/targetrequest
char.dispel( char, 1, "cast_delay" )
eventlist = char.events
eventlist.remove( 'wolfpack.magic' )
char.events = eventlist
char.effect( 0x3735, 1, 30 )
char.soundeffect( 0x5c )
# Check whether the spellbook's of a char have that specific spell
def hasSpell( char, spell ):
book = char.itemonlayer( 1 )
if spellbook.hasspell( book, spell ):
return 1
for book in char.getbackpack().content:
if spellbook.hasspell( book, spell ):
return 1
return 0
|