Poodletooth-iLand/toontown/distributed/ToontownDistrictStatsAI.py

96 lines
3.4 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from direct.directnotify.DirectNotifyGlobal import directNotify
from direct.distributed.DistributedObjectAI import DistributedObjectAI
2015-08-01 09:08:37 -05:00
from toontown.toonbase import ToontownGlobals
from toontown.toon import DistributedToonAI
2015-03-03 16:10:12 -06:00
class ToontownDistrictStatsAI(DistributedObjectAI):
notify = directNotify.newCategory('ToontownDistrictStatsAI')
districtId = 0
avatarCount = 0
invasionStatus = 0
2015-08-01 09:08:37 -05:00
groupAvCount = [0] * len(ToontownGlobals.GROUP_ZONES)
2015-03-03 16:10:12 -06:00
def announceGenerate(self):
DistributedObjectAI.announceGenerate(self)
# We want to handle shard status queries so that a ShardStatusReceiver
# being created after we're generated will know where we're at:
2015-08-01 09:08:37 -05:00
self.air.accept('queryShardStatus', self.handleShardStatusQuery)
taskMgr.doMethodLater(15, self.__countGroups, self.uniqueName('countGroups'))
def delete(self):
taskMgr.remove(self.uniqueName('countGroups'))
DistributedObjectAI.delete(self)
2015-03-03 16:10:12 -06:00
def handleShardStatusQuery(self):
# Send a shard status update containing our population:
status = {'population': self.avatarCount}
2015-07-12 11:51:05 -05:00
self.air.sendNetEvent('shardStatus', [self.air.ourChannel, status])
2015-03-03 16:10:12 -06:00
2015-06-29 13:54:28 -05:00
def setDistrictId(self, districtId):
2015-03-03 16:10:12 -06:00
self.districtId = districtId
2015-06-29 13:54:28 -05:00
def d_setDistrictId(self, districtId):
self.sendUpdate('setDistrictId', [districtId])
2015-03-03 16:10:12 -06:00
2015-06-29 13:54:28 -05:00
def b_setDistrictId(self, districtId):
self.setDistrictId(districtId)
self.d_setDistrictId(districtId)
2015-03-03 16:10:12 -06:00
2015-06-29 13:54:28 -05:00
def getDistrictId(self):
2015-03-03 16:10:12 -06:00
return self.districtId
def setAvatarCount(self, avatarCount):
self.avatarCount = avatarCount
# Send a shard status update containing our population:
status = {'population': self.avatarCount}
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 d_setAvatarCount(self, avatarCount):
self.sendUpdate('setAvatarCount', [avatarCount])
def b_setAvatarCount(self, avatarCount):
self.d_setAvatarCount(avatarCount)
self.setAvatarCount(avatarCount)
def getAvatarCount(self):
return self.avatarCount
def setInvasionStatus(self, invasionStatus):
self.invasionStatus = invasionStatus
def d_setInvasionStatus(self, invasionStatus):
self.sendUpdate('setInvasionStatus', [invasionStatus])
def b_setInvasionStatus(self, invasionStatus):
self.setInvasionStatus(invasionStatus)
self.d_setInvasionStatus(invasionStatus)
def getInvasionStatus(self):
2015-07-05 18:59:25 -05:00
return self.invasionStatus
2015-08-01 09:08:37 -05:00
def setGroupAvCount(self, groupAvCount):
self.groupAvCount = groupAvCount
def d_setGroupAvCount(self, groupAvCount):
self.sendUpdate('setGroupAvCount', [groupAvCount])
def b_setGroupAvCount(self, groupAvCount):
self.setGroupAvCount(groupAvCount)
self.d_setGroupAvCount(groupAvCount)
def getGroupAvCount(self):
return self.groupAvCount
def __countGroups(self, task):
zones = ToontownGlobals.GROUP_ZONES
self.groupAvCount = [0] * len(zones)
for av in self.air.doId2do.values():
if isinstance(av, DistributedToonAI.DistributedToonAI) and av.isPlayerControlled() and av.zoneId in zones:
self.groupAvCount[zones.index(av.zoneId)] += 1
taskMgr.doMethodLater(15, self.__countGroups, self.uniqueName('countGroups'))
self.b_setGroupAvCount(self.groupAvCount)