-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomAttributesPlugin.cs
More file actions
301 lines (257 loc) · 9.96 KB
/
Copy pathRandomAttributesPlugin.cs
File metadata and controls
301 lines (257 loc) · 9.96 KB
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
299
300
301
using BepInEx;
using BoplFixedMath;
using HarmonyLib;
using System;
using UnityEngine;
namespace RandomAttributes
{
[BepInPlugin("com.dogoodogster.randomattributes", "Random Attributes", "1.1.0")]
public class RandomAttributesPlugin : BaseUnityPlugin
{
private Harmony harmony;
private static RandomAttributesPlugin instance;
public static Attributes[] attributes = new Attributes[4];
private void Awake()
{
instance = this;
harmony = new Harmony(Info.Metadata.GUID);
harmony.PatchAll(GetType());
var bob = new Cow("Bob", "oogashaka", "culting");
var joe = new Cow("Joe", "a communist", "voting for communist leaders");
var Sam = new Cow("Sam", "the prankster", "playing tricks on other cows"); // totally not made by chatGPT in any way whatsoever.
var Molly = new Cow("Molly", "the singer", "mooing melodiously"); // also totally not made by chatGPT in any way whatsoever.
var Kim = new Cow("Kim", "a communist", "being a communist leader"); // <-- fixed missing semicolon and comma
var Tim = new Cow("Tim", "a communist", "voting for communist leaders");
Logger.LogInfo(bob.Moo());
Logger.LogInfo(joe.Moo());
Logger.LogInfo(Sam.Moo());
Logger.LogInfo(Molly.Moo());
Logger.LogInfo(Kim.Moo());
Logger.LogInfo(Tim.Moo());
OnLevelStart += RandomizeThings;
var color = new FixColor((Fix)110 / (Fix)255, (Fix)55 / (Fix)255, (Fix)74 / (Fix)255);
color.ToHSV(out var h, out var s, out var v);
var newColor = FixColor.FromHSV(h, s, v);
Logger.LogInfo($"rgb({color.r * (Fix)255}, {color.g * (Fix)255}, {color.b * (Fix)255})");
Logger.LogInfo($"hsv({h* (Fix)360}, {s * (Fix)100}, {v * (Fix)100})");
Logger.LogInfo($"rgb({newColor.r * (Fix)255}, {newColor.g * (Fix)255}, {newColor.b * (Fix)255})");
}
public static event Action OnLevelStart;
[HarmonyPatch(typeof(GameSessionHandler), nameof(GameSessionHandler.Init))]
[HarmonyPostfix]
private static void GameStart()
{
OnLevelStart();
foreach (var player in PlayerHandler.Get().PlayerList())
{
player.Scale = attributes[player.Id - 1].scale;
}
}
[HarmonyPatch(typeof(PlayerPhysics), nameof(PlayerPhysics.UpdateSim))]
[HarmonyPrefix]
private static void PlayerPhysicsUpdate(PlayerPhysics __instance, ref IPlayerIdHolder ___playerIdHolder)
{
var slimecontroller = __instance.GetComponent<SlimeController>();
if (slimecontroller != null)
{
slimecontroller.GetPlayerSprite().material.SetColor("_ShadowColor", attributes[___playerIdHolder.GetPlayerId() - 1].color);
__instance.Speed = attributes[___playerIdHolder.GetPlayerId() - 1].speed;
__instance.jumpStrength = attributes[___playerIdHolder.GetPlayerId() - 1].jumpStrength;
// Set gravity using randomized value
__instance.gravity_modifier = attributes[___playerIdHolder.GetPlayerId() - 1].gravity;
__instance.gravity_accel = attributes[___playerIdHolder.GetPlayerId() - 1].gravity;
}
}
public static void RandomizeThings()
{
for (int i = 0; i < attributes.Length; i++)
{
attributes[i] = new Attributes()
{
scale = Updater.RandomFix((Fix)(-1), (Fix)3),
speed = Updater.RandomFix((Fix)1, (Fix)87.2),
jumpStrength = Updater.RandomFix((Fix)9.3, (Fix)109.8),
color = new FixColor(Updater.RandomFix((Fix)0, (Fix)1), Updater.RandomFix((Fix)0, (Fix)1), Updater.RandomFix((Fix)0, (Fix)1)),
gravity = Updater.RandomFix((Fix)5, (Fix)30) // <-- ensure gravity is randomized
};
}
}
}
public class Attributes
{
public Fix scale;
public Fix speed;
public Fix jumpStrength;
public FixColor color;
public Fix ability;
public Fix gravity;
public override string ToString()
{
return $"{GetType().Name} {{ scale={scale}, speed={speed}, jumpStrength={jumpStrength}, color={color} }}";
}
public Attributes Clone()
{
return new Attributes()
{
scale = scale,
speed = speed,
jumpStrength = jumpStrength,
color = color,
gravity = gravity
};
}
public void CopyFrom(Attributes other)
{
scale = other.scale;
speed = other.speed;
jumpStrength = other.jumpStrength;
color = other.color;
gravity = other.gravity;
}
}
public struct FixColor
{
public Fix r; public Fix g; public Fix b;
public FixColor(Fix r, Fix g, Fix b)
{
this.r = r;
this.g = g;
this.b = b;
}
public override string ToString()
{
return $"rgb({(int)(r * (Fix)255)}, {(int)(g * (Fix)255)}, {(int)(b * (Fix)255)})";
}
public void ToHSV(out Fix h, out Fix s, out Fix v)
{
// h, s, v = hue, saturation, value
Fix cmax = Fix.Max(r, Fix.Max(g, b)); // maximum of r, g, b
Fix cmin = Fix.Min(r, Fix.Min(g, b)); // minimum of r, g, b
Fix diff = cmax - cmin; // diff of cmax and cmin.
h = -Fix.One;
s = -Fix.One;
// if cmax and cmax are equal then h = 0
if (cmax == cmin)
h = (Fix)0;
// if cmax equal r then compute h
else if (cmax == r)
h = (Fix.One / (Fix)6 * ((g - b) / diff) + Fix.One) % Fix.One;
// if cmax equal g then compute h
else if (cmax == g)
h = (Fix.One / (Fix)6 * ((b - r) / diff) + Fix.One / (Fix)3) % Fix.One;
// if cmax equal b then compute h
else if (cmax == b)
h = (Fix.One / (Fix)6 * ((r - g) / diff) + (Fix)2 / (Fix)3) % Fix.One;
// if cmax equal zero
if (cmax == 0)
s = Fix.Zero;
else
s = diff / cmax;
// compute v
v = cmax;
}
public static FixColor FromHSV(Fix h, Fix s, Fix v)
{
Fix H = h;
while (H < 0) { H += Fix.One; };
while (H >= 1) { H -= Fix.One; };
Fix R, G, B;
if (v <= 0)
{ R = G = B = Fix.Zero; }
else if (s <= 0)
{
R = G = B = v;
}
else
{
Fix hf = H * (Fix)6;
int i = (int)Fix.Floor(hf);
Fix f = hf - (Fix)i;
Fix pv = v * (Fix.One - s);
Fix qv = v * (Fix.One - s * f);
Fix tv = v * (Fix.One - s * (Fix.One - f));
switch (i)
{
// Red is the dominant color
case 0:
R = v;
G = tv;
B = pv;
break;
// Green is the dominant color
case 1:
R = qv;
G = v;
B = pv;
break;
case 2:
R = pv;
G = v;
B = tv;
break;
// Blue is the dominant color
case 3:
R = pv;
G = qv;
B = v;
break;
case 4:
R = tv;
G = pv;
B = v;
break;
// Red is the dominant color
case 5:
R = v;
G = pv;
B = qv;
break;
// Just in case we overshoot on our math by a little, we put these here. Since its a switch it won't slow us down at all to put these here.
case 6:
R = v;
G = tv;
B = pv;
break;
case -1:
R = v;
G = pv;
B = qv;
break;
// The color is not defined, we should throw an error.
default:
//LFATAL("i Value error in Pixel conversion, Value is %d", i);
R = G = B = v; // Just pretend its black/white
break;
}
}
return new FixColor(Fix.Clamp01(R), Fix.Clamp01(G), Fix.Clamp01(B));
}
public Color ToColor()
{
return new Color((float)r, (float)g, (float)b);
}
public static implicit operator Color(FixColor fixColor) { return fixColor.ToColor(); }
}
public class Cow
{
public string name;
public string description;
public string purpose;
public string speciesName;
public Cow(string name, string description, string purpose)
{
speciesName = GetType().Name;
this.name = name;
this.description = description;
this.purpose = purpose;
}
public string Moo()
{
return $"Moo, I am a {speciesName}. my name is {name} and I am described as {description} and my purpose is {purpose}.";
}
}
}
public class propaganda
{
public string name;
}