예제 #1
0
    def __init__(self):
        EventReceiver.__init__(self)
        attributes = {
            "playerSemaphore": threading.BoundedSemaphore(1),
            "npcSemaphore": threading.BoundedSemaphore(1),
            "roomID": "",
            "name": "",
            "description": [],
            "exits": [],
            "players": [],
            "npcs": [],
            "spawnableNPCs": [],
            "updateRate": 0,
        }

        for key in attributes.keys():
            self.attributes[key] = attributes[key]

        self.addEventHandler(PlayerEnteredHandler())
        self.addEventHandler(PlayerExitedHandler())
        self.addEventHandler(PlayerLogoutHandler())
        self.addEventHandler(ActorMovedHandler())
        self.addEventHandler(WasObservedHandler())
        self.addEventHandler(ActorObservedHandler())
        self.addEventHandler(ActorEmotedHandler())
예제 #2
0
    def __init__(self, templateJson, room):
        import EventHandlers.SpawnTemplate

        EventReceiver.__init__(self)
        EventEmitter.__init__(self, None)

        attributes = {
            'npcID': '',
            'npcs': [],
            'wanderRate': .5,
            'spawnRate': .5,
            'room': room
        }

        for key in attributes.keys():
            self.attributes[key] = attributes[key]

        for key in templateJson.keys():
            if key == 'eventHandlers':
                for element in templateJson[key]:
                    adjusters = (
                        lambda dictionary: dictionary.has_key('adjusters') and
                        dictionary['adjusters'] or None)(element)

                    self.addEventHandlerByNameWithAdjusters(
                        element['name'], adjusters)
            else:
                self.attributes[key] = templateJson[key]

        room.addEventSubscriber(self)
예제 #3
0
	def __init__(self, templateJson, room):
		import EventHandlers.SpawnTemplate
		
		EventReceiver.__init__(self)
		EventEmitter.__init__(self, None)
		
		attributes = {
			'npcID'		: '',
			'npcs'		: [],
			'wanderRate'	: .5,
			'spawnRate'	: .5,
			'room'		: room
		}
		
		for key in attributes.keys():
			self.attributes[key] = attributes[key]
			
		for key in templateJson.keys():
			if key == 'eventHandlers':
				for element in templateJson[key]:
					adjusters = (lambda dictionary: dictionary.has_key('adjusters') and dictionary['adjusters'] or None)(element)
					
					self.addEventHandlerByNameWithAdjusters(element['name'], adjusters)
			else:
				self.attributes[key] = templateJson[key]
		
		room.addEventSubscriber(self)
예제 #4
0
	def __init__(self):
		EventReceiver.__init__(self)
		attributes = {
			'actorID'		: '',
			'uniqueID'		: '',
			'name'			: '',
			'description'	: [],
			'race'			: '',
			'gender'		: '',
			'roomID'		: '',
			'stats'			: {
									'strength'		: 0,
									'constitution'	: 0,
									'agility'		: 0,
									'energy'		: 0,
									'focus'			: 0,
									'awareness'		: 0
			},
			'currentHP'		: 0,
			'maxHP'			: 0,
			'currentMana'	: 0,
			'maxMana'		: 0
		}
		
		for key in attributes.keys():
			self.attributes[key] = attributes[key]
			
		self.addEventHandler(WasObservedEventHandler())
예제 #5
0
    def __init__(self):
        EventReceiver.__init__(self)
        EventEmitter.__init__(self, None)

        attributes = {'name': '', 'destination': '', 'isHidden': False}

        for key in attributes.keys():
            self.attributes[key] = attributes[key]
예제 #6
0
	def __init__(self):
		EventReceiver.__init__(self)

		commandExecutionHandler = EventHandler()

		commandExecutionHandler.attributes['signature'] = 'execute_command'
		commandExecutionHandler.attributes['function']	= self.execute

		self.addEventHandler(commandExecutionHandler)
예제 #7
0
파일: Menu.py 프로젝트: longstl/python_mud
    def __init__(self, player):
        EventReceiver.__init__(self)

        attributes = {'player': player, 'options': {}}

        for key in attributes.keys():
            self.attributes[key] = attributes[key]

        self.addEventHandlerByNameWithAdjusters(
            'Menu.EventHandlers.MenuOptionChosenHandler.MenuOptionChosenHandler',
            None)
