Пример #1
0
 public static void Execute()
 {
     if (BoltNetwork.isRunning)
     {
         foreach (var entity in BoltNetwork.entities.Where(entity => entity.isAttached))
         {
             try
             {
                 if (entity.GetComponentInChildren <Craft_Structure>())
                 {
                     // Cancel blueprints
                     var cancelBlueprint = CancelBluePrint.Create(GlobalTargets.OnlyServer);
                     cancelBlueprint.BluePrint = entity;
                     PacketQueue.Add(cancelBlueprint);
                 }
                 else if (entity.StateIs <IBuildingDestructibleState>())
                 {
                     // Destroy building
                     var destroyBuilding = DestroyBuilding.Create(GlobalTargets.OnlyServer);
                     destroyBuilding.BuildingEntity = entity;
                     PacketQueue.Add(destroyBuilding);
                 }
                 else if (entity.gameObject.GetComponentInChildren <BuildingHealthHitRelay>() ||
                          entity.gameObject.GetComponentInChildren <BuildingHealthChunkHitRelay>() ||
                          entity.gameObject.GetComponentInChildren <FoundationChunkTier>() ||
                          entity.gameObject.GetComponentInChildren <BuildingHealth>())
                 {
                     entity.gameObject.SendMessage("LocalizedHit", new LocalizedHitData(entity.gameObject.transform.position, 10000f));
                 }
             }
             catch (Exception)
             {
                 // ignored
             }
         }
     }
 }
Пример #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());
                }
            }
        }