3 private static bool m_Initialized;
11 static bool LoadData()
18 if (
GetGame().ServerConfigGetInt(
"enableCfgGameplayFile" ))
21 m_PRAFiles =
g_Game.GetMission().GetWorldData().GetDefaultPRAPaths();
27 GetGame().GetWorldName(worldName);
29 foreach (
string filename : m_PRAFiles)
33 string errorMessage,
path;
35 path =
string.Format(
"$mission:%1", filename);
36 if (!JsonFileLoader<PlayerRestrictedAreaInstance>.LoadFile(
path, area, errorMessage))
39 path =
string.Format(
"dz/worlds/%1/ce/%2", worldName, filename);
41 if (!JsonFileLoader<PlayerRestrictedAreaInstance>.LoadFile(
path, area, errorMessage))
49 m_Data.m_Areas.Insert(area);
57 static bool IsInitialized()
67 GetGame().RPCSingleParam(null,
ERPCs.RPC_PLAYERRESTRICTEDAREAS_SYNC,
new Param1<CfgPlayerRestrictedAreaJsonData>(
m_Data),
true, identity);
72 Param1<CfgPlayerRestrictedAreaJsonData> data =
new Param1<CfgPlayerRestrictedAreaJsonData>(null);
81 ErrorEx(
"CfgPlayerRestrictedAreaHandler - client failed to read incoming data");
94 if (area && IsCylinderInAreaBox(area,point) || IsPointInAreaPolygon(area,point))
104 if (!IsInitialized())
109 if (IsCylinderInAreaBox(area,point) || IsPointInAreaPolygon(area,point))
125 float closestDist =
float.MAX;
130 currentDist =
vector.DistanceSq(point,area.GetCenterPos2D());
131 if (currentDist < closestDist)
134 closestDist = currentDist;
144 foreach (PRAShapeBoxData boxData : area.m_PRABoxDataTranslated)
147 Math3D.MatrixIdentity4(matPlayer4);
148 matPlayer4[3] = point;
149 if (
Math3D.IntersectCylinderOBB(boxData.m_Mins,boxData.m_Maxs,boxData.m_Mat4,matPlayer4,cylinderRadius,cylinderHeight))
161 translatedDta.Clear();
165 translatedDta.Insert(vertexPos[0]);
166 translatedDta.Insert(vertexPos[1]);
169 if (
Math2D.IsPointInPolygon(translatedDta,point[0],point[2]))
180 static private ref
array<Shape> m_DbgShapesPolygonLines;
182 static void DrawBoxesDebug(
bool draw)
184 if (!IsInitialized())
187 if (!m_DbgShapesBoxes)
188 m_DbgShapesBoxes = {};
190 if (draw && m_DbgShapesBoxes.Count() == 0)
194 foreach (PRAShapeBoxData boxData : area.m_PRABoxDataTranslated)
196 Shape shp =
Debug.DrawBox(boxData.m_Mins,boxData.m_Maxs);
197 shp.SetMatrix(boxData.m_Mat4);
198 m_DbgShapesBoxes.Insert(shp);
202 else if (!draw && m_DbgShapesBoxes.Count() > 0)
204 foreach (
Shape box : m_DbgShapesBoxes)
209 m_DbgShapesBoxes.Clear();
213 static void DrawPolygonLinesDebug(
bool draw)
215 if (!IsInitialized())
218 if (!m_DbgShapesPolygonLines)
219 m_DbgShapesPolygonLines = {};
221 if (draw && m_DbgShapesPolygonLines.Count() == 0)
234 polygonVectors.Insert(
Vector(vertexPos[0],
GetGame().SurfaceY(vertexPos[0],vertexPos[1]) + 2,vertexPos[1]));
237 int count = polygonVectors.Count();
238 for (
int i = 0; i < count; ++i)
240 current = polygonVectors[i];
243 first = polygonVectors[i];
252 polygonVectors.Clear();
256 else if (!draw && m_DbgShapesPolygonLines.Count() > 0)
258 foreach (
Shape item : m_DbgShapesPolygonLines)
263 m_DbgShapesPolygonLines.Clear();