예제 #8
0
파일: Exit.py 프로젝트: longstl/python_mud
	def __init__(self):
		EventReceiver.__init__(self)
		EventEmitter.__init__(self, None)
		
		attributes = {
			'name'			: '',
			'destination'	: '',
			'isHidden'		: False
		}
		
		for key in attributes.keys():
			self.attributes[key] = attributes[key]
예제 #9
0
파일: Menu.py 프로젝트: longstl/python_mud
	def __init__(self, player):
		EventReceiver.__init__(self)
		
		attributes = {
			'player'	: player,
			'options'	: {}
		}
		
		for key in attributes.keys():
			self.attributes[key] = attributes[key]
		
		self.addEventHandlerByNameWithAdjusters('Menu.EventHandlers.MenuOptionChosenHandler.MenuOptionChosenHandler', None)
예제 #10
0
	def __init__(self):
		EventReceiver.__init__(self)
		attributes = {
			'commandList' : {}
		}

		for key in attributes.keys():
			self.attributes[key] = attributes[key]

		self.addEventHandler(CommandExecutionEventHandler())
		
		CommandEngine.instance = self
		
		self.buildCommandList()
예제 #11
0
	def __init__(self, inventoryJson, owner):		
		EventReceiver.__init__(self)
		EventEmitter.__init__(self, None)
		
		self.attributes['items']	= []
		self.attributes['owner']	= owner
		
		if inventoryJson != None:
			for itemJson in inventoryJson['items']:
				item = self.createItem(itemJson)
			
				if item != None:
					self.attributes['items'].append(item)
		
		owner.addEventSubscriber(self)
예제 #12
0
    def __init__(self, inventoryJson, owner):
        EventReceiver.__init__(self)
        EventEmitter.__init__(self, None)

        self.attributes['items'] = []
        self.attributes['owner'] = owner

        if inventoryJson != None:
            for itemJson in inventoryJson['items']:
                item = self.createItem(itemJson)

                if item != None:
                    self.attributes['items'].append(item)

        owner.addEventSubscriber(self)
예제 #13
0
	def __init__(self):
		EventReceiver.__init__(self)
		attributes = {
			'playerSetSemaphore'	: threading.BoundedSemaphore(1),
			'playerMap'				: {},
			'playerList'			: [],
			'npcMap'				: {}
		}
		
		for key in attributes.keys():
			self.attributes[key] = attributes[key]
	
		self.addEventHandler(PlayerLoginEventHandler())
		self.addEventHandler(PlayerLogoutEventHandler())
		self.addEventHandler(BroadcastEventHandler())
		
		ActorEngine.instance = self
예제 #14
0
	def __init__(self):
		EventReceiver.__init__(self)
		attributes = {
			'openConnectionsSemaphore'	: threading.BoundedSemaphore(3),
			'newConnectionSemaphore'	: threading.BoundedSemaphore(1),
			'closedConnectionSemaphore' : threading.BoundedSemaphore(1),
			'connectionList'			: [],
			'newConnections'			: [],
			'closedConnections'			: []
		}
		
		for key in attributes.keys():
			self.attributes[key] = attributes[key]

		self.addEventHandler(PlayerLoginHandler())
		self.addEventHandler(PlayerLogoutHandler())
		
		ConnectionEngine.instance = self
예제 #15
0
	def __init__(self):
		EventReceiver.__init__(self)
		attributes = {
			'roomMap'	: {},
			'roomList'	: []
		}
		
		for key in attributes.keys():
			self.attributes[key] = attributes[key]
				
		
		self.addEventHandler(PlayerLoginEventHandler())
		self.addEventHandler(RoomEnginePlayerLogoutEventHandler())
		self.addEventHandler(ActorMovedEventHandler())
		
		RoomEngine.instance = self
		
		self.buildWorld()
