-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPlague.py
196 lines (175 loc) · 7.76 KB
/
Plague.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
#Plague
import bs
import bsUtils
def bsGetAPIVersion():
return 4
def bsGetGames():
return [Plague]
class PlagueMessage(object):
pass
class _BombDiedMessage(object):
pass
class PlagueSpazDeathMessage(object):
pass
class PlagueBomb(bs.Bomb):
def __init__(self,position=(0,1,0),velocity=(0,0,0),bombType='plague',blastRadius=2.0,sourcePlayer=None,owner=None):
bs.Actor.__init__(self)
factory = self.getFactory()
self.bombType = 'plague'
self._exploded = False
self.blastRadius = self.getActivity().settings["Blast Size"]
self._explodeCallbacks = []
self.sourcePlayer = sourcePlayer
self.hitType = 'explosion'
self.hitSubType = 'plague'
if owner is None: owner = bs.Node(None)
self.owner = owner
fuseTime = 6000
sticky = False
model = factory.bombModel
rType = 'sharper'
rScale = 1.8
materials = (factory.bombMaterial, bs.getSharedObject('objectMaterial'))
self.node = bs.newNode('bomb',
delegate=self,
attrs={'position':position,
'velocity':velocity,
'model':model,
'shadowSize':0.3,
'colorTexture':bs.getTexture("powerupCurse"),
'sticky':sticky,
'owner':owner,
'reflection':rType,
'reflectionScale':[rScale],
'materials':materials})
self.node.addDeathAction(bs.WeakCall(self.handleMessage,_BombDiedMessage()))
sound = bs.newNode('sound',owner=self.node,attrs={'sound':factory.fuseSound,'volume':0.25})
self.node.connectAttr('position',sound,'position')
bsUtils.animate(self.node,'fuseLength',{0:1,fuseTime:0})
bs.gameTimer(fuseTime,bs.Call(self.handleMessage, PlagueMessage()))
def handleMessage(self, m):
if isinstance(m, PlagueMessage): self.explode()
elif isinstance(m, _BombDiedMessage): self.sourcePlayer.actor.bombCount += 1
else: bs.Bomb.handleMessage(self, m)
def explode(self):
if self._exploded: return
self._exploded = True
activity = self.getActivity()
if activity is not None and self.node.exists():
blast = bs.Blast(position=self.node.position,velocity=self.node.velocity,
blastRadius=self.blastRadius,blastType=self.bombType,sourcePlayer=self.sourcePlayer,hitType=self.hitType,hitSubType=self.hitSubType).autoRetain()
for c in self._explodeCallbacks: c(self,blast)
bs.gameTimer(1,bs.WeakCall(self.handleMessage,bs.DieMessage()))
class PlagueSpaz(bs.PlayerSpaz):
def __init__(self, color=(1,1,1), highlight=(0.5,0.5,0.5), character="Spaz", sourcePlayer=None, startInvincible=True,
canAcceptPowerups=True, powerupsExpire=False, demoMode=False):
self._player = sourcePlayer
bs.Spaz.__init__(self, color, highlight, character, sourcePlayer, startInvincible, canAcceptPowerups, powerupsExpire, demoMode)
def handleMessage(self, m):
if isinstance(m, bs.HitMessage):
if m.hitSubType == 'plague': self.curse()
else: bs.Spaz.handleMessage(self,m)
else: bs.Spaz.handleMessage(self,m)
def dropBomb(self):
if (self.landMineCount <= 0 and self.bombCount <= 0) or self.frozen: return
p = self.node.positionForward
v = self.node.velocity
droppingBomb = True
bombType = self.bombType
bomb = PlagueBomb(position=(p[0],p[1] - 0.0,p[2]),
velocity=(v[0],v[1],v[2]),
bombType='plague',
blastRadius=self.blastRadius,
sourcePlayer=self.sourcePlayer,
owner=self.node).autoRetain()
if droppingBomb:
self.bombCount -= 1
bomb.node.addDeathAction(bs.WeakCall(self.handleMessage,_BombDiedMessage()))
self._pickUp(bomb.node)
for c in self._droppedBombCallbacks: c(self,bomb)
return bomb
class Plague(bs.TeamGameActivity):
@classmethod
def getName(cls):
return "Plague"
@classmethod
def getDescription(cls, sessionType):
return "Dodge the bombs, survive the plague!"
@classmethod
def getScoreInfo(cls):
return{'scoreType':'points'}
@classmethod
def getSettings(cls, sessionType):
return [("Epic Mode", {'default': False}),
("Enable Running", {'default': False}),
("Enable Jumping", {'default': False}),
("Enable Picking Up", {'default': False}),
("Blast Size", {
'choices': [
('1', 1),
('2', 2),
('3', 3),
('5', 5),
('10', 10)
],
'default': 2})]
@classmethod
def getSupportedMaps(cls, sessionType):
return bs.getMapsSupportingPlayType('melee')
@classmethod
def supportsSessionType(cls, sessionType):
return True if issubclass(sessionType, bs.FreeForAllSession) or issubclass(sessionType, bs.TeamsSession) else False
def __init__(self,settings):
bs.TeamGameActivity.__init__(self,settings)
if self.settings['Epic Mode']: self._isSlowMotion = True
def onTransitionIn(self):
bs.TeamGameActivity.onTransitionIn(self,music='ToTheDeath')
def onBegin(self):
bs.TeamGameActivity.onBegin(self)
for team in self.teams:
team.gameData['score'] = 0
for player in self.players:
player.gameData['score'] = 0
self.checkEnd()
def spawnPlayerSpaz(self,player,position=(0,5,-3),angle=None):
s = self.settings
name = player.getName()
color = player.color
highlight = player.highlight
players = self.players
spaz = PlagueSpaz(color=color,
highlight=highlight,
character=player.character,
sourcePlayer=player)
spaz.connectControlsToPlayer(enablePunch=False, enablePickUp = s["Enable Picking Up"], enableRun = s["Enable Running"], enableJump = s["Enable Jumping"])
player.setActor(spaz)
spaz.node.addDeathAction(bs.WeakCall(self.handleMessage,PlagueSpazDeathMessage()))
spaz.handleMessage(bs.StandMessage(self.getMap().getFFAStartPosition(self.players),90))
def handleMessage(self, m):
if isinstance(m, PlagueSpazDeathMessage): self.checkEnd()
else: bs.TeamGameActivity.handleMessage(self,m)
def checkEnd(self):
if isinstance(self.getSession(), bs.FreeForAllSession):
i = 0
for team in self.teams:
if team.players[0].isAlive():
team.gameData['score'] += 1
i += 1
if i <= 1:
self.endGame()
if isinstance(self.getSession(), bs.TeamsSession):
for team in self.teams:
i=0
team.gameData['score'] = 1
for player in team.players:
if player.isAlive():
team.gameData['score'] += 1
i += 1
if i == 0: team.gameData['score'] = 0
for team in self.teams:
if team.gameData['score'] == 0: self.endGame()
def endGame(self):
results = bs.TeamGameResults()
for team in self.teams:
results.setTeamScore(team, team.gameData['score'])
self.end(results=results)