undergroundarealoader.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. class JsonUndergroundTriggers
  2. {
  3. ref array<ref JsonUndergroundAreaTriggerData> Triggers;
  4. }
  5. class JsonUndergroundAreaBreadcrumb
  6. {
  7. vector GetPosition()
  8. {
  9. return Vector(Position[0],Position[1],Position[2]);
  10. }
  11. ref array<float> Position;
  12. float EyeAccommodation;
  13. bool UseRaycast;
  14. float Radius;
  15. bool LightLerp; // only used in LinePointFade
  16. }
  17. class JsonUndergroundAreaTriggerData
  18. {
  19. vector GetPosition()
  20. {
  21. return Vector(Position[0],Position[1],Position[2]);
  22. }
  23. vector GetOrientation()
  24. {
  25. return Vector(Orientation[0],Orientation[1],Orientation[2]);
  26. }
  27. vector GetSize()
  28. {
  29. return Vector(Size[0],Size[1],Size[2]);
  30. }
  31. ref array<float> Position;
  32. ref array<float> Orientation;
  33. ref array<float> Size;
  34. float EyeAccommodation;
  35. float InterpolationSpeed;
  36. bool UseLinePointFade; // simple fade between points which are defined using existing breadcrumbs array
  37. ref array<ref JsonUndergroundAreaBreadcrumb> Breadcrumbs;
  38. };
  39. class UndergroundAreaLoader
  40. {
  41. private static string m_Path = "$mission:cfgundergroundtriggers.json";
  42. static ref JsonUndergroundTriggers m_JsonData;
  43. static JsonUndergroundTriggers GetData()
  44. {
  45. if (!FileExist(m_Path))
  46. {
  47. // We fallback to check in data and notify user file was not found in mission
  48. PrintToRPT("[WARNING] :: [UndergroundAreaLoader GetData()] :: file not found in MISSION folder, your path is " + m_Path + " Attempting DATA folder");
  49. string worldName;
  50. GetGame().GetWorldName(worldName);
  51. m_Path = string.Format("dz/worlds/%1/ce/cfgundergroundtriggers.json", worldName);
  52. if (!FileExist(m_Path))
  53. {
  54. PrintToRPT("[WARNING] :: [UndergroundAreaLoader GetData()] ::file not found in DATA folder, your path is " + m_Path);
  55. return null; // Nothing could be read, just end here
  56. }
  57. }
  58. string errorMessage;
  59. JsonUndergroundTriggers data;
  60. if (!JsonFileLoader<JsonUndergroundTriggers>.LoadFile(m_Path, data, errorMessage))
  61. ErrorEx(errorMessage);
  62. return data;
  63. }
  64. static void SpawnAllTriggerCarriers()
  65. {
  66. if (!m_JsonData)
  67. {
  68. m_JsonData = GetData();
  69. }
  70. if (!m_JsonData || !m_JsonData.Triggers)
  71. {
  72. return;
  73. }
  74. foreach (int i, auto data:m_JsonData.Triggers)
  75. {
  76. SpawnTriggerCarrier(i, data);
  77. }
  78. }
  79. static void SpawnTriggerCarrier(int index, JsonUndergroundAreaTriggerData data)
  80. {
  81. UndergroundTriggerCarrierBase carrier = UndergroundTriggerCarrierBase.Cast(GetGame().CreateObjectEx( "UndergroundTriggerCarrier", data.GetPosition(), ECE_NONE ));
  82. //Print("spawning trigger carrier at pos :" +data.GetPosition());
  83. if (carrier)
  84. {
  85. carrier.SetIndex(index);
  86. carrier.SetOrientation(data.GetOrientation());
  87. }
  88. }
  89. //---------------------------------------------------------------------------------------
  90. static void SyncDataSend(PlayerIdentity identity)
  91. {
  92. GetGame().RPCSingleParam(null, ERPCs.RPC_UNDERGROUND_SYNC, new Param1<JsonUndergroundTriggers>(m_JsonData), true, identity);
  93. }
  94. //---------------------------------------------------------------------------------------
  95. static void OnRPC(ParamsReadContext ctx)
  96. {
  97. Param1<JsonUndergroundTriggers> data = new Param1< JsonUndergroundTriggers>(null);
  98. if ( ctx.Read(data) )
  99. {
  100. m_JsonData = data.param1;
  101. }
  102. else
  103. {
  104. ErrorEx("UndergroundAreaLoader datasynced - failed to read");
  105. }
  106. }
  107. }