kitbase.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. class KitBase extends ItemBase
  2. {
  3. protected bool m_DeployedRegularly;
  4. void KitBase()
  5. {
  6. RegisterNetSyncVariableBool("m_IsSoundSynchRemote");
  7. RegisterNetSyncVariableBool("m_IsDeploySound");
  8. }
  9. override bool IsBasebuildingKit()
  10. {
  11. return true;
  12. }
  13. override bool HasProxyParts()
  14. {
  15. return true;
  16. }
  17. override bool CanProxyObstruct()
  18. {
  19. return false;
  20. }
  21. override void OnVariablesSynchronized()
  22. {
  23. super.OnVariablesSynchronized();
  24. if ( IsDeploySound() )
  25. {
  26. PlayDeploySound();
  27. }
  28. if ( m_DeployedRegularly && IsSoundSynchRemote() )
  29. {
  30. PlayDeployFinishSound();
  31. }
  32. }
  33. override void EEInit()
  34. {
  35. super.EEInit();
  36. //set visual on init
  37. UpdateVisuals();
  38. UpdatePhysics();
  39. if (GetGame().IsServer())
  40. {
  41. GetGame().GetCallQueue( CALL_CATEGORY_GAMEPLAY ).Call( AssembleKit );
  42. }
  43. }
  44. override bool DisassembleOnLastDetach()
  45. {
  46. return true;
  47. }
  48. override void EEItemDetached(EntityAI item, string slot_name)
  49. {
  50. super.EEItemDetached( item, slot_name );
  51. PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
  52. if ( player && player.IsPlayerDisconnected() )
  53. return;
  54. if (item && slot_name == "Rope")
  55. {
  56. if (GetGame().IsServer() && !m_DeployedRegularly)
  57. {
  58. DisassembleKit(ItemBase.Cast(item));
  59. Delete();
  60. }
  61. }
  62. }
  63. override void OnItemLocationChanged( EntityAI old_owner, EntityAI new_owner )
  64. {
  65. super.OnItemLocationChanged( old_owner, new_owner );
  66. //update visuals after location change
  67. UpdatePhysics();
  68. }
  69. override void OnEndPlacement()
  70. {
  71. m_DeployedRegularly = true;
  72. SoundSynchRemote();
  73. }
  74. override void OnPlacementCancelled( Man player )
  75. {
  76. super.OnPlacementCancelled(player);
  77. m_DeployedRegularly = false;
  78. }
  79. override bool IsDeployable()
  80. {
  81. return true;
  82. }
  83. override bool CanAssignAttachmentsToQuickbar()
  84. {
  85. return false;
  86. }
  87. override string GetDeploySoundset()
  88. {
  89. return "putDown_FenceKit_SoundSet";
  90. }
  91. override string GetLoopDeploySoundset()
  92. {
  93. //return "BarbedWire_Deploy_loop_SoundSet";
  94. return "Shelter_Site_Build_Loop_SoundSet";
  95. }
  96. override string GetDeployFinishSoundset()
  97. {
  98. return "";
  99. }
  100. override void RefreshPhysics()
  101. {
  102. super.RefreshPhysics();
  103. UpdatePhysics();
  104. }
  105. //Update visuals and physics
  106. void UpdateVisuals()
  107. {
  108. SetAnimationPhase( "Inventory", 0 );
  109. SetAnimationPhase( "Placing", 1 );
  110. }
  111. void UpdatePhysics()
  112. {
  113. AddProxyPhysics( "Inventory" );
  114. RemoveProxyPhysics( "Placing" );
  115. }
  116. void AssembleKit()
  117. {
  118. if (!IsHologram())
  119. {
  120. Rope rope = Rope.Cast(GetInventory().CreateAttachment("Rope"));
  121. }
  122. }
  123. void DisassembleKit(ItemBase item) {}
  124. void CreateRope(Rope rope)
  125. {
  126. if (!rope)
  127. return;
  128. InventoryLocation targetLoc = rope.GetTargetLocation();
  129. if (targetLoc && targetLoc.GetType() != InventoryLocationType.GROUND)
  130. {
  131. MiscGameplayFunctions.TransferItemProperties(this, rope);
  132. return;
  133. }
  134. EntityAI newRope = EntityAI.Cast(GetGame().CreateObjectEx(rope.GetType(), GetPosition(), ECE_PLACE_ON_SURFACE));
  135. if (newRope)
  136. MiscGameplayFunctions.TransferItemProperties(this, newRope);
  137. rope.Delete();
  138. }
  139. override void SetActions()
  140. {
  141. super.SetActions();
  142. AddAction(ActionTogglePlaceObject);
  143. AddAction(ActionDeployObject);
  144. }
  145. //!DEPRECATED
  146. protected ref EffectSound m_DeployLoopSound; //DEPRECATED in favor of m_DeployLoopSoundEx
  147. void PlayDeployLoopSound(); //!DEPRECATED
  148. void StopDeployLoopSound(); //!DEPRECATED
  149. }