Minigame skipping

This commit is contained in:
John 2015-06-21 22:09:31 +03:00
parent 44edf68ff7
commit 539afab9fe
6 changed files with 58 additions and 14 deletions

View file

@ -1100,9 +1100,11 @@ dclass DistributedMinigame : DistributedObject {
setTrolleyZone(uint32) broadcast ram required; setTrolleyZone(uint32) broadcast ram required;
setDifficultyOverrides(int32, int32) broadcast ram required; setDifficultyOverrides(int32, int32) broadcast ram required;
setAvatarJoined() airecv clsend; setAvatarJoined() airecv clsend;
setAvatarReady() airecv clsend; setAvatarReady() broadcast airecv clsend;
setAvatarExited() airecv clsend; setAvatarExited() airecv clsend;
requestExit() airecv clsend; requestExit() airecv clsend;
requestSkip() airecv clsend;
setSkipCount(uint8) broadcast;
setGameReady() broadcast; setGameReady() broadcast;
setGameStart(int16) broadcast; setGameStart(int16) broadcast;
setGameExit() broadcast; setGameExit() broadcast;

View file

@ -42,6 +42,7 @@ class DistributedMinigame(DistributedObject.DistributedObject):
hoodMinigameState.addChild(self.frameworkFSM) hoodMinigameState.addChild(self.frameworkFSM)
self.rulesDoneEvent = 'rulesDone' self.rulesDoneEvent = 'rulesDone'
self.acceptOnce('minigameAbort', self.d_requestExit) self.acceptOnce('minigameAbort', self.d_requestExit)
self.acceptOnce('minigameSkip', self.requestSkip)
base.curMinigame = self base.curMinigame = self
self.modelCount = 500 self.modelCount = 500
self.cleanupActions = [] self.cleanupActions = []
@ -213,6 +214,7 @@ class DistributedMinigame(DistributedObject.DistributedObject):
for avId in self.avIdList: for avId in self.avIdList:
if avId != self.localAvId: if avId != self.localAvId:
self.remoteAvIdList.append(avId) self.remoteAvIdList.append(avId)
self.setSkipCount(0)
def setTrolleyZone(self, trolleyZone): def setTrolleyZone(self, trolleyZone):
if not self.hasLocalToon: if not self.hasLocalToon:
@ -328,7 +330,7 @@ class DistributedMinigame(DistributedObject.DistributedObject):
def enterFrameworkRules(self): def enterFrameworkRules(self):
self.notify.debug('BASE: enterFrameworkRules') self.notify.debug('BASE: enterFrameworkRules')
self.accept(self.rulesDoneEvent, self.handleRulesDone) self.accept(self.rulesDoneEvent, self.handleRulesDone)
self.rulesPanel = MinigameRulesPanel.MinigameRulesPanel('MinigameRulesPanel', self.getTitle(), self.getInstructions(), self.rulesDoneEvent) self.rulesPanel = MinigameRulesPanel.MinigameRulesPanel('MinigameRulesPanel', self.getTitle(), self.getInstructions(), self.rulesDoneEvent, playerCount=len(self.avIdList))
self.rulesPanel.load() self.rulesPanel.load()
self.rulesPanel.enter() self.rulesPanel.enter()
@ -342,6 +344,9 @@ class DistributedMinigame(DistributedObject.DistributedObject):
self.notify.debug('BASE: handleRulesDone') self.notify.debug('BASE: handleRulesDone')
self.sendUpdate('setAvatarReady', []) self.sendUpdate('setAvatarReady', [])
self.frameworkFSM.request('frameworkWaitServerStart') self.frameworkFSM.request('frameworkWaitServerStart')
def setAvatarReady(self):
messenger.send('disableMinigameSkip')
def enterFrameworkWaitServerStart(self): def enterFrameworkWaitServerStart(self):
self.notify.debug('BASE: enterFrameworkWaitServerStart') self.notify.debug('BASE: enterFrameworkWaitServerStart')
@ -426,4 +431,10 @@ class DistributedMinigame(DistributedObject.DistributedObject):
Emote.globalEmote.disableAll(base.localAvatar) Emote.globalEmote.disableAll(base.localAvatar)
def unsetEmotes(self): def unsetEmotes(self):
Emote.globalEmote.releaseAll(base.localAvatar) Emote.globalEmote.releaseAll(base.localAvatar)
def requestSkip(self):
self.sendUpdate('requestSkip')
def setSkipCount(self, count):
messenger.send('gameSkipCountChange', [count, len(self.avIdList)])

View file

@ -8,7 +8,6 @@ from toontown.shtiker import PurchaseManagerAI
from toontown.shtiker import NewbiePurchaseManagerAI from toontown.shtiker import NewbiePurchaseManagerAI
import MinigameCreatorAI import MinigameCreatorAI
from direct.task import Task from direct.task import Task
import random
import MinigameGlobals import MinigameGlobals
from direct.showbase import PythonUtil from direct.showbase import PythonUtil
from toontown.toonbase import ToontownGlobals from toontown.toonbase import ToontownGlobals
@ -44,8 +43,8 @@ class DistributedMinigameAI(DistributedObjectAI.DistributedObjectAI):
self.scoreDict = {} self.scoreDict = {}
self.difficultyOverride = None self.difficultyOverride = None
self.trolleyZoneOverride = None self.trolleyZoneOverride = None
self.skippable = True
return self.skipAvIds = []
def addChildGameFSM(self, gameFSM): def addChildGameFSM(self, gameFSM):
self.frameworkFSM.getStateNamed('frameworkGame').addChild(gameFSM) self.frameworkFSM.getStateNamed('frameworkGame').addChild(gameFSM)
@ -236,6 +235,7 @@ class DistributedMinigameAI(DistributedObjectAI.DistributedObjectAI):
self.notify.debug('BASE: setAvatarReady: new avId states: ' + str(self.stateDict)) self.notify.debug('BASE: setAvatarReady: new avId states: ' + str(self.stateDict))
if self.frameworkFSM.getCurrentState().getName() == 'frameworkWaitClientsReady': if self.frameworkFSM.getCurrentState().getName() == 'frameworkWaitClientsReady':
self.__barrier.clear(avId) self.__barrier.clear(avId)
self.skippable = False
def exitFrameworkWaitClientsReady(self): def exitFrameworkWaitClientsReady(self):
self.__barrier.cleanup() self.__barrier.cleanup()
@ -275,6 +275,7 @@ class DistributedMinigameAI(DistributedObjectAI.DistributedObjectAI):
self.stateDict[avId] = EXITED self.stateDict[avId] = EXITED
self.notify.debug('BASE: setAvatarExited: new avId states: ' + str(self.stateDict)) self.notify.debug('BASE: setAvatarExited: new avId states: ' + str(self.stateDict))
self.__barrier.clear(avId) self.__barrier.clear(avId)
self.checkForSkip()
def exitFrameworkWaitClientsExit(self): def exitFrameworkWaitClientsExit(self):
self.__barrier.cleanup() self.__barrier.cleanup()
@ -293,13 +294,11 @@ class DistributedMinigameAI(DistributedObjectAI.DistributedObjectAI):
self.scoreDict[avId] *= scoreMult self.scoreDict[avId] *= scoreMult
scoreList = [] scoreList = []
if not self.normalExit:
randReward = random.randrange(DEFAULT_POINTS, MAX_POINTS + 1)
for avId in self.avIdList: for avId in self.avIdList:
if self.normalExit: if self.normalExit:
score = int(self.scoreDict[avId] + 0.5) score = int(self.scoreDict[avId] + 0.5)
else: else:
score = randReward score = 0
if ToontownGlobals.JELLYBEAN_TROLLEY_HOLIDAY in simbase.air.holidayManager.currentHolidays or ToontownGlobals.JELLYBEAN_TROLLEY_HOLIDAY_MONTH in simbase.air.holidayManager.currentHolidays: if ToontownGlobals.JELLYBEAN_TROLLEY_HOLIDAY in simbase.air.holidayManager.currentHolidays or ToontownGlobals.JELLYBEAN_TROLLEY_HOLIDAY_MONTH in simbase.air.holidayManager.currentHolidays:
score *= MinigameGlobals.JellybeanTrolleyHolidayScoreMultiplier score *= MinigameGlobals.JellybeanTrolleyHolidayScoreMultiplier
logEvent = False logEvent = False
@ -362,4 +361,20 @@ class DistributedMinigameAI(DistributedObjectAI.DistributedObjectAI):
def logAllPerfect(self): def logAllPerfect(self):
for avId in self.avIdList: for avId in self.avIdList:
self.logPerfectGame(avId) self.logPerfectGame(avId)
def requestSkip(self):
avId = self.air.getAvatarIdFromSender()
if (not self.skippable) or (avId not in self.avIdList) or (avId in self.skipAvIds):
return
self.skipAvIds.append(avId)
self.checkForSkip()
def checkForSkip(self):
if len(self.skipAvIds) >= len(self.avIdList):
self.skippable = False
self.setGameAbort()
else:
self.sendUpdate('setSkipCount', [len(self.skipAvIds)])

View file

@ -4,7 +4,7 @@ from toontown.hood import ZoneUtil
from random import choice from random import choice
latencyTolerance = 10.0 latencyTolerance = 10.0
MaxLoadTime = 40.0 MaxLoadTime = 40.0
rulesDuration = 16 rulesDuration = 21
JellybeanTrolleyHolidayScoreMultiplier = 2 JellybeanTrolleyHolidayScoreMultiplier = 2
DifficultyOverrideMult = int(1 << 16) DifficultyOverrideMult = int(1 << 16)

View file

@ -9,19 +9,25 @@ import MinigameGlobals
class MinigameRulesPanel(StateData.StateData): class MinigameRulesPanel(StateData.StateData):
def __init__(self, panelName, gameTitle, instructions, doneEvent, timeout = MinigameGlobals.rulesDuration): def __init__(self, panelName, gameTitle, instructions, doneEvent, timeout = MinigameGlobals.rulesDuration, playerCount = 0):
StateData.StateData.__init__(self, doneEvent) StateData.StateData.__init__(self, doneEvent)
self.gameTitle = gameTitle self.gameTitle = gameTitle
self.instructions = instructions self.instructions = instructions
self.TIMEOUT = timeout self.TIMEOUT = timeout
self.playerCount = playerCount
def load(self): def load(self):
minigameGui = loader.loadModel('phase_4/models/gui/minigame_rules_gui') minigameGui = loader.loadModel('phase_4/models/gui/minigame_rules_gui')
buttonGui = loader.loadModel('phase_3.5/models/gui/inventory_gui') buttonGui = loader.loadModel('phase_3.5/models/gui/inventory_gui')
buttonImage = (buttonGui.find('**/InventoryButtonUp'), buttonGui.find('**/InventoryButtonDown'), buttonGui.find('**/InventoryButtonRollover'))
self.frame = DirectFrame(image=minigameGui.find('**/minigame-rules-panel'), relief=None, pos=(0.1375, 0, -0.6667)) self.frame = DirectFrame(image=minigameGui.find('**/minigame-rules-panel'), relief=None, pos=(0.1375, 0, -0.6667))
self.gameTitleText = DirectLabel(parent=self.frame, text=self.gameTitle, scale=TTLocalizer.MRPgameTitleText, text_align=TextNode.ACenter, text_font=getSignFont(), text_fg=(1.0, 0.33, 0.33, 1.0), pos=TTLocalizer.MRgameTitleTextPos, relief=None) self.gameTitleText = DirectLabel(parent=self.frame, text=self.gameTitle, scale=TTLocalizer.MRPgameTitleText, text_align=TextNode.ACenter, text_font=getSignFont(), text_fg=(1.0, 0.33, 0.33, 1.0), pos=TTLocalizer.MRgameTitleTextPos, relief=None)
self.instructionsText = DirectLabel(parent=self.frame, text=self.instructions, scale=TTLocalizer.MRPinstructionsText, text_align=TextNode.ACenter, text_wordwrap=TTLocalizer.MRPinstructionsTextWordwrap, pos=TTLocalizer.MRPinstructionsTextPos, relief=None) self.instructionsText = DirectLabel(parent=self.frame, text=self.instructions, scale=TTLocalizer.MRPinstructionsText, text_align=TextNode.ACenter, text_wordwrap=TTLocalizer.MRPinstructionsTextWordwrap, pos=TTLocalizer.MRPinstructionsTextPos, relief=None)
self.playButton = DirectButton(parent=self.frame, relief=None, image=(buttonGui.find('**/InventoryButtonUp'), buttonGui.find('**/InventoryButtonDown'), buttonGui.find('**/InventoryButtonRollover')), image_color=Vec4(0, 0.9, 0.1, 1), text=TTLocalizer.MinigameRulesPanelPlay, text_fg=(1, 1, 1, 1), text_pos=(0, -0.02, 0), text_scale=TTLocalizer.MRPplayButton, pos=(1.0025, 0, -0.203), scale=1.05, command=self.playCallback) self.playButton = DirectButton(parent=self.frame, relief=None, image=buttonImage, image_color=Vec4(0, 0.9, 0.1, 1), text=TTLocalizer.MinigameRulesPanelPlay, text_fg=(1, 1, 1, 1), text_pos=(0, -0.02, 0), text_scale=TTLocalizer.MRPplayButton, pos=(1.0025, 0, -0.203), scale=1.05, command=self.playCallback)
if self.playerCount:
self.skipButton = DirectButton(parent=self.frame, relief=None, image=buttonImage, image_color=Vec4(0, 0.9, 0.1, 1), text=TTLocalizer.MinigameRulesPanelSkip % (0, self.playerCount), text_fg=(1, 1, 1, 1), text_pos=(0, 0.01, 0), text_scale=0.045, pos=(0, 0, 0.25), scale=1.05, command=self.skipCallback)
self.acceptOnce('disableMinigameSkip', self.skipButton.hide)
self.accept('gameSkipCountChange', self.updateSkipButton)
minigameGui.removeNode() minigameGui.removeNode()
buttonGui.removeNode() buttonGui.removeNode()
self.timer = ToontownTimer.ToontownTimer() self.timer = ToontownTimer.ToontownTimer()
@ -29,9 +35,12 @@ class MinigameRulesPanel(StateData.StateData):
self.timer.setScale(0.4) self.timer.setScale(0.4)
self.timer.setPos(0.997, 0, 0.064) self.timer.setPos(0.997, 0, 0.064)
self.frame.hide() self.frame.hide()
return
def unload(self): def unload(self):
self.ignoreAll()
if hasattr(self, 'skipButton'):
self.skipButton.destroy()
del self.skipButton
self.frame.destroy() self.frame.destroy()
del self.frame del self.frame
del self.gameTitleText del self.gameTitleText
@ -52,3 +61,9 @@ class MinigameRulesPanel(StateData.StateData):
def playCallback(self): def playCallback(self):
messenger.send(self.doneEvent) messenger.send(self.doneEvent)
def skipCallback(self):
messenger.send('minigameSkip')
def updateSkipButton(self, min, max):
self.skipButton['text'] = TTLocalizer.MinigameRulesPanelSkip % (min, max)

View file

@ -4418,6 +4418,7 @@ CogThiefBarrelSaved = '%(num)d Barrel\nSaved!'
CogThiefNoBarrelsSaved = 'No Barrels\nSaved' CogThiefNoBarrelsSaved = 'No Barrels\nSaved'
CogThiefPerfect = 'PERFECT!' CogThiefPerfect = 'PERFECT!'
MinigameRulesPanelPlay = 'PLAY' MinigameRulesPanelPlay = 'PLAY'
MinigameRulesPanelSkip = 'SKIP\n%s/%s'
GagShopName = "Goofy's Gag Shop" GagShopName = "Goofy's Gag Shop"
GagShopPlayAgain = 'PLAY\nAGAIN' GagShopPlayAgain = 'PLAY\nAGAIN'
GagShopBackToPlayground = 'EXIT BACK TO\nPLAYGROUND' GagShopBackToPlayground = 'EXIT BACK TO\nPLAYGROUND'