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;
setDifficultyOverrides(int32, int32) broadcast ram required;
setAvatarJoined() airecv clsend;
setAvatarReady() airecv clsend;
setAvatarReady() broadcast airecv clsend;
setAvatarExited() airecv clsend;
requestExit() airecv clsend;
requestSkip() airecv clsend;
setSkipCount(uint8) broadcast;
setGameReady() broadcast;
setGameStart(int16) broadcast;
setGameExit() broadcast;

View file

@ -42,6 +42,7 @@ class DistributedMinigame(DistributedObject.DistributedObject):
hoodMinigameState.addChild(self.frameworkFSM)
self.rulesDoneEvent = 'rulesDone'
self.acceptOnce('minigameAbort', self.d_requestExit)
self.acceptOnce('minigameSkip', self.requestSkip)
base.curMinigame = self
self.modelCount = 500
self.cleanupActions = []
@ -213,6 +214,7 @@ class DistributedMinigame(DistributedObject.DistributedObject):
for avId in self.avIdList:
if avId != self.localAvId:
self.remoteAvIdList.append(avId)
self.setSkipCount(0)
def setTrolleyZone(self, trolleyZone):
if not self.hasLocalToon:
@ -328,7 +330,7 @@ class DistributedMinigame(DistributedObject.DistributedObject):
def enterFrameworkRules(self):
self.notify.debug('BASE: enterFrameworkRules')
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.enter()
@ -343,6 +345,9 @@ class DistributedMinigame(DistributedObject.DistributedObject):
self.sendUpdate('setAvatarReady', [])
self.frameworkFSM.request('frameworkWaitServerStart')
def setAvatarReady(self):
messenger.send('disableMinigameSkip')
def enterFrameworkWaitServerStart(self):
self.notify.debug('BASE: enterFrameworkWaitServerStart')
if self.numPlayers > 1:
@ -427,3 +432,9 @@ class DistributedMinigame(DistributedObject.DistributedObject):
def unsetEmotes(self):
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
import MinigameCreatorAI
from direct.task import Task
import random
import MinigameGlobals
from direct.showbase import PythonUtil
from toontown.toonbase import ToontownGlobals
@ -44,8 +43,8 @@ class DistributedMinigameAI(DistributedObjectAI.DistributedObjectAI):
self.scoreDict = {}
self.difficultyOverride = None
self.trolleyZoneOverride = None
return
self.skippable = True
self.skipAvIds = []
def addChildGameFSM(self, 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))
if self.frameworkFSM.getCurrentState().getName() == 'frameworkWaitClientsReady':
self.__barrier.clear(avId)
self.skippable = False
def exitFrameworkWaitClientsReady(self):
self.__barrier.cleanup()
@ -275,6 +275,7 @@ class DistributedMinigameAI(DistributedObjectAI.DistributedObjectAI):
self.stateDict[avId] = EXITED
self.notify.debug('BASE: setAvatarExited: new avId states: ' + str(self.stateDict))
self.__barrier.clear(avId)
self.checkForSkip()
def exitFrameworkWaitClientsExit(self):
self.__barrier.cleanup()
@ -293,13 +294,11 @@ class DistributedMinigameAI(DistributedObjectAI.DistributedObjectAI):
self.scoreDict[avId] *= scoreMult
scoreList = []
if not self.normalExit:
randReward = random.randrange(DEFAULT_POINTS, MAX_POINTS + 1)
for avId in self.avIdList:
if self.normalExit:
score = int(self.scoreDict[avId] + 0.5)
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:
score *= MinigameGlobals.JellybeanTrolleyHolidayScoreMultiplier
logEvent = False
@ -363,3 +362,19 @@ class DistributedMinigameAI(DistributedObjectAI.DistributedObjectAI):
def logAllPerfect(self):
for avId in self.avIdList:
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
latencyTolerance = 10.0
MaxLoadTime = 40.0
rulesDuration = 16
rulesDuration = 21
JellybeanTrolleyHolidayScoreMultiplier = 2
DifficultyOverrideMult = int(1 << 16)

View file

@ -9,19 +9,25 @@ import MinigameGlobals
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)
self.gameTitle = gameTitle
self.instructions = instructions
self.TIMEOUT = timeout
self.playerCount = playerCount
def load(self):
minigameGui = loader.loadModel('phase_4/models/gui/minigame_rules_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.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.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()
buttonGui.removeNode()
self.timer = ToontownTimer.ToontownTimer()
@ -29,9 +35,12 @@ class MinigameRulesPanel(StateData.StateData):
self.timer.setScale(0.4)
self.timer.setPos(0.997, 0, 0.064)
self.frame.hide()
return
def unload(self):
self.ignoreAll()
if hasattr(self, 'skipButton'):
self.skipButton.destroy()
del self.skipButton
self.frame.destroy()
del self.frame
del self.gameTitleText
@ -52,3 +61,9 @@ class MinigameRulesPanel(StateData.StateData):
def playCallback(self):
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'
CogThiefPerfect = 'PERFECT!'
MinigameRulesPanelPlay = 'PLAY'
MinigameRulesPanelSkip = 'SKIP\n%s/%s'
GagShopName = "Goofy's Gag Shop"
GagShopPlayAgain = 'PLAY\nAGAIN'
GagShopBackToPlayground = 'EXIT BACK TO\nPLAYGROUND'