Beispiel #1
0
    public override void OnEvent(HitTree evnt)
    {
        if (!this.ValidateSender(evnt, SenderTypes.Any))
        {
            return;
        }
        CoopTreeId coopTreeId = CoopPlayerCallbacks.AllTrees.FirstOrDefault((CoopTreeId x) => x.Id == evnt.TreeId);

        if (coopTreeId)
        {
            TreeHealth currentView = coopTreeId.GetComponent <LOD_Trees>().CurrentView;
            if (currentView)
            {
                Transform transform = currentView.transform.Find(evnt.ChunkParent);
                if (transform)
                {
                    Transform transform2 = transform.Find("TreeDmg" + evnt.ChunkParent);
                    if (transform2)
                    {
                        transform2.SendMessage("ActivateFake", evnt.ChunkId);
                    }
                }
            }
        }
    }
Beispiel #2
0
 public override void Attached()
 {
     this.chunks = (from x in base.GetComponentsInChildren <TreeCutChunk>()
                    orderby int.Parse(x.transform.parent.gameObject.name)
                    select x).ToArray <TreeCutChunk>();
     base.state.AddCallback("TreeId", delegate
     {
         CoopTreeId coopTreeId = CoopPlayerCallbacks.AllTrees.FirstOrDefault((CoopTreeId x) => x.Id == base.state.TreeId);
         if (coopTreeId)
         {
             LOD_Trees component = coopTreeId.GetComponent <LOD_Trees>();
             if (component)
             {
                 component.enabled   = false;
                 component.DontSpawn = true;
                 if (component.CurrentView)
                 {
                     component.Pool.Despawn(component.CurrentView.transform);
                     component.CurrentView         = null;
                     component.CurrentLodTransform = null;
                 }
             }
         }
     });
     base.state.AddCallback("Damage", delegate
     {
         if (base.entity.isOwner && base.state.Damage == 16f)
         {
             base.entity.DestroyDelayed(10f);
             BoltEntity boltEntity = BoltNetwork.Instantiate(this.CoopTree.NetworkFallPrefab, base.entity.transform.position, base.entity.transform.rotation);
             boltEntity.GetState <ITreeFallState>().CutTree = base.entity;
             boltEntity.GetComponent <Rigidbody>().AddForce(new Vector3(UnityEngine.Random.value * 0.01f, 0f, UnityEngine.Random.value * 0.01f), ForceMode.VelocityChange);
         }
     });
 }
Beispiel #3
0
    public override void OnEvent(SpawnCutTree evnt)
    {
        CoopTreeId coopTreeId = CoopPlayerCallbacks.AllTrees.FirstOrDefault((CoopTreeId x) => x.Id == evnt.TreeId);

        if (coopTreeId && coopTreeId.state.State == 0)
        {
            coopTreeId.state.State = 1;
            coopTreeId.entity.Freeze(false);
        }
    }
Beispiel #4
0
    private void lookAtExplosion(Vector3 position)
    {
        Vector3 b = new Vector3(1f, 0f, 1f);

        if (!this._idleIfPresent && Vector3.Distance(Vector3.Scale(position, b), Vector3.Scale(base.transform.position, b)) < 3.5f)
        {
            if (LocalPlayer.Sfx)
            {
                LocalPlayer.Sfx.PlayBreakWood(base.gameObject);
            }
            LOD_Stump componentInParent = base.GetComponentInParent <LOD_Stump>();
            LOD_Trees lod_Trees         = (!componentInParent) ? base.GetComponentInParent <LOD_Trees>() : componentInParent.transform.parent.GetComponent <LOD_Trees>();
            if (lod_Trees)
            {
                if (componentInParent && componentInParent.Pool.IsSpawned(base.transform))
                {
                    base.transform.parent = componentInParent.Pool.transform;
                    componentInParent.Pool.Despawn(base.transform);
                }
                if (!BoltNetwork.isRunning)
                {
                    this.Finalize(lod_Trees, (!componentInParent) ? base.gameObject : componentInParent.gameObject);
                }
                else
                {
                    RemoveStump removeStump = RemoveStump.Create(GlobalTargets.OnlyServer);
                    removeStump.TargetTree = lod_Trees.GetComponent <BoltEntity>();
                    if (this._blownUpStump)
                    {
                        removeStump.Position           = base.transform.position;
                        removeStump.Rotation           = base.transform.rotation;
                        removeStump.CutUpStumpPrefabId = this._blownUpStump.GetComponent <BoltEntity>().prefabId;
                    }
                    removeStump.Send();
                    this.Finalize((!BoltNetwork.isServer) ? null : lod_Trees, (!componentInParent) ? base.gameObject : componentInParent.gameObject);
                }
            }
            else
            {
                TreeHealth componentInParent2 = base.GetComponentInParent <TreeHealth>();
                if (componentInParent2 && componentInParent2.LodTree)
                {
                    if (BoltNetwork.isRunning)
                    {
                        CoopTreeId component = componentInParent2.LodTree.GetComponent <CoopTreeId>();
                        if (component)
                        {
                            component.Goto_Removed();
                        }
                    }
                    this.Finalize(componentInParent2.LodTree, componentInParent2.gameObject);
                }
            }
        }
    }
