Update of /cvsroot/wpdev/xmlscripts/scripts/housing
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24789
Added Files:
__init__.py consts.py deed.py house.py security.py sign.py
Log Message:
started housing
--- NEW FILE: consts.py ---
# Access levels for housing
ACCESS_OWNER = 0
ACCESS_COOWNER = 1
ACCESS_FRIEND = 2
ACCESS_ANYONE = 3
--- NEW FILE: sign.py ---
import housing.house
def escapeHtml(text):
text = text.replace('<', '<')
text = text.replace('>', '>')
return text
#
# Show a special tooltip for house signs
#
def onShowTooltip(player, sign, tooltip):
tooltip.reset()
tooltip.add(1061638, "") # A house sign
if not sign.multi:
return
name = 'nothing'
if len(sign.name) != 0:
name = escapeHtml(sign.name)
tooltip.add(1061639, name)
owner = sign.multi.owner
if not owner:
tooltip.add(1061640, "nobody")
else:
tooltip.add(1061640, owner.orgname)
public = housing.house.isPublic(sign.multi)
if public:
tooltip.add(1061641, "")
else:
tooltip.add(1061642, "")
--- NEW FILE: security.py ---
import wolfpack.gumps
from housing.house import checkAccess
from housing.consts import *
#
# Security settings can only be changed by the house owner
#
def onContextCheckVisible(player, item, tag):
return checkAccess(player, item.multi, ACCESS_OWNER)
#
# Show the security setting gump
#
def onContextEntry(player, item, entry):
if entry != 67:
return False
if not checkAccess(player, item.multi, ACCESS_OWNER):
return False
showGump(player, item)
return True
#
# Get the security level for the given item
# 0 Owner Only
# 1 Co Owners
# 2 Friends
# 3 Anyone
#
def getLevel(item):
if item.hastag('security_level'):
return int(item.gettag('security_level'))
return 0
#
# Show the gump for a given securable item
#
def showGump(player, item):
if not item.multi:
return
owner = item.multi.owner
level = getLevel(item)
dialog = wolfpack.gumps.cGump()
dialog.startPage(0)
dialog.addBackground(5054, 220, 160)
dialog.addTiledGump( 10, 10, 200, 20, 5124 )
dialog.addTiledGump( 10, 40, 200, 20, 5124 )
dialog.addTiledGump( 10, 70, 200, 80, 5124 )
dialog.addCheckerTrans( 10, 10, 200, 140 )
dialog.addXmfHtmlGump( 10, 10, 200, 20, 1061276, False, False, 32767 )
dialog.addXmfHtmlGump( 10, 40, 100, 20, 1041474, False, False, 32767 )
if not owner:
dialog.addText( 110, 40, "", 1152 )
else:
dialog.addText( 110, 40, owner.name, 1152 )
if level == 0:
dialog.addButton( 10, 70, 4006, 4007, 1 )
dialog.addXmfHtmlGump( 45, 70, 150, 20, 1061277, False, False, 0x7F18 )
else:
dialog.addButton( 10, 70, 4005, 4007, 1 )
dialog.addXmfHtmlGump( 45, 70, 150, 20, 1061277, False, False, 0x7FFF )
if level == 1:
dialog.addButton( 10, 90, 4006, 4007, 2 )
dialog.addXmfHtmlGump( 45, 90, 150, 20, 1061278, False, False, 0x7F18 )
else:
dialog.addButton( 10, 90, 4005, 4007, 2 )
dialog.addXmfHtmlGump( 45, 90, 150, 20, 1061278, False, False, 0x7FFF )
if level == 2:
dialog.addButton( 10, 110, 4006, 4007, 3 )
dialog.addXmfHtmlGump( 45, 110, 150, 20, 1061279, False, False, 0x7F18 )
else:
dialog.addButton( 10, 110, 4005, 4007, 3 )
dialog.addXmfHtmlGump( 45, 110, 150, 20, 1061279, False, False, 0x7FFF )
if level == 3:
dialog.addButton( 10, 130, 4006, 4007, 4 )
dialog.addXmfHtmlGump( 45, 130, 150, 20, 1061626, False, False, 0x7F18 )
else:
dialog.addButton( 10, 130, 4005, 4007, 4 )
dialog.addXmfHtmlGump( 45, 130, 150, 20, 1061626, False, False, 0x7FFF )
dialog.setArgs([item.serial])
dialog.setCallback("housing.security.callback")
dialog.send(player)
#
# Gump callback
#
def callback(player, arguments, response):
if response.button <= 0 or response.button >= 5:
return
item = wolfpack.finditem(arguments[0])
if item and item.hasscript('housing.security'):
level = response.button - 1
current_level = getLevel(item)
if level == current_level:
player.socket.clilocmessage(1061281)
else:
if level == 0:
item.deltag('security_level')
else:
item.settag('security_level', level)
player.socket.clilocmessage(1061280)
--- NEW FILE: house.py ---
import wolfpack
from wolfpack import console
from wolfpack.consts import *
from wolfpack.utilities import hex2dec
import housing
#
# Is the given house public or private?
#
def isPublic(house):
return True # TODO: Public or Private
#
# Register house
#
def onAttach(house):
housing.registerHouse(house)
#
# Unregister house
#
def onDetach(house):
housing.unregisterHouse(house)
#
# Create the housing items
#
def onCreate(house, definition):
buildHouse(house, definition)
#
# Is the given character the owner of the given house?
#
def isOwner(house, player):
if not house:
return False
if player.gm or house.owner == player:
return True
else:
return False
#
# Place items in the house based on a given house definition
#
def buildHouse(house, definition):
node = wolfpack.getdefinition(WPDT_MULTI, definition)
if not node:
return
if node.hasattribute('inherit'):
value = str(node.getattribute('inherit'))
buildHouse(house, value) # Recursion
for i in range(0, node.childcount):
child = node.getchild(i)
# Inherit another definition
if child.name == 'inherit':
if child.hasattribute('id'):
buildHouse(house, child.getattribute('id'))
else:
buildHouse(house, child.value)
# Add a normal item to the house
elif child.name == 'item':
x = int(child.getattribute('x', '0'))
y = int(child.getattribute('y', '0'))
z = int(child.getattribute('z', '0'))
id = str(child.getattribute('id', ''))
item = wolfpack.additem(id)
item.moveto(house.pos.x + x, house.pos.y + y, house.pos.z + z, house.pos.map)
item.update()
# Add a house door to the house
elif child.name == 'door':
x = int(child.getattribute('x', '0'))
y = int(child.getattribute('y', '0'))
z = int(child.getattribute('z', '0'))
id = hex2dec(child.getattribute('id', ''))
item = wolfpack.additem('housedoor')
item.id = id
item.moveto(house.pos.x + x, house.pos.y + y, house.pos.z + z, house.pos.map)
item.update()
# Add a sign to the house
elif child.name == 'sign':
x = int(child.getattribute('x', '0'))
y = int(child.getattribute('y', '0'))
z = int(child.getattribute('z', '0'))
sign = wolfpack.additem('housesign')
sign.moveto(house.pos.x + x, house.pos.y + y, house.pos.z + z, house.pos.map)
sign.update()
#
# Check if access in this house is allowed to the given item
#
def onCheckSecurity(player, house, item):
if not item.hasscript('housing.security'):
return False
else:
level = housing.security.getLevel(item)
if not checkAccess(player, house, level):
if item.type == 1: # Container
player.socket.clilocmessage(501647) # It's secure
else:
player.socket.clilocmessage(1061637) # It's not accessable
return True
return False
#
# Checks if the given player is an owner of the given house
# NOTE: This does not check higher access levels.
#
def isOwner(player, house):
return player == house.owner
#
# Checks if the given player is an co-owner of the given house
# NOTE: This does not check higher access levels.
#
def isCoOwner(player, house):
return False
#
# Checks if the given player is a friend of the house.
# NOTE: This does not check higher access levels.
#
def isFriend(player, house):
return False
#
# Check the access level of the given char for this house
#
def checkAccess(player, house, level):
if not player or not house or level < 0 or level > 3:
return False # Error Checks
if player.gm or level == ACCESS_ANYONE:
return True
if level >= ACCESS_OWNER and isOwner(player, house):
return True
elif level >= ACCESS_COOWNER and isCoOwner(player, house):
return True
elif level >= ACCESS_FRIEND and isFriend(player, house):
return True
return False
--- NEW FILE: deed.py ---
--- NEW FILE: __init__.py ---
#
# Global house registry
#
HOUSES = {}
#
# Register a house in the global registry
#
def registerHouse(house):
if house.owner:
HOUSES[house.owner.serial] = house.serial
#
# Unregister a house from the global registry
#
def unregisterHouse(house):
if house.owner:
serial = house.owner.serial
if serial in HOUSES:
del HOUSES[serial]
|