oldschool-toontown/toontown/effects/DistributedFireworkShowAI.py

67 lines
2.9 KiB
Python
Raw Normal View History

2019-11-02 17:27:54 -05:00
from otp.ai.AIBaseGlobal import *
from direct.distributed import DistributedObjectAI
from direct.directnotify import DirectNotifyGlobal
from direct.distributed import ClockDelta
from .FireworkShow import FireworkShow
from .FireworkShows import getShowDuration
2019-11-02 17:27:54 -05:00
from direct.task import Task
class DistributedFireworkShowAI(DistributedObjectAI.DistributedObjectAI):
2022-12-31 03:20:47 -06:00
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedFireworkShowAI")
def __init__(self, air, fireworkMgr=None):
2019-11-02 17:27:54 -05:00
DistributedObjectAI.DistributedObjectAI.__init__(self, air)
self.fireworkMgr = fireworkMgr
2022-12-31 03:20:47 -06:00
self.eventId = None # either a holiday name constant from ToontownGlobals
# or a FireworkShows from PartyGlobals
2019-11-02 17:27:54 -05:00
self.style = None
self.timestamp = None
self.throwAwayShow = FireworkShow()
def delete(self):
del self.throwAwayShow
2022-12-31 03:20:47 -06:00
taskMgr.remove(self.taskName("waitForShowDone"))
2019-11-02 17:27:54 -05:00
DistributedObjectAI.DistributedObjectAI.delete(self)
def d_startShow(self, eventId, style):
timestamp = ClockDelta.globalClockDelta.getRealNetworkTime()
self.eventId = eventId
self.style = style
self.timestamp = timestamp
2022-12-31 03:20:47 -06:00
self.sendUpdate("startShow",
(self.eventId, self.style, self.timestamp))
2019-11-02 17:27:54 -05:00
if simbase.air.config.GetBool('want-old-fireworks', 0):
duration = getShowDuration(self.eventId, self.style)
2022-12-31 03:20:47 -06:00
taskMgr.doMethodLater(duration, self.fireworkShowDone, self.taskName("waitForShowDone"))
2019-11-02 17:27:54 -05:00
else:
2022-12-31 03:20:47 -06:00
2019-11-02 17:27:54 -05:00
duration = self.throwAwayShow.getShowDuration(self.eventId)
2022-12-31 03:20:47 -06:00
assert( DistributedFireworkShowAI.notify.debug("startShow: event: %s, networkTime: %s, showDuration: %s" \
% (self.eventId, self.timestamp, duration) ) )
# Add the start and postShow delays and give ample time for postshow to complete
2019-11-02 17:27:54 -05:00
duration += 20.0
2022-12-31 03:20:47 -06:00
taskMgr.doMethodLater(duration, self.fireworkShowDone, self.taskName("waitForShowDone"))
2019-11-02 17:27:54 -05:00
def fireworkShowDone(self, task):
2022-12-31 03:20:47 -06:00
self.notify.debug("fireworkShowDone")
# Tell the firework manager to stop us, we are done
2019-11-02 17:27:54 -05:00
if self.fireworkMgr:
self.fireworkMgr.stopShow(self.zoneId)
return Task.done
def requestFirework(self, x, y, z, style, color1, color2):
avId = self.air.getAvatarIdFromSender()
2022-12-31 03:20:47 -06:00
self.notify.debug("requestFirework: avId: %s, style: %s" % (avId, style))
# TODO: check permissions, check cost, etc
2019-11-02 17:27:54 -05:00
if self.fireworkMgr:
if self.fireworkMgr.isShowRunning(self.zoneId):
self.d_shootFirework(x, y, z, style, color1, color2)
2022-12-31 03:20:47 -06:00
# Charge the avId some jellybeans
2019-11-02 17:27:54 -05:00
else:
2022-12-31 03:20:47 -06:00
self.d_shootFirework(x, y, z, style, color1,color2)
2019-11-02 17:27:54 -05:00
def d_shootFirework(self, x, y, z, style, color1, color2):
2022-12-31 03:20:47 -06:00
self.sendUpdate("shootFirework", (x, y, z, style, color1, color2))