handanimated_guards.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. int SlotToAnimType(notnull Man player, notnull InventoryLocation src, InventoryLocation dst = null)
  2. {
  3. //Print("src.GetType() " + src.GetType());
  4. InventoryLocation invloc1 = new InventoryLocation;
  5. //InventoryLocation invloc2 = new InventoryLocation;
  6. if ( (dst && dst.GetParent() && !dst.GetParent().GetHierarchyRootPlayer()) || (src && src.GetParent() && !src.GetParent().GetHierarchyRootPlayer()) )
  7. return -1;
  8. if (dst && (dst.GetType() == InventoryLocationType.ATTACHMENT || dst.GetType() == InventoryLocationType.CARGO))
  9. {
  10. invloc1.Copy(dst);
  11. //invloc2.Copy(src);
  12. }
  13. else if (src.GetType() == InventoryLocationType.ATTACHMENT || src.GetType() == InventoryLocationType.CARGO)
  14. {
  15. invloc1.Copy(src);
  16. //invloc2.Copy(dst);
  17. }
  18. else
  19. {
  20. return -1;
  21. }
  22. int val = -1;
  23. if ( invloc1.GetItem() && invloc1.GetItem().GetInventoryHandAnimation(invloc1,val) )
  24. {
  25. return val;
  26. }
  27. if (invloc1.GetType() == InventoryLocationType.ATTACHMENT /*|| src.GetType() == InventoryLocationType.HANDS*/)
  28. {
  29. //return WeaponHideShowTypes.HIDESHOW_SLOT_KNIFEBACK;
  30. switch (invloc1.GetSlot())
  31. {
  32. case InventorySlots.SHOULDER:
  33. {
  34. if (invloc1.GetItem() && invloc1.GetItem().IsWeapon())
  35. {
  36. return WeaponHideShowTypes.HIDESHOW_SLOT_RFLLEFTBACK;
  37. }
  38. else if (invloc1.GetItem() && invloc1.GetItem().IsOneHandedBehaviour())
  39. {
  40. return WeaponHideShowTypes.HIDESHOW_SLOT_1HDLEFTBACK;
  41. }
  42. return WeaponHideShowTypes.HIDESHOW_SLOT_2HDLEFTBACK;
  43. }
  44. case InventorySlots.MELEE:
  45. {
  46. if (invloc1.GetItem() && invloc1.GetItem().IsWeapon())
  47. {
  48. return WeaponHideShowTypes.HIDESHOW_SLOT_RFLRIGHTBACK;
  49. }
  50. else if (invloc1.GetItem() && invloc1.GetItem().IsOneHandedBehaviour())
  51. {
  52. return WeaponHideShowTypes.HIDESHOW_SLOT_1HDRIGHTBACK;
  53. }
  54. return WeaponHideShowTypes.HIDESHOW_SLOT_2HDRIGHTBACK;
  55. }
  56. case InventorySlots.PISTOL:
  57. {
  58. EntityAI parent_item = invloc1.GetParent(); // belt
  59. Man owner;
  60. if (parent_item)
  61. owner = parent_item.GetHierarchyRootPlayer(); // player
  62. if (!owner)
  63. return -1;
  64. EntityAI item1 = owner.GetInventory().FindAttachment(InventorySlots.HIPS);
  65. EntityAI item2 = parent_item.GetHierarchyParent();
  66. if (owner && item1 == item2) // is the pistol in a belt holster?
  67. {
  68. return WeaponHideShowTypes.HIDESHOW_SLOT_PISTOLBELT;
  69. }
  70. return WeaponHideShowTypes.HIDESHOW_SLOT_PISTOLCHEST;
  71. }
  72. case InventorySlots.KNIFE:
  73. return WeaponHideShowTypes.HIDESHOW_SLOT_KNIFEBACK;
  74. /*case InventorySlots.VEST:
  75. case InventorySlots.FEET:
  76. case InventorySlots.BODY:
  77. case InventorySlots.LEGS:
  78. case InventorySlots.BACK:
  79. case InventorySlots.HIPS:
  80. case InventorySlots.HEADGEAR:
  81. return WeaponHideShowTypes.HIDESHOW_SLOT_INVENTORY;*/
  82. default:
  83. return WeaponHideShowTypes.HIDESHOW_SLOT_INVENTORY;
  84. //Print("[hndfsm] SlotToAnimType - not animated slot in src_loc=" + InventoryLocation.DumpToStringNullSafe(invloc1));
  85. };
  86. //
  87. //if (InventorySlots.GetSlotIdFromString("Pistol"))
  88. }
  89. else if (invloc1.GetType() == InventoryLocationType.CARGO)
  90. {
  91. if ( invloc1.GetItem() && (invloc1.GetItem().GetInventory().HasInventorySlot(InventorySlots.SHOULDER) || invloc1.GetItem().GetInventory().HasInventorySlot(InventorySlots.MELEE)) )
  92. {
  93. //Print("Special inventory anim");
  94. if (invloc1.GetItem() && invloc1.GetItem().IsWeapon())
  95. {
  96. return WeaponHideShowTypes.HIDESHOW_SLOT_RFLRIGHTBACK;
  97. }
  98. else if (invloc1.GetItem() && invloc1.GetItem().IsOneHandedBehaviour())
  99. {
  100. return WeaponHideShowTypes.HIDESHOW_SLOT_1HDRIGHTBACK;
  101. }
  102. return WeaponHideShowTypes.HIDESHOW_SLOT_2HDRIGHTBACK;
  103. }
  104. //Print("Default inventory anim");
  105. return WeaponHideShowTypes.HIDESHOW_SLOT_INVENTORY; //default item animation
  106. }
  107. return -1;
  108. }
  109. bool SelectAnimationOfTakeToHands(notnull Man player, notnull InventoryLocation src, notnull InventoryLocation dst, out int animType)
  110. {
  111. if (player.IsInTransport())
  112. return false;
  113. if (src.GetType() == InventoryLocationType.GROUND)
  114. return false;
  115. if (src.GetItem().GetHierarchyRootPlayer() == player)
  116. {
  117. animType = SlotToAnimType(player, src);
  118. if (animType != -1)
  119. {
  120. if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] SelectAnimationOfTakeToHands - selected animType=" + animType + " for item=" + src.GetItem());
  121. return true;
  122. }
  123. }
  124. if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] SelectAnimationOfTakeToHands - no animation");
  125. return false;
  126. }
  127. bool SelectAnimationOfMoveFromHands(notnull Man player, notnull InventoryLocation src, notnull InventoryLocation dst, out int animType)
  128. {
  129. if (player.IsInTransport())
  130. return false;
  131. if (src.GetItem().GetHierarchyRootPlayer() == player)
  132. {
  133. animType = SlotToAnimType(player, dst);
  134. if (animType != -1)
  135. {
  136. if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] SelectAnimationOfMoveFromHands guard - selected animType=" + animType + " for item=" + src.GetItem());
  137. return true;
  138. }
  139. }
  140. if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] SelectAnimationOfMoveFromHands - no animation");
  141. return false;
  142. }
  143. bool SelectAnimationOfForceSwapInHands(notnull Man player, notnull InventoryLocation old_src, notnull InventoryLocation new_src, notnull InventoryLocation old_dst, notnull InventoryLocation new_dst, out int animType1, out int animType2)
  144. {
  145. if (player.IsInTransport())
  146. return false;
  147. if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] SlotToAnimType - old_src=" + InventoryLocation.DumpToStringNullSafe(old_src) + " new_src=" + InventoryLocation.DumpToStringNullSafe(new_src) + " old_dst=" + InventoryLocation.DumpToStringNullSafe(old_dst) + " new_dst=" + InventoryLocation.DumpToStringNullSafe(new_dst));
  148. if (old_src.GetItem().GetHierarchyRootPlayer() == player || new_src.GetItem().GetHierarchyRootPlayer() == player)
  149. {
  150. animType1 = SlotToAnimType(player, old_src, old_dst);
  151. animType2 = SlotToAnimType(player, new_src, new_dst);
  152. //Print("animType1 = " + animType1);
  153. //Print("animType2 = " + animType2);
  154. if (animType1 != -1 && animType2 != -1)
  155. {
  156. if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] SelectAnimationOfForceSwapInHands guard - selected animType1=" + animType1 + " animType2=" + animType2 + " for old_item=" + old_src.GetItem() + " for new_item=" + new_src.GetItem());
  157. return true;
  158. }
  159. /*else if (animType1 != -1 || animType2 != -1) //HACK
  160. {
  161. animType1 = -1;
  162. animType2 = -1;
  163. return false;
  164. }*/
  165. }
  166. if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] SelectAnimationOfForceSwapInHands - no animation");
  167. return false;
  168. }
  169. class HandSelectAnimationOfTakeToHandsEvent extends HandGuardBase
  170. {
  171. void HandSelectAnimationOfTakeToHandsEvent(Man p = null) { }
  172. override bool GuardCondition(HandEventBase e)
  173. {
  174. int animType = -1;
  175. if (SelectAnimationOfTakeToHands(e.m_Player, e.GetSrc(), e.GetDst(), animType))
  176. {
  177. e.m_AnimationID = animType;
  178. return true;
  179. }
  180. return false;
  181. }
  182. };
  183. class HandSelectAnimationOfMoveFromHandsEvent extends HandGuardBase
  184. {
  185. protected Man m_Player;
  186. void HandSelectAnimationOfMoveFromHandsEvent(Man p = null)
  187. {
  188. m_Player = p;
  189. }
  190. override bool GuardCondition(HandEventBase e)
  191. {
  192. EntityAI eai = m_Player.GetHumanInventory().GetEntityInHands();
  193. if (eai)
  194. {
  195. InventoryLocation src = new InventoryLocation;
  196. if (eai.GetInventory().GetCurrentInventoryLocation(src))
  197. {
  198. if (e.m_IsJuncture == false && e.m_IsRemote == false)
  199. {
  200. if (!GameInventory.LocationCanMoveEntity(src, e.GetDst()))
  201. {
  202. if (LogManager.IsInventoryHFSMLogEnable())
  203. {
  204. hndDebugPrint("[hndfsm] HandSelectAnimationOfMoveFromHandsEvent - rejected");
  205. }
  206. return false;
  207. }
  208. }
  209. int animType = -1;
  210. if (SelectAnimationOfMoveFromHands(e.m_Player, src, e.GetDst(), animType))
  211. {
  212. e.m_AnimationID = animType;
  213. return true;
  214. }
  215. return false;
  216. }
  217. }
  218. return false;
  219. }
  220. };
  221. class HandSelectAnimationOfForceSwapInHandsEvent extends HandGuardBase
  222. {
  223. protected Man m_Player;
  224. void HandSelectAnimationOfForceSwapInHandsEvent(Man p = NULL) { m_Player = p; }
  225. bool ProcessSwapEvent(notnull HandEventBase e, out int animType1, out int animType2)
  226. {
  227. HandEventSwap es = HandEventSwap.Cast(e);
  228. if (es)
  229. return SelectAnimationOfForceSwapInHands(e.m_Player, es.m_Src, es.m_Src2, es.m_Dst, es.m_Dst2, animType1, animType2);
  230. Error("HandSelectAnimationOfForceSwapInHandsEvent - not an swap event");
  231. return false;
  232. }
  233. override bool GuardCondition(HandEventBase e)
  234. {
  235. HandEventForceSwap es = HandEventForceSwap.Cast(e);
  236. if (es)
  237. {
  238. if (LogManager.IsInventoryHFSMLogEnable())
  239. {
  240. hndDebugPrint("[hndfsm] HandSelectAnimationOfForceSwapInHandsEvent FSwap e=" + e.DumpToString());
  241. }
  242. if (!es.m_Src2.IsValid() || !es.m_Src.IsValid())
  243. {
  244. Error("[hndfsm] HandSelectAnimationOfForceSwapInHandsEvent - invalid item source");
  245. return false;
  246. }
  247. bool allow = e.m_IsJuncture || e.m_IsRemote;
  248. if (allow == false)
  249. {
  250. if (GameInventory.CanSwapEntitiesEx(es.GetSrc().GetItem(), es.m_Src2.GetItem()))
  251. {
  252. allow = true; // allow if ordinary swap
  253. }
  254. else if (es.m_Dst2)
  255. {
  256. if (GameInventory.CanForceSwapEntitiesEx(es.GetSrc().GetItem(), es.m_Dst, es.m_Src2.GetItem(), es.m_Dst2) == false)
  257. {
  258. Error("[hndfsm] HandSelectAnimationOfForceSwapInHandsEvent - no room at dst=" + InventoryLocation.DumpToStringNullSafe(es.m_Dst2));
  259. }
  260. else
  261. {
  262. allow = true;
  263. }
  264. }
  265. }
  266. if (allow)
  267. {
  268. int animType1 = -1;
  269. int animType2 = -1;
  270. if (ProcessSwapEvent(e, animType1, animType2))
  271. {
  272. e.m_AnimationID = animType1;
  273. es.m_Animation2ID = animType2;
  274. return true;
  275. }
  276. }
  277. else
  278. {
  279. Error("[hndfsm] HandSelectAnimationOfForceSwapInHandsEvent - m_HasRoomGuard.GuardCondition failed");
  280. }
  281. }
  282. else
  283. {
  284. Error("[hndfsm] HandSelectAnimationOfForceSwapInHandsEvent - not a swap event");
  285. }
  286. return false;
  287. }
  288. };
  289. class HandSelectAnimationOfSwapInHandsEvent extends HandSelectAnimationOfForceSwapInHandsEvent
  290. {
  291. override bool GuardCondition(HandEventBase e)
  292. {
  293. HandEventSwap es = HandEventSwap.Cast(e);
  294. if (es)
  295. {
  296. int animType1 = -1;
  297. int animType2 = -1;
  298. if (ProcessSwapEvent(e, animType1, animType2))
  299. {
  300. e.m_AnimationID = animType1;
  301. es.m_Animation2ID = animType2;
  302. return true;
  303. }
  304. }
  305. else
  306. Error("[hndfsm] HandSelectAnimationOfSwapInHandsEvent - not a swap event");
  307. return false;
  308. }
  309. };