plugindayzcreatureaidebug.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  1. typedef Param4<float, string, int, string> DayZCreatureAnimScriptDebugAnimEventData;
  2. typedef Param1<string> DayZCreatureAnimScriptDebugAnimPredictionData;
  3. typedef Param1<string> DayZCreatureAnimScriptDebugAnimTagData;
  4. class DayZCreatureAnimScriptDebug
  5. {
  6. proto native void SetCreature(DayZCreature creature);
  7. proto native int GetVariableCount();
  8. proto native owned string GetVariableName(int index);
  9. proto native int GetVariableType(int index);
  10. proto native int GetVariableInt(int index);
  11. proto native float GetVariableFloat(int index);
  12. proto native bool GetVariableBool(int index);
  13. proto native int SetVariableInt(int index, int value);
  14. proto native float SetVariableFloat(int index, float value);
  15. proto native bool SetVariableBool(int index, bool value);
  16. proto native int GetCommandCount();
  17. proto native owned string GetCommandName(int index);
  18. proto native int GetCommandID(int index);
  19. proto native void ActivateCommand(int index, int userInt, float userFloat);
  20. const int m_iMaxAnimEventsCount = 50;
  21. ref array<string> m_EventsFilter = new array<string>;
  22. ref array<ref DayZCreatureAnimScriptDebugAnimEventData> m_AnimEvents = new array<ref DayZCreatureAnimScriptDebugAnimEventData>;
  23. ref array<ref DayZCreatureAnimScriptDebugAnimPredictionData> m_AnimPredictions = new array<ref DayZCreatureAnimScriptDebugAnimPredictionData>;
  24. ref array<ref DayZCreatureAnimScriptDebugAnimTagData> m_AnimTags = new array<ref DayZCreatureAnimScriptDebugAnimTagData>;
  25. void OnAnimationEventsStart()
  26. {
  27. m_AnimPredictions.Clear();
  28. m_AnimTags.Clear();
  29. }
  30. void OnAnimationEvent(string evType, int userInt, string userString)
  31. {
  32. if (m_EventsFilter.Find(evType) != -1)
  33. {
  34. return;
  35. }
  36. m_AnimEvents.InsertAt(new DayZCreatureAnimScriptDebugAnimEventData(GetWorldTime(), evType, userInt, userString), 0);
  37. if (m_AnimEvents.Count() > m_iMaxAnimEventsCount)
  38. {
  39. m_AnimEvents.Remove(m_AnimEvents.Count() - 1);
  40. }
  41. }
  42. void OnAnimationPrediction(string predName)
  43. {
  44. m_AnimPredictions.Insert(new DayZCreatureAnimScriptDebugAnimPredictionData(predName));
  45. }
  46. void OnAnimationTag(string tagName)
  47. {
  48. m_AnimTags.Insert(new DayZCreatureAnimScriptDebugAnimTagData(tagName));
  49. }
  50. }
  51. enum PluginDayZCreatureAIDebugSyncMessageType
  52. {
  53. INIT_DEBUG_OBJECT,
  54. RELEASE_DEBUG_OBJECT,
  55. SET_VALUE_INT,
  56. SET_VALUE_FLOAT,
  57. SET_VALUE_BOOL,
  58. ACTIVATE_COMMAND,
  59. ENABLE_AI,
  60. DISABLE_AI,
  61. COUNT
  62. }
  63. class PluginDayZCreatureAIDebug extends PluginBase
  64. {
  65. int m_iDebugMenu = -1;
  66. DayZCreatureAI m_DebugEntity = NULL;
  67. string m_sDebugEntityName = "";
  68. ref DayZCreatureAnimScriptDebug m_EntityAnimDbg = NULL;
  69. ref Timer m_TickTimer;
  70. bool m_IsActive = false;
  71. bool m_ShowDbgUI = false;
  72. bool m_bIsCaptureMode = false;
  73. bool m_bEditMode = false;
  74. bool m_bAIEnabled = true;
  75. bool m_bShowAnimEvents = false;
  76. bool m_bBulkSet = false;
  77. ref array<bool> m_SetVariableCheckStates = new array<bool>;
  78. ref array<bool> m_SetCommandCheckStates = new array<bool>;
  79. ref array<ref Param> m_SyncMessages = new array<ref Param>;
  80. void PluginDayZCreatureAIDebug()
  81. {
  82. }
  83. void ~PluginDayZCreatureAIDebug()
  84. {
  85. }
  86. override void OnInit()
  87. {
  88. }
  89. override void OnDestroy()
  90. {
  91. }
  92. void CheckShowMode()
  93. {
  94. int actMenuValue = DiagMenu.GetEngineValue(DayZCreatureAIConstants.DEBUG_SHOWDEBUGPLUGIN);
  95. if (actMenuValue != m_iDebugMenu)
  96. {
  97. SetDebugShowMode(actMenuValue);
  98. m_iDebugMenu = actMenuValue;
  99. }
  100. }
  101. override void OnUpdate(float delta_time)
  102. {
  103. if (!GetGame().IsDedicatedServer())
  104. {
  105. CheckShowMode();
  106. }
  107. }
  108. string GetStrValue(int index)
  109. {
  110. string strVal;
  111. switch (m_EntityAnimDbg.GetVariableType(index))
  112. {
  113. case DayZCreatureAnimScriptDebugVarType.INT:
  114. int valInt = m_EntityAnimDbg.GetVariableInt(index);
  115. strVal = valInt.ToString();
  116. break;
  117. case DayZCreatureAnimScriptDebugVarType.FLOAT:
  118. float valFloat = m_EntityAnimDbg.GetVariableFloat(index);
  119. strVal = valFloat.ToString();
  120. break;
  121. case DayZCreatureAnimScriptDebugVarType.BOOL:
  122. bool valBool = m_EntityAnimDbg.GetVariableBool(index);
  123. if (valBool)
  124. {
  125. strVal = "true";
  126. }
  127. else
  128. {
  129. strVal = "false";
  130. }
  131. break;
  132. default:
  133. strVal = "unk";
  134. }
  135. return strVal;
  136. }
  137. string GetStrValueType(int index)
  138. {
  139. string strValType;
  140. switch (m_EntityAnimDbg.GetVariableType(index))
  141. {
  142. case DayZCreatureAnimScriptDebugVarType.INT:
  143. strValType = "int";
  144. break;
  145. case DayZCreatureAnimScriptDebugVarType.FLOAT:
  146. strValType = "float";
  147. break;
  148. case DayZCreatureAnimScriptDebugVarType.BOOL:
  149. strValType = "bool";
  150. break;
  151. default:
  152. strValType = "unk";
  153. }
  154. return strValType;
  155. }
  156. void InitDebugObject(Object obj)
  157. {
  158. m_EntityAnimDbg = new DayZCreatureAnimScriptDebug();
  159. m_EntityAnimDbg.SetCreature( DayZCreature.Cast( obj ) );
  160. m_DebugEntity = DayZCreatureAI.Cast( obj );
  161. m_sDebugEntityName = obj.GetType();
  162. int varCount = m_EntityAnimDbg.GetVariableCount();
  163. int cmdCount = m_EntityAnimDbg.GetCommandCount();
  164. int toAddCount = 0;
  165. if (m_SetVariableCheckStates.Count() < varCount)
  166. {
  167. toAddCount = varCount - m_SetVariableCheckStates.Count();
  168. for (int idxVar = 0; idxVar < toAddCount; idxVar++)
  169. {
  170. m_SetVariableCheckStates.Insert(false);
  171. }
  172. }
  173. if (m_SetCommandCheckStates.Count() < cmdCount)
  174. {
  175. toAddCount = cmdCount - m_SetCommandCheckStates.Count();
  176. for (int idxCmd = 0; idxCmd < toAddCount; idxCmd++)
  177. {
  178. m_SetCommandCheckStates.Insert(false);
  179. }
  180. }
  181. }
  182. void ReleaseDebugObject()
  183. {
  184. m_DebugEntity = NULL;
  185. m_EntityAnimDbg = NULL;
  186. m_sDebugEntityName = "";
  187. m_SetVariableCheckStates.Clear();
  188. m_SetCommandCheckStates.Clear();
  189. }
  190. void SetValueInt(int index, int value)
  191. {
  192. m_EntityAnimDbg.SetVariableInt(index, value);
  193. }
  194. void SetValueFloat(int index, float value)
  195. {
  196. m_EntityAnimDbg.SetVariableFloat(index, value);
  197. }
  198. void SetValueBool(int index, bool value)
  199. {
  200. m_EntityAnimDbg.SetVariableBool(index, value);
  201. }
  202. void ActivateCommand(int commandIdx, int userInt, float userFloat)
  203. {
  204. int commandId = m_EntityAnimDbg.GetCommandID(commandIdx);
  205. m_EntityAnimDbg.ActivateCommand(commandId, userInt, userFloat);
  206. }
  207. void EnableAI(bool enable)
  208. {
  209. if (m_DebugEntity.IsInherited(DayZCreatureAI))
  210. {
  211. DayZCreatureAI creatureAI = m_DebugEntity;
  212. if (enable)
  213. {
  214. #ifdef DIAG_DEVELOPER
  215. creatureAI.DebugRestoreAIControl();
  216. #endif
  217. }
  218. else
  219. {
  220. #ifdef DIAG_DEVELOPER
  221. creatureAI.DebugDisableAIControl();
  222. #endif
  223. }
  224. }
  225. }
  226. DayZCreatureAnimScriptDebugVarType GetVariableType(int index)
  227. {
  228. return m_EntityAnimDbg.GetVariableType(index);
  229. }
  230. void OnGUI_Variables()
  231. {
  232. int varCount = m_EntityAnimDbg.GetVariableCount();
  233. for (int i=0; i < varCount; i++)
  234. {
  235. DbgUI.BeginCleanupScope();
  236. DbgUI.Text(m_EntityAnimDbg.GetVariableName(i) + ": " + GetStrValue(i));
  237. DbgUI.EndCleanupScope();
  238. }
  239. }
  240. void OnGUI_VariablesEdit()
  241. {
  242. const int INPUT_BOX_SIZE = 35;
  243. DbgUI.PushID_Str("VariablesEdit");
  244. int varCount = m_EntityAnimDbg.GetVariableCount();
  245. for (int i=0; i < varCount; i++)
  246. {
  247. DbgUI.BeginCleanupScope();
  248. DbgUI.PushID_Int(i);
  249. bool result;
  250. DbgUI.Check("", result);
  251. m_SetVariableCheckStates[i] = result;
  252. DbgUI.SameLine();
  253. bool setButtonPressed = DbgUI.Button("Set");
  254. DbgUI.SameLine();
  255. string strUserVal;
  256. DbgUI.InputText(GetStrValueType(i), strUserVal, INPUT_BOX_SIZE);
  257. DbgUI.SameLine();
  258. DbgUI.Text(m_EntityAnimDbg.GetVariableName(i));
  259. if (setButtonPressed || (m_bBulkSet && m_SetVariableCheckStates[i]))
  260. {
  261. GUIAction_SetValue(i, strUserVal);
  262. }
  263. DbgUI.PopID();
  264. DbgUI.EndCleanupScope();
  265. }
  266. DbgUI.PopID();
  267. }
  268. void OnGUI_CommandsEdit()
  269. {
  270. const int INPUT_BOX_SIZE = 35;
  271. DbgUI.PushID_Str("CommandsEdit");
  272. int cmdCount = m_EntityAnimDbg.GetCommandCount();
  273. for (int i=0; i < cmdCount; i++)
  274. {
  275. DbgUI.BeginCleanupScope();
  276. DbgUI.PushID_Int(i);
  277. bool result;
  278. DbgUI.Check("", result);
  279. m_SetCommandCheckStates[i] = result;
  280. DbgUI.SameLine();
  281. bool setButtonPressed = DbgUI.Button("Set");
  282. DbgUI.SameLine();
  283. string strUserInt;
  284. DbgUI.InputText("int", strUserInt, INPUT_BOX_SIZE);
  285. DbgUI.SameLine();
  286. string strUserFloat;
  287. DbgUI.InputText("float", strUserFloat, INPUT_BOX_SIZE);
  288. DbgUI.SameLine();
  289. DbgUI.Text(m_EntityAnimDbg.GetCommandName(i) + "[" + m_EntityAnimDbg.GetCommandID(i) + "]");
  290. if (setButtonPressed || (m_bBulkSet && m_SetCommandCheckStates[i]))
  291. {
  292. GUIAction_ActivateCommand(i, strUserInt.ToInt(), strUserFloat.ToFloat());
  293. }
  294. DbgUI.PopID();
  295. DbgUI.EndCleanupScope();
  296. }
  297. DbgUI.PopID();
  298. }
  299. void OnGUI_AIControlEdit()
  300. {
  301. bool buttonPressed = false;
  302. if (m_bAIEnabled)
  303. {
  304. buttonPressed = DbgUI.Button("Disable AI");
  305. }
  306. else
  307. {
  308. buttonPressed = DbgUI.Button("Enable AI");
  309. }
  310. if (buttonPressed)
  311. {
  312. m_bAIEnabled = !m_bAIEnabled;
  313. GUIAction_EnableAI(m_bAIEnabled);
  314. }
  315. }
  316. void OnGUI_BulkSet()
  317. {
  318. m_bBulkSet = false;
  319. if (DbgUI.Button("Bulk set"))
  320. {
  321. m_bBulkSet = true;
  322. }
  323. }
  324. void OnGUI_AnimEvents()
  325. {
  326. DbgUI.PushID_Str("AnimEvents");
  327. const int panelMinSizeX = 350;
  328. DbgUI.Panel("MinimumSize", panelMinSizeX, 1);
  329. string strTags;
  330. for (int tagIdx = 0; tagIdx < m_EntityAnimDbg.m_AnimTags.Count(); ++tagIdx)
  331. {
  332. if (tagIdx != 0)
  333. strTags += ", ";
  334. strTags += m_EntityAnimDbg.m_AnimTags[tagIdx].param1;
  335. }
  336. string strPredictions;
  337. for (int predIdx = 0; predIdx < m_EntityAnimDbg.m_AnimPredictions.Count(); ++predIdx)
  338. {
  339. if (predIdx != 0)
  340. strPredictions += ", ";
  341. strPredictions += m_EntityAnimDbg.m_AnimPredictions[predIdx].param1;
  342. }
  343. DbgUI.PushID_Str("AnimTagsDisplay");
  344. DbgUI.Text(strTags);
  345. DbgUI.PopID();
  346. DbgUI.PushID_Str("AnimPredictionsDisplay");
  347. DbgUI.Text(strPredictions);
  348. DbgUI.PopID();
  349. string strFilter;
  350. DbgUI.InputText("Filter", strFilter, panelMinSizeX);
  351. m_EntityAnimDbg.m_EventsFilter.Clear();
  352. strFilter.Split(" ", m_EntityAnimDbg.m_EventsFilter);
  353. DbgUI.Button("TakeMyFocus");
  354. const int evDisplayCount = 15;
  355. int evToDisplayCount = (int)Math.Min(m_EntityAnimDbg.m_AnimEvents.Count(), evDisplayCount);
  356. for (int evIdx = 0; evIdx < evToDisplayCount; ++evIdx)
  357. {
  358. DbgUI.PushID_Int(evIdx);
  359. if (m_EntityAnimDbg.m_AnimEvents[evIdx].param2.Length() > 0)
  360. {
  361. DbgUI.Text((m_EntityAnimDbg.m_AnimEvents[evIdx].param1 / 1000.0).ToString() + " - " + m_EntityAnimDbg.m_AnimEvents[evIdx].param2);
  362. }
  363. DbgUI.PopID();
  364. }
  365. DbgUI.PopID();
  366. }
  367. void OnGUI(bool show)
  368. {
  369. const int windowPosX = 0;
  370. const int windowPosY = 300;
  371. const int mainPanelSizeX = 200;
  372. const int mainPanelSizeY = 1;
  373. const int margin = 10;
  374. DbgUI.BeginCleanupScope();
  375. DbgUI.Begin("CretureAI debug", windowPosX, windowPosY);
  376. if (show)
  377. {
  378. if (m_EntityAnimDbg == NULL)
  379. {
  380. if (m_bIsCaptureMode == true)
  381. {
  382. DbgUI.Text("Capturing...");
  383. }
  384. else
  385. {
  386. if (DbgUI.Button("Capture"))
  387. {
  388. m_bIsCaptureMode = true;
  389. }
  390. }
  391. // Clear additional windows
  392. DbgUI.Begin("CreatureAI EditMenu");
  393. DbgUI.End();
  394. DbgUI.Begin("CreatureAI AnimEvents");
  395. DbgUI.End();
  396. }
  397. else
  398. {
  399. DbgUI.Panel("MinimumSize", mainPanelSizeX, mainPanelSizeY);
  400. DbgUI.Text(m_sDebugEntityName);
  401. DbgUI.SameLine();
  402. bool btnReleasePressed = DbgUI.Button("Release");
  403. DbgUI.Check("Edit", m_bEditMode);
  404. DbgUI.Check("ShowAnimEvents", m_bShowAnimEvents);
  405. #ifdef _DAYZ_CREATURE_DEBUG_SHADOW
  406. if (!GetGame().IsMultiplayer())
  407. {
  408. DbgUI.SameLine();
  409. if (DbgUI.Button("CreateShadow"))
  410. {
  411. GUIAction_CreateShadow();
  412. }
  413. }
  414. #endif
  415. if (!GetGame().IsMultiplayer())
  416. {
  417. const int simLODInputSize = 20;
  418. int simLOD;
  419. DbgUI.InputInt("SimLOD", simLOD, simLODInputSize);
  420. DbgUI.SameLine();
  421. if (DbgUI.Button("UpdateSimulationPrecision"))
  422. {
  423. GUIAction_UpdateSimulationPrecision(simLOD);
  424. }
  425. }
  426. if (btnReleasePressed)
  427. {
  428. GUIAction_ReleaseDebugObject();
  429. }
  430. else
  431. {
  432. OnGUI_Variables();
  433. DbgUI.Begin("CreatureAI EditMenu", windowPosX + mainPanelSizeX + margin, windowPosY);
  434. if (m_bEditMode)
  435. {
  436. OnGUI_AIControlEdit();
  437. OnGUI_BulkSet();
  438. OnGUI_VariablesEdit();
  439. DbgUI.Spacer(20);
  440. OnGUI_CommandsEdit();
  441. }
  442. DbgUI.End();
  443. DbgUI.Begin("CreatureAI AnimEvents", windowPosX + mainPanelSizeX + margin, windowPosY);
  444. if (m_bShowAnimEvents)
  445. {
  446. OnGUI_AnimEvents();
  447. }
  448. DbgUI.End();
  449. }
  450. }
  451. }
  452. DbgUI.End();
  453. DbgUI.EndCleanupScope();
  454. }
  455. void OnGUITimer()
  456. {
  457. OnGUI(m_IsActive);
  458. if (GetGame().IsMultiplayer() && GetGame().IsClient())
  459. {
  460. SendSyncMessages();
  461. }
  462. }
  463. void SetDebugShowMode(int mode)
  464. {
  465. switch (mode)
  466. {
  467. case 0:
  468. {
  469. Hide();
  470. } break;
  471. case 1:
  472. {
  473. Show();
  474. } break;
  475. }
  476. }
  477. void Show()
  478. {
  479. m_IsActive = true;
  480. m_TickTimer = new Timer();
  481. m_TickTimer.Run(0.1, this, "OnGUITimer", NULL, true);
  482. }
  483. void Hide()
  484. {
  485. m_IsActive = false;
  486. m_TickTimer = NULL;
  487. OnGUI(false);
  488. }
  489. void Event_OnClick()
  490. {
  491. if (m_IsActive == false)
  492. return;
  493. const float MAX_RAYCAST_RANGE = 1000;
  494. if (m_bIsCaptureMode)
  495. {
  496. vector dir = GetGame().GetPointerDirection();
  497. vector pos = GetGame().GetCurrentCameraPosition();
  498. // Raycast
  499. vector from = pos;
  500. vector to = pos + (dir * MAX_RAYCAST_RANGE);
  501. vector contact_pos;
  502. vector contact_dir;
  503. int contact_component;
  504. set<Object> objects = new set<Object>;
  505. if (DayZPhysics.RaycastRV(from, to, contact_pos, contact_dir, contact_component, objects, NULL, GetGame().GetPlayer()))
  506. {
  507. for ( int i = 0; i < objects.Count(); i++ )
  508. {
  509. Object obj = objects.Get(i);
  510. if (obj && obj.IsInherited(DayZCreature))
  511. {
  512. m_bIsCaptureMode = false;
  513. GUIAction_InitDebugObject(obj);
  514. return;
  515. }
  516. }
  517. }
  518. }
  519. }
  520. ///
  521. //! GUI actions
  522. ///
  523. void GUIAction_InitDebugObject(Object obj)
  524. {
  525. InitDebugObject(obj);
  526. if (GetGame().IsMultiplayer())
  527. {
  528. SyncInitDebugObject(obj);
  529. }
  530. }
  531. #ifdef _DAYZ_CREATURE_DEBUG_SHADOW
  532. void GUIAction_CreateShadow()
  533. {
  534. auto shadowEntity = GetGame().CreateObject(m_sDebugEntityName, m_DebugEntity.GetPosition(), false, true);
  535. m_DebugEntity.DebugSetShadow(shadowEntity);
  536. }
  537. #endif
  538. void GUIAction_UpdateSimulationPrecision(int simLOD)
  539. {
  540. m_DebugEntity.UpdateSimulationPrecision(simLOD);
  541. }
  542. void GUIAction_ReleaseDebugObject()
  543. {
  544. ReleaseDebugObject();
  545. if (GetGame().IsMultiplayer())
  546. {
  547. SyncReleaseDebugObject();
  548. }
  549. }
  550. void GUIAction_SetValue(int index, string strVal)
  551. {
  552. switch (GetVariableType(index))
  553. {
  554. case DayZCreatureAnimScriptDebugVarType.INT:
  555. int intValue = strVal.ToInt();
  556. if (GetGame().IsMultiplayer())
  557. {
  558. SyncSetValueInt(index, intValue);
  559. }
  560. else
  561. {
  562. SetValueInt(index, intValue);
  563. }
  564. break;
  565. case DayZCreatureAnimScriptDebugVarType.FLOAT:
  566. float floatValue = strVal.ToFloat();
  567. if (GetGame().IsMultiplayer())
  568. {
  569. SyncSetValueFloat(index, floatValue);
  570. }
  571. else
  572. {
  573. SetValueFloat(index, floatValue);
  574. }
  575. break;
  576. case DayZCreatureAnimScriptDebugVarType.BOOL:
  577. bool boolValue;
  578. strVal.ToLower();
  579. if (strVal.Contains("true"))
  580. {
  581. boolValue = true;
  582. }
  583. else if (strVal.Contains("false"))
  584. {
  585. boolValue = false;
  586. }
  587. else
  588. {
  589. boolValue = (bool)strVal.ToInt();
  590. }
  591. if (GetGame().IsMultiplayer())
  592. {
  593. SyncSetValueBool(index, boolValue);
  594. }
  595. else
  596. {
  597. SetValueBool(index, boolValue);
  598. }
  599. break;
  600. }
  601. }
  602. void GUIAction_ActivateCommand(int commandIdx, int userInt, float userFloat)
  603. {
  604. if (GetGame().IsMultiplayer())
  605. {
  606. SyncActivateCommand(commandIdx, userInt, userFloat);
  607. }
  608. else
  609. {
  610. ActivateCommand(commandIdx, userInt, userFloat);
  611. }
  612. }
  613. void GUIAction_EnableAI(bool enable)
  614. {
  615. if (GetGame().IsMultiplayer())
  616. {
  617. SyncEnableAI(enable);
  618. }
  619. else
  620. {
  621. EnableAI(enable);
  622. }
  623. }
  624. ///
  625. //! sync
  626. ///
  627. void SendSyncMessages()
  628. {
  629. int count = m_SyncMessages.Count();
  630. if (count > 0)
  631. {
  632. Param1<int> paramCount = new Param1<int>(count);
  633. m_SyncMessages.InsertAt(paramCount, 0);
  634. GetGame().GetPlayer().RPC(ERPCs.DEV_RPC_PLUGIN_DZCREATURE_DEBUG, m_SyncMessages, true);
  635. m_SyncMessages.Clear();
  636. }
  637. }
  638. void OnRpc(PlayerBase player, int rpc_type, ParamsReadContext ctx)
  639. {
  640. if (rpc_type == ERPCs.DEV_RPC_PLUGIN_DZCREATURE_DEBUG)
  641. {
  642. SyncReceiveMessage(ctx);
  643. }
  644. }
  645. void SyncReceiveMessage(ParamsReadContext ctx)
  646. {
  647. Param1<int> count = new Param1<int>(0);
  648. if (ctx.Read(count))
  649. {
  650. Param1<int> type = new Param1<int>(PluginDayZCreatureAIDebugSyncMessageType.COUNT);
  651. for (int i=0; i < count.param1; ++i)
  652. {
  653. if (ctx.Read(type))
  654. {
  655. switch (type.param1)
  656. {
  657. case PluginDayZCreatureAIDebugSyncMessageType.INIT_DEBUG_OBJECT:
  658. SyncReceiveInitDebugObject(ctx);
  659. break;
  660. case PluginDayZCreatureAIDebugSyncMessageType.RELEASE_DEBUG_OBJECT:
  661. SyncReceiveReleaseDebugObject(ctx);
  662. break;
  663. case PluginDayZCreatureAIDebugSyncMessageType.SET_VALUE_INT:
  664. SyncReceiveValueInt(ctx);
  665. break;
  666. case PluginDayZCreatureAIDebugSyncMessageType.SET_VALUE_FLOAT:
  667. SyncReceiveValueFloat(ctx);
  668. break;
  669. case PluginDayZCreatureAIDebugSyncMessageType.SET_VALUE_BOOL:
  670. SyncReceiveValueBool(ctx);
  671. break;
  672. case PluginDayZCreatureAIDebugSyncMessageType.ACTIVATE_COMMAND:
  673. SyncReceiveActivateCommand(ctx);
  674. break;
  675. case PluginDayZCreatureAIDebugSyncMessageType.ENABLE_AI:
  676. SyncReceiveEnableAI(ctx);
  677. break;
  678. case PluginDayZCreatureAIDebugSyncMessageType.DISABLE_AI:
  679. SyncReceiveDisableAI(ctx);
  680. break;
  681. }
  682. }
  683. type.param1 = PluginDayZCreatureAIDebugSyncMessageType.COUNT;
  684. }
  685. }
  686. }
  687. void SyncInitDebugObject(Object obj)
  688. {
  689. Param1<int> type = new Param1<int>(PluginDayZCreatureAIDebugSyncMessageType.INIT_DEBUG_OBJECT);
  690. Param1<Object> object = new Param1<Object>(obj);
  691. m_SyncMessages.Insert(type);
  692. m_SyncMessages.Insert(object);
  693. }
  694. void SyncReceiveInitDebugObject(ParamsReadContext ctx)
  695. {
  696. Param1<Object> object = new Param1<Object>(NULL);
  697. if (ctx.Read(object))
  698. {
  699. InitDebugObject(object.param1);
  700. }
  701. }
  702. void SyncReleaseDebugObject()
  703. {
  704. Param1<int> type = new Param1<int>(PluginDayZCreatureAIDebugSyncMessageType.RELEASE_DEBUG_OBJECT);
  705. m_SyncMessages.Insert(type);
  706. }
  707. void SyncReceiveReleaseDebugObject(ParamsReadContext ctx)
  708. {
  709. ReleaseDebugObject();
  710. }
  711. void SyncSetValueInt(int index, int value)
  712. {
  713. Param1<int> type = new Param1<int>(PluginDayZCreatureAIDebugSyncMessageType.SET_VALUE_INT);
  714. Param2<int, int> paramValue = new Param2<int, int>(index, value);
  715. m_SyncMessages.Insert(type);
  716. m_SyncMessages.Insert(paramValue);
  717. }
  718. void SyncReceiveValueInt(ParamsReadContext ctx)
  719. {
  720. Param2<int, int> paramValue = new Param2<int, int>(-1, 0);
  721. if (ctx.Read(paramValue))
  722. {
  723. SetValueInt(paramValue.param1, paramValue.param2);
  724. }
  725. }
  726. void SyncSetValueFloat(int index, float value)
  727. {
  728. Param1<int> type = new Param1<int>(PluginDayZCreatureAIDebugSyncMessageType.SET_VALUE_FLOAT);
  729. Param2<int, float> paramValue = new Param2<int, float>(index, value);
  730. m_SyncMessages.Insert(type);
  731. m_SyncMessages.Insert(paramValue);
  732. }
  733. void SyncReceiveValueFloat(ParamsReadContext ctx)
  734. {
  735. Param2<int, float> paramValue = new Param2<int, float>(-1, 0.0);
  736. if (ctx.Read(paramValue))
  737. {
  738. SetValueFloat(paramValue.param1, paramValue.param2);
  739. }
  740. }
  741. void SyncSetValueBool(int index, bool value)
  742. {
  743. Param1<int> type = new Param1<int>(PluginDayZCreatureAIDebugSyncMessageType.SET_VALUE_BOOL);
  744. Param2<int, bool> paramValue = new Param2<int, bool>(index, value);
  745. m_SyncMessages.Insert(type);
  746. m_SyncMessages.Insert(paramValue);
  747. }
  748. void SyncReceiveValueBool(ParamsReadContext ctx)
  749. {
  750. Param2<int, bool> paramValue = new Param2<int, bool>(-1, false);
  751. if (ctx.Read(paramValue))
  752. {
  753. SetValueBool(paramValue.param1, paramValue.param2);
  754. }
  755. }
  756. void SyncActivateCommand(int commandIdx, int userInt, float userFloat)
  757. {
  758. Param1<int> type = new Param1<int>(PluginDayZCreatureAIDebugSyncMessageType.ACTIVATE_COMMAND);
  759. Param3<int, int, float> command = new Param3<int, int, float>(commandIdx, userInt, userFloat);
  760. m_SyncMessages.Insert(type);
  761. m_SyncMessages.Insert(command);
  762. }
  763. void SyncReceiveActivateCommand(ParamsReadContext ctx)
  764. {
  765. Param3<int, int, float> command = new Param3<int, int, float>(-1, 0, 0.0);
  766. if (ctx.Read(command))
  767. {
  768. ActivateCommand(command.param1, command.param2, command.param3);
  769. }
  770. }
  771. void SyncEnableAI(bool enable)
  772. {
  773. Param1<int> type = new Param1<int>(PluginDayZCreatureAIDebugSyncMessageType.COUNT);
  774. if (enable)
  775. {
  776. type.param1 = PluginDayZCreatureAIDebugSyncMessageType.ENABLE_AI;
  777. }
  778. else
  779. {
  780. type.param1 = PluginDayZCreatureAIDebugSyncMessageType.DISABLE_AI;
  781. }
  782. m_SyncMessages.Insert(type);
  783. }
  784. void SyncReceiveEnableAI(ParamsReadContext ctx)
  785. {
  786. EnableAI(true);
  787. }
  788. void SyncReceiveDisableAI(ParamsReadContext ctx)
  789. {
  790. EnableAI(false);
  791. }
  792. }