actionplugtargetintothis.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. class ActionPlugTargetIntoThis: ActionSingleUseBase
  2. {
  3. bool m_Retoggle;
  4. void ActionPlugTargetIntoThis()
  5. {
  6. m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_INTERACTONCE;
  7. m_Retoggle = false;
  8. m_Text = "#connect_together";
  9. }
  10. override void CreateConditionComponents()
  11. {
  12. m_ConditionItem = new CCINonRuined();
  13. m_ConditionTarget = new CCTNonRuined(UAMaxDistances.DEFAULT);
  14. }
  15. override bool Can(PlayerBase player, ActionTarget target, ItemBase item)
  16. {
  17. if (super.Can(player, target, item))
  18. {
  19. if (player.IsPlacingLocal())
  20. {
  21. m_Retoggle = true;
  22. player.GetHologramLocal().SetIsHidden(true);
  23. player.GetHologramLocal().GetProjectionEntity().HideAllSelections();
  24. }
  25. }
  26. if (!super.Can(player, target, item))
  27. {
  28. if (m_Retoggle)
  29. {
  30. m_Retoggle = false;
  31. player.GetHologramLocal().SetIsHidden(false);
  32. player.GetHologramLocal().GetProjectionEntity().ShowAllSelections();
  33. }
  34. }
  35. return super.Can(player, target, item);
  36. }
  37. override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
  38. {
  39. ItemBase targetIB = ItemBase.Cast(target.GetObject());
  40. //Prevent plugging to items in inventory
  41. if (targetIB && targetIB.GetHierarchyRoot() == targetIB && item && targetIB.HasEnergyManager() && item.HasEnergyManager())
  42. {
  43. if (!targetIB.GetCompEM().IsPlugged() && item.GetCompEM().CanReceivePlugFrom(targetIB))
  44. {
  45. //hotfix, re-work entire action!
  46. return targetIB.IsElectricAppliance();
  47. }
  48. // Special case for vehicle batteries
  49. if (item.IsInherited(VehicleBattery))
  50. {
  51. MetalWire metalWire = MetalWire.Cast(item.GetCompEM().GetPluggedDevice());
  52. if (metalWire && metalWire.GetCompEM().CanReceivePlugFrom(targetIB))
  53. {
  54. return true; // We can power the action_data.m_Target from vehicle battery because it has metal wire attached.
  55. }
  56. }
  57. }
  58. return false;
  59. }
  60. override bool IsDeploymentAction()
  61. {
  62. return true;
  63. }
  64. override void OnExecuteServer(ActionData action_data)
  65. {
  66. Process(action_data);
  67. }
  68. override void OnExecuteClient(ActionData action_data)
  69. {
  70. m_Retoggle = false;
  71. }
  72. void Process(ActionData action_data)
  73. {
  74. ItemBase targetIB = ItemBase.Cast(action_data.m_Target.GetObject());
  75. if (action_data.m_MainItem.IsInherited(VehicleBattery))
  76. {
  77. // Car/truck batteries can have a metal wire attached through which they can power common electric appliances
  78. MetalWire metalWire = MetalWire.Cast(action_data.m_MainItem.GetCompEM().GetPluggedDevice());
  79. if (metalWire)
  80. targetIB.GetCompEM().PlugThisInto(metalWire);
  81. }
  82. else
  83. {
  84. // Everything else in general
  85. targetIB.GetCompEM().PlugThisInto(action_data.m_MainItem);
  86. }
  87. Spotlight spotlight;
  88. if (Spotlight.CastTo(spotlight, targetIB))
  89. spotlight.Unfold();
  90. targetIB.GetInventory().TakeEntityAsAttachment(InventoryMode.LOCAL, action_data.m_MainItem);
  91. action_data.m_Player.ServerDropEntity(action_data.m_MainItem);
  92. }
  93. }