/
Map.cs
3220 lines (2592 loc) · 70.2 KB
/
Map.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
#region Map Updates
/*
* Name: Map Updates
* Date: 20th August, 2015
* Author: Vorspire
* Testing: Punkte
*
* Test Methods: Stealth; 250+ clients connected, all moving randomly.
* Test Results: 35ms average latency (ping) under load.
*
* Notes:
* Until these updates become main-stream, they will remain differentiated
* by their preprocessor directives. When they are deemed stable enough,
* old code can be removed, along with the directives.
*/
/*
* Map_AllUpdates
*
* When defined, enables all updates listed below regardless of whether their
* preprocessor directives are defined.
*
* This can be used to compile your server with all of the updates enabled by
* adding a single preprocessor directive definition to your build solution.
*/
//#define Map_AllUpdates
/*
* Map_NewEnumerables
*
* When defined, enables a major update to the IPooledEnumerables factory.
*
* This update removes the need for enumerator instantiation and replaces
* them with simple, yet powerful Linq queries.
*
* In addition, the PooledEnumerable class is replaced with a compatible,
* single generic class template and takes advantage of the nature of
* nested static context to ensure that a buffer pool is available for
* each type of PooledEnumerable<T> result, where result is T.
* This update generally increases performance and reduces overall player
* connection latency.
*/
#define Map_NewEnumerables
/*
* UseMaxRange
*
* When defined, enables a minor update that forces Get*InRange methods to
* use Core.GlobalMaxUpdateRange, when no range is specified.
*
* By default, a constant range of 18 is used however, Core.GlobalMaxUpdateRange
* is usually greater than that with a default value of 24.
*
* This update will allow things such as Effects to be displayed to more players,
* as well as increasing the range of player sight.
*
* The benefits of this update appeal to players who choose to increase the
* dimensions of their game window beyond the client's limits.
* (This can also be beneficial for shards that mainly target the Enhanced client)
*/
#define Map_UseMaxRange
/*
* Map_PoolFixColumn
*
* When defined, enables aminor update that attempts to improve the performance
* of Item stack fixing.
*
* Item stack fixing is a feature that corrects the Z level of items that
* are stacked on a single tile.
*
* This update also uses linq to increase performance.
*/
#define Map_PoolFixColumn
/*
* Map_InternalProtection
*
* When defined, enables a minor update that protects the Internal Map from
* potential name changes and ensures that Maps can be correctly parsed by
* ID or Name without conflicts.
*
* In some cases where the AllMaps list is modified after all Maps have been
* defined, the Map names may be cached and that cache will become stale.
* This update removes the caching and uses Linq to improve performance.
*
* If you have issues with Map parsing where the Map returns null or an
* unexpected Map instance, try enabling this update.
*
* If your shard implements any kind of feature that modifies (adds or removes)
* the AllMaps list, then you should enable this update.
* If this update is not enabled in the case of the above context, issues can
* be verified by having your system generate a new Map instance and modifying
* the AllMaps list, then using [Props on an Item or Mobile and selecting the
* Map property from the Gump; The list of names may not be what you expect,
* in which case, enabling this update will fix it.
*/
#define Map_InternalProtection
#endregion
#region References
#region References
using System;
using System.Collections;
using System.Collections.Generic;
using Server.Items;
using Server.Network;
using Server.Targeting;
#endregion
#if Map_NewEnumerables || Map_PoolFixColumn || Map_InternalProtection || Map_AllUpdates
using System.Linq;
#endif
#endregion
namespace Server
{
[Flags]
public enum MapRules
{
None = 0x0000,
Internal = 0x0001, // Internal map (used for dragging, commodity deeds, etc)
FreeMovement = 0x0002, // Anyone can move over anyone else without taking stamina loss
BeneficialRestrictions = 0x0004, // Disallow performing beneficial actions on criminals/murderers
HarmfulRestrictions = 0x0008, // Disallow performing harmful actions on innocents
TrammelRules = FreeMovement | BeneficialRestrictions | HarmfulRestrictions,
FeluccaRules = None
}
public interface IPooledEnumerable : IEnumerable
{
void Free();
}
public interface IPooledEnumerable<out T> : IPooledEnumerable, IEnumerable<T>
{ }
public interface IPooledEnumerator<out T> : IEnumerator<T>
{
void Free();
}
#if Map_NewEnumerables || Map_AllUpdates
public static class PooledEnumeration
{
public delegate IEnumerable<T> Selector<out T>(Sector sector, Rectangle2D bounds);
public static Selector<NetState> ClientSelector { get; set; }
public static Selector<IEntity> EntitySelector { get; set; }
public static Selector<Mobile> MobileSelector { get; set; }
public static Selector<Item> ItemSelector { get; set; }
public static Selector<BaseMulti> MultiSelector { get; set; }
public static Selector<StaticTile[]> MultiTileSelector { get; set; }
static PooledEnumeration()
{
ClientSelector = SelectClients;
EntitySelector = SelectEntities;
MobileSelector = SelectMobiles;
ItemSelector = SelectItems;
MultiSelector = SelectMultis;
MultiTileSelector = SelectMultiTiles;
}
public static IEnumerable<NetState> SelectClients(Sector s, Rectangle2D bounds)
{
return s.Clients.Where(o => o != null && o.Mobile != null && !o.Mobile.Deleted && bounds.Contains(o.Mobile));
}
public static IEnumerable<IEntity> SelectEntities(Sector s, Rectangle2D bounds)
{
return
Enumerable.Empty<IEntity>()
.Union(s.Mobiles.Where(o => o != null && !o.Deleted))
.Union(s.Items.Where(o => o != null && !o.Deleted && o.Parent == null))
.Where(bounds.Contains);
}
public static IEnumerable<Mobile> SelectMobiles(Sector s, Rectangle2D bounds)
{
return s.Mobiles.Where(o => o != null && !o.Deleted && bounds.Contains(o));
}
public static IEnumerable<Item> SelectItems(Sector s, Rectangle2D bounds)
{
return s.Items.Where(o => o != null && !o.Deleted && o.Parent == null && bounds.Contains(o));
}
public static IEnumerable<BaseMulti> SelectMultis(Sector s, Rectangle2D bounds)
{
return s.Multis.Where(o => o != null && !o.Deleted && bounds.Contains(o.Location));
}
public static IEnumerable<StaticTile[]> SelectMultiTiles(Sector s, Rectangle2D bounds)
{
foreach (var o in s.Multis.Where(o => o != null && !o.Deleted))
{
var c = o.Components;
int x, y, xo, yo;
StaticTile[] t, r;
for (x = bounds.Start.X; x < bounds.End.X; x++)
{
xo = x - (o.X + c.Min.X);
if (xo < 0 || xo >= c.Width)
{
continue;
}
for (y = bounds.Start.Y; y < bounds.End.Y; y++)
{
yo = y - (o.Y + c.Min.Y);
if (yo < 0 || yo >= c.Height)
{
continue;
}
t = c.Tiles[xo][yo];
if (t.Length <= 0)
{
continue;
}
r = new StaticTile[t.Length];
for (var i = 0; i < t.Length; i++)
{
r[i] = t[i];
r[i].Z += o.Z;
}
yield return r;
}
}
}
}
public static Map.PooledEnumerable<NetState> GetClients(Map map, Rectangle2D bounds)
{
return Map.PooledEnumerable<NetState>.Instantiate(map, bounds, ClientSelector ?? SelectClients);
}
public static Map.PooledEnumerable<IEntity> GetEntities(Map map, Rectangle2D bounds)
{
return Map.PooledEnumerable<IEntity>.Instantiate(map, bounds, EntitySelector ?? SelectEntities);
}
public static Map.PooledEnumerable<Mobile> GetMobiles(Map map, Rectangle2D bounds)
{
return Map.PooledEnumerable<Mobile>.Instantiate(map, bounds, MobileSelector ?? SelectMobiles);
}
public static Map.PooledEnumerable<Item> GetItems(Map map, Rectangle2D bounds)
{
return Map.PooledEnumerable<Item>.Instantiate(map, bounds, ItemSelector ?? SelectItems);
}
public static Map.PooledEnumerable<BaseMulti> GetMultis(Map map, Rectangle2D bounds)
{
return Map.PooledEnumerable<BaseMulti>.Instantiate(map, bounds, MultiSelector ?? SelectMultis);
}
public static Map.PooledEnumerable<StaticTile[]> GetMultiTiles(Map map, Rectangle2D bounds)
{
return Map.PooledEnumerable<StaticTile[]>.Instantiate(map, bounds, MultiTileSelector ?? SelectMultiTiles);
}
public static IEnumerable<Sector> EnumerateSectors(Map map, Rectangle2D bounds)
{
if (map == null || map == Map.Internal)
{
yield break;
}
int x1 = bounds.Start.X, y1 = bounds.Start.Y, x2 = bounds.End.X, y2 = bounds.End.Y;
if (!Bound(map, ref x1, ref y1, ref x2, ref y2, out var xSector, out var ySector))
{
yield break;
}
var index = 0;
while (NextSector(map, x1, y1, x2, y2, ref index, ref xSector, ref ySector, out var s))
{
yield return s;
}
}
public static bool Bound(Map map, ref int x1, ref int y1, ref int x2, ref int y2, out int xSector, out int ySector)
{
if (map == null || map == Map.Internal)
{
xSector = ySector = 0;
return false;
}
map.Bound(x1, y1, out x1, out y1);
map.Bound(x2 - 1, y2 - 1, out x2, out y2);
x1 >>= Map.SectorShift;
y1 >>= Map.SectorShift;
x2 >>= Map.SectorShift;
y2 >>= Map.SectorShift;
xSector = x1;
ySector = y1;
return true;
}
private static bool NextSector(
Map map,
int x1,
int y1,
int x2,
int y2,
ref int index,
ref int xSector,
ref int ySector,
out Sector s)
{
if (map == null)
{
s = null;
xSector = ySector = 0;
return false;
}
if (map == Map.Internal)
{
s = map.InvalidSector;
xSector = ySector = 0;
return false;
}
if (index++ > 0)
{
if (++ySector > y2)
{
ySector = y1;
if (++xSector > x2)
{
xSector = x1;
s = map.InvalidSector;
return false;
}
}
}
s = map.GetRealSector(xSector, ySector);
return true;
}
}
#endif
[Parsable]
//[CustomEnum( new string[]{ "Felucca", "Trammel", "Ilshenar", "Malas", "Internal" } )]
public class Map : IComparable, IComparable<Map>
{
#region Compile-Time -> Run-Time Support
#if Map_NewEnumerables || Map_AllUpdates
public static readonly bool NewEnumerables = true;
#else
public static readonly bool NewEnumerables = false;
#endif
#if Map_UseMaxRange || Map_AllUpdates
public static readonly bool UseMaxRange = true;
#else
public static readonly bool UseMaxRange = false;
#endif
#if Map_PoolFixColumn || Map_AllUpdates
public static readonly bool PoolFixColumn = true;
#else
public static readonly bool PoolFixColumn = false;
#endif
#if Map_InternalProtection || Map_AllUpdates
public static readonly bool InternalProtection = true;
#else
public static readonly bool InternalProtection = false;
#endif
#endregion
public const int SectorSize = 16;
public const int SectorShift = 4;
public static int SectorActiveRange = 2;
private static readonly Map[] m_Maps = new Map[0x100];
public static Map[] Maps => m_Maps;
public static Map Felucca => m_Maps[0];
public static Map Trammel => m_Maps[1];
public static Map Ilshenar => m_Maps[2];
public static Map Malas => m_Maps[3];
public static Map Tokuno => m_Maps[4];
public static Map TerMur => m_Maps[5];
public static Map Internal => m_Maps[0x7F];
private static readonly List<Map> m_AllMaps = new List<Map>();
public static List<Map> AllMaps => m_AllMaps;
private readonly int m_MapID;
private readonly int m_MapIndex;
private readonly int m_FileIndex;
private readonly int m_Width;
private readonly int m_Height;
private readonly int m_SectorsWidth;
private readonly int m_SectorsHeight;
private readonly Dictionary<string, Region> m_Regions;
private Region m_DefaultRegion;
public int Season { get; set; }
private readonly Sector[][] m_Sectors;
private readonly Sector m_InvalidSector;
private TileMatrix m_Tiles;
#if Map_InternalProtection || Map_AllUpdates
public static string[] GetMapNames()
{
return m_Maps.Where(m => m != null).Select(m => m.Name).ToArray();
}
public static Map[] GetMapValues()
{
return m_Maps.Where(m => m != null).ToArray();
}
public static Map Parse(string value)
{
if (String.IsNullOrWhiteSpace(value))
{
return null;
}
if (Insensitive.Equals(value, "Internal"))
{
return Internal;
}
if (!Int32.TryParse(value, out var index))
{
return m_Maps.FirstOrDefault(m => m != null && Insensitive.Equals(m.Name, value));
}
if (index == 127)
{
return Internal;
}
return m_Maps.FirstOrDefault(m => m != null && m.MapIndex == index);
}
public override string ToString()
{
return Name;
}
#else
private static string[] m_MapNames;
private static Map[] m_MapValues;
public static string[] GetMapNames()
{
CheckNamesAndValues();
return m_MapNames;
}
public static Map[] GetMapValues()
{
CheckNamesAndValues();
return m_MapValues;
}
public static Map Parse(string value)
{
CheckNamesAndValues();
for (int i = 0; i < m_MapNames.Length; ++i)
{
if (Insensitive.Equals(m_MapNames[i], value))
{
return m_MapValues[i];
}
}
int index;
if (int.TryParse(value, out index))
{
if (index >= 0 && index < m_Maps.Length && m_Maps[index] != null)
{
return m_Maps[index];
}
}
throw new ArgumentException("Invalid map name");
}
private static void CheckNamesAndValues()
{
if (m_MapNames != null && m_MapNames.Length == m_AllMaps.Count)
{
return;
}
m_MapNames = new string[m_AllMaps.Count];
m_MapValues = new Map[m_AllMaps.Count];
for (int i = 0; i < m_AllMaps.Count; ++i)
{
Map map = m_AllMaps[i];
m_MapNames[i] = map.Name;
m_MapValues[i] = map;
}
}
public override string ToString()
{
return Name;
}
#endif
public int GetAverageZ(int x, int y)
{
int z = 0, avg = 0, top = 0;
GetAverageZ(x, y, ref z, ref avg, ref top);
return avg;
}
public void GetAverageZ(int x, int y, ref int z, ref int avg, ref int top)
{
var zTop = Tiles.GetLandTile(x, y).Z;
var zLeft = Tiles.GetLandTile(x, y + 1).Z;
var zRight = Tiles.GetLandTile(x + 1, y).Z;
var zBottom = Tiles.GetLandTile(x + 1, y + 1).Z;
z = zTop;
if (zLeft < z)
{
z = zLeft;
}
if (zRight < z)
{
z = zRight;
}
if (zBottom < z)
{
z = zBottom;
}
top = zTop;
if (zLeft > top)
{
top = zLeft;
}
if (zRight > top)
{
top = zRight;
}
if (zBottom > top)
{
top = zBottom;
}
if (Math.Abs(zTop - zBottom) > Math.Abs(zLeft - zRight))
{
avg = FloorAverage(zLeft, zRight);
}
else
{
avg = FloorAverage(zTop, zBottom);
}
}
private static int FloorAverage(int a, int b)
{
var v = a + b;
if (v < 0)
{
--v;
}
return v / 2;
}
#if Map_NewEnumerables || Map_AllUpdates
#region Get*InRange/Bounds
public IPooledEnumerable<IEntity> GetObjectsInRange(Point3D p)
{
#if Map_UseMaxRange || Map_AllUpdates
return GetObjectsInRange(p, Core.GlobalMaxUpdateRange);
#else
return GetObjectsInRange(p, 18);
#endif
}
public IPooledEnumerable<IEntity> GetObjectsInRange(Point3D p, int range)
{
return GetObjectsInBounds(new Rectangle2D(p.m_X - range, p.m_Y - range, range * 2 + 1, range * 2 + 1));
}
public IPooledEnumerable<IEntity> GetObjectsInBounds(Rectangle2D bounds)
{
return PooledEnumeration.GetEntities(this, bounds);
}
public IPooledEnumerable<NetState> GetClientsInRange(Point3D p)
{
#if Map_UseMaxRange || Map_AllUpdates
return GetClientsInRange(p, Core.GlobalMaxUpdateRange);
#else
return GetClientsInRange(p, 18);
#endif
}
public IPooledEnumerable<NetState> GetClientsInRange(Point3D p, int range)
{
return GetClientsInBounds(new Rectangle2D(p.m_X - range, p.m_Y - range, range * 2 + 1, range * 2 + 1));
}
public IPooledEnumerable<NetState> GetClientsInBounds(Rectangle2D bounds)
{
return PooledEnumeration.GetClients(this, bounds);
}
public IPooledEnumerable<Item> GetItemsInRange(Point3D p)
{
#if Map_UseMaxRange || Map_AllUpdates
return GetItemsInRange(p, Core.GlobalMaxUpdateRange);
#else
return GetItemsInRange(p, 18);
#endif
}
public IPooledEnumerable<Item> GetItemsInRange(Point3D p, int range)
{
return GetItemsInBounds(new Rectangle2D(p.m_X - range, p.m_Y - range, range * 2 + 1, range * 2 + 1));
}
public IPooledEnumerable<Item> GetItemsInBounds(Rectangle2D bounds)
{
return PooledEnumeration.GetItems(this, bounds);
}
public IPooledEnumerable<Mobile> GetMobilesInRange(Point3D p)
{
#if Map_UseMaxRange || Map_AllUpdates
return GetMobilesInRange(p, Core.GlobalMaxUpdateRange);
#else
return GetMobilesInRange(p, 18);
#endif
}
public IPooledEnumerable<Mobile> GetMobilesInRange(Point3D p, int range)
{
return GetMobilesInBounds(new Rectangle2D(p.m_X - range, p.m_Y - range, range * 2 + 1, range * 2 + 1));
}
public IPooledEnumerable<Mobile> GetMobilesInBounds(Rectangle2D bounds)
{
return PooledEnumeration.GetMobiles(this, bounds);
}
#endregion
public IPooledEnumerable<StaticTile[]> GetMultiTilesAt(int x, int y)
{
return PooledEnumeration.GetMultiTiles(this, new Rectangle2D(x, y, 1, 1));
}
#else
#region Get*InRange/Bounds
public IPooledEnumerable<IEntity> GetObjectsInRange(Point3D p)
{
#if Map_UseMaxRange || Map_AllUpdates
return GetObjectsInRange(p, Core.GlobalMaxUpdateRange);
#else
return GetObjectsInRange(p, 18);
#endif
}
public IPooledEnumerable<IEntity> GetObjectsInRange(Point3D p, int range)
{
if (this == Internal)
{
return NullEnumerable<IEntity>.Instance;
}
return
PooledEnumerable<IEntity>.Instantiate(
EntityEnumerator.Instantiate(this, new Rectangle2D(p.m_X - range, p.m_Y - range, range * 2 + 1, range * 2 + 1)));
}
public IPooledEnumerable<IEntity> GetObjectsInBounds(Rectangle2D bounds)
{
if (this == Internal)
{
return NullEnumerable<IEntity>.Instance;
}
return PooledEnumerable<IEntity>.Instantiate(EntityEnumerator.Instantiate(this, bounds));
}
public IPooledEnumerable<NetState> GetClientsInRange(Point3D p)
{
#if Map_UseMaxRange || Map_AllUpdates
return GetClientsInRange(p, Core.GlobalMaxUpdateRange);
#else
return GetClientsInRange(p, 18);
#endif
}
public IPooledEnumerable<NetState> GetClientsInRange(Point3D p, int range)
{
if (this == Internal)
{
return NullEnumerable<NetState>.Instance;
}
return
PooledEnumerable<NetState>.Instantiate(
ClientEnumerator.Instantiate(this, new Rectangle2D(p.m_X - range, p.m_Y - range, range * 2 + 1, range * 2 + 1)));
}
public IPooledEnumerable<NetState> GetClientsInBounds(Rectangle2D bounds)
{
if (this == Internal)
{
return NullEnumerable<NetState>.Instance;
}
return PooledEnumerable<NetState>.Instantiate(ClientEnumerator.Instantiate(this, bounds));
}
public IPooledEnumerable<Item> GetItemsInRange(Point3D p)
{
#if Map_UseMaxRange || Map_AllUpdates
return GetItemsInRange(p, Core.GlobalMaxUpdateRange);
#else
return GetItemsInRange(p, 18);
#endif
}
public IPooledEnumerable<Item> GetItemsInRange(Point3D p, int range)
{
if (this == Internal)
{
return NullEnumerable<Item>.Instance;
}
return
PooledEnumerable<Item>.Instantiate(
ItemEnumerator.Instantiate(this, new Rectangle2D(p.m_X - range, p.m_Y - range, range * 2 + 1, range * 2 + 1)));
}
public IPooledEnumerable<Item> GetItemsInBounds(Rectangle2D bounds)
{
if (this == Internal)
{
return NullEnumerable<Item>.Instance;
}
return PooledEnumerable<Item>.Instantiate(ItemEnumerator.Instantiate(this, bounds));
}
public IPooledEnumerable<Mobile> GetMobilesInRange(Point3D p)
{
#if Map_UseMaxRange || Map_AllUpdates
return GetMobilesInRange(p, Core.GlobalMaxUpdateRange);
#else
return GetMobilesInRange(p, 18);
#endif
}
public IPooledEnumerable<Mobile> GetMobilesInRange(Point3D p, int range)
{
if (this == Internal)
{
return NullEnumerable<Mobile>.Instance;
}
return
PooledEnumerable<Mobile>.Instantiate(
MobileEnumerator.Instantiate(this, new Rectangle2D(p.m_X - range, p.m_Y - range, range * 2 + 1, range * 2 + 1)));
}
public IPooledEnumerable<Mobile> GetMobilesInBounds(Rectangle2D bounds)
{
if (this == Internal)
{
return NullEnumerable<Mobile>.Instance;
}
return PooledEnumerable<Mobile>.Instantiate(MobileEnumerator.Instantiate(this, bounds));
}
#endregion
public IPooledEnumerable<StaticTile[]> GetMultiTilesAt(int x, int y)
{
if (this == Internal)
{
return NullEnumerable<StaticTile[]>.Instance;
}
Sector sector = GetSector(x, y);
if (sector.Multis.Count == 0)
{
return NullEnumerable<StaticTile[]>.Instance;
}
return PooledEnumerable<StaticTile[]>.Instantiate(MultiTileEnumerator.Instantiate(sector, new Point2D(x, y)));
}
#endif
#region CanFit
public bool CanFit(Point3D p, int height, bool checkBlocksFit)
{
return CanFit(p.m_X, p.m_Y, p.m_Z, height, checkBlocksFit, true, true);
}
public bool CanFit(Point3D p, int height, bool checkBlocksFit, bool checkMobiles)
{
return CanFit(p.m_X, p.m_Y, p.m_Z, height, checkBlocksFit, checkMobiles, true, false);
}
public bool CanFit(Point2D p, int z, int height, bool checkBlocksFit)
{
return CanFit(p.m_X, p.m_Y, z, height, checkBlocksFit, true, true, false);
}
public bool CanFit(Point3D p, int height)
{
return CanFit(p.m_X, p.m_Y, p.m_Z, height, false, true, true, false);
}
public bool CanFit(Point2D p, int z, int height)
{
return CanFit(p.m_X, p.m_Y, z, height, false, true, true, false);
}
public bool CanFit(int x, int y, int z, int height)
{
return CanFit(x, y, z, height, false, true, true, false);
}
public bool CanFit(int x, int y, int z, int height, bool checksBlocksFit)
{
return CanFit(x, y, z, height, checksBlocksFit, true, true, false);
}
public bool CanFit(int x, int y, int z, int height, bool checkBlocksFit, bool checkMobiles)
{
return CanFit(x, y, z, height, checkBlocksFit, checkMobiles, true, false);
}
public bool CanFit(int x, int y, int z, int height, bool checkBlocksFit, bool checkMobiles, bool requireSurface)
{
return CanFit(x, y, z, height, checkBlocksFit, checkMobiles, requireSurface, false);
}
public bool CanFit(int x, int y, int z, int height, bool checkBlocksFit, bool checkMobiles, bool requireSurface, bool ignoreRoof)
{
if (this == Internal)
{
return false;
}
if (x < 0 || y < 0 || x >= m_Width || y >= m_Height)
{
return false;
}
int lowZ = 0, avgZ = 0, topZ = 0;
GetAverageZ(x, y, ref lowZ, ref avgZ, ref topZ);
var lt = Tiles.GetLandTile(x, y);
var landFlags = TileData.LandTable[lt.ID & TileData.MaxLandValue].Flags;
if ((landFlags & TileFlag.Impassable) != 0 && avgZ > z && (z + height) > lowZ)
{
return false;
}
var hasSurface = (landFlags & TileFlag.Impassable) == 0 && z == avgZ && !lt.Ignored;
var staticTiles = Tiles.GetStaticTiles(x, y, true);
bool surface, impassable, roof;
foreach (var t in staticTiles)
{
var id = TileData.ItemTable[t.ID & TileData.MaxItemValue];
surface = id.Surface;
impassable = id.Impassable;
roof = (id.Flags & TileFlag.Roof) != 0;
if ((surface || impassable) && (!ignoreRoof || !roof) && (t.Z + id.CalcHeight) > z && (z + height) > t.Z)
{
return false;
}
if (surface && !impassable && z == (t.Z + id.CalcHeight))
{
hasSurface = true;
}
}
var sector = GetSector(x, y);
var items = sector.Items;
var mobs = sector.Mobiles;
foreach (var item in items)
{
if (!(item is BaseMulti) && item.ItemID <= TileData.MaxItemValue && item.AtWorldPoint(x, y))
{
var id = item.ItemData;
surface = id.Surface;
impassable = id.Impassable;
if ((surface || impassable || (checkBlocksFit && item.BlocksFit)) && (item.Z + id.CalcHeight) > z &&
(z + height) > item.Z)
{
return false;
}
if (surface && !impassable && !item.Movable && z == (item.Z + id.CalcHeight))
{
hasSurface = true;
}
}
}
if (checkMobiles)
{
foreach (var m in mobs)
{
if (m.Location.m_X == x && m.Location.m_Y == y && (m.AccessLevel == AccessLevel.Player || !m.Hidden))
{
if ((m.Z + 16) > z && (z + height) > m.Z)
{
return false;
}
}
}
}
return !requireSurface || hasSurface;
}
public bool CanFit(int x, int y, int z, int height, bool checkBlocksFit, bool checkMobiles, bool requireSurface, Mobile mob)
{
if (this == Internal)
return false;
if (x < 0 || y < 0 || x >= Width || y >= Height)
return false;
var hasSurface = false;
var checkmob = false;
var canswim = false;
var cantwalk = false;
if (mob != null)
{
checkmob = true;
canswim = mob.CanSwim;
cantwalk = mob.CantWalk;
}
var lt = Tiles.GetLandTile(x, y);
int lowZ = 0, avgZ = 0, topZ = 0;
bool surface, impassable;
var wet = false;