Poodletooth-iLand/toontown/ai/NewsManagerAI.py

148 lines
5 KiB
Python
Raw Normal View History

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
from otp.ai.MagicWordGlobal import *
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()
2015-03-03 16:10:12 -06:00
self.accept('avatarEntered', self.__handleAvatarEntered)
taskMgr.doMethodLater(15, self.__checkHolidays, 'holidayCheckTask')
2015-07-05 18:59:25 -05:00
2015-06-22 02:23:46 -05:00
def delete(self):
DistributedObjectAI.delete(self)
self.deleteTasks()
def deleteTasks(self):
taskMgr.remove('holidayCheckTask')
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):
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
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-08-22 01:25:00 -05:00
date = datetime.datetime.now(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, *args):
for id in args:
if id in self.activeHolidays:
return True
2015-06-22 02:23:46 -05:00
def startHoliday(self, id):
if id in self.activeHolidays or id not in HolidayGlobals.Holidays:
return False
2015-06-22 02:23:46 -05:00
self.activeHolidays.append(id)
self.startSpecialHoliday(id)
self.sendUpdate('startHoliday', [id])
return True
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 False
2015-06-22 02:23:46 -05:00
self.activeHolidays.remove(id)
self.endSpecialHoliday(id)
self.sendUpdate('endHoliday', [id])
return True
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('startBingo')
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:
messenger.send('stopBingo')
2015-06-25 13:20:15 -05:00
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-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
@magicWord(category=CATEGORY_PROGRAMMER)
def newsShutdown():
"""
Shutdown the news manager tasks.
"""
simbase.air.newsManager.deleteTasks()
return 'News manager shut down!'
@magicWord(category=CATEGORY_PROGRAMMER, types=[int])
def startHoliday(holiday):
"""
Start a holiday.
"""
if simbase.air.newsManager.startHoliday(holiday):
return 'Started holiday %s!' % holiday
return 'Holiday %s is already running!' % holiday
@magicWord(category=CATEGORY_PROGRAMMER, types=[int])
def stopHoliday(holiday):
"""
Stop a holiday.
"""
if simbase.air.newsManager.endHoliday(holiday):
return 'Stopped holiday %s!' % holiday
return 'Holiday %s is not running!' % holiday