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

FREE FProtection : 1.0.0 1.0.0

Нет прав для скачивания
C#:
using Oxide.Core.Plugins;
using UnityEngine;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Game.Rust.Cui;
using System;
using Oxide.Core;
using Newtonsoft.Json.Linq;
using System.Globalization;

namespace Oxide.Plugins
{
    [Info("FProtection", "King", "1.0.0")]
    class FProtection : RustPlugin
	{ 
        #region [Vars]
        bool _time;
        float damage;
        TimeSpan On, Off;
        #endregion

        #region [Config]
        private PluginConfig config;

        protected override void LoadDefaultConfig()
        {
            config = PluginConfig.DefaultConfig();
        }

        protected override void LoadConfig()
        {
            base.LoadConfig();
            config = Config.ReadObject<PluginConfig>();

            if (config.PluginVersion < Version)
                UpdateConfigValues();

            Config.WriteObject(config, true);
        }

        private void UpdateConfigValues()
        {
            PluginConfig baseConfig = PluginConfig.DefaultConfig();
            if (config.PluginVersion < Version)
            {
                config.PluginVersion = Version;
                if (Version == new VersionNumber(1, 0, 0))
                {
                    //
                }

                PrintWarning("Config checked completed!");
            }
            config.PluginVersion = Version;
        }

        protected override void SaveConfig()
        {
            Config.WriteObject(config);
        }

        public class ProtectSettings
        {
			[JsonProperty("Начало защиты | Часы")]
            public int HourStart;

			[JsonProperty("Начало защиты | Минуты")]
            public int MinuteStart;

			[JsonProperty("Конец защиты | Часы")]
            public int HourEnd;

			[JsonProperty("Конец защиты | Минуты")]
            public int MinuteEnd;

            [JsonProperty("Процент защиты. 1.0 - 100%")]
            public float Damage;
        }

        public class MainSettings
        {
            [JsonProperty("Раз в сколько секунд проверять активность защиты ( Секунды )")] 
            public int Timer;

            [JsonProperty("Часовой пояс - UTC+0:00")] 
            public int GMT;

            [JsonProperty("Разрешить ломать солому во время защиты")] 
            public bool Twigs;
        }

        private class PluginConfig
        {
            [JsonProperty("Основные настройки")]
            public MainSettings _MainSettings = new MainSettings();

            [JsonProperty("Настройки защиты")]
            public List<ProtectSettings> _ProtectSettings = new List<ProtectSettings>();

			[JsonProperty("Время")]
			public DateTime MSCTime;

            [JsonProperty("Config version")]
            public VersionNumber PluginVersion = new VersionNumber();

            public static PluginConfig DefaultConfig()
            {
                return new PluginConfig()
                {
                    _MainSettings = new MainSettings
                    {
                        Timer = 120,
                        GMT = 3,
                        Twigs = true,
                    }, 
                    _ProtectSettings = new List<ProtectSettings>()
                    {
                        new ProtectSettings()
                        {
                            HourStart = 22,
                            MinuteStart = 0,
                            HourEnd = 23,
                            MinuteEnd = 0,
                            Damage = 0.5f,
                        },
                        new ProtectSettings()
                        {
                            HourStart = 23,
                            MinuteStart = 0,
                            HourEnd = 12,
                            MinuteEnd = 0,
                            Damage = 1f,
                        },
                    },
                    PluginVersion = new VersionNumber()
                };
            }
        }
        #endregion

        #region [Oxide]

		private void OnServerInitialized()
		{
			MSC();
			timer.Every(config._MainSettings.Timer, () => MSC());
		}

        #endregion

        #region [Rust-Api]

		private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
		{
			if (entity == null || info?.InitiatorPlayer == null) return;
			
			Protection(entity, info);
		}

        #endregion

        #region [Func]

		private void MSC()
		{
			webrequest.Enqueue("http://worldtimeapi.org/api/timezone/Europe/London", null, (code, response) =>
            {
                if (code != 200 || response == null) return;
				
			    config.MSCTime = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(double.Parse(JsonConvert.DeserializeObject<JObject>(response)["unixtime"].ToString()) + (config._MainSettings.GMT * 3600));
			    SaveConfig();
				
				timer.Once(3, () => _time = Time());
            }, this);
		}

		private bool Time()
		{
            bool succes = false;
            foreach (var check in config._ProtectSettings)
            {
                if (succes) break;
                var Now = config.MSCTime.TimeOfDay;

			    On = new TimeSpan(check.HourStart, check.MinuteStart, 0);
			    Off = new TimeSpan(check.HourEnd, check.MinuteEnd, 0);

                if (On < Off)
                {
                    succes = On <= Now && Now <= Off;
                    if (succes)
                    {
                        if (damage != check.Damage)
                        {
                            damage = check.Damage;
                            Server.Broadcast($"Защита строений изменена, дополнительное сопротивление урону <color=#9ACD32>{damage * 100}%</color>");
                        }
                        continue;
                    }
                }
                else if (!(Off < Now && Now < On))
                {
                    succes = !(Off < Now && Now < On);
                    if (succes)
                    {
                        if (damage != check.Damage)
                        {
                            damage = check.Damage;
                            Server.Broadcast($"Защита строений изменена, дополнительное сопротивление урону <color=#9ACD32>{damage * 100}%</color>");
                        }
                        continue;
                    }
                }
            }
            if (succes == false)
            {
                if (damage != 0f)
                {
                    damage = 0f;
                    Server.Broadcast($"Защита строений изменена, дополнительное сопротивление урону <color=#9ACD32>{damage * 100}%</color>");
                }
            }
            return succes;
		}

		private void Protection(BaseCombatEntity entity, HitInfo info)
		{
			if (_time)
			{
				BasePlayer player = info.InitiatorPlayer;
				bool ent = entity is BuildingBlock;
				
				if(config._MainSettings.Twigs && ent)
					if((entity as BuildingBlock).grade == BuildingGrade.Enum.Twigs)
						return;
				
		        if (ent || entity is Door || entity is SimpleBuildingBlock)
			    {
					var dm = info.damageTypes.Total();
					
					info.damageTypes.ScaleAll(1.0f - damage);
			    }
			}
		}

        #endregion

        #region [ChatCommand]

        [ChatCommand("bps")]
        private void cmd_ShowTop(BasePlayer player, string command, string[] args)
        {
            string text = $"Защита строений изменена, дополнительное сопротивление урону <color=#9ACD32>{damage * 100}%</color>";

            player.ChatMessage(text);
        }

        #endregion
    }
}

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