Ejemplo n.º 1
0
    private IEnumerator setPickupRoutine()
    {
        if (this.fromMutantRagdoll)
        {
            if (this._rootGo && !BoltNetwork.isClient)
            {
                destroyAfter destroyAfter = this._rootGo.AddComponent <destroyAfter>();
                destroyAfter.destroyTime = 60f;
            }
            GameObject value = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("CutScene/girl_Pickup"), LocalPlayer.PlayerBase.transform.position, LocalPlayer.PlayerBase.transform.rotation);
            LocalPlayer.SpecialActions.SendMessage("setGirlGo", value, SendMessageOptions.DontRequireReceiver);
            LocalPlayer.SpecialActions.SendMessage("setGirlTrigger", base.gameObject, SendMessageOptions.DontRequireReceiver);
            this.ragdollGo.SetActive(false);
        }
        else
        {
            LocalPlayer.SpecialActions.SendMessage("setGirlGo", this.girlGo, SendMessageOptions.DontRequireReceiver);
            LocalPlayer.SpecialActions.SendMessage("setGirlTrigger", base.gameObject, SendMessageOptions.DontRequireReceiver);
        }
        LocalPlayer.SpecialActions.SendMessage("pickupGirlRoutine", base.transform.position, SendMessageOptions.DontRequireReceiver);
        if (BoltNetwork.isRunning)
        {
            base.entity.Freeze(false);
            syncGirlPickup syncGirlPickup = syncGirlPickup.Create(GlobalTargets.Everyone);
            syncGirlPickup.target         = base.transform.GetComponentInParent <BoltEntity>();
            syncGirlPickup.disableTrigger = true;
            syncGirlPickup.Send();
        }
        base.gameObject.SetActive(false);
        yield return(null);

        yield break;
    }
Ejemplo n.º 2
0
    private void OnDisable()
    {
        base.CancelInvoke("updatePlayerTargets");
        FMODCommon.UnloadEvents(new string[]
        {
            this.dieEvent,
            this.sharkAttackEvent
        });
        if (this.MyTrigger)
        {
            this.MyTrigger.SetActive(false);
        }
        destroyAfter component = base.transform.GetComponent <destroyAfter>();

        if (component)
        {
            component.enabled = false;
        }
        if (this.rb)
        {
            this.rb.useGravity  = false;
            this.rb.isKinematic = true;
            this.spearedBool    = false;
        }
        if (this.col)
        {
            this.col.isTrigger = true;
            this.col.enabled   = true;
        }
        this.Dead     = false;
        this.exploded = false;
        base.CancelInvoke("enableGrabTrigger");
    }
Ejemplo n.º 3
0
 private void Die()
 {
     if (!this.Dead)
     {
         this.Dead = true;
         this.controller.AddFishSpawnBackCounter();
         FMODCommon.PlayOneshot(this.dieEvent, base.transform);
         if (this.Blood)
         {
             this.Blood.SetActive(true);
             this.Blood.transform.parent = null;
         }
         if (this.exploded)
         {
             base.Invoke("enableGrabTrigger", 5f);
         }
         else if (this.MyTrigger)
         {
             this.MyTrigger.SetActive(true);
         }
         base.CancelInvoke("switchDirection");
         base.CancelInvoke("checkForwardCollide");
         base.StopCoroutine("setFleeSpeed");
         if (this.typeShark)
         {
             EventRegistry.Animal.Publish(TfEvent.KilledShark, base.gameObject);
             base.StartCoroutine("setDeathSpeedShark");
         }
         else
         {
             base.StartCoroutine("setDeathSpeed");
         }
         destroyAfter component = base.transform.GetComponent <destroyAfter>();
         if (component)
         {
             component.enabled = true;
         }
         if (!this.typeShark)
         {
             this.rb.useGravity  = true;
             this.rb.isKinematic = false;
             base.transform.GetComponent <Collider>().isTrigger = false;
         }
         if (this.exploded)
         {
             this.rb.AddTorque((float)UnityEngine.Random.Range(-2000, 2000), (float)UnityEngine.Random.Range(-2000, 2000), (float)UnityEngine.Random.Range(-2000, 2000), ForceMode.Force);
         }
         else if (!this.typeShark)
         {
             this.rb.AddTorque(base.transform.forward * 8000f, ForceMode.Force);
         }
         if (this.typeShark)
         {
             this.animator.SetBoolReflected("Dead", true);
             this.animator.speed = 1f;
             base.Invoke("doRagDoll", 3.3f);
         }
     }
 }
