actionplugin.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. class ActionPlugIn: ActionSingleUseBase
  2. {
  3. void ActionPlugIn()
  4. {
  5. m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_INTERACTONCE;
  6. m_Text = "#plug_in";
  7. }
  8. override void CreateConditionComponents()
  9. {
  10. m_ConditionItem = new CCINonRuined();
  11. m_ConditionTarget = new CCTNonRuined(UAMaxDistances.DEFAULT);
  12. }
  13. override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
  14. {
  15. if (player.IsPlacingLocal())
  16. return false;
  17. ItemBase targetIB = ItemBase.Cast(target.GetObject());
  18. //Prevent plugging to items in inventory
  19. if (targetIB && targetIB.GetHierarchyRoot() == targetIB && item)
  20. {
  21. if (item.HasEnergyManager() && !item.GetCompEM().IsPlugged() && targetIB.HasEnergyManager() && targetIB.GetCompEM().CanReceivePlugFrom(item))
  22. {
  23. return true;
  24. }
  25. ItemBase attachedDevice = GetAttachedDevice(targetIB);
  26. //Will only ever affect batteries
  27. if (attachedDevice)
  28. {
  29. return attachedDevice.GetCompEM().HasFreeSocket();
  30. }
  31. }
  32. return false;
  33. }
  34. override void OnExecuteServer(ActionData action_data)
  35. {
  36. ItemBase targetIB = ItemBase.Cast(action_data.m_Target.GetObject());
  37. if (targetIB.HasEnergyManager())
  38. {
  39. ItemBase attachedDevice = GetAttachedDevice(targetIB);
  40. if (attachedDevice)
  41. targetIB = attachedDevice;
  42. action_data.m_MainItem.GetCompEM().PlugThisInto(targetIB);
  43. if (!g_Game.IsDedicatedServer())
  44. {
  45. if (!action_data.m_Player.IsPlacingLocal())
  46. {
  47. action_data.m_Player.PlacingStartLocal(action_data.m_MainItem);
  48. Process(action_data);
  49. }
  50. }
  51. else
  52. {
  53. if (!action_data.m_Player.IsPlacingServer())
  54. {
  55. action_data.m_Player.PlacingStartServer(action_data.m_MainItem);
  56. Process(action_data);
  57. }
  58. }
  59. }
  60. }
  61. void Process(ActionData action_data)
  62. {
  63. ItemBase targetIB = ItemBase.Cast(action_data.m_Target.GetObject());
  64. targetIB.GetInventory().TakeEntityAsAttachment(InventoryMode.LOCAL, action_data.m_MainItem);
  65. }
  66. override void OnExecuteClient(ActionData action_data)
  67. {
  68. if (!action_data.m_Player.IsPlacingLocal())
  69. action_data.m_Player.PlacingStartLocal(action_data.m_MainItem);
  70. else
  71. Process(action_data);
  72. }
  73. ItemBase GetAttachedDevice(ItemBase parent)
  74. {
  75. if (parent.IsInherited(CarBattery) || parent.IsInherited(TruckBattery))
  76. {
  77. ItemBase parentAttachment = ItemBase.Cast(parent.GetAttachmentByType(MetalWire));
  78. if (!parentAttachment)
  79. parentAttachment = ItemBase.Cast(parent.GetAttachmentByType(BarbedWire));
  80. return parentAttachment;
  81. }
  82. return null;
  83. }
  84. };