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

FREE GemsSystem : 1.0.0 1.0.0

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

namespace Oxide.Plugins
{
    [Info("GemsSystem", "https://Topplugins.Ru", "1.0.0")]
    internal class GemsSystem : RustPlugin
    {
        #region Static

        private static GemsSystem _ins;
        private Configuration _config;

        #endregion

        #region Config

        private class Configuration
        {
            [JsonProperty("ShortName предмета")] public string ShortName = "halloween.lootbag.small";
            
            [JsonProperty(PropertyName = "Список самоцветов", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<ulong, ArtefactType> GemsList = new Dictionary<ulong, ArtefactType>()
            {
                [12354635] = new ArtefactType()
                {
                    DamageScale = 1.1f,
                    GatheringMultiply = 1,
                    HealthPercent = 0
                },
                [123] = new ArtefactType()
                {
                    DamageScale = 1.1f,
                    GatheringMultiply = 1,
                    HealthPercent = 0
                }
            };
            
            internal class ArtefactType
            {
                [JsonProperty("Множитель урона(1 = стандарт)")]
                public float DamageScale;
                [JsonProperty("Множитель добываемых ресурсов(1 = стандарт)")]
                public float GatheringMultiply;
                [JsonProperty("Множитель здоровья(0 = стандарт хп)")]
                public float HealthPercent;
            }
        }

        protected override void LoadConfig()
        {
            base.LoadConfig();
            try
            {
                _config = Config.ReadObject<Configuration>();
                if (_config == null) throw new Exception();
                SaveConfig();
            }
            catch
            {
                PrintError("Your configuration file contains an error.Using default configuration values.");
                LoadDefaultConfig();
            }
        }

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

        protected override void LoadDefaultConfig()
        {
            _config = new Configuration();
        }

        #endregion


        [ConsoleCommand("givegems")]
        private void cmdConsolegiveitemsystem(ConsoleSystem.Arg args)
        {
            var player = args.Player();
            if (args.Connection != null)
                if (!player.IsAdmin)
                    return;
            if (args.Args.Length != 2)
            {
                Puts(
                    "Вы не верно ввели команду, используйте: givegems Name/SteamID SkinID");
                return;
            }

            var findPlayer = BasePlayer.Find(args.Args[0]) ?? BasePlayer.FindSleeping(args.Args[0]);
            if (findPlayer == null)
            {
                Puts($"Игрок {args.Args[0]} не найден в списке игроков");
                return;
            }

            var item = ItemManager.CreateByName(_config.ShortName, 1, ulong.Parse(args.Args[1]));
            findPlayer.GiveItem(item);
        }

        #region OxideHooks

        private void OnServerInitialized()
        {
            _ins = this;
            LoadConfig();
        }

        private object OnItemAction(Item item, string action, BasePlayer player)
        {
            if (item == null || !_config.GemsList.ContainsKey(item.skin)) return null;
            if (action != "unwrap") return null;
            player.gameObject.AddComponent<ArtefactBuff>().ArtefactBuffcfg = _config.GemsList[item.skin];
            player.GetComponent<ArtefactBuff>().ArtefactActivate();
            item.UseItem();
            return false;
        }
        
        private void Unload()
        {
            foreach (var check in UnityEngine.Object.FindObjectsOfType<ArtefactBuff>())
            {
                check.Kill();
            }
            _ins = null;

        }

        private void OnEntityDeath(BasePlayer player)
        {
            if (player == null) return;
            if (player.GetComponent<ArtefactBuff>() == null) return;
            player.GetComponent<ArtefactBuff>().Kill();
        }
        
        private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
            if (entity == null || info == null || !(entity as BasePlayer) && !(entity as BaseNpc)) return;
            var attacker = info.InitiatorPlayer;
            if (attacker == null) return;
            var comp = attacker.gameObject.GetComponent<ArtefactBuff>();
            if (comp != null && attacker.HasPlayerFlag(BasePlayer.PlayerFlags.Unused1))
                info.damageTypes.ScaleAll(comp.GetDamageScale());
        }

        private void OnDispenserGather(ResourceDispenser dispenser, BasePlayer player, Item item)
        {
            OnDispenserBonus(dispenser, player, item);
        }

        private void OnDispenserBonus(ResourceDispenser dispenser, BasePlayer player, Item item)
        {
            if (player == null) return;
            var comp = player.gameObject.GetComponent<ArtefactBuff>();
            if (comp != null && player.HasPlayerFlag(BasePlayer.PlayerFlags.Unused2))
            {
                var amount = (int) (item.amount * comp.GetGatheringMultiply());
                item.amount = amount > 1 ? amount : 1;
            }
        }
        
        #endregion

        private class ArtefactBuff : FacepunchBehaviour
        {
            public Configuration.ArtefactType ArtefactBuffcfg;
            private BasePlayer player;

            private void Awake()
            {
                player = GetComponent<BasePlayer>();
                player.modifiers.RemoveAll();
            }
            public void ArtefactActivate()
            {
                var modifiers = new List<ModifierDefintion>();
                modifiers.Clear();
                var ArtSettings = ArtefactBuffcfg;
                var HealthPercent = ArtSettings.HealthPercent;

                if (HealthPercent != 0)
                {
                    var modifier = new ModifierDefintion()
                    {
                        type = Modifier.ModifierType.Max_Health, duration = 86400, source = Modifier.ModifierSource.Tea,
                        value = HealthPercent,
                    };
                    modifiers.Add(modifier);
                    player.modifiers.Add(modifiers);
                }

                if (ArtSettings.DamageScale != 1)
                    if (!player.HasPlayerFlag(BasePlayer.PlayerFlags.Unused1))
                        player.SetPlayerFlag(BasePlayer.PlayerFlags.Unused1, true);

                if (ArtSettings.GatheringMultiply != 1)
                    if (!player.HasPlayerFlag(BasePlayer.PlayerFlags.Unused2))
                        player.SetPlayerFlag(BasePlayer.PlayerFlags.Unused2, true);

            }
            
            public float GetGatheringMultiply()
            {
                return GetRate();
            }

            private float GetRate()
            {
                var def = ArtefactBuffcfg.GatheringMultiply;
                return def;
            }
            public float GetDamageScale()
            {
                return ArtefactBuffcfg.DamageScale;
            }

            public void Kill() 
            {
                player.modifiers.RemoveAll();
                if (player.HasPlayerFlag(BasePlayer.PlayerFlags.Unused1))
                    player.SetPlayerFlag(BasePlayer.PlayerFlags.Unused1, false);
                if (player.HasPlayerFlag(BasePlayer.PlayerFlags.Unused2))
                    player.SetPlayerFlag(BasePlayer.PlayerFlags.Unused2, false);
                Destroy(this);
            }
        }

    }
}

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