actionpackgift.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. class ActionPackGiftCB : ActionContinuousBaseCB
  2. {
  3. override void CreateActionComponent()
  4. {
  5. m_ActionData.m_ActionComponent = new CAContinuousTime(UATimeSpent.UNPACK);
  6. }
  7. };
  8. class ActionPackGift: ActionContinuousBase
  9. {
  10. void ActionPackGift()
  11. {
  12. m_CallbackClass = ActionPackGiftCB;
  13. m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_OPENITEM;
  14. //m_FullBody = true;
  15. m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH;
  16. m_SpecialtyWeight = UASoftSkillsWeight.ROUGH_LOW;
  17. m_Text = "#STR_Wrap";
  18. }
  19. override void CreateConditionComponents()
  20. {
  21. m_ConditionItem = new CCINonRuined;
  22. m_ConditionTarget = new CCTNonRuined;
  23. }
  24. override bool HasTarget()
  25. {
  26. return true;
  27. }
  28. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  29. {
  30. ItemBase item_to_pack = ItemBase.Cast(target.GetObject());
  31. if (!item_to_pack)
  32. return false;
  33. if ( !item_to_pack.IsTakeable() ) return false;
  34. if ( item_to_pack.IsBeingPlaced() ) return false;
  35. if ( BaseBuildingBase.Cast(item_to_pack) ) return false;
  36. if ( !item_to_pack.CanPutInCargo(null) ) return false;
  37. EntityAI tgt_parent = EntityAI.Cast( target.GetParent() );
  38. if ( tgt_parent )
  39. {
  40. if ( item_to_pack.GetInventory().IsAttachment() )
  41. {
  42. if ( !item_to_pack.CanDetachAttachment(tgt_parent) || !tgt_parent.CanReleaseAttachment(item_to_pack) )
  43. return false;
  44. }
  45. else
  46. {
  47. if ( !item_to_pack.CanRemoveFromCargo(tgt_parent) || !tgt_parent.CanReleaseCargo(item_to_pack) )
  48. return false;
  49. }
  50. }
  51. if ( item_to_pack.GetInventory().GetCargo() && item_to_pack.GetInventory().GetCargo().GetItemCount() > 0)
  52. return false;
  53. if ( !item_to_pack.IsWeapon() && item_to_pack.GetInventory().AttachmentCount() > 0)
  54. return false;
  55. int x,y;
  56. GetGame().GetInventoryItemSize( item_to_pack, x, y );
  57. if( x > 5 || y > 5 )
  58. return false;
  59. return true;
  60. }
  61. override void OnFinishProgressClient( ActionData action_data )
  62. {
  63. PlayerBase player = action_data.m_Player;
  64. ItemBase item_to_pack = ItemBase.Cast(action_data.m_Target.GetObject());
  65. player.RemoveQuickBarEntityShortcut(item_to_pack);
  66. }
  67. override void OnFinishProgressServer( ActionData action_data )
  68. {
  69. ItemBase item_to_pack = ItemBase.Cast(action_data.m_Target.GetObject());
  70. ItemBase item = action_data.m_MainItem;
  71. PlayerBase player = action_data.m_Player;
  72. string typeName;
  73. if (item_to_pack)
  74. {
  75. int x,y;
  76. GetGame().GetInventoryItemSize( item_to_pack, x, y );
  77. int rnd = Math.RandomIntInclusive(1, 4);
  78. ReplaceWithNewReciveCargoLambda lambda;
  79. if( x <= 2 && y <= 2 )
  80. {
  81. typeName = "GiftBox_Small_" + rnd;
  82. }
  83. else if( x <= 3 && y <= 3 )
  84. {
  85. typeName = "GiftBox_Medium_" + rnd;
  86. }
  87. else if( x <= 5 && y <= 5 )
  88. {
  89. typeName = "GiftBox_Large_" + rnd;
  90. }
  91. else return;
  92. if(!GetGame().IsDedicatedServer())
  93. player.RemoveQuickBarEntityShortcut(item_to_pack);
  94. lambda = new ReplaceWithNewReciveCargoLambda( item, typeName, player,item_to_pack);
  95. player.ServerReplaceItemWithNew(lambda);
  96. }
  97. }
  98. };
  99. class ReplaceWithNewReciveCargoLambda : TurnItemIntoItemLambda
  100. {
  101. protected EntityAI m_ItemToCargo;
  102. void ReplaceWithNewReciveCargoLambda(EntityAI old_item, string new_item_type, PlayerBase player, EntityAI item_to_cargo)
  103. {
  104. m_ItemToCargo = item_to_cargo;
  105. }
  106. override void OnSuccess(EntityAI new_item)
  107. {
  108. super.OnSuccess(new_item);
  109. InventoryLocation src = new InventoryLocation;
  110. m_ItemToCargo.GetInventory().GetCurrentInventoryLocation(src);
  111. InventoryLocation dst = new InventoryLocation;
  112. dst.SetCargo(new_item, m_ItemToCargo, 0,0,0,false);
  113. if ( dst.IsValid() )
  114. {
  115. if(GetGame().IsDedicatedServer())
  116. m_Player.ServerTakeToDst(src,dst);
  117. else
  118. m_Player.LocalTakeToDst(src,dst);
  119. }
  120. }
  121. };