diff --git a/toontown/ai/NewsManagerAI.py b/toontown/ai/NewsManagerAI.py index 3062d24a..f55a8eaf 100755 --- a/toontown/ai/NewsManagerAI.py +++ b/toontown/ai/NewsManagerAI.py @@ -1,6 +1,7 @@ from direct.distributed.DistributedObjectAI import DistributedObjectAI from direct.distributed.ClockDelta import globalClockDelta from direct.task import Task +from otp.ai.MagicWordGlobal import * from toontown.effects.DistributedFireworkShowAI import DistributedFireworkShowAI from toontown.effects import FireworkShows from toontown.toonbase import ToontownGlobals @@ -18,19 +19,21 @@ class NewsManagerAI(DistributedObjectAI): def announceGenerate(self): DistributedObjectAI.announceGenerate(self) self.__checkHolidays() - self.checkTask = taskMgr.doMethodLater(15, self.__checkHolidays, 'holidayCheckTask') self.accept('avatarEntered', self.__handleAvatarEntered) + taskMgr.doMethodLater(15, self.__checkHolidays, 'holidayCheckTask') def delete(self): DistributedObjectAI.delete(self) - taskMgr.remove(self.checkTask) + self.deleteTasks() + + def deleteTasks(self): + taskMgr.remove('holidayCheckTask') self.deleteFireworkTasks() def deleteFireworkTasks(self): - if self.fireworkTasks: - for task in self.fireworkTasks: - taskMgr.remove(task) - self.fireworkTasks = [] + for task in self.fireworkTasks: + taskMgr.remove(task) + self.fireworkTasks = [] def __handleAvatarEntered(self, av): avId = av.getDoId() @@ -64,41 +67,44 @@ class NewsManagerAI(DistributedObjectAI): else: return HolidayGlobals.getStartDate(holiday) <= date <= HolidayGlobals.getEndDate(holiday) - def isHolidayRunning(self, id): - return id in self.activeHolidays + def isHolidayRunning(self, *args): + for id in args: + if id in self.activeHolidays: + return True def startHoliday(self, id): if id in self.activeHolidays or id not in HolidayGlobals.Holidays: - return + return False self.activeHolidays.append(id) self.startSpecialHoliday(id) self.sendUpdate('startHoliday', [id]) + return True def endHoliday(self, id): if id not in self.activeHolidays or id not in HolidayGlobals.Holidays: - return + return False self.activeHolidays.remove(id) self.endSpecialHoliday(id) self.sendUpdate('endHoliday', [id]) + return True def startSpecialHoliday(self, id): if id == ToontownGlobals.FISH_BINGO or id == ToontownGlobals.SILLY_SATURDAY: - messenger.send('checkBingoState') + messenger.send('startBingo') elif id in [ToontownGlobals.SUMMER_FIREWORKS, ToontownGlobals.NEW_YEAR_FIREWORKS]: self.fireworkTasks.append(taskMgr.doMethodLater((60 - datetime.datetime.now().minute) * 60, self.startFireworkTask, 'initialFireworkTask-%s' % id, extraArgs=[id])) def endSpecialHoliday(self, id): if id == ToontownGlobals.FISH_BINGO or id == ToontownGlobals.SILLY_SATURDAY: - messenger.send('checkBingoState') + messenger.send('stopBingo') elif id in [ToontownGlobals.SUMMER_FIREWORKS, ToontownGlobals.NEW_YEAR_FIREWORKS]: self.deleteFireworkTasks() def startFireworkTask(self, id, task=None): self.startFireworks(id) self.fireworkTasks.append(taskMgr.doMethodLater(3600, self.startFireworks, 'fireworkTask-%s' % id, extraArgs=[id])) - return Task.done def startFireworks(self, type, task=None): maxShow = len(FireworkShows.shows.get(type, [])) - 1 @@ -112,3 +118,31 @@ class NewsManagerAI(DistributedObjectAI): fireworkShow.b_startShow(type, random.randint(0, maxShow), globalClockDelta.getRealNetworkTime()) 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 \ No newline at end of file diff --git a/toontown/estate/DistributedEstateAI.py b/toontown/estate/DistributedEstateAI.py index 172504a1..028a1c87 100755 --- a/toontown/estate/DistributedEstateAI.py +++ b/toontown/estate/DistributedEstateAI.py @@ -5,7 +5,6 @@ import HouseGlobals import time, random from toontown.fishing.DistributedFishingPondAI import DistributedFishingPondAI -from toontown.fishing.DistributedPondBingoManagerAI import DistributedPondBingoManagerAI from toontown.fishing import FishingTargetGlobals, FishGlobals from toontown.safezone import TreasureGlobals from toontown.safezone.SZTreasurePlannerAI import SZTreasurePlannerAI @@ -506,11 +505,6 @@ class DistributedEstateAI(DistributedObjectAI): self.pond.generateWithRequired(self.zoneId) self.pond.start() - self.pond.bingoMgr = DistributedPondBingoManagerAI(simbase.air) - self.pond.bingoMgr.setPondDoId(self.pond.getDoId()) - self.pond.bingoMgr.generateWithRequired(self.zoneId) - self.pond.bingoMgr.initTasks() - treasureType, healAmount, spawnPoints, spawnRate, maxTreasures = TreasureGlobals.SafeZoneTreasureSpawns[ToontownGlobals.MyEstate] self.treasurePlanner = SZTreasurePlannerAI(self.zoneId, treasureType, healAmount, spawnPoints, spawnRate, maxTreasures) self.treasurePlanner.start() diff --git a/toontown/fishing/BingoCardGui.py b/toontown/fishing/BingoCardGui.py index d0ce358f..b0cba51a 100755 --- a/toontown/fishing/BingoCardGui.py +++ b/toontown/fishing/BingoCardGui.py @@ -156,11 +156,6 @@ class BingoCardGui(DirectFrame): elif self.game.getGameState() & 1 << index: self.cellGuiList[index].disable() - def disableCard(self): - self.stopCellBlinking() - for index in xrange(self.game.getCardSize()): - self.cellGuiList[index].disable() - def enableCard(self, callback = None): self.notify.info('enable Bingo card') self.stopCellBlinking() diff --git a/toontown/fishing/DistributedFishingPondAI.py b/toontown/fishing/DistributedFishingPondAI.py index ad387d7b..ee98b379 100755 --- a/toontown/fishing/DistributedFishingPondAI.py +++ b/toontown/fishing/DistributedFishingPondAI.py @@ -1,8 +1,9 @@ from direct.directnotify.DirectNotifyGlobal import * from direct.distributed.DistributedObjectAI import DistributedObjectAI -from toontown.fishing import FishingTargetGlobals -from toontown.fishing.DistributedFishingTargetAI import DistributedFishingTargetAI - +from toontown.toonbase import ToontownGlobals +from DistributedFishingTargetAI import DistributedFishingTargetAI +from DistributedPondBingoManagerAI import DistributedPondBingoManagerAI +import FishingTargetGlobals class DistributedFishingPondAI(DistributedObjectAI): notify = directNotify.newCategory("DistributedFishingPondAI") @@ -14,12 +15,42 @@ class DistributedFishingPondAI(DistributedObjectAI): self.targets = {} self.spots = {} self.bingoMgr = None + + def announceGenerate(self): + if self.air.newsManager.isHolidayRunning(ToontownGlobals.FISH_BINGO, ToontownGlobals.SILLY_SATURDAY): + self.startBingo() + + self.accept('startBingo', self.startBingo) + self.accept('stopBingo', self.stopBingo) + DistributedObjectAI.announceGenerate(self) + + def delete(self): + self.ignoreAll() + DistributedObjectAI.delete(self) def start(self): for _ in xrange(FishingTargetGlobals.getNumTargets(self.area)): fishingTarget = DistributedFishingTargetAI(simbase.air) fishingTarget.setPondDoId(self.doId) fishingTarget.generateWithRequired(self.zoneId) + + def startBingo(self): + if self.bingoMgr: + self.notify.warning('Tried to start bingo while already started!') + return + + self.bingoMgr = DistributedPondBingoManagerAI(self.air) + self.bingoMgr.setPondDoId(self.getDoId()) + self.bingoMgr.generateWithRequired(self.zoneId) + self.bingoMgr.createGame() + + def stopBingo(self): + if not self.bingoMgr: + self.notify.warning('Tried to stop bingo but not started!') + return + + self.bingoMgr.requestDelete() + self.bingoMgr = None def hitTarget(self, target): avId = self.air.getAvatarIdFromSender() diff --git a/toontown/fishing/DistributedPondBingoManager.py b/toontown/fishing/DistributedPondBingoManager.py index ed07b643..5eaa61d0 100755 --- a/toontown/fishing/DistributedPondBingoManager.py +++ b/toontown/fishing/DistributedPondBingoManager.py @@ -49,6 +49,7 @@ class DistributedPondBingoManager(DistributedObject.DistributedObject, FSM.FSM): self.notify.debug('generate: DistributedPondBingoManager') def delete(self): + self.pond.resetSpotGui() del self.pond.pondBingoMgr self.pond.pondBingoMgr = None del self.pond @@ -58,7 +59,6 @@ class DistributedPondBingoManager(DistributedObject.DistributedObject, FSM.FSM): del self.card self.notify.debug('delete: Deleting Local PondManager %s' % self.doId) DistributedObject.DistributedObject.delete(self) - return def d_cardUpdate(self, cellId, genus, species): self.sendUpdate('cardUpdate', [self.cardId, @@ -121,7 +121,7 @@ class DistributedPondBingoManager(DistributedObject.DistributedObject, FSM.FSM): self.card.hide() def showCard(self): - if (self.state != 'Off' or self.state != 'CloseEvent') and self.card.getGame(): + if self.state != 'Off' and self.card.getGame() != None: self.card.loadCard() self.card.show() elif self.state == 'GameOver': @@ -283,8 +283,6 @@ class DistributedPondBingoManager(DistributedObject.DistributedObject, FSM.FSM): return (request, args) elif request == 'Intermission': return (request, args) - elif request == 'CloseEvent': - return 'CloseEvent' elif request == 'Off': return 'Off' else: @@ -305,8 +303,6 @@ class DistributedPondBingoManager(DistributedObject.DistributedObject, FSM.FSM): return (request, args) elif request == 'Intermission': return (request, args) - elif request == 'CloseEvent': - return 'CloseEvent' elif request == 'Off': return 'Off' else: @@ -338,17 +334,3 @@ class DistributedPondBingoManager(DistributedObject.DistributedObject, FSM.FSM): def exitIntermission(self): self.notify.debug('enterIntermission: Exit Intermission State') - - def enterCloseEvent(self, timestamp): - self.notify.debug('enterCloseEvent: Enter CloseEvent State') - self.card.hide() - self.pond.resetSpotGui() - - def filterCloseEvent(self, request, args): - if request == 'Off': - return 'Off' - else: - self.notify.warning('filterOff: Invalid State Transition from GameOver to %s' % request) - - def exitCloseEvent(self): - self.notify.debug('exitCloseEvent: Exit CloseEvent State') diff --git a/toontown/fishing/DistributedPondBingoManagerAI.py b/toontown/fishing/DistributedPondBingoManagerAI.py index f5d6e3e4..bcdab127 100755 --- a/toontown/fishing/DistributedPondBingoManagerAI.py +++ b/toontown/fishing/DistributedPondBingoManagerAI.py @@ -1,18 +1,16 @@ from direct.directnotify import DirectNotifyGlobal from direct.distributed.DistributedObjectAI import DistributedObjectAI +from direct.distributed.ClockDelta import * from toontown.fishing import BingoGlobals from toontown.fishing import FishGlobals -from toontown.toonbase import ToontownGlobals from toontown.fishing.NormalBingo import NormalBingo from toontown.fishing.ThreewayBingo import ThreewayBingo from toontown.fishing.DiagonalBingo import DiagonalBingo from toontown.fishing.BlockoutBingo import BlockoutBingo from toontown.fishing.FourCornerBingo import FourCornerBingo -from direct.task import Task -from direct.distributed.ClockDelta import * -import random, datetime -RequestCard = {} +import random +RequestCard = {} class DistributedPondBingoManagerAI(DistributedObjectAI): notify = DirectNotifyGlobal.directNotify.newCategory("DistributedPondBingoManagerAI") @@ -26,35 +24,14 @@ class DistributedPondBingoManagerAI(DistributedObjectAI): self.state = 'Off' self.pond = None self.canCall = False - self.shouldStop = False self.lastUpdate = globalClockDelta.getRealNetworkTime() self.cardId = 0 - - def initTasks(self): - now = datetime.datetime.now() - weekday = now.weekday() - targetday = 2 # Wednesday - if weekday in (3, 4): - targetday = 5 - togo = targetday - weekday - if togo < 0: - togo += 7 - s = now + datetime.timedelta(days=togo) - start = datetime.datetime(s.year, s.month, s.day) - secs = max(0, (start - now).total_seconds()) - self.notify.debug('Today it\'s %d, so we wait for %d, togo: %d %d' % (weekday, targetday, togo, secs)) - taskMgr.doMethodLater(secs, DistributedPondBingoManagerAI.startTask, self.taskName('start'), extraArgs=[self]) - - def startTask(self): - self.notify.debug('Starting game') - - def stop(task): - self.notify.debug('Stopping game') - self.shouldStop = True - return task.done - - taskMgr.doMethodLater(24 * 60 * 60, stop, self.taskName('stop')) - self.createGame() + + def delete(self): + taskMgr.remove(self.uniqueName('startWait')) + taskMgr.remove(self.uniqueName('createGame')) + taskMgr.remove(self.uniqueName('finishGame')) + DistributedObjectAI.delete(self) def setPondDoId(self, pondId): self.pond = self.air.doId2do[pondId] @@ -87,12 +64,16 @@ class DistributedPondBingoManagerAI(DistributedObjectAI): elif result == BingoGlobals.UPDATE: self.sendGameStateUpdate(cellId) - def d_enableBingo(self): - self.sendUpdate('enableBingo', []) - def handleBingoCall(self, cardId): avId = self.air.getAvatarIdFromSender() + av = self.air.doId2do.get(avId) + + if not av: + self.air.writeServerEvent('suspicious', avId, 'Toon tried to call bingo while not on district!') + return + spot = self.pond.hasToon(avId) + if not spot: self.air.writeServerEvent('suspicious', avId, 'Toon tried to call bingo while not fishing!') return @@ -102,7 +83,7 @@ class DistributedPondBingoManagerAI(DistributedObjectAI): if cardId != self.cardId: self.air.writeServerEvent('suspicious', avId, 'Toon tried to call bingo with an expired cardId!') return - av = self.air.doId2do[avId] + av.d_announceBingo() self.rewardAll() @@ -158,40 +139,25 @@ class DistributedPondBingoManagerAI(DistributedObjectAI): continue av = self.air.doId2do[self.pond.spots[spot].avId] av.addMoney(self.jackpot) - if self.shouldStop: - self.stopGame() - return - taskMgr.doMethodLater(5, DistributedPondBingoManagerAI.startWait, 'startWait%d' % self.getDoId(), [self]) - taskMgr.remove('finishGame%d' % self.getDoId()) + taskMgr.doMethodLater(5, self.startWait, self.uniqueName('startWait')) + taskMgr.remove(self.uniqueName('finishGame')) - def finishGame(self): + def finishGame(self, task=None): self.state = 'GameOver' self.sendStateUpdate() - if self.shouldStop: - self.stopGame() - return - taskMgr.doMethodLater(5, DistributedPondBingoManagerAI.startWait, 'startWait%d' % self.getDoId(), [self]) - - def stopGame(self): - self.state = 'CloseEvent' - self.sendStateUpdate() - taskMgr.doMethodLater(10, DistributedPondBingoManagerAI.turnOff, 'turnOff%d' % self.getDoId(), [self]) - - def turnOff(self): - self.state = 'Off' - self.sendStateUpdate() + taskMgr.doMethodLater(5, self.startWait, self.uniqueName('startWait')) def startIntermission(self): self.state = 'Intermission' self.sendStateUpdate() - taskMgr.doMethodLater(300, DistributedPondBingoManagerAI.startWait, 'startWait%d' % self.getDoId(), [self]) + taskMgr.doMethodLater(300, self.startWait, self.uniqueName('startWait')) - def startWait(self): + def startWait(self, task=None): self.state = 'WaitCountdown' self.sendStateUpdate() - taskMgr.doMethodLater(15, DistributedPondBingoManagerAI.createGame, 'createGame%d' % self.getDoId(), [self]) + taskMgr.doMethodLater(15, self.createGame, self.uniqueName('createGame')) - def createGame(self): + def createGame(self, task=None): self.canCall = False self.tileSeed = None self.typeId = None @@ -223,4 +189,4 @@ class DistributedPondBingoManagerAI(DistributedObjectAI): self.b_setJackpot(BingoGlobals.getJackpot(self.typeId)) self.state = 'Playing' self.sendStateUpdate() - taskMgr.doMethodLater(BingoGlobals.getGameTime(self.typeId), DistributedPondBingoManagerAI.finishGame, 'finishGame%d' % self.getDoId(), [self]) + taskMgr.doMethodLater(BingoGlobals.getGameTime(self.typeId), self.finishGame, self.uniqueName('finishGame')) diff --git a/toontown/hood/HoodAI.py b/toontown/hood/HoodAI.py index 8b0446ad..8ba9b854 100755 --- a/toontown/hood/HoodAI.py +++ b/toontown/hood/HoodAI.py @@ -5,7 +5,6 @@ from toontown.fishing.DistributedFishingPondAI import DistributedFishingPondAI from toontown.hood import ZoneUtil from toontown.safezone import TreasureGlobals from toontown.safezone.DistributedFishingSpotAI import DistributedFishingSpotAI -from toontown.fishing.DistributedPondBingoManagerAI import DistributedPondBingoManagerAI from toontown.safezone.DistributedPartyGateAI import DistributedPartyGateAI from toontown.safezone.SZTreasurePlannerAI import SZTreasurePlannerAI from toontown.suit import DistributedSuitPlannerAI @@ -90,12 +89,6 @@ class HoodAI: fishingPond.setArea(area) fishingPond.generateWithRequired(zoneId) fishingPond.start() - - fishingPond.bingoMgr = DistributedPondBingoManagerAI(simbase.air) - fishingPond.bingoMgr.setPondDoId(fishingPond.getDoId()) - fishingPond.bingoMgr.generateWithRequired(zoneId) - fishingPond.bingoMgr.initTasks() - fishingPonds.append(fishingPond) elif isinstance(dnaGroup, DNAVisGroup): zoneId = int(dnaGroup.getName().split(':')[0]) diff --git a/toontown/makeatoon/BodyShop.py b/toontown/makeatoon/BodyShop.py index 1ed6b4bd..9188e360 100755 --- a/toontown/makeatoon/BodyShop.py +++ b/toontown/makeatoon/BodyShop.py @@ -18,7 +18,6 @@ class BodyShop(StateData.StateData): self.legChoice = 0 self.headChoice = 0 self.speciesChoice = 0 - return def enter(self, toon, shopsVisited = []): base.disableMouse() diff --git a/toontown/makeatoon/ShuffleButton.py b/toontown/makeatoon/ShuffleButton.py index 47168fbc..46869042 100755 --- a/toontown/makeatoon/ShuffleButton.py +++ b/toontown/makeatoon/ShuffleButton.py @@ -51,7 +51,6 @@ class ShuffleButton: self.incBtnShowLerp = LerpColorInterval(self.incBtn, self.lerpDuration, Vec4(1, 1, 1, 1), Vec4(1, 1, 1, 0)) self.decBtnShowLerp = LerpColorInterval(self.decBtn, self.lerpDuration, Vec4(1, 1, 1, 1), Vec4(1, 1, 1, 0)) self.__updateArrows() - return def unload(self): if self.showLerp: diff --git a/toontown/safezone/DistributedFishingSpot.py b/toontown/safezone/DistributedFishingSpot.py index e757171c..078f197f 100755 --- a/toontown/safezone/DistributedFishingSpot.py +++ b/toontown/safezone/DistributedFishingSpot.py @@ -661,6 +661,8 @@ class DistributedFishingSpot(DistributedObject.DistributedObject): jar.setPos(0, 0, 0) def resetCastGui(self): + if not self.castGui: + return self.notify.debug('resetCastGui: Bingo Night Ends - resetting Gui') bucket = self.castGui.find('**/bucket') jar = self.castGui.find('**/jar')