Beispiel #5
0
    public void Start()
    {
        int stepCount = this.GetStepCount();

        LOD_Base[]      array    = UnityEngine.Object.FindObjectsOfType <LOD_Base>();
        List <LOD_Base> list     = new List <LOD_Base>();
        Vector3         position = base.transform.position;
        float           num      = this.Radius + this.Length;

        num *= num;
        float num2 = this.Radius * this.Radius;

        LOD_Base[] array2 = array;
        for (int i = 0; i < array2.Length; i++)
        {
            LOD_Base lOD_Base = array2[i];
            if ((lOD_Base.transform.position - position).sqrMagnitude < num)
            {
                list.Add(lOD_Base);
            }
        }
        for (int j = 0; j < stepCount; j++)
        {
            float   progress  = (float)j / (float)stepCount;
            Vector3 position2 = this.GetPosition(progress);
            foreach (LOD_Base current in list)
            {
                if ((current.transform.position - position2).sqrMagnitude < num2)
                {
                    CoopTreeId coopTreeId = null;
                    if (BoltNetwork.isServer)
                    {
                        coopTreeId = current.GetComponent <CoopTreeId>();
                    }
                    UnityEngine.Object.Destroy(current);
                    if (coopTreeId)
                    {
                        coopTreeId.Goto_Removed();
                    }
                }
            }
            if (this.ShouldCutGrass)
            {
                NeoGrassCutter.Cut(position2, this.Radius, false);
            }
        }
    }
Beispiel #6
0
    public void startClearing()
    {
        int stepCount = this.GetStepCount();

        LOD_Base[]      array    = UnityEngine.Object.FindObjectsOfType <LOD_Base>();
        List <LOD_Base> list     = new List <LOD_Base>();
        Vector3         position = base.transform.position;
        float           num      = this.Radius + this.Length;

        num *= num;
        float num2 = this.Radius * this.Radius;

        foreach (LOD_Base lod_Base in array)
        {
            if (!(lod_Base is LOD_Rocks) && (lod_Base.transform.position - position).sqrMagnitude < num)
            {
                list.Add(lod_Base);
            }
        }
        for (int j = 0; j < stepCount; j++)
        {
            float   progress  = (float)j / (float)stepCount;
            Vector3 position2 = this.GetPosition(progress);
            foreach (LOD_Base lod_Base2 in list)
            {
                if ((lod_Base2.transform.position - position2).sqrMagnitude < num2)
                {
                    CoopTreeId coopTreeId = null;
                    if (BoltNetwork.isServer)
                    {
                        coopTreeId = lod_Base2.GetComponent <CoopTreeId>();
                    }
                    Debug.Log(lod_Base2 + " CLEARED");
                    UnityEngine.Object.DestroyImmediate(lod_Base2);
                    if (coopTreeId)
                    {
                        coopTreeId.Goto_Removed();
                    }
                }
            }
            if (this.ShouldCutGrass)
            {
                NeoGrassCutter.Cut(position2, this.Radius, false);
            }
        }
    }
Beispiel #7
0
        public override IEnumerator OnDeserialized()
        {
            if (BoltNetwork.isRunning)
            {
                while (!base.entity.isAttached)
                {
                    yield return(null);
                }
            }
            if (!BoltNetwork.isRunning || base.entity.isAttached)
            {
                yield return(null);

                if (this._treeId >= 0)
                {
                    CoopTreeId tid = CoopPlayerCallbacks.AllTrees.FirstOrDefault((CoopTreeId i) => i.Id == this.$this._treeId);
                    if (!tid)
                    {
                        yield return(YieldPresets.WaitThreeSeconds);

                        tid = CoopPlayerCallbacks.AllTrees.FirstOrDefault((CoopTreeId i) => i.Id == this.$this._treeId);
                    }
                    if (tid)
                    {
                        LOD_Trees component = tid.GetComponent <LOD_Trees>();
                        component.AddTreeCutDownTarget(base.gameObject);
                    }
                }
                if (this._treeId2 >= 0)
                {
                    CoopTreeId tid2 = CoopPlayerCallbacks.AllTrees.FirstOrDefault((CoopTreeId i) => i.Id == this.$this._treeId2);
                    if (!tid2)
                    {
                        yield return(YieldPresets.WaitThreeSeconds);

                        tid2 = CoopPlayerCallbacks.AllTrees.FirstOrDefault((CoopTreeId i) => i.Id == this.$this._treeId2);
                    }
                    if (tid2)
                    {
                        LOD_Trees component2 = tid2.GetComponent <LOD_Trees>();
                        component2.AddTreeCutDownTarget(base.gameObject);
                    }
                }
            }
            yield break;
        }
