private void Process(ClientBuildConstruct msg) { var prefab = CraftData.GetBuildPrefab(msg.tech); if (prefab == null) { return; } Logic.Building.buildBase = GuidHelper.FindComponent <Base>(msg.targetGuid); Logic.Building.buildDirection = msg.direction; Logic.Building.buildBaseFace = msg.face; Logic.Building.buildBaseAnchor = msg.anchor; Logic.Building.buildPlaceActive = true; using (var change = new BuildChange(msg.cameraPosition, msg.cameraRotation, msg.subGuid)) { try { MultiplayerBuilder.baseGhostGuid = msg.ghostGuid; MultiplayerBuilder.targetGuid = msg.targetGuid; MultiplayerBuilder.targetGuid = msg.targetGuid; MultiplayerBuilder.overridePosition = msg.objectPosition; MultiplayerBuilder.overrideRotation = msg.objectRotation; MultiplayerBuilder.additiveRotation = msg.additiveRotation; Builder.additiveRotation = msg.additiveRotation; MultiplayerBuilder.Begin(prefab); MultiplayerBuilder.Update(); GameObject gameObject; Constructable constructable; if (MultiplayerBuilder.TryPlace(out gameObject, out constructable)) { if (gameObject != null) { GuidHelper.Set(gameObject, msg.objectGuid); } if (constructable != null) { var method = typeof(Constructable).GetMethod("Start", BindingFlags.NonPublic | BindingFlags.Instance); method.Invoke(constructable, new object[] { }); } } else { Log.Warn("Couldn't place piece: " + msg.tech); } MultiplayerBuilder.End(); } catch (Exception exception) { UnityEngine.Debug.LogException(exception); } } Logic.Building.buildPlaceActive = false; }
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(); }