actionungagself.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. class ActionUngagSelf: ActionContinuousBase
  2. {
  3. void ActionUngagSelf()
  4. {
  5. m_CallbackClass = ActionUncoverHeadSelfCB;
  6. m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_COVERHEAD_SELF;
  7. m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH;
  8. m_Text = "#ungag";
  9. }
  10. override void CreateConditionComponents()
  11. {
  12. m_ConditionItem = new CCINone;
  13. m_ConditionTarget = new CCTNone;
  14. }
  15. override bool HasTarget()
  16. {
  17. return false;
  18. }
  19. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  20. {
  21. if ( IsWearingGag(player) && null == player.GetHumanInventory().GetEntityInHands())
  22. return true;
  23. return false;
  24. }
  25. override void OnFinishProgressServer( ActionData action_data )
  26. {
  27. EntityAI attachment;
  28. Class.CastTo(attachment, action_data.m_Player.GetInventory().FindAttachment(InventorySlots.MASK));
  29. if ( attachment && attachment.GetType() == "MouthRag" )
  30. {
  31. UngagSelfLambda lamb = new UngagSelfLambda(attachment, "Rag", action_data.m_Player);
  32. lamb.SetTransferParams(true, true, true, false, 1);
  33. action_data.m_Player.ServerReplaceItemElsewhereWithNewInHands(lamb);
  34. }
  35. }
  36. bool IsWearingGag( PlayerBase player )
  37. {
  38. EntityAI attachment;
  39. Class.CastTo(attachment, player.GetInventory().FindAttachment(InventorySlots.MASK));
  40. if ( attachment && attachment.GetType() == "MouthRag" )
  41. {
  42. return true;
  43. }
  44. return false;
  45. }
  46. };
  47. class UngagSelfLambda : TurnItemIntoItemLambda
  48. {
  49. MouthRag gag;
  50. EntityAI m_OriginalOwner;
  51. void UngagSelfLambda (EntityAI old_item, string new_item_type, PlayerBase player)
  52. {
  53. gag = MouthRag.Cast(m_OldItem);
  54. if (gag)
  55. gag.SetIncomingLambaBool(true);
  56. InventoryLocation targetHnd = new InventoryLocation;
  57. targetHnd.SetHands(player, null);
  58. OverrideNewLocation(targetHnd);
  59. m_OriginalOwner = m_OldItem.GetHierarchyRoot();
  60. }
  61. override void OnSuccess (EntityAI new_item)
  62. {
  63. super.OnSuccess(new_item);
  64. PlayerBase player;
  65. if (Class.CastTo(player,m_OriginalOwner))
  66. {
  67. player.CheckForGag();
  68. }
  69. }
  70. override void OnAbort ()
  71. {
  72. if (gag)
  73. gag.SetIncomingLambaBool(false);
  74. }
  75. };