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 static void Prefix(BaseDeconstructable __instance) { NitroxId id = NitroxIdentifier.GetId(__instance.gameObject); Log.Info("Deconstructing " + id); TransientLocalObjectManager.Add(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID, id); }
static public void DeconstructBase(BaseDeconstructable target, Base targetBase, GameObject constructable, TechType tech) { lastConstructableObject = constructable; if (Multiplayer.main.blocked) { return; } if (buildConstructActive) { return; } var res = new ClientBuildDeconstructBase(); res.deconstructableGuid = GuidHelper.Get(target.gameObject); res.constructableGuid = GuidHelper.Get(GetNewConstructable()); res.baseGuid = GuidHelper.Get(targetBase?.gameObject); res.tech = tech; res.position = target.transform.position; res.faceType = target.faceType; res.boundsMin = target.bounds.mins; res.boundsMax = target.bounds.maxs; var face = target.face.GetValueOrDefault(); res.faceDirection = face.direction; res.faceCell = face.cell; Multiplayer.main.Send(res); }
private bool TryFindSecondLadderPiece(Base latestBase, Int3 cellToSearch, out Optional <GameObject> piece) { Transform cellTransform = latestBase.GetCellObject(cellToSearch); piece = Optional.Empty; if (!cellTransform) { return(false); } foreach (Transform child in cellTransform) { NitroxEntity id = child.GetComponent <NitroxEntity>(); BaseDeconstructable baseDeconstructable = child.GetComponent <BaseDeconstructable>(); bool isNewBasePiece = id == null && baseDeconstructable != null; if (isNewBasePiece) { TechType techType = baseDeconstructable.recipe; if (techType == TechType.BaseLadder) { piece = Optional.Of(child.gameObject); return(true); } } if (child.name.Contains("ConnectorLadder")) { return(true); } } return(false); }
public static void Postfix(ref BaseDeconstructable __instance) { if (__instance.recipe == TechType.BaseCorridor || __instance.recipe == TechType.BaseCorridorGlass) { switch (__instance.name) { case "BaseCorridorIShape(Clone)": __instance.recipe = TechType.BaseCorridorI; break; case "BaseCorridorIShapeGlass(Clone)": __instance.recipe = TechType.BaseCorridorGlassI; break; case "BaseCorridorLShape(Clone)": __instance.recipe = TechType.BaseCorridorL; break; case "BaseCorridorLShapeGlass(Clone)": __instance.recipe = TechType.BaseCorridorGlassL; break; case "BaseCorridorTShape(Clone)": __instance.recipe = TechType.BaseCorridorT; break; case "BaseCorridorXShape(Clone)": __instance.recipe = TechType.BaseCorridorX; break; } } }
public static void Prefix(BaseDeconstructable __instance) { string guid = GuidHelper.GetGuid(__instance.gameObject); Log.Info("Deconstructing " + guid); TransientLocalObjectManager.Add(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID, guid); }
private void OnHover(BaseDeconstructable deconstructable) { if (isActive) { HandReticle main = HandReticle.main; main.SetText(HandReticle.TextType.Hand, this.deconstructText, false); } }
private void OnHover(BaseDeconstructable deconstructable) { if (isActive) { HandReticle main = HandReticle.main; main.SetInteractText(deconstructable.Name, this.deconstructText); } }
public static void Prefix(BaseDeconstructable __instance) { NitroxId id = NitroxEntity.GetId(__instance.gameObject); Log.Info("Deconstructing " + id); NitroxServiceLocator.LocateService <Building>().DeconstructionBegin(id); TransientLocalObjectManager.Add(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID, id); }
[HarmonyPrefix] // We're attempting to replace the geometry building method public static bool Prefix(ref Base __instance, Int3 cell) { Int3 v = Base.CellSize[7]; Int3.Bounds bounds = new Int3.Bounds(cell, cell + v - 1); BaseDeconstructable parent = null; if (__instance.GetCellMask(cell)) { Transform transform = __instance.SpawnPiece(Base.Piece.Moonpool, cell); parent = BaseDeconstructable.MakeCellDeconstructable(transform, bounds, TechType.BaseMoonpool); transform.tag = "MainPieceGeometry"; } for (int i = 0; i < Base.moonpoolFaces.Length; i++) { Base.RoomFace roomFace = Base.moonpoolFaces[i]; Base.Face face = new Base.Face(cell + roomFace.offset, roomFace.direction); if (__instance.GetFaceMask(face)) { Base.FaceType face2 = __instance.GetFace(face); Base.Piece moonpoolPiece = __instance.GetMoonpoolPiece(face, face2); if (moonpoolPiece != Base.Piece.Invalid) { Transform transform2 = __instance.SpawnPiece(moonpoolPiece, cell, roomFace.rotation, null); transform2.localPosition = Int3.Scale(roomFace.offset, Base.cellSize) + roomFace.localOffset; if (face2 != Base.FaceType.Solid) { TechType recipe = Base.FaceToRecipe[(int)face2]; BaseDeconstructable baseDeconstructable = BaseDeconstructable.MakeFaceDeconstructable(transform2, bounds, face, face2, recipe); if (!__instance.isGhost) { transform2.GetComponentsInChildren <IBaseModuleGeometry>(true, Base.sBaseModulesGeometry); int j = 0; int count = Base.sBaseModulesGeometry.Count; while (j < count) { IBaseModuleGeometry baseModuleGeometry = Base.sBaseModulesGeometry[j]; baseModuleGeometry.geometryFace = face; j++; } Base.sBaseModulesGeometry.Clear(); if (face2 == Base.FaceType.UpgradeConsole) { baseDeconstructable.LinkModule(new Base.Face?(new Base.Face(face.cell - __instance.anchor, face.direction))); } } } else if (!__instance.isGhost) { BaseExplicitFace.MakeFaceDeconstructable(transform2, face, parent); } } } } return(false); }
public static void RunSpawnProcessor(BaseDeconstructable baseDeconstructable, Base latestBase, Int3 latestCell, GameObject finishedPiece) { TechType techType = baseDeconstructable.recipe; if (processorsByType.TryGetValue(techType, out BasePieceSpawnProcessor processor)) { Log.Info($"Found custom BasePieceSpawnProcessor for {techType}"); processor.SpawnPostProcess(latestBase, latestCell, finishedPiece); } }
private void OnHover(BaseDeconstructable deconstructable) { if (isActive) { HandReticle main = HandReticle.main; #if SN1 main.SetInteractText(deconstructable.Name, deconstructText); #elif BZ main.SetText(HandReticle.TextType.Hand, this.deconstructText, false); #endif } }
public static BasePieceSpawnProcessor From(BaseDeconstructable baseDeconstructable) { TechType techType = (TechType)baseDeconstructable.ReflectionGet("recipe"); if (processorsByType.TryGetValue(techType, out BasePieceSpawnProcessor processor)) { Log.Info("Found custom BasePieceSpawnProcessor for " + techType); return(processor); } return(noOpProcessor); }
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 string getObjectKey(GameObject gameObject) { BaseDeconstructable deconstructable = gameObject.GetComponentInChildren <BaseDeconstructable>(); Int3 faceCell = default(Int3); Base.Direction?faceDirection = null; if (deconstructable && deconstructable.face.HasValue) { Base.Face face = deconstructable.face.Value; faceCell = face.cell; faceDirection = face.direction; } return(getObjectKey(gameObject.name, gameObject.transform.position, faceCell, faceDirection)); }
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 Optional <GameObject> FindSecondLadderPiece(Base latestBase, Int3 cellToSearch) { Transform cellTransform = latestBase.GetCellObject(cellToSearch); foreach (Transform child in cellTransform) { NitroxEntity id = child.GetComponent <NitroxEntity>(); BaseDeconstructable baseDeconstructable = child.GetComponent <BaseDeconstructable>(); bool isNewBasePiece = id == null && baseDeconstructable != null; if (isNewBasePiece) { TechType techType = baseDeconstructable.recipe; if (techType == TechType.BaseLadder) { return(Optional.Of(child.gameObject)); } } } return(Optional.Empty); }
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); } } } }
public static void Postfix(BaseDeconstructable __instance) { TransientLocalObjectManager.Add(TransientObjectType.LATEST_CONSTRUCTED_BASE_PIECE, __instance.gameObject); }
public static void Prefix(BaseDeconstructable __instance) { NitroxId id = NitroxEntity.GetId(__instance.gameObject); Add(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID, id); }