man.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  1. #ifdef FEATURE_NETWORK_RECONCILIATION
  2. class Person extends Pawn
  3. {
  4. //! ???
  5. };
  6. #endif
  7. #ifdef FEATURE_NETWORK_RECONCILIATION
  8. class Man extends Person
  9. #else
  10. class Man extends EntityAI
  11. #endif
  12. {
  13. //! Returns player's input interface
  14. proto native UAInterface GetInputInterface();
  15. //! Returns player's identity
  16. proto native PlayerIdentity GetIdentity();
  17. //! Returns vehicle which this Man object is driving. If this Man object isn't as driver of any vehicle it will return NULL.
  18. proto native EntityAI GetDrivingVehicle();
  19. proto native owned string GetCurrentWeaponMode();
  20. //! Set speech restriction
  21. proto native void SetSpeechRestricted(bool state);
  22. //! Check if player has resctricted speech
  23. proto native bool IsSpeechRestricted();
  24. //! Texture that is used on the Man's face and hands
  25. proto native void SetFaceTexture(string texture_name);
  26. //! Material that is used on the Man's face and hands
  27. proto native void SetFaceMaterial(string material_name);
  28. proto native bool IsSoundInsideBuilding();
  29. proto native bool IsCameraInsideVehicle();
  30. proto native owned string GetMasterAttenuation();
  31. proto native void SetMasterAttenuation(string masterAttenuation);
  32. void Man()
  33. {
  34. SetFlags(EntityFlags.TOUCHTRIGGERS, false);
  35. }
  36. override bool IsMan()
  37. {
  38. return true;
  39. }
  40. override bool IsHealthVisible()
  41. {
  42. return false;
  43. }
  44. override bool HasFixedActionTargetCursorPosition()
  45. {
  46. return true;
  47. }
  48. bool IsUnconscious();
  49. //! uncon command might be still in progress but state already changed (for simple checks only - eg.: UI)
  50. bool IsUnconsciousStateOnly();
  51. int GetPlayerState()
  52. {
  53. if (IsAlive())
  54. return EPlayerStates.ALIVE;
  55. return EPlayerStates.DEAD;
  56. }
  57. void AddItemToDelete(EntityAI item);
  58. ///@{ inventory
  59. //! Returns player's inventory
  60. proto native HumanInventory GetHumanInventory();
  61. //Called when an item is removed from the cargo of this item
  62. protected ref ScriptInvoker m_OnItemAddedToHands;
  63. //Called when an item is moved around in the cargo of this item
  64. protected ref ScriptInvoker m_OnItemRemovedFromHands;
  65. ScriptInvoker GetOnItemAddedToHands()
  66. {
  67. if (!m_OnItemAddedToHands)
  68. m_OnItemAddedToHands = new ScriptInvoker();
  69. return m_OnItemAddedToHands;
  70. }
  71. ScriptInvoker GetOnItemRemovedFromHands()
  72. {
  73. if( !m_OnItemRemovedFromHands )
  74. m_OnItemRemovedFromHands = new ScriptInvoker;
  75. return m_OnItemRemovedFromHands;
  76. }
  77. void EEItemIntoHands(EntityAI item)
  78. {
  79. SetWeightDirty();
  80. if( m_OnItemAddedToHands )
  81. m_OnItemAddedToHands.Invoke( item, this );
  82. }
  83. void EEItemOutOfHands(EntityAI item)
  84. {
  85. SetWeightDirty();
  86. if( m_OnItemRemovedFromHands )
  87. m_OnItemRemovedFromHands.Invoke( item, this );
  88. }
  89. ///@{ drop juncture
  90. bool JunctureDropEntity (notnull EntityAI item)
  91. {
  92. return DropEntityImpl(InventoryMode.JUNCTURE, this, item);
  93. }
  94. override bool PredictiveDropEntity (notnull EntityAI item)
  95. {
  96. if (!ScriptInputUserData.CanStoreInputUserData())
  97. {
  98. Print("[inv] " + GetSimulationTimeStamp() + " Man@" + this + " ::PredictiveDropEntity input data not sent yet, cannot allow another input action");
  99. return false;
  100. }
  101. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), this))
  102. return JunctureDropEntity(item);
  103. else
  104. return DropEntityImpl(InventoryMode.PREDICTIVE, this, item);
  105. }
  106. override bool LocalDropEntity (notnull EntityAI item)
  107. {
  108. return DropEntityImpl(InventoryMode.LOCAL, this, item);
  109. }
  110. override bool ServerDropEntity (notnull EntityAI item)
  111. {
  112. return DropEntityImpl(InventoryMode.SERVER, this, item);
  113. }
  114. protected bool DropEntityImpl (InventoryMode mode, notnull EntityAI owner, notnull EntityAI item)
  115. {
  116. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::DropEntity(" + typename.EnumToString(InventoryMode, mode) + ") item=" + Object.GetDebugName(item));
  117. bool code = GetHumanInventory().DropEntity(mode, owner, item);
  118. UpdateInventoryMenu();
  119. return code;
  120. }
  121. ///@} drop juncture
  122. override bool CanDropEntity (notnull EntityAI item) { return true; }
  123. void OnItemInHandsChanged () { }
  124. bool NeedInventoryJunctureFromServer (notnull EntityAI item, EntityAI currParent, EntityAI newParent) { return false; }
  125. ///@{ hand juncture
  126. void JunctureTakeEntityToHands (notnull EntityAI item)
  127. {
  128. TakeEntityToHandsImpl(InventoryMode.JUNCTURE, item);
  129. }
  130. void PredictiveTakeEntityToHands (EntityAI item)
  131. {
  132. if (!ScriptInputUserData.CanStoreInputUserData())
  133. {
  134. Print("[inv] " + GetSimulationTimeStamp() + " Man@" + this + " ::PredictiveTakeEntityToHands input data not sent yet, cannot allow another input action");
  135. return;
  136. }
  137. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), this))
  138. JunctureTakeEntityToHands(item);
  139. else
  140. TakeEntityToHandsImpl(InventoryMode.PREDICTIVE, item);
  141. }
  142. void LocalTakeEntityToHands (EntityAI item)
  143. {
  144. TakeEntityToHandsImpl(InventoryMode.LOCAL, item);
  145. }
  146. void ServerTakeEntityToHands (EntityAI item)
  147. {
  148. TakeEntityToHandsImpl(InventoryMode.SERVER, item);
  149. }
  150. void TakeEntityToHandsImpl (InventoryMode mode, EntityAI item)
  151. {
  152. if (!GetGame().IsDedicatedServer() )
  153. {
  154. InventoryLocation il = new InventoryLocation;
  155. il.SetHands(this, item);
  156. //GetInventory().AddInventoryReservationEx(item, il ,GameInventory.c_InventoryReservationTimeoutShortMS);
  157. }
  158. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::Take2Hands(" + typename.EnumToString(InventoryMode, mode) + ") item=" + Object.GetDebugName(item));
  159. EntityAI itemInHands = GetHumanInventory().GetEntityInHands();
  160. InventoryLocation src_item = new InventoryLocation;
  161. if (item.GetInventory().GetCurrentInventoryLocation(src_item))
  162. {
  163. if (itemInHands == null)
  164. {
  165. InventoryLocation hand_dst = new InventoryLocation;
  166. hand_dst.SetHands(this, item);
  167. GetHumanInventory().TakeToDst(mode, src_item, hand_dst);
  168. }
  169. else if (GetHumanInventory().CanSwapEntitiesEx(itemInHands, item))
  170. GetInventory().SwapEntities(mode, itemInHands, item);
  171. UpdateInventoryMenu();
  172. }
  173. }
  174. ///@} hand juncture
  175. void LocalDestroyEntityInHands ()
  176. {
  177. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " Destroy IH=" + GetHumanInventory().GetEntityInHands());
  178. GetHumanInventory().LocalDestroyEntity(GetHumanInventory().GetEntityInHands());
  179. UpdateInventoryMenu();
  180. }
  181. //! ToDo: Old system method. Might should be adjusted to new system at some point
  182. void PredictiveMoveItemFromHandsToInventory ()
  183. {
  184. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " Stash IH=" + GetHumanInventory().GetEntityInHands());
  185. if (!ScriptInputUserData.CanStoreInputUserData())
  186. {
  187. Print("[inv] PredictiveMoveItemFromHandsToInventory input data not sent yet, cannot allow another input action");
  188. return;
  189. }
  190. InventoryMode invMode = InventoryMode.PREDICTIVE;
  191. EntityAI entityInHands = GetHumanInventory().GetEntityInHands();
  192. if (NeedInventoryJunctureFromServer(entityInHands, this, this))
  193. invMode = InventoryMode.JUNCTURE;
  194. //! returns item to previous location, if available
  195. if (entityInHands.m_OldLocation && entityInHands.m_OldLocation.IsValid())
  196. {
  197. InventoryLocation invLoc = new InventoryLocation;
  198. entityInHands.GetInventory().GetCurrentInventoryLocation(invLoc);
  199. //! Check if old strored location is somewhere on this player
  200. if (entityInHands.m_OldLocation.GetParent() && entityInHands.m_OldLocation.GetParent().GetHierarchyRootPlayer())
  201. {
  202. GetHumanInventory().ClearInventoryReservation(entityInHands, entityInHands.m_OldLocation);
  203. if (GetHumanInventory().LocationCanMoveEntity(invLoc, entityInHands.m_OldLocation))
  204. {
  205. EntityAI oldLocEntity = GetHumanInventory().LocationGetEntity(entityInHands.m_OldLocation);
  206. if (!oldLocEntity && GetHumanInventory().TakeToDst(invMode, invLoc, entityInHands.m_OldLocation))
  207. {
  208. UpdateInventoryMenu();
  209. return;
  210. }
  211. else //! This should not happen after clearing inventory reservation but just in case handle also getting a new location if the old location is obscured by an item.
  212. {
  213. InventoryLocation newLocation = new InventoryLocation;
  214. if (GetHumanInventory().FindFreeLocationFor(entityInHands, FindInventoryLocationType.CARGO, newLocation))
  215. {
  216. if (GetHumanInventory().TakeToDst(invMode, invLoc, newLocation))
  217. {
  218. UpdateInventoryMenu();
  219. return;
  220. }
  221. }
  222. }
  223. }
  224. }
  225. }
  226. GetHumanInventory().TakeEntityToInventory(invMode, FindInventoryLocationType.ATTACHMENT | FindInventoryLocationType.CARGO, GetHumanInventory().GetEntityInHands());
  227. UpdateInventoryMenu();
  228. }
  229. ///@{ !hand -> !hand replace
  230. protected bool ReplaceItemWithNewImpl(InventoryMode mode, ReplaceItemWithNewLambdaBase lambda)
  231. {
  232. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " Replace !HND lambda=" + lambda.DumpToString());
  233. bool code = GetHumanInventory().ReplaceItemWithNew(mode, lambda);
  234. UpdateInventoryMenu();
  235. return code;
  236. }
  237. bool LocalReplaceItemWithNew(ReplaceItemWithNewLambdaBase lambda)
  238. {
  239. return ReplaceItemWithNewImpl(InventoryMode.LOCAL, lambda);
  240. }
  241. bool ServerReplaceItemWithNew(ReplaceItemWithNewLambdaBase lambda)
  242. {
  243. return ReplaceItemWithNewImpl(InventoryMode.SERVER, lambda);
  244. }
  245. ///@} !hand -> !hand replace
  246. ///@{ !hand replace -> hand
  247. protected bool ReplaceItemElsewhereWithNewInHandsImpl (InventoryMode mode, ReplaceItemWithNewLambdaBase lambda)
  248. {
  249. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " Replace !HND->HND lambda=" + lambda.DumpToString());
  250. bool code = GetHumanInventory().ReplaceItemElsewhereWithNewInHands(mode, lambda);
  251. UpdateInventoryMenu();
  252. return code;
  253. }
  254. bool LocalReplaceItemElsewhereWithNewInHands (ReplaceItemWithNewLambdaBase lambda)
  255. {
  256. return ReplaceItemElsewhereWithNewInHandsImpl(InventoryMode.LOCAL, lambda);
  257. }
  258. bool ServerReplaceItemElsewhereWithNewInHands (ReplaceItemWithNewLambdaBase lambda)
  259. {
  260. return ReplaceItemElsewhereWithNewInHandsImpl(InventoryMode.SERVER, lambda);
  261. }
  262. ///@} !hand replace -> hand
  263. ///@{ hand replace
  264. protected bool ReplaceItemInHandsWithNewImpl (InventoryMode mode, ReplaceItemWithNewLambdaBase lambda)
  265. {
  266. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " Replace HND->HND lambda=" + lambda.DumpToString());
  267. bool code = GetHumanInventory().ReplaceItemInHandsWithNew(mode, lambda);
  268. UpdateInventoryMenu();
  269. return code;
  270. }
  271. bool LocalReplaceItemInHandsWithNew (ReplaceItemWithNewLambdaBase lambda)
  272. {
  273. return ReplaceItemInHandsWithNewImpl(InventoryMode.LOCAL, lambda);
  274. }
  275. bool ServerReplaceItemInHandsWithNew (ReplaceItemWithNewLambdaBase lambda)
  276. {
  277. return ReplaceItemInHandsWithNewImpl(InventoryMode.SERVER, lambda);
  278. }
  279. ///@} hand replace
  280. ///@{ hand replace2
  281. protected bool ReplaceItemInHandsWithNewElsewhereImpl (InventoryMode mode, ReplaceItemWithNewLambdaBase lambda)
  282. {
  283. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " Replace HND->elsewhere lambda=" + lambda.DumpToString());
  284. bool code = GetHumanInventory().ReplaceItemInHandsWithNewElsewhere(mode, lambda);
  285. UpdateInventoryMenu();
  286. return code;
  287. }
  288. bool LocalReplaceItemInHandsWithNewElsewhere (ReplaceItemWithNewLambdaBase lambda)
  289. {
  290. return ReplaceItemInHandsWithNewElsewhereImpl(InventoryMode.LOCAL, lambda);
  291. }
  292. bool ServerReplaceItemInHandsWithNewElsewhere (ReplaceItemWithNewLambdaBase lambda)
  293. {
  294. return ReplaceItemInHandsWithNewElsewhereImpl(InventoryMode.SERVER, lambda);
  295. }
  296. ///@} hand replace2
  297. ///@{ to inv juncture
  298. bool JunctureTakeEntityToInventory (FindInventoryLocationType flags, notnull EntityAI item)
  299. {
  300. return TakeEntityToInventoryImpl(InventoryMode.JUNCTURE, flags, item);
  301. }
  302. override bool PredictiveTakeEntityToInventory (FindInventoryLocationType flags, notnull EntityAI item)
  303. {
  304. if (!ScriptInputUserData.CanStoreInputUserData())
  305. {
  306. Print("[inv] " + GetSimulationTimeStamp() + " Man@" + this + " ::PredictiveTakeEntityToInventory input data not sent yet, cannot allow another input action");
  307. return false;
  308. }
  309. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), this))
  310. return JunctureTakeEntityToInventory(flags, item);
  311. else
  312. return TakeEntityToInventoryImpl(InventoryMode.PREDICTIVE, flags, item);
  313. }
  314. override bool LocalTakeEntityToInventory (FindInventoryLocationType flags, notnull EntityAI item)
  315. {
  316. return TakeEntityToInventoryImpl(InventoryMode.LOCAL, flags, item);
  317. }
  318. override bool ServerTakeEntityToInventory (FindInventoryLocationType flags, notnull EntityAI item)
  319. {
  320. return TakeEntityToInventoryImpl(InventoryMode.SERVER, flags, item);
  321. }
  322. protected bool TakeEntityToInventoryImpl (InventoryMode mode, FindInventoryLocationType flags, notnull EntityAI item)
  323. {
  324. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::Take2Inv(" + typename.EnumToString(InventoryMode, mode) + ") item=" + Object.GetDebugName(item));
  325. bool code = GetHumanInventory().TakeEntityToInventory(mode, flags, item);
  326. UpdateInventoryMenu();
  327. return code;
  328. }
  329. ///@} to inv juncture
  330. ///@{ to cgo juncture
  331. bool JunctureTakeEntityToCargo (notnull EntityAI item)
  332. {
  333. return TakeEntityToCargoImpl(InventoryMode.JUNCTURE, item);
  334. }
  335. override bool PredictiveTakeEntityToCargo (notnull EntityAI item)
  336. {
  337. if (!ScriptInputUserData.CanStoreInputUserData())
  338. {
  339. Print("[inv] " + GetSimulationTimeStamp() + " Man@" + this + " ::PredictiveTakeEntityToCargo input data not sent yet, cannot allow another input action");
  340. return false;
  341. }
  342. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), this))
  343. return JunctureTakeEntityToCargo(item);
  344. else
  345. return TakeEntityToCargoImpl(InventoryMode.PREDICTIVE, item);
  346. }
  347. override bool LocalTakeEntityToCargo (notnull EntityAI item)
  348. {
  349. return TakeEntityToCargoImpl(InventoryMode.LOCAL, item);
  350. }
  351. override bool ServerTakeEntityToCargo (notnull EntityAI item)
  352. {
  353. return TakeEntityToCargoImpl(InventoryMode.SERVER, item);
  354. }
  355. protected bool TakeEntityToCargoImpl (InventoryMode mode, notnull EntityAI item)
  356. {
  357. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::Take2Cgo(" + typename.EnumToString(InventoryMode, mode) + ") item=" + Object.GetDebugName(item));
  358. bool code = GetHumanInventory().TakeEntityToCargo(mode, item);
  359. UpdateInventoryMenu();
  360. return code;
  361. }
  362. ///@} to cgo juncture
  363. ///@{ as att juncture
  364. bool JunctureTakeEntityAsAttachment (notnull EntityAI item)
  365. {
  366. return TakeEntityAsAttachmentImpl(InventoryMode.JUNCTURE, item);
  367. }
  368. override bool PredictiveTakeEntityAsAttachment (notnull EntityAI item)
  369. {
  370. if (!ScriptInputUserData.CanStoreInputUserData())
  371. {
  372. Print("[inv] " + GetSimulationTimeStamp() + " Man@" + this + " ::PredictiveTakeEntityAsAttachment input data not sent yet, cannot allow another input action");
  373. return false;
  374. }
  375. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), this))
  376. return JunctureTakeEntityAsAttachment(item);
  377. else
  378. return TakeEntityAsAttachmentImpl(InventoryMode.PREDICTIVE, item);
  379. }
  380. override bool LocalTakeEntityAsAttachment (notnull EntityAI item)
  381. {
  382. return TakeEntityAsAttachmentImpl(InventoryMode.LOCAL, item);
  383. }
  384. override bool ServerTakeEntityAsAttachment (notnull EntityAI item)
  385. {
  386. return TakeEntityAsAttachmentImpl(InventoryMode.SERVER, item);
  387. }
  388. protected bool TakeEntityAsAttachmentImpl (InventoryMode mode, notnull EntityAI item)
  389. {
  390. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::Take2Att(" + typename.EnumToString(InventoryMode, mode) + ") item=" + Object.GetDebugName(item));
  391. bool code = GetHumanInventory().TakeEntityAsAttachment(mode, item);
  392. UpdateInventoryMenu();
  393. return code;
  394. }
  395. ///@} as att juncture
  396. ///@{ as att ex juncture
  397. bool JunctureTakeEntityAsAttachmentEx (notnull EntityAI item, int slot)
  398. {
  399. return TakeEntityAsAttachmentExImpl(InventoryMode.JUNCTURE, item, slot);
  400. }
  401. override bool PredictiveTakeEntityAsAttachmentEx (notnull EntityAI item, int slot)
  402. {
  403. if (!ScriptInputUserData.CanStoreInputUserData())
  404. {
  405. Print("[inv] " + GetSimulationTimeStamp() + " Man@" + this + " ::PredictiveTakeEntityAsAttachmentEx input data not sent yet, cannot allow another input action");
  406. return false;
  407. }
  408. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), this))
  409. return JunctureTakeEntityAsAttachmentEx(item, slot);
  410. else
  411. return TakeEntityAsAttachmentExImpl(InventoryMode.PREDICTIVE, item, slot);
  412. }
  413. override bool LocalTakeEntityAsAttachmentEx (notnull EntityAI item, int slot)
  414. {
  415. return TakeEntityAsAttachmentExImpl(InventoryMode.LOCAL, item, slot);
  416. }
  417. override bool ServerTakeEntityAsAttachmentEx (notnull EntityAI item, int slot)
  418. {
  419. return TakeEntityAsAttachmentExImpl(InventoryMode.SERVER, item, slot);
  420. }
  421. protected bool TakeEntityAsAttachmentExImpl (InventoryMode mode, notnull EntityAI item, int slot)
  422. {
  423. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::Take2AttEx(" + typename.EnumToString(InventoryMode, mode) + ") item=" + Object.GetDebugName(item));
  424. bool code = GetHumanInventory().TakeEntityAsAttachmentEx(mode, item, slot);
  425. UpdateInventoryMenu();
  426. return code;
  427. }
  428. ///@} as att ex juncture
  429. ///@{ swap juncture
  430. bool JunctureSwapEntities (notnull EntityAI item1, notnull EntityAI item2)
  431. {
  432. return SwapEntitiesImpl(InventoryMode.JUNCTURE, item1, item2);
  433. }
  434. bool PredictiveSwapEntities (notnull EntityAI item1, notnull EntityAI item2)
  435. {
  436. if (!ScriptInputUserData.CanStoreInputUserData())
  437. {
  438. Print("[inv] " + GetSimulationTimeStamp() + " Man@" + this + " ::PredictiveSwapEntities input data not sent yet, cannot allow another input action");
  439. return false;
  440. }
  441. bool need_j1 = NeedInventoryJunctureFromServer(item1, item1.GetHierarchyParent(), item2.GetHierarchyParent());
  442. bool need_j2 = NeedInventoryJunctureFromServer(item2, item2.GetHierarchyParent(), item1.GetHierarchyParent());
  443. if (need_j1 || need_j2)
  444. return SwapEntitiesImpl(InventoryMode.JUNCTURE, item1, item2);
  445. else
  446. return SwapEntitiesImpl(InventoryMode.PREDICTIVE, item1, item2);
  447. }
  448. bool LocalSwapEntities (notnull EntityAI item1, notnull EntityAI item2)
  449. {
  450. return SwapEntitiesImpl(InventoryMode.LOCAL, item1, item2);
  451. }
  452. bool ServerSwapEntities (notnull EntityAI item1, notnull EntityAI item2)
  453. {
  454. return SwapEntitiesImpl(InventoryMode.SERVER, item1, item2);
  455. }
  456. protected bool SwapEntitiesImpl (InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2)
  457. {
  458. bool code;
  459. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::SwapImpl(" + typename.EnumToString(InventoryMode, mode) + ") item1=" + Object.GetDebugName(item1) + " item2=" + item2.GetDebugName(this));
  460. if (!GameInventory.CanSwapEntitiesEx(item1, item2))
  461. Error("[inv] (Man@" + this + ") SwapEntitiesImpl - cannot swap items!");
  462. code = GetHumanInventory().SwapEntities(mode, item1, item2);
  463. UpdateInventoryMenu();
  464. if (!code)
  465. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " SwapEntitiesImpl - cannot swap or forceswap");
  466. return code;
  467. }
  468. ///@} swap juncture
  469. ///@{ ForceSwap juncture
  470. bool JunctureForceSwapEntities (notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation item2_dst)
  471. {
  472. return ForceSwapEntitiesImpl(InventoryMode.JUNCTURE, item1, item2, item2_dst);
  473. }
  474. bool PredictiveForceSwapEntities (notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation item2_dst)
  475. {
  476. if (!ScriptInputUserData.CanStoreInputUserData())
  477. {
  478. Print("[inv] " + GetSimulationTimeStamp() + " Man@" + this + " ::PredictiveForceSwapEntities input data not sent yet, cannot allow another input action");
  479. return false;
  480. }
  481. bool need_j1 = NeedInventoryJunctureFromServer(item1, item1.GetHierarchyParent(), item2.GetHierarchyParent());
  482. bool need_j2 = NeedInventoryJunctureFromServer(item2, item2.GetHierarchyParent(), item1.GetHierarchyParent());
  483. if (need_j1 || need_j2)
  484. return ForceSwapEntitiesImpl(InventoryMode.JUNCTURE, item1, item2, item2_dst);
  485. else
  486. return ForceSwapEntitiesImpl(InventoryMode.PREDICTIVE, item1, item2, item2_dst);
  487. }
  488. bool LocalForceSwapEntities (notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation item2_dst)
  489. {
  490. return ForceSwapEntitiesImpl(InventoryMode.LOCAL, item1, item2, item2_dst);
  491. }
  492. bool ServerForceSwapEntities (notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation item2_dst)
  493. {
  494. return ForceSwapEntitiesImpl(InventoryMode.SERVER, item1, item2, item2_dst);
  495. }
  496. protected bool ForceSwapEntitiesImpl (InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation item2_dst)
  497. {
  498. bool code = false;
  499. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ForceSwapImpl(" + typename.EnumToString(InventoryMode, mode) + ") item1=" + Object.GetDebugName(item1) + " item2=" + item2.GetDebugName(this));
  500. code = GetHumanInventory().ForceSwapEntities(mode, item1, item2, item2_dst);
  501. UpdateInventoryMenu();
  502. if (!code)
  503. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ForceSwapEntitiesImpl - cannot Forceswap");
  504. return code;
  505. }
  506. ///@} ForceSwap juncture
  507. ///@{ to target inv juncture
  508. bool JunctureTakeEntityToTargetInventory (notnull EntityAI target, FindInventoryLocationType flags, notnull EntityAI item)
  509. {
  510. return TakeEntityToTargetInventoryImpl(InventoryMode.JUNCTURE, target, flags, item);
  511. }
  512. override bool PredictiveTakeEntityToTargetInventory (notnull EntityAI target, FindInventoryLocationType flags, notnull EntityAI item)
  513. {
  514. if (!ScriptInputUserData.CanStoreInputUserData())
  515. {
  516. Print("[inv] " + GetSimulationTimeStamp() + " ::PredictiveTakeEntityToTargetInventory input data not sent yet, cannot allow another input action");
  517. return false;
  518. }
  519. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), target))
  520. return JunctureTakeEntityToTargetInventory(target, flags, item);
  521. else
  522. return TakeEntityToTargetInventoryImpl(InventoryMode.PREDICTIVE, target, flags, item);
  523. }
  524. bool PredictiveTakeOrSwapAttachment( notnull EntityAI item )
  525. {
  526. if( GetInventory().CanAddAttachment( item ) )
  527. {
  528. return PredictiveTakeEntityAsAttachment( item );
  529. }
  530. else
  531. {
  532. for( int i = 0; i < item.GetInventory().GetSlotIdCount(); i++ )
  533. {
  534. int slot_id = item.GetInventory().GetSlotId(i);
  535. EntityAI slot_item = GetInventory().FindAttachment( slot_id );
  536. if( slot_item && GetInventory().CanSwapEntitiesEx( item, slot_item ) )
  537. {
  538. return PredictiveSwapEntities(item, slot_item);
  539. }
  540. }
  541. }
  542. return false;
  543. }
  544. override bool LocalTakeEntityToTargetInventory (notnull EntityAI target, FindInventoryLocationType flags, notnull EntityAI item)
  545. {
  546. return TakeEntityToTargetInventoryImpl(InventoryMode.LOCAL, target, flags, item);
  547. }
  548. protected bool TakeEntityToTargetInventoryImpl (InventoryMode mode, notnull EntityAI target, FindInventoryLocationType flags, notnull EntityAI item)
  549. {
  550. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::Take2TargetInv(" + typename.EnumToString(InventoryMode, mode) + ") item=" + Object.GetDebugName(item));
  551. bool code = GetInventory().TakeEntityToTargetInventory(mode, target, flags, item);
  552. UpdateInventoryMenu();
  553. return code;
  554. }
  555. ///@} to target inv juncture
  556. ///@{ to target cgo ex juncture
  557. bool JunctureTakeEntityToTargetCargoEx (notnull CargoBase cargo, notnull EntityAI item, int row, int col)
  558. {
  559. return TakeEntityToTargetCargoExImpl(InventoryMode.JUNCTURE, cargo, item, row, col);
  560. }
  561. override bool PredictiveTakeEntityToTargetCargoEx (notnull CargoBase cargo, notnull EntityAI item, int row, int col)
  562. {
  563. if (!ScriptInputUserData.CanStoreInputUserData())
  564. {
  565. Print("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::PredictiveTakeEntityToTargetCargoEx input data not sent yet, cannot allow another input action");
  566. return false;
  567. }
  568. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), cargo.GetCargoOwner()))
  569. return JunctureTakeEntityToTargetCargoEx(cargo, item, row, col);
  570. else
  571. return TakeEntityToTargetCargoExImpl(InventoryMode.PREDICTIVE, cargo, item, row, col);
  572. }
  573. override bool LocalTakeEntityToTargetCargoEx (notnull CargoBase cargo, notnull EntityAI item, int row, int col)
  574. {
  575. return TakeEntityToTargetCargoExImpl(InventoryMode.LOCAL, cargo, item, row, col);
  576. }
  577. override bool ServerTakeEntityToTargetCargoEx (notnull CargoBase cargo, notnull EntityAI item, int row, int col)
  578. {
  579. return TakeEntityToTargetCargoExImpl(InventoryMode.SERVER, cargo, item, row, col);
  580. }
  581. protected bool TakeEntityToTargetCargoExImpl (InventoryMode mode, notnull CargoBase cargo, notnull EntityAI item, int row, int col)
  582. {
  583. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::Take2TargetCgoEx(" + typename.EnumToString(InventoryMode, mode) + ") item=" + Object.GetDebugName(item));
  584. bool code = GetInventory().TakeEntityToTargetCargoEx(mode, cargo, item, row, col);
  585. UpdateInventoryMenu();
  586. return code;
  587. }
  588. ///@} to target cgo ex juncture
  589. ///@{ to target cgo juncture
  590. bool JunctureTakeEntityToTargetCargo (notnull EntityAI target, notnull EntityAI item)
  591. {
  592. return TakeEntityToTargetCargoImpl(InventoryMode.JUNCTURE, target, item);
  593. }
  594. override bool PredictiveTakeEntityToTargetCargo (notnull EntityAI target, notnull EntityAI item)
  595. {
  596. if (!ScriptInputUserData.CanStoreInputUserData())
  597. {
  598. Print("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::PredictiveTakeEntityToTargetCargo input data not sent yet, cannot allow another input action");
  599. return false;
  600. }
  601. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), target))
  602. return JunctureTakeEntityToTargetCargo(target, item);
  603. else
  604. return TakeEntityToTargetCargoImpl(InventoryMode.PREDICTIVE, target, item);
  605. }
  606. override bool LocalTakeEntityToTargetCargo (notnull EntityAI target, notnull EntityAI item)
  607. {
  608. return TakeEntityToTargetCargoImpl(InventoryMode.LOCAL, target, item);
  609. }
  610. override bool ServerTakeEntityToTargetCargo (notnull EntityAI target, notnull EntityAI item)
  611. {
  612. if (IsAlive())
  613. return TakeEntityToTargetCargoImpl(InventoryMode.SERVER, target, item);
  614. else
  615. return TakeEntityToTargetCargoImpl(InventoryMode.SERVER, target, item);
  616. }
  617. protected bool TakeEntityToTargetCargoImpl (InventoryMode mode, notnull EntityAI target, notnull EntityAI item)
  618. {
  619. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " Take2TargetCgo(" + typename.EnumToString(InventoryMode, mode) + ") item=" + Object.GetDebugName(item));
  620. bool code = GetInventory().TakeEntityToTargetInventory(mode, target, FindInventoryLocationType.CARGO, item);
  621. UpdateInventoryMenu();
  622. return code;
  623. }
  624. ///@} to target cgo juncture
  625. ///@{ to target att ex juncture
  626. bool JunctureTakeEntityToTargetAttachmentEx (notnull EntityAI target, notnull EntityAI item, int slot)
  627. {
  628. return TakeEntityToTargetAttachmentExImpl(InventoryMode.JUNCTURE, target, item, slot);
  629. }
  630. override bool PredictiveTakeEntityToTargetAttachmentEx (notnull EntityAI target, notnull EntityAI item, int slot)
  631. {
  632. if (!ScriptInputUserData.CanStoreInputUserData())
  633. {
  634. Print("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::PredictiveTakeEntityToTargetAttachmentEx input data not sent yet, cannot allow another input action");
  635. return false;
  636. }
  637. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), target))
  638. return JunctureTakeEntityToTargetAttachmentEx(target, item, slot);
  639. else
  640. return TakeEntityToTargetAttachmentExImpl(InventoryMode.PREDICTIVE, target, item, slot);
  641. }
  642. override bool LocalTakeEntityToTargetAttachmentEx (notnull EntityAI target, notnull EntityAI item, int slot)
  643. {
  644. return TakeEntityToTargetAttachmentExImpl(InventoryMode.LOCAL, target, item, slot);
  645. }
  646. override bool ServerTakeEntityToTargetAttachmentEx (notnull EntityAI target, notnull EntityAI item, int slot)
  647. {
  648. return TakeEntityToTargetAttachmentExImpl(InventoryMode.SERVER, target, item, slot);
  649. }
  650. protected bool TakeEntityToTargetAttachmentExImpl (InventoryMode mode, notnull EntityAI target, notnull EntityAI item, int slot)
  651. {
  652. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::Take2TargetAtt(" + typename.EnumToString(InventoryMode, mode) + ") item=" + Object.GetDebugName(item));
  653. bool code = GetInventory().TakeEntityAsTargetAttachmentEx(mode, target, item, slot);
  654. UpdateInventoryMenu();
  655. return code;
  656. }
  657. ///@} to target att ex juncture
  658. ///@{ to target att juncture
  659. bool JunctureTakeEntityToTargetAttachment (notnull EntityAI target, notnull EntityAI item)
  660. {
  661. return TakeEntityToTargetAttachmentImpl(InventoryMode.JUNCTURE, target, item);
  662. }
  663. override bool PredictiveTakeEntityToTargetAttachment (notnull EntityAI target, notnull EntityAI item)
  664. {
  665. if (!ScriptInputUserData.CanStoreInputUserData())
  666. {
  667. Print("[inv] " + GetSimulationTimeStamp() + " Man@" + this + " ::PredictiveTakeEntityToTargetAttachment input data not sent yet, cannot allow another input action");
  668. return false;
  669. }
  670. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), target))
  671. return JunctureTakeEntityToTargetAttachment(target, item);
  672. else
  673. return TakeEntityToTargetAttachmentImpl(InventoryMode.PREDICTIVE, target, item);
  674. }
  675. override bool LocalTakeEntityToTargetAttachment (notnull EntityAI target, notnull EntityAI item)
  676. {
  677. return TakeEntityToTargetAttachmentImpl(InventoryMode.LOCAL, target, item);
  678. }
  679. override bool ServerTakeEntityToTargetAttachment (notnull EntityAI target, notnull EntityAI item)
  680. {
  681. return TakeEntityToTargetAttachmentImpl(InventoryMode.SERVER, target, item);
  682. }
  683. protected bool TakeEntityToTargetAttachmentImpl (InventoryMode mode, notnull EntityAI target, notnull EntityAI item)
  684. {
  685. InventoryLocation il = new InventoryLocation;
  686. if( target.GetInventory().FindFreeLocationFor( item, FindInventoryLocationType.ATTACHMENT, il) )
  687. {
  688. return TakeEntityToTargetAttachmentExImpl(mode, target, item, il.GetSlot());
  689. }
  690. return false;
  691. }
  692. ///@} to target att juncture
  693. ///@{ to dst juncture
  694. bool JunctureTakeToDst (notnull InventoryLocation src, notnull InventoryLocation dst)
  695. {
  696. return TakeToDstImpl(InventoryMode.JUNCTURE, src, dst);
  697. }
  698. override bool PredictiveTakeToDst (notnull InventoryLocation src, notnull InventoryLocation dst)
  699. {
  700. if (!ScriptInputUserData.CanStoreInputUserData())
  701. {
  702. Print("[inv] " + GetSimulationTimeStamp() + " Man@" + this + " ::PredictiveTakeToDst input data not sent yet, cannot allow another input action");
  703. return false;
  704. }
  705. if (NeedInventoryJunctureFromServer(src.GetItem(), src.GetParent(), dst.GetParent()))
  706. return JunctureTakeToDst(src, dst);
  707. else
  708. return TakeToDstImpl(InventoryMode.PREDICTIVE, src, dst);
  709. }
  710. override bool LocalTakeToDst (notnull InventoryLocation src, notnull InventoryLocation dst)
  711. {
  712. return TakeToDstImpl(InventoryMode.LOCAL, src, dst);
  713. }
  714. override bool ServerTakeToDst (notnull InventoryLocation src, notnull InventoryLocation dst)
  715. {
  716. return TakeToDstImpl(InventoryMode.SERVER, src, dst);
  717. }
  718. protected bool TakeToDstImpl (InventoryMode mode, notnull InventoryLocation src, notnull InventoryLocation dst)
  719. {
  720. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::Take2Dst(" + typename.EnumToString(InventoryMode, mode) + ") src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
  721. bool code = GetHumanInventory().TakeToDst(mode, src, dst);
  722. UpdateInventoryMenu();
  723. return code;
  724. }
  725. ///@} to dst juncture
  726. ///@} inventory
  727. void JunctureDeleteItem(EntityAI item)
  728. {
  729. }
  730. override bool CanBeSkinned()
  731. {
  732. return !GetIsFrozen();
  733. }
  734. override bool DisableVicinityIcon()
  735. {
  736. return true;
  737. }
  738. void UpdateInventoryMenu();
  739. ///@{ Stats
  740. //! Registers new stat type for this player.
  741. /*!
  742. \param[in] name The name of the stat type.
  743. */
  744. proto native bool StatRegister( string name );
  745. //! Gets counter value of the specified stat type.
  746. /*!
  747. \param[in] name The name of the stat type.
  748. */
  749. proto native float StatGet( string name );
  750. //! Gets counter value as string of the specified stat type.
  751. /*!
  752. \param[in] name The name of the stat type.
  753. \param[out] value A formatted string containing stat value.
  754. */
  755. proto void StatGetCounter( string name, out string value );
  756. //! Gets counter value as formatted time string of the specified stat type.
  757. /*!
  758. \param[in] name The name of the stat type.
  759. \param[out] value A formatted string containing stat value.
  760. */
  761. proto void StatGetAsTime( string name, out string value );
  762. //! Updates stat counter with given value.
  763. /*!
  764. \param[in] name The name of the stat type.
  765. \param[in] value The specified value.
  766. */
  767. proto native void StatUpdate( string name, float value );
  768. //! Updates stat counter by time.
  769. /*!
  770. Use this to measure play time.
  771. \param[in] name The name of the stat type.
  772. */
  773. proto native void StatUpdateByTime( string name );
  774. //! Updates stat counter by player's actual position.
  775. /*!
  776. Use this to measure player's travelling distance.
  777. \param[in] name The name of the stat type.
  778. */
  779. proto native void StatUpdateByPosition( string name );
  780. //! Updates stat counter by given position.
  781. /*!
  782. \param[in] name The name of the stat type.
  783. \param[in] pos The specified position.
  784. */
  785. proto native void StatUpdateByGivenPos( string name, vector pos );
  786. /*! Invokes read stats from server to client.
  787. \note Call this on client when you need update stats.
  788. */
  789. proto native void StatInvokeUpdate();
  790. /*! Invokes save stats from server to client.
  791. \note Call this on server when you need update stats.
  792. */
  793. proto native void StatSyncToClient();
  794. ///@} Stats
  795. bool IsInventorySoftLocked()
  796. {
  797. return false;
  798. }
  799. void SetInventorySoftLock(bool status);
  800. /// returns true if man is in transport, false otherwise
  801. bool IsInTransport()
  802. {
  803. return Transport.Cast(GetParent()) != null;
  804. }
  805. void StopDeathDarkeningEffect();
  806. bool PhysicalPredictiveDropItem(EntityAI entity, bool heavy_item_only = true);
  807. void SetProcessUIWarning(bool state);
  808. void OnGameplayDataHandlerSync(); //depricated, sync now happens before the player is created, calling of this event still happens for legacy reasons
  809. bool CanPlaceItem(EntityAI item);
  810. /*!
  811. Called when 2D optics are about to be drawn.
  812. \return Collection of optics to be drawn.
  813. Draws the provided optics when of `ItemOptics` type.
  814. Draws optic of current muzzle when of `Weapon_Base` type.
  815. */
  816. protected array<InventoryItem> OnDrawOptics2D()
  817. {
  818. return null;
  819. }
  820. };