diff --git a/dependencies/config/general.prc b/dependencies/config/general.prc index f1030914..23cae64b 100644 --- a/dependencies/config/general.prc +++ b/dependencies/config/general.prc @@ -67,7 +67,7 @@ want-golf-zone #t # Safe zone settings: want-treasure-planners #t want-suit-planners #t -want-butterflies #f +want-butterflies #t # Trolley minigames: want-minigames #t diff --git a/toontown/hood/BRHoodAI.py b/toontown/hood/BRHoodAI.py index 88d79993..c1f159b5 100755 --- a/toontown/hood/BRHoodAI.py +++ b/toontown/hood/BRHoodAI.py @@ -22,7 +22,7 @@ class BRHoodAI(HoodAI.HoodAI): self.PolarPlaceEffectManager = DistributedPolarPlaceEffectMgrAI.DistributedPolarPlaceEffectMgrAI(self.air) self.PolarPlaceEffectManager.generateWithRequired(3821) - + if simbase.air.wantHalloween: self.TrickOrTreatTargetManager = DistributedTrickOrTreatTargetAI.DistributedTrickOrTreatTargetAI(self.air) self.TrickOrTreatTargetManager.generateWithRequired(3707) @@ -30,4 +30,4 @@ class BRHoodAI(HoodAI.HoodAI): def createTrolley(self): self.trolley = DistributedTrolleyAI.DistributedTrolleyAI(self.air) self.trolley.generateWithRequired(self.zoneId) - self.trolley.start() \ No newline at end of file + self.trolley.start() diff --git a/toontown/hood/DDHoodAI.py b/toontown/hood/DDHoodAI.py index 6a84791e..3ceea6a9 100755 --- a/toontown/hood/DDHoodAI.py +++ b/toontown/hood/DDHoodAI.py @@ -22,7 +22,7 @@ class DDHoodAI(HoodAI.HoodAI): if simbase.config.GetBool('want-minigames', True): self.createTrolley() self.createBoat() - + if simbase.air.wantHalloween: self.TrickOrTreatTargetManager = DistributedTrickOrTreatTargetAI.DistributedTrickOrTreatTargetAI(self.air) self.TrickOrTreatTargetManager.generateWithRequired(1834) @@ -35,4 +35,4 @@ class DDHoodAI(HoodAI.HoodAI): def createBoat(self): self.boat = DistributedBoatAI.DistributedBoatAI(self.air) self.boat.generateWithRequired(self.zoneId) - self.boat.start() \ No newline at end of file + self.boat.start() diff --git a/toontown/hood/DGHoodAI.py b/toontown/hood/DGHoodAI.py index 0b553ac6..5e049939 100755 --- a/toontown/hood/DGHoodAI.py +++ b/toontown/hood/DGHoodAI.py @@ -27,10 +27,10 @@ class DGHoodAI(HoodAI.HoodAI): self.createFlower() if simbase.config.GetBool('want-butterflies', True): self.createButterflies() - + #self.GreenToonEffectManager = DistributedGreenToonEffectMgrAI.DistributedGreenToonEffectMgrAI(self.air) #self.GreenToonEffectManager.generateWithRequired(5819) - + if simbase.air.wantHalloween: self.TrickOrTreatTargetManager = DistributedTrickOrTreatTargetAI.DistributedTrickOrTreatTargetAI(self.air) self.TrickOrTreatTargetManager.generateWithRequired(5620) @@ -50,10 +50,11 @@ class DGHoodAI(HoodAI.HoodAI): self.flower.generateWithRequired(self.zoneId) self.flower.start() - def createButterflies(self, playground): + def createButterflies(self): + playground = ButterflyGlobals.DG ButterflyGlobals.generateIndexes(self.zoneId, ButterflyGlobals.DG) for i in xrange(0, ButterflyGlobals.NUM_BUTTERFLY_AREAS[ButterflyGlobals.DG]): for _ in xrange(0, ButterflyGlobals.NUM_BUTTERFLIES[ButterflyGlobals.DG]): - butterfly = DistributedButterflyAI(self.air, playground, i, self.zoneId) + butterfly = DistributedButterflyAI.DistributedButterflyAI(self.air, playground, i, self.zoneId) butterfly.generateWithRequired(self.zoneId) butterfly.start() diff --git a/toontown/hood/DLHoodAI.py b/toontown/hood/DLHoodAI.py index f66b3e7d..245a4c8e 100755 --- a/toontown/hood/DLHoodAI.py +++ b/toontown/hood/DLHoodAI.py @@ -22,7 +22,7 @@ class DLHoodAI(HoodAI.HoodAI): self.createTrolley() self.resistanceEmoteManager = DistributedResistanceEmoteMgrAI.DistributedResistanceEmoteMgrAI(self.air) self.resistanceEmoteManager.generateWithRequired(9720) - + if simbase.air.wantHalloween: self.TrickOrTreatTargetManager = DistributedTrickOrTreatTargetAI.DistributedTrickOrTreatTargetAI(self.air) self.TrickOrTreatTargetManager.generateWithRequired(9619) diff --git a/toontown/hood/GSHoodAI.py b/toontown/hood/GSHoodAI.py index 726737ca..737a7f6e 100755 --- a/toontown/hood/GSHoodAI.py +++ b/toontown/hood/GSHoodAI.py @@ -142,4 +142,4 @@ class GSHoodAI(HoodAI.HoodAI): def cycleLeaderBoards(self, task=None): messenger.send('leaderBoardSwap-' + str(self.zoneId)) - taskMgr.doMethodLater(10, self.cycleLeaderBoards, 'leaderBoardSwitch') \ No newline at end of file + taskMgr.doMethodLater(10, self.cycleLeaderBoards, 'leaderBoardSwitch') diff --git a/toontown/hood/MMHoodAI.py b/toontown/hood/MMHoodAI.py index 3755109c..a8ae2a11 100755 --- a/toontown/hood/MMHoodAI.py +++ b/toontown/hood/MMHoodAI.py @@ -31,4 +31,4 @@ class MMHoodAI(HoodAI.HoodAI): def createTrolley(self): self.trolley = DistributedTrolleyAI.DistributedTrolleyAI(self.air) self.trolley.generateWithRequired(self.zoneId) - self.trolley.start() \ No newline at end of file + self.trolley.start() diff --git a/toontown/hood/OZHoodAI.py b/toontown/hood/OZHoodAI.py index d7aa7a28..ba253095 100755 --- a/toontown/hood/OZHoodAI.py +++ b/toontown/hood/OZHoodAI.py @@ -36,7 +36,6 @@ class OZHoodAI(HoodAI.HoodAI): self.timer = DistributedTimerAI(self.air) self.timer.generateWithRequired(self.zoneId) - def findPicnicTables(self, dnaGroup, zoneId, area, overrideDNAZone=False): picnicTables = [] if isinstance(dnaGroup, DNAGroup) and ('picnic_table' in dnaGroup.getName()): diff --git a/toontown/hood/SellbotHQAI.py b/toontown/hood/SellbotHQAI.py index fa87f6a7..093282a2 100755 --- a/toontown/hood/SellbotHQAI.py +++ b/toontown/hood/SellbotHQAI.py @@ -48,7 +48,7 @@ class SellbotHQAI(CogHQAI.CogHQAI): self.air, self.air.factoryMgr, ToontownGlobals.SellbotFactoryInt, i) factoryElevator.generateWithRequired(ToontownGlobals.SellbotFactoryExt) self.factoryElevators.append(factoryElevator) - + if simbase.config.GetBool('want-megacorp', True): factoryElevator = DistributedFactoryElevatorExtAI( self.air, self.air.factoryMgr, ToontownGlobals.SellbotMegaCorpInt, 2) diff --git a/toontown/hood/TTHoodAI.py b/toontown/hood/TTHoodAI.py index 69817bf0..c4ed3f39 100755 --- a/toontown/hood/TTHoodAI.py +++ b/toontown/hood/TTHoodAI.py @@ -27,7 +27,7 @@ class TTHoodAI(HoodAI.HoodAI): self.createTrolley() if simbase.config.GetBool('want-butterflies', True): self.createButterflies() - + NPCToons.createNPC( simbase.air, 2021, (ToontownGlobals.ToontownCentral, TTLocalizer.NPCToonNames[2021], ('dss', 'ls', 's', 'm', 13, 41, 13, 13, 1, 6, 1, 6, 0, 18, 0), 'm', 1, NPCToons.NPC_GLOVE), @@ -36,7 +36,7 @@ class TTHoodAI(HoodAI.HoodAI): if simbase.air.wantHalloween: self.TrickOrTreatTargetManager = DistributedTrickOrTreatTargetAI.DistributedTrickOrTreatTargetAI(self.air) self.TrickOrTreatTargetManager.generateWithRequired(2649) - + if simbase.air.wantChristmas: self.WinterCarolingTargetManager = DistributedWinterCarolingTargetAI.DistributedWinterCarolingTargetAI(self.air) self.WinterCarolingTargetManager.generateWithRequired(2649) @@ -55,9 +55,10 @@ class TTHoodAI(HoodAI.HoodAI): self.trolley.start() def createButterflies(self): + playground = ButterflyGlobals.TTC ButterflyGlobals.generateIndexes(self.zoneId, ButterflyGlobals.TTC) for i in xrange(0, ButterflyGlobals.NUM_BUTTERFLY_AREAS[ButterflyGlobals.TTC]): for _ in xrange(0, ButterflyGlobals.NUM_BUTTERFLIES[ButterflyGlobals.TTC]): - butterfly = DistributedButterflyAI(self.air, playground, i, self.zoneId) + butterfly = DistributedButterflyAI.DistributedButterflyAI(self.air, playground, i, self.zoneId) butterfly.generateWithRequired(self.zoneId) butterfly.start() diff --git a/toontown/safezone/ButterflyGlobals.py b/toontown/safezone/ButterflyGlobals.py index c6dd941e..d6cde7da 100755 --- a/toontown/safezone/ButterflyGlobals.py +++ b/toontown/safezone/ButterflyGlobals.py @@ -6,7 +6,7 @@ LANDED = 2 states = {OFF: 'off', FLYING: 'Flying', LANDED: 'Landed'} -NUM_BUTTERFLIES = (6, 36, 5) # gg spawning too many butterflies causes Astron to kick some people. +NUM_BUTTERFLIES = (6, 36, 5) NUM_BUTTERFLY_AREAS = (4, 1, 4) BUTTERFLY_SPEED = 2.0 BUTTERFLY_HEIGHT = (2.2, 3.2, 2.2) diff --git a/toontown/safezone/DistributedButterflyAI.py b/toontown/safezone/DistributedButterflyAI.py index e2f31549..7c1ab322 100755 --- a/toontown/safezone/DistributedButterflyAI.py +++ b/toontown/safezone/DistributedButterflyAI.py @@ -1,70 +1,99 @@ from direct.directnotify import DirectNotifyGlobal from direct.distributed.DistributedObjectAI import DistributedObjectAI +from otp.ai.AIBase import * +from toontown.toonbase.ToontownGlobals import * from direct.distributed.ClockDelta import * +from direct.fsm import ClassicFSM, State +from direct.fsm import State +from direct.task import Task import ButterflyGlobals import random class DistributedButterflyAI(DistributedObjectAI): notify = DirectNotifyGlobal.directNotify.newCategory("DistributedButterflyAI") - def __init__(self, air): + def __init__(self, air, playground, area, ownerId): DistributedObjectAI.__init__(self, air) - self.area = 0 - self.playground = 0 - self.stateIndex = 0 - self.curIndex = 0 - self.destIndex = 0 - self.time = 0 - self.timestamp = 0 - - def generate(self): - ButterflyGlobals.generateIndexes(self.doId, self.playground) - fr = ButterflyGlobals.getFirstRoute(self.playground, self.area, self.doId) - self.b_setState(ButterflyGlobals.FLYING, fr[1], fr[3], fr[4], globalClockDelta.getRealNetworkTime()) - taskMgr.doMethodLater(fr[4], self.__land, 'landButterfly%i' % self.doId, []) - - def __land(self): - ttl = random.uniform(0, ButterflyGlobals.MAX_LANDED_TIME) - self.b_setState(ButterflyGlobals.LANDED, self.curIndex, self.destIndex, ttl, globalClockDelta.getRealNetworkTime()) - taskMgr.doMethodLater(ttl, self.__fly, 'flyButterfly%i' % self.doId, []) - - def __fly(self): - next = ButterflyGlobals.getNextPos(ButterflyGlobals.ButterflyPoints[self.playground][self.area][self.destIndex], self.playground, self.area, self.doId) - - self.b_setState(ButterflyGlobals.FLYING, self.destIndex, next[1], next[2], globalClockDelta.getRealNetworkTime()) - taskMgr.doMethodLater(next[2], self.__land, 'landButterfly%i' % self.doId, []) - - def setArea(self, playground, area): - self.area = area self.playground = playground - - def d_setArea(self, playground, area): - self.sendUpdate('setArea', [playground, area]) - - def b_setArea(self, playground, area): - self.setArea(playground, area) - self.d_setArea(playground, area) - + self.area = area + self.ownerId = ownerId + self.fsm = ClassicFSM.ClassicFSM('DistributedButterfliesAI', [State.State('off', self.enterOff, self.exitOff, ['Flying', 'Landed']), State.State('Flying', self.enterFlying, self.exitFlying, ['Landed']), State.State('Landed', self.enterLanded, self.exitLanded, ['Flying'])], 'off', 'off') + self.fsm.enterInitialState() + self.curPos, self.curIndex, self.destPos, self.destIndex, self.time = ButterflyGlobals.getFirstRoute(self.playground, self.area, self.ownerId) + return None + + def delete(self): + try: + self.butterfly_deleted + except: + self.butterfly_deleted = 1 + ButterflyGlobals.recycleIndex(self.curIndex, self.playground, self.area, self.ownerId) + ButterflyGlobals.recycleIndex(self.destIndex, self.playground, self.area, self.ownerId) + self.fsm.request('off') + del self.fsm + DistributedObjectAI.delete(self) + + def d_setState(self, stateIndex, curIndex, destIndex, time): + self.sendUpdate('setState', [stateIndex, + curIndex, + destIndex, + time, + globalClockDelta.getRealNetworkTime()]) + def getArea(self): return [self.playground, self.area] - def setState(self, stateIndex, curIndex, destIndex, time, timestamp): - self.stateIndex = stateIndex - self.curIndex = curIndex - self.destIndex = destIndex - self.time = time - self.timestamp = timestamp - - def d_setState(self, stateIndex, curIndex, destIndex, time, timestamp): - self.sendUpdate('setState', [stateIndex, curIndex, destIndex, time, timestamp]) - - def b_setState(self, stateIndex, curIndex, destIndex, time, timestamp): - self.setState(stateIndex, curIndex, destIndex, time, timestamp) - self.d_setState(stateIndex, curIndex, destIndex, time, timestamp) - def getState(self): - return [self.stateIndex, self.curIndex, self.destIndex, self.time, self.timestamp] + return [self.stateIndex, + self.curIndex, + self.destIndex, + self.time, + globalClockDelta.getRealNetworkTime()] + + def start(self): + self.fsm.request('Flying') def avatarEnter(self): - pass + if self.fsm.getCurrentState().getName() == 'Landed': + self.__ready() + return None + def enterOff(self): + self.stateIndex = ButterflyGlobals.OFF + return None + + def exitOff(self): + return None + + def enterFlying(self): + self.stateIndex = ButterflyGlobals.FLYING + ButterflyGlobals.recycleIndex(self.curIndex, self.playground, self.area, self.ownerId) + self.d_setState(ButterflyGlobals.FLYING, self.curIndex, self.destIndex, self.time) + taskMgr.doMethodLater(self.time, self.__handleArrival, self.uniqueName('butter-flying')) + return None + + def exitFlying(self): + taskMgr.remove(self.uniqueName('butter-flying')) + return None + + def __handleArrival(self, task): + self.curPos = self.destPos + self.curIndex = self.destIndex + self.fsm.request('Landed') + return Task.done + + def enterLanded(self): + self.stateIndex = ButterflyGlobals.LANDED + self.time = random.random() * ButterflyGlobals.MAX_LANDED_TIME + self.d_setState(ButterflyGlobals.LANDED, self.curIndex, self.destIndex, self.time) + taskMgr.doMethodLater(self.time, self.__ready, self.uniqueName('butter-ready')) + return None + + def exitLanded(self): + taskMgr.remove(self.uniqueName('butter-ready')) + return None + + def __ready(self, task = None): + self.destPos, self.destIndex, self.time = ButterflyGlobals.getNextPos(self.curPos, self.playground, self.area, self.ownerId) + self.fsm.request('Flying') + return Task.done