public static bool Prefix(BaseGhost __instance) { var basebase1Color = __instance.GetAllComponentsInChildren <SkinnedMeshRenderer>(); var basebase2Color = __instance.GetAllComponentsInChildren <MeshRenderer>(); { foreach (var basebase01Color in basebase1Color) { if (basebase01Color.name.Contains("fabricator2_geo")) { basebase01Color.material.color = new Color32(Convert.ToByte(Config.fabricatorValue), Convert.ToByte(Config.fabricatorgValue), Convert.ToByte(Config.fabricatorbValue), 1); } foreach (var basebase3olor in basebase2Color) { if (basebase3olor.name.Contains("Moon_Pool_fabricator_01")) { basebase3olor.material.color = new Color32(Convert.ToByte(Config.fabricatorValue), Convert.ToByte(Config.fabricatorgValue), Convert.ToByte(Config.fabricatorbValue), 1); } } } } return(true); }
private static void UpdatePosition() { ConstructableBase componentInParent = ghostModel.GetComponentInParent <ConstructableBase>(); if (componentInParent != null) { Transform transform = componentInParent.transform; transform.position = PlacePosition; transform.rotation = PlaceRotation; bool flag; BaseGhost baseGhost = ghostModel.GetComponent <BaseGhost>(); bool flag2 = UpdatePlacement(baseGhost, GetAimTransform(), componentInParent.placeMaxDistance, out bool positionFound, out flag, componentInParent); componentInParent.SetGhostVisible(positionFound); if (flag2 && RotationMetadata.HasValue) { ApplyRotationMetadata(baseGhost, RotationMetadata.Value); } if (flag) { renderers = MaterialExtensions.AssignMaterial(ghostModel, ghostStructureMaterial); InitBounds(ghostModel); } } Transform ghostModelTransform = ghostModel.transform; ghostModelTransform.position = PlacePosition + PlaceRotation * ghostModelPosition; ghostModelTransform.rotation = PlaceRotation * ghostModelRotation; ghostModelTransform.localScale = ghostModelScale; }
// Token: 0x06002B9B RID: 11163 RVA: 0x00103EBC File Offset: 0x001020BC private static bool CreateGhost() { if (MultiplayerBuilder.ghostModel != null) { return(false); } Constructable component = MultiplayerBuilder.prefab.GetComponent <Constructable>(); MultiplayerBuilder.constructableTechType = component.techType; MultiplayerBuilder.placeMinDistance = component.placeMinDistance; MultiplayerBuilder.placeMaxDistance = component.placeMaxDistance; MultiplayerBuilder.placeDefaultDistance = component.placeDefaultDistance; MultiplayerBuilder.allowedSurfaceTypes = component.allowedSurfaceTypes; MultiplayerBuilder.forceUpright = component.forceUpright; MultiplayerBuilder.allowedInSub = component.allowedInSub; MultiplayerBuilder.allowedInBase = component.allowedInBase; MultiplayerBuilder.allowedOutside = component.allowedOutside; MultiplayerBuilder.allowedOnConstructables = component.allowedOnConstructables; MultiplayerBuilder.rotationEnabled = component.rotationEnabled; ConstructableBase component2 = MultiplayerBuilder.prefab.GetComponent <ConstructableBase>(); if (component2 != null) { GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(MultiplayerBuilder.prefab); component2 = gameObject.GetComponent <ConstructableBase>(); MultiplayerBuilder.ghostModel = component2.model; BaseGhost component3 = MultiplayerBuilder.ghostModel.GetComponent <BaseGhost>(); component3.SetupGhost(); MultiplayerBuilder.ghostModelPosition = Vector3.zero; MultiplayerBuilder.ghostModelRotation = Quaternion.identity; MultiplayerBuilder.ghostModelScale = Vector3.one; MultiplayerBuilder.renderers = MaterialExtensions.AssignMaterial(MultiplayerBuilder.ghostModel, MultiplayerBuilder.ghostStructureMaterial); MultiplayerBuilder.InitBounds(MultiplayerBuilder.ghostModel); } else { MultiplayerBuilder.ghostModel = UnityEngine.Object.Instantiate <GameObject>(component.model); MultiplayerBuilder.ghostModel.SetActive(true); Transform component4 = component.GetComponent <Transform>(); Transform component5 = component.model.GetComponent <Transform>(); Quaternion quaternion = Quaternion.Inverse(component4.rotation); MultiplayerBuilder.ghostModelPosition = quaternion * (component5.position - component4.position); MultiplayerBuilder.ghostModelRotation = quaternion * component5.rotation; MultiplayerBuilder.ghostModelScale = component5.lossyScale; Collider[] componentsInChildren = MultiplayerBuilder.ghostModel.GetComponentsInChildren <Collider>(); for (int i = 0; i < componentsInChildren.Length; i++) { UnityEngine.Object.Destroy(componentsInChildren[i]); } MultiplayerBuilder.renderers = MaterialExtensions.AssignMaterial(MultiplayerBuilder.ghostModel, MultiplayerBuilder.ghostStructureMaterial); MultiplayerBuilder.SetupRenderers(MultiplayerBuilder.ghostModel, Player.main.IsInSub()); MultiplayerBuilder.CreatePowerPreview(MultiplayerBuilder.constructableTechType, MultiplayerBuilder.ghostModel); MultiplayerBuilder.InitBounds(MultiplayerBuilder.prefab); } return(true); }
public static GameObject CacheObject(GameObject builtObject, BaseGhost baseGhost) { var constructableBase = baseGhost.GetComponentInParent <ConstructableBase>(); var parent = constructableBase != null ? constructableBase.transform.parent : null; parentObject = parent != null ? parent.gameObject : null; gameObject = builtObject; return(builtObject); }
private void EatenEffectPauseEnd() { _eatenGhost.EnableSpriteRenderer(); _eatenGhost = null; _ghostScoreText.gameObject.SetActive(false); ResumeUnits(); }
public static void Postfix(BaseGhost __instance) { if (gameObject != null && parentObject != null) { gameObject.transform.SetParent(parentObject.transform); } gameObject = null; parentObject = null; }
private static void ApplyRotationMetadata(GameObject ghostModel, RotationMetadata rotationMetadata) { BaseGhost component = ghostModel.GetComponent <BaseGhost>(); if (component == null) { Log.Error("Was unable to apply rotation metadata - no BaseGhost found"); } else if (component.GetType() != rotationMetadata.GhostType) { Log.Error("Was unable to apply rotation metadata - " + component.GetType() + " did not match " + rotationMetadata.GhostType); } else if (component is BaseAddCorridorGhost corridor) { Log.Info("Placing BaseAddCorridorGhost Rotation Metadata"); CorridorRotationMetadata corridorRotationMetadata = (CorridorRotationMetadata)rotationMetadata; corridor.rotation = corridorRotationMetadata.Rotation; int corridorType = corridor.CalculateCorridorType(); corridor.ghostBase.SetCorridor(Int3.zero, corridorType, corridor.isGlass); corridor.RebuildGhostGeometry(); } else if (component is BaseAddMapRoomGhost mapRoom) { Log.Info("Placing MapRoomRotationMetadata Rotation Metadata"); MapRoomRotationMetadata mapRoomRotationMetadata = (MapRoomRotationMetadata)rotationMetadata; mapRoom.cellType = (Base.CellType)mapRoomRotationMetadata.CellType; mapRoom.connectionMask = mapRoomRotationMetadata.ConnectionMask; mapRoom.ghostBase.SetCell(Int3.zero, (Base.CellType)mapRoomRotationMetadata.CellType); mapRoom.RebuildGhostGeometry(); } else if (component is BaseAddModuleGhost ghost) { BaseModuleRotationMetadata baseModuleRotationMetadata = (BaseModuleRotationMetadata)rotationMetadata; ghost.anchoredFace = new Base.Face(baseModuleRotationMetadata.Cell.ToUnity(), (Base.Direction)baseModuleRotationMetadata.Direction); ghost.RebuildGhostGeometry(); } else if (component is BaseAddFaceGhost faceGhost) { AnchoredFaceRotationMetadata baseModuleRotationMetadata = (AnchoredFaceRotationMetadata)rotationMetadata; Log.Info("Applying BaseAddFaceGhost " + baseModuleRotationMetadata); Base.Face face = new(baseModuleRotationMetadata.Cell.ToUnity(), (Base.Direction)baseModuleRotationMetadata.Direction); faceGhost.anchoredFace = face; Base.FaceType faceType = (Base.FaceType)baseModuleRotationMetadata.FaceType; faceGhost.ghostBase.SetFace(face, faceType); faceGhost.RebuildGhostGeometry(); } }
private static bool UpdatePlacement(BaseGhost baseGhost, Transform camera, float placeMaxDistance, out bool positionFound, out bool flag, ConstructableBase componentInParent) { bool flag2; switch (baseGhost) { default: flag2 = baseGhost.UpdatePlacement(camera, placeMaxDistance, out positionFound, out flag, componentInParent); break; } return(flag2); }
private static void ApplyRotationMetadata(GameObject ghostModel, RotationMetadata rotationMetadata) { BaseGhost component = ghostModel.GetComponent <BaseGhost>(); if (component == null) { Log.Error("Was unable to apply rotation metadata - no BaseGhost found"); } else if (component.GetType() != rotationMetadata.GhostType) { Log.Error("Was unable to apply rotation metadata - " + component.GetType() + " did not match " + rotationMetadata.GhostType); } else if (component is BaseAddCorridorGhost) { Log.Info("Placing BaseAddCorridorGhost Rotation Metadata"); CorridorRotationMetadata corridorRotationMetadata = (rotationMetadata as CorridorRotationMetadata); BaseAddCorridorGhost corridor = (component as BaseAddCorridorGhost); corridor.ReflectionSet("rotation", corridorRotationMetadata.Rotation); int corridorType = (int)corridor.ReflectionCall("CalculateCorridorType"); Base ghostBase = (Base)corridor.ReflectionGet("ghostBase"); ghostBase.SetCorridor(Int3.zero, corridorType, corridor.isGlass); corridor.ReflectionCall("RebuildGhostGeometry"); } else if (component is BaseAddMapRoomGhost) { Log.Info("Placing MapRoomRotationMetadata Rotation Metadata"); MapRoomRotationMetadata mapRoomRotationMetadata = (rotationMetadata as MapRoomRotationMetadata); BaseAddMapRoomGhost mapRoom = (component as BaseAddMapRoomGhost); mapRoom.ReflectionSet("cellType", mapRoomRotationMetadata.CellType); mapRoom.ReflectionSet("connectionMask", mapRoomRotationMetadata.ConnectionMask); Base ghostBase = (Base)mapRoom.ReflectionGet("ghostBase"); ghostBase.SetCell(Int3.zero, (Base.CellType)mapRoomRotationMetadata.CellType); mapRoom.ReflectionCall("RebuildGhostGeometry"); } else if (component is BaseAddModuleGhost) { BaseModuleRotationMetadata baseModuleRotationMetadata = (rotationMetadata as BaseModuleRotationMetadata); BaseAddModuleGhost module = (component as BaseAddModuleGhost); module.anchoredFace = new Base.Face(baseModuleRotationMetadata.Cell.Global(), (Base.Direction)baseModuleRotationMetadata.Direction); module.ReflectionCall("RebuildGhostGeometry"); } }
private static void ApplyRotationMetadata(BaseGhost baseGhost, BuilderMetadata builderMetadata) { switch (baseGhost) { case BaseAddCorridorGhost corridor when builderMetadata is CorridorBuilderMetadata corridorRotationMetadata: { corridor.rotation = corridorRotationMetadata.Rotation; int corridorType = corridor.CalculateCorridorType(); corridor.ghostBase.SetCorridor(Int3.zero, corridorType, corridor.isGlass); corridor.RebuildGhostGeometry(); break; } case BaseAddMapRoomGhost mapRoom when builderMetadata is MapRoomBuilderMetadata mapRoomRotationMetadata: { mapRoom.cellType = (Base.CellType)mapRoomRotationMetadata.CellType; mapRoom.connectionMask = mapRoomRotationMetadata.ConnectionMask; mapRoom.ghostBase.SetCell(Int3.zero, (Base.CellType)mapRoomRotationMetadata.CellType); mapRoom.RebuildGhostGeometry(); break; } case BaseAddModuleGhost ghost when builderMetadata is BaseModuleBuilderMetadata baseModuleRotationMetadata: { ghost.anchoredFace = new Base.Face(baseModuleRotationMetadata.Cell.ToUnity(), (Base.Direction)baseModuleRotationMetadata.Direction); ghost.RebuildGhostGeometry(); break; } case BaseAddFaceGhost faceGhost when builderMetadata is AnchoredFaceBuilderMetadata baseModuleRotationMetadata: { Base.Face face = new(baseModuleRotationMetadata.Cell.ToUnity(), (Base.Direction)baseModuleRotationMetadata.Direction); faceGhost.anchoredFace = face; Base.FaceType faceType = (Base.FaceType)baseModuleRotationMetadata.FaceType; faceGhost.ghostBase.SetFace(face, faceType); faceGhost.RebuildGhostGeometry(); break; } default: Log.Error($"Was unable to apply rotation metadata for {baseGhost.GetType()} and {builderMetadata}"); break; } }
public void ReceiveGhostIsEaten(BaseGhost ghost) { PauseUnits(); _eatenGhost = ghost; _eatenGhost.DisableSpriteRenderer(); _ghostAteChainCount++; int chainScore = 200 * _ghostAteChainCount; PlusScore(chainScore); _ghostScoreText.text = chainScore.ToString(); _ghostScoreText.gameObject.SetActive(true); _ghostScoreText.transform.position = Camera.main.WorldToScreenPoint(ghost.SpritePos); Invoke(nameof(EatenEffectPauseEnd), 1.0f); }
public void PlaceBasePiece(BaseGhost baseGhost, ConstructableBase constructableBase, Base targetBase, TechType techType, Quaternion quaternion) { if (!Builder.isPlacing) //prevent possible echoing { return; } NitroxId id = NitroxEntity.GetId(constructableBase.gameObject); NitroxId parentBaseId = (targetBase == null) ? null : NitroxEntity.GetId(targetBase.gameObject); Vector3 placedPosition = constructableBase.gameObject.transform.position; Transform camera = Camera.main.transform; Optional <RotationMetadata> rotationMetadata = rotationMetadataFactory.From(baseGhost); BasePiece basePiece = new BasePiece(id, placedPosition, quaternion, camera.position, camera.rotation, techType.Model(), Optional <NitroxId> .OfNullable(parentBaseId), false, rotationMetadata); PlaceBasePiece placedBasePiece = new PlaceBasePiece(basePiece); packetSender.Send(placedBasePiece); }
public void PlaceBasePiece(BaseGhost baseGhost, ConstructableBase constructableBase, Base targetBase, TechType techType, Quaternion quaternion) { if (!Builder.isPlacing) //prevent possible echoing { return; } string guid = GuidHelper.GetGuid(constructableBase.gameObject); string parentBaseGuid = (targetBase == null) ? null : GuidHelper.GetGuid(targetBase.gameObject); Vector3 placedPosition = constructableBase.gameObject.transform.position; Transform camera = Camera.main.transform; Optional <RotationMetadata> rotationMetadata = RotationMetadata.From(baseGhost); BasePiece basePiece = new BasePiece(guid, placedPosition, quaternion, camera.position, camera.rotation, techType, Optional <string> .OfNullable(parentBaseGuid), false, rotationMetadata); PlaceBasePiece placedBasePiece = new PlaceBasePiece(basePiece); packetSender.Send(placedBasePiece); }
private static void CreateGhost() { Constructable component = prefab.GetComponent <Constructable>(); constructableTechType = component.techType; allowedOutside = component.allowedOutside; ConstructableBase component2 = prefab.GetComponent <ConstructableBase>(); if (component2 != null) { GameObject gameObject = Object.Instantiate <GameObject>(prefab); component2 = gameObject.GetComponent <ConstructableBase>(); ghostModel = component2.model; BaseGhost component3 = ghostModel.GetComponent <BaseGhost>(); component3.SetupGhost(); ghostModelPosition = Vector3.zero; ghostModelRotation = Quaternion.identity; ghostModelScale = Vector3.one; renderers = MaterialExtensions.AssignMaterial(ghostModel, ghostStructureMaterial); InitBounds(ghostModel); } else { ghostModel = Object.Instantiate <GameObject>(component.model); ghostModel.SetActive(true); Transform component4 = component.GetComponent <Transform>(); Transform component5 = component.model.GetComponent <Transform>(); Quaternion quaternion = Quaternion.Inverse(component4.rotation); ghostModelPosition = quaternion * (component5.position - component4.position); ghostModelRotation = quaternion * component5.rotation; ghostModelScale = component5.lossyScale; Collider[] componentsInChildren = ghostModel.GetComponentsInChildren <Collider>(); foreach (Collider collider in componentsInChildren) { Object.Destroy(collider); } renderers = MaterialExtensions.AssignMaterial(ghostModel, ghostStructureMaterial); SetupRenderers(ghostModel, Player.main.IsInSub()); CreatePowerPreview(); InitBounds(prefab); } }
public void PlaceBasePiece(BaseGhost baseGhost, ConstructableBase constructableBase, Base targetBase, TechType techType, Quaternion quaternion) { if (!Builder.isPlacing) //prevent possible echoing { return; } NitroxId id = NitroxEntity.GetId(constructableBase.gameObject); NitroxId parentBaseId = null; if (targetBase != null) { parentBaseId = NitroxEntity.GetId(targetBase.gameObject); } else if (constructableBase != null) { Base playerBase = constructableBase.gameObject.GetComponentInParent <Base>(); if (playerBase != null) { parentBaseId = NitroxEntity.GetId(playerBase.gameObject); } } if (parentBaseId == null) { Base playerBase = baseGhost.gameObject.GetComponentInParent <Base>(); if (playerBase != null) { parentBaseId = NitroxEntity.GetId(playerBase.gameObject); } } Vector3 placedPosition = constructableBase.gameObject.transform.position; Transform camera = Camera.main.transform; Optional <RotationMetadata> rotationMetadata = rotationMetadataFactory.From(baseGhost); BasePiece basePiece = new BasePiece(id, placedPosition.ToDto(), quaternion.ToDto(), camera.position.ToDto(), camera.rotation.ToDto(), techType.ToDto(), Optional.OfNullable(parentBaseId), false, rotationMetadata); PlaceBasePiece placedBasePiece = new PlaceBasePiece(basePiece); packetSender.Send(placedBasePiece); }
public static ConstructableBase TryPlaceBase(GameObject targetBaseGameObject) { #pragma warning disable CS0618 //Disabling warning as we dont have the FModAsset to use instead. Utils.PlayEnvSound(PLACE_SOUND, ghostModel.transform.position); #pragma warning restore CS0618 ConstructableBase componentInParent = ghostModel.GetComponentInParent <ConstructableBase>(); BaseGhost component = ghostModel.GetComponent <BaseGhost>(); component.GhostBase.transform.position = OverridePosition; component.Place(); componentInParent.transform.position = OverridePosition; Transform transform = component.transform; transform.position = OverridePosition; transform.rotation = OverrideQuaternion; if (targetBaseGameObject) { Base targetBase = targetBaseGameObject.GetComponent <Base>(); if (targetBase != null) { component.targetBase = targetBase; componentInParent.transform.SetParent(targetBase.transform, true); } else { Log.Error("Could not find base component on the given game object: " + targetBaseGameObject.name); } } componentInParent.SetState(false); component.GhostBase.transform.position = OverridePosition; ghostModel = null; prefab = null; RotationMetadata = Optional.Empty; return(componentInParent); }
public static void Prefix(BaseGhost __instance) { // Null out fields that will be used for storing state TransientLocalObjectManager.Remove(TransientObjectType.LATEST_BASE_WITH_NEW_CONSTRUCTION); TransientLocalObjectManager.Remove(TransientObjectType.LATEST_BASE_CELL_WITH_NEW_CONSTRUCTION); // In this case, our piece is part of an existing, larger base. We'll record the base and offset. // We don't directly record the piece as it will be re-built when the base rebuilds geometry (this // happens each time a piece is built, subnautica destroys all others and replaces them). if (__instance.TargetBase != null) { Log.Debug("Placed BaseGhost is a new piece of an existing base"); TransientLocalObjectManager.Add(TransientObjectType.LATEST_BASE_WITH_NEW_CONSTRUCTION, __instance.TargetBase); TransientLocalObjectManager.Add(TransientObjectType.LATEST_BASE_CELL_WITH_NEW_CONSTRUCTION, __instance.TargetOffset); } else { Log.Debug("Placed BaseGhost is the first piece of a new base."); } }
public static Optional <RotationMetadata> From(BaseGhost baseGhost) { RotationMetadata rotationMetadata = null; if (baseGhost is BaseAddCorridorGhost) { BaseAddCorridorGhost corridorGhost = baseGhost as BaseAddCorridorGhost; int rotation = (int)corridorGhost.ReflectionGet("rotation"); rotationMetadata = new CorridorRotationMetadata(rotation); } else if (baseGhost is BaseAddMapRoomGhost) { BaseAddMapRoomGhost mapRoomGhost = baseGhost as BaseAddMapRoomGhost; Base.CellType cellType = (Base.CellType)mapRoomGhost.ReflectionGet("cellType"); int connectionMask = (int)mapRoomGhost.ReflectionGet("connectionMask"); rotationMetadata = new MapRoomRotationMetadata(cellType, connectionMask); } return(Optional <RotationMetadata> .OfNullable(rotationMetadata)); }
public static ConstructableBase TryPlaceBase(Optional <GameObject> opTargetBaseGameObject) { MultiplayerBuilder.Initialize(); global::Utils.PlayEnvSound(MultiplayerBuilder.placeSound, MultiplayerBuilder.ghostModel.transform.position, 10f); ConstructableBase componentInParent = MultiplayerBuilder.ghostModel.GetComponentInParent <ConstructableBase>(); BaseGhost component = MultiplayerBuilder.ghostModel.GetComponent <BaseGhost>(); component.GhostBase.transform.position = overridePosition; component.Place(); componentInParent.transform.position = overridePosition; component.transform.position = overridePosition; component.transform.rotation = overrideQuaternion; if (opTargetBaseGameObject.IsPresent()) { GameObject targetBaseGameObject = opTargetBaseGameObject.Get(); Base targetBase = targetBaseGameObject.GetComponent <Base>(); if (targetBase != null) { component.ReflectionSet("targetBase", targetBase); componentInParent.transform.SetParent(targetBase.transform, true); } else { Console.WriteLine("Could not find base component on the given game object"); } } componentInParent.SetState(false, true); component.GhostBase.transform.position = overridePosition; MultiplayerBuilder.ghostModel = null; MultiplayerBuilder.prefab = null; MultiplayerBuilder.canPlace = false; return(componentInParent); }
public static ConstructableBase TryPlaceBase(GameObject targetBaseGameObject) { MultiplayerBuilder.Initialize(); global::Utils.PlayEnvSound(MultiplayerBuilder.placeSound, MultiplayerBuilder.ghostModel.transform.position, 10f); ConstructableBase componentInParent = MultiplayerBuilder.ghostModel.GetComponentInParent <ConstructableBase>(); BaseGhost component = MultiplayerBuilder.ghostModel.GetComponent <BaseGhost>(); component.GhostBase.transform.position = overridePosition; component.Place(); componentInParent.transform.position = overridePosition; component.transform.position = overridePosition; component.transform.rotation = overrideQuaternion; if (targetBaseGameObject) { Base targetBase = targetBaseGameObject.GetComponent <Base>(); if (targetBase != null) { component.targetBase = targetBase; componentInParent.transform.SetParent(targetBase.transform, true); } else { Log.Error("Could not find base component on the given game object: " + targetBaseGameObject.name); } } componentInParent.SetState(false, true); component.GhostBase.transform.position = overridePosition; MultiplayerBuilder.ghostModel = null; MultiplayerBuilder.prefab = null; MultiplayerBuilder.canPlace = false; return(componentInParent); }
public static bool Prefix(Constructable __instance) { if (__instance.constructed) { return(true); } // If we are constructing a base piece then we'll want to store all of the BaseGhost information // as it will not be available when the construction hits 100% if (__instance is ConstructableBase constructableBase) { BaseGhost baseGhost = constructableBase.gameObject.GetComponentInChildren <BaseGhost>(); if (baseGhost != null) { lastTargetBase = baseGhost.TargetBase; lastTargetBaseOffset = baseGhost.TargetOffset; } lastFace = baseGhost switch { BaseAddFaceGhost { anchoredFace : { } } baseAddFaceGhost => baseAddFaceGhost.anchoredFace.Value, BaseAddModuleGhost { anchoredFace : { } } baseAddModuleGhost => baseAddModuleGhost.anchoredFace.Value, _ => lastFace }; } else { lastTargetBase = null; lastTargetBaseOffset = default(Int3); } return(true); }
public static bool Prefix(Constructable __instance) { if (!__instance._constructed && __instance.constructedAmount < 1.0f) { NitroxServiceLocator.LocateService <Building>().ChangeConstructionAmount(__instance.gameObject, __instance.constructedAmount); } // If we are constructing a base piece then we'll want to store all of the BaseGhost information // as it will not be available when the construction hits 100% BaseGhost baseGhost = __instance.gameObject.GetComponentInChildren <BaseGhost>(); if (baseGhost != null && baseGhost.TargetBase) { lastTargetBase = baseGhost.TargetBase.GetComponent <Base>(); lastTargetBaseOffset = baseGhost.TargetOffset; } else { lastTargetBase = null; lastTargetBaseOffset = default(Int3); } return(true); }
public static GameObject CacheObject(GameObject builtObject, BaseGhost baseGhost) { parentObject = baseGhost.GetComponentInParent <ConstructableBase>()?.transform?.parent?.gameObject; gameObject = builtObject; return(builtObject); }
// Token: 0x06002B9D RID: 11165 public static bool TryPlace() { MultiplayerBuilder.Initialize(); if (MultiplayerBuilder.prefab == null || !MultiplayerBuilder.canPlace) { return(false); } global::Utils.PlayEnvSound(MultiplayerBuilder.placeSound, MultiplayerBuilder.ghostModel.transform.position, 10f); ConstructableBase componentInParent = MultiplayerBuilder.ghostModel.GetComponentInParent <ConstructableBase>(); if (componentInParent != null) { BaseGhost component = MultiplayerBuilder.ghostModel.GetComponent <BaseGhost>(); component.GhostBase.transform.position = overridePosition; component.Place(); componentInParent.transform.position = overridePosition; component.transform.position = overridePosition; component.transform.rotation = overrideQuaternion; if (component.TargetBase != null) { componentInParent.transform.SetParent(component.TargetBase.transform, true); } componentInParent.SetState(false, true); component.GhostBase.transform.position = overridePosition; if (component.TargetBase != null) { component.TargetBase.transform.position = overridePosition; } } else { GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(MultiplayerBuilder.prefab); bool flag = false; bool flag2 = false; SubRoot currentSub = Player.main.GetCurrentSub(); if (currentSub != null) { flag = currentSub.isBase; flag2 = currentSub.isCyclops; gameObject.transform.parent = currentSub.GetModulesRoot(); } else if (MultiplayerBuilder.placementTarget != null && MultiplayerBuilder.allowedOutside) { SubRoot componentInParent2 = MultiplayerBuilder.placementTarget.GetComponentInParent <SubRoot>(); if (componentInParent2 != null) { gameObject.transform.parent = componentInParent2.GetModulesRoot(); } } Transform expr_138 = gameObject.transform; expr_138.position = MultiplayerBuilder.placePosition; expr_138.rotation = MultiplayerBuilder.placeRotation; Constructable componentInParent3 = gameObject.GetComponentInParent <Constructable>(); componentInParent3.SetState(false, true); global::Utils.SetLayerRecursively(gameObject, LayerMask.NameToLayer((!flag) ? "Interior" : "Default"), true, -1); componentInParent3.SetIsInside(flag | flag2); SkyEnvironmentChanged.Send(gameObject, currentSub); gameObject.transform.position = overridePosition; gameObject.transform.rotation = overrideQuaternion; } MultiplayerBuilder.ghostModel = null; MultiplayerBuilder.prefab = null; MultiplayerBuilder.canPlace = false; return(true); }
// Token: 0x060030FF RID: 12543 RVA: 0x0012D7E8 File Offset: 0x0012B9E8 public static bool TryPlace(out GameObject outObject, out Constructable outConstructable) { outObject = null; outConstructable = null; MultiplayerBuilder.Initialize(); if (MultiplayerBuilder.prefab == null) { return(false); } Utils.PlayEnvSound(MultiplayerBuilder.placeSound, MultiplayerBuilder.ghostModel.transform.position, 10f); ConstructableBase componentInParent = MultiplayerBuilder.ghostModel.GetComponentInParent <ConstructableBase>(); if (componentInParent != null) { MultiplayerBuilder.Update(); BaseGhost component = MultiplayerBuilder.ghostModel.GetComponent <BaseGhost>(); component.Place(); if (component.TargetBase != null) { componentInParent.transform.SetParent(component.TargetBase.transform, true); } componentInParent.SetState(false, true); componentInParent.transform.position = overridePosition; componentInParent.transform.rotation = overrideRotation; outObject = componentInParent.gameObject; outConstructable = componentInParent; } else { MultiplayerBuilder.placementTarget = GuidHelper.Find(targetGuid); GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(MultiplayerBuilder.prefab); bool flag = false; bool flag2 = false; SubRoot currentSub = Player.main.GetCurrentSub(); if (currentSub != null) { flag = currentSub.isBase; flag2 = currentSub.isCyclops; gameObject.transform.parent = currentSub.GetModulesRoot(); } else if (MultiplayerBuilder.placementTarget != null && MultiplayerBuilder.allowedOutside) { SubRoot componentInParent2 = MultiplayerBuilder.placementTarget.GetComponentInParent <SubRoot>(); if (componentInParent2 != null) { gameObject.transform.parent = componentInParent2.GetModulesRoot(); } } Transform transform = gameObject.transform; transform.localPosition = overridePosition; transform.localRotation = overrideRotation; Constructable componentInParent3 = gameObject.GetComponentInParent <Constructable>(); componentInParent3.SetState(false, true); Utils.SetLayerRecursively(gameObject, LayerMask.NameToLayer((!flag) ? "Interior" : "Default"), true, -1); if (MultiplayerBuilder.ghostModel != null) { UnityEngine.Object.Destroy(MultiplayerBuilder.ghostModel); } componentInParent3.SetIsInside(flag || flag2); SkyEnvironmentChanged.Send(gameObject, currentSub); transform.localPosition = overridePosition; transform.localRotation = overrideRotation; outObject = gameObject; outConstructable = componentInParent3; } MultiplayerBuilder.ghostModel = null; MultiplayerBuilder.prefab = null; MultiplayerBuilder.canPlace = false; return(true); }
private void ConstructionCompleted(ConstructionCompletedEvent constructionCompleted) { GameObject constructing = NitroxEntity.RequireObjectFrom(constructionCompleted.PieceId); // For bases, we need to transfer the GUID off of the ghost and onto the finished piece. // Furniture just re-uses the same piece. if (constructing.TryGetComponent(out ConstructableBase constructableBase)) { Int3 latestCell = default; Base latestBase = null; // must fetch BEFORE setState as the BaseGhost gets destroyed BaseGhost baseGhost = constructableBase.model.AliveOrNull()?.GetComponent <BaseGhost>(); if (baseGhost && baseGhost.TargetBase) { latestBase = baseGhost.TargetBase; latestCell = latestBase.WorldToGrid(baseGhost.transform.position); } constructableBase.constructedAmount = 1f; constructableBase.SetState(true); Transform cellTransform; GameObject placedPiece = null; if (!latestBase) { Optional <object> opConstructedBase = Get(TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT); if (opConstructedBase.HasValue) { latestBase = ((GameObject)opConstructedBase.Value).GetComponent <Base>(); } Validate.NotNull(latestBase, "latestBase can not be null"); latestCell = latestBase !.WorldToGrid(constructing.transform.position); } if (latestCell != default(Int3)) { cellTransform = latestBase.GetCellObject(latestCell); if (cellTransform) { placedPiece = FindFinishedPiece(cellTransform); } } if (!placedPiece) { Int3 position = latestBase.WorldToGrid(constructableBase.transform.position); cellTransform = latestBase.GetCellObject(position); Validate.NotNull(cellTransform, "Unable to find cell transform at " + position); placedPiece = FindFinishedPiece(cellTransform); } Validate.NotNull(placedPiece, $"Could not find placed Piece in cell {latestCell} when constructing {constructionCompleted.PieceId}"); // This destroy instruction must be executed now, else it won't be able to happen in the case the action will have a later completion Destroy(constructableBase.gameObject); if (BuildingInitialSyncProcessor.LaterConstructionTechTypes.Contains(constructableBase.techType)) { // We need to transfer these 3 objects to the later completed event Add(TransientObjectType.LATER_CONSTRUCTED_BASE, placedPiece); Add(TransientObjectType.LATER_OBJECT_LATEST_BASE, latestBase); Add(TransientObjectType.LATER_OBJECT_LATEST_CELL, latestCell); return; } FinishConstructionCompleted(placedPiece, latestBase, latestCell, constructionCompleted.PieceId); } else if (constructing.TryGetComponent(out Constructable constructable)) { constructable.constructedAmount = 1f; constructable.SetState(true); FurnitureSpawnProcessor.RunSpawnProcessor(constructable); } else { Log.Error($"Found ghost which is neither base piece nor a constructable: {constructing.name}"); } if (constructionCompleted.BaseId != null && !NitroxEntity.GetObjectFrom(constructionCompleted.BaseId).HasValue) { ConfigureNewlyConstructedBase(constructionCompleted.BaseId); } }
private void ConstructionCompleted(ConstructionCompletedEvent constructionCompleted) { GameObject constructing = NitroxEntity.RequireObjectFrom(constructionCompleted.PieceId); ConstructableBase constructableBase = constructing.GetComponent <ConstructableBase>(); // For bases, we need to transfer the GUID off of the ghost and onto the finished piece. // Furniture just re-uses the same piece. if (constructableBase) { Int3 latestCell = default(Int3); Base latestBase = null; // must fetch BEFORE setState or else the BaseGhost gets destroyed BaseGhost baseGhost = constructing.GetComponentInChildren <BaseGhost>(); if (baseGhost) { latestCell = baseGhost.TargetOffset; latestBase = baseGhost.TargetBase; } constructableBase.constructedAmount = 1f; constructableBase.SetState(true, true); if (latestBase == null) { Optional <object> opConstructedBase = TransientLocalObjectManager.Get(TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT); latestBase = ((GameObject)opConstructedBase.Value).GetComponent <Base>(); Validate.NotNull(latestBase, "latestBase can not be null"); } Transform cellTransform = latestBase.GetCellObject(latestCell); if (latestCell == default(Int3) || cellTransform == null) { Vector3 worldPosition; float distance; latestBase.GetClosestCell(constructing.gameObject.transform.position, out latestCell, out worldPosition, out distance); cellTransform = latestBase.GetCellObject(latestCell); Validate.NotNull(cellTransform, "Must have a cell transform, one not found near " + constructing.gameObject.transform.position + " for latestcell " + latestCell); } GameObject finishedPiece = null; // There can be multiple objects in a cell (such as a corridor with hatces built into it) // we look for a object that is able to be deconstucted that hasn't been tagged yet. foreach (Transform child in cellTransform) { bool isNewBasePiece = (child.GetComponent <NitroxEntity>() == null && child.GetComponent <BaseDeconstructable>() != null); if (isNewBasePiece) { finishedPiece = child.gameObject; break; } } Validate.NotNull(finishedPiece, "Could not find finished piece in cell " + latestCell + " when constructing " + constructionCompleted.PieceId + " " + finishedPiece.name); Log.Info("Construction completed on a base piece: " + constructionCompleted.PieceId + " " + finishedPiece.name); UnityEngine.Object.Destroy(constructableBase.gameObject); NitroxEntity.SetNewId(finishedPiece, constructionCompleted.PieceId); BasePieceSpawnProcessor customSpawnProcessor = BasePieceSpawnProcessor.From(finishedPiece.GetComponent <BaseDeconstructable>()); customSpawnProcessor.SpawnPostProcess(latestBase, latestCell, finishedPiece); } else { Constructable constructable = constructing.GetComponent <Constructable>(); constructable.constructedAmount = 1f; constructable.SetState(true, true); Log.Info("Construction completed on a piece of furniture: " + constructionCompleted.PieceId + " " + constructable.gameObject.name); } if (constructionCompleted.BaseId != null && !NitroxEntity.GetObjectFrom(constructionCompleted.BaseId).HasValue) { Log.Info("Creating base: " + constructionCompleted.BaseId); ConfigureNewlyConstructedBase(constructionCompleted.BaseId); } }
static public void Place(GameObject gameObject, GameObject target, BaseGhost baseGhost, TechType tech, bool furniture) { if (Multiplayer.main.blocked) { return; } var res = new ClientBuildConstruct(); res.tech = tech; res.furniture = furniture; res.objectGuid = GuidHelper.Get(gameObject); res.targetGuid = GuidHelper.Get(target); res.subGuid = GuidHelper.Get(Player.main.GetCurrentSub()?.gameObject); res.cameraPosition = MainCamera.camera.transform.position; res.cameraRotation = MainCamera.camera.transform.rotation; res.additiveRotation = Builder.additiveRotation; if (furniture == false) { res.objectPosition = gameObject.transform.position; res.objectRotation = gameObject.transform.rotation; } else { res.objectPosition = gameObject.transform.localPosition; res.objectRotation = gameObject.transform.localRotation; } if (baseGhost != null) { Log.Info("Base ghost: type:{0}, target:{1}", baseGhost.GetType().FullName, baseGhost.targetOffset); res.ghostGuid = GuidHelper.Get(baseGhost.gameObject); var corridorGhost = baseGhost as BaseAddCorridorGhost; if (corridorGhost != null) { res.direction = (int)corridorGhost.ReflectionGet("rotation"); } var addModuleGhost = baseGhost as BaseAddModuleGhost; if (addModuleGhost != null) { res.direction = (int)(Base.Direction)addModuleGhost.ReflectionGet("direction"); } var addMapRoom = baseGhost as BaseAddMapRoomGhost; if (addMapRoom != null) { res.direction = (int)(Base.CellType)addMapRoom.ReflectionGet("cellType"); } var addFaceGhost = baseGhost as BaseAddFaceGhost; if (addFaceGhost != null) { res.anchor = addFaceGhost.TargetBase.GetAnchor(); res.face = addFaceGhost.anchoredFace.GetValueOrDefault(); res.hasFace = addFaceGhost.anchoredFace.HasValue; } } // Log.Info("Sending ClientBuildConstruct: {0}, {1}, {2}, {3}", res.tech, res.objectGuid, res.targetGuid, res.objectPosition); Multiplayer.main.Send(res); // ShinkaiPatcher.Unity.SceneDumper.DumpScene(); }
static public void PlaceBase(ConstructableBase component, BaseGhost baseGhost, TechType tech) { Place(component.gameObject, baseGhost?.TargetBase?.gameObject, baseGhost, tech, false); }
private void ConstructionCompleted(ConstructionCompletedEvent constructionCompleted) { GameObject constructing = NitroxEntity.RequireObjectFrom(constructionCompleted.PieceId); // For bases, we need to transfer the GUID off of the ghost and onto the finished piece. // Furniture just re-uses the same piece. if (constructing.TryGetComponent(out ConstructableBase constructableBase)) { Int3 latestCell = default(Int3); Base latestBase = null; // must fetch BEFORE setState or else the BaseGhost gets destroyed BaseGhost baseGhost = constructing.GetComponentInChildren <BaseGhost>(); if (baseGhost) { latestCell = baseGhost.TargetOffset; latestBase = baseGhost.TargetBase; } constructableBase.constructedAmount = 1f; constructableBase.SetState(true, true); if (!latestBase) { Optional <object> opConstructedBase = TransientLocalObjectManager.Get(TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT); latestBase = ((GameObject)opConstructedBase.Value).GetComponent <Base>(); Validate.NotNull(latestBase, "latestBase can not be null"); } Transform cellTransform = latestBase.GetCellObject(latestCell); if (latestCell == default(Int3) || !cellTransform) { latestBase.GetClosestCell(constructing.gameObject.transform.position, out latestCell, out _, out _); cellTransform = latestBase.GetCellObject(latestCell); Validate.NotNull(cellTransform, $"Must have a cell transform, one not found near {constructing.gameObject.transform.position} for latestCell {latestCell}"); } GameObject finishedPiece = null; // There can be multiple objects in a cell (such as a corridor with hatches built into it) // we look for a object that is able to be deconstructed that hasn't been tagged yet. foreach (Transform child in cellTransform) { bool isNewBasePiece = !child.GetComponent <NitroxEntity>() && child.GetComponent <BaseDeconstructable>(); if (isNewBasePiece) { finishedPiece = child.gameObject; break; } } Validate.NotNull(finishedPiece, $"Could not find finished piece in cell {latestCell} when constructing {constructionCompleted.PieceId}"); Log.Debug($"Construction completed on a base piece: {constructionCompleted.PieceId} {finishedPiece.name}"); Destroy(constructableBase.gameObject); NitroxEntity.SetNewId(finishedPiece, constructionCompleted.PieceId); BasePieceSpawnProcessor.RunSpawnProcessor(finishedPiece.GetComponent <BaseDeconstructable>(), latestBase, latestCell, finishedPiece); } else if (constructing.TryGetComponent(out Constructable constructable)) { constructable.constructedAmount = 1f; constructable.SetState(true, true); FurnitureSpawnProcessor.RunSpawnProcessor(constructable); Log.Debug($"Construction completed on a piece of furniture: {constructionCompleted.PieceId} {constructable.gameObject.name}"); } else { Log.Error($"Found ghost which is neither base piece nor a constructable: {constructing.name}"); } if (constructionCompleted.BaseId != null && !NitroxEntity.GetObjectFrom(constructionCompleted.BaseId).HasValue) { Log.Debug($"Creating base: {constructionCompleted.BaseId}"); ConfigureNewlyConstructedBase(constructionCompleted.BaseId); } }