-
Notifications
You must be signed in to change notification settings - Fork 63
/
GameLocation.cs
9568 lines (9362 loc) · 424 KB
/
GameLocation.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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Decompiled with JetBrains decompiler
// Type: StardewValley.GameLocation
// Assembly: Stardew Valley, Version=1.2.6400.27469, Culture=neutral, PublicKeyToken=null
// MVID: 77B7094A-F6F0-4ACC-91F4-E335E2733EDB
// Assembly location: D:\SteamLibrary\steamapps\common\Stardew Valley\Stardew Valley.exe
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using StardewValley.BellsAndWhistles;
using StardewValley.Characters;
using StardewValley.Events;
using StardewValley.Locations;
using StardewValley.Menus;
using StardewValley.Minigames;
using StardewValley.Monsters;
using StardewValley.Objects;
using StardewValley.Projectiles;
using StardewValley.TerrainFeatures;
using StardewValley.Tools;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using xTile;
using xTile.Dimensions;
using xTile.ObjectModel;
using xTile.Tiles;
namespace StardewValley
{
[XmlInclude(typeof (Farm))]
[XmlInclude(typeof (Beach))]
[XmlInclude(typeof (AnimalHouse))]
[XmlInclude(typeof (SlimeHutch))]
[XmlInclude(typeof (Shed))]
[XmlInclude(typeof (LibraryMuseum))]
[XmlInclude(typeof (AdventureGuild))]
[XmlInclude(typeof (Woods))]
[XmlInclude(typeof (Railroad))]
[XmlInclude(typeof (Summit))]
[XmlInclude(typeof (Forest))]
[XmlInclude(typeof (SeedShop))]
[XmlInclude(typeof (BathHousePool))]
[XmlInclude(typeof (FarmHouse))]
[XmlInclude(typeof (Club))]
[XmlInclude(typeof (BusStop))]
[XmlInclude(typeof (CommunityCenter))]
[XmlInclude(typeof (Desert))]
[XmlInclude(typeof (FarmCave))]
[XmlInclude(typeof (JojaMart))]
[XmlInclude(typeof (MineShaft))]
[XmlInclude(typeof (Mountain))]
[XmlInclude(typeof (Sewer))]
[XmlInclude(typeof (WizardHouse))]
[XmlInclude(typeof (Town))]
[XmlInclude(typeof (Cellar))]
public class GameLocation
{
private static readonly char[] ForwardSlash = new char[1]
{
'/'
};
public List<NPC> characters = new List<NPC>();
public SerializableDictionary<Vector2, Object> objects = new SerializableDictionary<Vector2, Object>();
[XmlIgnore]
public List<TemporaryAnimatedSprite> temporarySprites = new List<TemporaryAnimatedSprite>();
[XmlIgnore]
public List<Warp> warps = new List<Warp>();
[XmlIgnore]
public Dictionary<Point, string> doors = new Dictionary<Point, string>();
[XmlIgnore]
public List<Farmer> farmers = new List<Farmer>();
[XmlIgnore]
public List<Projectile> projectiles = new List<Projectile>();
public SerializableDictionary<Vector2, TerrainFeature> terrainFeatures = new SerializableDictionary<Vector2, TerrainFeature>();
public List<Debris> debris = new List<Debris>();
[XmlIgnore]
public Point fishSplashPoint = Point.Zero;
[XmlIgnore]
public Point orePanPoint = Point.Zero;
public Color waterColor = Color.White * 0.33f;
[XmlIgnore]
public Vector2 lastTouchActionLocation = Vector2.Zero;
private List<Vector2> terrainFeaturesToRemoveList = new List<Vector2>();
[XmlIgnore]
public List<Vector2> lightGlows = new List<Vector2>();
public const int minDailyWeeds = 5;
public const int maxDailyWeeds = 12;
public const int minDailyObjectSpawn = 1;
public const int maxDailyObjectSpawn = 4;
public const int maxSpawnedObjectsAtOnce = 6;
public const int maxTriesForDebrisPlacement = 3;
public const int maxTriesForObjectSpawn = 6;
public const double chanceForStumpOrBoulderRespawn = 0.2;
public const double chanceForClay = 0.03;
public const int forageDataIndex = 0;
public const int fishDataIndex = 4;
public const int diggablesDataIndex = 8;
private GameLocation.afterQuestionBehavior afterQuestion;
[XmlIgnore]
public Map map;
[XmlIgnore]
public Dictionary<Point, TemporaryAnimatedSprite> doorSprites;
public List<LargeTerrainFeature> largeTerrainFeatures;
protected List<Critter> critters;
[XmlIgnore]
public TemporaryAnimatedSprite fishSplashAnimation;
[XmlIgnore]
public TemporaryAnimatedSprite orePanAnimation;
[XmlIgnore]
public bool[,] waterTiles;
[XmlIgnore]
public string uniqueName;
public string name;
[XmlIgnore]
public string lastQuestionKey;
protected float lightLevel;
public bool isFarm;
public bool isOutdoors;
public bool isStructure;
public bool ignoreDebrisWeather;
public bool ignoreOutdoorLighting;
public bool ignoreLights;
public bool treatAsOutdoors;
protected bool wasUpdated;
public int numberOfSpawnedObjectsOnMap;
[XmlIgnore]
public Event currentEvent;
[XmlIgnore]
public Object actionObjectForQuestionDialogue;
[XmlIgnore]
public int waterAnimationIndex;
[XmlIgnore]
public int waterAnimationTimer;
[XmlIgnore]
public bool waterTileFlip;
[XmlIgnore]
public bool forceViewportPlayerFollow;
private float waterPosition;
private Vector2 snowPos;
private const int fireIDBase = 944468;
[XmlIgnore]
public float LightLevel
{
get
{
return this.lightLevel;
}
set
{
this.lightLevel = value;
}
}
[XmlIgnore]
public Map Map
{
get
{
return this.map;
}
set
{
this.map = value;
}
}
[XmlIgnore]
public SerializableDictionary<Vector2, Object> Objects
{
get
{
return this.objects;
}
}
[XmlIgnore]
public List<TemporaryAnimatedSprite> TemporarySprites
{
get
{
return this.temporarySprites;
}
}
public string Name
{
get
{
return this.name;
}
}
[XmlIgnore]
public bool IsFarm
{
get
{
return this.isFarm;
}
set
{
this.isFarm = value;
}
}
[XmlIgnore]
public bool IsOutdoors
{
get
{
return this.isOutdoors;
}
set
{
this.isOutdoors = value;
}
}
public GameLocation()
{
}
public GameLocation(Map map, string name)
{
this.map = map;
this.name = name;
if (name.Contains("Farm") || name.Contains("Coop") || (name.Contains("Barn") || name.Equals("SlimeHutch")))
this.isFarm = true;
this.loadObjects();
this.objects.CollectionChanged += new NotifyCollectionChangedEventHandler(this.objectCollectionChanged);
this.terrainFeatures.CollectionChanged += new NotifyCollectionChangedEventHandler(this.terrainFeaturesCollectionChanged);
if ((this.isOutdoors || this is Sewer) && !(this is Desert))
{
this.waterTiles = new bool[map.Layers[0].LayerWidth, map.Layers[0].LayerHeight];
bool flag = false;
for (int xTile = 0; xTile < map.Layers[0].LayerWidth; ++xTile)
{
for (int yTile = 0; yTile < map.Layers[0].LayerHeight; ++yTile)
{
if (this.doesTileHaveProperty(xTile, yTile, "Water", "Back") != null)
{
flag = true;
this.waterTiles[xTile, yTile] = true;
}
}
}
if (!flag)
this.waterTiles = (bool[,]) null;
}
if (!this.isOutdoors)
return;
this.critters = new List<Critter>();
}
public virtual bool canSlimeMateHere()
{
return true;
}
public virtual bool canSlimeHatchHere()
{
return true;
}
public void objectCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (!Game1.IsServer || Game1.server.connectionsCount <= 0)
return;
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
Vector2 newItem = (Vector2) e.NewItems[0];
MultiplayerUtility.broadcastObjectChange((short) newItem.X, (short) newItem.Y, (byte) 0, this.objects[newItem].bigCraftable ? (byte) 1 : (byte) 0, (int) (short) this.objects[newItem].ParentSheetIndex, this.name);
break;
case NotifyCollectionChangedAction.Remove:
Vector2 oldItem = (Vector2) e.OldItems[0];
MultiplayerUtility.broadcastObjectChange((short) oldItem.X, (short) oldItem.Y, (byte) 1, (byte) 0, -1, this.name);
break;
}
}
public void terrainFeaturesCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (!Game1.IsServer || Game1.server.connectionsCount <= 0)
return;
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
Vector2 newItem = (Vector2) e.NewItems[0];
TerrainFeatureDescription fromTerrainFeature = TerrainFeatureFactory.getIndexFromTerrainFeature(this.terrainFeatures[newItem]);
MultiplayerUtility.broadcastObjectChange((short) newItem.X, (short) newItem.Y, (byte) 2, fromTerrainFeature.index, fromTerrainFeature.extraInfo, this.name);
break;
case NotifyCollectionChangedAction.Remove:
Vector2 oldItem = (Vector2) e.OldItems[0];
MultiplayerUtility.broadcastObjectChange((short) oldItem.X, (short) oldItem.Y, (byte) 3, (byte) 0, -1, this.name);
break;
}
}
public void addCharacter(NPC character)
{
this.characters.Add(character);
}
public List<NPC> getCharacters()
{
return this.characters;
}
public Microsoft.Xna.Framework.Rectangle getSourceRectForObject(int tileIndex)
{
return new Microsoft.Xna.Framework.Rectangle(tileIndex * 16 % Game1.objectSpriteSheet.Width, tileIndex * 16 / Game1.objectSpriteSheet.Width * 16, 16, 16);
}
public Warp isCollidingWithWarp(Microsoft.Xna.Framework.Rectangle position)
{
foreach (Warp warp in this.warps)
{
if ((warp.X == (int) Math.Floor((double) position.Left / (double) Game1.tileSize) || warp.X == (int) Math.Floor((double) position.Right / (double) Game1.tileSize)) && (warp.Y == (int) Math.Floor((double) position.Top / (double) Game1.tileSize) || warp.Y == (int) Math.Floor((double) position.Bottom / (double) Game1.tileSize)))
return warp;
}
return (Warp) null;
}
public Warp isCollidingWithWarpOrDoor(Microsoft.Xna.Framework.Rectangle position)
{
return this.isCollidingWithWarp(position) ?? this.isCollidingWithDoors(position);
}
public Warp isCollidingWithDoors(Microsoft.Xna.Framework.Rectangle position)
{
for (int corner = 0; corner < 4; ++corner)
{
Vector2 cornersOfThisRectangle = Utility.getCornersOfThisRectangle(ref position, corner);
Point point = new Point((int) cornersOfThisRectangle.X / Game1.tileSize, (int) cornersOfThisRectangle.Y / Game1.tileSize);
foreach (KeyValuePair<Point, string> door in this.doors)
{
Point key = door.Key;
if (point.Equals(key))
return this.getWarpFromDoor(key);
}
}
return (Warp) null;
}
public Warp getWarpFromDoor(Point door)
{
string[] strArray = this.doesTileHaveProperty(door.X, door.Y, "Action", "Buildings").Split(' ');
if (strArray[0].Equals("WarpCommunityCenter"))
return new Warp(door.X, door.Y, "CommunityCenter", 32, 23, false);
return new Warp(door.X, door.Y, strArray[3], Convert.ToInt32(strArray[1]), Convert.ToInt32(strArray[2]), false);
}
public bool isFarmerCollidingWithAnyCharacter()
{
foreach (NPC character in this.characters)
{
if (character != null && Game1.player.GetBoundingBox().Intersects(character.GetBoundingBox()))
return true;
}
return false;
}
public bool isCollidingPosition(Microsoft.Xna.Framework.Rectangle position, xTile.Dimensions.Rectangle viewport, bool isFarmer)
{
return this.isCollidingPosition(position, viewport, isFarmer, 0, false, (Character) null, false, false, false);
}
public bool isCollidingPosition(Microsoft.Xna.Framework.Rectangle position, xTile.Dimensions.Rectangle viewport, Character character)
{
return this.isCollidingPosition(position, viewport, false, 0, false, character, false, false, false);
}
public bool isCollidingPosition(Microsoft.Xna.Framework.Rectangle position, xTile.Dimensions.Rectangle viewport, bool isFarmer, int damagesFarmer, bool glider)
{
return this.isCollidingPosition(position, viewport, isFarmer, damagesFarmer, glider, (Character) null, false, false, false);
}
public virtual bool isCollidingPosition(Microsoft.Xna.Framework.Rectangle position, xTile.Dimensions.Rectangle viewport, bool isFarmer, int damagesFarmer, bool glider, Character character)
{
return this.isCollidingPosition(position, viewport, isFarmer, damagesFarmer, glider, character, false, false, false);
}
public virtual bool isCollidingPosition(Microsoft.Xna.Framework.Rectangle position, xTile.Dimensions.Rectangle viewport, bool isFarmer, int damagesFarmer, bool glider, Character character, bool pathfinding, bool projectile = false, bool ignoreCharacterRequirement = false)
{
if (position.Right < 0 || position.X > this.map.Layers[0].DisplayWidth || (position.Bottom < 0 || position.Top > this.map.Layers[0].DisplayHeight))
return false;
Vector2 index1 = new Vector2((float) (position.Right / Game1.tileSize), (float) (position.Top / Game1.tileSize));
Vector2 index2 = new Vector2((float) (position.Left / Game1.tileSize), (float) (position.Top / Game1.tileSize));
Vector2 index3 = new Vector2((float) (position.Right / Game1.tileSize), (float) (position.Bottom / Game1.tileSize));
Vector2 index4 = new Vector2((float) (position.Left / Game1.tileSize), (float) (position.Bottom / Game1.tileSize));
bool flag = position.Width > Game1.tileSize;
Vector2 index5 = new Vector2((float) (position.Center.X / Game1.tileSize), (float) (position.Bottom / Game1.tileSize));
Vector2 index6 = new Vector2((float) (position.Center.X / Game1.tileSize), (float) (position.Top / Game1.tileSize));
if (character == null && !ignoreCharacterRequirement)
return true;
Microsoft.Xna.Framework.Rectangle boundingBox;
if (!glider && (!Game1.eventUp || character != null && character.GetType() != typeof (Character) && !isFarmer && (!pathfinding || !character.willDestroyObjectsUnderfoot)))
{
Object o;
this.objects.TryGetValue(index1, out o);
if (o != null && !o.IsHoeDirt && (!o.isPassable() && !Game1.player.temporaryImpassableTile.Intersects(o.getBoundingBox(index1))))
{
boundingBox = o.getBoundingBox(index1);
if (boundingBox.Intersects(position) && character != null && (character.GetType() != typeof (FarmAnimal) || !o.isAnimalProduct()) && character.collideWith(o))
return true;
}
this.objects.TryGetValue(index3, out o);
if (o != null && !o.IsHoeDirt && (!o.isPassable() && !Game1.player.temporaryImpassableTile.Intersects(o.getBoundingBox(index3))))
{
boundingBox = o.getBoundingBox(index3);
if (boundingBox.Intersects(position) && character != null && (character.GetType() != typeof (FarmAnimal) || !o.isAnimalProduct()) && character.collideWith(o))
return true;
}
this.objects.TryGetValue(index2, out o);
if (o != null && !o.IsHoeDirt && (!o.isPassable() && !Game1.player.temporaryImpassableTile.Intersects(o.getBoundingBox(index2))))
{
boundingBox = o.getBoundingBox(index2);
if (boundingBox.Intersects(position) && character != null && (character.GetType() != typeof (FarmAnimal) || !o.isAnimalProduct()) && character.collideWith(o))
return true;
}
this.objects.TryGetValue(index4, out o);
if (o != null && !o.IsHoeDirt && (!o.isPassable() && !Game1.player.temporaryImpassableTile.Intersects(o.getBoundingBox(index4))))
{
boundingBox = o.getBoundingBox(index4);
if (boundingBox.Intersects(position) && character != null && (character.GetType() != typeof (FarmAnimal) || !o.isAnimalProduct()) && character.collideWith(o))
return true;
}
if (flag)
{
this.objects.TryGetValue(index5, out o);
if (o != null && !o.IsHoeDirt && (!o.isPassable() && !Game1.player.temporaryImpassableTile.Intersects(o.getBoundingBox(index5))))
{
boundingBox = o.getBoundingBox(index5);
if (boundingBox.Intersects(position) && (character.GetType() != typeof (FarmAnimal) || !o.isAnimalProduct()) && character.collideWith(o))
return true;
}
this.objects.TryGetValue(index6, out o);
if (o != null && !o.IsHoeDirt && (!o.isPassable() && !Game1.player.temporaryImpassableTile.Intersects(o.getBoundingBox(index6))))
{
boundingBox = o.getBoundingBox(index6);
if (boundingBox.Intersects(position) && (character.GetType() != typeof (FarmAnimal) || !o.isAnimalProduct()) && character.collideWith(o))
return true;
}
}
}
if (this.largeTerrainFeatures != null && !glider)
{
foreach (LargeTerrainFeature largeTerrainFeature in this.largeTerrainFeatures)
{
boundingBox = largeTerrainFeature.getBoundingBox();
if (boundingBox.Intersects(position))
return true;
}
}
if (!Game1.eventUp && !glider)
{
if (this.terrainFeatures.ContainsKey(index1))
{
boundingBox = this.terrainFeatures[index1].getBoundingBox(index1);
if (boundingBox.Intersects(position))
{
if (!pathfinding)
this.terrainFeatures[index1].doCollisionAction(position, Game1.player.speed + Game1.player.addedSpeed, index1, character, this);
if (this.terrainFeatures.ContainsKey(index1) && !this.terrainFeatures[index1].isPassable(character))
return true;
}
}
if (this.terrainFeatures.ContainsKey(index2))
{
boundingBox = this.terrainFeatures[index2].getBoundingBox(index2);
if (boundingBox.Intersects(position))
{
if (!pathfinding)
this.terrainFeatures[index2].doCollisionAction(position, Game1.player.speed + Game1.player.addedSpeed, index2, character, this);
if (this.terrainFeatures.ContainsKey(index2) && !this.terrainFeatures[index2].isPassable(character))
return true;
}
}
if (this.terrainFeatures.ContainsKey(index3))
{
boundingBox = this.terrainFeatures[index3].getBoundingBox(index3);
if (boundingBox.Intersects(position))
{
if (!pathfinding)
this.terrainFeatures[index3].doCollisionAction(position, Game1.player.speed + Game1.player.addedSpeed, index3, character, this);
if (this.terrainFeatures.ContainsKey(index3) && !this.terrainFeatures[index3].isPassable(character))
return true;
}
}
if (this.terrainFeatures.ContainsKey(index4))
{
boundingBox = this.terrainFeatures[index4].getBoundingBox(index4);
if (boundingBox.Intersects(position))
{
if (!pathfinding)
this.terrainFeatures[index4].doCollisionAction(position, Game1.player.speed + Game1.player.addedSpeed, index4, character, this);
if (this.terrainFeatures.ContainsKey(index4) && !this.terrainFeatures[index4].isPassable(character))
return true;
}
}
if (flag)
{
if (this.terrainFeatures.ContainsKey(index5))
{
boundingBox = this.terrainFeatures[index5].getBoundingBox(index5);
if (boundingBox.Intersects(position))
{
if (!pathfinding)
this.terrainFeatures[index5].doCollisionAction(position, Game1.player.speed + Game1.player.addedSpeed, index5, character, this);
if (this.terrainFeatures.ContainsKey(index5) && !this.terrainFeatures[index5].isPassable((Character) null))
return true;
}
}
if (this.terrainFeatures.ContainsKey(index6))
{
boundingBox = this.terrainFeatures[index6].getBoundingBox(index6);
if (boundingBox.Intersects(position))
{
if (!pathfinding)
this.terrainFeatures[index6].doCollisionAction(position, Game1.player.speed + Game1.player.addedSpeed, index6, character, this);
if (this.terrainFeatures.ContainsKey(index6) && !this.terrainFeatures[index6].isPassable((Character) null))
return true;
}
}
}
}
if (character != null && character.hasSpecialCollisionRules() && (character.isColliding(this, index1) || character.isColliding(this, index2) || (character.isColliding(this, index3) || character.isColliding(this, index4))))
return true;
if (isFarmer || character != null && character.collidesWithOtherCharacters)
{
for (int index7 = this.characters.Count - 1; index7 >= 0; --index7)
{
if (this.characters[index7] != null && (character == null || !character.Equals((object) this.characters[index7])))
{
boundingBox = this.characters[index7].GetBoundingBox();
if (boundingBox.Intersects(position) && !Game1.player.temporarilyInvincible)
this.characters[index7].behaviorOnFarmerPushing();
if (isFarmer && !Game1.eventUp && !this.characters[index7].farmerPassesThrough)
{
boundingBox = this.characters[index7].GetBoundingBox();
if (boundingBox.Intersects(position) && !Game1.player.temporarilyInvincible && Game1.player.temporaryImpassableTile.Equals(Microsoft.Xna.Framework.Rectangle.Empty))
{
if (this.characters[index7].IsMonster)
{
if (!((Monster) this.characters[index7]).isGlider)
{
boundingBox = Game1.player.GetBoundingBox();
if (boundingBox.Intersects(this.characters[index7].GetBoundingBox()))
goto label_83;
}
else
goto label_83;
}
if (!this.characters[index7].isInvisible)
return true;
}
}
label_83:
if (!isFarmer)
{
boundingBox = this.characters[index7].GetBoundingBox();
if (boundingBox.Intersects(position))
return true;
}
}
}
}
if (isFarmer)
{
if (this.currentEvent != null && this.currentEvent.checkForCollision(position, character != null ? character as Farmer : Game1.player) || Game1.player.currentUpgrade != null && Game1.player.currentUpgrade.daysLeftTillUpgradeDone <= 3 && (this.name.Equals("Farm") && position.Intersects(new Microsoft.Xna.Framework.Rectangle((int) Game1.player.currentUpgrade.positionOfCarpenter.X, (int) Game1.player.currentUpgrade.positionOfCarpenter.Y + Game1.tileSize, Game1.tileSize, Game1.tileSize / 2))))
return true;
}
else
{
if (position.Intersects(Game1.player.GetBoundingBox()))
{
if (damagesFarmer > 0)
{
if (Game1.player.CurrentTool != null && Game1.player.CurrentTool is MeleeWeapon && (((MeleeWeapon) Game1.player.CurrentTool).isOnSpecial && ((MeleeWeapon) Game1.player.CurrentTool).type == 3))
{
Game1.farmerTakeDamage(damagesFarmer, false, character as Monster);
return true;
}
if (character != null)
character.collisionWithFarmerBehavior();
Game1.farmerTakeDamage(Math.Max(1, damagesFarmer + Game1.random.Next(-damagesFarmer / 4, damagesFarmer / 4)), false, character as Monster);
if (!glider && (character == null || !(character as Monster).passThroughCharacters()))
return true;
}
else if (!glider && (!pathfinding || !(character is Monster)))
return true;
}
if (damagesFarmer > 0 && !glider)
{
for (int index7 = 0; index7 < this.characters.Count; ++index7)
{
if (!this.characters[index7].Equals((object) character) && position.Intersects(this.characters[index7].GetBoundingBox()) && (!(character is GreenSlime) && !(character is DustSpirit)))
return true;
}
}
if ((this.isFarm || this.name.Equals("UndergroundMine")) && (character != null && !character.name.Contains("NPC")) && (!character.eventActor && !glider))
{
PropertyValue propertyValue = (PropertyValue) null;
Tile tile1 = this.map.GetLayer("Back").PickTile(new Location(position.Right, position.Top), viewport.Size);
if (tile1 != null)
tile1.Properties.TryGetValue("NPCBarrier", out propertyValue);
if (propertyValue != null)
return true;
Tile tile2 = this.map.GetLayer("Back").PickTile(new Location(position.Right, position.Bottom), viewport.Size);
if (tile2 != null)
tile2.Properties.TryGetValue("NPCBarrier", out propertyValue);
if (propertyValue != null)
return true;
Tile tile3 = this.map.GetLayer("Back").PickTile(new Location(position.Left, position.Top), viewport.Size);
if (tile3 != null)
tile3.Properties.TryGetValue("NPCBarrier", out propertyValue);
if (propertyValue != null)
return true;
Tile tile4 = this.map.GetLayer("Back").PickTile(new Location(position.Left, position.Bottom), viewport.Size);
if (tile4 != null)
tile4.Properties.TryGetValue("NPCBarrier", out propertyValue);
if (propertyValue != null)
return true;
}
if (glider && !projectile)
return false;
}
if (!isFarmer || !Game1.player.isRafting)
{
PropertyValue propertyValue = (PropertyValue) null;
Tile tile1 = this.map.GetLayer("Back").PickTile(new Location(position.Right, position.Top), viewport.Size);
if (tile1 != null)
tile1.TileIndexProperties.TryGetValue("Passable", out propertyValue);
if (propertyValue != null && (!isFarmer || !Game1.player.temporaryImpassableTile.Contains(position.Right, position.Top)))
return true;
Tile tile2 = this.map.GetLayer("Back").PickTile(new Location(position.Right, position.Bottom), viewport.Size);
if (tile2 != null)
tile2.TileIndexProperties.TryGetValue("Passable", out propertyValue);
if (propertyValue != null && (!isFarmer || !Game1.player.temporaryImpassableTile.Contains(position.Right, position.Bottom)))
return true;
Tile tile3 = this.map.GetLayer("Back").PickTile(new Location(position.Left, position.Top), viewport.Size);
if (tile3 != null)
tile3.TileIndexProperties.TryGetValue("Passable", out propertyValue);
if (propertyValue != null && (!isFarmer || !Game1.player.temporaryImpassableTile.Contains(position.Left, position.Top)))
return true;
Tile tile4 = this.map.GetLayer("Back").PickTile(new Location(position.Left, position.Bottom), viewport.Size);
if (tile4 != null)
tile4.TileIndexProperties.TryGetValue("Passable", out propertyValue);
if (propertyValue != null && (!isFarmer || !Game1.player.temporaryImpassableTile.Contains(position.Left, position.Bottom)))
return true;
if (flag)
{
Tile tile5 = this.map.GetLayer("Back").PickTile(new Location(position.Center.X, position.Bottom), viewport.Size);
if (tile5 != null)
tile5.TileIndexProperties.TryGetValue("Passable", out propertyValue);
if (propertyValue != null && (!isFarmer || !Game1.player.temporaryImpassableTile.Contains(position.Center.X, position.Bottom)))
return true;
Tile tile6 = this.map.GetLayer("Back").PickTile(new Location(position.Center.X, position.Top), viewport.Size);
if (tile6 != null)
tile6.TileIndexProperties.TryGetValue("Passable", out propertyValue);
if (propertyValue != null && (!isFarmer || !Game1.player.temporaryImpassableTile.Contains(position.Center.X, position.Top)))
return true;
}
Tile tile7 = this.map.GetLayer("Buildings").PickTile(new Location(position.Right, position.Top), viewport.Size);
if (tile7 != null)
{
tile7.TileIndexProperties.TryGetValue("Shadow", out propertyValue);
if (propertyValue == null)
tile7.TileIndexProperties.TryGetValue("Passable", out propertyValue);
if (propertyValue == null && !isFarmer)
tile7.TileIndexProperties.TryGetValue("NPCPassable", out propertyValue);
if (propertyValue == null && !isFarmer && (character != null && character.canPassThroughActionTiles()))
tile7.Properties.TryGetValue("Action", out propertyValue);
if ((propertyValue == null || propertyValue.ToString().Length == 0) && (!isFarmer || !Game1.player.temporaryImpassableTile.Contains(position.Right, position.Top)))
{
if (character == null)
return true;
return character.shouldCollideWithBuildingLayer(this);
}
}
Tile tile8 = this.map.GetLayer("Buildings").PickTile(new Location(position.Right, position.Bottom), viewport.Size);
if (tile8 != null && propertyValue == null | isFarmer)
{
tile8.TileIndexProperties.TryGetValue("Shadow", out propertyValue);
if (propertyValue == null)
tile8.TileIndexProperties.TryGetValue("Passable", out propertyValue);
if (propertyValue == null && !isFarmer)
tile8.TileIndexProperties.TryGetValue("NPCPassable", out propertyValue);
if (propertyValue == null && !isFarmer && (character != null && character.canPassThroughActionTiles()))
tile8.Properties.TryGetValue("Action", out propertyValue);
if ((propertyValue == null || propertyValue.ToString().Length == 0) && (!isFarmer || !Game1.player.temporaryImpassableTile.Contains(position.Right, position.Bottom)))
{
if (character == null)
return true;
return character.shouldCollideWithBuildingLayer(this);
}
}
Tile tile9 = this.map.GetLayer("Buildings").PickTile(new Location(position.Left, position.Top), viewport.Size);
if (tile9 != null && propertyValue == null | isFarmer)
{
tile9.TileIndexProperties.TryGetValue("Shadow", out propertyValue);
if (propertyValue == null)
tile9.TileIndexProperties.TryGetValue("Passable", out propertyValue);
if (propertyValue == null && !isFarmer)
tile9.TileIndexProperties.TryGetValue("NPCPassable", out propertyValue);
if (propertyValue == null && !isFarmer && (character != null && character.canPassThroughActionTiles()))
tile9.Properties.TryGetValue("Action", out propertyValue);
if ((propertyValue == null || propertyValue.ToString().Length == 0) && (!isFarmer || !Game1.player.temporaryImpassableTile.Contains(position.Left, position.Top)))
{
if (character == null)
return true;
return character.shouldCollideWithBuildingLayer(this);
}
}
Tile tile10 = this.map.GetLayer("Buildings").PickTile(new Location(position.Left, position.Bottom), viewport.Size);
if (tile10 != null && propertyValue == null | isFarmer)
{
tile10.TileIndexProperties.TryGetValue("Shadow", out propertyValue);
if (propertyValue == null)
tile10.TileIndexProperties.TryGetValue("Passable", out propertyValue);
if (propertyValue == null && !isFarmer)
tile10.TileIndexProperties.TryGetValue("NPCPassable", out propertyValue);
if (propertyValue == null && !isFarmer && (character != null && character.canPassThroughActionTiles()))
tile10.Properties.TryGetValue("Action", out propertyValue);
if ((propertyValue == null || propertyValue.ToString().Length == 0) && (!isFarmer || !Game1.player.temporaryImpassableTile.Contains(position.Left, position.Bottom)))
{
if (character == null)
return true;
return character.shouldCollideWithBuildingLayer(this);
}
}
if (flag)
{
Tile tile5 = this.map.GetLayer("Buildings").PickTile(new Location(position.Center.X, position.Top), viewport.Size);
if (tile5 != null && propertyValue == null | isFarmer)
{
tile5.TileIndexProperties.TryGetValue("Shadow", out propertyValue);
if (propertyValue == null)
tile5.TileIndexProperties.TryGetValue("Passable", out propertyValue);
if (propertyValue == null && !isFarmer)
tile5.TileIndexProperties.TryGetValue("NPCPassable", out propertyValue);
if (propertyValue == null && !isFarmer && (character != null && character.canPassThroughActionTiles()))
tile5.Properties.TryGetValue("Action", out propertyValue);
if ((propertyValue == null || propertyValue.ToString().Length == 0) && (!isFarmer || !Game1.player.temporaryImpassableTile.Contains(position.Center.X, position.Top)))
{
if (character == null)
return true;
return character.shouldCollideWithBuildingLayer(this);
}
}
Tile tile6 = this.map.GetLayer("Buildings").PickTile(new Location(position.Center.X, position.Bottom), viewport.Size);
if (tile6 != null && propertyValue == null | isFarmer)
{
tile6.TileIndexProperties.TryGetValue("Shadow", out propertyValue);
if (propertyValue == null)
tile6.TileIndexProperties.TryGetValue("Passable", out propertyValue);
if (propertyValue == null && !isFarmer)
tile6.TileIndexProperties.TryGetValue("NPCPassable", out propertyValue);
if (propertyValue == null && !isFarmer && (character != null && character.canPassThroughActionTiles()))
tile6.Properties.TryGetValue("Action", out propertyValue);
if ((propertyValue == null || propertyValue.ToString().Length == 0) && (!isFarmer || !Game1.player.temporaryImpassableTile.Contains(position.Center.X, position.Bottom)))
{
if (character == null)
return true;
return character.shouldCollideWithBuildingLayer(this);
}
}
}
if (!isFarmer && propertyValue != null)
{
if (propertyValue.ToString().Split(' ')[0] == "Door")
{
this.openDoor(new Location(position.Center.X / Game1.tileSize, position.Bottom / Game1.tileSize), false);
this.openDoor(new Location(position.Center.X / Game1.tileSize, position.Top / Game1.tileSize), Game1.currentLocation.Equals((object) this));
}
}
return false;
}
PropertyValue propertyValue1 = (PropertyValue) null;
Tile tile11 = this.map.GetLayer("Back").PickTile(new Location(position.Right, position.Top), viewport.Size);
if (tile11 != null)
tile11.TileIndexProperties.TryGetValue("Water", out propertyValue1);
if (propertyValue1 == null)
{
if (this.isTileLocationOpen(new Location(position.Right, position.Top)) && !this.isTileOccupiedForPlacement(new Vector2((float) (position.Right / Game1.tileSize), (float) (position.Top / Game1.tileSize)), (Object) null))
{
Game1.player.isRafting = false;
Game1.player.position = new Vector2((float) (position.Right / Game1.tileSize * Game1.tileSize), (float) (position.Top / Game1.tileSize * Game1.tileSize - Game1.tileSize / 2));
Game1.player.setTrajectory(0, 0);
}
return true;
}
Tile tile12 = this.map.GetLayer("Back").PickTile(new Location(position.Right, position.Bottom), viewport.Size);
if (tile12 != null)
tile12.TileIndexProperties.TryGetValue("Water", out propertyValue1);
if (propertyValue1 == null)
{
if (this.isTileLocationOpen(new Location(position.Right, position.Bottom)) && !this.isTileOccupiedForPlacement(new Vector2((float) (position.Right / Game1.tileSize), (float) (position.Bottom / Game1.tileSize)), (Object) null))
{
Game1.player.isRafting = false;
Game1.player.position = new Vector2((float) (position.Right / Game1.tileSize * Game1.tileSize), (float) (position.Bottom / Game1.tileSize * Game1.tileSize - Game1.tileSize / 2));
Game1.player.setTrajectory(0, 0);
}
return true;
}
Tile tile13 = this.map.GetLayer("Back").PickTile(new Location(position.Left, position.Top), viewport.Size);
if (tile13 != null)
tile13.TileIndexProperties.TryGetValue("Water", out propertyValue1);
if (propertyValue1 == null)
{
if (this.isTileLocationOpen(new Location(position.Left, position.Top)) && !this.isTileOccupiedForPlacement(new Vector2((float) (position.Left / Game1.tileSize), (float) (position.Top / Game1.tileSize)), (Object) null))
{
Game1.player.isRafting = false;
Game1.player.position = new Vector2((float) (position.Left / Game1.tileSize * Game1.tileSize), (float) (position.Top / Game1.tileSize * Game1.tileSize - Game1.tileSize / 2));
Game1.player.setTrajectory(0, 0);
}
return true;
}
Tile tile14 = this.map.GetLayer("Back").PickTile(new Location(position.Left, position.Bottom), viewport.Size);
if (tile14 != null)
tile14.TileIndexProperties.TryGetValue("Water", out propertyValue1);
if (propertyValue1 != null)
return false;
if (this.isTileLocationOpen(new Location(position.Left, position.Bottom)) && !this.isTileOccupiedForPlacement(new Vector2((float) (position.Left / Game1.tileSize), (float) (position.Bottom / Game1.tileSize)), (Object) null))
{
Game1.player.isRafting = false;
Game1.player.position = new Vector2((float) (position.Left / Game1.tileSize * Game1.tileSize), (float) (position.Bottom / Game1.tileSize * Game1.tileSize - Game1.tileSize / 2));
Game1.player.setTrajectory(0, 0);
}
return true;
}
public bool isTilePassable(Location tileLocation, xTile.Dimensions.Rectangle viewport)
{
PropertyValue propertyValue = (PropertyValue) null;
Tile tile1 = this.map.GetLayer("Back").PickTile(new Location(tileLocation.X * Game1.tileSize, tileLocation.Y * Game1.tileSize), viewport.Size);
if (tile1 != null)
tile1.TileIndexProperties.TryGetValue("Passable", out propertyValue);
Tile tile2 = this.map.GetLayer("Buildings").PickTile(new Location(tileLocation.X * Game1.tileSize, tileLocation.Y * Game1.tileSize), viewport.Size);
if (propertyValue == null && tile2 == null)
return tile1 != null;
return false;
}
public bool isPointPassable(Location location, xTile.Dimensions.Rectangle viewport)
{
PropertyValue propertyValue1 = (PropertyValue) null;
PropertyValue propertyValue2 = (PropertyValue) null;
Tile tile1 = this.map.GetLayer("Back").PickTile(new Location(location.X, location.Y), viewport.Size);
if (tile1 != null)
tile1.TileIndexProperties.TryGetValue("Passable", out propertyValue1);
Tile tile2 = this.map.GetLayer("Buildings").PickTile(new Location(location.X, location.Y), viewport.Size);
if (tile2 != null)
tile2.TileIndexProperties.TryGetValue("Shadow", out propertyValue2);
if (propertyValue1 != null)
return false;
if (tile2 != null)
return propertyValue2 != null;
return true;
}
public bool isTilePassable(Microsoft.Xna.Framework.Rectangle nextPosition, xTile.Dimensions.Rectangle viewport)
{
if (this.isPointPassable(new Location(nextPosition.Left, nextPosition.Top), viewport) && this.isPointPassable(new Location(nextPosition.Left, nextPosition.Bottom), viewport) && this.isPointPassable(new Location(nextPosition.Right, nextPosition.Top), viewport))
return this.isPointPassable(new Location(nextPosition.Right, nextPosition.Bottom), viewport);
return false;
}
public bool isTileOnMap(Vector2 position)
{
if ((double) position.X >= 0.0 && (double) position.X < (double) this.map.Layers[0].LayerWidth && (double) position.Y >= 0.0)
return (double) position.Y < (double) this.map.Layers[0].LayerHeight;
return false;
}
public bool isTileOnMap(int x, int y)
{
if (x >= 0 && x < this.map.Layers[0].LayerWidth && y >= 0)
return y < this.map.Layers[0].LayerHeight;
return false;
}
public void busLeave()
{
NPC npc = (NPC) null;
for (int index = this.characters.Count - 1; index >= 0; --index)
{
if (this.characters[index].name.Equals("Pam"))
{
npc = this.characters[index];
this.characters.RemoveAt(index);
break;
}
}
if (npc == null)
return;
Game1.changeMusicTrack("none");
Game1.playSound("openBox");
if (this.name.Equals("BusStop"))
{
Game1.warpFarmer("Desert", 32, 27, true);
npc.followSchedule = false;
npc.position = new Vector2((float) (31 * Game1.tileSize), (float) (28 * Game1.tileSize - Game1.tileSize / 2 - Game1.tileSize / 8));
npc.faceDirection(2);
npc.CurrentDialogue.Peek().temporaryDialogue = Game1.parseText(Game1.content.LoadString("Strings\\Locations:Desert_BusArrived"));
Game1.getLocationFromName("Desert").characters.Add(npc);
}
else
{
npc.CurrentDialogue.Peek().temporaryDialogue = (string) null;
Game1.warpFarmer("BusStop", 9, 9, true);
if (Game1.timeOfDay >= 2300)
{
npc.position = new Vector2((float) (18 * Game1.tileSize), (float) (7 * Game1.tileSize - Game1.tileSize / 2 - Game1.tileSize / 8));
npc.faceDirection(2);
Game1.getLocationFromName("Trailer").characters.Add(npc);
}
else if (Game1.timeOfDay >= 1700)
{
npc.position = new Vector2((float) (7 * Game1.tileSize), (float) (18 * Game1.tileSize - Game1.tileSize / 2 - Game1.tileSize / 8));
npc.faceDirection(1);
Game1.getLocationFromName("Saloon").characters.Add(npc);
}
else
{
npc.position = new Vector2((float) (8 * Game1.tileSize), (float) (10 * Game1.tileSize - Game1.tileSize / 2 - Game1.tileSize / 8));
npc.faceDirection(2);
Game1.getLocationFromName("BusStop").characters.Add(npc);
npc.sprite.CurrentFrame = 0;
}
npc.DirectionsToNewLocation = (SchedulePathDescription) null;
npc.followSchedule = true;
}
}
public int numberOfObjectsWithName(string name)
{
int num = 0;
foreach (Item obj in this.objects.Values)
{
if (obj.Name.Equals(name))
++num;
}
return num;
}
public Point getWarpPointTo(string location)
{
foreach (Warp warp in this.warps)
{
if (warp.TargetName.Equals(location))
return new Point(warp.X, warp.Y);
}
foreach (KeyValuePair<Point, string> door in this.doors)
{
if (door.Value.Equals(location))
return door.Key;
}
return Point.Zero;
}
public Point getWarpPointTarget(Point warpPointLocation)
{
foreach (Warp warp in this.warps)
{
if (warp.X == warpPointLocation.X && warp.Y == warpPointLocation.Y)
return new Point(warp.TargetX, warp.TargetY);
}
foreach (KeyValuePair<Point, string> door in this.doors)
{
if (door.Key.Equals(warpPointLocation))
{
string str = this.doesTileHaveProperty(warpPointLocation.X, warpPointLocation.Y, "Action", "Buildings");
if (str != null && str.Contains("Warp"))
{
string[] strArray = str.Split(' ');
if (strArray[0].Equals("WarpCommunityCenter"))
return new Point(32, 23);
return new Point(Convert.ToInt32(strArray[1]), Convert.ToInt32(strArray[2]));
}
}
}
return Point.Zero;
}
public void boardBus(Vector2 playerTileLocation)
{
if (!Game1.player.hasBusTicket && !this.name.Equals("Desert"))
return;
bool flag = false;
int num = this.characters.Count - 1;
while (num >= 0)
--num;