Example #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())
Example #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)
Example #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)
Example #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())
Example #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]
Example #6
0
	def __init__(self):
		EventReceiver.__init__(self)

		commandExecutionHandler = EventHandler()

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

		self.addEventHandler(commandExecutionHandler)
Example #7
0
    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)
Example #8
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]
Example #9
0
	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)
Example #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()
Example #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)
Example #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)
Example #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
Example #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
Example #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()
Example #16
0
	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)
Example #17
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)
Example #18
0
 def __init__(self):
     EventReceiver.__init__(self)
     EventEmitter.__init__(self, None)
Example #19
0
	def __init__(self):
		EventReceiver.__init__(self)
		EventEmitter.__init__(self, None)
Example #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)
Example #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)