def parseTxt( file, map ): warnings = '' count = 0 parseTickCount = 0 createTickCount = 0 propTickCount = 0 moveTickCount = 0 for line in file: step1 = wolfpack.tickcount() # Replace \r and \n's line = line.replace( "\r", "" ) line = line.replace( "\n", "" ) ( id, x, y, z, color ) = line.split( ' ' ) id = hex2dec( id ) baseid = '%x' % id color = hex2dec( color ) x = int( x ) y = int( y ) z = int( z ) step2 = wolfpack.tickcount() newitem = wolfpack.additem( '%s' % baseid ) # Generate a new serial for us step3 = wolfpack.tickcount() newitem.decay = 0 newitem.color = color newitem.id = id step4 = wolfpack.tickcount() newposition = wolfpack.coord( x, y, z, map ) if not isValidPosition( newposition ): newitem.delete() continue newitem.moveto( newposition ) step5 = wolfpack.tickcount() parseTickCount += step2 - step1 createTickCount += step3 - step2 propTickCount += step4 - step3 moveTickCount += step5 - step4 newitem.update() count += 1 print "Parsing: %i ticks" % parseTickCount print "Creating: %i ticks" % createTickCount print "Prop: %i ticks" % propTickCount print "Move: %i ticks" % moveTickCount return ( count, warnings )
def parseTxt(file, map): warnings = "" count = 0 parseTickCount = 0 createTickCount = 0 propTickCount = 0 moveTickCount = 0 for line in file: step1 = wolfpack.tickcount() # Replace \r and \n's line = line.replace("\r", "") line = line.replace("\n", "") (baseid, id, x, y, z, map, color) = line.split(" ") baseid = baseid id = hex2dec(id) color = hex2dec(color) x = int(x) y = int(y) z = int(z) map = int(map) step2 = wolfpack.tickcount() newitem = wolfpack.additem("%s" % baseid) # Generate a new serial for us step3 = wolfpack.tickcount() newitem.decay = 0 newitem.color = color newitem.id = id step4 = wolfpack.tickcount() newitem.moveto(x, y, z, map, 1) step5 = wolfpack.tickcount() parseTickCount += step2 - step1 createTickCount += step3 - step2 propTickCount += step4 - step3 moveTickCount += step5 - step4 newitem.update() count += 1 print "Parsing: %i ticks" % parseTickCount print "Creating: %i ticks" % createTickCount print "Prop: %i ticks" % propTickCount print "Move: %i ticks" % moveTickCount return (count, warnings)
def run(self): while not self.stopped.isSet(): self.lock() process = self.unprocessed[:100] self.unprocessed = self.unprocessed[100:] if DEBUG_SPAWNS == 1: console.log(LOG_MESSAGE, "Found %u spawn items." % len(process)) # Process the designated partition for i in range(0, len(process)): item = wolfpack.finditem(process[i]) # Check if the spawn is valid. valid = item != None if valid and not item.hasscript("spawngem"): valid = 0 if valid and not item.hastag("spawntype") or not item.hastag("spawndef"): valid = 0 if not valid: if DEBUG_SPAWNS == 1: console.log(LOG_WARNING, "Invalid spawn item: 0x%x.\n" % item.serial) pass else: spawntype = int(item.gettag("spawntype")) # 0: Items, 1: NPCs spawndef = str(item.gettag("spawndef")) # Definition # This is either how far the npcs will wander # or how far from the spawn the items will be spawned. area = 0 if item.hastag("area"): area = int(item.gettag("area")) # This is a minimum/maximum spawn interval in minutes mininterval = 1 maxinterval = 1 if item.hastag("interval"): interval = item.gettag("interval") if "," in interval: (mininterval, maxinterval) = interval.split(",", 1) try: mininterval = max(1, int(mininterval)) maxinterval = max(1, int(maxinterval)) if maxinterval < mininterval: temp = mininterval mininterval = maxinterval maxinterval = temp except: mininterval = 1 maxinterval = 1 # Currently / Maximimum spawned by this gem current = 0 if item.hastag("current"): try: current = int(item.gettag("current")) except: current = 0 maximum = 1 if item.hastag("maximum"): try: maximum = int(item.gettag("maximum")) except: maximum = 1 nextspawn = 0 if item.hastag("nextspawn"): try: nextspawn = int(item.gettag("nextspawn")) except: nextspawn = 0 currenttime = wolfpack.tickcount() # It's possible that the spawntime got too far into the future (server-reload etc.) # reset it here. if nextspawn - currenttime > maxinterval * 60 * 1000: nextspawn = 0 # If we didn't have a spawntime set yet. if nextspawn == 0 and current < maximum: item.settag("nextspawn", currenttime + random.randint(mininterval, maxinterval) * 60 * 1000) continue elif current >= maximum: item.deltag("nextspawn") continue if nextspawn <= currenttime: spawn(item, spawntype, spawndef, current, area) # console.log(LOG_MESSAGE, "SPAWNTIME REACHED!") item.deltag("nextspawn") if DEBUG_SPAWNS == 1: console.log( LOG_MESSAGE, "Valid Spawnpoint: %x, Cur/Max: %u/%u, Def: %s, Type: %u, Interval: %u,%u, Time: %d/%d" % ( item.serial, current, maximum, spawndef, spawntype, mininterval, maxinterval, nextspawn, currenttime, ), ) self.processed += process if len(self.unprocessed) == 0: self.unprocessed = self.processed self.processed = [] self.unlock() self.stopped.wait(15.0) # Every 15 seconds.
def processSpawns(process): # Process the designated partition for i in range(0, len(process)): item = wolfpack.finditem(process[i]) # Check if the spawn is valid. valid = item != None if valid and not item.hasscript( 'spawngem' ): valid = False if valid and (not item.hastag('spawntype') or not item.hastag('spawndef')): valid = False if not valid: if DEBUG_SPAWNS == 1: console.log(LOG_WARNING, "Invalid spawn item: 0x%x.\n" % item.serial) pass else: spawntype = int(item.gettag('spawntype')) # 0: Items, 1: NPCs spawndef = str(item.gettag('spawndef')) # Definition # This is either how far the npcs will wander # or how far from the spawn the items will be spawned. area = 0 if item.hastag('area'): area = int(item.gettag('area')) # This is a minimum/maximum spawn interval in minutes mininterval = 5 if item.hastag('mininterval'): try: mininterval = int(item.gettag('mininterval')) except: mininterval = 10 maxinterval = mininterval if item.hastag('maxinterval'): try: maxinterval = int(item.gettag('maxinterval')) except: maxinterval = 10 # Normalize min and maxinterval (min. is 1) if mininterval < 1: mininterval = 1 if maxinterval < 1: maxinterval = 1 if mininterval > maxinterval: temp = maxinterval maxinterval = mininterval mininterval = temp # Currently / Maximimum spawned by this gem current = 0 if item.hastag('current'): try: current = int(item.gettag('current')) except: current = 0 maximum = 1 if item.hastag('maximum'): try: maximum = int(item.gettag('maximum')) except: maximum = 1 nextspawn = 0 if item.hastag('nextspawn'): try: nextspawn = int(item.gettag('nextspawn')) except: nextspawn = 0 currenttime = wolfpack.tickcount() # It's possible that the spawntime got too far into the future (server-reload etc.) # reset it here. if nextspawn - currenttime > maxinterval * 60 * 1000: nextspawn = 0 # If we didn't have a spawntime set yet. if nextspawn == 0 and current < maximum: delay = random.randint(mininterval, maxinterval) * 60 * 1000 item.settag('nextspawn', currenttime + delay) if DEBUG_SPAWNS == 1: console.log(LOG_MESSAGE, "Set spawntime for spawngem 0x%x to %u miliseconds in the future.\n" % (item.serial, delay)) continue elif current >= maximum: item.deltag('nextspawn') continue if nextspawn <= currenttime: spawn(item, spawntype, spawndef, current, area) #console.log(LOG_MESSAGE, "SPAWNTIME REACHED!") item.deltag('nextspawn') if DEBUG_SPAWNS == 1: console.log(LOG_MESSAGE, "Valid Spawnpoint: %x, Cur/Max: %u/%u, Def: %s, Type: %u, Interval: %u,%u, Time: %d/%d" % \ (item.serial, current, maximum, spawndef, spawntype, mininterval, maxinterval, currenttime, nextspawn))
def processSpawns(process): # Process the designated partition for i in range(0, len(process)): item = wolfpack.finditem(process[i]) # Check if the spawn is valid. valid = item != None if valid and not item.hasscript('spawngem'): valid = False if valid and (not item.hastag('spawntype') or not item.hastag('spawndef')): valid = False if not valid: if DEBUG_SPAWNS: console.log(LOG_WARNING, "Invalid spawn item: 0x%x.\n" % item.serial) pass else: spawntype = int(item.gettag('spawntype')) # 0: Items, 1: NPCs spawndef = str(item.gettag('spawndef')) # Definition # This is either how far the npcs will wander # or how far from the spawn the items will be spawned. area = 0 if item.hastag('area'): area = int(item.gettag('area')) # This is a minimum/maximum spawn interval in minutes mininterval = 5 if item.hastag('mininterval'): try: mininterval = int(item.gettag('mininterval')) except: mininterval = 10 maxinterval = mininterval if item.hastag('maxinterval'): try: maxinterval = int(item.gettag('maxinterval')) except: maxinterval = 10 # Normalize min and maxinterval (min. is 1) if mininterval < 1: mininterval = 1 if maxinterval < 1: maxinterval = 1 if mininterval > maxinterval: temp = maxinterval maxinterval = mininterval mininterval = temp # Currently / Maximimum spawned by this gem current = 0 if item.hastag('current'): try: current = int(item.gettag('current')) except: current = 0 maximum = 1 if item.hastag('maximum'): try: maximum = int(item.gettag('maximum')) except: maximum = 1 nextspawn = 0 if item.hastag('nextspawn'): try: nextspawn = int(item.gettag('nextspawn')) except: nextspawn = 0 currenttime = wolfpack.tickcount() # It's possible that the spawntime got too far into the future (server-reload etc.) # reset it here. if nextspawn - currenttime > maxinterval * 60 * 1000: nextspawn = 0 # If we didn't have a spawntime set yet. if nextspawn == 0 and current < maximum: delay = random.randint(mininterval, maxinterval) * 60 * 1000 item.settag('nextspawn', currenttime + delay) if DEBUG_SPAWNS: console.log( LOG_MESSAGE, "Set spawntime for spawngem 0x%x to %u miliseconds in the future.\n" % (item.serial, delay)) continue elif current >= maximum: item.deltag('nextspawn') continue if nextspawn <= currenttime: spawn(item, spawntype, spawndef, current, area) #console.log(LOG_MESSAGE, "SPAWNTIME REACHED!") item.deltag('nextspawn') if DEBUG_SPAWNS: console.log(LOG_MESSAGE, "Valid Spawnpoint: %x, Cur/Max: %u/%u, Def: %s, Type: %u, Interval: %u,%u, Time: %d/%d" % \ (item.serial, current, maximum, spawndef, spawntype, mininterval, maxinterval, currenttime, nextspawn))