-
Notifications
You must be signed in to change notification settings - Fork 0
/
bsChosenOnePro.py
297 lines (226 loc) · 9.82 KB
/
bsChosenOnePro.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# -*- coding: utf-8 -*-
#by wsdx233
#菜猪比赛专用~
import bs
import random
def bsGetAPIVersion():
# see bombsquadgame.com/apichanges
return 4
def bsGetGames():
return [ChosenOneGame]
class ChosenOneGame(bs.TeamGameActivity):
@classmethod
def getName(cls):
return '传递诅咒'
@classmethod
def getScoreInfo(cls):
return {'scoreName': 'Time Held'}
@classmethod
def getDescription(cls, sessionType):
return ('被选中将会倒计时走向死亡!.\n'
'攻击别人传递诅咒给他')
@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("keepAway")
@classmethod
def getSettings(cls, sessionType):
return [("Chosen One Time", {'minValue': 10, 'default': 30,
'increment': 10}),
("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
self._scoreBoard = bs.ScoreBoard()
self._chosenOnePlayer = None
self._swipSound = bs.getSound("swip")
self._countDownSounds = {10: bs.getSound('announceTen'),
9: bs.getSound('announceNine'),
8: bs.getSound('announceEight'),
7: bs.getSound('announceSeven'),
6: bs.getSound('announceSix'),
5: bs.getSound('announceFive'),
4: bs.getSound('announceFour'),
3: bs.getSound('announceThree'),
2: bs.getSound('announceTwo'),
1: bs.getSound('announceOne')}
def getInstanceDescription(self):
return '倒计时结束意味着永远的死亡!'
def onTransitionIn(self):
bs.TeamGameActivity.onTransitionIn(
self, music='Epic' if self.settings['Epic Mode'] else 'Chosen One')
def onTeamJoin(self, team):
if self.hasBegun():
return
team.gameData['timeRemaining'] = self.settings["Chosen One Time"]
self._updateScoreBoard()
def onPlayerJoin(self, player):
# don't allow joining after we start
# (would enable leave/rejoin tomfoolery)
if self.hasBegun():
bs.screenMessage(
bs.Lstr(
resource='playerDelayedJoinText',
subs=[('${PLAYER}', player.getName(full=True))]),
color=(0, 1, 0))
# for score purposes, mark them as having died right as the
# game started
return
player.gameData['die'] = False
bs.TeamGameActivity.onPlayerJoin(self, player)
#def onPlayerJoin(self,player):
def onPlayerLeave(self, player):
bs.TeamGameActivity.onPlayerLeave(self, player)
if self._getChosenOnePlayer() is player:
self._setChosenOnePlayer(None)
def onBegin(self):
# test...
if not all(player.exists() for player in self.players):
bs.printError(
"Nonexistant player in onBegin: " +
str([str(p) for p in self.players]) + ': we are ' + str(player))
bs.TeamGameActivity.onBegin(self)
self.setupStandardTimeLimit(self.settings['Time Limit'])
self.setupStandardPowerupDrops()
bs.gameTimer(1000, call=self._tick, repeat=True)
self._setChosenOnePlayer(None)
def _getChosenOnePlayer(self):
if self._chosenOnePlayer is not None and self._chosenOnePlayer.exists():
return self._chosenOnePlayer
else:
return None
def _handleResetCollide(self):
# if we have a chosen one ignore these
if self._getChosenOnePlayer() is not None:
return
try:
player = bs.getCollisionInfo(
"opposingNode").getDelegate().getPlayer()
except Exception:
return
if player is not None and player.isAlive():
self._setChosenOnePlayer(player)
def _tick(self):
# give the chosen one points
player = self._getChosenOnePlayer()
#bs.screenMessage('!')
if player is not None:
# this shouldnt happen, but just in case..
if not player.isAlive():
pass
#if False:
#bs.printError('got dead player as chosen one in _tick')
#self._setChosenOnePlayer(None)
else:
scoringTeam = player.getTeam()
self.scoreSet.playerScored(
player, 3, screenMessage=False, display=False)
scoringTeam.gameData['timeRemaining'] = max(
0, scoringTeam.gameData['timeRemaining']-1)
# show the count over their head
try:
if scoringTeam.gameData['timeRemaining'] > 0:
player.actor.setScoreText(
str(scoringTeam.gameData['timeRemaining']))
except Exception:
pass
self._updateScoreBoard()
# announce numbers we have sounds for
try:
bs.playSound(
self._countDownSounds
[scoringTeam.gameData['timeRemaining']])
except Exception:
pass
# winner
if scoringTeam.gameData['timeRemaining'] <= 0:
#self.endGame()
player.gameData['die'] = True
self.onPlayerLeave(player)
# player is None
else:
# this shouldnt happen, but just in case..
# (chosen-one player ceasing to exist should trigger onPlayerLeave
# which resets chosen-one)
if self._chosenOnePlayer is not None:
bs.printError('got nonexistant player as chosen one in _tick')
self._setChosenOnePlayer(None)
def endGame(self):
results = bs.TeamGameResults()
for team in self.teams:
results.setTeamScore(
team, team.gameData['timeRemaining'])
self.end(results=results, announceDelay=0)
def _setChosenOnePlayer(self, player):
try:
for p in self.players:
p.gameData['chosenLight'] = None
bs.playSound(self._swipSound)
if player == "die":
return
if player is None or not player.exists():
#self._flag = bs.Flag(color=(1, 0.9, 0.2),
# position=self._flagSpawnPos,
# touchable=False)
totalp = []
for team in self.teams :
for player in team.players :
if not player.gameData['die'] :
totalp.append(player)
#bs.screenMessage(str(totalp))
if len(totalp) <= 1 :
self.endGame()
return
self._setChosenOnePlayer(totalp[random.randint(0,len(totalp)-1)])
bs.screenMessage(totalp[random.randint(0,len(totalp)-1)])
else:
if player.actor is not None:
self._chosenOnePlayer = player
except Exception, e:
import traceback
print 'EXC in _setChosenOnePlayer'
traceback.print_exc(e)
traceback, print_stack()
bs.screenMessage(str('!'))
def handleMessage(self, m):
if isinstance(m, bs.PlayerSpazDeathMessage):
bs.TeamGameActivity.handleMessage(
self, m) # augment standard behavior
player = m.spaz.getPlayer()
killerPlayer = m.killerPlayer
if killerPlayer is self._getChosenOnePlayer():
self._setChosenOnePlayer(
"die" if (player is None or
killerPlayer is player)
else player)
if killerPlayer is player :
scoringTeam = player.getTeam()
scoringTeam.gameData['timeRemaining'] = max(
0, scoringTeam.gameData['timeRemaining']-5)
self._updateScoreBoard()
self.respawnPlayer(player)
else:
bs.TeamGameActivity.handleMessage(self, m)
def _updateScoreBoard(self):
for team in self.teams:
self._scoreBoard.setTeamValue(
team, team.gameData['timeRemaining'],
(self.settings['Chosen One Time']),
countdown=True)