private void ConstructionAmountChanged(ConstructionAmountChangedEvent amountChanged) { Log.Debug($"Processing ConstructionAmountChanged {amountChanged.Id} {amountChanged.Amount}"); GameObject constructing = NitroxEntity.RequireObjectFrom(amountChanged.Id); BaseDeconstructable baseDeconstructable = constructing.GetComponent <BaseDeconstructable>(); // Bases don't send a deconstruct being packet. Instead, we just make sure // that if we are changing the amount that we set it into deconstruction mode // if it still has a BaseDeconstructable object on it. if (baseDeconstructable != null) { baseDeconstructable.Deconstruct(); // After we have begun the deconstructing for a base piece, we need to transfer the id Optional <object> opGhost = TransientLocalObjectManager.Get(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GHOST); if (opGhost.HasValue) { GameObject ghost = (GameObject)opGhost.Value; Destroy(constructing); NitroxEntity.SetNewId(ghost, amountChanged.Id); } else { Log.Error($"Could not find newly created ghost to set deconstructed id {amountChanged.Id}"); } } else { Constructable constructable = constructing.GetComponentInChildren <Constructable>(); constructable.constructedAmount = amountChanged.Amount; constructable.Construct(); } }
public override void Process(DeconstructionBegin packet) { Log.Info("Received deconstruction packet for basePieceId: " + packet.Id); GameObject deconstructing = NitroxEntity.RequireObjectFrom(packet.Id); BaseDeconstructable baseDeconstructable = deconstructing.RequireComponent <BaseDeconstructable>(); TransientLocalObjectManager.Add(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID, packet.Id); using (packetSender.Suppress <DeconstructionBegin>()) { baseDeconstructable.Deconstruct(); } }
private void ConstructionAmountChanged(ConstructionAmountChangedEvent amountChanged) { Log.Info("Processing ConstructionAmountChanged " + amountChanged.Guid + " " + amountChanged.Amount); GameObject constructing = GuidHelper.RequireObjectFrom(amountChanged.Guid); BaseDeconstructable baseDeconstructable = constructing.GetComponent <BaseDeconstructable>(); // Bases don't send a deconstruct being packet. Instead, we just make sure // that if we are changing the amount that we set it into deconstruction mode // if it still has a BaseDeconstructable object on it. if (baseDeconstructable != null) { baseDeconstructable.Deconstruct(); // After we have begun the deconstructing for a base piece, we need to transfer the guid Optional <object> opGhost = TransientLocalObjectManager.Get(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE); if (opGhost.IsPresent()) { GameObject ghost = (GameObject)opGhost.Get(); UnityEngine.Object.Destroy(constructing); GuidHelper.SetNewGuid(ghost, amountChanged.Guid); } else { Log.Info("Could not find newly created ghost to set deconstructed guid "); } } else { Constructable constructable = constructing.GetComponentInChildren <Constructable>(); constructable.constructedAmount = amountChanged.Amount; using (packetSender.Suppress <ConstructionAmountChanged>()) { constructable.Construct(); } } }
public override void Process(DeconstructionBegin packet) { Log.Info("Received deconstruction packet for id: " + packet.Id); GameObject deconstructing = NitroxEntity.RequireObjectFrom(packet.Id); Constructable constructable = deconstructing.GetComponent <Constructable>(); BaseDeconstructable baseDeconstructable = deconstructing.GetComponent <BaseDeconstructable>(); using (packetSender.Suppress <DeconstructionBegin>()) { if (baseDeconstructable != null) { TransientLocalObjectManager.Add(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID, packet.Id); baseDeconstructable.Deconstruct(); } else if (constructable != null) { constructable.SetState(false, false); } } }
private void HandleInput() { if (handleInputFrame == Time.frameCount) { return; } handleInputFrame = Time.frameCount; if (!AvatarInputHandler.main.IsEnabled()) { return; } bool flag = TryDisplayNoPowerTooltip(); if (flag) { return; } Targeting.AddToIgnoreList(Player.main.gameObject); Targeting.GetTarget(60f, out GameObject gameObject, out float num); if (gameObject == null) { return; } bool buttonHeld = GameInput.GetButtonHeld(GameInput.Button.LeftHand); bool buttonDown = GameInput.GetButtonDown(GameInput.Button.Deconstruct); bool buttonHeld2 = GameInput.GetButtonHeld(GameInput.Button.Deconstruct); bool quickbuild = GameInput.GetButtonHeld(GameInput.Button.Sprint); Constructable constructable = gameObject.GetComponentInParent <Constructable>(); if (constructable != null && num > constructable.placeMaxDistance * 2) { constructable = null; } if (constructable != null) { OnHover(constructable); if (buttonHeld) { Construct(constructable, true); if (quickbuild) { Construct(constructable, true); Construct(constructable, true); Construct(constructable, true); } } else if (constructable.DeconstructionAllowed(out string text)) { if (buttonHeld2) { if (constructable.constructed) { constructable.SetState(false, false); } else { Construct(constructable, false); if (quickbuild) { Construct(constructable, false); Construct(constructable, false); Construct(constructable, false); } } } } else if (buttonDown && !string.IsNullOrEmpty(text)) { ErrorMessage.AddMessage(text); } } else { BaseDeconstructable baseDeconstructable = gameObject.GetComponentInParent <BaseDeconstructable>(); if (baseDeconstructable == null) { BaseExplicitFace componentInParent = gameObject.GetComponentInParent <BaseExplicitFace>(); if (componentInParent != null) { baseDeconstructable = componentInParent.parent; } } else { if (baseDeconstructable.DeconstructionAllowed(out string text)) { OnHover(baseDeconstructable); if (buttonDown) { baseDeconstructable.Deconstruct(); } } else if (buttonDown && !string.IsNullOrEmpty(text)) { ErrorMessage.AddMessage(text); } } } }
//===================================================================== // HandleInput // // Called by Update. Checks for input events and operates the Builder // accordingly //===================================================================== private void HandleInput() { if (this.handleInputFrame == Time.frameCount) { return; } this.handleInputFrame = Time.frameCount; if (Builder.isPlacing || !AvatarInputHandler.main.IsEnabled()) { return; } Targeting.AddToIgnoreList(Player.main.gameObject); GameObject gameObject; float num; // Range increased to 40 to give the seamoth more room Targeting.GetTarget(hitRange, out gameObject, out num, null); if (gameObject == null) { return; } // Bring up the construct menu on alt tool use // (because the seamoth has lights bound to right hand) if (GameInput.GetButtonDown(GameInput.Button.AltTool)) { uGUI_BuilderMenu.Show(); return; } bool constructHeld = GameInput.GetButtonHeld(GameInput.Button.LeftHand); bool deconstructDown = GameInput.GetButtonDown(GameInput.Button.Deconstruct); bool deconstructHeld = GameInput.GetButtonHeld(GameInput.Button.Deconstruct); Constructable constructable = gameObject.GetComponentInParent <Constructable>(); if (constructable != null && num > constructable.placeMaxDistance) { constructable = null; } if (constructable != null) { this.OnHover(constructable); string text; if (constructHeld) { this.Construct(constructable, true); } else if (constructable.DeconstructionAllowed(out text)) { if (deconstructHeld) { if (constructable.constructed) { constructable.SetState(false, false); } else { this.Construct(constructable, false); } } } else if (deconstructDown && !string.IsNullOrEmpty(text)) { ErrorMessage.AddMessage(text); } } else { BaseDeconstructable baseDeconstructable = gameObject.GetComponentInParent <BaseDeconstructable>(); if (baseDeconstructable == null) { BaseExplicitFace componentInParent = gameObject.GetComponentInParent <BaseExplicitFace>(); if (componentInParent != null) { baseDeconstructable = componentInParent.parent; } } if (baseDeconstructable != null) { string text; if (baseDeconstructable.DeconstructionAllowed(out text)) { this.OnHover(baseDeconstructable); if (deconstructDown) { baseDeconstructable.Deconstruct(); } } else if (deconstructDown && !string.IsNullOrEmpty(text)) { ErrorMessage.AddMessage(text); } } } }