Пример #1
0
        private void MakeRepair(IRepairableStructure structure)
        {
            try
            {
                int missingMaterials = structure.CalcTotalRepairMaterial() - structure.RepairMaterial;
                int missingLogs      = structure.CalcMissingRepairLogs() - structure.RepairLogs;

                if (missingMaterials > 0)
                {
                    for (int i = 0; i < missingMaterials; i++)
                    {
                        structure.AddRepairMaterial(false);
                    }
                }
                if (missingLogs > 0)
                {
                    for (int i = 0; i < missingLogs; i++)
                    {
                        structure.AddRepairMaterial(true);
                    }
                }
            }
            catch
            { }
        }
Пример #2
0
        private void Update()
        {
            if (Menu.InstantBuild && LocalPlayer.IsInWorld && TheForest.Utils.Input.GetKey(KeyCode.E))
            {
                if (!IsLastPressed)
                {
                    Craft_Structure[] array = FindObjectsOfType <Craft_Structure>();
                    foreach (Craft_Structure structure in array)
                    {
                        if (Vector3.Distance(LocalPlayer.Transform.position, structure.transform.position) >
                            Menu.AutoCompleteDistance)
                        {
                            continue;
                        }

                        MakeComplete(structure);
                    }

                    /*
                     * foreach (RaycastHit hit in Physics.RaycastAll(LocalPlayer.Transform.position,
                     *      LocalPlayer.Transform.TransformDirection(Vector3.forward), Menu.CutTreeDistance))
                     * {
                     *      if (hit.collider.GetComponent<BuildingRepair>() != null)
                     *      {
                     *              MakeRepair(hit.collider.GetComponent<BuildingRepair>());
                     *              break;
                     *      }
                     * }
                     */

                    foreach (Collider hit in Physics.OverlapSphere(
                                 LocalPlayer.MainCam.transform.position, Menu.AutoCompleteDistance))
                    {
                        BoltEntity entity = hit.GetComponent <BoltEntity>();
                        if (entity != null && entity.isAttached && entity.StateIs <IRepairableStructure>())
                        {
                            IRepairableStructure structure = entity.GetState <IRepairableStructure>();
                            if (structure != null)
                            {
                                //Logger.Info("Got repairable structure!");
                                MakeRepair(structure);
                            }
                        }
                    }

                    IsLastPressed = true;
                }
            }
            else
            {
                IsLastPressed = false;
            }
        }