Exemple #1
0
	def spawn(self):
		if self.active:
		 	#if self.startingLocation[0] is not None:
			#print self.active

			if self.repeat:
				self.timer.currentTime = self.time
				#print "repeatTime: " + str(self.timer.currentTime)
				self.TIMERS.append(self.timer)
				#print str(self.timer) + " repeated. " + str(Globals.TIMERS)

			elif self.cycles > 1:
				self.cycles -= 1
				#Globals.TIMERS.remove(self.timer)
				self.timer.currentTime = self.time
				#print "cycleTime: " + str(self.timer.currentTime)
				Globals.TIMERS.append(self.timer)
				#print "cycles -1 " + str(Globals.TIMERS)

			winner = Engine.selector(self.oddsList)
			if winner[0]:
				#print self.active
				#print self.owner.owner.currentRoom
				#print self.startingLocation
				#self.obj.currentRoom = self.startingLocation[0]	# tell the object what room it is in

				for obj in Globals.fromFileList:
					if obj.name == self.obj.name:
						refobj = obj.name
						ob = obj

				#print self.active
				newObject = Engine.cmdSpawnObject(refobj, self.startingLocation[0], whereFrom='objSpawner', spawnContainer=self.owner.owner.spawnContainer)
				#print self.active
				#print str(newObject.name) + " added timer " + str(newObject.kind.objectSpawner.timer)
				#print "ob " +str(ob.kind.objectSpawner.active)
				#print self.active
				#print newObject.spawnContainer
				#print self.owner.owner
				# if self.startingLocation[0] is not None:
				#self.startingLocation[0].objects.append(self.obj)
				# else:
				# 	pass	# add the new object to the room

				stuffed = self.stuff(newObject, True)		# try shoving items in containers if they should be there instead of in the room

				# 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 == self.startingLocation[0]:		# if a client is in the room object just appeared in, let it know
				# 			if not stuffed:
				# 				client.send_cc("^BA %s appeared.^~\n" %self.owner.owner.name)
				# print "repeat:" + str(self.repeat)
				# print "cycles:" + str(self.cycles)
				# print "timer:" + str(self.timer)
				#print "currentTime:" + str(self.obj.kind.objectSpawner.timer.currentTime)
				# print "time:" + str(self.timer.time)
				# print "name:" + str(self.owner.owner.name)


					#print "$o  "+ str(self.owner.owner)+ " "+ str(self.owner.owner.name) + " @ [" + str(self.startingLocation[0].region) + ":" + str(self.startingLocation[0].name) +"]"

			# else:
			# 	self.obj.kind.objectSpawner.timer.currentTime = self.time
			# 	#print self.timer.time
			# 	Globals.TIMERS.append(self.obj.kind.objectSpawner.timer)
			# 	print "noWin " + str(Globals.TIMERS)
	
		else:
			if self.owner.owner.spawnContainer is not None:
				if not(self.owner.owner in self.owner.owner.spawnContainer.kind.inventory):
					stuffed = self.stuff(self.owner.owner, False)	
