Poodletooth-iLand/toontown/distributed/ToontownDistrictAI.py

49 lines
1.8 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from direct.directnotify.DirectNotifyGlobal import directNotify
from otp.distributed.DistributedDistrictAI import DistributedDistrictAI
2015-06-12 09:12:36 -05:00
import time
2015-03-03 16:10:12 -06:00
class ToontownDistrictAI(DistributedDistrictAI):
notify = directNotify.newCategory('ToontownDistrictAI')
created = 0
def announceGenerate(self):
DistributedDistrictAI.announceGenerate(self)
# Remember the time of which this district was created:
self.created = int(time.time())
# We want to handle shard status queries so that a ShardStatusReceiver
# being created after we're generated will know where we're at:
2015-07-13 06:13:05 -05:00
self.air.accept('queryShardStatus', self.handleShardStatusQuery)
2015-03-03 16:10:12 -06:00
# Send a shard status update with the information we have:
status = {
'available': bool(self.available),
'name': self.name,
'created': int(time.time())
}
2015-07-12 11:48:58 -05:00
self.air.sendNetEvent('shardStatus', [self.air.ourChannel, status])
2015-03-03 16:10:12 -06:00
def handleShardStatusQuery(self):
# Send a shard status update with the information we have:
status = {
'available': bool(self.available),
'name': self.name,
'created': int(time.time())
}
2015-07-12 11:48:58 -05:00
self.air.sendNetEvent('shardStatus', [self.air.ourChannel, status])
2015-03-03 16:10:12 -06:00
def setName(self, name):
DistributedDistrictAI.setName(self, name)
# Send a shard status update containing our name:
status = {'name': name}
2015-07-12 11:48:58 -05:00
self.air.sendNetEvent('shardStatus', [self.air.ourChannel, status])
2015-03-03 16:10:12 -06:00
def setAvailable(self, available):
DistributedDistrictAI.setAvailable(self, available)
# Send a shard status update containing our availability:
status = {'available': bool(available)}
2015-07-12 11:48:58 -05:00
self.air.sendNetEvent('shardStatus', [self.air.ourChannel, status])