source: binary-improvements/7dtd-server-fixes/src/LandClaimList.cs@ 501

Last change on this file since 501 was 488, checked in by alloc, 6 months ago

27_32_48

  • V1.0 compatibility
File size: 2.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using AllocsFixes.PersistentData;
4
5namespace AllocsFixes {
6 public static class LandClaimList {
7 public delegate bool OwnerFilter (Player _owner);
8
9 public delegate bool PositionFilter (Vector3i _position);
10
11 public static Dictionary<Player, List<Vector3i>> GetLandClaims (OwnerFilter[] _ownerFilters,
12 PositionFilter[] _positionFilters) {
13 Dictionary<Vector3i, PersistentPlayerData> d = GameManager.Instance.GetPersistentPlayerList ().m_lpBlockMap;
14 Dictionary<Player, List<Vector3i>> result = new Dictionary<Player, List<Vector3i>> ();
15
16 if (d == null) {
17 return result;
18 }
19
20 Dictionary<PersistentPlayerData, List<Vector3i>> owners =
21 new Dictionary<PersistentPlayerData, List<Vector3i>> ();
22 foreach (KeyValuePair<Vector3i, PersistentPlayerData> kvp in d) {
23 bool allowed = true;
24 if (_positionFilters != null) {
25 foreach (PositionFilter pf in _positionFilters) {
26 if (!pf (kvp.Key)) {
27 allowed = false;
28 break;
29 }
30 }
31 }
32
33 if (allowed) {
34 if (!owners.ContainsKey (kvp.Value)) {
35 owners.Add (kvp.Value, new List<Vector3i> ());
36 }
37
38 owners [kvp.Value].Add (kvp.Key);
39 }
40 }
41
42 foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) {
43 Player p = PersistentContainer.Instance.Players.GetByInternalId (kvp.Key.PrimaryId);
44 if (p == null) {
45 PlatformUserIdentifierAbs platformId = kvp.Key.NativeId;
46 PlatformUserIdentifierAbs internalId = kvp.Key.PrimaryId;
47 PlatformUserIdentifierAbs crossPlatformId = platformId == null || platformId.Equals (internalId) ? null : internalId;
48 p = new Player (internalId, platformId, crossPlatformId);
49 }
50
51 bool allowed = true;
52 if (_ownerFilters != null) {
53 foreach (OwnerFilter of in _ownerFilters) {
54 if (!of (p)) {
55 allowed = false;
56 break;
57 }
58 }
59 }
60
61 if (allowed) {
62 result.Add (p, new List<Vector3i> ());
63 foreach (Vector3i v in kvp.Value) {
64 result [p].Add (v);
65 }
66 }
67 }
68
69 return result;
70 }
71
72 public static OwnerFilter UserIdFilter (PlatformUserIdentifierAbs _userId) {
73 return _p => _p.InternalId.Equals (_userId);
74 }
75
76 public static PositionFilter CloseToFilter2dRect (Vector3i _position, int _maxDistance) {
77 return _v => Math.Abs (_v.x - _position.x) <= _maxDistance && Math.Abs (_v.z - _position.z) <= _maxDistance;
78 }
79
80 public static OwnerFilter OrOwnerFilter (OwnerFilter _f1, OwnerFilter _f2) {
81 return _p => _f1 (_p) || _f2 (_p);
82 }
83 }
84}
Note: See TracBrowser for help on using the repository browser.