예제 #16
0
파일: Item.py 프로젝트: longstl/python_mud
	def __init__(self, itemJson, inventory):		
		EventReceiver.__init__(self)
		
		attributes = {
			'itemType'		: '',
			'itemClass'		: '',
			'itemID'		: '',
			'name'			: '',
			'pluralName'	: '',
			'description'	: [],
			'inventory'		: inventory,
			'stats'			: {
									'weight':0
			}
		}
		
		for key in attributes.keys():
			self.attributes[key] = attributes[key]
		
		out_adjusters = []
		
		if itemJson != None:
			for key in itemJson.keys():
				if key == 'out_adjusters':
					out_adjusters = itemJson[key]
				else:
					self.attributes[key] = itemJson[key]
			
		self.attributes['adjective'] = (lambda char: 
											((char == 'a' or char == 'e' or char == 'i' or char == 'o' or char == 'u') and 'an') or 'a')(self.attributes['name'].lower()[0])
			
		self.addEventHandlerByNameWithAdjusters('Item.EventHandlers.Item.ActorAttemptedDropHandler', None)
		self.addEventHandlerByNameWithAdjusters('Item.EventHandlers.Item.ItemDroppedHandler', None)
		self.addEventHandlerByNameWithAdjusters('Item.EventHandlers.Item.ActorAttemptedItemGrabHandler', None)
		self.addEventHandlerByNameWithAdjusters('Item.EventHandlers.Item.ActorGrabbedItemHandler', None)
		self.addEventHandlerByNameWithAdjusters('Item.EventHandlers.Item.ActorAttemptedItemEquipHandler', None)
		self.addEventHandlerByNameWithAdjusters('Item.EventHandlers.Item.WasObservedHandler', None)
		
		EventEmitter.__init__(self, out_adjusters)
		
		inventory.addEventSubscriber(self)
예제 #17
0
파일: Actor.py 프로젝트: longstl/python_mud
    def __init__(self, actorJSON):
        import Engine.RoomEngine
        import Engine.ActorEngine
        from Inventory.ActorInventory import ActorInventory
        from AI.AI import AI

        EventReceiver.__init__(self)

        attributes = {
            'id': '',
            'name': '',
            'description': [],
            'race': 'Human',
            'gender': '',
            'roomID': '0',
            'stats': {
                'strength': 0,  #physical skills, inventory limit
                'constitution': 0,  #combat tree, max hp
                'agility': 0,  #stealth tree, dodging
                'energy': 0,  #magic skills, max mana
                'focus': 0,  #psionic skills, mana regen
                'awareness': 0,  #traps tree, searching
                'ingenuity': 0,  #crafting tree, critical hits
                'composure': 0  #support tree, hp regen
            },
            'currentHP': 0,
            'maxHP': 0,
            'currentMana': 0,
            'maxMana': 0,
            'eventAdjusters': {},
            'eventHandlers': {},
            'inventory': None
        }

        out_adjusters = []
        inventory = None

        if actorJSON != None:
            for key in actorJSON.keys():
                if key == 'inventory':
                    inventory = actorJSON[key]
                elif key == 'eventHandlers':
                    for element in actorJSON[key]:
                        adjusters = (
                            lambda dictionary: dictionary.has_key('adjusters')
                            and dictionary['adjusters'] or None)(element)

                        self.addEventHandlerByNameWithAdjusters(
                            element['name'], adjusters)
                elif key == 'out_adjusters':
                    out_adjusters = actorJSON[key]
                elif key == 'AI':
                    self.attributes['AI'] = AI(actorJSON[key])
                else:
                    attributes[key] = actorJSON[key]

            for key in attributes.keys():
                self.attributes[key] = attributes[key]

            Engine.ActorEngine.addEventSubscriber(self)

            startingRoom = Engine.RoomEngine.getRoom(self.attributes['roomID'])

            startingRoom.addEventSubscriber(self)

            self.addEventHandlerByNameWithAdjusters(
                'Actor.EventHandlers.Actor.ActorAttemptedDropHandler', None)
            self.addEventHandlerByNameWithAdjusters(
                'Actor.EventHandlers.Actor.ItemDroppedHandler', None)
            self.addEventHandlerByNameWithAdjusters(
                'Actor.EventHandlers.Actor.ActorInitiatedItemGrabHandler',
                None)
            self.addEventHandlerByNameWithAdjusters(
                'Actor.EventHandlers.Actor.ActorGrabbedItemHandler', None)
            self.addEventHandlerByNameWithAdjusters(
                'Actor.EventHandlers.Actor.ActorAttemptedItemEquipHandler',
                None)
            self.addEventHandlerByNameWithAdjusters(
                'Actor.EventHandlers.Actor.ActorAttemptedItemRemovalHandler',
                None)
            self.addEventHandlerByNameWithAdjusters(
                'Actor.EventHandlers.Actor.ActorMovedFromRoomEventHandler',
                None)
            self.addEventHandlerByNameWithAdjusters(
                'Actor.EventHandlers.Actor.ActorGainedHealthFromTickHandler',
                None)

        #add event handlers specific to this actor's race

        filePath = '{}/Content/races/{}.txt'.format(currentDir,
                                                    self.attributes['race'])
        raceFile = open(filePath, 'r')
        jsonString = raceFile.read()
        jsonObj = json.loads(jsonString)
        handlers = jsonObj['eventHandlers']

        if jsonObj.has_key('out_adjusters'):
            out_adjusters = out_adjusters + jsonObj['out_adjusters']

        raceFile.close()

        for handler in handlers:
            adjusters = (lambda dictionary: dictionary.has_key('adjusters') and
                         dictionary['adjusters'] or None)(handler)

            self.addEventHandlerByNameWithAdjusters(handler['name'], adjusters)

        EventEmitter.__init__(self, out_adjusters)

        if inventory != None:
            self.attributes['inventory'] = ActorInventory(inventory, self)
        else:
            self.attributes['inventory'] = ActorInventory(None, self)
