[253] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using AllocsFixes.PersistentData;
|
---|
| 4 |
|
---|
[325] | 5 | namespace AllocsFixes {
|
---|
[369] | 6 | public static class LandClaimList {
|
---|
[351] | 7 | public delegate bool OwnerFilter (Player _owner);
|
---|
[253] | 8 |
|
---|
[351] | 9 | public delegate bool PositionFilter (Vector3i _position);
|
---|
[253] | 10 |
|
---|
[325] | 11 | public static Dictionary<Player, List<Vector3i>> GetLandClaims (OwnerFilter[] _ownerFilters,
|
---|
| 12 | PositionFilter[] _positionFilters) {
|
---|
[253] | 13 | Dictionary<Vector3i, PersistentPlayerData> d = GameManager.Instance.GetPersistentPlayerList ().m_lpBlockMap;
|
---|
| 14 | Dictionary<Player, List<Vector3i>> result = new Dictionary<Player, List<Vector3i>> ();
|
---|
| 15 |
|
---|
[326] | 16 | if (d == null) {
|
---|
| 17 | return result;
|
---|
| 18 | }
|
---|
[325] | 19 |
|
---|
[326] | 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;
|
---|
[253] | 29 | }
|
---|
| 30 | }
|
---|
| 31 | }
|
---|
| 32 |
|
---|
[326] | 33 | if (allowed) {
|
---|
| 34 | if (!owners.ContainsKey (kvp.Value)) {
|
---|
| 35 | owners.Add (kvp.Value, new List<Vector3i> ());
|
---|
[253] | 36 | }
|
---|
| 37 |
|
---|
[326] | 38 | owners [kvp.Value].Add (kvp.Key);
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) {
|
---|
[446] | 43 | Player p = PersistentContainer.Instance.Players.GetByInternalId (kvp.Key.UserIdentifier);
|
---|
[326] | 44 | if (p == null) {
|
---|
[446] | 45 | PlatformUserIdentifierAbs platformId = kvp.Key.PlatformUserIdentifier;
|
---|
| 46 | PlatformUserIdentifierAbs internalId = kvp.Key.UserIdentifier;
|
---|
[448] | 47 | PlatformUserIdentifierAbs crossPlatformId = platformId == null || platformId.Equals (internalId) ? null : internalId;
|
---|
[446] | 48 | p = new Player (internalId, platformId, crossPlatformId);
|
---|
[326] | 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;
|
---|
[253] | 57 | }
|
---|
| 58 | }
|
---|
[326] | 59 | }
|
---|
[253] | 60 |
|
---|
[326] | 61 | if (allowed) {
|
---|
| 62 | result.Add (p, new List<Vector3i> ());
|
---|
| 63 | foreach (Vector3i v in kvp.Value) {
|
---|
| 64 | result [p].Add (v);
|
---|
[253] | 65 | }
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
[325] | 68 |
|
---|
[253] | 69 | return result;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[369] | 72 | public static OwnerFilter UserIdFilter (PlatformUserIdentifierAbs _userId) {
|
---|
[446] | 73 | return _p => _p.InternalId.Equals (_userId);
|
---|
[253] | 74 | }
|
---|
| 75 |
|
---|
| 76 | public static PositionFilter CloseToFilter2dRect (Vector3i _position, int _maxDistance) {
|
---|
[351] | 77 | return _v => Math.Abs (_v.x - _position.x) <= _maxDistance && Math.Abs (_v.z - _position.z) <= _maxDistance;
|
---|
[253] | 78 | }
|
---|
| 79 |
|
---|
| 80 | public static OwnerFilter OrOwnerFilter (OwnerFilter _f1, OwnerFilter _f2) {
|
---|
[351] | 81 | return _p => _f1 (_p) || _f2 (_p);
|
---|
[253] | 82 | }
|
---|
| 83 | }
|
---|
[325] | 84 | }
|
---|