Esempio n. 1
0
 private void DistortRandom()
 {
     if (this._chunks.Length <= 0)
     {
         if (this._mpRandomDistortColliders != null && this._mpRandomDistortColliders.Length > 0)
         {
             Collider collider = this._mpRandomDistortColliders[UnityEngine.Random.Range(0, this._mpRandomDistortColliders.Length)];
             Vector3  vector   = default(Vector3);
             if (collider is BoxCollider)
             {
                 vector = BuildingHealth.GetPointInCollider(collider as BoxCollider);
             }
             if (collider is SphereCollider)
             {
                 vector = BuildingHealth.GetPointInCollider(collider as SphereCollider);
             }
             if (vector != Vector3.zero)
             {
                 LocalizedHitData data = default(LocalizedHitData);
                 float            num  = (1f - this.Hp / this._maxHP) / (float)base.state.BuildingHits;
                 data._damage       = num * this._maxHP;
                 data._position     = vector;
                 data._distortRatio = num * 50f;
                 this.DistortReal(data);
             }
         }
     }
 }
Esempio n. 2
0
 private bool ValidateCollider(Collider other)
 {
     if (Grabber.FocusedItem != other)
     {
         PrefabIdentifier componentInParent = other.GetComponentInParent <PrefabIdentifier>();
         if (componentInParent)
         {
             BuildingHealth component = componentInParent.GetComponent <BuildingHealth>();
             if (component && component.CanBeRepaired && (component.CalcMissingRepairMaterial() > 0 || component.CalcMissingRepairLogs() > 0) && LocalPlayer.Inventory.Logs.HasLogs == component.CalcMissingRepairLogs() > 0)
             {
                 return(!other.isTrigger);
             }
             FoundationHealth component2 = componentInParent.GetComponent <FoundationHealth>();
             if (component2 && component2.CanBeRepaired)
             {
                 bool flag  = component2.CalcMissingRepairMaterial() > 0;
                 bool flag2 = component2.CalcMissingRepairLogs() > 0;
                 if (!LocalPlayer.Inventory.Logs.HasLogs == flag || (LocalPlayer.Inventory.Logs.HasLogs && flag2))
                 {
                     return(!other.isTrigger);
                 }
             }
         }
     }
     return(LocalPlayer.Grabber.IsValid(other));
 }
Esempio n. 3
0
 private void Start()
 {
     if (!this._bh)
     {
         this._bh = base.transform.parent.GetComponentInParent <BuildingHealth>();
     }
 }
Esempio n. 4
0
 public bool CheckRepairStatus(BuildingHealth bh)
 {
     if (this.CalcMissingRepairMaterial() == 0 && this.CalcMissingRepairLogs() == 0)
     {
         if (this._foundation._mode == FoundationArchitect.Modes.Auto)
         {
             bh.Repair();
         }
         else
         {
             this.ResetHP();
             if (!BoltNetwork.isClient)
             {
                 if (LocalPlayer.Sfx)
                 {
                     LocalPlayer.Sfx.PlayTwinkle();
                 }
                 this.PublishDestroyedTierData(this.LightWeightExport());
                 this.RespawnFoundation(false);
             }
         }
         GameStats.RepairedStructure.Invoke();
         return(true);
     }
     return(false);
 }
Esempio n. 5
0
        public void LocalizedHit(LocalizedHitData data)
        {
            BuildingHealth buildingHealth = this.GetBuildingHealth();

            if (buildingHealth)
            {
                buildingHealth.LocalizedHit(data);
            }
        }
Esempio n. 6
0
        public void LocalizedHit(LocalizedHitData data)
        {
            PrefabIdentifier componentInParent = base.transform.GetComponentInParent <PrefabIdentifier>();

            if (componentInParent)
            {
                BuildingHealth component = componentInParent.GetComponent <BuildingHealth>();
                if (component)
                {
                    component.LocalizedHit(data);
                }
            }
        }
Esempio n. 7
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag(this._tag))
     {
         BuildingHealth componentInParent = base.transform.GetComponentInParent <BuildingHealth>();
         if (componentInParent)
         {
             componentInParent.LocalizedHit(new LocalizedHitData
             {
                 _position = other.transform.position,
                 _damage   = (float)this._damage
             });
         }
     }
 }
