2015-03-03 16:10:12 -06:00
|
|
|
from direct.distributed.DistributedObjectAI import DistributedObjectAI
|
2015-06-25 13:20:15 -05:00
|
|
|
from direct.distributed.ClockDelta import globalClockDelta
|
2015-06-22 02:23:46 -05:00
|
|
|
from direct.task import Task
|
2015-06-25 13:20:15 -05:00
|
|
|
from toontown.effects.DistributedFireworkShowAI import DistributedFireworkShowAI
|
|
|
|
from toontown.effects import FireworkShows
|
2015-06-22 02:23:46 -05:00
|
|
|
from toontown.toonbase import ToontownGlobals
|
2015-06-25 13:20:15 -05:00
|
|
|
from toontown.parties import PartyGlobals
|
2015-06-22 02:23:46 -05:00
|
|
|
import HolidayGlobals
|
2015-06-25 13:20:15 -05:00
|
|
|
import datetime, random
|
2015-03-03 16:10:12 -06:00
|
|
|
|
|
|
|
class NewsManagerAI(DistributedObjectAI):
|
|
|
|
|
2015-06-22 02:23:46 -05:00
|
|
|
def __init__(self, air):
|
|
|
|
DistributedObjectAI.__init__(self, air)
|
|
|
|
self.activeHolidays = []
|
2015-07-06 14:13:54 -05:00
|
|
|
self.fireworkTasks = []
|
2015-07-05 18:59:25 -05:00
|
|
|
|
2015-03-03 16:10:12 -06:00
|
|
|
def announceGenerate(self):
|
|
|
|
DistributedObjectAI.announceGenerate(self)
|
2015-06-22 02:23:46 -05:00
|
|
|
self.__checkHolidays()
|
|
|
|
self.checkTask = taskMgr.doMethodLater(15, self.__checkHolidays, 'holidayCheckTask')
|
2015-03-03 16:10:12 -06:00
|
|
|
self.accept('avatarEntered', self.__handleAvatarEntered)
|
2015-07-05 18:59:25 -05:00
|
|
|
|
2015-06-22 02:23:46 -05:00
|
|
|
def delete(self):
|
|
|
|
DistributedObjectAI.delete(self)
|
|
|
|
taskMgr.remove(self.checkTask)
|
2015-07-06 14:13:54 -05:00
|
|
|
self.deleteFireworkTasks()
|
2015-07-05 18:59:25 -05:00
|
|
|
|
2015-07-06 14:13:54 -05:00
|
|
|
def deleteFireworkTasks(self):
|
|
|
|
if self.fireworkTasks:
|
|
|
|
for task in self.fireworkTasks:
|
|
|
|
taskMgr.remove(task)
|
|
|
|
self.fireworkTasks = []
|
2015-06-25 13:20:15 -05:00
|
|
|
|
2015-06-22 02:23:46 -05:00
|
|
|
def __handleAvatarEntered(self, av):
|
2015-06-30 13:50:15 -05:00
|
|
|
avId = av.getDoId()
|
|
|
|
|
|
|
|
if self.air.suitInvasionManager.getInvading():
|
|
|
|
self.air.suitInvasionManager.notifyInvasionBulletin(avId)
|
|
|
|
|
|
|
|
self.sendUpdateToAvatarId(avId, 'setActiveHolidays', [self.activeHolidays])
|
2015-06-25 13:20:15 -05:00
|
|
|
|
2015-06-24 08:49:20 -05:00
|
|
|
def getActiveHolidays(self):
|
|
|
|
return self.activeHolidays
|
2015-06-25 13:20:15 -05:00
|
|
|
|
2015-06-22 02:23:46 -05:00
|
|
|
def __checkHolidays(self, task=None):
|
2015-06-25 13:20:15 -05:00
|
|
|
date = datetime.datetime.utcnow().replace(tzinfo=HolidayGlobals.TIME_ZONE)
|
2015-06-22 02:23:46 -05:00
|
|
|
|
|
|
|
for id in HolidayGlobals.Holidays:
|
|
|
|
holiday = HolidayGlobals.Holidays[id]
|
|
|
|
running = self.isHolidayRunning(id)
|
2015-07-05 18:59:25 -05:00
|
|
|
|
2015-06-25 13:20:15 -05:00
|
|
|
if self.isHolidayInRange(holiday, date):
|
2015-06-22 02:23:46 -05:00
|
|
|
if not running:
|
|
|
|
self.startHoliday(id)
|
|
|
|
elif running:
|
|
|
|
self.endHoliday(id)
|
|
|
|
|
|
|
|
return Task.again
|
2015-07-05 18:59:25 -05:00
|
|
|
|
2015-06-25 13:20:15 -05:00
|
|
|
def isHolidayInRange(self, holiday, date):
|
|
|
|
if 'weekDay' in holiday:
|
|
|
|
return holiday['weekDay'] == date.weekday()
|
|
|
|
else:
|
|
|
|
return HolidayGlobals.getStartDate(holiday) <= date <= HolidayGlobals.getEndDate(holiday)
|
2015-06-22 02:23:46 -05:00
|
|
|
|
|
|
|
def isHolidayRunning(self, id):
|
|
|
|
return id in self.activeHolidays
|
|
|
|
|
|
|
|
def startHoliday(self, id):
|
|
|
|
if id in self.activeHolidays or id not in HolidayGlobals.Holidays:
|
|
|
|
return
|
|
|
|
|
|
|
|
self.activeHolidays.append(id)
|
|
|
|
self.startSpecialHoliday(id)
|
|
|
|
self.sendUpdate('startHoliday', [id])
|
2015-07-05 18:59:25 -05:00
|
|
|
|
2015-06-22 02:23:46 -05:00
|
|
|
def endHoliday(self, id):
|
|
|
|
if id not in self.activeHolidays or id not in HolidayGlobals.Holidays:
|
|
|
|
return
|
|
|
|
|
|
|
|
self.activeHolidays.remove(id)
|
|
|
|
self.endSpecialHoliday(id)
|
|
|
|
self.sendUpdate('endHoliday', [id])
|
2015-07-05 18:59:25 -05:00
|
|
|
|
2015-06-22 02:23:46 -05:00
|
|
|
def startSpecialHoliday(self, id):
|
|
|
|
if id == ToontownGlobals.FISH_BINGO or id == ToontownGlobals.SILLY_SATURDAY:
|
|
|
|
messenger.send('checkBingoState')
|
2015-06-25 13:20:15 -05:00
|
|
|
elif id in [ToontownGlobals.SUMMER_FIREWORKS, ToontownGlobals.NEW_YEAR_FIREWORKS]:
|
2015-07-06 17:49:02 -05:00
|
|
|
self.fireworkTasks.append(taskMgr.doMethodLater((60 - datetime.datetime.now().minute) * 60, self.startFireworkTask, 'initialFireworkTask-%s' % id, extraArgs=[id]))
|
2015-06-22 02:23:46 -05:00
|
|
|
|
|
|
|
def endSpecialHoliday(self, id):
|
|
|
|
if id == ToontownGlobals.FISH_BINGO or id == ToontownGlobals.SILLY_SATURDAY:
|
2015-06-25 13:20:15 -05:00
|
|
|
messenger.send('checkBingoState')
|
|
|
|
elif id in [ToontownGlobals.SUMMER_FIREWORKS, ToontownGlobals.NEW_YEAR_FIREWORKS]:
|
2015-07-06 14:13:54 -05:00
|
|
|
self.deleteFireworkTasks()
|
|
|
|
|
|
|
|
def startFireworkTask(self, id, task=None):
|
|
|
|
self.startFireworks(id)
|
2015-07-06 16:47:56 -05:00
|
|
|
self.fireworkTasks.append(taskMgr.doMethodLater(3600, self.startFireworks, 'fireworkTask-%s' % id, extraArgs=[id]))
|
2015-07-06 14:13:54 -05:00
|
|
|
return Task.done
|
2015-07-05 18:59:25 -05:00
|
|
|
|
2015-07-02 09:04:31 -05:00
|
|
|
def startFireworks(self, type, task=None):
|
2015-06-25 13:20:15 -05:00
|
|
|
maxShow = len(FireworkShows.shows.get(type, [])) - 1
|
|
|
|
|
|
|
|
for hood in self.air.hoods:
|
|
|
|
if hood.zoneId == ToontownGlobals.GolfZone:
|
|
|
|
continue
|
|
|
|
|
|
|
|
fireworkShow = DistributedFireworkShowAI(self.air)
|
|
|
|
fireworkShow.generateWithRequired(hood.zoneId)
|
|
|
|
fireworkShow.b_startShow(type, random.randint(0, maxShow), globalClockDelta.getRealNetworkTime())
|
|
|
|
|
2015-07-05 18:59:25 -05:00
|
|
|
return Task.again
|