cablereel.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. RegisterNetSyncVariableBool("m_IsSoundSynchRemote");
  10. RegisterNetSyncVariableBool("m_IsPlaceSound");
  11. }
  12. override bool IsElectricAppliance()
  13. {
  14. return true;
  15. }
  16. void ForceIntoHandsNow(PlayerBase player)
  17. {
  18. m_ForceIntoHands = true;
  19. player.LocalTakeEntityToHands(this); // Local, because ForceIntoHandsNow is executed on both, Client and Server
  20. m_ForceIntoHands = false;
  21. }
  22. override bool CanPutInCargo(EntityAI parent)
  23. {
  24. if (!super.CanPutInCargo(parent))
  25. return false;
  26. EntityAI owner = GetHierarchyParent();
  27. if (owner && owner.IsKindOf("Fence"))
  28. return true;
  29. bool allowIntoInventory = !GetCompEM().IsPlugged();
  30. return allowIntoInventory;
  31. }
  32. override bool CanPutIntoHands(EntityAI player)
  33. {
  34. if (!super.CanPutIntoHands(parent))
  35. return false;
  36. if (m_ForceIntoHands)
  37. {
  38. return true;
  39. }
  40. else
  41. {
  42. EntityAI owner = GetHierarchyParent();
  43. if (owner && owner.IsKindOf("Fence"))
  44. return true;
  45. }
  46. return true;
  47. }
  48. // Event called on item when it is placed in the player(Man) inventory, passes the owner as a parameter
  49. override void OnInventoryEnter(Man player)
  50. {
  51. super.OnInventoryEnter(player);
  52. PlayerBase playerPB = PlayerBase.Cast(player);
  53. if (playerPB.GetItemInHands() == this && GetCompEM().IsPlugged())
  54. return;
  55. GetCompEM().UnplugAllDevices();
  56. if (!playerPB.IsPlacingLocal())
  57. GetCompEM().UnplugThis();
  58. }
  59. override bool CanRemoveFromHands(EntityAI player)
  60. {
  61. return true;
  62. }
  63. override void OnVariablesSynchronized()
  64. {
  65. super.OnVariablesSynchronized();
  66. if (IsPlaceSound())
  67. PlayPlaceSound();
  68. }
  69. //================================================================
  70. // ADVANCED PLACEMENT
  71. //================================================================
  72. override void OnPlacementStarted(Man player)
  73. {
  74. super.OnPlacementStarted(player);
  75. array<string> selections = {
  76. SEL_CORD_PLUGGED,
  77. SEL_CORD_FOLDED
  78. };
  79. PlayerBase playerPB = PlayerBase.Cast(player);
  80. if (GetGame().IsMultiplayer() && GetGame().IsServer())
  81. playerPB.GetHologramServer().SetSelectionToRefresh(selections);
  82. else
  83. playerPB.GetHologramLocal().SetSelectionToRefresh(selections);
  84. }
  85. override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
  86. {
  87. super.OnPlacementComplete(player, position, orientation);
  88. SetIsPlaceSound(true);
  89. }
  90. override string GetPlaceSoundset()
  91. {
  92. return "placeCableReel_SoundSet";
  93. }
  94. override void SetActions()
  95. {
  96. super.SetActions();
  97. RemoveAction(ActionTakeItemToHands);
  98. AddAction(ActionPlugIn);
  99. AddAction(ActionPlugTargetIntoThis);
  100. AddAction(ActionTogglePlaceObject);
  101. AddAction(ActionPullOutPlug);
  102. AddAction(ActionUnplugThisByCord);
  103. AddAction(ActionRepositionPluggedItem);
  104. AddAction(ActionPlaceObject);
  105. AddAction(ActionTakeItemToHands);
  106. }
  107. }