Ejemplo n.º 4
0
 public void TierDestroyed_Actual(FoundationChunkTier tier)
 {
     if (!PlayerPreferences.NoDestruction)
     {
         try
         {
             if (!this._collapsing)
             {
                 int num = tier._segmentNum + this._foundation.Edges.Take(tier._edgeNum).Sum((FoundationArchitect.Edge e) => e._segments.Length);
                 this._chunks[num]._tiers[tier._tierNum]._hp = -42f;
                 Transform exists = this._foundation.FoundationRoot.transform.Find("Edge" + tier._edgeNum);
                 if (exists)
                 {
                     Renderer[] componentsInChildren = tier.GetComponentsInChildren <Renderer>();
                     for (int i = 0; i < componentsInChildren.Length; i++)
                     {
                         Transform  transform  = componentsInChildren[i].transform;
                         GameObject gameObject = transform.gameObject;
                         transform.parent = null;
                         gameObject.layer = 31;
                         CapsuleCollider capsuleCollider = gameObject.AddComponent <CapsuleCollider>();
                         capsuleCollider.radius    = 0.5f;
                         capsuleCollider.height    = 4.5f;
                         capsuleCollider.direction = 2;
                         Rigidbody rigidbody = gameObject.AddComponent <Rigidbody>();
                         if (rigidbody)
                         {
                             rigidbody.AddForce((transform.position - tier.transform.position).normalized * 2.5f, ForceMode.Impulse);
                             rigidbody.AddRelativeTorque(Vector3.up * 2f, ForceMode.Impulse);
                         }
                         destroyAfter destroyAfter = gameObject.AddComponent <destroyAfter>();
                         destroyAfter.destroyTime = 1.75f;
                         this._collapsedLogs++;
                     }
                 }
                 Collider component = tier.GetComponent <Collider>();
                 if (component && !component.isTrigger)
                 {
                     UnityEngine.Object.Destroy(component);
                 }
                 if (BoltNetwork.isServer)
                 {
                     this.PublishDestroyedTierData(this.LightWeightExport());
                 }
                 this.IntegrityCheck(num, tier._tierNum);
                 if (!this._collapsing)
                 {
                     this.CheckSpawnRepairTrigger();
                 }
             }
         }
         catch (Exception exception)
         {
             Debug.LogException(exception);
         }
     }
 }
Ejemplo n.º 5
0
 private void StartCleanUp()
 {
     if (!this.CleanUpActive)
     {
         this.CleanUpActive = true;
         base.Invoke("CleanUp", this.DelayBeforeCleanup);
         destroyAfter destroyAfter = base.GetComponentInParent <Rigidbody>().gameObject.AddComponent <destroyAfter>();
         destroyAfter.destroyTime = this.DelayBeforeCleanup;
     }
 }
Ejemplo n.º 6
0
    private void DieSpear()
    {
        destroyAfter component = base.transform.GetComponent <destroyAfter>();

        if (component)
        {
            component.enabled = false;
        }
        if (this.controlScript && this.controlScript.allFish.Contains(base.gameObject))
        {
            this.controlScript.allFish.Remove(base.gameObject);
        }
        this.spearedBool    = true;
        this.rb.useGravity  = false;
        this.rb.isKinematic = true;
        this.col.isTrigger  = true;
        this.col.enabled    = false;
        if (!this.Dead)
        {
            FMODCommon.PlayOneshot(this.dieEvent, base.transform);
            if (this.controller)
            {
                this.controller.AddFishSpawnBackCounter();
            }
        }
        if (this.Blood)
        {
            this.Blood.SetActive(true);
            this.Blood.transform.parent = null;
        }
        this.Dead = true;
        if (this.animator)
        {
            this.animator.SetBoolReflected("Dead", true);
        }
        base.CancelInvoke("switchDirection");
        base.CancelInvoke("checkForwardCollide");
        if (this.MyTrigger)
        {
            this.MyTrigger.SetActive(true);
        }
        base.StopCoroutine("setFleeSpeed");
        if (this.typeShark)
        {
            base.StartCoroutine("setDeathSpeedShark");
        }
        else
        {
            base.StartCoroutine("setDeathSpeed");
        }
    }