Esempio n. 8
0
        protected virtual IEnumerator OnTreeCutDown(GameObject trunk)
        {
            Transform fallingT;

            if (trunk.GetComponent <Rigidbody>())
            {
                fallingT = trunk.transform;
            }
            else
            {
                fallingT = trunk.GetComponentInChildren <Rigidbody>().transform;
            }
            base.transform.parent = fallingT;
            foreach (Collider collider in base.GetComponentsInChildren <Collider>())
            {
                collider.enabled = false;
            }
            if (!BoltNetwork.isClient)
            {
                yield return(YieldPresets.WaitPointHeightSeconds);
            }
            else
            {
                yield return(YieldPresets.WaitPointSixSeconds);
            }
            foreach (StructureAnchor structureAnchor in base.GetComponentsInChildren <StructureAnchor>())
            {
                UnityEngine.Object.Destroy(structureAnchor.gameObject);
            }
            Craft_Structure ghost = base.GetComponentInChildren <Craft_Structure>();

            if (ghost && ghost.transform.parent == base.transform)
            {
                if (!BoltNetwork.isClient)
                {
                    ghost.CancelBlueprintSafe();
                }
            }
            else
            {
                yield return(YieldPresets.WaitThreeSeconds);

                BuildingHealth bh = base.GetComponent <BuildingHealth>();
                bh.Collapse(base.transform.position + Vector3.down);
            }
            yield break;
        }
Esempio n. 9
0
        public void AddRepairMaterialReal(bool isLog)
        {
            if (isLog)
            {
                this.RepairLogs++;
            }
            else
            {
                this.RepairMaterial++;
            }
            BuildingHealth component = base.GetComponent <BuildingHealth>();

            if (!component || (component.CalcMissingRepairMaterial() == 0 && component.CalcMissingRepairLogs() == 0))
            {
                this.CheckRepairStatus(component);
            }
        }
Esempio n. 10
0
 public void CopyDamageFrom(BuildingHealth other)
 {
     if (other && other.Hp < other._maxHP)
     {
         this.DamageOnly(new LocalizedHitData
         {
             _damage = other._maxHP - other.Hp
         }, 0);
         if (BoltNetwork.isRunning && base.entity.isAttached && other.entity.isAttached)
         {
             base.state.BuildingHits = other.state.BuildingHits;
             if (base.state.BuildingHits > 0)
             {
                 this.DistortRandom();
             }
         }
     }
 }
Esempio n. 11
0
        private void OnGrabberEnter()
        {
            PrefabIdentifier componentInParent = Grabber.FocusedItemGO.GetComponentInParent <PrefabIdentifier>();

            if (componentInParent)
            {
                BuildingHealth   component  = componentInParent.GetComponent <BuildingHealth>();
                FoundationHealth component2 = componentInParent.GetComponent <FoundationHealth>();
                if ((component && component.CanBeRepaired && (component.CalcMissingRepairMaterial() > 0 || component.CalcMissingRepairLogs() > 0) && !LocalPlayer.Inventory.Logs.HasLogs) || (component2 && component2.CanBeRepaired && (!LocalPlayer.Inventory.Logs.HasLogs == component2.CalcMissingRepairMaterial() > 0 || (LocalPlayer.Inventory.Logs.HasLogs && component2.CalcMissingRepairLogs() > 0))))
                {
                    this._buildingTarget   = component;
                    this._foundationTarget = component2;
                    return;
                }
            }
            this.GrabExit();
            this._buildingTarget   = null;
            this._foundationTarget = null;
            LocalPlayer.Grabber.EnterMessage();
        }
Esempio n. 12
0
        public IEnumerator OnExplode(Explode.Data explodeData)
        {
            if (!this._exploding && !PlayerPreferences.NoDestruction)
            {
                this._exploding = true;
                if (!BoltNetwork.isClient)
                {
                    BuildingHealth component = base.GetComponent <BuildingHealth>();
                    if (component)
                    {
                        component.LocalizedHit(new LocalizedHitData
                        {
                            _damage       = explodeData.explode.damage * this.GetDamageRatio(explodeData.distance, explodeData.explode.radius),
                            _position     = explodeData.explode.transform.position,
                            _distortRatio = 1.35f
                        });
                    }
                }
                else
                {
                    FoundationHealth component2 = base.GetComponent <FoundationHealth>();
                    if (component2)
                    {
                        component2.Distort(new LocalizedHitData
                        {
                            _damage       = explodeData.explode.damage * this.GetDamageRatio(explodeData.distance, explodeData.explode.radius),
                            _position     = explodeData.explode.transform.position,
                            _distortRatio = 2.5f
                        });
                    }
                }
                yield return(null);

                this._exploding = false;
            }
            yield break;
        }
Esempio 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;
        }
Esempio n. 14
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;
        }