cablereel.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. class CableReel extends ItemBase
  2. {
  3. bool m_ForceIntoHands;
  4. static const string SEL_CORD_FOLDED = "cord_folded";
  5. static const string SEL_CORD_PLUGGED = "cord_plugged";
  6. void CableReel()
  7. {
  8. m_ForceIntoHands = false;
  9. }
  10. override bool IsElectricAppliance()
  11. {
  12. return true;
  13. }
  14. void ForceIntoHandsNow(PlayerBase player)
  15. {
  16. m_ForceIntoHands = true;
  17. player.LocalTakeEntityToHands(this); // Local, because ForceIntoHandsNow is executed on both, Client and Server
  18. m_ForceIntoHands = false;
  19. }
  20. override bool CanPutInCargo(EntityAI parent)
  21. {
  22. if (!super.CanPutInCargo(parent))
  23. return false;
  24. EntityAI owner = GetHierarchyParent();
  25. if (owner && owner.IsKindOf("Fence"))
  26. return true;
  27. bool allowIntoInventory = !GetCompEM().IsPlugged();
  28. return allowIntoInventory;
  29. }
  30. override bool CanPutIntoHands(EntityAI parent)
  31. {
  32. if (!super.CanPutIntoHands(parent))
  33. return false;
  34. if (m_ForceIntoHands)
  35. {
  36. return true;
  37. }
  38. else
  39. {
  40. EntityAI owner = GetHierarchyParent();
  41. if (owner && owner.IsKindOf("Fence"))
  42. return true;
  43. }
  44. return true;
  45. }
  46. // Event called on item when it is placed in the player(Man) inventory, passes the owner as a parameter
  47. override void OnInventoryEnter(Man player)
  48. {
  49. super.OnInventoryEnter(player);
  50. PlayerBase playerPB = PlayerBase.Cast(player);
  51. if (playerPB.GetItemInHands() == this && GetCompEM().IsPlugged())
  52. return;
  53. GetCompEM().UnplugAllDevices();
  54. if (!playerPB.IsPlacingLocal())
  55. GetCompEM().UnplugThis();
  56. }
  57. override bool CanRemoveFromHands(EntityAI parent)
  58. {
  59. return true;
  60. }
  61. //================================================================
  62. // ADVANCED PLACEMENT
  63. //================================================================
  64. override void OnPlacementStarted(Man player)
  65. {
  66. super.OnPlacementStarted(player);
  67. array<string> selections = {
  68. SEL_CORD_PLUGGED,
  69. SEL_CORD_FOLDED
  70. };
  71. PlayerBase playerPB = PlayerBase.Cast(player);
  72. if (GetGame().IsMultiplayer() && GetGame().IsServer())
  73. playerPB.GetHologramServer().SetSelectionToRefresh(selections);
  74. else
  75. playerPB.GetHologramLocal().SetSelectionToRefresh(selections);
  76. }
  77. override string GetDeploySoundset()
  78. {
  79. return "placeCableReel_SoundSet";
  80. }
  81. override void SetActions()
  82. {
  83. super.SetActions();
  84. RemoveAction(ActionTakeItemToHands);
  85. AddAction(ActionPlugIn);
  86. AddAction(ActionPlugTargetIntoThis);
  87. AddAction(ActionTogglePlaceObject);
  88. AddAction(ActionPullOutPlug);
  89. AddAction(ActionUnplugThisByCord);
  90. AddAction(ActionRepositionPluggedItem);
  91. AddAction(ActionPlaceObject);
  92. AddAction(ActionTakeItemToHands);
  93. }
  94. }