Changeset 135
- Timestamp:
- 04/26/08 15:14:21 (7 months ago)
- Files:
-
- adventure/movable.py (added)
- adventure/place.py (modified) (3 diffs)
- adventure/player.py (modified) (3 diffs)
- adventure/thing.py (modified) (3 diffs)
- adventure/world.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
adventure/place.py
r131 r135 19 19 20 20 from xmpp import Message, Presence, NS_MUC_USER 21 22 from thing import NonPlayableCharacter 21 23 22 24 class Place: … … 45 47 message = '/me disintegrates' 46 48 47 if player.is_npc:49 if isinstance(player, NonPlayableCharacter): 48 50 player.trigger_event('on-self-leave') 49 51 self.npcs.remove(player) … … 87 89 self.broadcast_message(player.name, message) 88 90 89 if player.is_npc:91 if isinstance(player, NonPlayableCharacter): 90 92 self.npcs.append(player) 91 93 player.trigger_event('on-self-enter') adventure/player.py
r134 r135 3 3 # MUDMUC 4 4 # player.py 5 # Copyright (c) 2008 Thibaut G IRKA, Anaël Verrier5 # Copyright (c) 2008 Thibaut Girka, Anaël Verrier 6 6 7 7 # This program is free software; you can redistribute it and/or modify … … 23 23 from sha import sha 24 24 25 from thing import Thing26 25 from xmpp import Message, Presence, NS_MUC_USER, NS_VCARD, Node 27 26 28 class Player( object):27 class Player(Movable): 29 28 def __init__(self, world, name, jid): 30 self.world = world 31 self.name = name 32 self.jid = unicode(jid) 33 self.place = None 34 self.presence = None 35 36 self.vcard = None 37 38 self.is_npc = False 39 29 Movable.__init__(self, world, name, jid) 40 30 self.inventory = list() 41 42 def set_vcard(self, image=None, birthday=None):43 vcard = Node(NS_VCARD + ' vCard')44 vcard.addChild(node=Node('NICKNAME', {}, self.name))45 if image:46 if not isabs(image):47 image = path_join(self.world.data_dir, image)48 if isfile(image):49 file = open(image, 'rb')50 data = file.read()51 encoded_data = encodestring(data)52 mime = guess_mimetype(image)[0]53 file.close()54 photo = vcard.setTag('PHOTO')55 photo.addChild(node=Node('TYPE', {}, mime))56 photo.addChild(node=Node('BINVAL', {}, encoded_data))57 58 vcard_pres = self.presence.getTag(NS_VCARD + ':x:update x')59 if not vcard_pres:60 vcard_pres = self.presence.setTag(NS_VCARD + ':x:update x')61 vcard_pres.addChild(node=Node('photo', {},62 sha(data).hexdigest()))63 64 if birthday:65 vcard.addChild(node=Node('BDAY', {}, birthday))66 #TODO: DESC67 self.vcard = vcard68 31 69 32 def send_message(self, fromresource, text, subject=None, … … 82 45 pres.setTo(self.jid) 83 46 self.world.send(fromresource, pres) 84 85 def say(self, text, target=None):86 """ Make the player say something. If target is None, broadcast """87 if target is None:88 self.place.broadcast_message(self.name, text)89 else:90 target.send_message(self.name, text)91 92 def move_to(self, to_, warning=True):93 """ Move the player to its new place """94 oldplace = self.place95 self.place = to_96 if self.place:97 self.place.player_entered(self, oldplace)98 elif warning:99 self.send_message(None,100 'Sorry! The room isn\'t available!\n'101 'It\'s a bug for sure '102 '(either in the data '103 'either in the engine) :/')104 if oldplace is not None:105 oldplace.player_leaved(self)106 47 107 def fix_presence(self, role=None, affiliation=None): 108 """ 109 Fix presence: Remove double presence tag and set 110 the specified role and affiliation 111 """ 112 if not role: 113 if self.is_npc: 114 role = 'participant' 115 affiliation = 'member' 116 else: 117 role = 'visitor' 118 affiliation = 'none' 119 pres = Presence(node=self.presence) 120 tag_x = pres.getTag(NS_MUC_USER + ' x') 121 if not tag_x: 122 tag_x = pres.setTag(NS_MUC_USER + ' x') 123 tag_item = tag_x.getTag(NS_MUC_USER + ' item') 124 if not tag_item: 125 tag_item = tag_x.setTag(NS_MUC_USER + ' item') 126 tag_item.setAttr('affiliation', affiliation) 127 tag_item.setAttr('role', role) 128 return pres 48 def fix_presence(self, role='visitor', affiliation='none'): 49 return Movable.fix_presence(self, role, affiliation) 129 50 130 131 class NonPlayableCharacter(Player, Thing):132 def __init__(self, world, name, jid, place):133 Player.__init__(self, world, name, jid)134 Thing.__init__(self, world, name, place)135 136 self.on_self_enter = list()137 self.on_self_leave = list()138 139 self.is_npc = True140 141 adventure/thing.py
r131 r135 17 17 # along with this program; if not, write to the Free Software 18 18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 20 from movable import Movable 19 21 20 22 class Thing: … … 113 115 # <follow [target="actor|self|name"] /> 114 116 elif action['name'] == 'follow': 115 if target.place is not None and not target.is_npc:117 if target.place is not None and not isinstance(target, NonPlayableCharacter): 116 118 forbidden_places = params.split(',') 117 119 for i in xrange(len(forbidden_places)): … … 225 227 return True 226 228 return False 229 230 class NonPlayableCharacter(Movable, Thing): 231 def __init__(self, world, name, jid, place): 232 Movable.__init__(self, world, name, jid) 233 Thing.__init__(self, world, name, place) 234 235 self.on_self_enter = list() 236 self.on_self_leave = list() 237 238 def fix_presence(self, role='participant', affiliation='member'): 239 return Movable.fix_presence(self, role, affiliation) 240 adventure/world.py
r131 r135 25 25 26 26 from place import Place 27 from player import Player , NonPlayableCharacter28 from thing import Thing 27 from player import Player 28 from thing import Thing, NonPlayableCharacter 29 29 30 30 class World:
