def cmdSpawnObject(refobj, spawnLocation, active=False, alert=True, whereFrom='cmd', spawnContainer=None): # creates a new object based on the attributes of the object fed to the function obj = None # if whereFrom == 'cmd': # active = True #print Objects.fromFileList[0].name #print str(refobj) for thing in Objects.fromFileList: if thing.name == str(refobj): obj = thing #print obj if obj == None: print ("Unable to spawn, %s not found." %refobj) return newObject = World.Object(obj.name, obj.description) newObject.currentRoom = spawnLocation newObject.isVisible = obj.isVisible if obj.spawnContainer: newObject.spawnContainer = obj.spawnContainer else: newObject.spawnContainer = spawnContainer newObject.longDescription = obj.longDescription newObject.kind = obj.kind if newObject.kind is not None and hasattr(newObject, 'kind'): newObject.kind.owner = newObject newObject.TIMERS = obj.TIMERS if obj.mobSpawner is not None: mobSpawner = obj.mobSpawner else: mobSpawner = None # if newObject.TIMERS: # newObject.TIMERS.owner = newObject if newObject.kind is not None: if isinstance(newObject.kind, World.item): newObject.kind = World.item() newObject.kind.owner = newObject newObject.kind.isCarryable = obj.kind.isCarryable newObject.kind.respawns = obj.kind.respawns if hasattr(obj.kind, 'itemGrabHandler') and obj.kind.itemGrabHandler is not None: newObject.kind.itemGrabHandler = World.itemGrabHandler() else: newObject.kind.itemGrabHandler = None if newObject.kind.itemGrabHandler is not None: newObject.kind.itemGrabHandler.owner = newObject.kind newObject.kind.objectSpawner = obj.kind.objectSpawner if newObject.kind.objectSpawner: newObject.kind.objectSpawner.owner = newObject.kind newObject.kind.onUse = obj.kind.onUse # if newObject.kind.onUse: # newObject.kind.onUse.owner = newObject.kind if isinstance(newObject.kind, World.container): newObject.kind = World.container() newObject.kind.owner = newObject newObject.kind.inventory = [] newObject.kind.isLocked = obj.kind.isLocked newObject.kind.isCarryable = obj.kind.isCarryable newObject.kind.respawns = obj.kind.respawns newObject.kind.respawnContents = obj.kind.respawnContents if hasattr(obj.kind, 'itemGrabHandler') and obj.kind.itemGrabHandler is not None: newObject.kind.itemGrabHandler = World.itemGrabHandler() else: newObject.kind.itemGrabHandler = None #print newObject.kind.itemGrabHandler # newObject.kind.itemGrabHandler.owner = newObject.kind if newObject.kind.itemGrabHandler is not None: newObject.kind.itemGrabHandler.owner = newObject.kind newObject.kind.objectSpawner = obj.kind.objectSpawner if newObject.kind.objectSpawner: newObject.kind.objectSpawner.owner = newObject.kind if newObject.kind.itemGrabHandler is not None: if obj.kind.itemGrabHandler.notDroppable is not None: newObject.kind.itemGrabHandler.notDroppable = obj.kind.itemGrabHandler.notDroppable else: newObject.kind.itemGrabHandler.notDroppable = False if newObject.kind.objectSpawner: newObject.kind.objectSpawner = World.objectSpawner(newObject.kind) newObject.kind.objectSpawner.TIMERS = obj.kind.objectSpawner.TIMERS newObject.kind.objectSpawner.time = obj.kind.objectSpawner.time newObject.kind.objectSpawner.obj = obj.kind.objectSpawner.obj newObject.kind.objectSpawner.oddsList = obj.kind.objectSpawner.oddsList newObject.kind.objectSpawner.container = obj.kind.objectSpawner.container newObject.kind.objectSpawner.cycles = obj.kind.objectSpawner.cycles newObject.kind.objectSpawner.repeat = obj.kind.objectSpawner.repeat newObject.kind.objectSpawner.timer = World.Timer(newObject.kind.objectSpawner.TIMERS, newObject.kind.objectSpawner.time, newObject.kind.objectSpawner.spawn, [], newObject.kind.objectSpawner, newObject.kind.respawns) newObject.kind.objectSpawner.startingLocation = spawnLocation, if newObject.kind: if newObject.kind.objectSpawner: # print "has object spawner" newObject.kind.objectSpawner.active = active # set the spawned object to active #print "active:" + str(newObject.kind.objectSpawner.active) if mobSpawner is not None: newObject.mobSpawner = World.mobSpawner(newObject) newObject.mobSpawner.TIMERS = mobSpawner.TIMERS newObject.mobSpawner.time = mobSpawner.time newObject.mobSpawner.mob = mobSpawner.mob newObject.mobSpawner.oddsList = mobSpawner.oddsList newObject.mobSpawner.mode = mobSpawner.mode newObject.mobSpawner.cycles = mobSpawner.cycles newObject.mobSpawner.active = mobSpawner.active if spawnLocation is not None: spawnLocation.objects.append(newObject) symbol = '+' if whereFrom == 'cmd': symbol = 's' elif whereFrom == 'objSpawner': symbol = '$' if newObject.kind: if newObject.kind.objectSpawner: if newObject.currentRoom is not None: print symbol +"o " + str(newObject) +": " + newObject.name + " @ [" + str(newObject.currentRoom.region) + ":" + str(newObject.currentRoom.name) + "] (active=" + str(newObject.kind.objectSpawner.active) +")" else: print symbol +"o " + str(newObject) +": " + newObject.name + " @ [None] (active=" + str(newObject.kind.objectSpawner.active) +")" else: print symbol +"o " + str(newObject) +": " + newObject.name + " @ [" + str(newObject.currentRoom.region) + ":" + str(newObject.currentRoom.name) + "]" else: print symbol +"o " + str(newObject) +": " + newObject.name + " @ [" + str(newObject.currentRoom.region) + ":" + str(newObject.currentRoom.name) + "]" for client in Globals.CLIENT_LIST: if Globals.CLIENT_DATA[str(client.addrport())].avatar is not None: if Globals.CLIENT_DATA[str(client.addrport())].avatar.currentRoom == newObject.currentRoom: # if a client is in the room object just appeared in, let it know if newObject.spawnContainer is None and alert: # if not stuffed: client.send_cc("^BA %s appeared.^~\n" %newObject.name) return newObject
def buildObjectFromFile(file): ''' creates an object by constructing it out of details in a file ''' print file if str(file).endswith('~'): print "\n" return path = 'blueprints/obj/' + file with open(path, 'r') as f: fileData = f.readlines() newObject = World.Object('none', 'none') print fileData kind = None isCarryable = None isVisible = None isLocked = False respawns = None objectSpawner = None itemGrabHandler = None repeat = None time = None spawnOdds = None container = None cycles = None repeat = None active = None notDroppable = None objectSpawnerComponent = None itemGrabHandlerComponent = None itemComponent = None mobActive = None mobCycles = None mobMode = None mobSpawnOdds = None mobTime = None mobFile = None mobSpawner = None onUse = None for Data in fileData: if Data.startswith('name='): newObject.name = Data[6:-2] if Data.startswith('description='): newObject.description = Data[13:-2] if Data.startswith('longDescription='): newObject.longDescription = Data[17:-2] if Data.startswith('isVisible='): text = Data[10:-1] if text == 'True': newObject.isVisible = True elif text == 'False': newObject.isVisible = False if Data.startswith('kind='): text = Data[5:-1] #print "kind:" + text if text == 'item': kind = 'item' elif text == 'container': kind = 'container' if Data.startswith('kind.isCarryable='): text = Data[17:-1] #print "isCarryable:" +text if text == 'True': isCarryable = True elif text == 'False': isCarryable = False if Data.startswith('kind.respawns='): text = Data[14:-1] if text == 'True': respawns = True elif text == 'False': respawns = False if Data.startswith('kind.isLocked='): text = Data[14:-1] if text == 'True': isLocked = True if text == 'False': isLocked = False if Data.startswith('kind.respawnContents='): text = Data[21:-1] if text == 'True': respawnContents = True elif text == 'False': respawnContents = False if Data.startswith('kind.objectSpawner='): text = Data[19:-1] if text == 'True': objectSpawner = True elif text == 'False': objectSpawner = False if Data.startswith('kind.objectSpawner.time='): time = int(Data[24:-1]) if Data.startswith('kind.objectSpawner.spawnOdds='): text = Data[29:-1] oddsList = text.split(',') #print "oddsList:" + str(oddsList) nestedOddsList = [] for odds in oddsList: nestedOddsList.append(odds.split(':')) for oddsEntry in nestedOddsList: oddsEntry[1] = int(oddsEntry[1]) if oddsEntry[0] == 'True': oddsEntry[0] = True elif oddsEntry[0] == 'False': oddsEntry[0] = False #print nestedOddsList spawnOdds = nestedOddsList if Data.startswith('kind.objectSpawner.container='): text = Data[29:-1] if text == 'None': container = None else: container = text[1:-1] # this should be a reference to another object container = container.split(', ') if Data.startswith('kind.objectSpawner.cycles='): cycles = int(Data[26:-1]) if Data.startswith('kind.objectSpawner.repeat='): text = Data[26:-1] if text == 'True': repeat = True elif text == 'False': repeat = False if Data.startswith('kind.objectSpawner.active='): text = Data[26:-1] #print "***active:" + text if text == 'True': active = True elif text == 'False': active = False if Data.startswith('kind.itemGrabHandler='): text = Data[21:-1] #print "itemGrabHandler:" +text if text == 'True': itemGrabHandler = True elif text == 'False': itemGrabHandler = False if Data.startswith('kind.itemGrabHandler.notDroppable='): text = Data[34:-1] #print "*** notDroppabletext:" + text if text == 'True': notDroppable = True elif text == 'False': notDroppable = False if Data.startswith('kind.onUse='): text = Data[11:-1] onUse = text if Data.startswith('mobSpawner='): text = Data[11:-1] if text == 'True': mobSpawner = True elif text == 'False': mobSpawner = False if Data.startswith('mobSpawner.mobFile='): text = Data[19:-1] mobFile = text if Data.startswith('mobSpawner.time='): text = Data[16:-1] mobTime = int(text) if Data.startswith('mobSpawner.oddsList='): text = Data[20:-1] oddsList = text.split(',') #print "oddsList:" + str(oddsList) nestedOddsList = [] for odds in oddsList: nestedOddsList.append(odds.split(':')) for oddsEntry in nestedOddsList: oddsEntry[1] = int(oddsEntry[1]) if oddsEntry[0] == 'True': oddsEntry[0] = True elif oddsEntry[0] == 'False': oddsEntry[0] = False #print nestedOddsList mobSpawnOdds = nestedOddsList if Data.startswith('mobSpawner.mode='): text = Data[16:-1] print "mobModeff:" + text mobMode = text if Data.startswith('mobSpawner.cycles='): text = Data[18:-1] mobCycles = int(text) if Data.startswith('mobSpawner.active='): text = Data[18:-1] if text == 'True': mobActive = True elif text == 'False': mobActive = False #print kind if kind == 'item': # print itemGrabHandler # print objectSpawnerComponent # print isCarryable itemComponent = World.item() itemComponent.owner = newObject if kind == 'container': itemComponent = World.container(inventory=[]) itemComponent.owner = newObject if objectSpawner: objectSpawnerComponent = World.objectSpawner(itemComponent, Globals.TIMERS, time, newObject, spawnOdds, container, cycles, repeat, active) else: objectSpawnerComponent = None if itemGrabHandler: itemGrabHandlerComponent = World.itemGrabHandler(notDroppable) else: itemGrabHandlerComponent = None if mobSpawner: mobFileMod = mobFile.split("/") # print mobFileMod # print Globals.mobsFromFile # for mob in Globals.mobsFromFile: # if mob.name == mobFileMod[1]: # mobref = mob #print mobMode mobSpawnerComponent = World.mobSpawner(newObject, Globals.TIMERS, mobTime, mobFileMod[1], mobSpawnOdds, mobCycles, mode=mobMode, active=mobActive) else: mobSpawnerComponent = None #print kind if kind == 'item': # print itemGrabHandler # print objectSpawnerComponent #print isCarryable itemComponent.isCarryable = isCarryable itemComponent.respawns = respawns itemComponent.itemGrabHandler = itemGrabHandlerComponent itemComponent.objectSpawner = objectSpawnerComponent itemComponent.onUse = onUse #itemComponent = World.item(isCarryable, respawns, itemGrabHandlerComponent, objectSpawnerComponent) if kind == 'container': itemComponent.isLocked = isLocked itemComponent.isCarryable = isCarryable itemComponent.respawns = respawns itemComponent.respawnContents = respawnContents itemComponent.itemGrabHandler = itemGrabHandlerComponent itemComponent.objectSpawner = objectSpawnerComponent itemComponent.inventory = [] #itemComponent = World.container(isLocked, isCarryable, respawns, respawnContents, itemGrabHandlerComponent, objectSpawnerComponent) #print newObject.name if kind is not None: newObject.kind = itemComponent if mobSpawner: newObject.mobSpawner = mobSpawnerComponent else: newObject.mobSpawner = None #print newObject.kind fromFileList.append(newObject) # printing suite print "name:" + str(newObject.name) print "description:" + str(newObject.description) print "currentRoom:" + str(newObject.currentRoom) print "isVisible:" + str(newObject.isVisible) print "spawnContainer:" + str(newObject.spawnContainer) print "longDescription:" + str(newObject.longDescription) print "kind:" + str(newObject.kind) print "TIMERS:" + str(newObject.TIMERS) if newObject.kind is not None: if isinstance(newObject.kind, World.item): print "kind.isCarryable:" + str(newObject.kind.isCarryable) print "kind.respawns:" + str(newObject.kind.respawns) print "kind.itemGrabHandler:" + str(newObject.kind.itemGrabHandler) print "kind.objectSpawner:" + str(newObject.kind.objectSpawner) print "kind.onUse:" + str(newObject.kind.onUse) if isinstance(newObject.kind, World.container): print "kind.inventory:" + str(newObject.kind.inventory) print "kind.isLocked:" + str(newObject.kind.isLocked) print "kind.isCarryable:" + str(newObject.kind.isCarryable) print "kind.respawns:" + str(newObject.kind.respawns) print "kind.respawnContents:" + str(newObject.kind.respawnContents) print "kind.itemGrabHandler:" + str(newObject.kind.itemGrabHandler) print "kind.objectSpawner:" + str(newObject.kind.objectSpawner) if newObject.kind.itemGrabHandler is not None: print "kind.itemGrabHandler.notDroppable:" + str(newObject.kind.itemGrabHandler.notDroppable) if newObject.kind.objectSpawner is not None: print "kind.objectSpawner.owner:" + str(newObject.kind.objectSpawner.owner) print "kind.objectSpawner.TIMERS:" + str(newObject.kind.objectSpawner.TIMERS) print "kind.objectSpawner.time:" + str(newObject.kind.objectSpawner.time) print "kind.objectSpawner.obj:" + str(newObject.kind.objectSpawner.obj) print "kind.objectSpawner.oddsList:" + str(newObject.kind.objectSpawner.oddsList) print "kind.objectSpawner.container:" + str(newObject.kind.objectSpawner.container) print "kind.objectSpanwer.cycles:" + str(newObject.kind.objectSpawner.cycles) print "kind.objectSpawner.repeat:" + str(newObject.kind.objectSpawner.repeat) print "kind.objectSpawner.active:" + str(newObject.kind.objectSpawner.active) print "kind.objectSpawner.timer:" + str(newObject.kind.objectSpawner.timer) print "kind.objectSpawner.startingLocation:" + str(newObject.kind.objectSpawner.startingLocation) print "mobSpawner:" + str(newObject.mobSpawner) if newObject.mobSpawner is not None: #print "mobSpawner.mobFile:" + str(newObject.mobSpawner.mobFile) print "mobSpawner.time:" + str(newObject.mobSpawner.time) print "mobSpawner.oddsList:" + str(newObject.mobSpawner.oddsList) print "mobSpawner.mode:" + str(newObject.mobSpawner.mode) print "mobSpawner.cycles:" + str(newObject.mobSpawner.cycles) print "mobSpawner.active:" + str(newObject.mobSpawner.active) print "\n"