forked from bombsquad-community/plugin-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisco_light.py
232 lines (189 loc) · 7.79 KB
/
disco_light.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
"""Disco Light Mod: V2.1
Made by Cross Joy"""
# If anyone who wanna help me on giving suggestion/ fix bugs/ creating PR,
# Can visit my github https://github.com/CrossJoy/Bombsquad-Modding
# You can contact me through discord:
# My Discord Id: Cross Joy#0721
# My BS Discord Server: https://discord.gg/JyBY6haARJ
# ----------------------------------------------------------------------------
# Add disco light into the game, so you can
# play with your friends under the colorful light. :)
# type '/disco' in your chat box to activate or
# type '/disco off' to deactivate the disco light.
# Coop and multiplayer compatible.
# Work on any 1.7.20+ ver.
# Note:
# The plugin commands only works on the host with the plugin activated.
# Other clients/players can't use the commands.
# v2.1
# - Enhance compatibility with other mods
# - Tint change when /disco off will be more dynamic.
# ----------------------------------------------------------------------------
# ba_meta require api 8
from __future__ import annotations
from typing import TYPE_CHECKING
import bascenev1 as bs
import babase
import bauiv1 as bui
from bascenev1 import _gameutils
import random
from bascenev1 import animate
if TYPE_CHECKING:
from typing import Sequence, Union
class DiscoLight:
def __init__(self):
activity = bs.get_foreground_host_activity()
self.globalnodes = activity.globalsnode.tint
# Activate disco light.
def start(self):
activity = bs.get_foreground_host_activity()
with activity.context:
self.partyLight(True)
self.rainbow(activity)
# Deactivate disco light.
def stop(self):
activity = bs.get_foreground_host_activity()
with activity.context:
self.partyLight(False)
self.stop_rainbow(activity)
# Create and animate colorful spotlight.
def partyLight(self, switch=True):
from bascenev1._nodeactor import NodeActor
x_spread = 10
y_spread = 5
positions = [[-x_spread, -y_spread], [0, -y_spread], [0, y_spread],
[x_spread, -y_spread], [x_spread, y_spread],
[-x_spread, y_spread]]
times = [0, 2700, 1000, 1800, 500, 1400]
# Store this on the current activity, so we only have one at a time.
activity = bs.getactivity()
activity.camera_flash_data = [] # type: ignore
for i in range(6):
r = random.choice([0.5, 1])
g = random.choice([0.5, 1])
b = random.choice([0.5, 1])
light = NodeActor(
bs.newnode('light',
attrs={
'position': (
positions[i][0], 0, positions[i][1]),
'radius': 1.0,
'lights_volumes': False,
'height_attenuated': False,
'color': (r, g, b)
}))
sval = 1.87
iscale = 1.3
tcombine = bs.newnode('combine',
owner=light.node,
attrs={
'size': 3,
'input0': positions[i][0],
'input1': 0,
'input2': positions[i][1]
})
assert light.node
tcombine.connectattr('output', light.node, 'position')
xval = positions[i][0]
yval = positions[i][1]
spd = 1.0 + random.random()
spd2 = 1.0 + random.random()
animate(tcombine,
'input0', {
0.0: xval + 0,
0.069 * spd: xval + 10.0,
0.143 * spd: xval - 10.0,
0.201 * spd: xval + 0
},
loop=True)
animate(tcombine,
'input2', {
0.0: yval + 0,
0.15 * spd2: yval + 10.0,
0.287 * spd2: yval - 10.0,
0.398 * spd2: yval + 0
},
loop=True)
animate(light.node,
'intensity', {
0.0: 0,
0.02 * sval: 0,
0.05 * sval: 0.8 * iscale,
0.08 * sval: 0,
0.1 * sval: 0
},
loop=True,
offset=times[i])
if not switch:
bs.timer(0.1,
light.node.delete)
activity.camera_flash_data.append(light) # type: ignore
# Create RGB tint.
def rainbow(self, activity) -> None:
"""Create RGB tint."""
cnode = bs.newnode('combine',
attrs={
'input0': self.globalnodes[0],
'input1': self.globalnodes[1],
'input2': self.globalnodes[2],
'size': 3
})
_gameutils.animate(cnode, 'input0',
{0.0: 1.0, 1.0: 1.0, 2.0: 1.0, 3.0: 1.0,
4.0: 0.2, 5.0: 0.1, 6.0: 0.5,
7.0: 1.0}, loop=True)
_gameutils.animate(cnode, 'input1',
{0.0: 0.2, 1.0: 0.2, 2.0: 0.5, 3.0: 1.0,
4.0: 1.0, 5.0: 0.1, 6.0: 0.3,
7.0: 0.2}, loop=True)
_gameutils.animate(cnode, 'input2',
{0.0: 0.2, 1.0: 0.2, 2.0: 0.0, 3.0: 0.0,
4.0: 0.2, 5.0: 1.0, 6.0: 1.0,
7.0: 0.2}, loop=True)
cnode.connectattr('output', activity.globalsnode, 'tint')
# Revert to the original map tint.
def stop_rainbow(self, activity):
"""Revert to the original map tint."""
c_existing = activity.globalsnode.tint
# map_name = activity.map.getname()
tint = self.globalnodes
cnode = bs.newnode('combine',
attrs={
'input0': c_existing[0],
'input1': c_existing[1],
'input2': c_existing[2],
'size': 3
})
_gameutils.animate(cnode, 'input0', {0: c_existing[0], 1.0: tint[0]})
_gameutils.animate(cnode, 'input1', {0: c_existing[1], 1.0: tint[1]})
_gameutils.animate(cnode, 'input2', {0: c_existing[2], 1.0: tint[2]})
cnode.connectattr('output', activity.globalsnode, 'tint')
# New chat func to add some commands to activate/deactivate the disco light.
def new_chat_message(func):
def wrapper(*args, **kwargs):
func(*args, **kwargs)
activity = bs.get_foreground_host_activity()
with activity.context:
try:
if not activity.disco_light:
activity.disco_light = DiscoLight()
except:
activity.disco_light = DiscoLight()
if args[0] == '/disco':
activity.disco_light.start()
elif args[0] == '/disco off':
activity.disco_light.stop()
return wrapper
def new_begin(func):
"""Runs when game is began."""
def wrapper(*args, **kwargs):
func(*args, **kwargs)
bui.set_party_icon_always_visible(True)
return wrapper
# ba_meta export plugin
class ByCrossJoy(babase.Plugin):
def __init__(self):
# Replace new chat func to the original game codes.
bs.chatmessage = new_chat_message(bs.chatmessage)
bs._activity.Activity.on_begin = new_begin(
bs._activity.Activity.on_begin)