public BoltEntity GetParentEntity(GameObject ghost) { BoltEntity boltEntity = null; SingleAnchorStructure component = ghost.GetComponent <SingleAnchorStructure>(); if (component && component.Anchor1) { component.enabled = false; boltEntity = component.Anchor1.GetComponentInParent <BoltEntity>(); } if (this._buildingPlacer.ForcedParent) { boltEntity = this._buildingPlacer.ForcedParent.GetComponentInParent <BoltEntity>(); this._buildingPlacer.ForcedParent = null; } else if (this._buildingPlacer.LastHit != null && !this._currentBlueprint._isDynamic && !boltEntity) { boltEntity = this._buildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>(); } if (!boltEntity) { boltEntity = null; } else { DynamicBuilding component2 = boltEntity.GetComponent <DynamicBuilding>(); if (component2 && (!this._currentBlueprint._allowParentingToDynamic || !component2._allowParenting)) { boltEntity = null; } } return(boltEntity); }
private IEnumerator OnPlaced() { base.enabled = false; yield return(null); Transform ghost; if (this._snappedGo.activeSelf) { ghost = this._snappedGo.transform.GetChild(0); } else { ghost = this._freeGo.transform.GetChild(0); } if (!BoltNetwork.isRunning) { if (LocalPlayer.Create.BuildingPlacer.LastHit != null && LocalPlayer.Create.BuildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>()) { ghost.parent = LocalPlayer.Create.BuildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>().transform; } else if (LocalPlayer.Create.ParentEntity) { DynamicBuilding component = LocalPlayer.Create.ParentEntity.GetComponent <DynamicBuilding>(); ghost.transform.parent = ((!component || !component._parentOverride) ? LocalPlayer.Create.ParentEntity.transform : component._parentOverride); } else { ghost.parent = null; } ghost.SendMessage("OnPlaced", SendMessageOptions.DontRequireReceiver); GameObject gameObject = ghost.Find("Trigger").gameObject; gameObject.SetActive(true); if ((this._snappedGo.activeSelf && this._initializeSnapped) || (this._freeGo.activeSelf && this._initializeAirborne)) { gameObject.GetComponent <Craft_Structure>().Initialize(); } UnityEngine.Object.Destroy(base.gameObject); } else { PlaceConstruction placeConstruction = PlaceConstruction.Create(GlobalTargets.OnlyServer); if (LocalPlayer.Create.BuildingPlacer.LastHit != null) { placeConstruction.Parent = LocalPlayer.Create.BuildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>(); } placeConstruction.PrefabId = ghost.GetComponent <BoltEntity>().prefabId; placeConstruction.Position = ghost.position; placeConstruction.Rotation = ghost.rotation; FoundationArchitect component2 = ghost.GetComponent <FoundationArchitect>(); if (component2) { placeConstruction.AboveGround = component2._aboveGround; } placeConstruction.Send(); UnityEngine.Object.Destroy(base.gameObject, 0.05f); } yield break; }
private void OnPlaced() { base.enabled = false; Transform child; if (this._inWaterGo.activeSelf) { child = this._inWaterGo.transform.GetChild(0); } else { child = this._outWaterGo.transform.GetChild(0); } if (!BoltNetwork.isRunning) { if (LocalPlayer.Create.BuildingPlacer.LastHit != null && LocalPlayer.Create.BuildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>()) { child.parent = LocalPlayer.Create.BuildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>().transform; } else if (LocalPlayer.Create.ParentEntity) { DynamicBuilding component = LocalPlayer.Create.ParentEntity.GetComponent <DynamicBuilding>(); child.transform.parent = ((!component || !component._parentOverride) ? LocalPlayer.Create.ParentEntity.transform : component._parentOverride); } else { child.parent = null; } child.SendMessage("OnPlaced", SendMessageOptions.DontRequireReceiver); GameObject gameObject = child.Find("Trigger").gameObject; gameObject.SetActive(true); if ((this._inWaterGo.activeSelf && this._initializeOutWater) || (this._outWaterGo.activeSelf && this._initializeInWater)) { gameObject.GetComponent <Craft_Structure>().Initialize(); } UnityEngine.Object.Destroy(base.gameObject); } else { CoopConstructionEx component2 = child.GetComponent <CoopConstructionEx>(); if (component2) { BoltEntity component3 = child.GetComponent <BoltEntity>(); BoltEntity boltEntity = LocalPlayer.Create.GetParentEntity(child.gameObject) ?? LocalPlayer.Create.ParentEntity; component2.SendMessage("OnSerializing"); CoopConstructionExToken coopConstructionExToken = LocalPlayer.Create.GetCoopConstructionExToken(component2, boltEntity); PlaceFoundationEx placeFoundationEx = PlaceFoundationEx.Create(GlobalTargets.OnlyServer); placeFoundationEx.Parent = boltEntity; placeFoundationEx.Position = child.transform.position; placeFoundationEx.Prefab = component3.prefabId; placeFoundationEx.Token = coopConstructionExToken; placeFoundationEx.Send(); } else { PlaceConstruction placeConstruction = PlaceConstruction.Create(GlobalTargets.OnlyServer); if (LocalPlayer.Create.BuildingPlacer.LastHit != null) { placeConstruction.Parent = LocalPlayer.Create.BuildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>(); } placeConstruction.PrefabId = child.GetComponent <BoltEntity>().prefabId; placeConstruction.Position = child.position; placeConstruction.Rotation = child.rotation; FoundationArchitect component4 = child.GetComponent <FoundationArchitect>(); if (component4) { placeConstruction.AboveGround = component4._aboveGround; } placeConstruction.Send(); } UnityEngine.Object.Destroy(base.gameObject, 0.05f); } }
private IEnumerator PlaceGhostRoutine(bool chain) { BuildingTypes bType = this.CurrentBlueprint._type; yield return(null); if (this.CreateMode) { this.ShownPlace = false; this.CreateMode = false; if (!this.ToolsShown) { base.SendMessage("BuildToolsTut"); this.ToolsShown = true; } TreeStructure ts = this._currentGhost.GetComponentInChildren <TreeStructure>(); if (ts && this.TargetTree) { if (this.TargetTree.CompareTag("conTree")) { ts.TreeId = this.TargetTree.parent.GetComponent <TreeHealth>().LodTree.GetComponentInChildren <CoopTreeId>().Id; } else { ts.TreeId = this.TargetTree.GetComponent <TreeHealth>().LodTree.GetComponentInChildren <CoopTreeId>().Id; } ts.enabled = true; if (!BoltNetwork.isRunning) { Scene.ActiveMB.StartCoroutine(ts.OnDeserialized()); } } CoopConstructionEx coopEx = this._currentGhost.GetComponent <CoopConstructionEx>(); WallArchitect wallArch = this.CurrentGhost.GetComponent <WallArchitect>(); ICoopTokenConstruction tokenConstruction = this._currentGhost.GetComponent <ICoopTokenConstruction>(); this.ParentEntity = this.GetParentEntity(this._currentGhost); if (BoltNetwork.isRunning && !wallArch) { BoltEntity component = this._currentGhost.GetComponent <BoltEntity>(); if (tokenConstruction != null) { PlaceFoundationEx placeFoundationEx = PlaceFoundationEx.Create(GlobalTargets.OnlyServer); placeFoundationEx.Position = this._currentGhost.transform.position; placeFoundationEx.Rotation = this._currentGhost.transform.rotation; placeFoundationEx.Prefab = component.prefabId; placeFoundationEx.Token = tokenConstruction.CustomToken; placeFoundationEx.Parent = this.ParentEntity; placeFoundationEx.Send(); UnityEngine.Object.Destroy(this._currentGhost); } else if (coopEx) { coopEx.SendMessage("OnSerializing"); CoopConstructionExToken coopConstructionExToken = this.GetCoopConstructionExToken(coopEx, this.ParentEntity); PlaceFoundationEx placeFoundationEx2 = PlaceFoundationEx.Create(GlobalTargets.OnlyServer); placeFoundationEx2.Parent = this.ParentEntity; placeFoundationEx2.Position = this._currentGhost.transform.position; placeFoundationEx2.Rotation = this._currentGhost.transform.rotation; placeFoundationEx2.Prefab = component.prefabId; placeFoundationEx2.Token = coopConstructionExToken; placeFoundationEx2.Send(); UnityEngine.Object.Destroy(this._currentGhost); } else if (!this._currentGhost.GetComponent(typeof(IAnchorableStructure)) && component) { this._currentGhost.AddComponent <CoopDestroyPredictedGhost>(); this._currentGhost.AddComponent <destroyAfter>().destroyTime = 2f; PlaceConstruction placeConstruction = PlaceConstruction.Create(GlobalTargets.OnlyServer); placeConstruction.Parent = this.ParentEntity; placeConstruction.PrefabId = component.prefabId; placeConstruction.Position = this._currentGhost.transform.position; placeConstruction.Rotation = this._currentGhost.transform.rotation; if (ts) { placeConstruction.TreeIndex = ts.TreeId; } placeConstruction.Send(); this._currentGhost.SendMessage("OnPlacingRemotely", SendMessageOptions.DontRequireReceiver); } else { this._currentGhost.SendMessage("OnPlaced", false, SendMessageOptions.DontRequireReceiver); } } else { this._currentGhost.SendMessage("OnPlaced", false, SendMessageOptions.DontRequireReceiver); this._currentGhost.transform.Find("Trigger").gameObject.SetActive(true); Transform transform = this._currentGhost.transform.Find("LastBuiltLocation"); if (transform) { transform.gameObject.SetActive(true); } if (this.ParentEntity) { DynamicBuilding component2 = this.ParentEntity.GetComponent <DynamicBuilding>(); this._currentGhost.transform.parent = ((!component2 || !component2._parentOverride) ? this.ParentEntity.transform : component2._parentOverride); } } this.ClearReferences(!chain); LocalPlayer.Sfx.PlayPlaceGhost(); this.RefreshGrabber(); yield return(YieldPresets.WaitPointFiveSeconds); if (chain) { this.MultiPlaceAction(bType); } } yield break; }
private void Update() { if (this._allowInTree) { LocalPlayer.Create.TargetTree = null; } RaycastHit value; if (Physics.Raycast((this._origin != VerticalSnap.RayCastOrigins.Player) ? base.transform.position : LocalPlayer.MainCamTr.position, LocalPlayer.MainCamTr.forward, out value, this._raycastDistance, this._wallLayers.value)) { DynamicBuilding componentInParent = value.collider.GetComponentInParent <DynamicBuilding>(); bool flag = (double)Mathf.Abs(value.normal.y) < 0.5; bool flag2 = !componentInParent || componentInParent._allowParenting; if (this._origin == VerticalSnap.RayCastOrigins.Player) { base.transform.parent = null; base.transform.position = value.point; } if (!this._verticalOnly) { if (this._origin == VerticalSnap.RayCastOrigins.Player) { base.transform.rotation = Quaternion.FromToRotation(Vector3.up, value.normal) * LocalPlayer.Create.BuildingPlacer.transform.rotation; Scene.HudGui.RotateIcon.SetActive(true); } } else if (flag) { Vector3 normal = value.normal; normal.y = 0f; base.transform.rotation = Quaternion.Euler(0f, LocalPlayer.Create.BuildingPlacer.transform.rotation.y, 0f) * Quaternion.LookRotation(normal); } if (flag2 && this._allowInTree) { if (value.collider.CompareTag("conTree")) { LocalPlayer.Create.TargetTree = value.collider.transform; } else if (value.collider.CompareTag("Tree")) { LocalPlayer.Create.TargetTree = value.collider.transform; } } if (flag2 && (!this._verticalOnly || flag)) { LocalPlayer.Create.BuildingPlacer.LastHit = new RaycastHit?(value); LocalPlayer.Create.BuildingPlacer.SetClear(); Scene.HudGui.PlaceIcon.SetActive(true); Scene.HudGui.RotateIcon.SetActive(!this._verticalOnly); } else { LocalPlayer.Create.BuildingPlacer.SetNotclear(); Scene.HudGui.PlaceIcon.SetActive(false); Scene.HudGui.RotateIcon.SetActive(true); } } else if (base.transform.parent == null) { base.transform.parent = LocalPlayer.Create.BuildingPlacer.transform; base.transform.localPosition = this._offsetWithPlacer; if (this._verticalOnly) { LocalPlayer.Create.BuildingPlacer.SetNotclear(); Scene.HudGui.PlaceIcon.SetActive(false); Scene.HudGui.RotateIcon.SetActive(true); } } else { LocalPlayer.Create.BuildingPlacer.SetNotclear(); Scene.HudGui.PlaceIcon.SetActive(false); Scene.HudGui.RotateIcon.SetActive(true); } }
private void Build() { if (this._type != BuildingTypes.None) { EventRegistry.Player.Publish(TfEvent.BuiltStructure, this._type); this._type = BuildingTypes.None; } if (BoltNetwork.isClient) { if (base.enabled) { base.enabled = false; this.AllOff(false); } return; } if (!this._ghost) { this._ghost = base.transform.parent.gameObject; } GameObject gameObject; if (BoltNetwork.isServer) { if (base.entity.attachToken != null) { if (base.entity.attachToken is CoopWallChunkToken) { (base.entity.attachToken as CoopWallChunkToken).Additions = base.entity.GetComponent <WallChunkArchitect>().Addition; } gameObject = BoltNetwork.Instantiate(this.Built, base.entity.attachToken, this._ghost.transform.position, this._ghost.transform.rotation).gameObject; } else { gameObject = BoltNetwork.Instantiate(this.Built, base.entity.attachToken, this._ghost.transform.position, this._ghost.transform.rotation).gameObject; BoltEntity component = gameObject.GetComponent <BoltEntity>(); if (component && component.isAttached && component.StateIs <IMultiHolderState>()) { component.GetState <IMultiHolderState>().IsReal = true; } BoltEntity component2 = gameObject.GetComponent <BoltEntity>(); if (component2 && component.isAttached && component2.StateIs <IRaftState>()) { component2.GetState <IRaftState>().IsReal = true; } } } else { gameObject = UnityEngine.Object.Instantiate <GameObject>(this.Built, this._ghost.transform.position, this._ghost.transform.rotation); } TreeStructure component3 = this._ghost.GetComponent <TreeStructure>(); if (component3) { TreeStructure treeStructure = gameObject.GetComponent <TreeStructure>(); if (!treeStructure) { treeStructure = gameObject.AddComponent <TreeStructure>(); } treeStructure.TreeId = component3.TreeId; } ropeSetGroundHeight component4 = gameObject.GetComponent <ropeSetGroundHeight>(); if (component4) { gameObject.SendMessage("setGroundTriggerHeight", SendMessageOptions.DontRequireReceiver); } if (this._ghost.transform.parent != null) { gameObject.transform.parent = this._ghost.transform.parent; DynamicBuilding componentInParent = gameObject.GetComponentInParent <DynamicBuilding>(); if (componentInParent != null) { IgnoreCollisionInChildren componentInChildren = componentInParent.GetComponentInChildren <IgnoreCollisionInChildren>(); if (componentInChildren != null) { componentInChildren.startDisableChildren(); } } } this.OnBuilt(gameObject); this.OnBuilt = null; base.enabled = false; this._initialized = false; if (this._ghost) { base.StartCoroutine(this.DelayedDestroy()); } else { this.AllOff(true); } if (this._playTwinkle && LocalPlayer.Sfx) { LocalPlayer.Sfx.PlayBuildingComplete(gameObject, true); } else if (SteamDSConfig.isDedicatedServer) { FmodOneShot fmodOneShot = FmodOneShot.Create(GlobalTargets.Others, ReliabilityModes.Unreliable); fmodOneShot.EventPath = CoopAudioEventDb.FindId("event:/ui/ingame/ui_complete"); fmodOneShot.Position = gameObject.transform.position; fmodOneShot.Send(); } }