Elin Decompiled Documentation EA 23.102 Nightly
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Pages
RoomManager.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Linq;
3using Newtonsoft.Json;
4
5public class RoomManager : EClass
6{
7 private List<BaseArea> tempList = new List<BaseArea>();
8
9 [JsonProperty]
10 public List<Area> listArea = new List<Area>();
11
12 [JsonProperty]
13 public List<Room> listRoom = new List<Room>();
14
15 [JsonProperty]
16 public int uidRoom = 1;
17
18 public Dictionary<int, BaseArea> mapIDs = new Dictionary<int, BaseArea>();
19
20 public List<Lot> listLot = new List<Lot>();
21
22 public bool dirtyLots;
23
24 public bool dirtyRooms;
25
26 public void OnLoad()
27 {
28 foreach (Area item in listArea)
29 {
30 item.OnLoad();
31 }
32 foreach (Room item2 in listRoom)
33 {
34 item2.OnLoad();
35 }
36 Refresh();
37 }
38
39 public void AssignCharas()
40 {
41 }
42
43 public void RefreshAll()
44 {
45 foreach (Room item in listRoom)
46 {
47 item.SetDirty();
48 }
49 Refresh();
50 }
51
52 public void Refresh()
53 {
54 if (dirtyRooms)
55 {
56 foreach (Room item in listRoom)
57 {
58 if (item.dirty)
59 {
60 item.Refresh();
61 }
62 }
63 }
64 if (dirtyLots)
65 {
67 }
68 }
69
70 public void AssignUID(BaseArea a)
71 {
72 a.uid = uidRoom;
73 uidRoom++;
74 }
75
76 public Area AddArea(Area a, Point p)
77 {
78 if (!listArea.Contains(a))
79 {
80 listArea.Add(a);
81 mapIDs.Add(a.uid, a);
82 }
83 a.AddPoint(p.Copy());
84 return a;
85 }
86
87 public Area TryAddArea(Point p, Area existingArea)
88 {
89 if (p.area != null)
90 {
91 return existingArea;
92 }
93 if (existingArea == null)
94 {
95 existingArea = Area.Create("public");
96 listArea.Add(existingArea);
97 mapIDs.Add(existingArea.uid, existingArea);
98 }
99 existingArea.AddPoint(p.Copy());
100 return existingArea;
101 }
102
103 public void RemoveArea(Area a)
104 {
105 listArea.Remove(a);
106 mapIDs.Remove(a.uid);
107 a.OnRemove();
108 }
109
110 public Room AddRoom(Room r)
111 {
112 listRoom.Add(r);
113 AssignUID(r);
114 r.SetDirty();
115 mapIDs.Add(r.uid, r);
116 return r;
117 }
118
119 public void RemoveRoom(Room r)
120 {
121 listRoom.Remove(r);
122 mapIDs.Remove(r.uid);
123 r.OnRemove();
124 }
125
126 public HitResult GetHitResult(Point point, Point start)
127 {
128 if (point.area != null)
129 {
130 return HitResult.Invalid;
131 }
132 if (!point.HasBlock)
133 {
134 return HitResult.Valid;
135 }
136 return HitResult.Default;
137 }
138
139 public void RebuildLots()
140 {
141 listLot.Clear();
142 foreach (Room item in listRoom)
143 {
144 item.lot = null;
145 }
146 foreach (Room item2 in listRoom)
147 {
148 if (item2.lot == null)
149 {
150 Lot lot = new Lot
151 {
152 x = item2.x,
153 z = item2.z,
154 mx = item2.mx,
155 mz = item2.mz
156 };
157 lot.SetBaseRoom(item2);
158 listLot.Add(lot);
159 }
160 }
161 dirtyLots = false;
162 }
163
164 public BaseArea FindBaseArea(string id)
165 {
166 tempList.Clear();
167 foreach (BaseArea item in ((IEnumerable<BaseArea>)listRoom).Concat((IEnumerable<BaseArea>)listArea))
168 {
169 if (item.type.id == id)
170 {
171 tempList.Add(item);
172 }
173 }
174 if (tempList.Count == 0)
175 {
176 return null;
177 }
178 return tempList.RandomItem();
179 }
180}
HitResult
Definition: HitResult.cs:2
Definition: Area.cs:4
void AddPoint(Point point, bool onLoad=false)
Definition: Area.cs:27
void OnRemove()
Definition: Area.cs:84
static Area Create(string id)
Definition: Area.cs:104
int uid
Definition: BaseArea.cs:23
Definition: EClass.cs:5
Definition: Lot.cs:5
void SetBaseRoom(Room r)
Definition: Lot.cs:82
Definition: Point.cs:9
Point Copy()
Definition: Point.cs:467
Area area
Definition: Point.cs:73
bool HasBlock
Definition: Point.cs:141
Area TryAddArea(Point p, Area existingArea)
Definition: RoomManager.cs:87
Room AddRoom(Room r)
Definition: RoomManager.cs:110
void RefreshAll()
Definition: RoomManager.cs:43
void AssignUID(BaseArea a)
Definition: RoomManager.cs:70
List< Lot > listLot
Definition: RoomManager.cs:20
void RebuildLots()
Definition: RoomManager.cs:139
Area AddArea(Area a, Point p)
Definition: RoomManager.cs:76
Dictionary< int, BaseArea > mapIDs
Definition: RoomManager.cs:18
void RemoveRoom(Room r)
Definition: RoomManager.cs:119
List< Room > listRoom
Definition: RoomManager.cs:13
bool dirtyLots
Definition: RoomManager.cs:22
List< Area > listArea
Definition: RoomManager.cs:10
void RemoveArea(Area a)
Definition: RoomManager.cs:103
void Refresh()
Definition: RoomManager.cs:52
void AssignCharas()
Definition: RoomManager.cs:39
HitResult GetHitResult(Point point, Point start)
Definition: RoomManager.cs:126
List< BaseArea > tempList
Definition: RoomManager.cs:7
bool dirtyRooms
Definition: RoomManager.cs:24
BaseArea FindBaseArea(string id)
Definition: RoomManager.cs:164
void OnLoad()
Definition: RoomManager.cs:26
Definition: Room.cs:4
void SetDirty()
Definition: Room.cs:213
int x
Definition: Room.cs:5
int z
Definition: Room.cs:7
void OnLoad()
Definition: Room.cs:36
int mx
Definition: Room.cs:9
void OnRemove()
Definition: Room.cs:54
Lot lot
Definition: Room.cs:21