Ejemplo n.º 7
0
        private int CollapseReal(Vector3 origin)
        {
            if (base.transform.parent && base.transform.parent.parent)
            {
                LODGroup component = base.transform.parent.parent.GetComponent <LODGroup>();
                if (component)
                {
                    component.ForceLOD(0);
                }
            }
            int num = 0;

            foreach (Renderer renderer in (!this._destroyTarget) ? base.GetComponentsInChildren <Renderer>() : this._destroyTarget.GetComponentsInChildren <Renderer>())
            {
                GameObject gameObject = renderer.gameObject;
                if (gameObject.activeInHierarchy)
                {
                    Transform transform = renderer.transform;
                    transform.parent = null;
                    gameObject.layer = this._detachedLayer;
                    CapsuleCollider capsuleCollider = gameObject.AddComponent <CapsuleCollider>();
                    capsuleCollider.radius    = 0.1f;
                    capsuleCollider.height    = 1f;
                    capsuleCollider.direction = 2;
                    Rigidbody rigidbody = gameObject.AddComponent <Rigidbody>();
                    if (rigidbody)
                    {
                        rigidbody.AddForce(((transform.position - origin).normalized + Vector3.up) * 2f, ForceMode.Impulse);
                        rigidbody.AddRelativeTorque(Vector3.up * 2f, ForceMode.Impulse);
                        if (gameObject.CompareTag("Log"))
                        {
                            num++;
                        }
                    }
                    destroyAfter destroyAfter = gameObject.AddComponent <destroyAfter>();
                    destroyAfter.destroyTime = 2f;
                }
            }
            if (this._dustPrefab)
            {
                UnityEngine.Object.Instantiate <GameObject>(this._dustPrefab, base.transform.position, base.transform.rotation);
            }
            UnityEngine.Object.Destroy((!this._destroyTarget) ? base.gameObject : this._destroyTarget);
            return(num);
        }
Ejemplo n.º 8
0
    private void releaseFish()
    {
        if (this.MyTrigger)
        {
            this.MyTrigger.SetActive(true);
        }
        base.CancelInvoke("switchDirection");
        base.CancelInvoke("checkForwardCollide");
        base.StopCoroutine("setFleeSpeed");
        base.StartCoroutine("setDeathSpeed");
        destroyAfter component = base.transform.GetComponent <destroyAfter>();

        if (component)
        {
            component.enabled = false;
        }
        this.spearedBool    = false;
        this.rb.useGravity  = true;
        this.rb.isKinematic = false;
        base.transform.GetComponent <Collider>().isTrigger = false;
    }
Ejemplo n.º 9
0
 private void OnProjectileThrown(GameObject projectile)
 {
     if (this._state == BurnableItem.States.Burning)
     {
         if (this._weaponFire)
         {
             this._weaponFire.transform.parent = projectile.transform;
             this._weaponFire = null;
         }
         destroyAfter destroyAfter = projectile.AddComponent <destroyAfter>();
         destroyAfter.destroyTime = this._fuel;
         Renderer component = projectile.GetComponent <Renderer>();
         if (component)
         {
             component.sharedMaterial = base.GetComponent <Renderer>().sharedMaterial;
         }
         MasterFireSpread component2 = projectile.GetComponent <MasterFireSpread>();
         if (component2)
         {
             component2.Fuel = this._fuel * 2f;
         }
         PickUp componentInChildren = projectile.GetComponentInChildren <PickUp>();
         if (componentInChildren)
         {
             UnityEngine.Object.Destroy(componentInChildren.gameObject);
         }
         this.Burnt();
         this.Dissolved(true);
     }
     else if (this._state > BurnableItem.States.Burning)
     {
         destroyAfter destroyAfter2 = projectile.AddComponent <destroyAfter>();
         destroyAfter2.destroyTime = this._fuel;
         Renderer component3 = projectile.GetComponent <Renderer>();
         if (component3)
         {
             component3.sharedMaterial = base.GetComponent <Renderer>().sharedMaterial;
         }
     }
 }
Ejemplo n.º 10
0
 public void Collapse()
 {
     MeshRenderer[] array = (!this._destroyTarget) ? base.GetComponentsInChildren <MeshRenderer>() : this._destroyTarget.GetComponentsInChildren <MeshRenderer>();
     for (int i = 0; i < array.Length; i++)
     {
         Renderer   renderer   = array[i];
         GameObject gameObject = renderer.gameObject;
         if (gameObject.activeInHierarchy)
         {
             Transform transform = renderer.transform;
             transform.parent = null;
             gameObject.layer = this._detachedLayer;
             if (!gameObject.GetComponent <Collider>())
             {
                 CapsuleCollider capsuleCollider = gameObject.AddComponent <CapsuleCollider>();
                 capsuleCollider.radius    = 0.1f;
                 capsuleCollider.height    = 1.5f;
                 capsuleCollider.direction = (int)this._capsuleDirection;
             }
             Rigidbody rigidbody = gameObject.AddComponent <Rigidbody>();
             if (rigidbody)
             {
                 rigidbody.AddForce((transform.position.normalized + Vector3.up) * (2.5f * this._destructionForceMultiplier), ForceMode.Impulse);
                 rigidbody.AddRelativeTorque(Vector3.up * (2f * this._destructionForceMultiplier), ForceMode.Impulse);
             }
             destroyAfter destroyAfter = gameObject.AddComponent <destroyAfter>();
             destroyAfter.destroyTime = 2.5f;
         }
     }
     if (BoltNetwork.isClient)
     {
         BoltEntity component = base.GetComponent <BoltEntity>();
         if (component && component.isAttached && !component.isOwner)
         {
             return;
         }
     }
     UnityEngine.Object.Destroy(base.gameObject);
 }