예제 #18
0
 def __init__(self):
     EventReceiver.__init__(self)
     EventEmitter.__init__(self, None)
예제 #19
0
	def __init__(self):
		EventReceiver.__init__(self)
		EventEmitter.__init__(self, None)
예제 #20
0
	def __init__(self, roomJson):
		import threading
		from Exit import Exit
		import Engine.RoomEngine
		from Inventory.RoomInventory import RoomInventory
		from SpawnTemplate import SpawnTemplate
		
		EventReceiver.__init__(self)
		
		attributes = {
			'playerSemaphore'	: threading.BoundedSemaphore(1),
			'roomID'			: '',
			'name'				: '',
			'description'		: [],
			'exits'				: [],
			'players'			: [],
			'npcs'				: [],
			'spawnableNPCs'		: [],
			'inventory'			: None,
			'spawnTemplates'	: []
		}
		
		out_adjusters	= []
		inventory		= None
		spawnTemplates	= None
		
		for key in attributes.keys():
			self.attributes[key] = attributes[key]
			
		for key in roomJson.keys():
			if key == 'exits':
				for exitJson in roomJson[key]:
					exit = Exit()
					for field in exitJson.keys():
						exit.attributes[field] = exitJson[field]
					
					self.attributes[key].append(exit)
			elif key == 'eventHandlers':
				for element in roomJson[key]:
					adjusters = (lambda dictionary: dictionary.has_key('adjusters') and dictionary['adjusters'] or None)(element)
					
					self.addEventHandlerByNameWithAdjusters(element['name'], adjusters)
			elif key == 'inventory':
				inventory = roomJson[key]
			elif key == 'spawnTemplates':
				spawnTemplates = roomJson[key]
			elif key == 'out_adjusters':
				out_adjusters = roomJson[key]
			else:
				self.attributes[key] = roomJson[key]
		
		self.addEventHandlerByNameWithAdjusters('Environment.EventHandlers.Room.ActorAttemptedMovementEventHandler', None)
		self.addEventHandlerByNameWithAdjusters('Environment.EventHandlers.Room.ActorMovedFromRoomEventHandler', None)
		self.addEventHandlerByNameWithAdjusters('Environment.EventHandlers.Room.ActorAddedToRoomEventHandler', None)
		self.addEventHandlerByNameWithAdjusters('Environment.EventHandlers.Room.ActorObservedHandler', None)
		self.addEventHandlerByNameWithAdjusters('Environment.EventHandlers.Room.WasObservedHandler', None)
		self.addEventHandlerByNameWithAdjusters('Environment.EventHandlers.Room.ActorEmotedHandler', None)
		self.addEventHandlerByNameWithAdjusters('Environment.EventHandlers.Room.PlayerLogoutHandler', None)
		self.addEventHandlerByNameWithAdjusters('Environment.EventHandlers.Room.SpellCastAttempted', None)
		self.addEventHandlerByNameWithAdjusters('Environment.EventHandlers.Room.ActorAttemptedItemGrabHandler', None)
		self.addEventHandlerByNameWithAdjusters('Environment.EventHandlers.Room.ActorGrabbedItemHandler', None)
		self.addEventHandlerByNameWithAdjusters('Environment.EventHandlers.Room.ItemDroppedHandler', None)
		
		Engine.RoomEngine.addEventSubscriber(self)
		
		EventEmitter.__init__(self, out_adjusters)
		
		if inventory != None:
			self.attributes['inventory'] = RoomInventory(inventory, self)
		else:
			self.attributes['inventory'] = RoomInventory(None, self)
			
		if spawnTemplates != None:
			for template in spawnTemplates:
				spawnTemplate = SpawnTemplate(template, self)
					
				self.attributes['spawnTemplates'].append(spawnTemplate)
