1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 |
|
---|
4 | using AllocsFixes.PersistentData;
|
---|
5 |
|
---|
6 | namespace AllocsFixes
|
---|
7 | {
|
---|
8 | public class LandClaimList {
|
---|
9 | public delegate bool OwnerFilter (Player owner);
|
---|
10 |
|
---|
11 | public delegate bool PositionFilter (Vector3i position);
|
---|
12 |
|
---|
13 | public static Dictionary<Player, List<Vector3i>> GetLandClaims (OwnerFilter[] _ownerFilters, PositionFilter[] _positionFilters) {
|
---|
14 | Dictionary<Vector3i, PersistentPlayerData> d = GameManager.Instance.GetPersistentPlayerList ().m_lpBlockMap;
|
---|
15 | Dictionary<Player, List<Vector3i>> result = new Dictionary<Player, List<Vector3i>> ();
|
---|
16 |
|
---|
17 | if (d != null) {
|
---|
18 | Dictionary<PersistentPlayerData, List<Vector3i>> owners = new Dictionary<PersistentPlayerData, List<Vector3i>> ();
|
---|
19 | foreach (KeyValuePair<Vector3i, PersistentPlayerData> kvp in d) {
|
---|
20 | bool allowed = true;
|
---|
21 | if (_positionFilters != null) {
|
---|
22 | foreach (PositionFilter pf in _positionFilters) {
|
---|
23 | if (!pf (kvp.Key)) {
|
---|
24 | allowed = false;
|
---|
25 | break;
|
---|
26 | }
|
---|
27 | }
|
---|
28 | }
|
---|
29 | if (allowed) {
|
---|
30 | if (!owners.ContainsKey (kvp.Value)) {
|
---|
31 | owners.Add (kvp.Value, new List<Vector3i> ());
|
---|
32 | }
|
---|
33 | owners [kvp.Value].Add (kvp.Key);
|
---|
34 | }
|
---|
35 | }
|
---|
36 |
|
---|
37 | foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) {
|
---|
38 | Player p = PersistentData.PersistentContainer.Instance.Players [kvp.Key.PlayerId, false];
|
---|
39 | if (p == null) {
|
---|
40 | p = new Player (kvp.Key.PlayerId);
|
---|
41 | }
|
---|
42 |
|
---|
43 | bool allowed = true;
|
---|
44 | if (_ownerFilters != null) {
|
---|
45 | foreach (OwnerFilter of in _ownerFilters) {
|
---|
46 | if (!of (p)) {
|
---|
47 | allowed = false;
|
---|
48 | break;
|
---|
49 | }
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | if (allowed) {
|
---|
54 | result.Add (p, new List<Vector3i> ());
|
---|
55 | foreach (Vector3i v in kvp.Value) {
|
---|
56 | result [p].Add (v);
|
---|
57 | }
|
---|
58 | }
|
---|
59 | }
|
---|
60 | }
|
---|
61 | return result;
|
---|
62 | }
|
---|
63 |
|
---|
64 | public static OwnerFilter SteamIdFilter (string _steamId) {
|
---|
65 | return p => p.SteamID.Equals (_steamId);
|
---|
66 | }
|
---|
67 |
|
---|
68 | public static PositionFilter CloseToFilter2dRect (Vector3i _position, int _maxDistance) {
|
---|
69 | return v => Math.Abs (v.x - _position.x) <= _maxDistance && Math.Abs (v.z - _position.z) <= _maxDistance;
|
---|
70 | }
|
---|
71 |
|
---|
72 | public static OwnerFilter OrOwnerFilter (OwnerFilter _f1, OwnerFilter _f2) {
|
---|
73 | return p => _f1 (p) || _f2 (p);
|
---|
74 | }
|
---|
75 |
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|