Ejemplo n.º 11
0
 private void OnBeginCollapse()
 {
     for (int i = base.transform.childCount - 1; i >= 0; i--)
     {
         Transform child = base.transform.GetChild(i);
         child.parent = null;
         if (!child.GetComponent <Collider>())
         {
             CapsuleCollider capsuleCollider = child.gameObject.AddComponent <CapsuleCollider>();
             capsuleCollider.radius    = 0.1f;
             capsuleCollider.height    = 1.5f;
             capsuleCollider.direction = 1;
         }
         Rigidbody rigidbody = child.gameObject.AddComponent <Rigidbody>();
         if (rigidbody)
         {
             rigidbody.AddForce((child.position.normalized + Vector3.up) * 2.5f, ForceMode.Impulse);
             rigidbody.AddRelativeTorque(Vector3.up * 2f, ForceMode.Impulse);
         }
         destroyAfter destroyAfter = child.gameObject.AddComponent <destroyAfter>();
         destroyAfter.destroyTime = 2.5f;
     }
 }
Ejemplo n.º 12
0
        public void Collapse()
        {
            if (!BoltNetwork.isClient)
            {
                for (int i = base.transform.childCount - 1; i >= 0; i--)
                {
                    Transform      child     = base.transform.GetChild(i);
                    BuildingHealth component = child.GetComponent <BuildingHealth>();
                    if (component)
                    {
                        child.parent = null;
                        component.Collapse(child.position);
                    }
                    else
                    {
                        FoundationHealth component2 = child.GetComponent <FoundationHealth>();
                        if (component2)
                        {
                            child.parent = null;
                            component2.Collapse(child.position);
                        }
                        else if (BoltNetwork.isRunning && child.GetComponent <BoltEntity>())
                        {
                            child.parent = null;
                            destroyAfter destroyAfter = child.gameObject.AddComponent <destroyAfter>();
                            destroyAfter.destroyTime = 1f;
                        }
                    }
                }
            }
            bool flag = true;

            MeshRenderer[] componentsInChildren = (this._destroyTarget ?? base.gameObject).GetComponentsInChildren <MeshRenderer>();
            int            mask = LayerMask.GetMask(new string[]
            {
                "Default",
                "ReflectBig",
                "Prop",
                "PropSmall",
                "PickUp"
            });

            foreach (MeshRenderer renderer in componentsInChildren)
            {
                GameObject gameObject = renderer.gameObject;
                if (gameObject.activeInHierarchy && (1 << gameObject.layer & mask) != 0)
                {
                    Transform transform = renderer.transform;
                    transform.parent = null;
                    if (gameObject == base.gameObject)
                    {
                        flag = false;
                    }
                    gameObject.layer = this._detachedLayer;
                    if (!gameObject.GetComponent <Collider>())
                    {
                        CapsuleCollider capsuleCollider = gameObject.AddComponent <CapsuleCollider>();
                        capsuleCollider.radius    = 0.1f;
                        capsuleCollider.height    = 1.5f;
                        capsuleCollider.direction = (int)this._capsuleDirection;
                    }
                    Rigidbody rigidbody = gameObject.AddComponent <Rigidbody>();
                    if (rigidbody)
                    {
                        rigidbody.AddForce((transform.position.normalized + Vector3.up) * (2.5f * this._destructionForceMultiplier), ForceMode.Impulse);
                        rigidbody.AddRelativeTorque(Vector3.up * (2f * this._destructionForceMultiplier), ForceMode.Impulse);
                    }
                    destroyAfter destroyAfter2 = gameObject.AddComponent <destroyAfter>();
                    destroyAfter2.destroyTime = 2.5f;
                }
            }
            if (BoltNetwork.isClient)
            {
                BoltEntity component3 = base.GetComponent <BoltEntity>();
                if (component3 && component3.isAttached && !component3.isOwner)
                {
                    return;
                }
            }
            if (flag)
            {
                UnityEngine.Object.Destroy(base.gameObject);
            }
        }
