Пример #1
0
 private void Hit(int damage)
 {
     if (!this.IsHit)
     {
         this.IsHit   = true;
         this.health -= damage;
         if (this.health > 0)
         {
             this.IsHit = false;
             return;
         }
         if (BoltNetwork.isRunning && this.entity)
         {
             DestroyBuilding destroyBuilding = DestroyBuilding.Raise(GlobalTargets.OnlyServer);
             destroyBuilding.BuildingEntity = this.entity;
             destroyBuilding.Send();
             UnityEngine.Object.Instantiate(Resources.Load("WallBuiltDynamic_MP", typeof(GameObject)), base.transform.position, base.transform.rotation);
             return;
         }
         UnityEngine.Object.Instantiate(this.dynamicWall, base.transform.position, base.transform.rotation);
         if (this.dust)
         {
             UnityEngine.Object.Instantiate(this.dust, base.transform.position, base.transform.rotation);
         }
         if (this.destroyGo != null)
         {
             UnityEngine.Object.Destroy(this.destroyGo);
         }
         else
         {
             UnityEngine.Object.Destroy(base.gameObject);
         }
     }
 }
Пример #2
0
        void Update()
        {
            if (!Initialized)
            {
                Initialize();
            }

            if (!CheatMenuPlusCtrl.Options.Player.InstantDestroy)
            {
                return;
            }

            if (camera == null)
            {
                camera = TheForest.Utils.LocalPlayer.MainCam;
            }

            if (camera != null)
            {
                try
                {
                    Ray          r    = new Ray(camera.transform.position + camera.transform.forward * 1f, camera.transform.forward);
                    RaycastHit[] hits = Physics.RaycastAll(r, 5f);
                    if (hits.Length == 0)
                    {
                        removeCloneTexture.gameObject.SetActive(false);
                    }

                    foreach (RaycastHit hitInfo in hits)
                    {
                        Transform  t     = hitInfo.collider.transform;
                        BoltEntity ent   = null;
                        bool       found = false;

                        if (BoltNetwork.isRunning)
                        {
                            ent = t.GetComponentInParent <BoltEntity>();
                            if (ent == null || !ent.StateIs <IBuildingState>())
                            {
                                t = null;
                            }
                            else
                            {
                                found = true;
                            }
                        }
                        else
                        {
                            while (!found)
                            {
                                if (t == null)
                                {
                                    break;
                                }
                                foreach (string n in buildingNames)
                                {
                                    if (t.name.StartsWith(n))
                                    {
                                        found = true;
                                        break;
                                    }
                                }
                                if (found)
                                {
                                    break;
                                }
                                t = t.parent;
                            }
                        }

                        if (found)
                        {
                            ShowRemoveIcon = true;
                            removeCloneTexture.gameObject.SetActive(true);
                            if (ModAPI.Input.GetButtonDown("RemoveBuilding"))
                            {
                                if (BoltNetwork.isRunning)
                                {
                                    if (ent != null)
                                    {
                                        DestroyBuilding building = DestroyBuilding.Create(Bolt.GlobalTargets.OnlyServer);
                                        //DestroyBuilding building = DestroyBuilding.Raise(Bolt.GlobalTargets.OnlyServer);
                                        building.BuildingEntity = ent;
                                        building.Send();
                                    }
                                }
                                else
                                {
                                    Destroy(t.gameObject);
                                }
                                return;
                            }
                            break;
                        }
                        else
                        {
                            ShowRemoveIcon = false;
                            removeCloneTexture.gameObject.SetActive(false);
                        }
                    }
                }
                catch (Exception e)
                {
                    ModAPI.Log.Write(e.ToString());
                }
            }
        }