Elin Modding Docs Doc
Loading...
Searching...
No Matches
Fov.cs
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4
5// Token: 0x020000A3 RID: 163
6public class Fov : EClass
7{
8 // Token: 0x0600044E RID: 1102 RVA: 0x0001CAA4 File Offset: 0x0001ACA4
9 public void SetVisible(int x, int y)
10 {
11 Cell cell = Fov.map.cells[x, y];
12 if (cell.light > 100 && !this.isPC)
13 {
14 return;
15 }
16 int key = x + y * Fov.map.Size;
17 if (this.isPC && !cell.outOfBounds)
18 {
19 cell.pcSync = true;
20 }
21 if (Fov._power < 0.1f)
22 {
23 this.lastPoints[key] = 0;
24 return;
25 }
26 float num = this.GetVisDistance(x, y, Fov.origin.X, Fov.origin.Y);
27 float num2 = Fov._power;
28 if (this.limitGradient)
29 {
30 num2 *= Fov.nonGradientMod;
31 if (num >= (float)Fov.range)
32 {
33 num2 *= EClass.scene.profile.global.edgeLight;
34 }
35 }
36 else
37 {
38 if (num <= 1f)
39 {
40 num = 1f;
41 }
42 num2 *= (float)(Fov.range + 1) - num;
43 }
44 if (num2 < 1f)
45 {
46 num2 = 1f;
47 }
48 else if (num2 > 20f)
49 {
50 num2 = 20f;
51 }
52 if (cell.outOfBounds)
53 {
54 if (this.isPC && (num2 > 0f || this.GetVisDistance(Fov.origin.X, Fov.origin.Y, x, y) < 4f))
55 {
56 cell.isSeen = true;
57 }
58 num2 = 0f;
59 }
60 this.lastPoints[key] = (byte)num2;
61 }
62
63 // Token: 0x0600044F RID: 1103 RVA: 0x0001CBFC File Offset: 0x0001ADFC
64 public void ClearVisible()
65 {
66 foreach (KeyValuePair<int, byte> keyValuePair in this.lastPoints)
67 {
68 Cell cell = Fov.map.GetCell(keyValuePair.Key);
69 byte value = keyValuePair.Value;
70 Cell cell2 = cell;
71 cell2.light -= value;
72 Cell cell3 = cell;
73 cell3.lightR -= (ushort)(value * this.r / 2);
74 Cell cell4 = cell;
75 cell4.lightG -= (ushort)(value * this.g / 2);
76 Cell cell5 = cell;
77 cell5.lightB -= (ushort)(value * this.b / 2);
78 if (this.isPC)
79 {
80 cell.pcSync = false;
81 }
82 }
83 this.lastPoints.Clear();
84 }
85
86 // Token: 0x06000450 RID: 1104 RVA: 0x0001CCDC File Offset: 0x0001AEDC
87 public List<Point> ListPoints()
88 {
89 List<Point> list = new List<Point>();
90 foreach (KeyValuePair<int, byte> keyValuePair in this.lastPoints)
91 {
92 list.Add(new Point(keyValuePair.Key));
93 }
94 return list;
95 }
96
97 // Token: 0x06000451 RID: 1105 RVA: 0x0001CD44 File Offset: 0x0001AF44
98 private float GetVisDistance(int x1, int y1, int x2, int y2)
99 {
100 return Mathf.Sqrt((float)((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
101 }
102
103 // Token: 0x06000452 RID: 1106 RVA: 0x0001CD68 File Offset: 0x0001AF68
104 public static float DistanceFloat(int x1, int y1, int x2, int y2)
105 {
106 return Mathf.Sqrt((float)((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
107 }
108
109 // Token: 0x06000453 RID: 1107 RVA: 0x0001CD8C File Offset: 0x0001AF8C
110 public static int Distance(int x1, int y1, int x2, int y2)
111 {
112 return (int)Mathf.Sqrt((float)((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
113 }
114
115 // Token: 0x06000454 RID: 1108 RVA: 0x0001CDB0 File Offset: 0x0001AFB0
116 public void Perform(int _x, int _z, int _range, float power = 1f)
117 {
118 Fov.range = _range;
119 this.ClearVisible();
120 if (Fov.range == 0)
121 {
122 return;
123 }
124 Fov._power = power;
125 Fov.origin.X = _x;
126 Fov.origin.Y = _z;
127 this.SetVisible(Fov.origin.X, Fov.origin.Y);
128 int num = Fov.origin.X - Fov.range;
129 if (num < 0)
130 {
131 num = 0;
132 }
133 int num2 = Fov.origin.Y - Fov.range;
134 if (num2 < 0)
135 {
136 num2 = 0;
137 }
138 int num3 = Fov.origin.X + Fov.range + 1;
139 if (num3 >= EClass._map.Size)
140 {
141 num3 = EClass._map.Size;
142 }
143 int num4 = Fov.origin.Y + Fov.range + 1;
144 if (num4 >= EClass._map.Size)
145 {
146 num4 = EClass._map.Size;
147 }
148 for (int i = num; i < num3; i++)
149 {
150 this.TraceLine(i, num2);
151 this.TraceLine(i, num4 - 1);
152 }
153 for (int j = num2 + 1; j < num4 - 1; j++)
154 {
155 this.TraceLine(num, j);
156 this.TraceLine(num3 - 1, j);
157 }
158 if (Fov.range >= 6)
159 {
160 int max = EClass._map.Size - 1;
161 int x = (Fov.origin.X + 4).ClampMax(max);
162 int y = (Fov.origin.Y + 1).ClampMax(max);
163 int x2 = (Fov.origin.X - 4).ClampMin(0);
164 int y2 = (Fov.origin.Y - 1).ClampMin(0);
165 int x3 = (Fov.origin.X + 1).ClampMax(max);
166 int y3 = (Fov.origin.Y + 4).ClampMax(max);
167 int x4 = (Fov.origin.X - 1).ClampMin(0);
168 int y4 = (Fov.origin.Y - 4).ClampMin(0);
169 this.TraceLine(x, y);
170 this.TraceLine(x, y2);
171 this.TraceLine(x2, y);
172 this.TraceLine(x2, y2);
173 this.TraceLine(x3, y3);
174 this.TraceLine(x3, y4);
175 this.TraceLine(x4, y3);
176 this.TraceLine(x4, y4);
177 }
178 foreach (KeyValuePair<int, byte> keyValuePair in this.lastPoints)
179 {
180 Cell cell = Fov.map.GetCell(keyValuePair.Key);
181 byte value = keyValuePair.Value;
182 Cell cell2 = cell;
183 cell2.light += value;
184 Cell cell3 = cell;
185 cell3.lightR += (ushort)(value * this.r / 2);
186 Cell cell4 = cell;
187 cell4.lightG += (ushort)(value * this.g / 2);
188 Cell cell5 = cell;
189 cell5.lightB += (ushort)(value * this.b / 2);
190 if (this.isPC && (value > 0 || this.GetVisDistance(Fov.origin.X, Fov.origin.Y, (int)cell.x, (int)cell.z) < 2f) && !cell.isSeen && (!cell.HasWall || EClass._zone.UseFog || cell.room == EClass.pc.Cell.room || cell.hasDoor))
191 {
192 EClass._map.SetSeen((int)cell.x, (int)cell.z, true, true);
193 Fov.newPoints.Add(cell);
194 }
195 }
196 if (this.isPC && Fov.newPoints.Count > 0)
197 {
198 WidgetMinimap.UpdateMap(Fov.newPoints);
199 }
200 }
201
202 // Token: 0x06000455 RID: 1109 RVA: 0x0001D17C File Offset: 0x0001B37C
203 private void TraceLine(int x2, int y2)
204 {
205 int value = x2 - Fov.origin.X;
206 int value2 = y2 - Fov.origin.Y;
207 int num = Math.Abs(value);
208 int num2 = Math.Abs(value2);
209 int num3 = Math.Sign(value);
210 int num4 = Math.Sign(value2) << 16;
211 int num5 = (Fov.origin.Y << 16) + Fov.origin.X;
212 if (num < num2)
213 {
214 int num6 = num;
215 num = num2;
216 num2 = num6;
217 int num7 = num3;
218 num3 = num4;
219 num4 = num7;
220 }
221 int num8 = num2 * 2;
222 int num9 = -num;
223 int num10 = num * 2;
224 while (--num >= 0)
225 {
226 num5 += num3;
227 num9 += num8;
228 if (num9 > 0)
229 {
230 num9 -= num10;
231 num5 += num4;
232 }
233 Fov.x = (num5 & 65535);
234 Fov.y = num5 >> 16;
235 int num11 = (int)this.GetVisDistance(Fov.origin.X, Fov.origin.Y, Fov.x, Fov.y);
236 if (Fov.range >= 0 && num11 > Fov.range)
237 {
238 break;
239 }
240 this.SetVisible(Fov.x, Fov.y);
241 if (Fov.map.cells[Fov.x, Fov.y].blockSight)
242 {
243 break;
244 }
245 }
246 }
247
248 // Token: 0x040005D1 RID: 1489
249 public static float nonGradientMod;
250
251 // Token: 0x040005D2 RID: 1490
252 public static List<Cell> newPoints = new List<Cell>();
253
254 // Token: 0x040005D3 RID: 1491
255 public static Map map;
256
257 // Token: 0x040005D4 RID: 1492
258 public static Fov.LevelPoint origin = default(Fov.LevelPoint);
259
260 // Token: 0x040005D5 RID: 1493
261 public static int range;
262
263 // Token: 0x040005D6 RID: 1494
264 public static float _power;
265
266 // Token: 0x040005D7 RID: 1495
267 public byte r;
268
269 // Token: 0x040005D8 RID: 1496
270 public byte g;
271
272 // Token: 0x040005D9 RID: 1497
273 public byte b;
274
275 // Token: 0x040005DA RID: 1498
276 public bool isPC;
277
278 // Token: 0x040005DB RID: 1499
279 public bool limitGradient;
280
281 // Token: 0x040005DC RID: 1500
282 public Dictionary<int, byte> lastPoints = new Dictionary<int, byte>();
283
284 // Token: 0x040005DD RID: 1501
285 private static int x;
286
287 // Token: 0x040005DE RID: 1502
288 private static int y;
289
290 // Token: 0x020007EE RID: 2030
291 public struct LevelPoint
292 {
293 // Token: 0x0400223E RID: 8766
294 public int X;
295
296 // Token: 0x0400223F RID: 8767
297 public int Y;
298 }
299}
Definition Cell.cs:10
Definition Fov.cs:7
Definition Map.cs:15
Definition Point.cs:11