Ejemplo n.º 13
0
        private IEnumerator CollapseRoutine(Vector3 collapsePoint)
        {
            Transform[] logs         = this._foundation.FoundationRoot.GetComponentsInChildren <Transform>();
            Vector3     startPos     = base.transform.position;
            Vector3     fallVelocity = Vector3.zero;
            float       tierFallGoal = 0f;
            float       fallprogress = 0f;

            if (!this._collapsing)
            {
                this._collapsing = true;
                GameStats.DestroyedStructure.Invoke();
                int     nbPickupSpawned    = 0;
                int     totalPickupSpawned = Mathf.Min(this._chunks.Length, 12);
                Vector3 centerPosition     = this._foundation.MultiPointsPositions.GetCenterPosition();
                collapsePoint.y = this._foundation.MultiPointsPositions[0].y;
                Vector3 endPos = startPos + Vector3.Lerp(centerPosition, collapsePoint, 0.3f) - centerPosition;
                endPos.y -= this._foundation.MaxHeight;
                Quaternion fallRotation = Quaternion.LookRotation((collapsePoint - centerPosition).normalized);
                for (int t = 3; t > 0; t--)
                {
                    string tierTag = "SLTier" + t;
                    tierFallGoal = 0.17f * (float)(4 - t);
                    float tierDuration = this._collapseFallDuration / 3f;
                    float startTime    = Time.time;
                    for (int i = 0; i < logs.Length; i++)
                    {
                        Transform transform = logs[i];
                        if (transform && transform.CompareTag(tierTag))
                        {
                            IEnumerator enumerator = transform.GetEnumerator();
                            try
                            {
                                while (enumerator.MoveNext())
                                {
                                    object     obj        = enumerator.Current;
                                    Transform  transform2 = (Transform)obj;
                                    GameObject gameObject = transform2.gameObject;
                                    transform2.parent = null;
                                    logs[i]           = null;
                                    if (t == 1 && nbPickupSpawned < totalPickupSpawned && (float)i / (float)logs.Length > (float)nbPickupSpawned / (float)totalPickupSpawned && !BoltNetwork.isClient)
                                    {
                                        nbPickupSpawned++;
                                        Transform transform3 = UnityEngine.Object.Instantiate <Transform>(Prefabs.Instance.LogPickupPrefab);
                                        transform3.position = transform2.position;
                                        transform3.rotation = transform2.rotation;
                                        Rigidbody component = transform3.GetComponent <Rigidbody>();
                                        if (component)
                                        {
                                            component.AddForce(transform3.right * -UnityEngine.Random.Range(2.5f, 10f), ForceMode.Impulse);
                                            component.AddRelativeTorque(Vector3.up * (float)UnityEngine.Random.Range(1, 10), ForceMode.Impulse);
                                        }
                                        if (BoltNetwork.isRunning)
                                        {
                                            BoltNetwork.Attach(transform3.gameObject);
                                        }
                                        UnityEngine.Object.Destroy(gameObject);
                                    }
                                    else
                                    {
                                        if (!gameObject.GetComponent <Rigidbody>())
                                        {
                                            gameObject.layer = 31;
                                            CapsuleCollider capsuleCollider = gameObject.AddComponent <CapsuleCollider>();
                                            capsuleCollider.radius    = 0.5f;
                                            capsuleCollider.height    = 4.5f;
                                            capsuleCollider.direction = 2;
                                            Rigidbody rigidbody = gameObject.AddComponent <Rigidbody>();
                                            if (rigidbody)
                                            {
                                                rigidbody.AddForce(transform2.right * -UnityEngine.Random.Range(2.5f, 10f), ForceMode.Impulse);
                                                rigidbody.AddRelativeTorque(Vector3.up * (float)UnityEngine.Random.Range(-10, 10), ForceMode.Impulse);
                                            }
                                        }
                                        destroyAfter destroyAfter = gameObject.AddComponent <destroyAfter>();
                                        destroyAfter.destroyTime = tierDuration + 2f;
                                    }
                                }
                            }
                            finally
                            {
                                IDisposable disposable;
                                if ((disposable = (enumerator as IDisposable)) != null)
                                {
                                    disposable.Dispose();
                                }
                            }
                        }
                    }
                    if (LocalPlayer.Sfx)
                    {
                        LocalPlayer.Sfx.PlayStructureBreak(base.gameObject, 0.4f + (float)t * 0.3f);
                    }
                    while (Time.time - startTime < tierDuration)
                    {
                        float alpha = fallprogress + (Time.time - startTime) / tierDuration * tierFallGoal;
                        base.transform.position = Vector3.Lerp(startPos, endPos, alpha);
                        yield return(null);
                    }
                    fallprogress += tierFallGoal;
                    if (t == 2 && this._foundation._mode != FoundationArchitect.Modes.Auto)
                    {
                        Transform transform4 = UnityEngine.Object.Instantiate <Transform>(Prefabs.Instance.BuildingCollapsingDust);
                        Vector3   position   = centerPosition;
                        position.y          = endPos.y + 2.5f;
                        transform4.position = position;
                    }
                    else if (t == 1 && BoltNetwork.isClient)
                    {
                        for (int j = base.transform.childCount - 1; j >= 0; j--)
                        {
                            Transform  child      = base.transform.GetChild(j);
                            BoltEntity component2 = child.GetComponent <BoltEntity>();
                            if (component2)
                            {
                                child.parent = null;
                                if (!component2.GetComponent <destroyAfter>())
                                {
                                    child.gameObject.AddComponent <destroyAfter>().destroyTime = 1f;
                                }
                            }
                        }
                    }
                    yield return(null);
                }
                if (!BoltNetwork.isClient)
                {
                    yield return(null);

                    for (int k = base.transform.childCount - 1; k >= 0; k--)
                    {
                        Transform      child2     = base.transform.GetChild(k);
                        BuildingHealth component3 = child2.GetComponent <BuildingHealth>();
                        if (component3)
                        {
                            child2.parent = null;
                            component3.Collapse(child2.position);
                        }
                        else
                        {
                            FoundationHealth component4 = child2.GetComponent <FoundationHealth>();
                            if (component4)
                            {
                                child2.parent = null;
                                component4.Collapse(child2.position);
                            }
                            else if (BoltNetwork.isRunning && child2.GetComponent <BoltEntity>())
                            {
                                child2.parent = null;
                                destroyAfter destroyAfter2 = child2.gameObject.AddComponent <destroyAfter>();
                                destroyAfter2.destroyTime = 3f;
                            }
                        }
                    }
                    if (this._foundation._mode == FoundationArchitect.Modes.Auto)
                    {
                        BuildingHealth bh = base.GetComponent <BuildingHealth>();
                        bh.Collapse(base.transform.position);
                        yield return(YieldPresets.WaitPointFiveSeconds);
                    }
                    if (!BoltNetwork.isRunning)
                    {
                        UnityEngine.Object.Destroy(base.gameObject);
                    }
                    else
                    {
                        BoltNetwork.Destroy(base.gameObject);
                    }
                }
            }
            yield break;
        }
