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

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

Fixed game version compatibility of GamePrefs
Code style cleanup (mostly argument names)

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