Exemple #1
0
        private void Start()
        {
            raftOnLand componentInParent = base.transform.GetComponentInParent <raftOnLand>();

            if (componentInParent && componentInParent.BuildContainer && base.transform.parent != componentInParent.BuildContainer)
            {
                base.transform.parent = componentInParent.BuildContainer;
            }
        }
Exemple #2
0
        public void RespawnBuilding()
        {
            if (BoltNetwork.isServer)
            {
                base.state.repairTrigger = false;
            }
            else if (BoltNetwork.isClient)
            {
                this.HpActual = this._maxHP;
                LocalPlayer.Create.Grabber.Reset();
            }
            DynamicBuilding dynamicBuilding = (!base.transform.parent) ? null : base.transform.parent.GetComponentInParent <DynamicBuilding>();

            if (dynamicBuilding == null)
            {
                dynamicBuilding = base.transform.GetComponent <DynamicBuilding>();
            }
            if (dynamicBuilding)
            {
                dynamicBuilding.LockPhysics();
            }
            GameObject gameObject2;

            if (this._type != BuildingTypes.None)
            {
                GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(Prefabs.Instance.Constructions._blueprints.Find((BuildingBlueprint bp) => bp._type == this._type)._builtPrefab);
                gameObject.transform.position = base.transform.position;
                gameObject.transform.rotation = base.transform.rotation;
                if (dynamicBuilding && this._repairMode == BuildingHealth.RepairModes.RenderersOnly)
                {
                    Collider[] componentsInChildren = gameObject.GetComponentsInChildren <Collider>(true);
                    for (int i = 0; i < componentsInChildren.Length; i++)
                    {
                        componentsInChildren[i].enabled = false;
                    }
                }
                if (this._repairMode == BuildingHealth.RepairModes.RenderersOnly)
                {
                    base.SendMessage("RespawningRenderersFrom", gameObject, SendMessageOptions.DontRequireReceiver);
                    Transform       transform       = (!this._renderersRoot) ? base.transform : this._renderersRoot.transform;
                    LOD_GroupToggle lod_GroupToggle = (!transform.parent) ? null : transform.parent.GetComponent <LOD_GroupToggle>();
                    for (int j = transform.childCount - 1; j >= 0; j--)
                    {
                        Transform child = transform.GetChild(j);
                        if ((!child.GetComponent <StoreInformation>() || child.GetComponent <ForceRepairRespawn>()) && !child.GetComponent <SkipRepairRespawn>() && !child.name.Contains("Anchor"))
                        {
                            UnityEngine.Object.Destroy(child.gameObject);
                        }
                    }
                    Transform transform2 = (!this._renderersRoot) ? gameObject.transform : gameObject.GetComponent <BuildingHealth>()._renderersRoot.transform;
                    for (int k = transform2.childCount - 1; k >= 0; k--)
                    {
                        Transform child2 = transform2.GetChild(k);
                        if ((!child2.GetComponent <StoreInformation>() || child2.GetComponent <ForceRepairRespawn>()) && !child2.GetComponent <SkipRepairRespawn>() && !child2.name.Contains("Anchor"))
                        {
                            child2.parent = transform;
                            if (lod_GroupToggle)
                            {
                                lod_GroupToggle._levels[0].Renderers[k] = child2.GetComponentInChildren <Renderer>();
                            }
                        }
                    }
                    if (lod_GroupToggle)
                    {
                        lod_GroupToggle.RefreshVisibility(true);
                    }
                    UnityEngine.Object.Destroy(gameObject);
                    gameObject2 = base.gameObject;
                }
                else
                {
                    TreeStructure component = base.GetComponent <TreeStructure>();
                    if (component)
                    {
                        TreeStructure component2 = gameObject.GetComponent <TreeStructure>();
                        component2.TreeId = component.TreeId;
                    }
                    UnityEngine.Object.Destroy(base.gameObject);
                    gameObject2 = gameObject;
                    if (BoltNetwork.isServer)
                    {
                        BoltNetwork.Attach(gameObject);
                    }
                }
                if (this._type == BuildingTypes.Shelter)
                {
                    EventRegistry.Achievements.Publish(TfEvent.Achievements.RepairedShelter, null);
                }
            }
            else
            {
                gameObject2 = base.gameObject;
            }
            gameObject2.SendMessage("ResetHP", SendMessageOptions.DontRequireReceiver);
            gameObject2.SendMessage("CreateStructure", true, SendMessageOptions.DontRequireReceiver);
            trapTrigger componentInChildren = base.GetComponentInChildren <trapTrigger>();

            if (componentInChildren && componentInChildren.GetComponentInParent <PrefabIdentifier>().gameObject == base.gameObject)
            {
                componentInChildren.CopyTrapStatusTo(gameObject2.GetComponentInChildren <trapTrigger>());
            }
            if (dynamicBuilding)
            {
                raftOnLand component3 = base.transform.GetComponent <raftOnLand>();
                if (component3)
                {
                    dynamicBuilding.UnlockPhysics();
                    component3.StartCoroutine(component3.fixBounceOnSpawn());
                }
                else
                {
                    dynamicBuilding.Invoke("UnlockPhysics", 0.1f);
                }
            }
            if (LocalPlayer.Sfx)
            {
                LocalPlayer.Sfx.PlayTwinkle();
            }
        }