def run(): try: global old global maxPlayers global players_num roster = bsInternal._getGameRoster() players_num = len(roster) if len(roster) != 0 else 1 bsInternal._setPublicPartyMaxSize( min(max(9, len(roster) + 1), maxPlayers)) global banned banned = some.banned if roster != old: for i in roster: a = bs.uni(i['displayString']) # print a if a in banned: with bs.Context('UI'): bs.screenMessage( "You Have Been Banned. If The Ban Is Temporary, Try Joining After Some Time.", transient=True, clients=[int(i['clientID'])]) bsInternal._disconnectClient(int(i['clientID'])) if eval(i['specString'])["a"] in [ '', 'Server' ] and int(i['clientID']) != -1: with bs.Context('UI'): bs.screenMessage("Please Sign In and Join", transient=True, clients=[int(i['clientID'])]) bsInternal._disconnectClient(int(i['clientID'])) old = roster except Exception as e: pass bs.realTimer(2000, run)
def checkSpam(clientID): #name = getID(clientID) #find id from clientID for i in bsInternal._getGameRoster(): if i['clientID'] == clientID: ID = i['displayString'] name = ID try: name = i['players'][0]['nameFull'] except: pass global counter if ID in counter: counter[ID] += 1 if counter[ID] == 3: #bsInternal._chatMessage("Don't spam here!") warnCount = warn(ID) with bs.Context(bsInternal._getForegroundHostActivity()): bs.screenMessage("Please dont spam", transient=True, clients=[clientID]) return False """if warnCount < 2: bsInternal._chatMessage("{}, don't spam here!".format(name)) with bs.Context(bsInternal._getForegroundHostActivity()):bs.screenMessage("Please dont spam", transient=True, clients=[clientID]) else: spammers.pop(ID) bsInternal._chatMessage("Warn limit exceeded. Kicking {} for spamming.".format(name)) #bsInternal._chatMessage("ChatFilter Made By Ankit") bsInternal._disconnectClient(clientID)""" else: counter[ID] = 1
def _startPreloads(self): # FIXME - the func that calls us back doesn't save/restore state # or check for a dead activity so we have to do that ourself.. if self.isFinalized(): return self._bot = bs.PenguinBot() with bs.Context(self): _preload1()
def _startPreloads(self): # FIXME - the func that calls us back doesn't save/restore state # or check for a dead activity so we have to do that ourself.. if self.isFinalized(): return with bs.Context(self): _preload1() bs.gameTimer(500,lambda: bs.playMusic('Menu'))
def skin(media={}, player=None): a = bsInternal._getForegroundHostActivity() if a is not None: with bs.Context(a): if player is not None: if isinstance(player, int) and hasattr(a, "players") and len(a.players) > player: player=a.players[player] a=None if isinstance(player, bs.Player) and player.exists() and player.isAlive(): a=player.actor.node if isinstance(player, bs.Node) and player.exists(): a=player if a is not None: a.headModel=media.get("headModel", a.headModel) a.pelvisModel=media.get("pelvisModel", a.pelvisModel) a.upperArmModel=media.get("upperArmModel", a.upperArmModel) a.foreArmModel=media.get("foreArmModel", a.foreArmModel) a.handModel=media.get("handModel", a.handModel) a.upperLegModel=media.get("upperLegModel", a.upperLegModel) a.lowerLegModel=media.get("lowerLegModel", a.lowerLegModel) a.torsoModel=media.get("torsoModel", a.torsoModel) a.toesModel=media.get("toesModel", a.toesModel) a.colorTexture=media.get("colorTexture", a.colorTexture) a.colorMaskTexture=media.get("colorMaskTexture", a.colorMaskTexture) a.jumpSounds=media.get('jumpSounds', a.jumpSounds) a.attackSounds=media.get('attackSounds', a.attackSounds) a.impactSounds=media.get('impactSounds', a.impactSounds) a.deathSounds=media.get('deathSounds', a.deathSounds) a.pickupSounds=media.get('pickupSounds', a.pickupSounds) a.fallSounds=media.get('fallSounds', a.fallSounds) a.style=media.get("style", a.style) a.name=media.get("name", a.name) a.color=media.get("color", a.color) a.highlight=media.get("highlight", a.highlight) return True #if we do it, send True return False #send False if something went wrong
def _checkInstallationForVH2(autoQuit=True): filePath = os.path.join(os.getcwd(), bs.getEnvironment().get("systemScriptsDirectory"), "bsUI.py") if os.path.isfile(filePath): fileText = open(filePath).read() originalChatHandleText = u"def _handleLocalChatMessage(msg):\n " replaceChatHandleText = u"def _handleLocalChatMessage(msg):\n try:import chatCmd;chatCmd.cmd(msg)\n except:bs.printException()\n " findCount = fileText.count(replaceChatHandleText) if findCount == 0: fileText = fileText.replace(originalChatHandleText, replaceChatHandleText) with open(filePath, "wb") as writer: writer.write(fileText.encode("utf-8")) fileText = open(filePath).read() if fileText.count(replaceChatHandleText) == 1: print("VirtualHost chat handler installed successfully!") with bs.Context("UI"): bs.realTimer(11000, bs.Call(bs.quit)) else: print("ChatManager installation failed.") elif findCount > 1: print("ChatManager was installed in a bad condition.(%d times)" % findCount) else: print("ChatManager can't be installed.Cannot find bsUI.py.")
def _gotNews(self, news): # run this stuff in the context of our activity since we need # to make nodes and stuff.. should fix the serverGet call so it activity = self._activity() if activity is None or activity.isFinalized(): return with bs.Context(activity): self._phrases = [] # show upcoming achievements in non-vr versions # (currently too hard to read in vr) self._usedPhrases = ( ['__ACH__'] if not bs.getEnvironment()['vrMode'] else []) + [s for s in news.split('<br>\n') if s != ''] self._phraseChangeTimer = bs.Timer( self._messageDuration+self._messageSpacing, bs.WeakCall(self._changePhrase), repeat=True) sc = 1.2 if (bs.getEnvironment()['interfaceType'] == 'small' or bs.getEnvironment()['vrMode']) else 0.8 self._text = bs.NodeActor(bs.newNode('text', attrs={ 'vAttach':'top', 'hAttach':'center', 'hAlign':'center', 'vrDepth':-20, 'shadow':1.0 if bs.getEnvironment()['vrMode'] else 0.4, 'flatness':0.8, 'vAlign':'top', 'color':((1, 1, 1, 1) if bs.getEnvironment()['vrMode'] else (0.7, 0.65, 0.75, 1.0)), 'scale':sc, 'maxWidth':900.0/sc, 'position':(0,-10)})) self._changePhrase()
def setActivity(self,activity): self._activity = None if activity is None else weakref.ref(activity) # load our media into this activity's context if activity is not None: if activity.isFinalized(): bs.printError('unexpected finalized activity') with bs.Context(activity): self._loadMedia()
def chatCmd_loop(): global cmds if cmds: for v in cmds: chatCmd.cmd(v) cmds = [] with bs.Context('UI'): bs.realTimer(100, chatCmd_loop)
def _setReady(self,ready): import bsInternal profileName = self.profileNames[self.profileIndex] # handle '_edit' as a special case if profileName == '_edit' and ready: import bsUI with bs.Context('UI'): bsUI.PlayerProfilesWindow(inMainMenu=False) # give their input-device UI ownership too # (prevent someone else from snatching it in crowded games) bsInternal._setUIInputDevice(self._player.getInputDevice()) return if not ready: self._player.assignInputCall('leftPress',bs.Call(self.handleMessage,bsLobby.ChangeMessage('team',-1))) self._player.assignInputCall('rightPress',bs.Call(self.handleMessage,bsLobby.ChangeMessage('team',1))) self._player.assignInputCall('bombPress',bs.Call(self.handleMessage,bsLobby.ChangeMessage('character',1))) self._player.assignInputCall('upPress',bs.Call(self.handleMessage,bsLobby.ChangeMessage('profileIndex',-1))) self._player.assignInputCall('downPress',bs.Call(self.handleMessage,bsLobby.ChangeMessage('profileIndex',1))) self._player.assignInputCall(('jumpPress','pickUpPress','punchPress'), bs.Call(self.handleMessage,bsLobby.ChangeMessage('ready',1))) self.ready = False self._updateText() self._player.setName('untitled',real=False) else: self._player.assignInputCall(('leftPress','rightPress', 'upPress','downPress', 'jumpPress','bombPress','pickUpPress'),self._doNothing) self._player.assignInputCall(('jumpPress','bombPress','pickUpPress','punchPress'), bs.Call(self.handleMessage,bsLobby.ChangeMessage('ready',0))) # store the last profile picked by this input for reuse inputDevice = self._player.getInputDevice() name = inputDevice.getName() uniqueID = inputDevice.getUniqueIdentifier() try: deviceProfiles = bs.getConfig()['Default Player Profiles'] except Exception: deviceProfiles = bs.getConfig()['Default Player Profiles'] = {} # make an exception if we have no custom profiles and are set to random; # in that case we'll want to start picking up custom profiles if/when one is made # so keep our setting cleared haveCustomProfiles = True if [p for p in self.profiles if p not in ('_random','_edit','__account__')] else False if profileName == '_random' and not haveCustomProfiles: try: del(deviceProfiles[name+' '+uniqueID]) except Exception: pass else: deviceProfiles[name+' '+uniqueID] = profileName bs.writeConfig() # set this player's short and full name self._player.setName(self._getName(),self._getName(full=True),real=True) self.ready = True self._updateText() # inform the session that this player is ready bs.getSession().handleMessage(bsLobby.PlayerReadyMessage(self))
def onPlayerRequest(self,player): # reject player requests, but if we're in a splash-screen, take the opportunity to tell it to leave # FIXME - should add a blanket way to capture all input for cases like this activity = self.getActivity() if isinstance(activity, SplashScreenActivity): with bs.Context(activity): activity.onSomethingPressed() return False
def onPunchRelease(self): if not self._fly_mode: PLAYER_SPAZ.onPunchRelease(self) else: player = self.getPlayer() if player is not None and player.exists() and not player.isAlive(): activity = self.getActivity() if activity is not None and hasattr(activity, 'spawnPlayer'): player.gameData['respawnTimer'] = player.gameData['respawnIcon'] = None with bs.Context(activity): activity.spawnPlayer(player=player)
def __init__(self, url, callback=None): threading.Thread.__init__(self) self._url = url.encode( "ascii") # embedded python2.7 has weird encoding issues self._callback = callback or (lambda d: None) self._context = bs.Context('current') # save and restore the context we were created from activity = bs.getActivity(exceptionOnNone=False) self._activity = weakref.ref( activity) if activity is not None else None
def kick(nick, reason='-', warn=False, mute=False, time=2): import ChatManager if '/' in nick: nick = nick.split('/')[0] #print nick.encode('unicode_escape') i = handle.getPlayerFromNick(nick) if i is not None: n = i.get_account_id() clid = i.getInputDevice().getClientID() name = i.getName(True) if mute: if clid not in ChatManager.mutedIDs: ChatManager.mutedIDs.append(clid) bs.screenMessage( u"{} Has Been Muted | Reason: {} | Muted For: {} Minutes". format(name, reason, time), transient=True) def unmute(clid): if clid in ChatManager.mutedIDs: ChatManager.mutedIDs.remove(clid) with bs.Context('UI'): bs.realTimer(time * 60 * 1000, bs.Call(unmute, clid)) if warn == True: if n in some.warn: some.warn[n] += 1 if some.warn[n] >= 3: some.banned.append(n) bs.screenMessage( u'Warn Limit Reached, Temporarily Banning Player', transient=True) k(reason, clid, name) return else: some.warn.update({n: 1}) bs.screenMessage( u"{} Has Been Warned | Reason: {} | Warn Count: {}/3".format( name, reason, some.warn[n]), transient=True) return else: k(reason, clid, name) return roster = bsInternal._getGameRoster() for i in roster: try: if bs.uni(i['displayString']).lower().find( bs.uni(nick).lower()) != -1 or str(i['clientID']) == nick: if not bs.uni(i['displayString']) == bs.uni(u'AwesomeLogic'): k(reason, int(i['clientID']), bs.uni(i['displayString'])) except Exception as e: print e
def _displayBanner(ach): try: import bsAchievement # FIXME - need to get these using the UI context somehow instead of trying to inject # these into whatever activity happens to be active.. (since that won't work while in client mode) a = bsInternal._getForegroundHostActivity() if a is not None: with bs.Context(a): bsAchievement.getAchievement(ach).announceCompletion() except Exception: bs.printException('error showing server ach')
def fadeToRed(): activity = bsInternal._getForegroundHostActivity() with bs.Context(activity): cExisting = bs.getSharedObject('globals').tint c = bs.newNode("combine", attrs={ 'input0': cExisting[0], 'input1': cExisting[1], 'input2': cExisting[2], 'size': 3 }) bs.animate(c, 'input1', {0: cExisting[1], 2000: 0}) bs.animate(c, 'input2', {0: cExisting[2], 2000: 0}) c.connectAttr('output', bs.getSharedObject('globals'), 'tint')
def run(self): try: global old roster = bsInternal._getGameRoster() if roster != old: #print roster for i in roster: a = i['displayString'] if a in banned: with bs.Context('UI'): bsInternal._chatMessage(a + ", You are banned due to voilation of rules.") bsInternal._disconnectClient(int(i['clientID'])) old = roster except Exception as e: pass bs.realTimer(2000,self.run)
def _startPreloads(self): # FIXME - the func that calls us back doesn't save/restore state # or check for a dead activity so we have to do that ourself.. if self.isFinalized(): return with bs.Context(self): _preload1() numb = random.randint(1, 101) if numb <= 30: bs.gameTimer(500,lambda: bs.playMusic('Menu')) elif numb <= 50: bs.gameTimer(500, lambda: bs.playMusic("rick_and_morty")) elif numb <= 70: bs.gameTimer(500, lambda: bs.playMusic("the_last_of_us")) elif numb <= 90: bs.gameTimer(500, lambda: bs.playMusic("naz_march")) else: bs.gameTimer(500,lambda: bs.playMusic('seny_seny'))
def opt(self, nick, msg): if self.checkDevice(nick): m = msg.split(' ')[0] # command a = msg.split(' ', 1)[1:] # arguments activity = bsInternal._getForegroundHostActivity() with bs.Context(activity): if m == '/kick': #just remove from the game if a == []: bsInternal._chatMessage("MUST USE KICK ID") else: try: kickedPlayerID = int(a[0]) except Exception: bsInternal._chatMessage("PLAYER NOT FOUND") else: if not kickedPlayerID == -1: bsInternal._disconnectClient(kickedPlayerID) bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) else: bsInternal._chatMessage("CANT KICK HOST") elif m == '/list': #list of current players id bsInternal._chatMessage( "==========PLAYER KICK IDS==========") for i in bsInternal._getGameRoster(): try: bsInternal._chatMessage( i['players'][0]['nameFull'] + " kick ID " + str(i['clientID'])) except Exception: pass bsInternal._chatMessage( "==========PLAYER IDS=============") for s in bsInternal._getForegroundHostSession().players: bsInternal._chatMessage( s.getName() + " ID = " + str(bsInternal._getForegroundHostSession().players. index(s))) elif m == '/ban': # add id to banlist=autokick list if a == []: bsInternal._chatMessage( "MUST USE PLAYER ID OR NICK" ) #also FIX this every time bsInternal ChatMessage thing!! for stop loops "update-FIXED" else: #firstly try nick if nick len is more then 2 else try as player id FIX ME if len(a[0]) > 2: for i in bs.getActivity().players: try: if (i.getName()).encode('utf-8') == (a[0]): bannedClient = i.getInputDevice( ).getClientID() bannedName = i.getName().encode( 'utf-8') bannedPlayerID = i.get_account_id() foolist = [] foolist = mbal.autoKickList if bannedPlayerID not in foolist: foolist.append(bannedPlayerID) bsInternal._chatMessage( str(bannedName) + " Banned") i.removeFromGame() else: bsInternal._chatMessage( str(bannedName) + " Already Banned") with open( bs.getEnvironment() ['systemScriptsDirectory'] + "/MythBAdminList.py") as file: s = [row for row in file] s[7] = 'autoKickList = ' + str( foolist) + '\n' f = open( bs.getEnvironment() ['systemScriptsDirectory'] + "/MythBAdminList.py", 'w') for i in s: f.write(i) f.close() reload(mbal) except Exception: pass bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) else: try: bannedClient = bsInternal._getForegroundHostSession( ).players[int(a[0])] except Exception: bsInternal._chatMessage("PLAYER NOT FOUND") else: foolist = [] foolist = mbal.autoKickList bannedPlayerID = bannedClient.get_account_id() if bannedPlayerID not in foolist: foolist.append(bannedPlayerID) bsInternal._chatMessage( str(bannedClient) + " Banned") bannedClient.removeFromGame() else: bsInternal._chatMessage( str(bannedClient) + " Already Banned") with open(bs.getEnvironment() ['systemScriptsDirectory'] + "/MythBAdminList.py") as file: s = [row for row in file] s[7] = 'autoKickList = ' + str( foolist) + '\n' f = open( bs.getEnvironment() ['systemScriptsDirectory'] + "/MythBAdminList.py", 'w') for i in s: f.write(i) f.close() reload(mbal) elif m == '/unban': # remove id from banlist=autokick list if a == []: bsInternal._chatMessage("MUST USE PLAYER ID OR NICK") else: if len(a[0]) > 2: for i in bs.getActivity().players: try: if (i.getName()).encode('utf-8') == (a[0]): bannedClient = i.getInputDevice( ).getClientID() bannedName = i.getName().encode( 'utf-8') bannedPlayerID = i.get_account_id() foolist = [] foolist = mbal.autoKickList if bannedPlayerID in foolist: foolist.remove(bannedPlayerID) bsInternal._chatMessage( str(bannedName) + " be free now!") else: bsInternal._chatMessage( str(bannedName) + " Already Not Banned") with open( bs.getEnvironment() ['systemScriptsDirectory'] + "/MythBAdminList.py") as file: s = [row for row in file] s[7] = 'autoKickList = ' + str( foolist) + '\n' f = open( bs.getEnvironment() ['systemScriptsDirectory'] + "/MythBAdminList.py", 'w') for i in s: f.write(i) f.close() reload(mbal) except Exception: pass bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) else: try: bannedClient = bsInternal._getForegroundHostSession( ).players[int(a[0])] except Exception: bsInternal._chatMessage("PLAYER NOT FOUND") else: foolist = [] foolist = mbal.autoKickList bannedPlayerID = bannedClient.get_account_id() if bannedPlayerID in foolist: foolist.remove(bannedPlayerID) bsInternal._chatMessage( str(bannedClient) + " be free now!") else: bsInternal._chatMessage( str(bannedClient) + " Already Not Banned") with open(bs.getEnvironment() ['systemScriptsDirectory'] + "/MythBAdminList.py") as file: s = [row for row in file] s[7] = 'autoKickList = ' + str( foolist) + '\n' f = open( bs.getEnvironment() ['systemScriptsDirectory'] + "/MythBAdminList.py", 'w') for i in s: f.write(i) f.close() reload(mbal) elif m == '/amnesty': # reset blacklist foolist = [] bsInternal._chatMessage( "==========FREEDOM TO ALL==========") bsInternal._chatMessage( "=========BLACKLİST WIPED=========") with open(bs.getEnvironment()['systemScriptsDirectory'] + "/MythBAdminList.py") as file: s = [row for row in file] s[7] = 'autoKickList = ' + str(foolist) + '\n' f = open( bs.getEnvironment()['systemScriptsDirectory'] + "/MythBAdminList.py", 'w') for i in s: f.write(i) f.close() reload(mbal) elif m == '/camera': #change camera mode bsInternal._chatMessage(bs.getSpecialChar('logoFlat')) try: if bs.getSharedObject( 'globals').cameraMode == 'follow': bs.getSharedObject('globals').cameraMode = 'rotate' else: bs.getSharedObject('globals').cameraMode = 'follow' except Exception: bsInternal._chatMessage('AN ERROR OCCURED') elif m == '/maxplayers': #set maxplayers limit if a == []: bsInternal._chatMessage('MUST USE NUMBERS') else: try: bsInternal._getForegroundHostSession( )._maxPlayers = int(a[0]) bsInternal._setPublicPartyMaxSize(int(a[0])) bsInternal._chatMessage('MaxPlayers = ' + str(int(a[0]))) except Exception: bsInternal._chatMessage('AN ERROR OCCURED') elif m == '/help': #show help bsInternal._chatMessage( "=====================COMMANDS=====================") bsInternal._chatMessage( "list-kick-remove-ban-unban-amnesty-kill-curse-end-heal" ) bsInternal._chatMessage( "freeze-thaw-headless-shield-punch-maxplayers-headlessall" ) bsInternal._chatMessage( "killall-freezeall-shieldall-punchall-camera-slow") elif m == '/remove': #remove from game if a == []: bsInternal._chatMessage('MUST USE PLAYER ID OR NICK') else: if len(a[0]) > 2: for i in bs.getActivity().players: try: if (i.getName()).encode('utf-8') == (a[0]): i.removeFromGame() except Exception: pass bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) else: try: bs.getActivity().players[int( a[0])].removeFromGame() bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) except Exception: bsInternal._chatMessage('PLAYER NOT FOUND') elif m == '/curse': #curse if a == []: bsInternal._chatMessage('MUST USE PLAYER ID OR NICK') else: if len(a[0]) > 2: for i in bs.getActivity().players: try: if (i.getName()).encode('utf-8') == (a[0]): if i.actor.exists(): i.actor.curse() except Exception: pass bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) else: try: bs.getActivity().players[int( a[0])].actor.curse() bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) except Exception: bsInternal._chatMessage('PLAYER NOT FOUND') elif m == '/curseall': #curse all for i in bs.getActivity().players: try: if i.actor.exists(): i.actor.curse() except Exception: pass bsInternal._chatMessage(bs.getSpecialChar('logoFlat')) elif m == '/kill': #kill if a == []: bsInternal._chatMessage('MUST USE PLAYER ID OR NICK') else: if len(a[0]) > 2: for i in bs.getActivity().players: try: if (i.getName()).encode('utf-8') == (a[0]): if i.actor.exists(): i.actor.node.handleMessage( bs.DieMessage()) except Exception: pass bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) else: try: bs.getActivity().players[int( a[0])].actor.node.handleMessage( bs.DieMessage()) bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) except Exception: bsInternal._chatMessage('PLAYER NOT FOUND') elif m == '/killall': #kill all for i in bs.getActivity().players: try: if i.actor.exists(): i.actor.node.handleMessage(bs.DieMessage()) except Exception: pass bsInternal._chatMessage(bs.getSpecialChar('logoFlat')) elif m == '/freeze': #freeze if a == []: bsInternal._chatMessage('MUST USE PLAYER ID OR NICK') else: if len(a[0]) > 2: for i in bs.getActivity().players: try: if (i.getName()).encode('utf-8') == (a[0]): if i.actor.exists(): i.actor.node.handleMessage( bs.FreezeMessage()) except Exception: pass bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) else: try: bs.getActivity().players[int( a[0])].actor.node.handleMessage( bs.FreezeMessage()) bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) except Exception: bsInternal._chatMessage('PLAYER NOT FOUND') elif m == '/freezeall': #freeze all for i in bs.getActivity().players: try: if i.actor.exists(): i.actor.node.handleMessage(bs.FreezeMessage()) except Exception: pass bsInternal._chatMessage(bs.getSpecialChar('logoFlat')) elif m == '/thaw': #thaw if a == []: bsInternal._chatMessage('MUST USE PLAYER ID OR NICK') else: if len(a[0]) > 2: for i in bs.getActivity().players: try: if (i.getName()).encode('utf-8') == (a[0]): if i.actor.exists(): i.actor.node.handleMessage( bs.ThawMessage()) except Exception: pass bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) else: try: bs.getActivity().players[int( a[0])].actor.node.handleMessage( bs.ThawMessage()) bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) except Exception: bsInternal._chatMessage('PLAYER NOT FOUND') elif m == '/thawall': #thaw all for i in bs.getActivity().players: try: if i.actor.exists(): i.actor.node.handleMessage(bs.ThawMessage()) except Exception: pass bsInternal._chatMessage(bs.getSpecialChar('logoFlat')) elif m == '/headless': #headless if a == []: bsInternal._chatMessage('MUST USE PLAYER ID OR NICK') else: if len(a[0]) > 2: for i in bs.getActivity().players: try: if (i.getName()).encode('utf-8') == (a[0]): if i.actor.exists(): i.actor.node.headModel = None i.actor.node.style = "cyborg" except Exception: pass bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) else: try: bs.getActivity().players[int( a[0])].actor.node.headModel = None bs.getActivity().players[int( a[0])].actor.node.style = "cyborg" bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) except Exception: bsInternal._chatMessage('PLAYER NOT FOUND') elif m == '/headlessall': #headless all for i in bs.getActivity().players: try: if i.actor.exists(): i.actor.node.headModel = None i.actor.node.style = "cyborg" except Exception: pass bsInternal._chatMessage(bs.getSpecialChar('logoFlat')) elif m == '/heal': #heal if a == []: bsInternal._chatMessage('MUST USE PLAYER ID OR NICK') else: if len(a[0]) > 2: for i in bs.getActivity().players: try: if (i.getName()).encode('utf-8') == (a[0]): if i.actor.exists(): i.actor.node.handleMessage( bs.PowerupMessage( powerupType='health')) except Exception: pass bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) else: try: bs.getActivity().players[int( a[0])].actor.node.handleMessage( bs.PowerupMessage( powerupType='health')) bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) except Exception: bsInternal._chatMessage('PLAYER NOT FOUND') elif m == '/healall': #heal all for i in bs.getActivity().players: try: if i.actor.exists(): i.actor.node.handleMessage( bs.PowerupMessage(powerupType='health')) except Exception: pass bsInternal._chatMessage(bs.getSpecialChar('logoFlat')) elif m == '/shield': #shield if a == []: bsInternal._chatMessage('MUST USE PLAYER ID OR NICK') else: if len(a[0]) > 2: for i in bs.getActivity().players: try: if (i.getName()).encode('utf-8') == (a[0]): if i.actor.exists(): i.actor.node.handleMessage( bs.PowerupMessage( powerupType='shield')) except Exception: pass bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) else: try: bs.getActivity().players[int( a[0])].actor.node.handleMessage( bs.PowerupMessage( powerupType='shield')) bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) except Exception: bsInternal._chatMessage('PLAYER NOT FOUND') elif m == '/shieldall': #shield all for i in bs.getActivity().players: try: if i.actor.exists(): i.actor.node.handleMessage( bs.PowerupMessage(powerupType='shield')) except Exception: pass bsInternal._chatMessage(bs.getSpecialChar('logoFlat')) elif m == '/punch': #punch if a == []: bsInternal._chatMessage('MUST USE PLAYER ID OR NICK') else: if len(a[0]) > 2: for i in bs.getActivity().players: try: if (i.getName()).encode('utf-8') == (a[0]): if i.actor.exists(): i.actor.node.handleMessage( bs.PowerupMessage( powerupType='punch')) except Exception: pass bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) else: try: bs.getActivity().players[int( a[0])].actor.node.handleMessage( bs.PowerupMessage(powerupType='punch')) bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) except Exception: bsInternal._chatMessage('PLAYER NOT FOUND') elif m == '/punchall': #punch all for i in bs.getActivity().players: try: if i.actor.exists(): i.actor.node.handleMessage( bs.PowerupMessage(powerupType='punch')) except Exception: pass bsInternal._chatMessage(bs.getSpecialChar('logoFlat')) elif m == '/knock': #knock him if a == []: bsInternal._chatMessage('MUST USE PLAYER ID OR NICK') else: if len(a[0]) > 2: for i in bs.getActivity().players: try: if (i.getName()).encode('utf-8') == (a[0]): if i.actor.exists(): i.actor.node.handleMessage( "knockout", 5000) except Exception: pass bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) else: try: bs.getActivity().players[int( a[0])].actor.node.handleMessage( "knockout", 5000) bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) except Exception: bsInternal._chatMessage('PLAYER NOT FOUND') elif m == '/knockall': #knock all for i in bs.getActivity().players: try: if i.actor.exists(): i.actor.node.handleMessage("knockout", 5000) except Exception: pass bsInternal._chatMessage(bs.getSpecialChar('logoFlat')) elif m == '/celebrate': #celebrate him if a == []: bsInternal._chatMessage('MUST USE PLAYER ID OR NICK') else: if len(a[0]) > 2: for i in bs.getActivity().players: try: if (i.getName()).encode('utf-8') == (a[0]): if i.actor.exists(): i.actor.node.handleMessage( 'celebrate', 30000) except Exception: pass bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) else: try: bs.getActivity().players[int( a[0])].actor.node.handleMessage( 'celebrate', 30000) bsInternal._chatMessage( bs.getSpecialChar('logoFlat')) except Exception: bsInternal._chatMessage('PLAYER NOT FOUND') elif m == '/celebrateall': #celebrate for i in bs.getActivity().players: try: if i.actor.exists(): i.actor.node.handleMessage('celebrate', 30000) except Exception: pass bsInternal._chatMessage(bs.getSpecialChar('logoFlat')) elif m == '/slow': # slow-mo bsInternal._chatMessage(bs.getSpecialChar('logoFlat')) try: if bs.getSharedObject('globals').slowMotion == True: bs.getSharedObject('globals').slowMotion = False else: bs.getSharedObject('globals').slowMotion = True except Exception: bsInternal._chatMessage('AN ERROR OCCURED') elif m == '/end': # just end game try: bsInternal._getForegroundHostActivity().endGame() bsInternal._chatMessage('THE END') except Exception: bsInternal._chatMessage('AN ERROR OCCURED')
def onTransitionIn(self): bs.Activity.onTransitionIn(self) global gDidInitialTransition random.seed(123) try: import install except ImportError: pass else: # check needed methods if hasattr(bs, "get_setting") and hasattr(install, "update_modpack"): if bs.get_setting("auto-update", False): install.update_modpack(True) self._logoNode = None self._customLogoTexName = None self._wordActors = [] env = bs.getEnvironment() vrMode = bs.getEnvironment()['vrMode'] if not bs.getEnvironment().get('toolbarTest', True): self.myName = bs.NodeActor( bs.newNode( 'text', attrs={ 'vAttach': 'bottom', 'hAlign': 'center', 'color': (1, 1, 1, 1) if vrMode else (1, 1, 1, 1), 'flatness': 1.0, 'shadow': 1.0 if vrMode else 0.5, 'scale': (0.65 if (env['interfaceType'] == 'small' or vrMode) else 0.7), # FIXME need a node attr for this 'position': (0, 25), 'vrDepth': -10, 'text': u'\xa9 2019 Eric Froemling' })) fullScreen = bsInternal._getSetting("TV Border") if env['interfaceType'] != 'small' or env['vrMode']: if fullScreen: position = (0, -10) else: position = (-425, 10) else: if fullScreen: position = (0, -10) else: position = (-425, 35) self.moderName = bs.NodeActor( bs.newNode( 'text', attrs={ 'vAttach': 'bottom', 'hAlign': 'center', 'color': (0.8, 0.8, 0.8, 0.8) if vrMode else (0.8, 0.8, 0.8, 0.8), 'flatness': 1.0, 'shadow': 1.0 if vrMode else 0.5, 'scale': (0.55 if (env['interfaceType'] == 'small' or vrMode) else 0.7), # FIXME need a node attr for this 'position': position, 'vrDepth': -10, 'text': u'\xa9 ModPack is created by Daniil Rakhov' })) self._hostIsNavigatingText = bs.NodeActor( bs.newNode('text', attrs={ 'text': bs.Lstr(resource='hostIsNavigatingMenusText', subs=[ ('${HOST}', bsInternal._getAccountDisplayString()) ]), 'clientOnly': True, 'position': (0, -200), 'flatness': 1.0, 'hAlign': 'center' })) if not gDidInitialTransition: if hasattr(self, 'myName'): bs.animate(self.myName.node, 'opacity', {2300: 0, 3000: 1.0}) if hasattr(self, 'moderName'): bs.animate(self.moderName.node, 'opacity', { 2300: 0, 3300: 1.0 }) # FIXME - shouldn't be doing things conditionally based on whether # the host is vr mode or not (clients may not be or vice versa) # - any differences need to happen at the engine level # so everyone sees things in their own optimal way vrMode = env['vrMode'] interfaceType = env['interfaceType'] # in cases where we're doing lots of dev work lets # always show the build number forceShowBuildNumber = True if not bs.getEnvironment().get('toolbarTest', True): text = "BROODYs WORLD" try: from multiversion import get_version except ImportError: path = os.path.join(env["userScriptsDirectory"], "about_modpack.json") if os.path.exists(path): try: data = json.load(open(path)) except Exception: pass else: text += " v." + str( data.get("version", { "v": "???" }).get("v")) else: text += " v." + str(get_version()) if env['debugBuild'] or env['testBuild']: if env['debugBuild']: text += " [debug]" else: text += " [test]" if forceShowBuildNumber: text = "based on " + str(env['version']) + "\n" + text self.version = bs.NodeActor( bs.newNode('text', attrs={ 'vAttach': 'bottom', 'hAttach': 'right', 'hAlign': 'right', 'flatness': 1.0, 'vrDepth': -10, 'shadow': 0.5, 'color': (0.5, 0.6, 0.5, 0.7), 'scale': 0.7 if (interfaceType == 'small' or vrMode) else 0.85, 'position': (-260, 10) if vrMode else (-10, 30), 'text': text })) if not gDidInitialTransition: bs.animate(self.version.node, 'opacity', { 0: 0, 3000: 0, 4000: 1.0 }) # throw in beta info.. self.betaInfo = self.betaInfo2 = None if env['testBuild'] and not env['kioskMode']: self.betaInfo = bs.NodeActor( bs.newNode('text', attrs={ 'vAttach': 'center', 'hAlign': 'center', 'color': (1, 1, 1, 1), 'shadow': 0.5, 'flatness': 0.5, 'scale': 1, 'vrDepth': -60, 'position': (230, 125) if env['kioskMode'] else (230, 35), 'text': bs.Lstr(resource="testBuildText") })) if not gDidInitialTransition: bs.animate(self.betaInfo.node, 'opacity', {1300: 0, 1800: 1.0}) model = bs.getModel('thePadLevel') treesModel = bs.getModel('trees') bottomModel = bs.getModel('thePadLevelBottom') borModel = bs.getCollideModel('thePadLevelCollide') testColorTexture = bs.getTexture('thePadLevelColor') treesTexture = bs.getTexture('treesColor') bgTex = bs.getTexture('alwaysLandBGColor') bgModel = bs.getModel('alwaysLandBG') vrBottomFillModel = bs.getModel('thePadVRFillBottom') vrTopFillModel = bs.getModel('thePadVRFillTop') bsGlobals = bs.getSharedObject('globals') bsGlobals.cameraMode = 'rotate' bsGlobals.tint = (1.1, 1.1, 1.0) self.bottom = bs.NodeActor( bs.newNode('terrain', attrs={ 'model': bottomModel, 'lighting': False, 'reflection': 'soft', 'reflectionScale': [0.45], 'colorTexture': testColorTexture })) self.node = bs.newNode('terrain', delegate=self, attrs={ 'collideModel': borModel, 'model': model, 'colorTexture': testColorTexture, 'materials': [bs.getSharedObject('footingMaterial')] }) self.vrBottomFill = bs.NodeActor( bs.newNode('terrain', attrs={ 'model': vrBottomFillModel, 'lighting': False, 'vrOnly': True, 'colorTexture': testColorTexture })) self.vrTopFill = bs.NodeActor( bs.newNode('terrain', attrs={ 'model': vrTopFillModel, 'vrOnly': True, 'lighting': False, 'colorTexture': bgTex })) self.terrain = bs.NodeActor( bs.newNode('terrain', attrs={ 'model': model, 'colorTexture': testColorTexture, 'reflection': 'soft', 'reflectionScale': [0.3] })) self.trees = bs.NodeActor( bs.newNode('terrain', attrs={ 'model': treesModel, 'lighting': False, 'reflection': 'char', 'reflectionScale': [0.1], 'colorTexture': treesTexture })) self.bg = bs.NodeActor( bs.newNode('terrain', attrs={ 'model': bgModel, 'color': (0.92, 0.91, 0.9), 'lighting': False, 'background': True, 'colorTexture': bgTex })) textOffsetV = 0 self._ts = 0.86 self._language = None self._updateTimer = bs.Timer(2000, bs.Call(self._update, False), repeat=True) self._update(True) bs.gameTimer(55000, bs.Call(self.fireworks)) bsUtils.animateArray(bs.getSharedObject("globals"), "tint", 3, {0:(1.1,1.1,1.0), 7500:(1.25, 1.21, 1.075), 30000:(1.25, 1.21, 1.075), \ 57500:(1.1, 0.86, 0.74), 67500:(1.1, 0.86, 0.74), \ 90000:(0, 0.27, 0.51), 120000:(0, 0.27, 0.51), 142500:(1.3, 1.06, 1.02), \ 157500:(1.3, 1.06, 1.02), 180000:(1.3, 1.25, 1.2), 195500:(1.3, 1.25, 1.2), \ 220000:(1.1,1.1,1.0)}) bsInternal._addCleanFrameCallback(bs.WeakCall(self._startPreloads)) random.seed() class News(object): def __init__(self, activity): self._valid = True self._messageDuration = 10000 self._messageSpacing = 2000 self._text = None self._activity = weakref.ref(activity) self._fetchTimer = bs.Timer(1000, bs.WeakCall(self._tryFetchingNews), repeat=True) self._tryFetchingNews() def _tryFetchingNews(self): if bsInternal._getAccountState() == 'SIGNED_IN': self._fetchNews() self._fetchTimer = None def _fetchNews(self): try: launchCount = bs.getConfig()['launchCount'] except Exception: launchCount = None global gLastNewsFetchTime gLastNewsFetchTime = time.time() # UPDATE - we now just pull news from MRVs news = bsInternal._getAccountMiscReadVal('n', None) if news is not None: self._gotNews(news) def _changePhrase(self): global gLastNewsFetchTime if time.time() - gLastNewsFetchTime > 100.0: self._fetchNews() self._text = None else: if self._text is not None: if len(self._phrases) == 0: for p in self._usedPhrases: self._phrases.insert(0, p) val = self._phrases.pop() if val == '__ACH__': vr = bs.getEnvironment()['vrMode'] bsUtils.Text( bs.Lstr(resource='nextAchievementsText'), color=(1,1,1,1) if vr else (0.95,0.9,1,0.4), hostOnly=True, maxWidth=200, position=(-300, -35), hAlign='right', transition='fadeIn', scale=0.9 if vr else 0.7, flatness=1.0 if vr else 0.6, shadow=1.0 if vr else 0.5, hAttach="center", vAttach="top", transitionDelay=1000, transitionOutDelay=self._messageDuration)\ .autoRetain() import bsAchievement achs = [ a for a in bsAchievement.gAchievements if not a.isComplete() ] if len(achs) > 0: a = achs.pop( random.randrange(min(4, len(achs)))) a.createDisplay(-180, -35, 1000, outDelay=self._messageDuration, style='news') if len(achs) > 0: a = achs.pop( random.randrange(min(8, len(achs)))) a.createDisplay(180, -35, 1250, outDelay=self._messageDuration, style='news') else: s = self._messageSpacing keys = { s: 0, s + 1000: 1.0, s + self._messageDuration - 1000: 1.0, s + self._messageDuration: 0.0 } bs.animate(self._text.node, "opacity", dict([[k, v] for k, v in keys.items()])) self._text.node.text = val def _gotNews(self, news): # run this stuff in the context of our activity since we need # to make nodes and stuff.. should fix the serverGet call so it activity = self._activity() if activity is None or activity.isFinalized(): return with bs.Context(activity): self._phrases = [] # show upcoming achievements in non-vr versions # (currently too hard to read in vr) self._usedPhrases = ( ['__ACH__'] if not bs.getEnvironment()['vrMode'] else []) + [s for s in news.split('<br>\n') if s != ''] self._phraseChangeTimer = bs.Timer( self._messageDuration + self._messageSpacing, bs.WeakCall(self._changePhrase), repeat=True) sc = 1.2 if ( bs.getEnvironment()['interfaceType'] == 'small' or bs.getEnvironment()['vrMode']) else 0.8 self._text = bs.NodeActor( bs.newNode( 'text', attrs={ 'vAttach': 'top', 'hAttach': 'center', 'hAlign': 'center', 'vrDepth': -20, 'shadow': 1.0 if bs.getEnvironment()['vrMode'] else 0.4, 'flatness': 0.8, 'vAlign': 'top', 'color': ((1, 1, 1, 1) if bs.getEnvironment()['vrMode'] else (0.7, 0.65, 0.75, 1.0)), 'scale': sc, 'maxWidth': 900.0 / sc, 'position': (0, -10) })) self._changePhrase() if not env['kioskMode'] and not env.get('toolbarTest', True): self._news = News(self) # bring up the last place we were, or start at the main menu otherwise with bs.Context('UI'): try: mainWindow = bsUI.gMainWindow except Exception: mainWindow = None # when coming back from a kiosk-mode game, jump to # the kiosk start screen.. if bsUtils.gRunningKioskModeGame: if bs.getEnvironment()['kioskMode']: bsUI.uiGlobals['mainMenuWindow'] = \ bsUI.KioskWindow().getRootWidget() # ..or in normal cases go back to the main menu else: if mainWindow == 'Gather': bsUI.uiGlobals['mainMenuWindow'] = \ bsUI.GatherWindow(transition=None).getRootWidget() elif mainWindow == 'Watch': bsUI.uiGlobals['mainMenuWindow'] = \ bsUI.WatchWindow(transition=None).getRootWidget() elif mainWindow == 'Team Game Select': bsUI.uiGlobals['mainMenuWindow'] = \ bsUI.TeamsWindow(sessionType=bs.TeamsSession, transition=None).getRootWidget() elif mainWindow == 'Free-for-All Game Select': bsUI.uiGlobals['mainMenuWindow'] = \ bsUI.TeamsWindow(sessionType=bs.FreeForAllSession, transition=None).getRootWidget() elif mainWindow == 'Coop Select': bsUI.uiGlobals['mainMenuWindow'] = \ bsUI.CoopWindow(transition=None).getRootWidget() else: bsUI.uiGlobals['mainMenuWindow'] = \ bsUI.MainMenuWindow(transition=None).getRootWidget() # attempt to show any pending offers immediately. # If that doesn't work, try again in a few seconds # (we may not have heard back from the server) # ..if that doesn't work they'll just have to wait # until the next opportunity. if not bsUI._showOffer(): def tryAgain(): if not bsUI._showOffer(): # try one last time.. bs.realTimer(2000, bsUI._showOffer) bs.realTimer(2000, tryAgain) gDidInitialTransition = True
def send_message(msg): if len(bsInternal._getGameRoster()) < 1: if bsUI.gPartyWindow is not None and bsUI.gPartyWindow() is not None: with bs.Context("UI"): bsUI.gPartyWindow()._addMsg(msg=msg, color=(1, 1, 1)) else: bsInternal._chatMessage(msg)
def showCompletionBanner(self, sound=True): global gLastAchievementDisplayTime gLastAchievementDisplayTime = bs.getRealTime() # just piggy-back onto any current activity... # (should we use the session instead?..) activity = bs.getActivity(exceptionOnNone=False) # if this gets called while this achievement is occupying a slot already, ignore it.. # (probably should never happen in real life but whatevs..) if self._completionBannerSlot is not None: return if activity is None: print 'showCompletionBanner() called with no current activity!' return if sound: bs.playSound(bs.getSound('achievement'), hostOnly=True) else: bs.gameTimer( 500, bs.Call(bs.playSound, bs.getSound('ding'), hostOnly=True)) yOffs = 0 inTime = 300 outTime = 3500 baseVRDepth = 200 # find the first free slot i = 0 while True: if not i in gCompletionBannerSlots: #print 'ADDING SLOT',i,'FOR',self gCompletionBannerSlots.add(i) self._completionBannerSlot = i # remove us from that slot when we close.. # use a real-timer in the UI context so the removal runs even if our activity/session dies with bs.Context('UI'): bs.realTimer(inTime + outTime, self._removeBannerSlot) break i += 1 yOffs = 110 * self._completionBannerSlot objs = [] obj = bsUtils.Image(bs.getTexture('shadow'), position=(-30, 30 + yOffs), front=True, attach='bottomCenter', transition='inBottom', vrDepth=baseVRDepth - 100, transitionDelay=inTime, transitionOutDelay=outTime, color=(0.0, 0.1, 0, 1), scale=(1000, 300)).autoRetain() objs.append(obj) obj.node.hostOnly = True obj = bsUtils.Image(bs.getTexture('light'), position=(-180, 60 + yOffs), front=True, attach='bottomCenter', vrDepth=baseVRDepth, transition='inBottom', transitionDelay=inTime, transitionOutDelay=outTime, color=(1.8, 1.8, 1.0, 0.0), scale=(40, 300)).autoRetain() objs.append(obj) obj.node.hostOnly = True obj.node.premultiplied = True c = bs.newNode('combine', owner=obj.node, attrs={'size': 2}) bsUtils.animate( c, 'input0', { inTime: 0, inTime + 400: 30, inTime + 500: 40, inTime + 600: 30, inTime + 2000: 0 }) bsUtils.animate( c, 'input1', { inTime: 0, inTime + 400: 200, inTime + 500: 500, inTime + 600: 200, inTime + 2000: 0 }) c.connectAttr('output', obj.node, 'scale') bsUtils.animate(obj.node, 'rotate', {0: 0.0, 350: 360.0}, loop=True) obj = bsUtils.Image(self.getIconTexture(True), position=(-180, 60 + yOffs), attach='bottomCenter', front=True, vrDepth=baseVRDepth - 10, transition='inBottom', transitionDelay=inTime, transitionOutDelay=outTime, scale=(100, 100)).autoRetain() objs.append(obj) obj.node.hostOnly = True # flash color = self.getIconColor(True) c = bs.newNode('combine', owner=obj.node, attrs={'size': 3}) keys = { inTime: 1.0 * color[0], inTime + 400: 1.5 * color[0], inTime + 500: 6.0 * color[0], inTime + 600: 1.5 * color[0], inTime + 2000: 1.0 * color[0] } bsUtils.animate(c, 'input0', keys) keys = { inTime: 1.0 * color[1], inTime + 400: 1.5 * color[1], inTime + 500: 6.0 * color[1], inTime + 600: 1.5 * color[1], inTime + 2000: 1.0 * color[1] } bsUtils.animate(c, 'input1', keys) keys = { inTime: 1.0 * color[2], inTime + 400: 1.5 * color[2], inTime + 500: 6.0 * color[2], inTime + 600: 1.5 * color[2], inTime + 2000: 1.0 * color[2] } bsUtils.animate(c, 'input2', keys) c.connectAttr('output', obj.node, 'color') obj = bsUtils.Image(bs.getTexture('achievementOutline'), modelTransparent=bs.getModel('achievementOutline'), position=(-180, 60 + yOffs), front=True, attach='bottomCenter', vrDepth=baseVRDepth, transition='inBottom', transitionDelay=inTime, transitionOutDelay=outTime, scale=(100, 100)).autoRetain() obj.node.hostOnly = True # flash color = (2, 1.4, 0.4, 1) c = bs.newNode('combine', owner=obj.node, attrs={'size': 3}) keys = { inTime: 1.0 * color[0], inTime + 400: 1.5 * color[0], inTime + 500: 6.0 * color[0], inTime + 600: 1.5 * color[0], inTime + 2000: 1.0 * color[0] } bsUtils.animate(c, 'input0', keys) keys = { inTime: 1.0 * color[1], inTime + 400: 1.5 * color[1], inTime + 500: 6.0 * color[1], inTime + 600: 1.5 * color[1], inTime + 2000: 1.0 * color[1] } bsUtils.animate(c, 'input1', keys) keys = { inTime: 1.0 * color[2], inTime + 400: 1.5 * color[2], inTime + 500: 6.0 * color[2], inTime + 600: 1.5 * color[2], inTime + 2000: 1.0 * color[2] } bsUtils.animate(c, 'input2', keys) c.connectAttr('output', obj.node, 'color') objs.append(obj) obj = bsUtils.Text(bs.Lstr(value='${A}:', subs=[('${A}', bs.Lstr(resource='achievementText')) ]), position=(-120, 91 + yOffs), front=True, vAttach='bottom', vrDepth=baseVRDepth - 10, transition='inBottom', flatness=0.5, transitionDelay=inTime, transitionOutDelay=outTime, color=(1, 1, 1, 0.8), scale=0.65).autoRetain() objs.append(obj) obj.node.hostOnly = True obj = bsUtils.Text(self.getDisplayString(), position=(-120, 50 + yOffs), front=True, vAttach='bottom', transition='inBottom', vrDepth=baseVRDepth, flatness=0.5, transitionDelay=inTime, transitionOutDelay=outTime, flash=True, color=(1, 0.8, 0, 1.0), scale=1.5).autoRetain() objs.append(obj) obj.node.hostOnly = True obj = bsUtils.Text(bs.getSpecialChar('ticket'), position=(-120 - 170 + 5, 75 + yOffs - 20), front=True, vAttach='bottom', hAlign='center', vAlign='center', transition='inBottom', vrDepth=baseVRDepth, transitionDelay=inTime, transitionOutDelay=outTime, flash=True, color=(0.5, 0.5, 0.5, 1), scale=3.0).autoRetain() objs.append(obj) obj.node.hostOnly = True obj = bsUtils.Text('+' + str(self.getAwardTicketValue()), position=(-120 - 180 + 5, 80 + yOffs - 20), vAttach='bottom', front=True, hAlign='center', vAlign='center', transition='inBottom', vrDepth=baseVRDepth, flatness=0.5, shadow=1.0, transitionDelay=inTime, transitionOutDelay=outTime, flash=True, color=(0, 1, 0, 1), scale=1.5).autoRetain() objs.append(obj) obj.node.hostOnly = True # add the 'x 2' if we've got pro if bsUtils._havePro(): obj = bsUtils.Text('x 2', position=(-120 - 180 + 45, 80 + yOffs - 50), vAttach='bottom', front=True, hAlign='center', vAlign='center', transition='inBottom', vrDepth=baseVRDepth, flatness=0.5, shadow=1.0, transitionDelay=inTime, transitionOutDelay=outTime, flash=True, color=(0.4, 0, 1, 1), scale=0.9).autoRetain() objs.append(obj) obj.node.hostOnly = True obj = bsUtils.Text( self.getDescriptionComplete(), # self.getDescriptionCompleteLocalized(), position=(-120, 30 + yOffs), front=True, vAttach='bottom', transition='inBottom', vrDepth=baseVRDepth - 10, flatness=0.5, transitionDelay=inTime, transitionOutDelay=outTime, color=(1.0, 0.7, 0.5, 1.0), scale=0.8).autoRetain() objs.append(obj) obj.node.hostOnly = True for obj in objs: bs.gameTimer(outTime + 1000, bs.WeakCall(obj.handleMessage, bs.DieMessage()))
def Modify_onPlayerLeave(self, player): """ Called when a previously-accepted bs.Player leaves the session. """ # remove them from the game rosters pid = player.get_account_id() if pid is None: idset = { p.get_account_id() for p in self.players if p.get_account_id() is not None } diff = list(set(db.cache.keys()) - idset) else: diff = [pid] if len(diff) > 1: print 'more than one diff:', diff for i in diff: db.playerLeave(i) if player in self.players: bs.playSound(bs.getSound('playerLeft')) # this will be None if the player is still in the chooser team = player.getTeam() activity = self._activityWeak() # if he had no team, he's in the lobby # if we have a current activity with a lobby, ask them to remove him if team is None: with bs.Context(self): try: self._lobby.removeChooser(player) except Exception: bs.printException( 'Error: exception in Lobby.removeChooser()') # *if* he was actually in the game, announce his departure if team is not None and len(activity.players) <= 3: bs.screenMessage( bs.Lstr(resource='playerLeftText', subs=[('${PLAYER}', player.getName(full=True))])) # remove him from his team and session lists # (he may not be on the team list since player are re-added to # team lists every activity) if team is not None and player in team.players: # testing.. can remove this eventually if isinstance(self, bs.FreeForAllSession): if len(team.players) != 1: bs.printError("expected 1 player in FFA team") team.players.remove(player) # remove player from any current activity if activity is not None and player in activity.players: activity.players.remove(player) # run the activity callback unless its been finalized if not activity.isFinalized(): try: with bs.Context(activity): activity.onPlayerLeave(player) except Exception: bs.printException( 'exception in onPlayerLeave for activity', activity) else: bs.printError( "finalized activity in onPlayerLeave; shouldn't happen") player._setActivity(None) # reset the player - this will remove its actor-ref and clear # its calls/etc try: with bs.Context(activity): player._reset() except Exception: bs.printException( 'exception in player._reset in' ' onPlayerLeave for player', player) # if we're a non-team session, remove the player's team completely if not self._useTeams and team is not None: # if the team's in an activity, call its onTeamLeave callback if activity is not None and team in activity.teams: activity.teams.remove(team) if not activity.isFinalized(): try: with bs.Context(activity): activity.onTeamLeave(team) except Exception: bs.printException( 'exception in onTeamLeave for activity', activity) else: bs.printError("finalized activity in onPlayerLeave p2" "; shouldn't happen") # clear the team's game-data (so dying stuff will # have proper context) try: with bs.Context(activity): team._resetGameData() except Exception: bs.printException('exception clearing gameData for team:', team, 'for player:', player, 'in activity:', activity) # remove the team from the session self.teams.remove(team) try: with bs.Context(self): self.onTeamLeave(team) except Exception: bs.printException('exception in onTeamLeave for session', self) # clear the team's session-data (so dying stuff will # have proper context) try: with bs.Context(self): team._resetSessionData() except Exception: bs.printException('exception clearing sessionData for team:', team, 'in session:', self) # now remove them from the session list self.players.remove(player) else: print( 'ERROR: Session.onPlayerLeave called' ' for player not in our list.')
def __init__(self, color=(1, 1, 1), highlight=(0.5, 0.5, 0.5), character="Spaz", player=None, powerupsExpire=True): a = bsInternal._getForegroundHostActivity() if player is None: player = bs.Player(None) if gSettingsEnabled: settings = bs.get_settings() else: settings = {} if a is not None: with bs.Context(a): account = player.getInputDevice()._getAccountName(True) skin = settings.get("skins", {}).get(account, None) if skin is not None: character_name = get_unformat_skin_name(skin) if character_name is not None and character_name in bsSpaz.appearances.keys( ): character = character_name bsSpaz.Spaz.__init__(self, color=color, highlight=highlight, character=character, sourcePlayer=player, startInvincible=True, powerupsExpire=powerupsExpire) self.lastPlayerAttackedBy = None self.lastAttackedTime = 0 self.lastAttackedType = None self.heldCount = 0 self.lastPlayerHeldBy = None self._player = player if skin not in ["invincible"]: prefixes = settings.get("prefixes", {}) vips, admins, hosts = settings.get("vips", []), settings.get( "admins", []), settings.get("hosts", []) profiles = self._player.getInputDevice()._getPlayerProfiles() if profiles == [] or profiles == {}: profiles = bs.getConfig()['Player Profiles'] if prefixes.get(account) is not None: prefix_info = prefixes[account] if isinstance(prefix_info, list): prefix_info = {prefix_info[0]: prefix_info[1]} PermissionEffect(owner=self.node, prefix=prefix_info.values()[0], prefixAnim={ 0: self.node.color, 5000: self.node.highlight, 10000: self.node.color }, type=prefix_info.keys()[0]) elif settings.get("admins_prefix", True): if account in vips or account in admins or account in hosts: anim = {0: (0, 1, 1), 2500: (1, 0, 1), 5000: (0, 1, 1)} if account in hosts: prefix = 'Host' elif account in admins: prefix = 'Admin' elif account in vips: prefix, anim = 'VIP', { 0: (1, 1, 0), 2500: (1, 0.75, 0), 5000: (1, 1, 0) } PermissionEffect(owner=self.node, prefix=prefix, prefixAnim=anim) if player.exists(): playerNode = bs.getActivity()._getPlayerNode(player) self.node.connectAttr('torsoPosition', playerNode, 'position') check_skin(account, self.node)
def _gotNews(self,data): # run this stuff in the context of our activity since we need to make nodes and stuff.. # we should fix the serverGet call so it activity = self._activity() if activity is None or activity.isFinalized(): return with bs.Context(activity): if data is None: return news = str(data['news']) #news = data['news'] # throw out a subtle notice if a new version is available try: env = bs.getEnvironment() # on test builds, report newer test-build availability if env['testBuild']: if 'latestTestBuild' in data and 'latestTestVersion' in data and data['latestTestBuild'] > env['buildNumber']: def foo(): bs.screenMessage(bs.Lstr(resource='newTestBuildAvailableText',subs=[('${VERSION}',str(data['latestTestVersion'])), ('${BUILD}',str(data['latestTestBuild'])), ('${ADDRESS}','files.froemling.net')]),(0.7,1,0)) bs.playSound(bs.getSound('ding')) bs.gameTimer(2000,foo) elif 'latestVersion' in data: # strip off any 'b1' type stuff rawVersion = env['version'].split('b')[0] ourVersion = [int(n) for n in rawVersion.split('.')] while len(ourVersion) < 3: ourVersion.append(0) newestVersion = [int(n) for n in data['latestVersion'].split('.')] while len(newestVersion) < 3: newestVersion.append(0) if newestVersion > ourVersion: def foo(): bs.screenMessage(bs.Lstr(resource='newVersionAvailableText',subs=[('${VERSION}',data['latestVersion']), ('${APP_NAME}',bs.Lstr(resource='titleText'))]),(0.7,1,0)) bs.playSound(bs.getSound('ding')) bs.gameTimer(2000,foo) except Exception,e: print 'Exception comparing versions:',e # our news data now starts with 'BSNews:' so we can filter out # result that arent actually coming in from our server # (such as wireless access point setup pages) if not news.startswith("BSNews:"): return news = news[7:] # if news == '' or not self._valid: return self._phrases = [] # show upcoming achievements in non-vr versions # (currently too hard to read in vr) self._usedPhrases = (['__ACH__'] if not bs.getEnvironment()['vrMode'] else []) + [s for s in news.split('<br>\r\n') if s != ''] self._phraseChangeTimer = bs.Timer(self._messageDuration+self._messageSpacing,bs.WeakCall(self._changePhrase),repeat=True) sc = 1.2 if (bs.getEnvironment()['interfaceType'] == 'small' or bs.getEnvironment()['vrMode']) else 0.8 self._text = bs.NodeActor(bs.newNode('text', attrs={'vAttach':'top', 'hAttach':'center', 'hAlign':'center', 'vrDepth':-20, 'shadow':1.0 if bs.getEnvironment()['vrMode'] else 0.4, 'flatness':0.8, 'vAlign':'top', 'color':(1,1,1,1) if bs.getEnvironment()['vrMode'] else (0.7,0.65,0.75,1.0), 'scale':sc, 'maxWidth':900.0/sc, 'position':(0,-10)})) self._changePhrase()
class MainMenuActivity(bs.Activity): def __init__(self, settings={}): bs.Activity.__init__(self,settings) def onTransitionIn(self): import bsInternal bs.Activity.onTransitionIn(self) global gDidInitialTransition random.seed(123) self._logoNode = None self._customLogoTexName = None self._wordActors = [] env = bs.getEnvironment() # FIXME - shouldn't be doing things conditionally based on whether the host is vr mode or not # (clients may not be or vice versa) - any differences need to happen at the engine level # so everyone sees things in their own optimal way vrMode = bs.getEnvironment()['vrMode'] if not bs.getEnvironment().get('toolbarTest',True): self.myName = bs.NodeActor(bs.newNode('text', attrs={'vAttach':'bottom', 'hAlign':'center', 'color':(1.0,1.0,1.0,1.0) if vrMode else (0.5,0.6,0.5,0.6), 'flatness':1.0, 'shadow':1.0 if vrMode else 0.5, 'scale':0.9 if (env['interfaceType'] == 'small' or vrMode) else 0.7, # FIXME need a node attr for this (smallDeviceExtraScale or something) 'position':(0,10), 'vrDepth':-10, 'text':u'\xa9 2016 Eric Froemling'})) # throw up some text that only clients can see so they know that the host is navigating menus # while they're just staring at an empty-ish screen.. self._hostIsNavigatingText = bs.NodeActor(bs.newNode('text', attrs={'text':bs.Lstr(resource='hostIsNavigatingMenusText',subs=[('${HOST}',bsInternal._getAccountDisplayString())]), 'clientOnly':True, 'position':(0,-200), 'flatness':1.0, 'hAlign':'center'})) # print 'TEXT IS',self._hostIsNavigatingText.node.text if not gDidInitialTransition and hasattr(self,'myName'): bs.animate(self.myName.node,'opacity',{2300:0,3000:1.0}) # TEMP - test hindi if False: # bs.screenMessage("TESTING: "+'TST: "deivit \xf0\x9f\x90\xa2"') self.tTest = bs.NodeActor(bs.newNode('text', attrs={'vAttach':'center', 'hAlign':'left', 'color':(1,1,1,1), 'shadow':1.0, 'flatness':0.0, 'scale':1, 'position':(-500,-40), 'text':('\xe0\xa4\x9c\xe0\xa4\xbf\xe0\xa4\xb8 \xe0\xa4\xad\xe0\xa5\x80 \xe0\xa4\x9a\xe0\xa5\x80\xe0\xa5\x9b \xe0\xa4\x95\xe0\xa5\x8b \xe0\xa4\x9b\xe0\xa5\x81\xe0\xa4\x8f\xe0\xa4\x81\xe0\xa4\x97\xe0\xa5\x87 \xe0\xa4\x89\xe0\xa4\xb8\xe0\xa4\xb8\xe0\xa5\x87 \xe0\xa4\x9a\xe0\xa4\xbf\xe0\xa4\xaa\xe0\xa4\x95\n\xe0\xa4\x9c\xe0\xa4\xbe\xe0\xa4\xaf\xe0\xa5\x87\xe0\xa4\x82\xe0\xa4\x97\xe0\xa5\x87 .. \xe0\xa4\x87\xe0\xa4\xb8\xe0\xa4\x95\xe0\xa4\xbe \xe0\xa4\xae\xe0\xa5\x9b\xe0\xa4\xbe \xe0\xa4\xb2\xe0\xa5\x87\xe0\xa4\x82 !')})) # TEMP - test emoji if False: # bs.screenMessage("TESTING: "+'TST: "deivit \xf0\x9f\x90\xa2"') self.tTest = bs.NodeActor(bs.newNode('text', attrs={'vAttach':'center', 'hAlign':'left', 'color':(1,1,1,1), 'shadow':1.0, 'flatness':1.0, 'scale':1, 'position':(-500,-40), 'text':('TST: "deivit \xf0\x9f\x90\xa2"')})) #'text':('TST: "deivit \xf0\x9f\x90\xa2"')})) if False: # bs.screenMessage("TESTING: "+'TST: "deivit \xf0\x9f\x90\xa2"') self.tTest = bs.NodeActor(bs.newNode('text', attrs={'vAttach':'center', 'hAlign':'left', 'color':(1,1,1,1), 'shadow':1.0, 'flatness':0.0, 'scale':1, 'position':(-500,0), #'text':u' \u3147\u3147 \uad8c\ucc2c\uadfc \uae40\uc6d0\uc7ac\n \ub10c \uc804\uac10\ud638\nlll\u0935\u093f\u0936\u0947\u0937 \u0927\u0928\u094d\u092f\u0935\u093e\u0926:\n'})) 'text':u' \u3147\u3147 \uad8c\ucc2c\uadfc \uae40\uc6d0\uc7ac\n \ub10c \uc804\uac10\ud638\nlll\u0935\u093f\u0936\u0947\u0937 \u0927\u0928\u094d\u092f\u0935\u093e\u0926:\n'})) # TEMP - test chinese stuff if False: self.tTest = bs.NodeActor(bs.newNode('text', attrs={'vAttach':'center', 'hAlign':'center', 'color':(1,1,1,1), 'shadow':1.0, 'flatness':0.0, 'scale':1, 'position':(-400,-40), 'text':('TST: "\xe8\x8e\xb7\xe5\x8f\x96\xe6\x9b\xb4\xe5\xa4\x9a\xe5\x9b\xbe\xe6\xa0\x87"\n' '\xe6\x88\x90\xe5\xb0\xb1\xe4\xb8\xad| foo\n' '\xe8\xb4\xa6\xe6\x88\xb7 \xe7\x99\xbb\xe9\x99\x86foo\n' 'end"\xe8\x8e\xb7\xe5\x8f\x96\xe6\x9b\xb4\xe5\xa4\x9a\xe5\x9b\xbe\xe6\xa0\x87"\n' 'end"\xe8\x8e\xb7\xe5\x8f\x96\xe6\x9b\xb4\xe5\xa4\x9a\xe5\x9b\xbe\xe6\xa0\x87"\n' 'end2"\xe8\x8e\xb7\xe5\x8f\x96\xe6\x9b\xb4\xe5\xa4\x9a\xe5\x9b\xbe\xe6\xa0\x87"\n' )})) # FIXME - shouldn't be doing things conditionally based on whether the host is vr mode or not # (clients may not be or vice versa) - any differences need to happen at the engine level # so everyone sees things in their own optimal way vrMode = env['vrMode'] interfaceType = env['interfaceType'] # in cases where we're doing lots of dev work lets always show the build number forceShowBuildNumber = False if not bs.getEnvironment().get('toolbarTest',True): if env['debugBuild'] or env['testBuild'] or forceShowBuildNumber: if env['debugBuild']: #text = bs.Lstr(value='${V} (${B}) (${D})',subs=[('${V}',env['version']),('${B}',str(env['buildNumber'])),('${D}',{'resource':'debugText'})]) text = bs.Lstr(value='${V} (${B}) (${D})',subs=[('${V}',env['version']),('${B}',str(env['buildNumber'])),('${D}',bs.Lstr(resource='debugText'))]) else: # text = bs.Lstr(value='${V} (${B})',subs=[('${V}',env['version']),('${B}',str(env['buildNumber']))]) text = bs.Lstr(value='${V} (${B})',subs=[('${V}',env['version']),('${B}',str(env['buildNumber']))]) else: text = bs.Lstr(value='${V}',subs=[('${V}',env['version'])]) self.version = bs.NodeActor(bs.newNode('text', attrs={'vAttach':'bottom', 'hAttach':'right', 'hAlign':'right', 'flatness':1.0, 'vrDepth':-10, 'shadow':1.0 if vrMode else 0.5, 'color':(1,1,1,1) if vrMode else (0.5,0.6,0.5,0.7), 'scale':0.9 if (interfaceType == 'small' or vrMode) else 0.7, 'position':(-260,10) if vrMode else (-10,10), 'text':text })) if not gDidInitialTransition: bs.animate(self.version.node,'opacity',{2300:0,3000:1.0}) # throw in beta info.. self.betaInfo = self.betaInfo2 = None if env['testBuild'] and not env['kioskMode']: self.betaInfo = bs.NodeActor(bs.newNode('text', attrs={'vAttach':'center', 'hAlign':'center', 'color':(1,1,1,1), 'shadow':0.5, 'flatness':0.5, 'scale':1, 'vrDepth':-60, 'position':(230,125) if env['kioskMode'] else (230,35), 'text':bs.Lstr(resource='testBuildText') })) if not gDidInitialTransition: bs.animate(self.betaInfo.node,'opacity',{1300:0,1800:1.0}) # if not gDidInitialTransition and not env['kioskMode'] and bs.getLanguage() == 'English': # self.betaInfo2 = bs.NodeActor(bs.newNode('text', # attrs={'vAttach':'center', # 'hAlign':'left', # 'color':(1,1,1,1), # 'shadow':0.5, # 'flatness':0.5, # 'scale':0.6, # 'position':(177,15), # 'text':('Thanks for helping test the game!\n' # +('Note that some features such as GameCenter\n' # 'will not function in this build.\n' if 'Mac' in bs.getEnvironment()['userAgentString'] else '') # +'Please email any bugs or other feedback to\n' # '[email protected] or just post it on the\n' # 'BombSquad facebook page.\n' # 'Enjoy!\n' # '-eric')})) # if not gDidInitialTransition: # bs.animate(self.betaInfo2.node,'opacity',{2300:0,3000:1.0,10000:1.0,11000:0.0}) model = bs.getModel('thePadLevel') treesModel = bs.getModel('trees') bottomModel = bs.getModel('thePadLevelBottom') testColorTexture = bs.getTexture('thePadLevelColor') treesTexture = bs.getTexture('treesColor') bgTex = bs.getTexture('menuBG') bgModel = bs.getModel('thePadBG') # (load these last since most platforms don't use them..) vrBottomFillModel = bs.getModel('thePadVRFillBottom') vrTopFillModel = bs.getModel('thePadVRFillTop') bsGlobals = bs.getSharedObject('globals') bsGlobals.cameraMode = 'rotate' if False: node = bs.newNode('timeDisplay', attrs={'timeMin':2000, 'timeMax':10000, 'showSubSeconds':True}) self._fooText = bs.NodeActor(bs.newNode('text', attrs={'position':(0,-220), 'flatness':1.0, 'hAlign':'center'})) bsGlobals.connectAttr('gameTime',node,'time2') node.connectAttr('output',self._fooText.node,'text') tint = (1.14,1.1,1.0) bsGlobals.tint = tint bsGlobals.ambientColor = (1.06,1.04,1.03) bsGlobals.vignetteOuter = (0.45,0.55,0.54) bsGlobals.vignetteInner = (0.99,0.98,0.98) self.bottom = bs.NodeActor(bs.newNode('terrain', attrs={'model':bottomModel, 'lighting':False, 'reflection':'soft', 'reflectionScale':[0.45], 'colorTexture':testColorTexture})) self.vrBottomFill = bs.NodeActor(bs.newNode('terrain', attrs={'model':vrBottomFillModel, 'lighting':False, 'vrOnly':True, 'colorTexture':testColorTexture})) self.vrTopFill = bs.NodeActor(bs.newNode('terrain', attrs={'model':vrTopFillModel, 'vrOnly':True, 'lighting':False, 'colorTexture':bgTex})) self.terrain = bs.NodeActor(bs.newNode('terrain', attrs={'model':model, 'colorTexture':testColorTexture, 'reflection':'soft', 'reflectionScale':[0.3]})) self.trees = bs.NodeActor(bs.newNode('terrain', attrs={'model':treesModel, 'lighting':False, 'reflection':'char', 'reflectionScale':[0.1], 'colorTexture':treesTexture})) self.bg = bs.NodeActor(bs.newNode('terrain', attrs={'model':bgModel, 'color':(0.92,0.91,0.9), 'lighting':False, 'background':True, 'colorTexture':bgTex})) textOffsetV = 0 self._ts = 0.86 self._language = None self._updateTimer = bs.Timer(1000, self._update, repeat=True) self._update() # hopefully this won't hitch but lets space these out anyway.. bsInternal._addCleanFrameCallback(bs.WeakCall(self._startPreloads)) random.seed() # on the main menu, also show our news.. class News(object): def __init__(self,activity): self._valid = True self._messageDuration = 10000 self._messageSpacing = 2000 self._text = None self._activity = weakref.ref(activity) # if we're signed in, fetch news immediately.. otherwise wait until we are signed in self._fetchTimer = bs.Timer(1000,bs.WeakCall(self._tryFetchingNews),repeat=True) self._tryFetchingNews() # we now want to wait until we're signed in before fetching news def _tryFetchingNews(self): if bsInternal._getAccountState() == 'SIGNED_IN': self._fetchNews() self._fetchTimer = None def _fetchNews(self): try: launchCount = bs.getConfig()['launchCount'] except Exception: launchCount = None global gLastNewsFetchTime gLastNewsFetchTime = time.time() #bsUtils.serverGet('bsNews',{'v':'2','lc':launchCount,'b':bs.getEnvironment()['buildNumber'],'t':int(gLastNewsFetchTime-gStartTime)},bs.WeakCall(self._gotNews)) env = bs.getEnvironment() bsInternal._newsQuery(args={'v':2,'lc':launchCount,'t':int(gLastNewsFetchTime-gStartTime),'p':env['platform'],'sp':env['subplatform']},callback=bs.WeakCall(self._gotNews)) def _changePhrase(self): global gLastNewsFetchTime # if our news is way out of date, lets re-request it.. otherwise, rotate our phrase if time.time()-gLastNewsFetchTime > 600.0: self._fetchNews() self._text = None else: if self._text is not None: if len(self._phrases) == 0: for p in self._usedPhrases: self._phrases.insert(0,p) val = self._phrases.pop() if val == '__ACH__': vr = bs.getEnvironment()['vrMode'] bsUtils.Text(bs.Lstr(resource='nextAchievementsText'), color=(1,1,1,1) if vr else (0.95,0.9,1,0.4), hostOnly=True, maxWidth=200, position=(-300, -35), hAlign='right', transition='fadeIn', scale=0.9 if vr else 0.7, flatness=1.0 if vr else 0.6, shadow=1.0 if vr else 0.5, hAttach="center", vAttach="top", transitionDelay=1000, transitionOutDelay=self._messageDuration).autoRetain() import bsAchievement achs = [a for a in bsAchievement.gAchievements if not a.isComplete()] if len(achs) > 0: a = achs.pop(random.randrange(min(4,len(achs)))) a.createDisplay(-180,-35,1000,outDelay=self._messageDuration,style='news') if len(achs) > 0: a = achs.pop(random.randrange(min(8,len(achs)))) a.createDisplay(180,-35,1250,outDelay=self._messageDuration,style='news') else: s = self._messageSpacing keys = {s:0,s+1000:1.0,s+self._messageDuration-1000:1.0,s+self._messageDuration:0.0} bs.animate(self._text.node,"opacity",dict([[k,v] for k,v in keys.items()])) self._text.node.text = val def _gotNews(self,data): # run this stuff in the context of our activity since we need to make nodes and stuff.. # we should fix the serverGet call so it activity = self._activity() if activity is None or activity.isFinalized(): return with bs.Context(activity): if data is None: return news = str(data['news']) #news = data['news'] # throw out a subtle notice if a new version is available try: env = bs.getEnvironment() # on test builds, report newer test-build availability if env['testBuild']: if 'latestTestBuild' in data and 'latestTestVersion' in data and data['latestTestBuild'] > env['buildNumber']: def foo(): bs.screenMessage(bs.Lstr(resource='newTestBuildAvailableText',subs=[('${VERSION}',str(data['latestTestVersion'])), ('${BUILD}',str(data['latestTestBuild'])), ('${ADDRESS}','files.froemling.net')]),(0.7,1,0)) bs.playSound(bs.getSound('ding')) bs.gameTimer(2000,foo) elif 'latestVersion' in data: # strip off any 'b1' type stuff rawVersion = env['version'].split('b')[0] ourVersion = [int(n) for n in rawVersion.split('.')] while len(ourVersion) < 3: ourVersion.append(0) newestVersion = [int(n) for n in data['latestVersion'].split('.')] while len(newestVersion) < 3: newestVersion.append(0) if newestVersion > ourVersion: def foo(): bs.screenMessage(bs.Lstr(resource='newVersionAvailableText',subs=[('${VERSION}',data['latestVersion']), ('${APP_NAME}',bs.Lstr(resource='titleText'))]),(0.7,1,0)) bs.playSound(bs.getSound('ding')) bs.gameTimer(2000,foo) except Exception,e: print 'Exception comparing versions:',e # our news data now starts with 'BSNews:' so we can filter out # result that arent actually coming in from our server # (such as wireless access point setup pages) if not news.startswith("BSNews:"): return news = news[7:] # if news == '' or not self._valid: return self._phrases = [] # show upcoming achievements in non-vr versions # (currently too hard to read in vr) self._usedPhrases = (['__ACH__'] if not bs.getEnvironment()['vrMode'] else []) + [s for s in news.split('<br>\r\n') if s != ''] self._phraseChangeTimer = bs.Timer(self._messageDuration+self._messageSpacing,bs.WeakCall(self._changePhrase),repeat=True) sc = 1.2 if (bs.getEnvironment()['interfaceType'] == 'small' or bs.getEnvironment()['vrMode']) else 0.8 self._text = bs.NodeActor(bs.newNode('text', attrs={'vAttach':'top', 'hAttach':'center', 'hAlign':'center', 'vrDepth':-20, 'shadow':1.0 if bs.getEnvironment()['vrMode'] else 0.4, 'flatness':0.8, 'vAlign':'top', 'color':(1,1,1,1) if bs.getEnvironment()['vrMode'] else (0.7,0.65,0.75,1.0), 'scale':sc, 'maxWidth':900.0/sc, 'position':(0,-10)})) self._changePhrase() if not env['kioskMode'] and not env.get('toolbarTest',True): self._news = News(self) # bring up the last place we were at, or start at the main menu otherwise with bs.Context('UI'): try: mainWindow = bsUI.gMainWindow except Exception: mainWindow = None # when coming back from a kiosk-mode game, jump to the kiosk start screen.. if bsUtils.gRunningKioskModeGame: bsUI.uiGlobals['mainMenuWindow'] = bsUI.KioskWindow().getRootWidget() # ..or in normal cases go back to the main menu else: if mainWindow == 'Gather': bsUI.uiGlobals['mainMenuWindow'] = bsUI.GatherWindow(transition=None).getRootWidget() elif mainWindow == 'Watch': bsUI.uiGlobals['mainMenuWindow'] = bsUI.WatchWindow(transition=None).getRootWidget() elif mainWindow == 'Team Game Select': bsUI.uiGlobals['mainMenuWindow'] = bsUI.TeamsWindow(sessionType=bs.TeamsSession,transition=None).getRootWidget() elif mainWindow == 'Free-for-All Game Select': bsUI.uiGlobals['mainMenuWindow'] = bsUI.TeamsWindow(sessionType=bs.FreeForAllSession,transition=None).getRootWidget() elif mainWindow == 'Coop Select': bsUI.uiGlobals['mainMenuWindow'] = bsUI.CoopWindow(transition=None).getRootWidget() else: bsUI.uiGlobals['mainMenuWindow'] = bsUI.MainMenuWindow(transition=None).getRootWidget() # attempt to show any pending offers immediately. If that doesn't work, try again in a few seconds (we may not have heard back from the server) # ..if that doesn't work they'll just have to wait until the next opportunity. if not bsUI._showOffer(): def tryAgain(): if not bsUI._showOffer(): bs.realTimer(2000,bsUI._showOffer) # try one last time.. bs.realTimer(2000,tryAgain) gDidInitialTransition = True
def k(reason, id, name='Player'): with bs.Context('UI'): bs.screenMessage((u'Kicking {} | Reason: {}').format(name, reason), transient=True) bsInternal._disconnectClient(int(id))
def onTransitionIn(self): import bsInternal bs.Activity.onTransitionIn(self) global gDidInitialTransition random.seed(123) self._logoNode = None self._customLogoTexName = None self._wordActors = [] env = bs.getEnvironment() # FIXME - shouldn't be doing things conditionally based on whether # the host is vr mode or not (clients may not be or vice versa) - # any differences need to happen at the engine level # so everyone sees things in their own optimal way vrMode = bs.getEnvironment()['vrMode'] if not bs.getEnvironment().get('toolbarTest', True): self.myName = bs.NodeActor( bs.newNode( 'text', attrs={ 'vAttach': 'bottom', 'hAlign': 'center', 'color': (1.0, 1.0, 1.0, 1.0) if vrMode else (0.5, 0.6, 0.5, 0.6), 'flatness': 1.0, 'shadow': 1.0 if vrMode else 0.5, 'scale': (0.9 if (env['interfaceType'] == 'small' or vrMode) else 0.7), # FIXME need a node attr for this 'position': (0, 10), 'vrDepth': -10, 'text': u'\xa9 2018 Eric Froemling' })) # throw up some text that only clients can see so they know that the # host is navigating menus while they're just staring at an # empty-ish screen.. self._hostIsNavigatingText = bs.NodeActor( bs.newNode('text', attrs={ 'text': bs.Lstr(resource='hostIsNavigatingMenusText', subs=[ ('${HOST}', bsInternal._getAccountDisplayString()) ]), 'clientOnly': True, 'position': (0, -200), 'flatness': 1.0, 'hAlign': 'center' })) if not gDidInitialTransition and hasattr(self, 'myName'): bs.animate(self.myName.node, 'opacity', {2300: 0, 3000: 1.0}) # TEMP - testing hindi text if False: # bs.screenMessage("TESTING: "+'TST: "deivit \xf0\x9f\x90\xa2"') self.tTest = bs.NodeActor( bs.newNode( 'text', attrs={ 'vAttach': 'center', 'hAlign': 'left', 'color': (1, 1, 1, 1), 'shadow': 1.0, 'flatness': 0.0, 'scale': 1, 'position': (-500, -40), 'text': ('\xe0\xa4\x9c\xe0\xa4\xbf\xe0\xa4\xb8 \xe0\xa4\xad' '\xe0\xa5\x80 \xe0\xa4\x9a\xe0\xa5\x80\xe0\xa5\x9b ' '\xe0\xa4\x95\xe0\xa5\x8b \xe0\xa4\x9b\xe0\xa5\x81' '\xe0\xa4\x8f\xe0\xa4\x81\xe0\xa4\x97\xe0\xa5\x87 ' '\xe0\xa4\x89\xe0\xa4\xb8\xe0\xa4\xb8\xe0\xa5\x87 ' '\xe0\xa4\x9a\xe0\xa4\xbf\xe0\xa4\xaa\xe0\xa4\x95' '\n\xe0\xa4\x9c\xe0\xa4\xbe\xe0\xa4\xaf\xe0\xa5\x87' '\xe0\xa4\x82\xe0\xa4\x97\xe0\xa5\x87 .. \xe0\xa4' '\x87\xe0\xa4\xb8\xe0\xa4\x95\xe0\xa4\xbe \xe0\xa4' '\xae\xe0\xa5\x9b\xe0\xa4\xbe \xe0\xa4\xb2\xe0\xa5' '\x87\xe0\xa4\x82 !') })) # TEMP - test emoji if False: # bs.screenMessage("TESTING: "+'TST: "deivit \xf0\x9f\x90\xa2"') self.tTest = bs.NodeActor( bs.newNode('text', attrs={ 'vAttach': 'center', 'hAlign': 'left', 'color': (1, 1, 1, 1), 'shadow': 1.0, 'flatness': 1.0, 'scale': 1, 'position': (-500, -40), 'text': ('TST: "deivit \xf0\x9f\x90\xa2"') })) # TEMP - testing something; forgot what if False: # bs.screenMessage("TESTING: "+'TST: "deivit \xf0\x9f\x90\xa2"') self.tTest = bs.NodeActor( bs.newNode( 'text', attrs={ 'vAttach': 'center', 'hAlign': 'left', 'color': (1, 1, 1, 1), 'shadow': 1.0, 'flatness': 0.0, 'scale': 1, 'position': (-500, 0), 'text': u(' \u3147\u3147 ' ' \uad8c\ucc2c\uadfc ' ' \uae40\uc6d0\uc7ac\n ' ' \ub10c ' ' \uc804\uac10\ud638\nlll\u0935\u093f\u0936\u0947' '\u0937 \u0927\u0928\u094d\u092f\u0935\u093e' '\u0926:\n') })) self.tTest = bs.NodeActor( bs.newNode('text', attrs={ 'vAttach': 'center', 'hAlign': 'left', 'color': (0, 8, 0, 1), 'shadow': 1.0, 'flatness': 1.0, 'scale': 3, 'position': (0, -30), 'text': ('EVOLVED') })) if False: self.tTest = bs.NodeActor( bs.newNode( 'text', attrs={ 'vAttach': 'center', 'hAlign': 'center', 'color': (1, 1, 1, 1), 'shadow': 1.0, 'flatness': 0.0, 'scale': 1, 'position': (-400, -40), 'text': ('TST: "\xe8\x8e\xb7\xe5\x8f\x96\xe6\x9b\xb4\xe5\xa4' '\x9a\xe5\x9b\xbe\xe6\xa0\x87"\n\xe6\x88\x90\xe5' '\xb0\xb1\xe4\xb8\xad| foo\n\xe8\xb4\xa6' '\xe6\x88\xb7 \xe7\x99\xbb\xe9\x99\x86foo\nend"' '\xe8\x8e\xb7\xe5\x8f\x96\xe6\x9b\xb4\xe5\xa4\x9a' '\xe5\x9b\xbe\xe6\xa0\x87"\nend"\xe8\x8e\xb7\xe5' '\x8f\x96\xe6\x9b\xb4\xe5\xa4\x9a\xe5\x9b\xbe\xe6' '\xa0\x87"\nend2"\xe8\x8e\xb7\xe5\x8f\x96\xe6\x9b' '\xb4\xe5\xa4\x9a\xe5\x9b\xbe\xe6\xa0\x87"\n') })) # FIXME - shouldn't be doing things conditionally based on whether # the host is vr mode or not (clients may not be or vice versa) # - any differences need to happen at the engine level # so everyone sees things in their own optimal way vrMode = env['vrMode'] interfaceType = env['interfaceType'] # in cases where we're doing lots of dev work lets # always show the build number forceShowBuildNumber = False if not bs.getEnvironment().get('toolbarTest', True): if env['debugBuild'] or env['testBuild'] or forceShowBuildNumber: if env['debugBuild']: text = bs.Lstr(value='${V} (${B}) (${D})', subs=[('${V}', env['version']), ('${B}', str(env['buildNumber'])), ('${D}', bs.Lstr(resource='debugText'))]) else: text = bs.Lstr(value='${V} (${B})', subs=[('${V}', env['version']), ('${B}', str(env['buildNumber']))]) else: text = bs.Lstr(value='${V}', subs=[('${V}', env['version'])]) self.version = bs.NodeActor( bs.newNode('text', attrs={ 'vAttach': 'bottom', 'hAttach': 'right', 'hAlign': 'right', 'flatness': 1.0, 'vrDepth': -10, 'shadow': 1.0 if vrMode else 0.5, 'color': (1, 1, 1, 1) if vrMode else (0.5, 0.6, 0.5, 0.7), 'scale': 0.9 if (interfaceType == 'small' or vrMode) else 0.7, 'position': (-260, 10) if vrMode else (-10, 10), 'text': text })) if not gDidInitialTransition: bs.animate(self.version.node, 'opacity', {2300: 0, 3000: 1.0}) # throw in beta info.. self.betaInfo = self.betaInfo2 = None if env['testBuild'] and not env['kioskMode']: self.betaInfo = bs.NodeActor( bs.newNode('text', attrs={ 'vAttach': 'center', 'hAlign': 'center', 'color': (1, 1, 1, 1), 'shadow': 0.5, 'flatness': 0.5, 'scale': 1, 'vrDepth': -60, 'position': (230, 125) if env['kioskMode'] else (230, 35), 'text': bs.Lstr(resource='testBuildText') })) if not gDidInitialTransition: bs.animate(self.betaInfo.node, 'opacity', {1300: 0, 1800: 1.0}) model = bs.getModel('bridgitLevelTop') treesModel = bs.getModel('trees') bottomModel = bs.getModel('bridgitLevelBottom') testColorTexture = bs.getTexture('bridgitLevelColor') treesTexture = bs.getTexture('bombColorIce') bgTex = bs.getTexture('natureBackgroundColor') bgModel = bs.getModel('natureBackground') bgCollide = bs.getCollideModel('natureBackgroundCollide') # (load these last since most platforms don't use them..) vrBottomFillModel = bs.getModel('thePadVRFillBottom') vrTopFillModel = bs.getModel('thePadVRFillTop') bsGlobals = bs.getSharedObject('globals') if False: node = bs.newNode('timeDisplay', attrs={ 'timeMin': 2000, 'timeMax': 10000, 'showSubSeconds': True }) self._fooText = bs.NodeActor( bs.newNode('text', attrs={ 'position': (0, -220), 'flatness': 1.0, 'hAlign': 'center' })) bsGlobals.connectAttr('gameTime', node, 'time2') node.connectAttr('output', self._fooText.node, 'text') tint = (1.14, 1.1, 1.0) bsGlobals.tint = tint bsGlobals.ambientColor = (1.06, 1.04, 1.03) bsGlobals.vignetteOuter = (0.45, 0.55, 0.54) bsGlobals.vignetteInner = (0.99, 0.98, 0.98) #self.bottom = bs.NodeActor(bs.newNode('terrain', attrs={ # 'model':bottomModel, # 'lighting':False, # 'reflection':'soft', # 'reflectionScale':[0.45], # 'colorTexture':testColorTexture})) self.vrBottomFill = bs.NodeActor( bs.newNode('terrain', attrs={ 'model': vrBottomFillModel, 'lighting': False, 'vrOnly': True, 'colorTexture': testColorTexture })) self.vrTopFill = bs.NodeActor( bs.newNode('terrain', attrs={ 'model': vrTopFillModel, 'vrOnly': True, 'lighting': False, 'colorTexture': bgTex })) #self.terrain = bs.NodeActor(bs.newNode('terrain', attrs={ # 'model':model, # 'colorTexture':testColorTexture, # 'reflection':'soft', # 'reflectionScale':[0.3]})) self.trees = bs.NodeActor( bs.newNode('terrain', attrs={ 'model': treesModel, 'lighting': True, 'reflection': 'char', 'reflectionScale': [0.1], 'colorTexture': treesTexture })) self.bg = bs.NodeActor( bs.newNode('terrain', attrs={ 'model': bgModel, 'color': (0.92, 0.91, 0.9), 'lighting': False, 'background': True, 'colorTexture': bgTex, 'collideModel': bgCollide, 'materials': [bs.getSharedObject('footingMaterial')] })) def _spawnBall(): bs.Something( (10, random.randint(-2, 8), random.randint(-5, 5)), (-20, random.randint(-2, 2), 0), (True, int(((random.randint(1, 8) / 4) * 1000)))).autoRetain() self.timer = bs.Timer(1000, bs.Call(_spawnBall), repeat=True) textOffsetV = 0 self._ts = 0.86 self._language = None self._updateTimer = bs.Timer(1000, self._update, repeat=True) self._update() # hopefully this won't hitch but lets space these out anyway.. bsInternal._addCleanFrameCallback(bs.WeakCall(self._startPreloads)) random.seed() # on the main menu, also show our news.. class News(object): def __init__(self, activity): self._valid = True self._messageDuration = 10000 self._messageSpacing = 2000 self._text = None self._activity = weakref.ref(activity) # if we're signed in, fetch news immediately.. # otherwise wait until we are signed in self._fetchTimer = bs.Timer(1000, bs.WeakCall(self._tryFetchingNews), repeat=True) self._tryFetchingNews() # we now want to wait until we're signed in before fetching news def _tryFetchingNews(self): if bsInternal._getAccountState() == 'SIGNED_IN': self._fetchNews() self._fetchTimer = None def _fetchNews(self): try: launchCount = bs.getConfig()['launchCount'] except Exception: launchCount = None global gLastNewsFetchTime gLastNewsFetchTime = time.time() # UPDATE - we now just pull news from MRVs news = bsInternal._getAccountMiscReadVal('n', None) if news is not None: self._gotNews(news) def _changePhrase(self): global gLastNewsFetchTime # if our news is way out of date, lets re-request it.. # otherwise, rotate our phrase if time.time() - gLastNewsFetchTime > 600.0: self._fetchNews() self._text = None else: if self._text is not None: if len(self._phrases) == 0: for p in self._usedPhrases: self._phrases.insert(0, p) val = self._phrases.pop() if val == '__ACH__': vr = bs.getEnvironment()['vrMode'] bsUtils.Text( bs.Lstr(resource='nextAchievementsText'), color=(1,1,1,1) if vr else (0.95,0.9,1,0.4), hostOnly=True, maxWidth=200, position=(-300, -35), hAlign='right', transition='fadeIn', scale=0.9 if vr else 0.7, flatness=1.0 if vr else 0.6, shadow=1.0 if vr else 0.5, hAttach="center", vAttach="top", transitionDelay=1000, transitionOutDelay=self._messageDuration)\ .autoRetain() import bsAchievement achs = [ a for a in bsAchievement.gAchievements if not a.isComplete() ] if len(achs) > 0: a = achs.pop( random.randrange(min(4, len(achs)))) a.createDisplay(-180, -35, 1000, outDelay=self._messageDuration, style='news') if len(achs) > 0: a = achs.pop( random.randrange(min(8, len(achs)))) a.createDisplay(180, -35, 1250, outDelay=self._messageDuration, style='news') else: s = self._messageSpacing keys = { s: 0, s + 1000: 1.0, s + self._messageDuration - 1000: 1.0, s + self._messageDuration: 0.0 } bs.animate(self._text.node, "opacity", dict([[k, v] for k, v in keys.items()])) self._text.node.text = val def _gotNews(self, news): # run this stuff in the context of our activity since we need # to make nodes and stuff.. should fix the serverGet call so it activity = self._activity() if activity is None or activity.isFinalized(): return with bs.Context(activity): self._phrases = [] # show upcoming achievements in non-vr versions # (currently too hard to read in vr) self._usedPhrases = ( ['__ACH__'] if not bs.getEnvironment()['vrMode'] else []) + [s for s in news.split('<br>\n') if s != ''] self._phraseChangeTimer = bs.Timer( self._messageDuration + self._messageSpacing, bs.WeakCall(self._changePhrase), repeat=True) sc = 1.2 if ( bs.getEnvironment()['interfaceType'] == 'small' or bs.getEnvironment()['vrMode']) else 0.8 self._text = bs.NodeActor( bs.newNode( 'text', attrs={ 'vAttach': 'top', 'hAttach': 'center', 'hAlign': 'center', 'vrDepth': -20, 'shadow': 1.0 if bs.getEnvironment()['vrMode'] else 0.4, 'flatness': 0.8, 'vAlign': 'top', 'color': ((1, 1, 1, 1) if bs.getEnvironment()['vrMode'] else (0.7, 0.65, 0.75, 1.0)), 'scale': sc, 'maxWidth': 900.0 / sc, 'position': (0, -10) })) self._changePhrase() if not env['kioskMode'] and not env.get('toolbarTest', True): self._news = News(self) # bring up the last place we were, or start at the main menu otherwise with bs.Context('UI'): try: mainWindow = bsUI.gMainWindow except Exception: mainWindow = None # when coming back from a kiosk-mode game, jump to # the kiosk start screen.. if bsUtils.gRunningKioskModeGame: if bs.getEnvironment()['kioskMode']: bsUI.uiGlobals['mainMenuWindow'] = \ bsUI.KioskWindow().getRootWidget() # ..or in normal cases go back to the main menu else: if mainWindow == 'Gather': bsUI.uiGlobals['mainMenuWindow'] = \ bsUI.GatherWindow(transition=None).getRootWidget() elif mainWindow == 'Watch': bsUI.uiGlobals['mainMenuWindow'] = \ bsUI.WatchWindow(transition=None).getRootWidget() elif mainWindow == 'Team Game Select': bsUI.uiGlobals['mainMenuWindow'] = \ bsUI.TeamsWindow(sessionType=bs.TeamsSession, transition=None).getRootWidget() elif mainWindow == 'Free-for-All Game Select': bsUI.uiGlobals['mainMenuWindow'] = \ bsUI.TeamsWindow(sessionType=bs.FreeForAllSession, transition=None).getRootWidget() elif mainWindow == 'Coop Select': bsUI.uiGlobals['mainMenuWindow'] = \ bsUI.CoopWindow(transition=None).getRootWidget() else: bsUI.uiGlobals['mainMenuWindow'] = \ bsUI.MainMenuWindow(transition=None).getRootWidget() # attempt to show any pending offers immediately. # If that doesn't work, try again in a few seconds # (we may not have heard back from the server) # ..if that doesn't work they'll just have to wait # until the next opportunity. if not bsUI._showOffer(): def tryAgain(): if not bsUI._showOffer(): # try one last time.. bs.realTimer(2000, bsUI._showOffer) bs.realTimer(2000, tryAgain) gDidInitialTransition = True
def opt(self, nick, msg): if self.checkDevice(nick): m = msg.split(' ')[0] # command a = msg.split(' ')[1:] # arguments activity = bsInternal._getForegroundHostActivity() with bs.Context(activity): if m == '/kick': if a == []: bsInternal._chatMessage( 'Using: /kick name or clientID') else: if len(a[0]) > 3: self.kickByNick(a[0]) bsInternal._chatMessage('Player Kicked By Admin') else: try: s = int(a[0]) bsInternal._chatMessage( 'Player Kicked By Admin') bsInternal._disconnectClient(int(a[0])) except: self.kickByNick(a[0]) elif m == '/admin': clID = int(a[0]) for client in bsInternal._getGameRoster(): if client['clientID'] == clID: if a[1] == 'add': newadmin = client['displayString'] updated_admins = gph.adminHashes.append( newadmin) elif a[1] == 'remove': newadmin = client['displayString'] if newadmin in gph.adminHashes: updated_admins = gph.adminHashes.remove( newadmin) with open(bs.getEnvironment()['systemScriptsDirectory'] + "/getPermissionsHashes.py") as file: s = [row for row in file] s[0] = 'vipHashes = []' + '\n' s[1] = 'adminHashes = ' + updated_admins + '\n' f = open( bs.getEnvironment()['systemScriptsDirectory'] + "/getPermissionsHashes.py", 'w') for i in s: f.write(i) f.close() elif m == '/ban': clID = int(a[0]) for client in bsInternal._getGameRoster(): if client['clientID'] == clID: if a[1] == 'add': ban = client['displayString'] updated_ban = gph.ban.append(ban) bs.screenMessage('Banning...') elif a[1] == 'remove': ban = client['displayString'] if ban in gph.ban: updated_ban = gph.ban.remove(ban) with open(bs.getEnvironment()['systemScriptsDirectory'] + "/getPermissionsHashes.py") as file: s = [row for row in file] s[0] = 'vipHashes = []' + '\n' s[1] = 'admin = []' + '\n' s[2] = 'ass = []' + '\n' s[3] = 'ban = ' + updated_ban + '\n' f = open( bs.getEnvironment()['systemScriptsDirectory'] + "/getPermissionsHashes.py", 'w') for i in s: f.write(i) f.close() elif m == '/ass': clID = int(a[0]) for client in bsInternal._getGameRoster(): if client['clientID'] == clID: if a[1] == 'add': ass = client['displayString'] updated_ass = gph.ass.append(ass) elif a[1] == 'remove': ass = client['displayString'] if ass in gph.ass: updated_ass = gph.ass.remove(ass) with open(bs.getEnvironment()['systemScriptsDirectory'] + "/getPermissionsHashes.py") as file: s = [row for row in file] s[0] = 'vipHashes = []' + '\n' s[1] = 'admin= []' + '\n' s[2] = 'ass = ' + updated_admins + '\n' f = open( bs.getEnvironment()['systemScriptsDirectory'] + "/getPermissionsHashes.py", 'w') for i in s: f.write(i) f.close() elif m == '/vip': clID = int(a[0]) for client in bsInternal._getGameRoster(): if client['clientID'] == clID: if a[1] == 'add': vip = client['displayString'] updated_vip = gph.vip.append(vip) elif a[1] == 'remove': vip = client['displayString'] if vip in gph.vip: updated_vip = gph.vip.remove(vip) with open(bs.getEnvironment()['systemScriptsDirectory'] + "/getPermissionsHashes.py") as file: s = [row for row in file] s[0] = 'vip = ' + updated_admins + '\n' f = open( bs.getEnvironment()['systemScriptsDirectory'] + "/getPermissionsHashes.py", 'w') for i in s: f.write(i) f.close() elif m == '/list': bsInternal._chatMessage( "======== FOR /kick ONLY: ========") for i in bsInternal._getGameRoster(): try: bsInternal._chatMessage( i['players'][0]['nameFull'] + " (/kick " + str(i['clientID']) + ")") except: pass bsInternal._chatMessage( "==================================") bsInternal._chatMessage( "======= For other commands: =======") for s in bsInternal._getForegroundHostSession().players: bsInternal._chatMessage( s.getName() + " " + str(bsInternal._getForegroundHostSession( ).players.index(s))) elif m == '/ooh': if a is not None and len(a) > 0: s = int(a[0]) def oohRecurce(c): bs.playSound(bs.getSound('ooh'), volume=2) c -= 1 if c > 0: bs.gameTimer( int(a[1]) if len(a) > 1 and a[1] is not None else 1000, bs.Call(oohRecurce, c=c)) oohRecurce(c=s) else: bs.playSound(bs.getSound('ooh'), volume=2) elif m == '/playSound': if a is not None and len(a) > 1: s = int(a[1]) def oohRecurce(c): bs.playSound(bs.getSound(str(a[0])), volume=2) c -= 1 if c > 0: bs.gameTimer( int(a[2]) if len(a) > 2 and a[2] is not None else 1000, bs.Call(oohRecurce, c=c)) oohRecurce(c=s) else: bs.playSound(bs.getSound(str(a[0])), volume=2) elif m == '/quit': bsInternal.quit() elif m == '/nv': if self.tint is None: self.tint = bs.getSharedObject('globals').tint bs.getSharedObject('globals').tint = ( 0.5, 0.7, 1) if a == [] or not a[0] == u'off' else self.tint elif m == '/freeze': if a == []: bsInternal._chatMessage( 'Using: /freeze all or number of list') else: if a[0] == 'all': for i in bs.getSession().players: try: i.actor.node.handleMessage( bs.FreezeMessage()) except: pass else: bs.getSession().players[int( a[0])].actor.node.handleMessage( bs.FreezeMessage()) elif m == '/thaw': if a == []: bsInternal._chatMessage( 'Using: /thaw all or number of list') else: if a[0] == 'all': for i in bs.getSession().players: try: i.actor.node.handleMessage( bs.ThawMessage()) except: pass else: bs.getSession().players[int( a[0])].actor.node.handleMessage( bs.ThawMessage()) elif m == '/sleep': if a == []: bsInternal._chatMessage('Using: number of list') else: if a[0] == 'all': for i in bs.getSession().players: try: i.actor.node.handleMessage( "knockout", 5000) except: pass else: bs.getSession().players[int( a[0])].actor.node.handleMessage( "knockout", 5000) elif m == '/kill': if a == []: bsInternal._chatMessage( 'Using: /kill all or number of list') else: if a[0] == 'all': for i in bs.getSession().players: try: i.actor.node.handleMessage(bs.DieMessage()) except: pass else: bs.getSession().players[int( a[0])].actor.node.handleMessage( bs.DieMessage()) elif m == '/curse': if a == []: bsInternal._chatMessage( 'Using: /curse all or number of list') else: if a[0] == 'all': for i in bs.getSession().players: try: i.actor.curse() except: pass else: bs.getSession().players[int(a[0])].actor.curse() elif m == '/box': if a == []: bsInternal._chatMessage( 'Using: /box all or number of list') else: try: if a[0] == 'all': for i in bs.getSession().players: try: i.actor.node.torsoModel = bs.getModel( "tnt") except: print 'error' for i in bs.getSession().players: try: i.actor.node.colorMaskTexture = bs.getTexture( "tnt") except: print 'error' for i in bs.getSession().players: try: i.actor.node.colorTexture = bs.getTexture( "tnt") except: print 'error' for i in bs.getSession().players: try: i.actor.node.highlight = (1, 1, 1) except: print 'error' for i in bs.getSession().players: try: i.actor.node.color = (1, 1, 1) except: print 'error' for i in bs.getSession().players: try: i.actor.node.headModel = None except: print 'error' for i in bs.getSession().players: try: i.actor.node.style = "cyborg" except: print 'error' else: n = int(a[0]) bs.getSession().players[ n].actor.node.torsoModel = bs.getModel( "tnt") bs.getSession().players[ n].actor.node.colorMaskTexture = bs.getTexture( "tnt") bs.getSession().players[ n].actor.node.colorTexture = bs.getTexture( "tnt") bs.getSession( ).players[n].actor.node.highlight = (1, 1, 1) bs.getSession().players[n].actor.node.color = ( 1, 1, 1) bs.getSession( ).players[n].actor.node.headModel = None bs.getSession( ).players[n].actor.node.style = "cyborg" except: bs.screenMessage('Ошибка!', color=(1, 0, 0)) elif m == '/spaz': if a == []: bsInternal._chatMessage( 'Using: /spaz all or number of list') else: try: if a[0] == 'all': for i in bs.getSession().players: t = i.actor.node try: t.colorTexture = bs.getTexture(a[1] + "Color") t.colorMaskTexture = bs.getTexture( a[1] + "ColorMask") t.headModel = bs.getModel(a[1] + "Head") t.torsoModel = bs.getModel(a[1] + "Torso") t.pelvisModel = bs.getModel(a[1] + "Pelvis") t.upperArmModel = bs.getModel( a[1] + "UpperArm") t.foreArmModel = bs.getModel(a[1] + "ForeArm") t.handModel = bs.getModel(a[1] + "Hand") t.upperLegModel = bs.getModel( a[1] + "UpperLeg") t.lowerLegModel = bs.getModel( a[1] + "LowerLeg") t.toesModel = bs.getModel(a[1] + "Toes") t.style = a[1] except: print 'error' else: n = int(a[0]) t = bs.getSession().players[n].actor.node t.colorTexture = bs.getTexture(a[1] + "Color") t.colorMaskTexture = bs.getTexture(a[1] + "ColorMask") t.headModel = bs.getModel(a[1] + "Head") t.torsoModel = bs.getModel(a[1] + "Torso") t.pelvisModel = bs.getModel(a[1] + "Pelvis") t.upperArmModel = bs.getModel(a[1] + "UpperArm") t.foreArmModel = bs.getModel(a[1] + "ForeArm") t.handModel = bs.getModel(a[1] + "Hand") t.upperLegModel = bs.getModel(a[1] + "UpperLeg") t.lowerLegModel = bs.getModel(a[1] + "LowerLeg") t.toesModel = bs.getModel(a[1] + "Toes") t.style = a[1] except: bs.screenMessage('error', color=(1, 0, 0)) elif m == '/inv': if a == []: bsInternal._chatMessage( 'Using: /spaz all or number of list') else: try: if a[0] == 'all': for i in bs.getSession().players: t = i.actor.node try: t.headModel = None t.torsoModel = None t.pelvisModel = None t.upperArmModel = None t.foreArmModel = None t.handModel = None t.upperLegModel = None t.lowerLegModel = None t.toesModel = None t.style = "cyborg" except: print 'error' else: n = int(a[0]) t = bs.getSession().players[n].actor.node t.headModel = None t.torsoModel = None t.pelvisModel = None t.upperArmModel = None t.foreArmModel = None t.handModel = None t.upperLegModel = None t.lowerLegModel = None t.toesModel = None t.style = "cyborg" except: bs.screenMessage('error', color=(1, 0, 0)) elif m == '/tex': if a == []: bsInternal._chatMessage( 'Using: /tex all or number of list') else: try: if a[0] == 'all': for i in bs.getSession().players: try: i.actor.node.colorMaskTexture = bs.getTexture( "egg1") except: print 'error' for i in bs.getSession().players: try: i.actor.node.colorTexture = bs.getTexture( "egg1") except: print 'error' else: n = int(a[0]) bs.getSession().players[ n].actor.node.colorMaskTexture = bs.getTexture( "egg1") bs.getSession().players[ n].actor.node.colorTexture = bs.getTexture( "egg1") except: bs.screenMessage('Ошибка!', color=(1, 0, 0)) elif m == '/remove': if a == []: bsInternal._chatMessage( 'Using: /remove all or number of list') else: if a[0] == 'all': for i in bs.getSession().players: try: i.removeFromGame() except: pass else: bs.getSession().players[int(a[0])].removeFromGame() elif m == '/end': try: bsInternal._getForegroundHostActivity().endGame() except: pass elif m == '/hug': if a == []: bsInternal._chatMessage( 'Using: /hug all or number of list') else: try: if a[0] == 'all': try: bsInternal._getForegroundHostActivity( ).players[ 0].actor.node.holdNode = bsInternal._getForegroundHostActivity( ).players[1].actor.node except: pass try: bsInternal._getForegroundHostActivity( ).players[ 1].actor.node.holdNode = bsInternal._getForegroundHostActivity( ).players[0].actor.node except: pass try: bsInternal._getForegroundHostActivity( ).players[ 3].actor.node.holdNode = bsInternal._getForegroundHostActivity( ).players[2].actor.node except: pass try: bsInternal._getForegroundHostActivity( ).players[ 4].actor.node.holdNode = bsInternal._getForegroundHostActivity( ).players[3].actor.node except: pass try: bsInternal._getForegroundHostActivity( ).players[ 5].actor.node.holdNode = bsInternal._getForegroundHostActivity( ).players[6].actor.node except: pass try: bsInternal._getForegroundHostActivity( ).players[ 6].actor.node.holdNode = bsInternal._getForegroundHostActivity( ).players[7].actor.node except: pass else: bsInternal._getForegroundHostActivity( ).players[int( a[0] )].actor.node.holdNode = bsInternal._getForegroundHostActivity( ).players[int(a[1])].actor.node except: bs.screenMessage('Ошибка!', color=(1, 0, 0)) elif m == '/gm': if a == []: for i in range(len(activity.players)): if activity.players[i].getName().encode( 'utf-8').find( nick.encode('utf-8').replace( '...', '').replace(':', '')) != -1: activity.players[ i].actor.node.hockey = activity.players[ i].actor.node.hockey == False activity.players[ i].actor.node.invincible = activity.players[ i].actor.node.invincible == False activity.players[ i].actor._punchPowerScale = 5 if activity.players[ i].actor._punchPowerScale == 1.2 else 1.2 else: activity.players[int( a[0])].actor.node.hockey = activity.players[int( a[0])].actor.node.hockey == False activity.players[int( a[0])].actor.node.invincible = activity.players[ int(a[0])].actor.node.invincible == False activity.players[int( a[0] )].actor._punchPowerScale = 5 if activity.players[int( a[0])].actor._punchPowerScale == 1.2 else 1.2 elif m == '/tint': if a == []: bsInternal._chatMessage('Using: /tint R G B') bsInternal._chatMessage('OR') bsInternal._chatMessage('Using: /tint r bright speed') else: if a[0] == 'r': m = 1.3 if a[1] is None else float(a[1]) s = 1000 if a[2] is None else float(a[2]) bsUtils.animateArray( bs.getSharedObject('globals'), 'tint', 3, { 0: (1 * m, 0, 0), s: (0, 1 * m, 0), s * 2: (0, 0, 1 * m), s * 3: (1 * m, 0, 0) }, True) else: try: if a[1] is not None: bs.getSharedObject('globals').tint = ( float(a[0]), float(a[1]), float(a[2])) else: bs.screenMessage('Error!', color=(1, 0, 0)) except: bs.screenMessage('Error!', color=(1, 0, 0)) elif m == 'pause': bs.getSharedObject('globals').paused = bs.getSharedObject( 'globals').paused == False elif m == '/sm': bs.getSharedObject( 'globals').slowMotion = bs.getSharedObject( 'globals').slowMotion == False elif m == '/bunny': if a == []: bsInternal._chatMessage( 'Using: /bunny count owner(number of list)') import BuddyBunny for i in range(int(a[0])): p = bs.getSession().players[int(a[1])] if not 'bunnies' in p.gameData: p.gameData['bunnies'] = BuddyBunny.BunnyBotSet(p) p.gameData['bunnies'].doBunny() elif m == '/cameraMode': try: if bs.getSharedObject( 'globals').cameraMode == 'follow': bs.getSharedObject('globals').cameraMode = 'rotate' else: bs.getSharedObject('globals').cameraMode = 'follow' except: pass elif m == '/lm': arr = [] for i in range(100): try: arr.append(bsInternal._getChatMessages()[-1 - i]) except: pass arr.reverse() for i in arr: bsInternal._chatMessage(i) elif m == '/gp': if a == []: bsInternal._chatMessage('Using: /gp number of list') else: s = bsInternal._getForegroundHostSession() for i in s.players[int( a[0])].getInputDevice()._getPlayerProfiles(): try: bsInternal._chatMessage(i) except: pass elif m == '/icy': bsInternal._getForegroundHostActivity().players[int( a[0] )].actor.node = bsInternal._getForegroundHostActivity( ).players[int(a[1])].actor.node elif m == '/fly': if a == []: bsInternal._chatMessage( 'Using: /fly all or number of list') else: if a[0] == 'all': for i in bsInternal._getForegroundHostActivity( ).players: i.actor.node.fly = True else: bsInternal._getForegroundHostActivity( ).players[int( a[0] )].actor.node.fly = bsInternal._getForegroundHostActivity( ).players[int(a[0])].actor.node.fly == False elif m == '/floorReflection': bs.getSharedObject( 'globals').floorReflection = bs.getSharedObject( 'globals').floorReflection == False elif m == '/ac': if a == []: bsInternal._chatMessage('Using: /ac R G B') bsInternal._chatMessage('OR') bsInternal._chatMessage('Using: /ac r bright speed') else: if a[0] == 'r': m = 1.3 if a[1] is None else float(a[1]) s = 1000 if a[2] is None else float(a[2]) bsUtils.animateArray( bs.getSharedObject('globals'), 'ambientColor', 3, { 0: (1 * m, 0, 0), s: (0, 1 * m, 0), s * 2: (0, 0, 1 * m), s * 3: (1 * m, 0, 0) }, True) else: try: if a[1] is not None: bs.getSharedObject( 'globals').ambientColor = (float(a[0]), float(a[1]), float(a[2])) else: bs.screenMessage('Error!', color=(1, 0, 0)) except: bs.screenMessage('Error!', color=(1, 0, 0)) elif m == '/iceOff': try: activity.getMap().node.materials = [ bs.getSharedObject('footingMaterial') ] activity.getMap().isHockey = False except: pass try: activity.getMap().floor.materials = [ bs.getSharedObject('footingMaterial') ] activity.getMap().isHockey = False except: pass for i in activity.players: i.actor.node.hockey = False elif m == '/maxPlayers': if a == []: bsInternal._chatMessage( 'Using: /maxPlayers count of players') else: try: bsInternal._getForegroundHostSession( )._maxPlayers = int(a[0]) bsInternal._setPublicPartyMaxSize(int(a[0])) bsInternal._chatMessage('Players limit set to ' + str(int(a[0]))) except: bs.screenMessage('Error!', color=(1, 0, 0)) elif m == '/heal': if a == []: bsInternal._chatMessage( 'Using: /heal all or number of list') else: try: bsInternal._getForegroundHostActivity().players[ int(a[0])].actor.node.handleMessage( bs.PowerupMessage(powerupType='health')) except: bs.screenMessage('Error!', color=(1, 0, 0)) elif m == '/reflections': if a == [] or len(a) < 2: bsInternal._chatMessage( 'Using: /reflections type(1/0) scale') rs = [int(a[1])] type = 'soft' if int(a[0]) == 0 else 'powerup' try: bsInternal._getForegroundHostActivity().getMap( ).node.reflection = type bsInternal._getForegroundHostActivity().getMap( ).node.reflectionScale = rs except: pass try: bsInternal._getForegroundHostActivity().getMap( ).bg.reflection = type bsInternal._getForegroundHostActivity().getMap( ).bg.reflectionScale = rs except: pass try: bsInternal._getForegroundHostActivity().getMap( ).floor.reflection = type bsInternal._getForegroundHostActivity().getMap( ).floor.reflectionScale = rs except: pass try: bsInternal._getForegroundHostActivity().getMap( ).center.reflection = type bsInternal._getForegroundHostActivity().getMap( ).center.reflectionScale = rs except: pass elif m == '/shatter': if a == []: bsInternal._chatMessage( 'Using: /shatter all or number of list') else: if a[0] == 'all': for i in bsInternal._getForegroundHostActivity( ).players: i.actor.node.shattered = int(a[1]) else: bsInternal._getForegroundHostActivity().players[ int(a[0])].actor.node.shattered = int(a[1]) elif m == '/cm': if a == []: time = 8000 else: time = int(a[0]) op = 0.08 std = bs.getSharedObject('globals').vignetteOuter bsUtils.animateArray( bs.getSharedObject('globals'), 'vignetteOuter', 3, { 0: bs.getSharedObject('globals').vignetteOuter, 17000: (0, 1, 0) }) try: bsInternal._getForegroundHostActivity().getMap( ).node.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).bg.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).bg.node.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).node1.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).node2.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).node3.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).steps.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).floor.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).center.opacity = op except: pass def off(): op = 1 try: bsInternal._getForegroundHostActivity().getMap( ).node.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).bg.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).bg.node.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).node1.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).node2.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).node3.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).steps.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).floor.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).center.opacity = op except: pass bsUtils.animateArray( bs.getSharedObject('globals'), 'vignetteOuter', 3, { 0: bs.getSharedObject('globals').vignetteOuter, 100: std }) bs.gameTimer(time, bs.Call(off)) elif m == 'help': bsInternal._chatMessage( bs.Lstr(resource='help1').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help2').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help3').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help4').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help5').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help6').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help7').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help8').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help9').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help10').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help11').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help12').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help13').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help14').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help15').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help16').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help17').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help18').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help19').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help20').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help21').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help22').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help23').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help24').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help25').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help26').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help27').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help28').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help29').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help30').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help31').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help32').evaluate())
def onFinalize(self): bs.TeamGameActivity.onFinalize(self) with bs.Context(self): self._vsText = None # kill our 'vs' if its there if self.settings['Preserve queue through games']: self._savePlayerPositionsForLaterUse()