Ejemplo n.º 14
0
 public void LocalizedTierHit(LocalizedHitData data, FoundationChunkTier tier)
 {
     if (!PlayerPreferences.NoDestruction && !BoltNetwork.isClient)
     {
         this._lastHit = Time.realtimeSinceStartup;
         FoundationArchitect.Edge edge = this._foundation.Edges[tier._edgeNum];
         int num  = this._foundation.Edges.Take(tier._edgeNum).Sum((FoundationArchitect.Edge e) => e._segments.Length);
         int num2 = tier._segmentNum + num;
         this._chunks[num2]._tiers[tier._tierNum]._hp -= data._damage;
         float hp = this._chunks[num2]._tiers[tier._tierNum]._hp;
         if (hp <= 0f)
         {
             if (tier.transform.parent)
             {
                 tier.transform.parent = null;
                 Renderer[] componentsInChildren = tier.GetComponentsInChildren <Renderer>();
                 for (int i = 0; i < componentsInChildren.Length; i++)
                 {
                     Transform  transform  = componentsInChildren[i].transform;
                     GameObject gameObject = transform.gameObject;
                     transform.parent = null;
                     gameObject.layer = 31;
                     CapsuleCollider capsuleCollider = gameObject.AddComponent <CapsuleCollider>();
                     capsuleCollider.radius    = 0.5f;
                     capsuleCollider.height    = 4.5f;
                     capsuleCollider.direction = 0;
                     Rigidbody rigidbody = gameObject.AddComponent <Rigidbody>();
                     if (rigidbody)
                     {
                         rigidbody.AddForce((transform.position - data._position).normalized * 2f, ForceMode.Impulse);
                         rigidbody.AddRelativeTorque(Vector3.up * 2f, ForceMode.Impulse);
                     }
                     destroyAfter destroyAfter = gameObject.AddComponent <destroyAfter>();
                     destroyAfter.destroyTime = 1.75f;
                     this._collapsedLogs++;
                 }
                 if (LocalPlayer.Sfx)
                 {
                     LocalPlayer.Sfx.PlayStructureBreak(base.gameObject, 0.2f);
                 }
                 UnityEngine.Object.Destroy(tier.gameObject);
                 if (BoltNetwork.isServer)
                 {
                     this.PublishDestroyedTierData(this.LightWeightExport());
                 }
                 this.IntegrityCheck(num2, tier._tierNum);
             }
         }
         else
         {
             if (BoltNetwork.isServer && base.entity && base.entity.isAttached)
             {
                 this.CalcTotalRepairMaterial();
             }
             this.Distort(data);
         }
         if (!this._collapsing)
         {
             this.CheckSpawnRepairTrigger();
         }
         Prefabs.Instance.SpawnHitPS(HitParticles.Wood, data._position, Quaternion.LookRotation(tier.transform.right));
     }
 }
