Exemplo n.º 1
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));
 }
Exemplo n.º 2
0
        public void OnExplodeFoundationTier(Explode.Data explodeData, FoundationChunkTier tier)
        {
            FoundationHealth component = base.GetComponent <FoundationHealth>();

            if (component)
            {
                component.LocalizedTierHit(new LocalizedHitData
                {
                    _damage       = explodeData.explode.damage * this.GetDamageRatio(explodeData.distance, explodeData.explode.radius),
                    _position     = explodeData.explode.transform.position,
                    _distortRatio = 2.5f
                }, tier);
            }
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
 public void AddRepairMaterialReal(bool isLog)
 {
     if (isLog)
     {
         this._repairLogs++;
     }
     else
     {
         this.RepairMaterialActual++;
     }
     if (this.CalcMissingRepairMaterial() == 0 && this.CalcMissingRepairLogs() == 0)
     {
         FoundationHealth component = base.GetComponent <FoundationHealth>();
         if (!component)
         {
             this.Repair();
         }
         else
         {
             component.CheckRepairStatus(this);
         }
     }
 }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
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;
        }
Exemplo n.º 8
0
 private void Start()
 {
     this._owner = base.transform.GetComponentInParent <FoundationHealth>();
 }