Go to the documentation of this file.00001
00002 '''
00003 Anoria (c) Gsk 2010
00004 '''
00005
00006 import BigWorld
00007 import time
00008 from Resources import ResourceDB as RDB
00009 from config.consts import *
00010
00011
00012 class SpawnControl():
00013 def __init__(self, spawnDef, id):
00014 self.spawnControlId = id
00015 self.entityType = spawnDef.entityType
00016 self.entityName = spawnDef.mobName
00017 self.mobDefId = spawnDef.mobDefId
00018 self.respawnDelay = spawnDef.respawnDelay
00019 self.spawnDefId = spawnDef.id
00020 self.isSpawned = False
00021 self.despawnTime = 0
00022
00023
00024
00025 class Spawn( BigWorld.Base ):
00026
00027 def __init__( self ):
00028 BigWorld.Base.__init__( self )
00029
00030
00031
00032
00033 self.createCellEntity( self.spawnerCellMb )
00034
00035
00036 spawnDef = RDB.spawns[self.spawnTypeId]
00037 sp = SpawnControl(spawnDef, 0)
00038 self.spawnControls = [sp]
00039
00040 delta_t = 1.0 / GAME_UPDATE_RATE
00041 self.addTimer(delta_t, delta_t)
00042
00043
00044
00045 def onTimer(self, timerId, userData):
00046 index = -1
00047 now = time.time()
00048 for spawnControl in self.spawnControls:
00049 if not spawnControl.isSpawned and now > spawnControl.despawnTime+spawnControl.respawnDelay:
00050 name = spawnControl.entityName
00051 print "Spawn[%d].onTimer(): spawning spawnDefId=%s entityName=%s" % \
00052 (self.id, spawnControl.spawnDefId, name)
00053
00054 self.doSpawn(spawnControl.spawnControlId, spawnControl.spawnDefId, spawnControl.entityType,
00055 name, 'bargu01', self.position, self.direction)
00056
00057 spawnControl.isSpawned=True
00058
00059
00060
00061
00062 def doSpawn(self, spawnControlId, defId, entityType, entityName, mobDefId, pos, dir):
00063
00064
00065 properties = { "mobDefId":mobDefId, "spawnControlId":spawnControlId }
00066 base = BigWorld.createBaseAnywhere(entityType, properties, spawnerCellMb = self.cell,
00067 name=entityName, position=pos, direction=dir, spawnDefId=defId, spawnBaseId=self.id)
00068
00069
00070 def onLoseCell( self ):
00071
00072 self.destroy()
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 def rpcNotifyDespawn(self, spawnControlId):
00083 print "Spawn[%d].rpcNotifyDespawn(): despawning spawnControlId=%s" % (self.id, spawnControlId)
00084 spawnControl = self.spawnControls[spawnControlId]
00085 spawnControl.isSpawned=False
00086 spawnControl.despawnTime=time.time()
00087
00088
00089