-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
ColShape.cs
73 lines (57 loc) · 1.91 KB
/
ColShape.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System.Collections.Generic;
using AltV.Net.Data;
using AltV.Net.Elements.Entities;
namespace AltV.Net.ColShape
{
public class ColShape : IColShape
{
public ulong Id { get; }
public int Dimension { get; }
public Position Position { get; }
public uint Radius { get; }
private readonly HashSet<IWorldObject> worldObjects;
public IDictionary<IWorldObject, bool> LastChecked { get; }
public IEnumerable<IWorldObject> WorldObjects => worldObjects;
public ColShape(ulong id, int dimension, Position position, uint radius)
{
Id = id;
Dimension = dimension;
Position = position;
Radius = radius;
worldObjects = new HashSet<IWorldObject>();
LastChecked = new Dictionary<IWorldObject, bool>();
}
public bool AddWorldObject(IWorldObject worldObject)
{
return worldObjects.Add(worldObject);
}
public void RemoveWorldObject(IWorldObject worldObject)
{
worldObjects.Remove(worldObject);
}
public bool ContainsWorldObject(IWorldObject worldObject)
{
return worldObjects.Contains(worldObject);
}
public virtual bool IsPositionInside(in Position position)
{
return Position.Distance(position) <= Radius;
}
public void SetCheck(IWorldObject worldObject)
{
LastChecked[worldObject] = true;
}
public void ResetCheck(IWorldObject worldObject)
{
LastChecked[worldObject] = false;
}
public void RemoveCheck(IWorldObject worldObject)
{
LastChecked.Remove(worldObject);
}
public bool HasCheck(IWorldObject worldObject)
{
return LastChecked.TryGetValue(worldObject, out var checkState) && checkState;
}
}
}