예제 #21
0
    def __init__(self, actorJSON):
        import Engine.RoomEngine
        import Engine.ActorEngine
        from Inventory.ActorInventory import ActorInventory
        from AI.AI import AI

        EventReceiver.__init__(self)

        attributes = {
            "id": "",
            "name": "",
            "description": [],
            "race": "Human",
            "gender": "",
            "roomID": "0",
            "stats": {
                "strength": 0,  # physical skills, inventory limit
                "constitution": 0,  # combat tree, max hp
                "agility": 0,  # stealth tree, dodging
                "energy": 0,  # magic skills, max mana
                "focus": 0,  # psionic skills, mana regen
                "awareness": 0,  # traps tree, searching
                "ingenuity": 0,  # crafting tree, critical hits
                "composure": 0,  # support tree, hp regen
            },
            "currentHP": 0,
            "maxHP": 0,
            "currentMana": 0,
            "maxMana": 0,
            "eventAdjusters": {},
            "eventHandlers": {},
            "inventory": None,
        }

        out_adjusters = []
        inventory = None

        if actorJSON != None:
            for key in actorJSON.keys():
                if key == "inventory":
                    inventory = actorJSON[key]
                elif key == "eventHandlers":
                    for element in actorJSON[key]:
                        adjusters = (
                            lambda dictionary: dictionary.has_key("adjusters") and dictionary["adjusters"] or None
                        )(element)

                        self.addEventHandlerByNameWithAdjusters(element["name"], adjusters)
                elif key == "out_adjusters":
                    out_adjusters = actorJSON[key]
                elif key == "AI":
                    self.attributes["AI"] = AI(actorJSON[key])
                else:
                    attributes[key] = actorJSON[key]

            for key in attributes.keys():
                self.attributes[key] = attributes[key]

            Engine.ActorEngine.addEventSubscriber(self)

            startingRoom = Engine.RoomEngine.getRoom(self.attributes["roomID"])

            startingRoom.addEventSubscriber(self)

            self.addEventHandlerByNameWithAdjusters("Actor.EventHandlers.Actor.ActorAttemptedDropHandler", None)
            self.addEventHandlerByNameWithAdjusters("Actor.EventHandlers.Actor.ItemDroppedHandler", None)
            self.addEventHandlerByNameWithAdjusters("Actor.EventHandlers.Actor.ActorInitiatedItemGrabHandler", None)
            self.addEventHandlerByNameWithAdjusters("Actor.EventHandlers.Actor.ActorGrabbedItemHandler", None)
            self.addEventHandlerByNameWithAdjusters("Actor.EventHandlers.Actor.ActorAttemptedItemEquipHandler", None)
            self.addEventHandlerByNameWithAdjusters("Actor.EventHandlers.Actor.ActorAttemptedItemRemovalHandler", None)
            self.addEventHandlerByNameWithAdjusters("Actor.EventHandlers.Actor.ActorMovedFromRoomEventHandler", None)
            self.addEventHandlerByNameWithAdjusters("Actor.EventHandlers.Actor.ActorGainedHealthFromTickHandler", None)

            # add event handlers specific to this actor's race

        filePath = "{}/Content/races/{}.txt".format(currentDir, self.attributes["race"])
        raceFile = open(filePath, "r")
        jsonString = raceFile.read()
        jsonObj = json.loads(jsonString)
        handlers = jsonObj["eventHandlers"]

        if jsonObj.has_key("out_adjusters"):
            out_adjusters = out_adjusters + jsonObj["out_adjusters"]

        raceFile.close()

        for handler in handlers:
            adjusters = (lambda dictionary: dictionary.has_key("adjusters") and dictionary["adjusters"] or None)(
                handler
            )

            self.addEventHandlerByNameWithAdjusters(handler["name"], adjusters)

        EventEmitter.__init__(self, out_adjusters)

        if inventory != None:
            self.attributes["inventory"] = ActorInventory(inventory, self)
        else:
            self.attributes["inventory"] = ActorInventory(None, self)