def createMinigame(air, playerArray, trolleyZone, minigameZone=None, previousGameId=ToontownGlobals.NoPreviousGameId, newbieIds=[], startingVotes=None, metagameRound=-1, desiredNextGame=None): if minigameZone == None: minigameZone = air.allocateZone() acquireMinigameZone(minigameZone) mgId = None mgDiff = None mgSzId = None for avId in playerArray: request = RequestMinigame.get(avId) if request != None: mgId, mgKeep, mgDiff, mgSzId = request if not mgKeep: del RequestMinigame[avId] break if mgId != None: pass else: if simbase.forcedMinigameId: mgId = simbase.forcedMinigameId else: randomList = list( copy.copy( ToontownGlobals.MinigamePlayerMatrix[len(playerArray)])) if simbase.air.useAllMinigames and len(playerArray) > 1: randomList = list(copy.copy(ToontownGlobals.MinigameIDs)) for gameId in [ToontownGlobals.TravelGameId]: if gameId in randomList: randomList.remove(gameId) for gameId in [ToontownGlobals.TravelGameId]: if gameId in randomList: randomList.remove(gameId) if previousGameId != ToontownGlobals.NoPreviousGameId: if randomList.count(previousGameId) != 0: randomList.remove(previousGameId) randomList = removeUnreleasedMinigames(randomList, True) mgId = random.choice(randomList) if metagameRound > -1: if metagameRound % 2 == 0: mgId = ToontownGlobals.TravelGameId elif desiredNextGame: mgId = desiredNextGame mgCtors = { ToontownGlobals.RaceGameId: DistributedRaceGameAI.DistributedRaceGameAI, ToontownGlobals.CannonGameId: DistributedCannonGameAI.DistributedCannonGameAI, ToontownGlobals.TagGameId: DistributedTagGameAI.DistributedTagGameAI, ToontownGlobals.PatternGameId: DistributedPatternGameAI.DistributedPatternGameAI, ToontownGlobals.RingGameId: DistributedRingGameAI.DistributedRingGameAI, ToontownGlobals.MazeGameId: DistributedMazeGameAI.DistributedMazeGameAI, ToontownGlobals.TugOfWarGameId: DistributedTugOfWarGameAI.DistributedTugOfWarGameAI, ToontownGlobals.CatchGameId: DistributedCatchGameAI.DistributedCatchGameAI, ToontownGlobals.DivingGameId: DistributedDivingGameAI.DistributedDivingGameAI, ToontownGlobals.TargetGameId: DistributedTargetGameAI.DistributedTargetGameAI, ToontownGlobals.MinigameTemplateId: DistributedMinigameTemplateAI.DistributedMinigameTemplateAI, ToontownGlobals.PairingGameId: DistributedPairingGameAI.DistributedPairingGameAI, ToontownGlobals.VineGameId: DistributedVineGameAI.DistributedVineGameAI, ToontownGlobals.IceGameId: DistributedIceGameAI.DistributedIceGameAI, ToontownGlobals.CogThiefGameId: DistributedCogThiefGameAI.DistributedCogThiefGameAI, ToontownGlobals.TwoDGameId: DistributedTwoDGameAI.DistributedTwoDGameAI, ToontownGlobals.TravelGameId: DistributedTravelGameAI.DistributedTravelGameAI, ToontownGlobals.PhotoGameId: DistributedPhotoGameAI.DistributedPhotoGameAI } if ALLOW_TEMP_MINIGAMES: from TempMinigameAI import TempMgCtors for key, value in TempMgCtors.items(): mgCtors[key] = value try: mg = mgCtors[mgId](air, mgId) except KeyError: raise Exception, 'unknown minigame ID: %s' % mgId mg.setExpectedAvatars(playerArray) mg.setNewbieIds(newbieIds) mg.setTrolleyZone(trolleyZone) mg.setDifficultyOverrides(mgDiff, mgSzId) if startingVotes == None: for avId in playerArray: mg.setStartingVote(avId, TravelGameGlobals.DefaultStartingVotes) else: for index in xrange(len(startingVotes)): avId = playerArray[index] votes = startingVotes[index] if votes < 0: print 'createMinigame negative votes, avId=%s votes=%s' % ( avId, votes) votes = 0 mg.setStartingVote(avId, votes) mg.setMetagameRound(metagameRound) mg.generateWithRequired(minigameZone) toons = [] for id in playerArray: toon = simbase.air.doId2do.get(id) if toon != None: toons.append(toon) for toon in toons: simbase.air.questManager.toonPlayedMinigame(toon, toons) retVal = {} retVal['minigameZone'] = minigameZone retVal['minigameId'] = mgId return retVal
def createMinigame(air, playerArray, trolleyZone, minigameZone = None, previousGameId = ToontownGlobals.NoPreviousGameId, newbieIds = [], startingVotes = None, metagameRound = -1, desiredNextGame = None): if minigameZone == None: minigameZone = air.allocateZone() acquireMinigameZone(minigameZone) excludeList = [ToontownGlobals.TravelGameId] if trolleyZone == ToontownGlobals.FunnyFarm: trolleyZone = config.GetInt('funny-farm-trolley-fake-hood', ToontownGlobals.DonaldsDreamland) # the games below need to be disabled on FF bc there's no support for them! excludeList.extend([ToontownGlobals.MazeGameId, ToontownGlobals.CogThiefGameId, ToontownGlobals.PhotoGameId]) mgId = None mgDiff = None mgSzId = None for avId in playerArray: request = RequestMinigame.get(avId) if request != None: mgId, mgKeep, mgDiff, mgSzId = request if not mgKeep: del RequestMinigame[avId] break if mgId != None: pass elif simbase.forcedMinigameId: mgId = simbase.forcedMinigameId else: randomList = list(copy.copy(ToontownGlobals.MinigamePlayerMatrix[len(playerArray)])) if simbase.air.useAllMinigames and len(playerArray) > 1: randomList = list(copy.copy(ToontownGlobals.MinigameIDs)) for gameId in excludeList: if gameId in randomList: randomList.remove(gameId) for gameId in [ToontownGlobals.TravelGameId]: if gameId in randomList: randomList.remove(gameId) if previousGameId != ToontownGlobals.NoPreviousGameId: if randomList.count(previousGameId) != 0 and len(randomList) > 1: randomList.remove(previousGameId) randomList = removeUnreleasedMinigames(randomList, True) mgId = random.choice(randomList) if metagameRound > -1: if metagameRound % 2 == 0: mgId = ToontownGlobals.TravelGameId elif desiredNextGame: mgId = desiredNextGame mgCtors = {ToontownGlobals.RaceGameId: DistributedRaceGameAI.DistributedRaceGameAI, ToontownGlobals.CannonGameId: DistributedCannonGameAI.DistributedCannonGameAI, ToontownGlobals.TagGameId: DistributedTagGameAI.DistributedTagGameAI, ToontownGlobals.PatternGameId: DistributedPatternGameAI.DistributedPatternGameAI, ToontownGlobals.RingGameId: DistributedRingGameAI.DistributedRingGameAI, ToontownGlobals.MazeGameId: DistributedMazeGameAI.DistributedMazeGameAI, ToontownGlobals.TugOfWarGameId: DistributedTugOfWarGameAI.DistributedTugOfWarGameAI, ToontownGlobals.CatchGameId: DistributedCatchGameAI.DistributedCatchGameAI, ToontownGlobals.DivingGameId: DistributedDivingGameAI.DistributedDivingGameAI, ToontownGlobals.TargetGameId: DistributedTargetGameAI.DistributedTargetGameAI, ToontownGlobals.MinigameTemplateId: DistributedMinigameTemplateAI.DistributedMinigameTemplateAI, ToontownGlobals.PairingGameId: DistributedPairingGameAI.DistributedPairingGameAI, ToontownGlobals.VineGameId: DistributedVineGameAI.DistributedVineGameAI, ToontownGlobals.IceGameId: DistributedIceGameAI.DistributedIceGameAI, ToontownGlobals.CogThiefGameId: DistributedCogThiefGameAI.DistributedCogThiefGameAI, ToontownGlobals.TwoDGameId: DistributedTwoDGameAI.DistributedTwoDGameAI, ToontownGlobals.TravelGameId: DistributedTravelGameAI.DistributedTravelGameAI, ToontownGlobals.PhotoGameId: DistributedPhotoGameAI.DistributedPhotoGameAI} if ALLOW_TEMP_MINIGAMES: from TempMinigameAI import TempMgCtors for key, value in TempMgCtors.items(): mgCtors[key] = value try: mg = mgCtors[mgId](air, mgId) except KeyError: raise Exception, 'unknown minigame ID: %s' % mgId mg.setExpectedAvatars(playerArray) mg.setNewbieIds(newbieIds) mg.setTrolleyZone(trolleyZone) mg.setDifficultyOverrides(mgDiff, mgSzId) if startingVotes == None: for avId in playerArray: mg.setStartingVote(avId, TravelGameGlobals.DefaultStartingVotes) else: for index in range(len(startingVotes)): avId = playerArray[index] votes = startingVotes[index] if votes < 0: print 'createMinigame negative votes, avId=%s votes=%s' % (avId, votes) votes = 0 mg.setStartingVote(avId, votes) mg.setMetagameRound(metagameRound) mg.generateWithRequired(minigameZone) toons = [] for id in playerArray: toon = simbase.air.doId2do.get(id) if toon != None: toons.append(toon) retVal = {} retVal['minigameZone'] = minigameZone retVal['minigameId'] = mgId return retVal
def createMinigame(air, playerArray, trolleyZone, minigameZone=None, previousGameId=ToontownGlobals.NoPreviousGameId, newbieIds=[], startingVotes=None, metagameRound=-1, desiredNextGame=None): if minigameZone is None: minigameZone = air.allocateZone() acquireMinigameZone(minigameZone) mgId = None mgDiff = None mgSzId = None for avId in playerArray: request = RequestMinigame.get(avId) if request is not None: mgId, mgKeep, mgDiff, mgSzId = request if not mgKeep: del RequestMinigame[avId] break if mgId is not None: pass elif simbase.forcedMinigameId: mgId = simbase.forcedMinigameId else: #randomList = list(copy.copy(ToontownGlobals.MinigamePlayerMatrix[len(playerArray)])) #if len(playerArray) > 1: # randomList = list(copy.copy(ToontownGlobals.MinigameIDs)) randomList = [ ToontownGlobals.CannonGameId, ToontownGlobals.PatternGameId, ToontownGlobals.TugOfWarGameId ] if len(playerArray) > 1: randomList = list(randomList) randomList.append(ToontownGlobals.TagGameId) #for gameId in [ToontownGlobals.TravelGameId] + getDisabledMinigames(): # if gameId in randomList: # randomList.remove(gameId) #if previousGameId != ToontownGlobals.NoPreviousGameId: # if randomList.count(previousGameId) != 0 and len(randomList) > 1: # randomList.remove(previousGameId) mgId = random.choice(randomList) #if metagameRound > -1: # if (metagameRound%2) == 0: # mgId = ToontownGlobals.TravelGameId # if desiredNextGame: # mgId = desiredNextGame mgCtors = { ToontownGlobals.RaceGameId: DistributedRaceGameAI.DistributedRaceGameAI, ToontownGlobals.CannonGameId: DistributedCannonGameAI.DistributedCannonGameAI, ToontownGlobals.TagGameId: DistributedTagGameAI.DistributedTagGameAI, ToontownGlobals.PatternGameId: DistributedPatternGameAI.DistributedPatternGameAI, ToontownGlobals.RingGameId: DistributedRingGameAI.DistributedRingGameAI, ToontownGlobals.MazeGameId: DistributedMazeGameAI.DistributedMazeGameAI, ToontownGlobals.TugOfWarGameId: DistributedTugOfWarGameAI.DistributedTugOfWarGameAI, ToontownGlobals.CatchGameId: DistributedCatchGameAI.DistributedCatchGameAI, } from TempMinigameAI import TempMgCtors for key, value in TempMgCtors.items(): mgCtors[key] = value try: mg = mgCtors[mgId](air, mgId) except Exception as e: raise (e) mg.setExpectedAvatars(playerArray) mg.setNewbieIds(newbieIds) mg.setTrolleyZone(trolleyZone) mg.setDifficultyOverrides(mgDiff, mgSzId) if startingVotes == None: for avId in playerArray: mg.setStartingVote(avId, TravelGameGlobals.DefaultStartingVotes) else: for index in xrange(len(startingVotes)): avId = playerArray[index] votes = startingVotes[index] if votes < 0: print 'createMinigame negative votes, avId=%s votes=%s' % ( avId, votes) votes = 0 mg.setStartingVote(avId, votes) mg.setMetagameRound(metagameRound) mg.generateWithRequired(minigameZone) toons = [] for doId in playerArray: toon = simbase.air.doId2do.get(doId) if toon is not None: toons.append(toon) for toon in toons: simbase.air.questManager.toonPlayedMinigame(toon, toons) retVal = {} retVal['minigameZone'] = minigameZone retVal['minigameId'] = mgId return retVal
def createMinigame(air, playerArray, trolleyZone, minigameZone=None, previousGameId=ToontownGlobals.NoPreviousGameId, newbieIds=[], startingVotes=None, metagameRound=-1, desiredNextGame=None): if minigameZone is None: minigameZone = air.allocateZone() acquireMinigameZone(minigameZone) mgId = None mgDiff = None mgSzId = None for avId in playerArray: request = RequestMinigame.get(avId) if request is not None: mgId, mgKeep, mgDiff, mgSzId = request if not mgKeep: del RequestMinigame[avId] break if mgId is not None: pass elif simbase.forcedMinigameId: mgId = simbase.forcedMinigameId else: randomList = list(copy.copy(ToontownGlobals.MinigamePlayerMatrix[len(playerArray)])) if len(playerArray) > 1: randomList = list(copy.copy(ToontownGlobals.MinigameIDs)) for gameId in [ToontownGlobals.TravelGameId] + getDisabledMinigames(): if gameId in randomList: randomList.remove(gameId) if previousGameId != ToontownGlobals.NoPreviousGameId: if randomList.count(previousGameId) != 0 and len(randomList) > 1: randomList.remove(previousGameId) mgId = random.choice(randomList) if metagameRound > -1: if (metagameRound%2) == 0: mgId = ToontownGlobals.TravelGameId elif desiredNextGame: mgId = desiredNextGame mgCtors = { ToontownGlobals.RaceGameId: DistributedRaceGameAI.DistributedRaceGameAI, ToontownGlobals.CannonGameId: DistributedCannonGameAI.DistributedCannonGameAI, ToontownGlobals.TagGameId: DistributedTagGameAI.DistributedTagGameAI, ToontownGlobals.PatternGameId: DistributedPatternGameAI.DistributedPatternGameAI, ToontownGlobals.RingGameId: DistributedRingGameAI.DistributedRingGameAI, ToontownGlobals.MazeGameId: DistributedMazeGameAI.DistributedMazeGameAI, ToontownGlobals.TugOfWarGameId: DistributedTugOfWarGameAI.DistributedTugOfWarGameAI, ToontownGlobals.CatchGameId: DistributedCatchGameAI.DistributedCatchGameAI, ToontownGlobals.DivingGameId: DistributedDivingGameAI.DistributedDivingGameAI, ToontownGlobals.TargetGameId: DistributedTargetGameAI.DistributedTargetGameAI, ToontownGlobals.MinigameTemplateId: DistributedMinigameTemplateAI.DistributedMinigameTemplateAI, ToontownGlobals.PairingGameId: DistributedPairingGameAI.DistributedPairingGameAI, ToontownGlobals.VineGameId: DistributedVineGameAI.DistributedVineGameAI, ToontownGlobals.IceGameId: DistributedIceGameAI.DistributedIceGameAI, ToontownGlobals.CogThiefGameId: DistributedCogThiefGameAI.DistributedCogThiefGameAI, ToontownGlobals.TwoDGameId: DistributedTwoDGameAI.DistributedTwoDGameAI, ToontownGlobals.TravelGameId: DistributedTravelGameAI.DistributedTravelGameAI, ToontownGlobals.PhotoGameId: DistributedPhotoGameAI.DistributedPhotoGameAI } from TempMinigameAI import TempMgCtors for key, value in TempMgCtors.items(): mgCtors[key] = value try: mg = mgCtors[mgId](air, mgId) except KeyError: raise Exception, 'unknown minigame ID: %s' % mgId mg.setExpectedAvatars(playerArray) mg.setNewbieIds(newbieIds) mg.setTrolleyZone(trolleyZone) mg.setDifficultyOverrides(mgDiff, mgSzId) if startingVotes == None: for avId in playerArray: mg.setStartingVote(avId, TravelGameGlobals.DefaultStartingVotes) else: for index in xrange(len(startingVotes)): avId = playerArray[index] votes = startingVotes[index] if votes < 0: print 'createMinigame negative votes, avId=%s votes=%s' % (avId, votes) votes = 0 mg.setStartingVote(avId, votes) mg.setMetagameRound(metagameRound) mg.generateWithRequired(minigameZone) toons = [] for doId in playerArray: toon = simbase.air.doId2do.get(doId) if toon is not None: toons.append(toon) for toon in toons: simbase.air.questManager.toonPlayedMinigame(toon, toons) retVal = {} retVal['minigameZone'] = minigameZone retVal['minigameId'] = mgId return retVal
def createMinigame(air, playerArray, trolleyZone, minigameZone=None, previousGameId=ToontownGlobals.NoPreviousGameId, newbieIds=[], startingVotes=None, metagameRound=-1, desiredNextGame=None): if minigameZone == None: minigameZone = air.allocateZone() acquireMinigameZone(minigameZone) mgId = None mgDiff = None mgSzId = None # Check for a specifically requested minigame from one of the players. for avId in playerArray: request = RequestMinigame.get(avId) if request != None: mgId, mgKeep, mgDiff, mgSzId = request if not mgKeep: del RequestMinigame[avId] break if mgId != None: # One of the players requested a particular minigame via # ~minigame; no need to pick another one. pass elif simbase.forcedMinigameId: # A particular minigame was forced using the Configrc option # minigame-id. mgId = simbase.forcedMinigameId else: # The normal path: choose a random minigame. randomList = list( copy.copy(ToontownGlobals.MinigamePlayerMatrix[len(playerArray)])) # when debugging minigames, it's useful to be able to play all # of the multi-player games with only two toons, even if some of # them normally require three or four toons if simbase.air.useAllMinigames and (len(playerArray) > 1): randomList = list(copy.copy(ToontownGlobals.MinigameIDs)) # don't include these games until they're ready for gameId in [ToontownGlobals.TravelGameId]: if gameId in randomList: randomList.remove(gameId) # we never want to get travel game as a regular minigame for gameId in [ToontownGlobals.TravelGameId]: if gameId in randomList: randomList.remove(gameId) # Never play the same game twice in a row if previousGameId != ToontownGlobals.NoPreviousGameId: # We might have just switched from multiplayer to # single-player minigames, which changes the pool of # minigames we have to draw from. Thus, it's possible our # previousGameId is not in randomList. if randomList.count(previousGameId) != 0: randomList.remove(previousGameId) # remove our unreleased minigames randomList = removeUnreleasedMinigames(randomList, True) mgId = random.choice(randomList) if (metagameRound > -1): if (metagameRound % 2 == 0): #we must start a trolley metagame mgId = ToontownGlobals.TravelGameId elif desiredNextGame: mgId = desiredNextGame # Create the minigame mgCtors = { ToontownGlobals.RaceGameId: DistributedRaceGameAI.DistributedRaceGameAI, ToontownGlobals.CannonGameId: DistributedCannonGameAI.DistributedCannonGameAI, ToontownGlobals.TagGameId: DistributedTagGameAI.DistributedTagGameAI, ToontownGlobals.PatternGameId: DistributedPatternGameAI.DistributedPatternGameAI, ToontownGlobals.RingGameId: DistributedRingGameAI.DistributedRingGameAI, ToontownGlobals.MazeGameId: DistributedMazeGameAI.DistributedMazeGameAI, ToontownGlobals.TugOfWarGameId: DistributedTugOfWarGameAI.DistributedTugOfWarGameAI, ToontownGlobals.CatchGameId: DistributedCatchGameAI.DistributedCatchGameAI, ToontownGlobals.DivingGameId: DistributedDivingGameAI.DistributedDivingGameAI, ToontownGlobals.TargetGameId: DistributedTargetGameAI.DistributedTargetGameAI, ToontownGlobals.MinigameTemplateId: DistributedMinigameTemplateAI.DistributedMinigameTemplateAI, ToontownGlobals.PairingGameId: DistributedPairingGameAI.DistributedPairingGameAI, ToontownGlobals.VineGameId: DistributedVineGameAI.DistributedVineGameAI, ToontownGlobals.IceGameId: DistributedIceGameAI.DistributedIceGameAI, ToontownGlobals.CogThiefGameId: DistributedCogThiefGameAI.DistributedCogThiefGameAI, ToontownGlobals.TwoDGameId: DistributedTwoDGameAI.DistributedTwoDGameAI, ToontownGlobals.TravelGameId: DistributedTravelGameAI.DistributedTravelGameAI, ToontownGlobals.PhotoGameId: DistributedPhotoGameAI.DistributedPhotoGameAI, } if ALLOW_TEMP_MINIGAMES: # Adds the temp minigames to the list of minigame creators... from TempMinigameAI import TempMgCtors for key, value in TempMgCtors.items(): mgCtors[key] = value """ print "\n\n\n\n\n\n\n\n\n\n" print mgCtors print air print mgId print mgCtors[mgId] print mgCtors[mgId](air,mgId) print "\n\n\n\n\n\n\n\n\n\n" """ try: #import pdb; pdb.set_trace() mg = mgCtors[mgId](air, mgId) except KeyError: raise Exception, "unknown minigame ID: %s" % mgId # Tell the minigame who we are expecting # do this before generating the minigame; # the av list is a required field mg.setExpectedAvatars(playerArray) # tell the minigame which players are playing their first minigame mg.setNewbieIds(newbieIds) # set trolley zone; another required field mg.setTrolleyZone(trolleyZone) # set the difficulty overrides mg.setDifficultyOverrides(mgDiff, mgSzId) # set the needed info for the trolley metagame if startingVotes == None: for avId in playerArray: mg.setStartingVote(avId, TravelGameGlobals.DefaultStartingVotes) #print('setting starting vote of %d to %d default' % (avId,TravelGameGlobals.DefaultStartingVotes)) else: for index in range(len(startingVotes)): avId = playerArray[index] votes = startingVotes[index] if votes < 0: print('createMinigame negative votes, avId=%s votes=%s' % (avId, votes)) votes = 0 mg.setStartingVote(avId, votes) #print('setting starting vote of %d to %d' % (avId,votes)) mg.setMetagameRound(metagameRound) # Generate it in that zone # this will kick off the minigame's ClassicFSM mg.generateWithRequired(minigameZone) # Notify the quest manager in case any toon had a minigame quest # TODO: should this be done AFTER the minigame, so that people can't get # out of newbie quests by hopping on the trolley and alt+F4-ing? Don't # if people are doing that. Maybe better to give credit to people that # crash during the game. toons = [] for id in playerArray: toon = simbase.air.doId2do.get(id) if (toon != None): toons.append(toon) for toon in toons: simbase.air.questManager.toonPlayedMinigame(toon, toons) retVal = {} retVal["minigameZone"] = minigameZone retVal["minigameId"] = mgId return retVal