Beispiel #8
0
    private void lookAtExplosion(Vector3 position)
    {
        Vector3 b = new Vector3(1f, 0f, 1f);

        if (!this._idleIfPresent && !BoltNetwork.isClient && Vector3.Distance(Vector3.Scale(position, b), Vector3.Scale(base.transform.position, b)) < 3.5f)
        {
            LocalPlayer.Sfx.PlayBreakWood(base.gameObject);
            LOD_Stump componentInParent = base.GetComponentInParent <LOD_Stump>();
            if (componentInParent)
            {
                LOD_Trees component = componentInParent.transform.parent.GetComponent <LOD_Trees>();
                if (component.Pool.IsSpawned(base.transform))
                {
                    base.transform.parent = component.Pool.transform;
                    component.Pool.Despawn(base.transform);
                }
                if (BoltNetwork.isRunning)
                {
                    CoopTreeId component2 = component.GetComponent <CoopTreeId>();
                    if (component2)
                    {
                        component2.Goto_Removed();
                    }
                }
                this.Finalize(component, componentInParent.gameObject);
            }
            else
            {
                TreeHealth componentInParent2 = base.GetComponentInParent <TreeHealth>();
                if (componentInParent2 && componentInParent2.LodTree)
                {
                    if (BoltNetwork.isRunning)
                    {
                        CoopTreeId component3 = componentInParent2.LodTree.GetComponent <CoopTreeId>();
                        if (component3)
                        {
                            component3.Goto_Removed();
                        }
                    }
                    this.Finalize(componentInParent2.LodTree, componentInParent2.gameObject);
                }
            }
        }
    }
Beispiel #9
0
 private void LocalizedHit(LocalizedHitData data)
 {
     if (!this._idleIfPresent)
     {
         if (BoltNetwork.isRunning)
         {
             CoopTreeId coopTreeId = base.GetComponentInParent <CoopTreeId>();
             if (!coopTreeId)
             {
                 TreeHealth componentInParent = base.GetComponentInParent <TreeHealth>();
                 if (componentInParent && componentInParent.LodTree)
                 {
                     coopTreeId = componentInParent.LodTree.GetComponent <CoopTreeId>();
                 }
             }
             if (coopTreeId && coopTreeId.state.State != 3)
             {
                 return;
             }
         }
         else if (this._tree)
         {
             if (this._tree.Health > 0)
             {
                 return;
             }
         }
         else if (this._coolDown != 0f)
         {
             return;
         }
         Prefabs.Instance.SpawnHitPS(HitParticles.Wood, data._position, Quaternion.LookRotation(base.transform.position - data._position));
         if (this._hp > 0f)
         {
             this._hp -= data._damage;
             if (this._hp <= 0f)
             {
                 this.lookAtExplosion(base.transform.position);
             }
         }
     }
 }
Beispiel #10
0
 private void OnDestroy()
 {
     if (this._tsl)
     {
         UnityEngine.Object.Destroy(this._tsl);
         this._tsl = null;
     }
     if (CoopPlayerCallbacks.AllTrees != null)
     {
         CoopTreeId coopTreeId = CoopPlayerCallbacks.AllTrees.FirstOrDefault((CoopTreeId i) => i.Id == this._treeId);
         if (coopTreeId)
         {
             LOD_Trees component = coopTreeId.GetComponent <LOD_Trees>();
             if (component)
             {
                 component.RemoveTreeCutDownTarget(base.gameObject);
             }
         }
     }
 }
Beispiel #11
0
 private void Burnt(GameObject trunk)
 {
     if (!BoltNetwork.isClient)
     {
         TreeHealth.OnTreeCutDown.Invoke(base.transform.position);
         EventRegistry.Player.Publish(TfEvent.CutTree, this);
         if (this.LodTree != null)
         {
             this.LodTree.SendMessageToTargets("OnTreeCutDown", trunk);
             if (BoltNetwork.isRunning)
             {
                 CoopTreeId component = this.LodTree.GetComponent <CoopTreeId>();
                 if (component)
                 {
                     component.Goto_Removed();
                 }
             }
             UnityEngine.Object.Destroy(this.LodTree);
         }
     }
 }
