From d80d8bfe5c9bae422990df0df78e6098f379b27d Mon Sep 17 00:00:00 2001 From: VinMannie <30628849+VinMannie@users.noreply.github.com> Date: Sun, 10 Feb 2019 14:07:18 -0500 Subject: [PATCH] Add files via upload --- mods/TossEm.py | 128 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 mods/TossEm.py diff --git a/mods/TossEm.py b/mods/TossEm.py new file mode 100644 index 0000000..9b0e4b4 --- /dev/null +++ b/mods/TossEm.py @@ -0,0 +1,128 @@ +import bs + +def bsGetAPIVersion(): + return 4 + +def bsGetGames(): + return [DeathMatchGame] + +class DeathMatchGame(bs.TeamGameActivity): + + @classmethod + def getName(cls): + return 'Toss`em' + + @classmethod + def getDescription(cls,sessionType): + return ('Show your chucking power!\n' + 'Toss people off the map for points.\n' + 'First to a set number wins!') + + @classmethod + def supportsSessionType(cls,sessionType): + return True if (issubclass(sessionType,bs.TeamsSession) + or issubclass(sessionType,bs.FreeForAllSession)) else False + + @classmethod + def getSupportedMaps(cls,sessionType): + return bs.getMapsSupportingPlayType("melee") + + @classmethod + def getSettings(cls,sessionType): + return [("KOs to Win Per Player",{'minValue':1,'default':5,'increment':1}), + ("Time Limit",{'choices':[('None',0),('1 Minute',60), + ('2 Minutes',120),('5 Minutes',300), + ('10 Minutes',600),('20 Minutes',1200)],'default':0}), + ("Respawn Times",{'choices':[('Shorter',0.25),('Short',0.5),('Normal',1.0),('Long',2.0),('Longer',4.0)],'default':1.0}), + ("Epic Mode",{'default':False})] + + + def __init__(self,settings): + bs.TeamGameActivity.__init__(self,settings) + if self.settings['Epic Mode']: self._isSlowMotion = True + + # print messages when players die since it matters here.. + self.announcePlayerDeaths = True + + self._scoreBoard = bs.ScoreBoard() + + def getInstanceDescription(self): + return ('Toss off ${ARG1} of your enemies.',self._scoreToWin) + + def getInstanceScoreBoardDescription(self): + return ('Toss off ${ARG1} enemies',self._scoreToWin) + + def onTransitionIn(self): + bs.TeamGameActivity.onTransitionIn(self, music='Epic' if self.settings['Epic Mode'] else 'GrandRomp') + + def onTeamJoin(self,team): + team.gameData['score'] = 0 + if self.hasBegun(): self._updateScoreBoard() + + def onBegin(self): + bs.TeamGameActivity.onBegin(self) + self.setupStandardTimeLimit(self.settings['Time Limit']) + if len(self.teams) > 0: + self._scoreToWin = self.settings['KOs to Win Per Player'] * max(1,max(len(t.players) for t in self.teams)) + else: self._scoreToWin = self.settings['KOs to Win Per Player'] + self._updateScoreBoard() + self._dingSound = bs.getSound('dingSmall') + + def spawnPlayer(self,player): + + spaz = self.spawnPlayerSpaz(player) + spaz.connectControlsToPlayer(enablePunch=False, + enableBomb=False, + enablePickUp=True) + + + def handleMessage(self,m): + + if isinstance(m,bs.PlayerSpazDeathMessage): + bs.TeamGameActivity.handleMessage(self,m) # augment standard behavior + + player = m.spaz.getPlayer() + self.respawnPlayer(player) + + killer = m.killerPlayer + if killer is None: return + + # handle team-kills + if killer.getTeam() is player.getTeam(): + + # in free-for-all, killing yourself loses you a point + if isinstance(self.getSession(),bs.FreeForAllSession): + player.getTeam().gameData['score'] = max(0,player.getTeam().gameData['score']-1) + + # in teams-mode it gives a point to the other team + else: + bs.playSound(self._dingSound) + for team in self.teams: + if team is not killer.getTeam(): + team.gameData['score'] += 1 + + # killing someone on another team nets a kill + else: + killer.getTeam().gameData['score'] += 1 + bs.playSound(self._dingSound) + # in FFA show our score since its hard to find on the scoreboard + try: killer.actor.setScoreText(str(killer.getTeam().gameData['score'])+'/'+str(self._scoreToWin),color=killer.getTeam().color,flash=True) + except Exception: pass + + self._updateScoreBoard() + + # if someone has won, set a timer to end shortly + # (allows the dust to clear and draws to occur if deaths are close enough) + if any(team.gameData['score'] >= self._scoreToWin for team in self.teams): + bs.gameTimer(500,self.endGame) + + else: bs.TeamGameActivity.handleMessage(self,m) + + def _updateScoreBoard(self): + for team in self.teams: + self._scoreBoard.setTeamValue(team,team.gameData['score'],self._scoreToWin) + + def endGame(self): + results = bs.TeamGameResults() + for t in self.teams: results.setTeamScore(t,t.gameData['score']) + self.end(results=results)