Fix the damn butterflies

This commit is contained in:
John Cote 2015-06-10 22:20:40 -04:00
parent 1326599905
commit a380e1e6d9
12 changed files with 100 additions and 70 deletions

View file

@ -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

View file

@ -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()
self.trolley.start()

View file

@ -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()
self.boat.start()

View file

@ -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()

View file

@ -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)

View file

@ -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')
taskMgr.doMethodLater(10, self.cycleLeaderBoards, 'leaderBoardSwitch')

View file

@ -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()
self.trolley.start()

View file

@ -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()):

View file

@ -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)

View file

@ -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()

View file

@ -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)

View file

@ -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