actionforceconsume.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. class ActionForceConsumeCB : ActionContinuousBaseCB
  2. {
  3. override void CreateActionComponent()
  4. {
  5. m_ActionData.m_ActionComponent = new CAContinuousQuantityEdible(UAQuantityConsumed.DEFAULT, UATimeSpent.DEFAULT);
  6. }
  7. }
  8. class ActionForceConsume : ActionContinuousBase
  9. {
  10. protected const float SOUND_REPEAT_INTERVAL = 1.5;
  11. void ActionForceConsume()
  12. {
  13. m_CallbackClass = ActionForceConsumeCB;
  14. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_FORCEFEED;
  15. m_StanceMask = DayZPlayerConstants.STANCEIDX_ERECT | DayZPlayerConstants.STANCEIDX_CROUCH;
  16. m_FullBody = true;
  17. m_Text = "#feed";
  18. }
  19. override void CreateConditionComponents()
  20. {
  21. m_ConditionTarget = new CCTMan(UAMaxDistances.DEFAULT);
  22. m_ConditionItem = new CCINonRuined();
  23. }
  24. override void OnStartServer(ActionData action_data)
  25. {
  26. super.OnStartServer(action_data);
  27. PlayerBase player = PlayerBase.Cast(action_data.m_Target.GetObject());
  28. if (player)
  29. GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(PlaySound, SOUND_REPEAT_INTERVAL * 1000, true, player);
  30. }
  31. override void OnEndServer(ActionData action_data)
  32. {
  33. super.OnEndServer(action_data);
  34. if (action_data.m_MainItem && (action_data.m_MainItem.GetQuantity() <= 0.01))
  35. {
  36. action_data.m_MainItem.SetQuantity(0);
  37. }
  38. GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).Remove(PlaySound);
  39. }
  40. override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
  41. {
  42. if (!super.ActionCondition(player, target, item))
  43. return false;
  44. PlayerBase targetPlayer = PlayerBase.Cast(target.GetObject());
  45. if (!targetPlayer || !targetPlayer.CanEatAndDrink())
  46. return false;
  47. float angleDiff = Math.AbsFloat(player.GetDirection().VectorToAngles()[0] - targetPlayer.GetDirection().VectorToAngles()[0]);
  48. if (angleDiff < 135 || angleDiff > 225) // not in 90 deg cone angle facing the other player
  49. return false;
  50. if (targetPlayer.GetPerformedActionID() != -1 || targetPlayer.GetActivePrimarySymptomID() == SymptomIDs.SYMPTOM_VOMIT)
  51. return false;
  52. return ( (item.GetQuantity() > item.GetQuantityMin()) && !item.GetIsFrozen() );
  53. }
  54. protected void PlaySound(PlayerBase player)
  55. {
  56. if (player)
  57. player.RequestSoundEventEx(EPlayerSoundEventID.FORCE_FEED);
  58. }
  59. }