emotemanager.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221
  1. class EmoteCB : HumanCommandActionCallback
  2. {
  3. bool m_IsFullbody;
  4. int m_callbackID; //Animation cmd ID
  5. PlayerBase m_player;
  6. EmoteManager m_Manager;
  7. void ~EmoteCB()
  8. {
  9. if (m_Manager)
  10. {
  11. m_Manager.OnCallbackEnd();
  12. }
  13. if (GetGame() && m_player)
  14. m_player.RequestHandAnimationStateRefresh();
  15. }
  16. bool CancelCondition()
  17. {
  18. return false;
  19. }
  20. bool IsEmoteCallback()
  21. {
  22. return IsGestureCallback();
  23. }
  24. override void OnAnimationEvent(int pEventID)
  25. {
  26. switch (pEventID)
  27. {
  28. case EmoteConstants.EMOTE_SUICIDE_DEATH :
  29. if (GetGame().IsServer())
  30. m_Manager.KillPlayer();
  31. m_Manager.LogSuicide();
  32. break;
  33. case UA_ANIM_EVENT :
  34. if (m_callbackID == DayZPlayerConstants.CMD_GESTUREFB_SURRENDERIN)
  35. m_Manager.m_ItemToBeCreated = true;
  36. break;
  37. case EmoteConstants.EMOTE_SUICIDE_BLEED :
  38. if (GetGame().IsServer())
  39. m_Manager.CreateBleedingEffect(m_callbackID);
  40. break;
  41. case EmoteConstants.EMOTE_SUICIDE_SIMULATION_END :
  42. if (GetGame().IsServer())
  43. {
  44. EntityAI itemInHands = m_player.GetHumanInventory().GetEntityInHands();
  45. if (itemInHands)
  46. {
  47. vector m4[4];
  48. itemInHands.GetTransform(m4);
  49. m_player.GetInventory().DropEntityWithTransform(InventoryMode.SERVER, m_player, itemInHands, m4);
  50. }
  51. }
  52. m_player.StartDeath();
  53. break;
  54. }
  55. }
  56. override bool IsGestureCallback()
  57. {
  58. return true;
  59. }
  60. };
  61. class EmoteLauncher
  62. {
  63. static const int FORCE_NONE = 0;
  64. static const int FORCE_DIFFERENT = 1;
  65. static const int FORCE_ALL = 2;
  66. protected bool m_InterruptsSameIDEmote;
  67. protected int m_ForcePlayEmote;
  68. protected int m_ID;
  69. void EmoteLauncher(int emoteID, bool interrupts_same)
  70. {
  71. m_ID = emoteID;
  72. m_InterruptsSameIDEmote = interrupts_same;
  73. m_ForcePlayEmote = FORCE_NONE;
  74. }
  75. void SetForced(int mode)
  76. {
  77. m_ForcePlayEmote = mode;
  78. }
  79. int GetForced()
  80. {
  81. return m_ForcePlayEmote;
  82. }
  83. int GetID()
  84. {
  85. return m_ID;
  86. }
  87. }
  88. class EmoteManager
  89. {
  90. PlayerBase m_Player;
  91. ItemBase m_item;
  92. EmoteCB m_Callback;
  93. HumanInputController m_HIC;
  94. ref array<string> m_InterruptInputs;
  95. ref array<UAInput> m_InterruptInputDirect;
  96. ref InventoryLocation m_HandInventoryLocation;
  97. ref EmoteLauncher m_MenuEmote;
  98. bool m_bEmoteIsRequestPending;
  99. bool m_bEmoteIsPlaying;
  100. bool m_IsSurrendered;
  101. bool m_ItemToBeCreated;
  102. bool m_CancelEmote;
  103. bool m_InstantCancelEmote;
  104. bool m_GestureInterruptInput;
  105. protected bool m_ItemToHands; //deprecated
  106. protected bool m_ItemIsOn;
  107. protected bool m_MouseButtonPressed;
  108. protected bool m_PlayerDies;
  109. protected bool m_controllsLocked;
  110. protected bool m_InventoryAccessLocked;
  111. protected bool m_EmoteLockState;
  112. protected int m_DeferredEmoteExecution;
  113. protected int m_GestureID;
  114. protected int m_PreviousGestureID;
  115. protected int m_CurrentGestureID;
  116. protected int m_LastMask;
  117. protected int m_RPSOutcome;
  118. protected int m_InterruptInputsCount;
  119. protected const int CALLBACK_CMD_INVALID = -1;
  120. protected const int CALLBACK_CMD_END = -2;
  121. protected const int CALLBACK_CMD_GESTURE_INTERRUPT = -3;
  122. protected const int CALLBACK_CMD_INSTACANCEL = -4;
  123. PluginAdminLog m_AdminLog;
  124. protected ref Timer m_ReservationTimer;
  125. protected ref map<int, ref EmoteBase> m_NameEmoteMap; //<emote_ID,EmoteBase>
  126. protected ref array<ref EmoteBase> m_EmoteClassArray; //registered 'EmoteBase' object refs
  127. protected ref array<int> m_EmoteIDs; //IDs of registered emotes (found in 'EmoteConstants'). For quick access.
  128. protected ref array<int> m_EmoteInputIDs; //input IDs for the registered 'EmoteBase' objects
  129. protected SHumanCommandSwimSettings m_HumanSwimSettings;
  130. void EmoteManager(PlayerBase player)
  131. {
  132. m_Player = player;
  133. m_HIC = m_Player.GetInputController();
  134. m_ItemIsOn = false;
  135. m_controllsLocked = false;
  136. m_InventoryAccessLocked = false;
  137. m_RPSOutcome = -1;
  138. m_DeferredEmoteExecution = CALLBACK_CMD_INVALID;
  139. m_InterruptInputs = new array<string>;
  140. m_InterruptInputs.Insert("UAMoveForward");
  141. m_InterruptInputs.Insert("UAMoveBack");
  142. m_InterruptInputs.Insert("UATurnLeft");
  143. m_InterruptInputs.Insert("UATurnRight");
  144. m_InterruptInputs.Insert("UAMoveLeft");
  145. m_InterruptInputs.Insert("UAMoveRight");
  146. m_InterruptInputs.Insert("UAStand");
  147. m_InterruptInputs.Insert("UACrouch");
  148. m_InterruptInputs.Insert("UAProne");
  149. m_InterruptInputs.Insert("UAGetOver");
  150. m_HandInventoryLocation = new InventoryLocation();
  151. m_HandInventoryLocation.SetHands(m_Player, null);
  152. if (GetGame().IsServer())
  153. {
  154. m_AdminLog = PluginAdminLog.Cast(GetPlugin(PluginAdminLog));
  155. }
  156. m_ReservationTimer = new Timer();
  157. m_ReservationTimer.Run(8, this, "CheckEmoteLockedState", null, true);
  158. m_HumanSwimSettings = m_Player.GetDayZPlayerType().CommandSwimSettingsW();
  159. ConstructData();
  160. }
  161. void ~EmoteManager()
  162. {
  163. if (m_ReservationTimer && m_ReservationTimer.IsRunning())
  164. m_ReservationTimer.Stop();
  165. }
  166. void ConstructData()
  167. {
  168. EmoteConstructor ec = new EmoteConstructor;
  169. if (!m_NameEmoteMap)
  170. {
  171. ec.ConstructEmotes(m_Player,m_NameEmoteMap);
  172. m_EmoteClassArray = new array<ref EmoteBase>;
  173. m_EmoteIDs = new array<int>;
  174. m_EmoteInputIDs = new array<int>;
  175. int inputID;
  176. int count = m_NameEmoteMap.Count();
  177. UAInput inp;
  178. for (int i = 0; i < count; i++)
  179. {
  180. m_EmoteClassArray.Insert(m_NameEmoteMap.GetElement(i));
  181. m_EmoteIDs.Insert(m_NameEmoteMap.GetElement(i).GetID());
  182. inp = GetUApi().GetInputByName(m_NameEmoteMap.GetElement(i).GetInputActionName());
  183. inputID = inp.ID();
  184. m_EmoteInputIDs.Insert(inputID);
  185. }
  186. if (m_EmoteInputIDs.Count() != m_EmoteClassArray.Count())
  187. {
  188. ErrorEx("Faulty emote data detected in 'ConstructData' method!",ErrorExSeverity.WARNING);
  189. }
  190. }
  191. }
  192. void SetGesture(int id)
  193. {
  194. m_GestureID = id;
  195. }
  196. int GetGesture()
  197. {
  198. return m_GestureID;
  199. }
  200. int DetermineGestureIndex()
  201. {
  202. int count = m_EmoteInputIDs.Count();
  203. for (int i = 0; i < count; ++i)
  204. {
  205. if (GetUApi().GetInputByID(m_EmoteInputIDs[i]).LocalPress())
  206. {
  207. return m_EmoteIDs[i];
  208. }
  209. }
  210. return 0;
  211. }
  212. //! Also includes a stance check for FB callbacks
  213. bool DetermineEmoteData(EmoteBase emote, out int callback_ID, out int stancemask, out bool is_fullbody)
  214. {
  215. if (emote.DetermineOverride(callback_ID, stancemask, is_fullbody))
  216. {
  217. return emote.EmoteFBStanceCheck(stancemask);
  218. }
  219. else if (emote.GetAdditiveCallbackUID() != 0 && m_Player.IsPlayerInStance(emote.GetStanceMaskAdditive()))
  220. {
  221. callback_ID = emote.GetAdditiveCallbackUID();
  222. stancemask = emote.GetStanceMaskAdditive();
  223. is_fullbody = false;
  224. return true;
  225. }
  226. else if (emote.GetFullbodyCallbackUID() != 0 && emote.EmoteFBStanceCheck(emote.GetStanceMaskFullbody()))
  227. {
  228. callback_ID = emote.GetFullbodyCallbackUID();
  229. stancemask = emote.GetStanceMaskFullbody();
  230. is_fullbody = true;
  231. return true;
  232. }
  233. return false;
  234. }
  235. //Called from players commandhandler each frame, checks input
  236. void Update(float deltaT)
  237. {
  238. // no updates on restrained characters
  239. if (m_Player.IsRestrained())
  240. return;
  241. if (m_ItemToBeCreated)
  242. {
  243. if (!m_Player.GetItemInHands() && GetGame().IsServer())
  244. {
  245. m_Player.GetHumanInventory().CreateInHands("SurrenderDummyItem");
  246. }
  247. m_ItemToBeCreated = false;
  248. }
  249. int gestureSlot = 0;
  250. #ifndef SERVER
  251. gestureSlot = DetermineGestureIndex();
  252. #endif
  253. //deferred emote cancel
  254. if (m_InstantCancelEmote) //'hard' cancel
  255. {
  256. if (m_Callback)
  257. {
  258. m_Callback.Cancel();
  259. }
  260. if (m_MenuEmote)
  261. {
  262. m_MenuEmote = null;
  263. }
  264. m_DeferredEmoteExecution = CALLBACK_CMD_INVALID;
  265. m_InstantCancelEmote = false;
  266. m_bEmoteIsRequestPending = false;
  267. SetEmoteLockState(false);
  268. }
  269. else if (m_CancelEmote) //'soft' cancel
  270. {
  271. if (m_IsSurrendered)
  272. {
  273. EndSurrenderRequest(new SurrenderData);
  274. }
  275. else if (m_Callback)
  276. {
  277. m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_INTERRUPT);
  278. }
  279. m_bEmoteIsRequestPending = false;
  280. m_CancelEmote = false;
  281. }
  282. if (m_MenuEmote && m_MenuEmote.GetForced() > EmoteLauncher.FORCE_NONE && !GetGame().IsDedicatedServer()) //forced emote playing
  283. {
  284. SendEmoteRequestSync(m_MenuEmote.GetID());
  285. }
  286. else if (m_Callback)
  287. {
  288. bool uiGesture = false;
  289. if (!GetGame().IsDedicatedServer())
  290. {
  291. uiGesture = GetGame().GetUIManager().IsMenuOpen(MENU_GESTURES);
  292. if (InterruptGestureCheck())
  293. {
  294. SendEmoteRequestSync(CALLBACK_CMD_END);
  295. }
  296. if (InterruptWaterCheck())
  297. {
  298. SendEmoteRequestSync(CALLBACK_CMD_INSTACANCEL);
  299. }
  300. }
  301. if (gestureSlot > 0 || m_GestureInterruptInput || (m_HIC.IsSingleUse() && !uiGesture) || (m_HIC.IsContinuousUseStart() && !uiGesture) || (m_Callback.m_IsFullbody && !uiGesture && m_HIC.IsWeaponRaised()))
  302. {
  303. if (m_CurrentGestureID == EmoteConstants.ID_EMOTE_SUICIDE && m_HIC.IsSingleUse())
  304. {
  305. if (m_Callback.GetState() == m_Callback.STATE_LOOP_LOOP)
  306. {
  307. CommitSuicide();
  308. }
  309. else
  310. {
  311. return;
  312. }
  313. }
  314. else if ((m_CurrentGestureID == EmoteConstants.ID_EMOTE_THUMB || m_CurrentGestureID == EmoteConstants.ID_EMOTE_THUMBDOWN) && m_HIC.IsSingleUse())
  315. {
  316. m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_ACTION);
  317. }
  318. else if (m_HIC.IsSingleUse() && (m_CurrentGestureID == EmoteConstants.ID_EMOTE_RPS || m_CurrentGestureID == EmoteConstants.ID_EMOTE_RPS_R || m_CurrentGestureID == EmoteConstants.ID_EMOTE_RPS_P || m_CurrentGestureID == EmoteConstants.ID_EMOTE_RPS_S))
  319. {
  320. if (m_RPSOutcome != -1)
  321. {
  322. if (m_RPSOutcome == 0)
  323. {
  324. m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_RPS_ROCK);
  325. }
  326. else if (m_RPSOutcome == 1)
  327. {
  328. m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_RPS_PAPER);
  329. }
  330. else if (m_RPSOutcome == 2)
  331. {
  332. m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_RPS_SCISSORS);
  333. }
  334. m_RPSOutcome = -1;
  335. }
  336. else
  337. {
  338. m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_END);
  339. }
  340. }
  341. else if (m_CurrentGestureID != EmoteConstants.ID_EMOTE_SUICIDE || (m_CurrentGestureID == EmoteConstants.ID_EMOTE_SUICIDE && m_Callback.GetState() < 3))
  342. {
  343. SendEmoteRequestSync(CALLBACK_CMD_END);
  344. }
  345. else if (m_CurrentGestureID == EmoteConstants.ID_EMOTE_SUICIDE)
  346. {
  347. SendEmoteRequestSync(CALLBACK_CMD_END);
  348. }
  349. }
  350. if (m_LastMask != -1 && m_Player.IsPlayerInStance(DayZPlayerConstants.STANCEMASK_PRONE))
  351. {
  352. m_Callback.Cancel();
  353. }
  354. if (m_MenuEmote && m_bEmoteIsPlaying)
  355. {
  356. SendEmoteRequestSync(CALLBACK_CMD_END);
  357. }
  358. if (m_DeferredEmoteExecution == CALLBACK_CMD_END)
  359. {
  360. EndCallbackCommand();
  361. }
  362. if (m_DeferredEmoteExecution == CALLBACK_CMD_GESTURE_INTERRUPT)
  363. {
  364. InterruptCallbackCommand();
  365. }
  366. }
  367. //no m_Callback exists
  368. else
  369. {
  370. if (m_bEmoteIsRequestPending && (m_Player.IsUnconscious() || !m_Player.IsAlive()))
  371. {
  372. m_bEmoteIsRequestPending = false;
  373. }
  374. if (m_bEmoteIsPlaying)
  375. {
  376. OnEmoteEnd();
  377. }
  378. else if (!m_Player.GetItemInHands() && m_IsSurrendered && !m_ItemToBeCreated && (!m_MenuEmote || m_MenuEmote.GetForced() != EmoteLauncher.FORCE_NONE)) //play only when there is time to do so
  379. {
  380. PlaySurrenderInOut(false);
  381. return;
  382. }
  383. // getting out of surrender state - hard cancel
  384. else if (m_IsSurrendered && (m_HIC.IsSingleUse() || m_HIC.IsContinuousUseStart() || m_HIC.IsWeaponRaised()))
  385. {
  386. if (m_Player.GetItemInHands())
  387. m_Player.GetItemInHands().DeleteSafe();//Note, this keeps item 'alive' until it is released by all the systems (inventory swapping etc.)
  388. return;
  389. }
  390. // fallback in case lock does not end properly
  391. else if (m_IsSurrendered && (!m_Player.GetItemInHands() || (m_Player.GetItemInHands() && m_Player.GetItemInHands().GetType() != "SurrenderDummyItem" && m_EmoteLockState)))
  392. {
  393. m_IsSurrendered = false;
  394. SetEmoteLockState(false);
  395. return;
  396. }
  397. //actual emote launch
  398. else if (m_DeferredEmoteExecution > CALLBACK_CMD_INVALID)
  399. {
  400. PlayEmote(m_DeferredEmoteExecution);
  401. }
  402. //client-side emote launcher
  403. else if (!m_bEmoteIsPlaying && m_MenuEmote && !GetGame().IsDedicatedServer())
  404. {
  405. SendEmoteRequestSync(m_MenuEmote.GetID());
  406. }
  407. else if (!m_MenuEmote && gestureSlot > 0)
  408. {
  409. CreateEmoteCBFromMenu(gestureSlot,true); //translation no longer needed
  410. }
  411. }
  412. }
  413. void OnEmoteEnd()
  414. {
  415. ShowItemInHands();
  416. if (m_PlayerDies)
  417. {
  418. m_Player.SetHealth(0.0);
  419. return;
  420. }
  421. //surrender "state" switch
  422. if (m_CurrentGestureID == EmoteConstants.ID_EMOTE_SURRENDER)
  423. {
  424. m_IsSurrendered = !m_IsSurrendered;
  425. SetEmoteLockState(m_IsSurrendered);
  426. }
  427. m_CurrentGestureID = 0;
  428. m_bEmoteIsPlaying = false;
  429. m_bEmoteIsRequestPending = false;
  430. if (m_IsSurrendered)
  431. {
  432. return;
  433. }
  434. m_GestureInterruptInput = false;
  435. SetEmoteLockState(false);
  436. // back to the default - shoot from camera - if not set already
  437. if (!m_Player.IsShootingFromCamera())
  438. m_Player.OverrideShootFromCamera(true);
  439. }
  440. //server-side
  441. bool OnInputUserDataProcess(int userDataType, ParamsReadContext ctx)
  442. {
  443. if (userDataType == INPUT_UDT_GESTURE)
  444. {
  445. int forced = EmoteLauncher.FORCE_NONE;
  446. int gestureID = -1;
  447. int random = -1;
  448. if (ctx.Read(gestureID))
  449. {
  450. ctx.Read(forced);
  451. if (ctx.Read(random))
  452. {
  453. m_RPSOutcome = random;
  454. }
  455. //server-side check, sends CALLBACK_CMD_INSTACANCEL as a fail
  456. if (forced == EmoteLauncher.FORCE_NONE && !CanPlayEmote(gestureID))
  457. gestureID = CALLBACK_CMD_INSTACANCEL;
  458. ScriptJunctureData pCtx = new ScriptJunctureData;
  459. pCtx.Write(gestureID);
  460. pCtx.Write(forced);
  461. m_Player.SendSyncJuncture(DayZPlayerSyncJunctures.SJ_GESTURE_REQUEST, pCtx);
  462. m_bEmoteIsRequestPending = true;
  463. }
  464. return true;
  465. }
  466. return false;
  467. }
  468. //server and client
  469. void OnSyncJuncture(int pJunctureID, ParamsReadContext pCtx)
  470. {
  471. int forced;
  472. int gesture_id;
  473. if (!m_CancelEmote)
  474. {
  475. pCtx.Read(gesture_id);
  476. pCtx.Read(forced);
  477. EmoteBase emoteData;
  478. if ((m_Callback || m_IsSurrendered) && (forced == EmoteLauncher.FORCE_ALL || (forced == EmoteLauncher.FORCE_DIFFERENT && m_CurrentGestureID != gesture_id)))
  479. {
  480. if (m_Callback)
  481. {
  482. if (m_NameEmoteMap.Find(m_CurrentGestureID,emoteData) && emoteData.CanBeCanceledNormally(m_Callback))
  483. m_CancelEmote = true;
  484. else
  485. return;
  486. }
  487. m_CancelEmote = true;
  488. }
  489. if (gesture_id == CALLBACK_CMD_INSTACANCEL)
  490. {
  491. if (m_Callback)
  492. {
  493. if (m_NameEmoteMap.Find(m_CurrentGestureID,emoteData) && !emoteData.CanBeCanceledNormally(m_Callback))
  494. {
  495. m_InstantCancelEmote = false;
  496. return;
  497. }
  498. }
  499. m_InstantCancelEmote = true;
  500. }
  501. m_DeferredEmoteExecution = gesture_id;
  502. }
  503. else
  504. m_CancelEmote = false;
  505. }
  506. void OnCallbackEnd()
  507. {
  508. EmoteBase emoteData;
  509. if (m_NameEmoteMap.Find(m_CurrentGestureID,emoteData))
  510. emoteData.OnCallbackEnd();
  511. }
  512. void AfterStoreLoad()
  513. {
  514. if (m_Player.GetItemInHands() && SurrenderDummyItem.Cast(m_Player.GetItemInHands()))
  515. m_Player.GetItemInHands().Delete();
  516. }
  517. bool PlayEmote(int id)
  518. {
  519. m_DeferredEmoteExecution = CALLBACK_CMD_INVALID;
  520. m_bEmoteIsRequestPending = false;
  521. if (CanPlayEmote(id))
  522. {
  523. if (m_AdminLog)
  524. m_AdminLog.LogPrint("[emote] " + Object.GetDebugName(m_Player) + " play emote id=" + id + " IH=" + Object.GetDebugName(m_Player.GetItemInHands()));
  525. m_PreviousGestureID = m_CurrentGestureID;
  526. m_CurrentGestureID = id;
  527. if (id > 0)
  528. {
  529. EmoteBase emote;
  530. if (m_NameEmoteMap.Find(id,emote))
  531. {
  532. int callback_ID;
  533. int stancemask;
  534. bool is_fullbody;
  535. if (DetermineEmoteData(emote,callback_ID,stancemask,is_fullbody))
  536. {
  537. if (!emote.EmoteStartOverride(EmoteCB,callback_ID,stancemask,is_fullbody))
  538. {
  539. emote.OnBeforeStandardCallbackCreated(callback_ID,stancemask,is_fullbody);
  540. CreateEmoteCallback(EmoteCB,callback_ID,stancemask,is_fullbody);
  541. }
  542. if (emote.GetHideItemInHands())
  543. {
  544. HideItemInHands();
  545. }
  546. }
  547. else
  548. {
  549. ErrorEx("EmoteManager | DetermineEmoteData failed!");
  550. }
  551. }
  552. }
  553. }
  554. SetEmoteLockState(m_bEmoteIsPlaying);
  555. return m_bEmoteIsPlaying;
  556. }
  557. //creates Emote callback
  558. protected void CreateEmoteCallback(typename callbacktype, int id, int mask, bool fullbody)
  559. {
  560. if (m_Player)
  561. {
  562. m_LastMask = -1;
  563. if (fullbody)
  564. {
  565. Class.CastTo(m_Callback, m_Player.StartCommand_Action(id,callbacktype,mask));
  566. m_Callback.m_IsFullbody = true;
  567. m_Callback.EnableCancelCondition(true);
  568. }
  569. else if (m_Player.IsPlayerInStance(mask))
  570. {
  571. m_LastMask = mask; //character is probably not prone now
  572. Class.CastTo(m_Callback, m_Player.AddCommandModifier_Action(id,callbacktype));
  573. }
  574. if (m_Callback)
  575. {
  576. m_bEmoteIsPlaying = true;
  577. m_Callback.m_callbackID = id;
  578. m_Callback.m_player = m_Player;
  579. m_Callback.m_Manager = this;
  580. }
  581. }
  582. }
  583. protected void HideItemInHands()
  584. {
  585. m_item = m_Player.GetItemInHands();
  586. if (m_Callback && m_item)
  587. {
  588. m_Player.TryHideItemInHands(true);
  589. }
  590. }
  591. protected void ShowItemInHands()
  592. {
  593. if (m_item)
  594. {
  595. m_Player.TryHideItemInHands(false);
  596. }
  597. }
  598. protected void CommitSuicide()
  599. {
  600. Weapon_Base weapon;
  601. WeaponEventBase weapon_event = new WeaponEventTrigger;
  602. if (Weapon_Base.CastTo(weapon,m_Player.GetItemInHands()))
  603. {
  604. if (weapon.CanFire())
  605. {
  606. m_Callback.RegisterAnimationEvent("Simulation_End",EmoteConstants.EMOTE_SUICIDE_SIMULATION_END);
  607. m_Player.SetSuicide(true);
  608. weapon.ProcessWeaponEvent(weapon_event);
  609. m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_FINISH);
  610. if (m_Player.IsAlive())
  611. {
  612. EntityAI helm = m_Player.FindAttachmentBySlotName("Headgear");
  613. if (helm && GetGame().IsServer())
  614. {
  615. float damage = helm.GetMaxHealth("","");
  616. helm.AddHealth("","", -damage/2);
  617. }
  618. GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).Call(this.KillPlayer);
  619. if (m_AdminLog)
  620. {
  621. m_AdminLog.Suicide(m_Player);
  622. }
  623. }
  624. }
  625. else
  626. {
  627. if (!weapon.IsDamageDestroyed())
  628. {
  629. weapon.ProcessWeaponEvent(weapon_event);
  630. }
  631. m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_END);
  632. }
  633. }
  634. else if (m_Player.GetItemInHands() && m_Player.GetItemInHands().ConfigIsExisting("suicideAnim"))
  635. {
  636. m_Callback.RegisterAnimationEvent("Death",EmoteConstants.EMOTE_SUICIDE_DEATH);
  637. m_Callback.RegisterAnimationEvent("Bleed",EmoteConstants.EMOTE_SUICIDE_BLEED);
  638. m_Callback.RegisterAnimationEvent("Simulation_End",EmoteConstants.EMOTE_SUICIDE_SIMULATION_END);
  639. m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_FINISH);
  640. m_Player.SetSuicide(true);
  641. }
  642. else
  643. {
  644. m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_FINISH);
  645. }
  646. }
  647. void KillPlayer()
  648. {
  649. if (GetGame().IsServer())
  650. {
  651. m_Player.SetHealth(0);
  652. }
  653. }
  654. void LogSuicide()
  655. {
  656. if (GetGame().IsServer())
  657. {
  658. PlayerIdentity identity = m_Player.GetIdentity();
  659. if (identity)
  660. {
  661. if (m_AdminLog)
  662. m_AdminLog.Suicide(m_Player);
  663. }
  664. }
  665. }
  666. void CreateEmoteCBFromMenu(int id, bool interrupts_same = false)
  667. {
  668. m_MenuEmote = new EmoteLauncher(id,interrupts_same);
  669. }
  670. EmoteLauncher GetEmoteLauncher()
  671. {
  672. return m_MenuEmote;
  673. }
  674. void InterruptCallbackCommand()
  675. {
  676. m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_INTERRUPT);
  677. if (m_MenuEmote)
  678. m_MenuEmote = null;
  679. m_DeferredEmoteExecution = CALLBACK_CMD_INVALID;
  680. }
  681. void EndCallbackCommand()
  682. {
  683. if (m_CurrentGestureID == EmoteConstants.ID_EMOTE_DANCE)
  684. {
  685. m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_INTERRUPT);
  686. }
  687. else
  688. {
  689. m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_END);
  690. }
  691. if (m_MenuEmote)
  692. m_MenuEmote = null;
  693. m_DeferredEmoteExecution = CALLBACK_CMD_INVALID;
  694. }
  695. //sends request (client)
  696. void SendEmoteRequestSync(int id)
  697. {
  698. int forced = EmoteLauncher.FORCE_NONE;
  699. if (m_MenuEmote)
  700. {
  701. forced = m_MenuEmote.GetForced();
  702. }
  703. m_RPSOutcome = -1;
  704. switch (id)
  705. {
  706. case EmoteConstants.ID_EMOTE_RPS :
  707. m_RPSOutcome = Math.RandomInt(0,3);
  708. break;
  709. case EmoteConstants.ID_EMOTE_RPS_R :
  710. m_RPSOutcome = 0;
  711. break;
  712. case EmoteConstants.ID_EMOTE_RPS_P :
  713. m_RPSOutcome = 1;
  714. break;
  715. case EmoteConstants.ID_EMOTE_RPS_S :
  716. m_RPSOutcome = 2;
  717. break;
  718. }
  719. ScriptInputUserData ctx = new ScriptInputUserData;
  720. if (GetGame().IsMultiplayer() && GetGame().IsClient())
  721. {
  722. bool canProceed = true; //running callbacks in certain state can block additional actions
  723. EmoteBase emoteData;
  724. if (m_Callback && m_NameEmoteMap.Find(m_CurrentGestureID,emoteData))
  725. {
  726. canProceed = emoteData.CanBeCanceledNormally(m_Callback);
  727. }
  728. if (ctx.CanStoreInputUserData() && ((CanPlayEmote(id) && CanPlayEmoteClientCheck(id)) || forced) && canProceed)
  729. {
  730. ctx.Write(INPUT_UDT_GESTURE);
  731. ctx.Write(id);
  732. ctx.Write(forced);
  733. if (m_RPSOutcome != -1)
  734. {
  735. ctx.Write(m_RPSOutcome);
  736. }
  737. ctx.Send();
  738. m_bEmoteIsRequestPending = true;
  739. }
  740. else
  741. {
  742. m_bEmoteIsRequestPending = false;
  743. }
  744. m_MenuEmote = NULL;
  745. SetEmoteLockState(IsEmotePlaying());
  746. }
  747. else if (!GetGame().IsMultiplayer())
  748. {
  749. if (id == CALLBACK_CMD_END)
  750. {
  751. EndCallbackCommand();
  752. }
  753. else if (id == CALLBACK_CMD_GESTURE_INTERRUPT)
  754. {
  755. m_DeferredEmoteExecution = CALLBACK_CMD_GESTURE_INTERRUPT;
  756. }
  757. else if (CanPlayEmote(id) && CanPlayEmoteClientCheck(id))
  758. {
  759. PlayEmote(id);
  760. }
  761. else
  762. {
  763. SetEmoteLockState(IsEmotePlaying());
  764. }
  765. m_MenuEmote = NULL;
  766. }
  767. }
  768. bool IsControllsLocked()
  769. {
  770. return m_controllsLocked;
  771. }
  772. bool CanPlayEmote(int id)
  773. {
  774. //special cases
  775. if (id == CALLBACK_CMD_END || id == CALLBACK_CMD_GESTURE_INTERRUPT || id == CALLBACK_CMD_INSTACANCEL)
  776. {
  777. return true;
  778. }
  779. if (!m_Player || !m_Player.IsAlive() || (!IsEmotePlaying() && (m_Player.GetCommand_Action() || m_Player.GetCommandModifier_Action())) || m_Player.GetThrowing().IsThrowingModeEnabled())
  780. {
  781. //Debug.Log("!CanPlayEmote | reason: 1");
  782. return false;
  783. }
  784. ItemBase item = m_Player.GetItemInHands();
  785. if (item)
  786. {
  787. if (item.IsHeavyBehaviour() && id != EmoteConstants.ID_EMOTE_SURRENDER)
  788. {
  789. //Debug.Log("!CanPlayEmote | reason: 2");
  790. return false;
  791. }
  792. SurrenderDummyItem sda;
  793. if (m_Player.IsItemsToDelete() && Class.CastTo(sda,item) && !sda.IsSetForDeletion())
  794. {
  795. //Debug.Log("!CanPlayEmote | reason: 3");
  796. return false;
  797. }
  798. }
  799. if ((m_Player.GetWeaponManager() && m_Player.GetWeaponManager().IsRunning()) || (m_Player.GetActionManager() && m_Player.GetActionManager().GetRunningAction()))
  800. {
  801. //Debug.Log("!CanPlayEmote | reason: 4");
  802. return false;
  803. }
  804. if (m_HIC.IsWeaponRaised() || m_Player.IsRolling() || m_Player.IsClimbing() || m_Player.IsRestrainStarted() || m_Player.IsFighting() || m_Player.IsSwimming() || m_Player.IsClimbingLadder() || m_Player.IsFalling() || m_Player.IsUnconscious() || m_Player.IsJumpInProgress() || m_Player.IsRestrained()) // rework conditions into something better?
  805. {
  806. //Debug.Log("!CanPlayEmote | reason: 5");
  807. return false;
  808. }
  809. if (m_Player.GetCommand_Vehicle())
  810. {
  811. //Debug.Log("!CanPlayEmote | reason: 6");
  812. return false;
  813. }
  814. HumanCommandMove cm = m_Player.GetCommand_Move();
  815. if (cm)
  816. {
  817. if (cm.IsOnBack() && id != EmoteConstants.ID_EMOTE_SURRENDER)
  818. return false;
  819. if (cm.IsChangingStance())
  820. return false;
  821. }
  822. //"locks" player in surrender state
  823. if (m_IsSurrendered && (id != EmoteConstants.ID_EMOTE_SURRENDER))
  824. {
  825. //Debug.Log("!CanPlayEmote | reason: 8");
  826. return false;
  827. }
  828. if (m_Player.GetDayZPlayerInventory().IsProcessing())
  829. {
  830. //Debug.Log("!CanPlayEmote | reason: 9");
  831. return false;
  832. }
  833. EmoteBase emote;
  834. if (m_NameEmoteMap.Find(id,emote))
  835. {
  836. int callback_ID;
  837. int stancemask;
  838. bool is_fullbody;
  839. if (DetermineEmoteData(emote,callback_ID,stancemask,is_fullbody) && emote.EmoteCondition(stancemask))
  840. {
  841. return true;
  842. }
  843. //Debug.Log("!CanPlayEmote | reason: 10");
  844. }
  845. return false;
  846. }
  847. bool CanPlayEmoteClientCheck(int id)
  848. {
  849. if (!GetGame().IsClient())
  850. return true;
  851. if (GetGame().GetUIManager().FindMenu(MENU_INVENTORY))
  852. {
  853. //Debug.Log("!CanPlayEmoteClientCheck | reason: 1");
  854. return false;
  855. }
  856. return true;
  857. }
  858. void PlaySurrenderInOut(bool state)
  859. {
  860. m_PreviousGestureID = m_CurrentGestureID;
  861. m_CurrentGestureID = EmoteConstants.ID_EMOTE_SURRENDER;
  862. if (state)
  863. {
  864. if (m_Player.GetItemInHands() && !m_Player.CanDropEntity(m_Player.GetItemInHands()))
  865. return;
  866. if (m_Player.GetItemInHands() && GetGame().IsClient())
  867. {
  868. if (m_Player.GetInventory().HasInventoryReservation(null, m_HandInventoryLocation))
  869. m_Player.GetInventory().ClearInventoryReservationEx(null, m_HandInventoryLocation);
  870. m_Player.PhysicalPredictiveDropItem(m_Player.GetItemInHands());
  871. }
  872. CreateEmoteCallback(EmoteCB,DayZPlayerConstants.CMD_GESTUREFB_SURRENDERIN,DayZPlayerConstants.STANCEMASK_ALL,true);
  873. if (m_Callback)
  874. m_Callback.RegisterAnimationEvent("ActionExec", UA_ANIM_EVENT);
  875. }
  876. else
  877. {
  878. if (m_Player.IsAlive() && !m_Player.IsUnconscious())
  879. {
  880. CreateEmoteCallback(EmoteCB,DayZPlayerConstants.CMD_GESTUREFB_SURRENDEROUT,DayZPlayerConstants.STANCEMASK_ALL,true);
  881. }
  882. else
  883. {
  884. OnEmoteEnd();
  885. }
  886. }
  887. }
  888. //!
  889. void SetEmoteLockState(bool state)
  890. {
  891. //separate inventory access locking
  892. if (state != m_InventoryAccessLocked)
  893. {
  894. m_Player.SetInventorySoftLock(state);
  895. m_InventoryAccessLocked = state;
  896. }
  897. //Movement lock in fullbody anims
  898. if (state && m_Callback && m_Callback.m_IsFullbody)
  899. m_controllsLocked = true;
  900. else
  901. m_controllsLocked = false;
  902. if (state == m_EmoteLockState)
  903. return;
  904. if (!m_HandInventoryLocation)
  905. {
  906. m_HandInventoryLocation = new InventoryLocation;
  907. m_HandInventoryLocation.SetHands(m_Player,null);
  908. }
  909. if (!state)
  910. {
  911. if (m_Player.GetInventory().HasInventoryReservation(null, m_HandInventoryLocation))
  912. m_Player.GetInventory().ClearInventoryReservationEx(null, m_HandInventoryLocation);
  913. if (m_Player.GetActionManager())
  914. m_Player.GetActionManager().EnableActions(true);
  915. }
  916. else
  917. {
  918. if (!m_Player.GetInventory().HasInventoryReservation(null, m_HandInventoryLocation))
  919. m_Player.GetInventory().AddInventoryReservationEx(null, m_HandInventoryLocation, GameInventory.c_InventoryReservationTimeoutMS);
  920. if (m_Player.GetActionManager())
  921. m_Player.GetActionManager().EnableActions(false);
  922. }
  923. m_EmoteLockState = state;
  924. }
  925. void CheckEmoteLockedState()
  926. {
  927. if (!m_Player.GetItemInHands() || (m_Player.GetItemInHands() && !SurrenderDummyItem.Cast(m_Player.GetItemInHands())))
  928. return;
  929. //refreshes reservation in case of unwanted timeout
  930. if (m_EmoteLockState && m_HandInventoryLocation)
  931. {
  932. m_Player.GetInventory().ExtendInventoryReservationEx(null, m_HandInventoryLocation, 10000);
  933. }
  934. }
  935. //! directly force-ends surrender state from outside of normal flow
  936. void EndSurrenderRequest(SurrenderData data = null)
  937. {
  938. if (m_IsSurrendered && data)
  939. {
  940. if (m_Player.GetItemInHands())
  941. m_Player.GetItemInHands().DeleteSafe();//Note, this keeps item 'alive' until it is released by all the systems (inventory swapping etc.)
  942. m_IsSurrendered = false;
  943. SetEmoteLockState(IsEmotePlaying());
  944. data.End();
  945. }
  946. }
  947. //sent from server to cancel generic emote callback
  948. void ServerRequestEmoteCancel()
  949. {
  950. ScriptJunctureData pCtx = new ScriptJunctureData;
  951. pCtx.Write(CALLBACK_CMD_GESTURE_INTERRUPT);
  952. m_Player.SendSyncJuncture(DayZPlayerSyncJunctures.SJ_GESTURE_REQUEST, pCtx);
  953. }
  954. bool InterruptGestureCheck()
  955. {
  956. //init pass
  957. if (!m_InterruptInputDirect)
  958. {
  959. m_InterruptInputDirect = new array<UAInput>;
  960. m_InterruptInputsCount = m_InterruptInputs.Count();
  961. for (int i = 0; i < m_InterruptInputsCount; i++)
  962. {
  963. m_InterruptInputDirect.Insert(GetUApi().GetInputByName(m_InterruptInputs[i]));
  964. }
  965. }
  966. //interrupts any callback if restrain action is in progress, takes priority
  967. if (!m_Callback.m_IsFullbody)
  968. return false;
  969. for (int idx = 0; idx < m_InterruptInputsCount; idx++)
  970. {
  971. if (m_InterruptInputDirect[idx].LocalPress())
  972. {
  973. return true;
  974. }
  975. }
  976. return false;
  977. }
  978. bool InterruptWaterCheck()
  979. {
  980. float waterLevel = m_Player.GetCurrentWaterLevel();
  981. if (m_Player.IsPlayerInStance(DayZPlayerConstants.STANCEMASK_PRONE | DayZPlayerConstants.STANCEMASK_PRONE) && waterLevel >= m_HumanSwimSettings.m_fToCrouchLevel)
  982. {
  983. return true;
  984. }
  985. else if (m_Player.IsPlayerInStance(DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEIDX_RAISEDCROUCH) && waterLevel >= m_HumanSwimSettings.m_fToErectLevel)
  986. {
  987. return true;
  988. }
  989. return m_Player.GetModifiersManager() && m_Player.GetModifiersManager().IsModifierActive(eModifiers.MDF_DROWNING);
  990. }
  991. bool IsEmotePlaying()
  992. {
  993. return m_bEmoteIsPlaying || m_IsSurrendered || m_bEmoteIsRequestPending;
  994. }
  995. map<int,ref EmoteBase> GetNameEmoteMap()
  996. {
  997. return m_NameEmoteMap;
  998. }
  999. void CreateBleedingEffect(int Callback_ID)
  1000. {
  1001. if (GetGame().IsServer() && m_Player.IsAlive())
  1002. {
  1003. switch (Callback_ID)
  1004. {
  1005. case DayZPlayerConstants.CMD_SUICIDEFB_1HD :
  1006. m_Player.GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("Neck");
  1007. break;
  1008. case DayZPlayerConstants.CMD_SUICIDEFB_FIREAXE :
  1009. m_Player.GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("LeftForeArmRoll");
  1010. break;
  1011. case DayZPlayerConstants.CMD_SUICIDEFB_PITCHFORK :
  1012. m_Player.GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("Spine2");
  1013. break;
  1014. case DayZPlayerConstants.CMD_SUICIDEFB_SWORD :
  1015. m_Player.GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("Spine2");
  1016. break;
  1017. case DayZPlayerConstants.CMD_SUICIDEFB_SPEAR :
  1018. m_Player.GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("Head");
  1019. break;
  1020. case DayZPlayerConstants.CMD_SUICIDEFB_WOODAXE :
  1021. m_Player.GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("LeftForeArmRoll");
  1022. break;
  1023. default :
  1024. ErrorEx("EmoteManager.c | CreateBleedingEffect | WRONG ID",ErrorExSeverity.INFO);
  1025. break;
  1026. }
  1027. }
  1028. }
  1029. /////////////////////////////////////////////////////////
  1030. //! Deprecated
  1031. protected void PickEmote(int gestureslot)
  1032. {
  1033. }
  1034. };
  1035. class SurrenderData
  1036. {
  1037. //!called on surrender end request end
  1038. void End();
  1039. }
  1040. /**@class ChainedDropAndKillPlayerLambda
  1041. * @brief drops weapon in hands to ground and then calls kill
  1042. **/
  1043. class ChainedDropAndKillPlayerLambda : ReplaceItemWithNewLambdaBase
  1044. {
  1045. PlayerBase m_Player;
  1046. void ChainedDropAndKillPlayerLambda (EntityAI old_item, string new_item_type, PlayerBase player)
  1047. {
  1048. m_Player = player;
  1049. InventoryLocation gnd = new InventoryLocation;
  1050. vector mtx[4];
  1051. old_item.GetTransform(mtx);
  1052. gnd.SetGround(old_item, mtx);
  1053. OverrideNewLocation(gnd);
  1054. }
  1055. override void Execute (HumanInventoryWithFSM fsm_to_notify = null)
  1056. {
  1057. if (PrepareLocations())
  1058. {
  1059. vector transform[4];
  1060. m_Player.GetInventory().TakeToDst(InventoryMode.SERVER, m_OldLocation, m_NewLocation);
  1061. m_Player.OnItemInHandsChanged();
  1062. }
  1063. m_Player.SetHealth(0);
  1064. if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[syncinv] player=" + Object.GetDebugName(m_Player) + " STS = " + m_Player.GetSimulationTimeStamp() + " ChainedDropAndKillPlayerLambda");
  1065. }
  1066. }