Update of /cvsroot/wpdev/xmlscripts/scripts/housing
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22468
Modified Files:
__init__.py deed.py house.py
Log Message:
gate fix
Index: deed.py
===================================================================
RCS file: /cvsroot/wpdev/xmlscripts/scripts/housing/deed.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** deed.py 17 Oct 2004 01:20:35 -0000 1.1
--- deed.py 18 Oct 2004 12:05:22 -0000 1.2
***************
*** 0 ****
--- 1,94 ----
+
+ from wolfpack import tr, console
+ import wolfpack
+ from wolfpack.consts import *
+ import housing
+ from wolfpack.utilities import hex2dec
+
+ #
+ # Get placement information from the multi definition
+ #
+ def getPlacementData(definition, dispid = 0, xoffset = 0, yoffset = 0, zoffset = 0):
+ node = wolfpack.getdefinition(WPDT_MULTI, definition)
+
+ if not node:
+ return (dispid, xoffset, yoffset, zoffset) # Return, wrong definition
+
+ if node.hasattribute('inherit'):
+ (dispid, xoffset, yoffset, zoffset) = getPlacementData(node.getattribute('inherit'), dispid, xoffset, yoffset, zoffset)
+
+ count = node.childcount
+ for i in range(0, count):
+ subnode = node.getchild(i)
+ if subnode.name == 'id': # Found the display id
+ dispid = hex2dec(subnode.value)
+ elif subnode.name == 'inherit': # Inherit another definition
+ if subnode.hasattribute('id'):
+ (dispid, xoffset, yoffset, zoffset) = getPlacementData(subnode.getattribute('id'), dispid, xoffset, yoffset, zoffset)
+ else:
+ (dispid, xoffset, yoffset, zoffset) = getPlacementData(subnode.value, dispid, xoffset, yoffset, zoffset)
+ elif subnode.name == 'placement': # Placement info
+ xoffset = hex2dec(subnode.getattribute('xoffset', '0'))
+ yoffset = hex2dec(subnode.getattribute('yoffset', '0'))
+ zoffset = hex2dec(subnode.getattribute('zoffset', '0'))
+
+ return (dispid, xoffset, yoffset, zoffset)
+
+ #
+ # Checks if the deed is ok
+ #
+ def checkDeed(player, item):
+ # Has to be in our belongings
+ if not player.canreach(item, -1):
+ player.socket.clilocmessage(1042001)
+ return False
+
+ # We may only own one house (Same for gamemasters -> registry)
+ house = housing.findHouse(player)
+ if house:
+ player.socket.clilocmessage(501271)
+ return False
+
+ # Does this deed have a multi section assigned to it?
+ if not item.hastag('section'):
+ player.socket.sysmessage(tr('This deed is broken.'))
+ return False
+
+ return True
+
+ #
+ # Do the basic checks first
+ #
+ def onUse(player, item):
+ if not checkDeed(player, item):
+ return True
+
+ (dispid, xoffset, yoffset, zoffset) = getPlacementData(str(item.gettag('section')))
+
+ if dispid == 0:
+ player.socket.sysmessage(tr('This deed is broken.'))
+ return True
+
+ player.socket.clilocmessage(1010433)
+ player.socket.attachmultitarget("housing.deed.placement", dispid - 0x4000, [item.serial], xoffset, yoffset, zoffset)
+ return True
+
+ #
+ # Target
+ #
+ def placement(player, arguments, target):
+ deed = wolfpack.finditem(arguments[0])
+ if not checkDeed(player, deed):
+ return
+
+ if not player.canreach(target.pos, 20):
+ player.socket.sysmessage('You can\'t reach that.')
+ return
+
+ house = wolfpack.addmulti(str(deed.gettag('section')))
+ house.owner = player
+ house.moveto(target.pos)
+ house.update()
+
+ housing.registerHouse(house)
+
Index: house.py
===================================================================
RCS file: /cvsroot/wpdev/xmlscripts/scripts/housing/house.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** house.py 17 Oct 2004 01:20:35 -0000 1.1
--- house.py 18 Oct 2004 12:05:22 -0000 1.2
***************
*** 5,8 ****
--- 5,103 ----
from wolfpack.utilities import hex2dec
import housing
+ from housing.consts import *
+
+ #
+ # CoOwner management
+ # Get a list of character STRINGS(!)
+ # Serials that are coowners of the house
+ #
+ def getCoOwners(house):
+ if not house:
+ return []
+
+ coowners = []
+ if house.hastag('coowners'):
+ coowners = str(house.gettag('coowners')).split(',')
+
+ return coowners
+
+ #
+ # Add a coowner to this house
+ #
+ def addCoOwner(house, coowner):
+ if not coowner or not house:
+ return
+
+ coowners = getCoOwner(house)
+ serial = str(coowner.serial)
+
+ if serial not in coowners:
+ coowners.append(serial)
+ house.settag('coowners', ','.join(coowners))
+
+ #
+ # Remove a co-owner from the house
+ #
+ def removeCoOwner(house, coowner):
+ if not house or not coowner:
+ return
+
+ coowners = getCoOwners(house)
+ serial = str(coowner.serial)
+ changed = False
+
+ while serial in coowners:
+ coowners.remove(serial)
+ changed = True
+
+ if changed:
+ house.settag('coowners', ','.join(coowners))
+
+ #
+ # Friends management
+ # Get a list of character STRINGS(!)
+ # Serials that are friends of the house
+ #
+ def getFriends(house):
+ if not house:
+ return []
+
+ friends = []
+ if house.hastag('friends'):
+ friends = str(house.gettag('friends')).split(',')
+
+ return friends
+
+ #
+ # Add a friend to this house
+ #
+ def addFriend(house, friend):
+ if not friend or not house:
+ return
+
+ friends = getFriends(house)
+ serial = str(friend.serial)
+
+ if serial not in friends:
+ friends.append(serial)
+ house.settag('friends', ','.join(friends))
+
+ #
+ # Remove a friend from the house
+ #
+ def removeFriend(house, friend):
+ if not house or not friend:
+ return
+
+ friends = getFriends(house)
+ serial = str(friend.serial)
+ changed = False
+
+ while serial in friends:
+ friends.remove(serial)
+ changed = True
+
+ if changed:
+ house.settag('friends', ','.join(friends))
#
***************
*** 13,17 ****
#
! # Register house
#
def onAttach(house):
--- 108,112 ----
#
! # Register house on load
#
def onAttach(house):
***************
*** 19,23 ****
#
! # Unregister house
#
def onDetach(house):
--- 114,118 ----
#
! # Unregister house on unload/deletion
#
def onDetach(house):
***************
*** 129,133 ****
#
def isCoOwner(player, house):
! return False
#
--- 224,230 ----
#
def isCoOwner(player, house):
! coowners = getCoOwners(house)
! serial = str(player.serial)
! return serial in coowners
#
***************
*** 136,140 ****
#
def isFriend(player, house):
! return False
#
--- 233,239 ----
#
def isFriend(player, house):
! friends = getFriends(house)
! serial = str(player.serial)
! return serial in friends
#
Index: __init__.py
===================================================================
RCS file: /cvsroot/wpdev/xmlscripts/scripts/housing/__init__.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** __init__.py 17 Oct 2004 01:20:35 -0000 1.1
--- __init__.py 18 Oct 2004 12:05:22 -0000 1.2
***************
*** 1,3 ****
--- 1,5 ----
+ import wolfpack
+
#
# Global house registry
***************
*** 20,21 ****
--- 22,33 ----
if serial in HOUSES:
del HOUSES[serial]
+
+ #
+ # Find a house for the given character in the registry
+ #
+ def findHouse(player):
+ serial = player.serial
+ if serial in HOUSES:
+ return wolfpack.finditem(HOUSES[serial])
+ else:
+ return None
|