emotemanager.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  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. EmoteBase emote;
  524. m_NameEmoteMap.Find(id,emote);
  525. if (m_AdminLog)
  526. m_AdminLog.OnEmote(m_Player, emote);
  527. m_PreviousGestureID = m_CurrentGestureID;
  528. m_CurrentGestureID = id;
  529. if (id > 0)
  530. {
  531. if (emote)
  532. {
  533. int callback_ID;
  534. int stancemask;
  535. bool is_fullbody;
  536. if (DetermineEmoteData(emote,callback_ID,stancemask,is_fullbody))
  537. {
  538. if (!emote.EmoteStartOverride(EmoteCB,callback_ID,stancemask,is_fullbody))
  539. {
  540. emote.OnBeforeStandardCallbackCreated(callback_ID,stancemask,is_fullbody);
  541. CreateEmoteCallback(EmoteCB,callback_ID,stancemask,is_fullbody);
  542. }
  543. if (emote.GetHideItemInHands())
  544. {
  545. HideItemInHands();
  546. }
  547. }
  548. else
  549. {
  550. ErrorEx("EmoteManager | DetermineEmoteData failed!");
  551. }
  552. }
  553. }
  554. }
  555. SetEmoteLockState(m_bEmoteIsPlaying);
  556. return m_bEmoteIsPlaying;
  557. }
  558. //creates Emote callback
  559. protected void CreateEmoteCallback(typename callbacktype, int id, int mask, bool fullbody)
  560. {
  561. if (m_Player)
  562. {
  563. m_LastMask = -1;
  564. if (fullbody)
  565. {
  566. Class.CastTo(m_Callback, m_Player.StartCommand_Action(id,callbacktype,mask));
  567. m_Callback.m_IsFullbody = true;
  568. m_Callback.EnableCancelCondition(true);
  569. }
  570. else if (m_Player.IsPlayerInStance(mask))
  571. {
  572. m_LastMask = mask; //character is probably not prone now
  573. Class.CastTo(m_Callback, m_Player.AddCommandModifier_Action(id,callbacktype));
  574. }
  575. if (m_Callback)
  576. {
  577. m_bEmoteIsPlaying = true;
  578. m_Callback.m_callbackID = id;
  579. m_Callback.m_player = m_Player;
  580. m_Callback.m_Manager = this;
  581. }
  582. }
  583. }
  584. protected void HideItemInHands()
  585. {
  586. m_item = m_Player.GetItemInHands();
  587. if (m_Callback && m_item)
  588. {
  589. m_Player.TryHideItemInHands(true);
  590. }
  591. }
  592. protected void ShowItemInHands()
  593. {
  594. if (m_item)
  595. {
  596. m_Player.TryHideItemInHands(false);
  597. }
  598. }
  599. void RequestCommitSuicide()
  600. {
  601. if (!GetGame().IsClient())
  602. CommitSuicide();
  603. }
  604. protected void CommitSuicide()
  605. {
  606. Weapon_Base weapon;
  607. WeaponEventBase weapon_event = new WeaponEventTrigger;
  608. if (Weapon_Base.CastTo(weapon,m_Player.GetItemInHands()))
  609. {
  610. if (weapon.CanFire())
  611. {
  612. m_Callback.RegisterAnimationEvent("Simulation_End",EmoteConstants.EMOTE_SUICIDE_SIMULATION_END);
  613. m_Player.SetSuicide(true);
  614. weapon.ProcessWeaponEvent(weapon_event);
  615. m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_FINISH);
  616. if (m_Player.IsAlive())
  617. {
  618. EntityAI helm = m_Player.FindAttachmentBySlotName("Headgear");
  619. if (helm && GetGame().IsServer())
  620. {
  621. float damage = helm.GetMaxHealth("","");
  622. helm.AddHealth("","", -damage/2);
  623. }
  624. GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).Call(this.KillPlayer);
  625. if (m_AdminLog)
  626. {
  627. m_AdminLog.Suicide(m_Player);
  628. }
  629. }
  630. }
  631. else
  632. {
  633. if (!weapon.IsDamageDestroyed())
  634. {
  635. weapon.ProcessWeaponEvent(weapon_event);
  636. }
  637. m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_END);
  638. }
  639. }
  640. else if (m_Player.GetItemInHands() && m_Player.GetItemInHands().ConfigIsExisting("suicideAnim"))
  641. {
  642. m_Callback.RegisterAnimationEvent("Death",EmoteConstants.EMOTE_SUICIDE_DEATH);
  643. m_Callback.RegisterAnimationEvent("Bleed",EmoteConstants.EMOTE_SUICIDE_BLEED);
  644. m_Callback.RegisterAnimationEvent("Simulation_End",EmoteConstants.EMOTE_SUICIDE_SIMULATION_END);
  645. m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_FINISH);
  646. m_Player.SetSuicide(true);
  647. }
  648. else
  649. {
  650. m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_FINISH);
  651. }
  652. }
  653. void KillPlayer()
  654. {
  655. if (GetGame().IsServer())
  656. {
  657. m_Player.SetHealth(0);
  658. }
  659. }
  660. void LogSuicide()
  661. {
  662. if (GetGame().IsServer())
  663. {
  664. PlayerIdentity identity = m_Player.GetIdentity();
  665. if (identity)
  666. {
  667. if (m_AdminLog)
  668. m_AdminLog.Suicide(m_Player);
  669. }
  670. }
  671. }
  672. void CreateEmoteCBFromMenu(int id, bool interrupts_same = false)
  673. {
  674. m_MenuEmote = new EmoteLauncher(id,interrupts_same);
  675. }
  676. EmoteLauncher GetEmoteLauncher()
  677. {
  678. return m_MenuEmote;
  679. }
  680. void InterruptCallbackCommand()
  681. {
  682. m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_INTERRUPT);
  683. if (m_MenuEmote)
  684. m_MenuEmote = null;
  685. m_DeferredEmoteExecution = CALLBACK_CMD_INVALID;
  686. }
  687. void EndCallbackCommand()
  688. {
  689. if (m_CurrentGestureID == EmoteConstants.ID_EMOTE_DANCE)
  690. {
  691. m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_INTERRUPT);
  692. }
  693. else
  694. {
  695. m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_END);
  696. }
  697. if (m_MenuEmote)
  698. m_MenuEmote = null;
  699. m_DeferredEmoteExecution = CALLBACK_CMD_INVALID;
  700. }
  701. //sends request (client)
  702. void SendEmoteRequestSync(int id)
  703. {
  704. int forced = EmoteLauncher.FORCE_NONE;
  705. if (m_MenuEmote)
  706. {
  707. forced = m_MenuEmote.GetForced();
  708. }
  709. m_RPSOutcome = -1;
  710. switch (id)
  711. {
  712. case EmoteConstants.ID_EMOTE_RPS :
  713. m_RPSOutcome = Math.RandomInt(0,3);
  714. break;
  715. case EmoteConstants.ID_EMOTE_RPS_R :
  716. m_RPSOutcome = 0;
  717. break;
  718. case EmoteConstants.ID_EMOTE_RPS_P :
  719. m_RPSOutcome = 1;
  720. break;
  721. case EmoteConstants.ID_EMOTE_RPS_S :
  722. m_RPSOutcome = 2;
  723. break;
  724. }
  725. ScriptInputUserData ctx = new ScriptInputUserData;
  726. if (GetGame().IsMultiplayer() && GetGame().IsClient())
  727. {
  728. bool canProceed = true; //running callbacks in certain state can block additional actions
  729. EmoteBase emoteData;
  730. if (m_Callback && m_NameEmoteMap.Find(m_CurrentGestureID,emoteData))
  731. {
  732. canProceed = emoteData.CanBeCanceledNormally(m_Callback);
  733. }
  734. if (ctx.CanStoreInputUserData() && ((CanPlayEmote(id) && CanPlayEmoteClientCheck(id)) || forced) && canProceed)
  735. {
  736. ctx.Write(INPUT_UDT_GESTURE);
  737. ctx.Write(id);
  738. ctx.Write(forced);
  739. if (m_RPSOutcome != -1)
  740. {
  741. ctx.Write(m_RPSOutcome);
  742. }
  743. ctx.Send();
  744. m_bEmoteIsRequestPending = true;
  745. }
  746. else
  747. {
  748. m_bEmoteIsRequestPending = false;
  749. }
  750. m_MenuEmote = NULL;
  751. SetEmoteLockState(IsEmotePlaying());
  752. }
  753. else if (!GetGame().IsMultiplayer())
  754. {
  755. if (id == CALLBACK_CMD_END)
  756. {
  757. EndCallbackCommand();
  758. }
  759. else if (id == CALLBACK_CMD_GESTURE_INTERRUPT)
  760. {
  761. m_DeferredEmoteExecution = CALLBACK_CMD_GESTURE_INTERRUPT;
  762. }
  763. else if (CanPlayEmote(id) && CanPlayEmoteClientCheck(id))
  764. {
  765. PlayEmote(id);
  766. }
  767. else
  768. {
  769. SetEmoteLockState(IsEmotePlaying());
  770. }
  771. m_MenuEmote = NULL;
  772. }
  773. }
  774. bool IsControllsLocked()
  775. {
  776. return m_controllsLocked;
  777. }
  778. bool CanPlayEmote(int id)
  779. {
  780. //special cases
  781. if (id == CALLBACK_CMD_END || id == CALLBACK_CMD_GESTURE_INTERRUPT || id == CALLBACK_CMD_INSTACANCEL)
  782. {
  783. return true;
  784. }
  785. if (!m_Player || !m_Player.IsAlive() || (!IsEmotePlaying() && (m_Player.GetCommand_Action() || m_Player.GetCommandModifier_Action())) || m_Player.GetThrowing().IsThrowingModeEnabled())
  786. {
  787. //Debug.Log("!CanPlayEmote | reason: 1");
  788. return false;
  789. }
  790. ItemBase item = m_Player.GetItemInHands();
  791. if (item)
  792. {
  793. if (item.IsHeavyBehaviour() && id != EmoteConstants.ID_EMOTE_SURRENDER)
  794. {
  795. //Debug.Log("!CanPlayEmote | reason: 2");
  796. return false;
  797. }
  798. SurrenderDummyItem sda;
  799. if (m_Player.IsItemsToDelete() && Class.CastTo(sda,item) && !sda.IsSetForDeletion())
  800. {
  801. //Debug.Log("!CanPlayEmote | reason: 3");
  802. return false;
  803. }
  804. }
  805. if ((m_Player.GetWeaponManager() && m_Player.GetWeaponManager().IsRunning()) || (m_Player.GetActionManager() && m_Player.GetActionManager().GetRunningAction()))
  806. {
  807. //Debug.Log("!CanPlayEmote | reason: 4");
  808. return false;
  809. }
  810. 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?
  811. {
  812. //Debug.Log("!CanPlayEmote | reason: 5");
  813. return false;
  814. }
  815. if (m_Player.GetCommand_Vehicle())
  816. {
  817. //Debug.Log("!CanPlayEmote | reason: 6");
  818. return false;
  819. }
  820. HumanCommandMove cm = m_Player.GetCommand_Move();
  821. if (cm)
  822. {
  823. if (cm.IsOnBack() && id != EmoteConstants.ID_EMOTE_SURRENDER)
  824. return false;
  825. if (cm.IsChangingStance())
  826. return false;
  827. }
  828. //"locks" player in surrender state
  829. if (m_IsSurrendered && (id != EmoteConstants.ID_EMOTE_SURRENDER))
  830. {
  831. //Debug.Log("!CanPlayEmote | reason: 8");
  832. return false;
  833. }
  834. if (m_Player.GetDayZPlayerInventory().IsProcessing())
  835. {
  836. //Debug.Log("!CanPlayEmote | reason: 9");
  837. return false;
  838. }
  839. EmoteBase emote;
  840. if (m_NameEmoteMap.Find(id,emote))
  841. {
  842. int callback_ID;
  843. int stancemask;
  844. bool is_fullbody;
  845. if (DetermineEmoteData(emote,callback_ID,stancemask,is_fullbody) && emote.EmoteCondition(stancemask))
  846. {
  847. return true;
  848. }
  849. //Debug.Log("!CanPlayEmote | reason: 10");
  850. }
  851. return false;
  852. }
  853. bool CanPlayEmoteClientCheck(int id)
  854. {
  855. if (!GetGame().IsClient())
  856. return true;
  857. if (GetGame().GetUIManager().FindMenu(MENU_INVENTORY))
  858. {
  859. //Debug.Log("!CanPlayEmoteClientCheck | reason: 1");
  860. return false;
  861. }
  862. return true;
  863. }
  864. void PlaySurrenderInOut(bool state)
  865. {
  866. m_PreviousGestureID = m_CurrentGestureID;
  867. m_CurrentGestureID = EmoteConstants.ID_EMOTE_SURRENDER;
  868. if (state)
  869. {
  870. if (m_Player.GetItemInHands() && !m_Player.CanDropEntity(m_Player.GetItemInHands()))
  871. return;
  872. if (m_Player.GetItemInHands() && GetGame().IsClient())
  873. {
  874. if (m_Player.GetInventory().HasInventoryReservation(null, m_HandInventoryLocation))
  875. m_Player.GetInventory().ClearInventoryReservationEx(null, m_HandInventoryLocation);
  876. m_Player.PhysicalPredictiveDropItem(m_Player.GetItemInHands());
  877. }
  878. CreateEmoteCallback(EmoteCB,DayZPlayerConstants.CMD_GESTUREFB_SURRENDERIN,DayZPlayerConstants.STANCEMASK_ALL,true);
  879. if (m_Callback)
  880. m_Callback.RegisterAnimationEvent("ActionExec", UA_ANIM_EVENT);
  881. }
  882. else
  883. {
  884. if (m_Player.IsAlive() && !m_Player.IsUnconscious())
  885. {
  886. CreateEmoteCallback(EmoteCB,DayZPlayerConstants.CMD_GESTUREFB_SURRENDEROUT,DayZPlayerConstants.STANCEMASK_ALL,true);
  887. }
  888. else
  889. {
  890. OnEmoteEnd();
  891. }
  892. }
  893. }
  894. //!
  895. void SetEmoteLockState(bool state)
  896. {
  897. //separate inventory access locking
  898. if (state != m_InventoryAccessLocked)
  899. {
  900. m_Player.SetInventorySoftLock(state);
  901. m_InventoryAccessLocked = state;
  902. }
  903. //Movement lock in fullbody anims
  904. if (state && m_Callback && m_Callback.m_IsFullbody)
  905. m_controllsLocked = true;
  906. else
  907. m_controllsLocked = false;
  908. if (state == m_EmoteLockState)
  909. return;
  910. if (!m_HandInventoryLocation)
  911. {
  912. m_HandInventoryLocation = new InventoryLocation;
  913. m_HandInventoryLocation.SetHands(m_Player,null);
  914. }
  915. if (!state)
  916. {
  917. if (m_Player.GetInventory().HasInventoryReservation(null, m_HandInventoryLocation))
  918. m_Player.GetInventory().ClearInventoryReservationEx(null, m_HandInventoryLocation);
  919. if (m_Player.GetActionManager())
  920. m_Player.GetActionManager().EnableActions(true);
  921. }
  922. else
  923. {
  924. if (!m_Player.GetInventory().HasInventoryReservation(null, m_HandInventoryLocation))
  925. m_Player.GetInventory().AddInventoryReservationEx(null, m_HandInventoryLocation, GameInventory.c_InventoryReservationTimeoutMS);
  926. if (m_Player.GetActionManager())
  927. m_Player.GetActionManager().EnableActions(false);
  928. }
  929. m_EmoteLockState = state;
  930. }
  931. void CheckEmoteLockedState()
  932. {
  933. if (!m_Player.GetItemInHands() || (m_Player.GetItemInHands() && !SurrenderDummyItem.Cast(m_Player.GetItemInHands())))
  934. return;
  935. //refreshes reservation in case of unwanted timeout
  936. if (m_EmoteLockState && m_HandInventoryLocation)
  937. {
  938. m_Player.GetInventory().ExtendInventoryReservationEx(null, m_HandInventoryLocation, 10000);
  939. }
  940. }
  941. //! directly force-ends surrender state from outside of normal flow
  942. void EndSurrenderRequest(SurrenderData data = null)
  943. {
  944. if (m_IsSurrendered && data)
  945. {
  946. if (m_Player.GetItemInHands())
  947. m_Player.GetItemInHands().DeleteSafe();//Note, this keeps item 'alive' until it is released by all the systems (inventory swapping etc.)
  948. m_IsSurrendered = false;
  949. SetEmoteLockState(IsEmotePlaying());
  950. data.End();
  951. }
  952. }
  953. //sent from server to cancel generic emote callback
  954. void ServerRequestEmoteCancel()
  955. {
  956. ScriptJunctureData pCtx = new ScriptJunctureData;
  957. pCtx.Write(CALLBACK_CMD_GESTURE_INTERRUPT);
  958. m_Player.SendSyncJuncture(DayZPlayerSyncJunctures.SJ_GESTURE_REQUEST, pCtx);
  959. }
  960. bool InterruptGestureCheck()
  961. {
  962. //init pass
  963. if (!m_InterruptInputDirect)
  964. {
  965. m_InterruptInputDirect = new array<UAInput>;
  966. m_InterruptInputsCount = m_InterruptInputs.Count();
  967. for (int i = 0; i < m_InterruptInputsCount; i++)
  968. {
  969. m_InterruptInputDirect.Insert(GetUApi().GetInputByName(m_InterruptInputs[i]));
  970. }
  971. }
  972. //interrupts any callback if restrain action is in progress, takes priority
  973. if (!m_Callback.m_IsFullbody)
  974. return false;
  975. for (int idx = 0; idx < m_InterruptInputsCount; idx++)
  976. {
  977. if (m_InterruptInputDirect[idx].LocalPress())
  978. {
  979. return true;
  980. }
  981. }
  982. return false;
  983. }
  984. bool InterruptWaterCheck()
  985. {
  986. float waterLevel = m_Player.GetCurrentWaterLevel();
  987. if (m_Player.IsPlayerInStance(DayZPlayerConstants.STANCEMASK_PRONE | DayZPlayerConstants.STANCEMASK_PRONE) && waterLevel >= m_HumanSwimSettings.m_fToCrouchLevel)
  988. {
  989. return true;
  990. }
  991. else if (m_Player.IsPlayerInStance(DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEIDX_RAISEDCROUCH) && waterLevel >= m_HumanSwimSettings.m_fToErectLevel)
  992. {
  993. return true;
  994. }
  995. return m_Player.GetModifiersManager() && m_Player.GetModifiersManager().IsModifierActive(eModifiers.MDF_DROWNING);
  996. }
  997. bool IsEmotePlaying()
  998. {
  999. return m_bEmoteIsPlaying || m_IsSurrendered || m_bEmoteIsRequestPending;
  1000. }
  1001. map<int,ref EmoteBase> GetNameEmoteMap()
  1002. {
  1003. return m_NameEmoteMap;
  1004. }
  1005. void CreateBleedingEffect(int Callback_ID)
  1006. {
  1007. if (GetGame().IsServer() && m_Player.IsAlive())
  1008. {
  1009. switch (Callback_ID)
  1010. {
  1011. case DayZPlayerConstants.CMD_SUICIDEFB_1HD :
  1012. m_Player.GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("Neck");
  1013. break;
  1014. case DayZPlayerConstants.CMD_SUICIDEFB_FIREAXE :
  1015. m_Player.GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("LeftForeArmRoll");
  1016. break;
  1017. case DayZPlayerConstants.CMD_SUICIDEFB_PITCHFORK :
  1018. m_Player.GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("Spine2");
  1019. break;
  1020. case DayZPlayerConstants.CMD_SUICIDEFB_SWORD :
  1021. m_Player.GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("Spine2");
  1022. break;
  1023. case DayZPlayerConstants.CMD_SUICIDEFB_SPEAR :
  1024. m_Player.GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("Head");
  1025. break;
  1026. case DayZPlayerConstants.CMD_SUICIDEFB_WOODAXE :
  1027. m_Player.GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("LeftForeArmRoll");
  1028. break;
  1029. default :
  1030. ErrorEx("EmoteManager.c | CreateBleedingEffect | WRONG ID",ErrorExSeverity.INFO);
  1031. break;
  1032. }
  1033. }
  1034. }
  1035. /////////////////////////////////////////////////////////
  1036. //! Deprecated
  1037. protected void PickEmote(int gestureslot)
  1038. {
  1039. }
  1040. };
  1041. class SurrenderData
  1042. {
  1043. //!called on surrender end request end
  1044. void End();
  1045. }
  1046. /**@class ChainedDropAndKillPlayerLambda
  1047. * @brief drops weapon in hands to ground and then calls kill
  1048. **/
  1049. class ChainedDropAndKillPlayerLambda : ReplaceItemWithNewLambdaBase
  1050. {
  1051. PlayerBase m_Player;
  1052. void ChainedDropAndKillPlayerLambda (EntityAI old_item, string new_item_type, PlayerBase player)
  1053. {
  1054. m_Player = player;
  1055. InventoryLocation gnd = new InventoryLocation;
  1056. vector mtx[4];
  1057. old_item.GetTransform(mtx);
  1058. gnd.SetGround(old_item, mtx);
  1059. OverrideNewLocation(gnd);
  1060. }
  1061. override void Execute (HumanInventoryWithFSM fsm_to_notify = null)
  1062. {
  1063. if (PrepareLocations())
  1064. {
  1065. vector transform[4];
  1066. m_Player.GetInventory().TakeToDst(InventoryMode.SERVER, m_OldLocation, m_NewLocation);
  1067. m_Player.OnItemInHandsChanged();
  1068. }
  1069. m_Player.SetHealth(0);
  1070. if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[syncinv] player=" + Object.GetDebugName(m_Player) + " STS = " + m_Player.GetSimulationTimeStamp() + " ChainedDropAndKillPlayerLambda");
  1071. }
  1072. }