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

Last change on this file since 325 was 325, checked in by alloc, 6 years ago

Code style cleanup (mostly whitespace changes, enforcing braces, using cleanup)

File size: 2.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using AllocsFixes.PersistentData;
4
5namespace AllocsFixes {
6 public 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 Dictionary<PersistentPlayerData, List<Vector3i>> owners =
18 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
30 if (allowed) {
31 if (!owners.ContainsKey (kvp.Value)) {
32 owners.Add (kvp.Value, new List<Vector3i> ());
33 }
34
35 owners [kvp.Value].Add (kvp.Key);
36 }
37 }
38
39 foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) {
40 Player p = PersistentContainer.Instance.Players [kvp.Key.PlayerId, false];
41 if (p == null) {
42 p = new Player (kvp.Key.PlayerId);
43 }
44
45 bool allowed = true;
46 if (_ownerFilters != null) {
47 foreach (OwnerFilter of in _ownerFilters) {
48 if (!of (p)) {
49 allowed = false;
50 break;
51 }
52 }
53 }
54
55 if (allowed) {
56 result.Add (p, new List<Vector3i> ());
57 foreach (Vector3i v in kvp.Value) {
58 result [p].Add (v);
59 }
60 }
61 }
62 }
63
64 return result;
65 }
66
67 public static OwnerFilter SteamIdFilter (string _steamId) {
68 return p => p.SteamID.Equals (_steamId);
69 }
70
71 public static PositionFilter CloseToFilter2dRect (Vector3i _position, int _maxDistance) {
72 return v => Math.Abs (v.x - _position.x) <= _maxDistance && Math.Abs (v.z - _position.z) <= _maxDistance;
73 }
74
75 public static OwnerFilter OrOwnerFilter (OwnerFilter _f1, OwnerFilter _f2) {
76 return p => _f1 (p) || _f2 (p);
77 }
78 }
79}
Note: See TracBrowser for help on using the repository browser.