-
Notifications
You must be signed in to change notification settings - Fork 17
/
Events.cs
377 lines (367 loc) · 16.3 KB
/
Events.cs
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
using Microsoft.Xna.Framework;
using StardewValley;
using StardewValleyMP.Packets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using SFarmer = StardewValley.Farmer;
namespace StardewValleyMP
{
class Events
{
public static void fix()
{
Event @event = Game1.currentLocation.currentEvent;
Dictionary<string, string> data = (Dictionary<string, string>)Util.GetInstanceField(typeof(Event), @event, "festivalData");
fixCommands( @event );
if ( @event.FestivalName.Equals("Flower Dance"))
{
fixFlowerDance( @event, data );
}
}
public static void reset()
{
didFixDance = false;
prevCommandCount = prevCommand = -1;
}
public static int prevCommandCount = -1, prevCommand = -1;
private static void fixCommands( Event @event )
{
if ( @event.isFestival && prevCommandCount != @event.eventCommands.Count() && prevCommandCount != -1 )
{
// I'll worry about other festivals another time
if (@event.FestivalName.Equals("Flower Dance"))
Multiplayer.sendFunc(new ContinueEventPacket());
}
prevCommandCount = @event.eventCommands.Count();
if (prevCommand == @event.currentCommand)
return;
for (int i = prevCommand + 1; i <= @event.currentCommand; ++i)
{
string[] array = @event.eventCommands[Math.Min(@event.eventCommands.Count<string>() - 1, i)].Split(new char[]
{
' '
});
fixCommand(@event, array);
}
prevCommand = @event.currentCommand;
}
private static void fixCommand( Event @event, string[] array )
{
// We only want to do things the game would have done to farmers
// So stuff affecting the NPCs or anything else was removed
// More stuff from Event
Dictionary<string, Vector3> actorPositionsAfterMove = (Dictionary<string, Vector3>)Util.GetInstanceField(typeof(Event), @event, "actorPositionsAfterMove");
if (array[0].Equals("showFrame"))
{
if (array.Count<string>() > 2 && !array[2].Equals("flip") && !array[1].Contains("farmer"))
{
}
else
{
SFarmer farmer = getFarmerFromFarmerNumberString(array[1]);
//if (farmer == Game1.player) return;
if (array.Count<string>() == 2)
{
farmer = Game1.player;
}
if (farmer != null)
{
if (array.Count<string>() > 2)
{
array[1] = array[2];
}
List<FarmerSprite.AnimationFrame> list = new List<FarmerSprite.AnimationFrame>();
list.Add(new FarmerSprite.AnimationFrame(Convert.ToInt32(array[1]), 100, false, array.Count<string>() > 2, null, false));
farmer.FarmerSprite.setCurrentAnimation(list.ToArray());
farmer.FarmerSprite.loopThisAnimation = true;
farmer.FarmerSprite.PauseForSingleAnimation = true;
farmer.sprite.CurrentFrame = Convert.ToInt32(array[1]);
}
}
}
else if (array[0].Equals("animate"))
{
int milliseconds = Convert.ToInt32(array[4]);
bool flip = array[2].Equals("true");
bool flag2 = array[3].Equals("true");
List<FarmerSprite.AnimationFrame> list2 = new List<FarmerSprite.AnimationFrame>();
for (int n = 5; n < array.Count<string>(); n++)
{
list2.Add(new FarmerSprite.AnimationFrame(Convert.ToInt32(array[n]), milliseconds, false, flip, null, false));
}
if (array[1].Contains("farmer"))
{
SFarmer farmerFromFarmerNumberString6 = getFarmerFromFarmerNumberString(array[1]);
//if (farmerFromFarmerNumberString6 == Game1.player) return;
if (farmerFromFarmerNumberString6 != null)
{
farmerFromFarmerNumberString6.FarmerSprite.setCurrentAnimation(list2.ToArray());
farmerFromFarmerNumberString6.FarmerSprite.loopThisAnimation = flag2;
farmerFromFarmerNumberString6.FarmerSprite.PauseForSingleAnimation = true;
}
}
else
{
}
}
else if (array[0].Equals("stopAnimation"))
{
if (array[1].Contains("farmer"))
{
SFarmer farmerFromFarmerNumberString7 = getFarmerFromFarmerNumberString(array[1]);
//if (farmerFromFarmerNumberString7 == Game1.player) return;
if (farmerFromFarmerNumberString7 != null)
{
farmerFromFarmerNumberString7.completelyStopAnimatingOrDoingAction();
farmerFromFarmerNumberString7.Halt();
farmerFromFarmerNumberString7.FarmerSprite.currentAnimation = null;
int num12 = farmerFromFarmerNumberString7.facingDirection;
switch (num12)
{
case 0:
farmerFromFarmerNumberString7.FarmerSprite.setCurrentSingleFrame(12, 32000, false, false);
break;
case 1:
farmerFromFarmerNumberString7.FarmerSprite.setCurrentSingleFrame(6, 32000, false, false);
break;
case 2:
farmerFromFarmerNumberString7.FarmerSprite.setCurrentSingleFrame(0, 32000, false, false);
break;
case 3:
farmerFromFarmerNumberString7.FarmerSprite.setCurrentSingleFrame(6, 32000, false, true);
break;
}
}
}
else
{
}
}
else if (array[0].Equals("positionOffset"))
{
if (array[1].Contains("farmer"))
{
SFarmer farmerFromFarmerNumberString8 = getFarmerFromFarmerNumberString(array[1]);
//if (farmerFromFarmerNumberString8 == Game1.player) return;
if (farmerFromFarmerNumberString8 != null)
{
SFarmer expr_46E6_cp_0 = farmerFromFarmerNumberString8;
expr_46E6_cp_0.position.X = expr_46E6_cp_0.position.X + (float)Convert.ToInt32(array[2]);
SFarmer expr_4702_cp_0 = farmerFromFarmerNumberString8;
expr_4702_cp_0.position.Y = expr_4702_cp_0.position.Y + (float)Convert.ToInt32(array[3]);
}
}
else
{
}
}
else if (array[0].Equals("move"))
{
int num3 = 1;
while (num3 < array.Count<string>() && array.Count<string>() - num3 >= 3)
{
if (array[num3].Contains("farmer") && !actorPositionsAfterMove.ContainsKey(array[num3]))
{
SFarmer farmerFromFarmerNumberString2 = Utility.getFarmerFromFarmerNumberString(array[num3]);
//if (farmerFromFarmerNumberString2 == Game1.player) { num3 += 4; continue; }
if (farmerFromFarmerNumberString2 != null)
{
farmerFromFarmerNumberString2.canOnlyWalk = false;
farmerFromFarmerNumberString2.setRunning(false, true);
farmerFromFarmerNumberString2.canOnlyWalk = true;
farmerFromFarmerNumberString2.convertEventMotionCommandToMovement(new Vector2((float)Convert.ToInt32(array[num3 + 1]), (float)Convert.ToInt32(array[num3 + 2])));
actorPositionsAfterMove.Add(array[num3], @event.getPositionAfterMove(Game1.player, Convert.ToInt32(array[num3 + 1]), Convert.ToInt32(array[num3 + 2]), Convert.ToInt32(array[num3 + 3])));
}
}
else
{
}
num3 += 4;
}
if (array.Last<string>().Equals("true"))
{
}
if (!array.Last<string>().Equals("false"))
{
}
if (array.Count<string>() == 2 && actorPositionsAfterMove.Count == 0)
{
}
}
else if (array[0].Equals("emote"))
{
bool flag = array.Count<string>() > 3;
if (array[1].Contains("farmer"))
{
SFarmer farmerFromFarmerNumberString3 = getFarmerFromFarmerNumberString(array[1]);
//if (farmerFromFarmerNumberString3 == Game1.player) return;
if (farmerFromFarmerNumberString3 != null)
{
Game1.player.doEmote(Convert.ToInt32(array[2]), !flag);
}
}
else
{
}
}
else if (array[0].Equals("faceDirection"))
{
if (array[1].Contains("farmer"))
{
SFarmer farmerFromFarmerNumberString4 = getFarmerFromFarmerNumberString(array[1]);
//if (farmerFromFarmerNumberString4 == Game1.player) return;
if (farmerFromFarmerNumberString4 != null)
{
farmerFromFarmerNumberString4.FarmerSprite.StopAnimation();
farmerFromFarmerNumberString4.completelyStopAnimatingOrDoingAction();
farmerFromFarmerNumberString4.faceDirection(Convert.ToInt32(array[2]));
farmerFromFarmerNumberString4.FarmerSprite.StopAnimation();
}
}
else if (array[1].Contains("spouse"))
{
}
else
{
}
if (array.Length == 3 && Game1.pauseTime <= 0f)
{
}
if (array.Length > 3)
{
}
}
else if (array[0].Equals("warp"))
{
if (array[1].Contains("farmer"))
{
SFarmer farmerFromFarmerNumberString5 = getFarmerFromFarmerNumberString(array[1]);
//if (farmerFromFarmerNumberString5 == Game1.player) return;
if (farmerFromFarmerNumberString5 != null)
{
farmerFromFarmerNumberString5.position.X = (float)(Convert.ToInt32(array[2]) * Game1.tileSize);
farmerFromFarmerNumberString5.position.Y = (float)(Convert.ToInt32(array[3]) * Game1.tileSize);
if (Game1.IsClient)
{
farmerFromFarmerNumberString5.remotePosition = new Vector2(farmerFromFarmerNumberString5.position.X, farmerFromFarmerNumberString5.position.Y);
}
}
}
else if (array[1].Contains("spouse"))
{
}
else
{
}
if (array.Count<string>() > 4)
{
}
}
if (array[0].Equals("proceedPosition"))
{/*
try
{
if (!this.getCharacterByName(array[1]).isMoving() || (this.npcControllers != null && this.npcControllers.Count<NPCController>() == 0))
{
this.getCharacterByName(array[1]).Halt();
this.CurrentCommand++;
}
goto IL_4406;
}*/
// TODO: Fix this^ later
}
}
private static SFarmer getFarmerFromFarmerNumberString(string s)
{
if (s.Equals("farmer"))
{
return Multiplayer.getFarmer(0);
}
return Multiplayer.getFarmer((byte)(Convert.ToInt32(string.Concat(s[s.Count<char>() - 1])) - 1));
}
private static bool didFixDance = false;
private static void fixFlowerDance( Event dance, Dictionary<string, string> data )
{
if (dance.playerControlSequence || didFixDance)
return;
if (dance.eventCommands[0] != "pause 500")
return;
Log.trace("Flower dance beginning, fixing");
didFixDance = true;
// Copied from Event.setupFestivalMainEvent
// All I did was make it use our players
List<string> list = new List<string>();
List<string> list2 = new List<string>();
List<string> list3 = new List<string>
{
"Abigail",
"Penny",
"Leah",
"Maru",
"Haley"
};
List<string> list4 = new List<string>
{
"Sebastian",
"Sam",
"Elliott",
"Harvey",
"Alex"
};
for (int i = 0; i < Multiplayer.getFarmerCount(); i++)
{
SFarmer farmerFromFarmerNumber = Multiplayer.getFarmer( ( byte ) i );
if (farmerFromFarmerNumber.dancePartner != null)
{
if (farmerFromFarmerNumber.dancePartner.gender == 1)
{
list.Add(farmerFromFarmerNumber.dancePartner.name);
list3.Remove(farmerFromFarmerNumber.dancePartner.name);
list2.Add("farmer" + (i + 1));
}
else
{
list2.Add(farmerFromFarmerNumber.dancePartner.name);
list4.Remove(farmerFromFarmerNumber.dancePartner.name);
list.Add("farmer" + (i + 1));
}
}
}
while (list.Count<string>() < 5)
{
string text = list3.Last<string>();
if (list4.Contains(Utility.getLoveInterest(text)))
{
list.Add(text);
list2.Add(Utility.getLoveInterest(text));
}
list3.Remove(text);
}
string text2 = data["mainEvent"];
for (int j = 1; j <= 5; j++)
{
text2 = text2.Replace("Girl" + j, list[j - 1]);
text2 = text2.Replace("Guy" + j, list2[j - 1]);
}
Regex regex = new Regex("showFrame (?<farmerName>farmer\\d) 44");
Regex regex2 = new Regex("showFrame (?<farmerName>farmer\\d) 40");
Regex regex3 = new Regex("animate (?<farmerName>farmer\\d) false true 600 44 45");
Regex regex4 = new Regex("animate (?<farmerName>farmer\\d) false true 600 43 41 43 42");
Regex regex5 = new Regex("animate (?<farmerName>farmer\\d) false true 300 46 47");
Regex regex6 = new Regex("animate (?<farmerName>farmer\\d) false true 600 46 47");
text2 = regex.Replace(text2, "showFrame $1 12/faceDirection $1 0");
text2 = regex2.Replace(text2, "showFrame $1 0/faceDirection $1 2");
text2 = regex3.Replace(text2, "animate $1 false true 600 12 13 12 14");
text2 = regex4.Replace(text2, "animate $1 false true 596 4 0");
text2 = regex5.Replace(text2, "animate $1 false true 150 12 13 12 14");
text2 = regex6.Replace(text2, "animate $1 false true 600 0 3");
string[] array = text2.Split(new char[]
{
'/'
});
dance.eventCommands = array;
}
}
}