Иконка ресурса

FREE ConstantTurbine : 1.0.2 1.0.2

Нет прав для скачивания
C#:
using System;
using System.Collections.Generic;
using Oxide.Core.Libraries.Covalence;
using Newtonsoft.Json;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("Constant Turbine", "Beast_", "1.0.2")]
    [Description("Overrides wind turbine output to be constant regardless of height or wind.")]
    public class ConstantTurbine : RustPlugin
    {
        #region Fields
        private Configuration config;
        private const string PERMS = "constantturbine.use";
        #endregion

        #region Configuration
        private class Configuration
        {
            [JsonProperty("Constant Output Power")]
            public int powerOutput = 100;

            [JsonProperty("Force Max Height Simulation")]
            public bool simulateHeight = false;

            public string ToJson() => JsonConvert.SerializeObject(this);
            public Dictionary<string, object> ToDictionary() => JsonConvert.DeserializeObject<Dictionary<string, object>>(ToJson());
        }

        protected override void LoadDefaultConfig() => config = new Configuration();

        protected override void LoadConfig()
        {
            base.LoadConfig();
            try
            {
                config = Config.ReadObject<Configuration>();
                if (config == null) throw new JsonException();

                SaveConfig();
            }
            catch
            {
                PrintWarning($"Configuration file {Name}.json is invalid; using defaults");
                LoadDefaultConfig();
            }
        }

        protected override void SaveConfig() => Config.WriteObject(config);
        #endregion

        #region Hooks
        private void Init() => permission.RegisterPermission(PERMS, this);

        private void OnWindmillUpdated(ElectricWindmill windmill)
        {
            if (windmill == null || windmill.IsDestroyed) return;

            IPlayer owner = covalence.Players.FindPlayerById(windmill.OwnerID.ToString());
            if (owner == null || !permission.UserHasPermission(owner.Id, PERMS)) return;

            if (config.simulateHeight)
            {
                int simulatedOutput = SimulateMaxHeight(windmill);
                if (windmill.currentEnergy != simulatedOutput)
                {
                    windmill.currentEnergy = simulatedOutput;
                    windmill.MarkDirty();
                    windmill.SendNetworkUpdate();
                }
            }
            else
            {
                if (windmill.currentEnergy != config.powerOutput)
                {
                    windmill.currentEnergy = config.powerOutput;
                    windmill.MarkDirty();
                    windmill.SendNetworkUpdate();
                }
            }
        }
        #endregion

        #region Helper
        private int SimulateMaxHeight(ElectricWindmill windmill)
        {
            float t = Time.time / 600f;
            float perlin = Mathf.PerlinNoise(t, t * 0.1f);
            float simulatedHeight = 100f;

            float heightFactor = Mathf.InverseLerp(0f, 50f, simulatedHeight) * 0.5f;
            float windScale = Mathf.Clamp01(heightFactor + perlin);

            return Mathf.FloorToInt(windScale * windmill.maxPowerGeneration);
        }
        #endregion
    }
}

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху