-
Notifications
You must be signed in to change notification settings - Fork 33
/
floater.py
298 lines (255 loc) · 9.57 KB
/
floater.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
298
# Ported by your friend: Freaku
# Join BCS:
# https://discord.gg/ucyaesh
# My GitHub:
# https://github.com/Freaku17/BombSquad-Mods-byFreaku
# ba_meta require api 8
from __future__ import annotations
from typing import TYPE_CHECKING
import _babase
import babase
import random
import math
import bauiv1 as bui
import bascenev1 as bs
from bascenev1lib.gameutils import SharedObjects
from bascenev1lib.actor.bomb import Bomb
from bascenev1lib.actor.popuptext import PopupText
from bauiv1lib.party import PartyWindow
import bauiv1lib.mainmenu
if TYPE_CHECKING:
from typing import Optional
class Floater(bs.Actor):
def __init__(self, bounds):
super().__init__()
shared = SharedObjects.get()
self.controlled = False
self.source_player = None
self.floaterMaterial = bs.Material()
self.floaterMaterial.add_actions(
conditions=('they_have_material',
shared.player_material),
actions=(('modify_node_collision', 'collide', True),
('modify_part_collision', 'physical', True)))
self.floaterMaterial.add_actions(
conditions=(('they_have_material',
shared.object_material), 'or',
('they_have_material',
shared.footing_material), 'or',
('they_have_material',
self.floaterMaterial)),
actions=('modify_part_collision', 'physical', False))
self.pos = bounds
self.px = "random.uniform(self.pos[0],self.pos[3])"
self.py = "random.uniform(self.pos[1],self.pos[4])"
self.pz = "random.uniform(self.pos[2],self.pos[5])"
self.node = bs.newnode(
'prop',
delegate=self,
owner=None,
attrs={
'position': (eval(self.px), eval(self.py), eval(self.pz)),
'mesh':
bs.getmesh('landMine'),
'light_mesh':
bs.getmesh('landMine'),
'body':
'landMine',
'body_scale':
3,
'mesh_scale':
3.1,
'shadow_size':
0.25,
'density':
999999,
'gravity_scale':
0.0,
'color_texture':
bs.gettexture('achievementFlawlessVictory'),
'reflection':
'soft',
'reflection_scale': [0.25],
'materials':
[shared.footing_material, self.floaterMaterial]
})
self.node2 = bs.newnode(
'prop',
owner=self.node,
attrs={
'position': (0, 0, 0),
'body':
'sphere',
'mesh':
None,
'color_texture':
None,
'body_scale':
1.0,
'reflection':
'powerup',
'density':
999999,
'reflection_scale': [1.0],
'mesh_scale':
1.0,
'gravity_scale':
0,
'shadow_size':
0.1,
'is_area_of_interest':
True,
'materials':
[shared.object_material, self.floaterMaterial]
})
self.node.connectattr('position', self.node2, 'position')
def pop(self): PopupText(text="Ported by \ue048Freaku", scale=1.3, position=(
self.node.position[0], self.node.position[1]-1, self.node.position[2]), color=(0, 1, 1)).autoretain()
def checkCanControl(self):
if not self.node.exists():
return False
if not self.source_player.is_alive():
self.dis()
return False
return True
def con(self):
self.controlled = True
self.checkPlayerDie()
def up(self):
if not self.checkCanControl():
return
v = self.node.velocity
self.node.velocity = (v[0], 5, v[2])
def upR(self):
if not self.checkCanControl():
return
v = self.node.velocity
self.node.velocity = (v[0], 0, v[2])
def down(self):
if not self.checkCanControl():
return
v = self.node.velocity
self.node.velocity = (v[0], -5, v[2])
def downR(self):
if not self.checkCanControl():
return
v = self.node.velocity
self.node.velocity = (v[0], 0, v[2])
def leftright(self, value):
if not self.checkCanControl():
return
v = self.node.velocity
self.node.velocity = (5 * value, v[1], v[2])
def updown(self, value):
if not self.checkCanControl():
return
v = self.node.velocity
self.node.velocity = (v[0], v[1], -5 * value)
def dis(self):
if self.node.exists():
self.controlled = False
self.node.velocity = (0, 0, 0)
self.move()
def checkPlayerDie(self):
if not self.controlled:
return
if self.source_player is None:
return
if self.source_player.is_alive():
bs.timer(1, self.checkPlayerDie)
return
else:
self.dis()
def distance(self, x1, y1, z1, x2, y2, z2):
d = math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2) + math.pow(z2 - z1, 2))
return d
def drop(self):
try:
np = self.node.position
except:
np = (0, 0, 0)
self.b = Bomb(bomb_type=random.choice(['normal', 'ice', 'sticky', 'impact', 'land_mine', 'tnt']),
source_player=self.source_player, position=(np[0], np[1] - 1, np[2]), velocity=(0, -1, 0)).autoretain()
if self.b.bomb_type in ['impact', 'land_mine']:
self.b.arm()
def move(self):
px = eval(self.px)
py = eval(self.py)
pz = eval(self.pz)
if self.node.exists() and not self.controlled:
pn = self.node.position
dist = self.distance(pn[0], pn[1], pn[2], px, py, pz)
self.node.velocity = ((px - pn[0]) / dist, (py - pn[1]) / dist, (pz - pn[2]) / dist)
bs.timer(dist-1, bs.WeakCall(self.move)) # suppress_format_warning=True)
def handlemessage(self, msg):
if isinstance(msg, bs.DieMessage):
self.node.delete()
self.node2.delete()
self.controlled = False
elif isinstance(msg, bs.OutOfBoundsMessage):
self.handlemessage(bs.DieMessage())
else:
super().handlemessage(msg)
def assignFloInputs(clientID: int):
activity = bs.get_foreground_host_activity()
with activity.context:
if not hasattr(activity, 'flo') or not activity.flo.node.exists():
try:
activity.flo = Floater(activity.map.get_def_bound_box('map_bounds'))
except:
return # Perhaps using in main-menu/score-screen
floater = activity.flo
if floater.controlled:
bs.broadcastmessage('Floater is already being controlled',
color=(1, 0, 0), transient=True, clients=[clientID])
return
bs.broadcastmessage('You Gained Control Over The Floater!\n Press Bomb to Throw Bombs and Punch to leave!', clients=[
clientID], transient=True, color=(0, 1, 1))
for i in activity.players:
if i.sessionplayer.inputdevice.client_id == clientID:
def dis(i, floater):
i.actor.node.invincible = False
i.resetinput()
i.actor.connect_controls_to_player()
floater.dis()
ps = i.actor.node.position
i.actor.node.invincible = True
floater.node.position = (ps[0], ps[1] + 1.0, ps[2])
bs.timer(1, floater.pop)
i.actor.node.hold_node = bs.Node(None)
i.actor.node.hold_node = floater.node2
i.actor.connect_controls_to_player()
i.actor.disconnect_controls_from_player()
i.resetinput()
floater.source_player = i
floater.con()
i.assigninput(babase.InputType.PICK_UP_PRESS, floater.up)
i.assigninput(babase.InputType.PICK_UP_RELEASE, floater.upR)
i.assigninput(babase.InputType.JUMP_PRESS, floater.down)
i.assigninput(babase.InputType.BOMB_PRESS, floater.drop)
i.assigninput(babase.InputType.PUNCH_PRESS, babase.Call(dis, i, floater))
i.assigninput(babase.InputType.UP_DOWN, floater.updown)
i.assigninput(babase.InputType.LEFT_RIGHT, floater.leftright)
old_piv = bui.set_party_icon_always_visible
def new_piv(*args, **kwargs):
# Do not let chat icon go away
old_piv(True)
bui.set_party_icon_always_visible = new_piv
old_fcm = bs.chatmessage
def new_chat_message(*args, **kwargs):
old_fcm(*args, **kwargs)
if args[0] == '/floater':
try:
assignFloInputs(-1)
except:
pass
bs.chatmessage = new_chat_message
class NewMainMenuWindow(bauiv1lib.mainmenu.MainMenuWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Display chat icon, but if user open/close gather it may disappear
bui.set_party_icon_always_visible(True)
# ba_meta export plugin
class byFreaku(babase.Plugin):
def on_app_running(self):
bauiv1lib.mainmenu.MainMenuWindow = NewMainMenuWindow