Ejemplo n.º 15
0
        private IEnumerator CollapseRoutine(Vector3 origin)
        {
            if (!this._collapsing)
            {
                this._collapsing = true;
                if (this._type == BuildingTypes.WorkBench || this._type == BuildingTypes.Chair || this._type == BuildingTypes.BoneChair)
                {
                    activateBench componentInChildren = base.transform.GetComponentInChildren <activateBench>();
                    if (componentInChildren)
                    {
                        componentInChildren.gameObject.SetActive(false);
                        if (componentInChildren.Sheen)
                        {
                            componentInChildren.Sheen.SetActive(false);
                        }
                        if (componentInChildren.MyPickUp)
                        {
                            componentInChildren.MyPickUp.SetActive(false);
                        }
                    }
                }
                if (BoltNetwork.isServer)
                {
                    yield return(YieldPresets.WaitPointOneSeconds);
                }
                if (this._type == BuildingTypes.WeaponRack)
                {
                    base.BroadcastMessage("OnBeginCollapse", SendMessageOptions.DontRequireReceiver);
                }
                else
                {
                    base.SendMessage("OnBeginCollapse", SendMessageOptions.DontRequireReceiver);
                }
                if ((this._type == BuildingTypes.HouseBoat || this._type == BuildingTypes.Raft || this._type == BuildingTypes.RaftEx) && LocalPlayer.Transform.IsChildOf(base.transform))
                {
                    RaftPush[] componentsInChildren = base.transform.GetComponentsInChildren <RaftPush>(true);
                    if (componentsInChildren.Length > 0)
                    {
                        foreach (RaftPush raftPush in componentsInChildren)
                        {
                            raftPush.SendMessage("offRaft");
                        }
                    }
                }
                for (int j = base.transform.childCount - 1; j >= 0; j--)
                {
                    LODGroup component = base.transform.GetChild(j).GetComponent <LODGroup>();
                    if (component)
                    {
                        LOD[] lods = component.GetLODs();
                        if (lods != null && (lods.Length > 1 & lods[1].renderers != null))
                        {
                            for (int k = 0; k < lods[1].renderers.Length; k++)
                            {
                                UnityEngine.Object.Destroy(lods[1].renderers[k].gameObject);
                            }
                        }
                        break;
                    }
                }
                Transform       renderersRoot = (!this._renderersRoot) ? base.transform : this._renderersRoot.transform;
                LOD_GroupToggle lgt           = (!renderersRoot.parent) ? null : renderersRoot.parent.GetComponent <LOD_GroupToggle>();
                if (lgt)
                {
                    lgt.ForceVisibility(0);
                    for (int l = lgt._levels.Length - 1; l > 0; l--)
                    {
                        foreach (Renderer renderer in lgt._levels[l].Renderers)
                        {
                            if (renderer)
                            {
                                renderer.transform.parent = null;
                                UnityEngine.Object.Destroy(renderer.gameObject);
                            }
                        }
                    }
                    UnityEngine.Object.Destroy(lgt);
                }
                if (!BoltNetwork.isClient)
                {
                    yield return(YieldPresets.WaitPointZeroFiveSeconds);

                    for (int n = base.transform.childCount - 1; n >= 0; n--)
                    {
                        Transform      child      = base.transform.GetChild(n);
                        BuildingHealth component2 = child.GetComponent <BuildingHealth>();
                        if (component2)
                        {
                            child.parent = null;
                            component2.Collapse(child.position);
                            Transform transform = child.Find("Trigger");
                            if (transform)
                            {
                                UnityEngine.Object.Destroy(transform.gameObject);
                            }
                        }
                        else
                        {
                            FoundationHealth component3 = child.GetComponent <FoundationHealth>();
                            if (component3)
                            {
                                child.parent = null;
                                component3.Collapse(child.position);
                            }
                            else if (BoltNetwork.isRunning && child.GetComponent <BoltEntity>())
                            {
                                child.parent = null;
                                destroyAfter destroyAfter = child.gameObject.AddComponent <destroyAfter>();
                                destroyAfter.destroyTime = 2.5f;
                                Transform transform2 = child.Find("Trigger");
                                if (transform2)
                                {
                                    UnityEngine.Object.Destroy(transform2.gameObject);
                                }
                            }
                        }
                        if (BoltNetwork.isRunning)
                        {
                            CoopAutoAttach component4 = child.GetComponent <CoopAutoAttach>();
                            if (component4)
                            {
                                UnityEngine.Object.Destroy(component4);
                            }
                        }
                    }
                }
                if (LocalPlayer.Sfx)
                {
                    LocalPlayer.Sfx.PlayStructureBreak(base.gameObject, this._maxHP / 2000f);
                }
                if (LocalPlayer.HitReactions != null)
                {
                    LocalPlayer.HitReactions.disableImpact(0.15f);
                }
                Renderer[] renderers = null;
                if (lgt && lgt._levels != null && lgt._levels.Length > 0)
                {
                    renderers = lgt._levels[0].Renderers;
                }
                if (renderers == null || renderers.Length == 0)
                {
                    renderers = ((!this._renderersRoot) ? base.GetComponentsInChildren <MeshRenderer>() : this._renderersRoot.GetComponentsInChildren <MeshRenderer>());
                }
                foreach (Renderer renderer2 in renderers)
                {
                    GameObject gameObject = renderer2.gameObject;
                    if (renderer2.enabled && gameObject.activeInHierarchy)
                    {
                        Transform transform3 = renderer2.transform;
                        if (!gameObject.GetComponent <Collider>())
                        {
                            MeshFilter component5 = renderer2.GetComponent <MeshFilter>();
                            if (!component5 || !component5.sharedMesh)
                            {
                                goto IL_7BB;
                            }
                            BoxCollider boxCollider = gameObject.AddComponent <BoxCollider>();
                            Bounds      bounds      = component5.sharedMesh.bounds;
                            boxCollider.size   = bounds.size * 0.9f;
                            boxCollider.center = bounds.center;
                        }
                        gameObject.layer  = this._detachedLayer;
                        transform3.parent = null;
                        Rigidbody rigidbody = gameObject.AddComponent <Rigidbody>();
                        if (rigidbody)
                        {
                            rigidbody.AddForce(((transform3.position - origin).normalized + Vector3.up) * (2.5f * this._destructionForceMultiplier), ForceMode.Impulse);
                            rigidbody.AddRelativeTorque(Vector3.up * (2f * this._destructionForceMultiplier), ForceMode.Impulse);
                            rigidbody.mass = 10f;
                        }
                        destroyAfter destroyAfter2 = gameObject.AddComponent <destroyAfter>();
                        if (this._type == BuildingTypes.WeaponRack)
                        {
                            destroyAfter2.destroyTime = 1.5f;
                        }
                        else
                        {
                            destroyAfter2.destroyTime = 5f;
                        }
                    }
                    IL_7BB :;
                }
                if (this._repairTrigger)
                {
                    UnityEngine.Object.Destroy(this._repairTrigger.gameObject);
                    this._repairTrigger = null;
                }
                this.SpawnCollapseDust();
                if (!BoltNetwork.isClient)
                {
                    if (!BoltNetwork.isRunning)
                    {
                        yield return(YieldPresets.WaitOneSecond);
                    }
                    else
                    {
                        yield return(YieldPresets.WaitTwoSeconds);
                    }
                    GameStats.DestroyedStructure.Invoke();
                    if (this._destroyTarget)
                    {
                        this._destroyTarget.transform.parent = null;
                        if (!BoltNetwork.isRunning)
                        {
                            UnityEngine.Object.Destroy(this._destroyTarget);
                        }
                        else
                        {
                            BoltNetwork.Destroy(this._destroyTarget);
                        }
                    }
                    else
                    {
                        base.transform.parent = null;
                        if (!BoltNetwork.isRunning)
                        {
                            UnityEngine.Object.Destroy(base.gameObject);
                        }
                        else
                        {
                            BoltNetwork.Destroy(base.gameObject);
                        }
                    }
                }
            }
            yield break;
        }