actionunpackbox.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. class ActionUnpackBoxCB : ActionContinuousBaseCB
  2. {
  3. override void CreateActionComponent()
  4. {
  5. m_ActionData.m_ActionComponent = new CAContinuousTime(UATimeSpent.UNPACK);
  6. }
  7. };
  8. class ActionUnpackBox: ActionContinuousBase
  9. {
  10. void ActionUnpackBox()
  11. {
  12. m_CallbackClass = ActionUnpackBoxCB;
  13. m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_OPENITEM;
  14. m_CommandUIDProne = DayZPlayerConstants.CMD_ACTIONFB_OPENITEM;
  15. m_SpecialtyWeight = UASoftSkillsWeight.PRECISE_LOW;
  16. m_Text = "#unbox";
  17. }
  18. override void CreateConditionComponents()
  19. {
  20. m_ConditionItem = new CCINonRuined;
  21. m_ConditionTarget = new CCTNone;
  22. }
  23. override bool HasProneException()
  24. {
  25. return true;
  26. }
  27. override bool HasTarget()
  28. {
  29. return false;
  30. }
  31. override void OnFinishProgressServer( ActionData action_data )
  32. {
  33. if ( action_data.m_MainItem && action_data.m_MainItem.GetHierarchyRootPlayer() == action_data.m_Player )
  34. {
  35. string path = "CfgVehicles " + action_data.m_MainItem.GetType();
  36. string child_name = "";
  37. int count;
  38. array<string> resources = new array<string>;
  39. if( GetGame().ConfigIsExisting( path ) && GetGame().ConfigIsExisting( path + " Resources") )
  40. {
  41. path = path + " Resources";
  42. count = GetGame().ConfigGetChildrenCount ( path );
  43. for (int i = 0; i < count; i++)
  44. {
  45. GetGame().ConfigGetChildName ( path, i, child_name );
  46. if ( GetGame().ConfigGetInt( path + " " + child_name + " value" ) )
  47. {
  48. resources.Insert( child_name );
  49. }
  50. }
  51. //TODO modify to allow for multiple ammo types spawning (if needed??)
  52. string itemType = resources.Get(0);
  53. int itemCount = GetGame().ConfigGetInt( path + " " + itemType + " value" );
  54. UnboxLambda lambda = new UnboxLambda(action_data.m_MainItem, itemType, action_data.m_Player, itemCount);
  55. action_data.m_Player.ServerReplaceItemInHandsWithNew(lambda);
  56. }
  57. }
  58. }
  59. };
  60. class UnboxLambda : ReplaceItemWithNewLambdaBase
  61. {
  62. int m_ItemCount;
  63. void UnboxLambda (EntityAI old_item, string new_item_type, PlayerBase player, int count) { m_ItemCount = count; }
  64. override void CopyOldPropertiesToNew (notnull EntityAI old_item, EntityAI new_item)
  65. {
  66. super.CopyOldPropertiesToNew(old_item, new_item);
  67. if ( GetGame().ConfigIsExisting( "CfgMagazines " + m_NewItemType ) )
  68. {
  69. Magazine pile;
  70. Class.CastTo(pile, new_item);
  71. pile.ServerSetAmmoCount(m_ItemCount);
  72. }
  73. else
  74. {
  75. ItemBase unboxed;
  76. Class.CastTo(unboxed, new_item);
  77. unboxed.SetQuantity(m_ItemCount);
  78. }
  79. }
  80. override void OnSuccess(EntityAI new_item)
  81. {
  82. super.OnSuccess(new_item);
  83. //spawns wrapping Paper
  84. ItemBase paper = ItemBase.Cast( GetGame().CreateObjectEx("Paper", new_item.GetHierarchyRoot().GetPosition(), ECE_PLACE_ON_SURFACE) );
  85. }
  86. };