2015-06-23 18:11:48 -05:00
|
|
|
from panda3d.core import *
|
2015-03-08 05:22:51 -05:00
|
|
|
from direct.task import Task
|
|
|
|
from direct.distributed import DistributedObjectAI
|
|
|
|
from direct.directnotify import DirectNotifyGlobal
|
|
|
|
from toontown.toonbase.ToontownGlobals import *
|
|
|
|
from GlobalGroup import GlobalGroup
|
|
|
|
|
|
|
|
class GroupManagerAI(DistributedObjectAI.DistributedObjectAI):
|
|
|
|
notify = DirectNotifyGlobal.directNotify.newCategory('GroupManagerAI')
|
|
|
|
|
|
|
|
def __init__(self, air):
|
|
|
|
DistributedObjectAI.DistributedObjectAI.__init__(self, air)
|
2015-04-23 21:07:17 -05:00
|
|
|
self.sellGroup = GlobalGroup('VP', SellbotHQ)
|
|
|
|
self.cashGroup = GlobalGroup('CFO', CashbotHQ)
|
|
|
|
self.lawGroup = GlobalGroup('CJ', LawbotHQ)
|
|
|
|
self.bossGroup = GlobalGroup('CEO', BossbotHQ)
|
2015-03-08 05:22:51 -05:00
|
|
|
self.shardGroups = {
|
|
|
|
SellbotHQ: self.sellGroup,
|
|
|
|
CashbotHQ: self.cashGroup,
|
|
|
|
LawbotHQ: self.lawGroup,
|
|
|
|
BossbotHQ: self.bossGroup,
|
|
|
|
}
|
|
|
|
self.groupPlayers = {
|
|
|
|
SellbotHQ: [],
|
|
|
|
CashbotHQ: [],
|
|
|
|
LawbotHQ: [],
|
|
|
|
BossbotHQ: [],
|
|
|
|
}
|
|
|
|
self.id2type = {
|
2015-04-23 21:07:17 -05:00
|
|
|
SellbotHQ: 'VP',
|
|
|
|
CashbotHQ: 'CFO',
|
|
|
|
LawbotHQ: 'CJ',
|
|
|
|
BossbotHQ: 'CEO',
|
2015-03-08 05:22:51 -05:00
|
|
|
}
|
|
|
|
self.childId = None
|
|
|
|
|
|
|
|
def announceGenerate(self):
|
|
|
|
DistributedObjectAI.DistributedObjectAI.announceGenerate(self)
|
|
|
|
self.air.groupManager = self
|
2015-04-21 22:31:41 -05:00
|
|
|
self.confirmActiveToons = taskMgr.doMethodLater(45, self.confirmToonsInGroup, 'confirmActiveToons')
|
2015-03-08 05:22:51 -05:00
|
|
|
|
|
|
|
def delete(self):
|
|
|
|
DistributedObjectAI.DistributedObjectAI.delete(self)
|
|
|
|
taskMgr.remove('confirmActiveToons')
|
|
|
|
self.air.groupManager = None
|
|
|
|
|
|
|
|
def setChildId(self):
|
|
|
|
doId = self.air.getAvatarIdFromSender()
|
|
|
|
self.childId = doId
|
|
|
|
self.sendUpdateToAvatarId(self.childId, 'requestInfo', [])
|
|
|
|
|
|
|
|
def isPlayerGrouped(self, avId):
|
|
|
|
for group in self.shardGroups.values():
|
|
|
|
if avId in group.getGroupPlayers():
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def isInGroup(self, avId, groupId):
|
|
|
|
group = self.shardGroups.get(groupId)
|
|
|
|
if group is None:
|
|
|
|
return False
|
|
|
|
if avId in group.getGroupPlayers():
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def confirmToonsInGroup(self, task):
|
|
|
|
for groupId, group in self.groupPlayers.items():
|
|
|
|
for player in group:
|
2015-04-21 22:31:41 -05:00
|
|
|
toon = simbase.air.doId2do.get(player)
|
2015-04-23 21:07:17 -05:00
|
|
|
if (toon.zoneId != groupId) or (toon.zoneId + 100 != groupId):
|
2015-03-08 05:22:51 -05:00
|
|
|
self.removePlayerFromGroup(groupId, player)
|
|
|
|
return task.again
|
|
|
|
|
|
|
|
def updateInfo(self):
|
|
|
|
self.d_setGroupPlayers(str(self.groupPlayers))
|
|
|
|
self.d_setGroups(str(self.id2type))
|
|
|
|
|
|
|
|
def getTypeFromId(self, groupId):
|
|
|
|
return self.id2type.get(groupId)
|
|
|
|
|
|
|
|
def d_setGroups(self, shardGroups):
|
|
|
|
self.sendUpdateToAvatarId(self.childId, 'setGroups', [shardGroups])
|
|
|
|
|
|
|
|
def getGroups(self):
|
|
|
|
return self.shardGroups
|
|
|
|
|
|
|
|
def d_setGroupPlayers(self, groupPlayers):
|
|
|
|
self.sendUpdateToAvatarId(self.childId, 'setGroupPlayers', [groupPlayers])
|
|
|
|
|
|
|
|
def getGroupPlayers(self, groupId):
|
|
|
|
group = self.shardGroups.get(groupId)
|
|
|
|
if group is None:
|
|
|
|
return []
|
|
|
|
players = group.getGroupPlayers()
|
|
|
|
return players
|
|
|
|
|
|
|
|
def createGroup(self, groupId, groupType):
|
|
|
|
group = self.shardGroups.get(groupId)
|
|
|
|
if group is not None:
|
|
|
|
newGroup = DistributedGlobalGroupAI(self.air, groupType, groupId)
|
|
|
|
self.shardGroups.update(groupId, newGroup)
|
|
|
|
players = {groupId: self.getGroupPlayers(groupId)}
|
|
|
|
self.groupPlayers.update(players)
|
|
|
|
self.updateInfo()
|
|
|
|
|
|
|
|
def closeGroup(self, groupId):
|
|
|
|
group = self.shardGroups.get(groupId)
|
|
|
|
if group is not None:
|
|
|
|
self.shardGroups.pop(groupId)
|
|
|
|
self.groupPlayers.pop(groupId)
|
|
|
|
self.updateInfo()
|
|
|
|
|
|
|
|
def addPlayerToGroup(self, groupId, avId):
|
|
|
|
group = self.shardGroups.get(groupId)
|
|
|
|
if group is not None:
|
|
|
|
if not group.isInGroup(avId):
|
|
|
|
group.addPlayerToGroup(avId)
|
|
|
|
players = {groupId: self.getGroupPlayers(groupId)}
|
|
|
|
self.groupPlayers.update(players)
|
|
|
|
self.updateInfo()
|
|
|
|
|
|
|
|
def removePlayerFromGroup(self, groupId, avId):
|
|
|
|
group = self.shardGroups.get(groupId)
|
|
|
|
if group is not None:
|
|
|
|
if group.isInGroup(avId):
|
|
|
|
group.removePlayerFromGroup(avId)
|
|
|
|
players = {groupId: self.getGroupPlayers(groupId)}
|
|
|
|
self.groupPlayers.update(players)
|
|
|
|
self.updateInfo()
|