Beispiel #12
0
        public virtual IEnumerator OnDeserialized()
        {
            if (BoltNetwork.isRunning)
            {
                while (!base.entity.isAttached)
                {
                    yield return(null);
                }
            }
            if (this._treeId >= 0 && !this._tsl && (!BoltNetwork.isRunning || base.entity.isAttached))
            {
                yield return(null);

                if (!this._tsl)
                {
                    if (BoltNetwork.isRunning && base.entity.isAttached && base.entity.isOwner && base.entity.StateIs <ITreeHouseState>())
                    {
                        base.entity.GetState <ITreeHouseState>().TreeId = this._treeId;
                    }
                    CoopTreeId tid = CoopPlayerCallbacks.AllTrees.FirstOrDefault((CoopTreeId i) => i.Id == this.$this._treeId);
                    if (!tid)
                    {
                        yield return(YieldPresets.WaitThreeSeconds);

                        tid = CoopPlayerCallbacks.AllTrees.FirstOrDefault((CoopTreeId i) => i.Id == this.$this._treeId);
                    }
                    if (tid && !this._tsl)
                    {
                        LOD_Trees component = tid.GetComponent <LOD_Trees>();
                        component.AddTreeCutDownTarget(base.gameObject);
                        if (this._cutLeaves)
                        {
                            this._tsl      = component.gameObject.AddComponent <TreeStructureLod>();
                            this._tsl._lod = component;
                        }
                    }
                }
            }
            yield break;
        }
Beispiel #13
0
 private void Burnt(GameObject trunk)
 {
     if (!BoltNetwork.isClient)
     {
         TreeHealth.OnTreeCutDown.Invoke(base.transform.position);
         GameStats.TreeCutDown.Invoke();
         if (this.LodTree != null)
         {
             if (this.LodTree.OnTreeCutDownTarget != null)
             {
                 this.LodTree.OnTreeCutDownTarget.SendMessage("OnTreeCutDown", trunk);
             }
             if (BoltNetwork.isRunning)
             {
                 CoopTreeId component = this.LodTree.GetComponent <CoopTreeId>();
                 if (component)
                 {
                     component.Goto_Removed();
                 }
             }
             UnityEngine.Object.Destroy(this.LodTree);
         }
     }
 }
Beispiel #14
0
 public static void CheckRegrowTrees()
 {
     if (PlayerPreferences.TreeRegrowth)
     {
         LOD_Trees[]      source = UnityEngine.Object.FindObjectsOfType <LOD_Trees>();
         List <LOD_Trees> list   = (from t in source
                                    where !t.enabled && t.CurrentView == null
                                    select t).ToList <LOD_Trees>();
         if (list != null && list.Count > 0)
         {
             TreeLodGrid treeLodGrid = UnityEngine.Object.FindObjectOfType <TreeLodGrid>();
             int         count       = list.Count;
             int         num         = count / 10 + 2;
             float       num2        = Mathf.Max((float)count / (float)num, 1f);
             int         num3        = 0;
             for (float num4 = 0f; num4 < (float)count; num4 += num2)
             {
                 int index = (int)num4;
                 if (BoltNetwork.isRunning)
                 {
                     CoopTreeId component = list[index].GetComponent <CoopTreeId>();
                     if (component)
                     {
                         component.RegrowTree();
                     }
                     list[index].DontSpawn = false;
                 }
                 list[index].enabled = true;
                 list[index].RefreshLODs();
                 if (treeLodGrid)
                 {
                     treeLodGrid.RegisterTreeRegrowth(list[index].transform.position);
                 }
                 IEnumerator enumerator = list[index].transform.GetEnumerator();
                 try
                 {
                     while (enumerator.MoveNext())
                     {
                         object    obj        = enumerator.Current;
                         Transform transform  = (Transform)obj;
                         LOD_Stump component2 = transform.GetComponent <LOD_Stump>();
                         if (component2)
                         {
                             component2.DespawnCurrent();
                             component2.CurrentView = null;
                         }
                         UnityEngine.Object.Destroy(transform.gameObject);
                     }
                 }
                 finally
                 {
                     IDisposable disposable;
                     if ((disposable = (enumerator as IDisposable)) != null)
                     {
                         disposable.Dispose();
                     }
                 }
                 num3++;
             }
             if (num3 != 0 && BoltNetwork.isRunning)
             {
                 CoopTreeGrid.SweepGrid();
             }
             Debug.Log(string.Concat(new object[]
             {
                 "Tree regrowth: ",
                 num3,
                 "/",
                 count
             }));
         }
     }
 }