Exemple #2
0
def loadMobFromFile(file):
	'''
	handles loading a single mob from a given mob definition file into the world
	'''
	print file

	if str(file).endswith('~'):
		print '\n'
		return

	path = 'blueprints/mob/' + file
	with open(path, 'r') as f:
		fileData = f.readlines()



	newMob = World.Mob('none', 'none', 'none')
	newMob.mobID = ''

	print fileData

	splitFile = file.split("/")
	mobID = None
	name = 'none'
	species = None
	currentRoom = None
	region = None
	description = ''
	longDescription = ''
	hp = 0
	exp = 0
	inventory = []
	inventorySize = 0
	equipment = {}
	kind = None
	expirator = None
	inventoryItems = []
	currentRoomString = ''
	moveAI = None
	battleAI = None

	newMob.kind = World.mortal(hp=0,maxHp=0,pp=0,maxPp=0,level=0,exp=0,money=0,offense=0,defense=0,speed=0,guts=0,luck=0,vitality=0,IQ=0,inventory=[],inventorySize=0,equipment={})
	newMob.region = splitFile[0]

	for Data in fileData:

		if Data.startswith('mobID='):
			IDstring = Data[6:-1]
			if IDstring != '':
				newMob.mobID = int(IDstring)
		if Data.startswith('name='):
			newMob.name = Data[5:-1]
		if Data.startswith('species='):
			newMob.species = Data[8:-1]

		if Data.startswith('currentRoom='):
			currentRoomString = Data[12:-1]

		if Data.startswith('description='):
			newMob.description = Data[12:-1]

		if Data.startswith('longDescription='):
			newMob.longDescription = Data[16:-1]

		if Data.startswith('speech='):
			newMob.speech = Data[7:-1]

		if Data.startswith('expirator='):
			expirator = Data[10:-1]
			if expirator != '':
				expirator = int(expirator)
		if Data.startswith('moveAI='):
			text = Data[7:-1]
			moveAI = text.split(":")
		if Data.startswith('battleAI='):
			text = Data[9:-1]
			if text == 'basicBash':
				battleAI = aiBattle.basicBash
			else:
				battleAI = ''

		if Data.startswith('kind.hp='):
			newMob.kind.hp = int(Data[8:-1])
		if Data.startswith('kind.maxHp='):
			newMob.kind.maxHp = int(Data[11:-1])
		if Data.startswith('kind.pp='):
			newMob.kind.pp = int(Data[8:-1])
		if Data.startswith('kind.maxPp='):
			newMob.kind.maxPp = int(Data[11:-1])
		if Data.startswith('kind.level='):
			newMob.kind.level = int(Data[11:-1])
		if Data.startswith('kind.exp='):
			newMob.kind.exp = int(Data[9:-1])
		if Data.startswith('kind.money='):
			newMob.kind.money = int(Data[11:-1])
		if Data.startswith('kind.offense='):
			newMob.kind.offense = int(Data[13:-1])
		if Data.startswith('kind.defense='):
			newMob.kind.defense = int(Data[13:-1])
		if Data.startswith('kind.speed='):
			newMob.kind.speed = int(Data[11:-1])
		if Data.startswith('kind.guts='):
			newMob.kind.guts = int(Data[10:-1])
		if Data.startswith('kind.luck='):
			newMob.kind.luck = int(Data[10:-1])
		if Data.startswith('kind.vitality='):
			newMob.kind.vitality = int(Data[14:-1])
		if Data.startswith('kind.IQ='):
			newMob.kind.IQ = int(Data[8:-1])
		if Data.startswith('kind.inventory='):
			invString = Data[15:-1]
			if invString != '':
				#print "invString:" + invString
				invList = invString.split(', ')
				#print 'invList:' + str(invList)
				for item in invList:
					for ob in Globals.fromFileList:
						if item == ob.name:
							inventoryItems.append(item)
			else:
				inventoryItems = []
		if Data.startswith('kind.inventorySize='):
			newMob.kind.inventorySize = int(Data[19:-1])


	if currentRoomString != '':
		currentRoomCoords = currentRoomString.split(":")
		newMob.currentRoom = Globals.regionListDict[currentRoomCoords[0]][currentRoomCoords[1]]
	else:
		# newMob.currentRoom = Globals.regionListDict[newMob.region]['bullpen']
		newMob.currentRoom = None

	if expirator != None and expirator != '':
		expiratorComponent = World.expirator(newMob, expirator)
		newMob.expirator = expiratorComponent

	if moveAI != None and moveAI != []:
		newMoveAI = aiMove.movementAI(newMob, int(moveAI[1]))
		if moveAI[0] == 'basicRandom':
			newMoveAI.Timer.actionFunction = newMoveAI.basicRandom
		elif moveAI[0] == 'introvertRandom':
			newMoveAI.Timer.actionFunction = newMoveAI.introvertRandom
		elif moveAI[0] == 'extrovertRandom':
			newMoveAI.Timer.actionFunction = newMoveAI.extrovertRandom
		elif moveAI[0] == 'doNotMove':
			newMoveAI.Timer.actionFunction = newMoveAI.doNotMove

		newMob.aiMove = newMoveAI
		Globals.MoveTIMERS.remove(newMob.aiMove.Timer)

	if battleAI != None:
		newMob.aiBattle = battleAI

	#print 'invItems:' + str(inventoryItems)
	for item in inventoryItems:
		#print 'invitem:' + str(item)
		removed = False
		newItem = Engine.cmdSpawnObject(item, newMob.currentRoom, alert=False, whereFrom='mobinv')
		newMob.kind.inventory.append(newItem)
		# for obj in newMob.currentRoom.objects:
		# 	if obj.name == item:
		# 		newMob.currentRoom.objects.remove(obj)
		if newMob.currentRoom is not None:
			newMob.currentRoom.objects.remove(newItem)

	if newMob.currentRoom is not None:
		newMob.currentRoom.mobs.append(newMob)

	if expirator != None and expirator != '':
		Globals.TIMERS.remove(newMob.expirator.Timer)
		#newMob.expirator.Timer = None

	Globals.mobsFromFile.append(newMob)