firearmactionloadmultibullet.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. class FirearmActionLoadMultiBullet : FirearmActionBase
  2. {
  3. //-----------------------------------------------------
  4. // Action events and methods
  5. //-----------------------------------------------------
  6. void FirearmActionLoadMultiBullet()
  7. {
  8. m_Text = "#load_bullets";
  9. }
  10. override int GetActionCategory()
  11. {
  12. return AC_CONTINUOUS;
  13. }
  14. /*string GetTargetDescription()
  15. {
  16. return "default target description";
  17. }*/
  18. /*protected bool ActionConditionContinue( ActionData action_data ) //condition for action
  19. {
  20. return true;
  21. }*/
  22. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item ) //condition for action
  23. {
  24. if (!super.ActionCondition( player, target, item ))
  25. return false;
  26. Weapon_Base wpn = Weapon_Base.Cast(item);
  27. Magazine mag = Magazine.Cast(target.GetObject());
  28. return mag && player.GetWeaponManager().CanLoadMultipleBullet(wpn,mag);
  29. }
  30. override void Start( ActionData action_data )
  31. {
  32. super.Start( action_data );
  33. Magazine mag = Magazine.Cast(action_data.m_Target.GetObject());
  34. action_data.m_Player.GetWeaponManager().LoadMultiBullet(mag, this);
  35. }
  36. override bool CanBePerformedFromInventory()
  37. {
  38. return false;
  39. }
  40. override bool CanBeSetFromInventory()
  41. {
  42. return false;
  43. }
  44. override void OnEndInput( ActionData action_data )
  45. {
  46. action_data.m_Player.GetWeaponManager().LoadMultiBulletStop();
  47. }
  48. override bool CanBePerformedFromQuickbar()
  49. {
  50. return true;
  51. }
  52. override bool HasProgress()
  53. {
  54. return false;
  55. }
  56. // action need first have permission from server before can start
  57. /*bool UseAcknowledgment()
  58. {
  59. return true;
  60. }*/
  61. /*override int GetState( ActionData action_data )
  62. {
  63. return UA_PROCESSING;
  64. }*/
  65. /*override float GetProgress( ActionData action_data )
  66. {
  67. return -1;
  68. }*/
  69. override typename GetInputType()
  70. {
  71. return ContinuousDefaultActionInput;
  72. }
  73. };
  74. class FirearmActionLoadMultiBulletQuick : FirearmActionBase
  75. {
  76. //-----------------------------------------------------
  77. // Action events and methods
  78. //-----------------------------------------------------
  79. void FirearmActionLoadMultiBulletQuick()
  80. {
  81. }
  82. override bool HasTarget()
  83. {
  84. return false;
  85. }
  86. override bool HasProgress()
  87. {
  88. return false;
  89. }
  90. override typename GetInputType()
  91. {
  92. return ContinuousWeaponManipulationActionInput;
  93. }
  94. override void CreateConditionComponents()
  95. {
  96. m_ConditionItem = new CCINonRuined();
  97. m_ConditionTarget = new CCTSelf;
  98. }
  99. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item ) //condition for action
  100. {
  101. if (!super.ActionCondition( player, target, item ))
  102. return false;
  103. Weapon_Base weapon = Weapon_Base.Cast( item );
  104. return player.GetWeaponManager().CanLoadMultipleBullet(weapon ,player.GetWeaponManager().GetPreparedMagazine());
  105. }
  106. override void Start( ActionData action_data )
  107. {
  108. super.Start( action_data );
  109. WeaponManager weaponManager = action_data.m_Player.GetWeaponManager();
  110. int idx = 0;
  111. Magazine mag = weaponManager.GetNextPreparedMagazine(idx);
  112. Weapon weapon = Weapon.Cast(action_data.m_Player.GetItemInHands());
  113. int internalCount = weapon.GetInternalMagazineCartridgeCount(0);
  114. int maxCount = weapon.GetInternalMagazineMaxCartridgeCount(0) + 1;
  115. int total = mag.GetAmmoCount() + internalCount;
  116. if (total < maxCount)
  117. {
  118. //Increment index for the first additional mag find, since GetNextPreparedMagazine does not do that
  119. //Normally the mag at found index is combined right after, removing it from the suitable magazine array
  120. ++idx;
  121. Magazine additionalMag = weaponManager.GetNextPreparedMagazine(idx);
  122. while ((additionalMag != null) && (total < maxCount))
  123. {
  124. total += additionalMag.GetAmmoCount();
  125. mag.CombineItems(additionalMag);
  126. additionalMag = weaponManager.GetNextPreparedMagazine(idx);
  127. }
  128. }
  129. action_data.m_Player.GetWeaponManager().LoadMultiBullet(mag, this);
  130. }
  131. override void OnEndInput( ActionData action_data )
  132. {
  133. action_data.m_Player.GetWeaponManager().LoadMultiBulletStop();
  134. }
  135. };
  136. class FirearmActionLoadMultiBulletRadial : FirearmActionBase
  137. {
  138. //-----------------------------------------------------
  139. // Action events and methods
  140. //-----------------------------------------------------
  141. void FirearmActionLoadMultiBulletRadial()
  142. {
  143. }
  144. override bool HasProgress()
  145. {
  146. return false;
  147. }
  148. override void CreateConditionComponents()
  149. {
  150. m_ConditionItem = new CCINonRuined();
  151. m_ConditionTarget = new CCTSelf;
  152. }
  153. override bool CanContinue( ActionData action_data )
  154. {
  155. if (!super.CanContinue( action_data ))
  156. return false;
  157. return ActionCondition(action_data.m_Player, action_data.m_Target, action_data.m_MainItem);
  158. }
  159. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item ) //condition for action
  160. {
  161. if (!super.ActionCondition( player, target, item ))
  162. return false;
  163. Weapon_Base wpn = Weapon_Base.Cast(item);
  164. Magazine mag = Magazine.Cast(target.GetObject());
  165. return mag && player.GetWeaponManager().CanLoadBullet(wpn,mag);
  166. }
  167. override void OnStart( ActionData action_data )
  168. {
  169. super.OnStart(action_data);
  170. Magazine mag = Magazine.Cast(action_data.m_Target.GetObject());
  171. action_data.m_Player.GetWeaponManager().LoadMultiBullet(mag, this);
  172. }
  173. override void OnEnd( ActionData action_data )
  174. {
  175. action_data.m_Player.GetWeaponManager().LoadMultiBulletStop();
  176. }
  177. };