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

FREE TheGoldenEgg : 1.9.24 1.9.24

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System;
using System.Collections.Generic;
using System.Linq;
using Oxide.Core;
using Oxide.Core.Libraries;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Configuration;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Facepunch;
namespace Oxide.Plugins {
    [Info("The Golden Egg", "crunch", "1.9.24")]
    [Description("Once found, the Golden Egg can bring you great riches, but it doesn't want to remain hidden...")]
    class TheGoldenEgg : CovalencePlugin {
        [PluginReference]
        private Plugin TimedPermissions, RaidableBases;
        private Configuration _pluginConfig;
        private static TheGoldenEgg ins;
        private const string permissionUse = "thegoldenegg.use";
        private StoredData storedData;
        private DynamicConfigFile data;
        public float chance = 0f;
        public ulong eggUID = 0;
        public ulong chinookID = 0;
        private List<ulong> crateID = new List<ulong>();
        private Timer markerTimer, rewardTimer, delayTimer, saveTimer, blockTimer, moveTimer, crateEventTimer, crateMarkTimer, safeTimer, buildTimer, raidBaseTimer;
        private int resource, amount, spawnTime;
        private string cleanName, itemName;
        private bool blockEggOpen, safezone = false, inPriv = false, pop = false, priv = false, tod = false, blocked = false, isBlocked = false, crateDrop, isRunning = false;
        public static string currentOwner;
        private DateTime startTime;
        private static PluginTimers Timer;
        public List<MapMarkerGenericRadius> eggRadMarker = new List<MapMarkerGenericRadius>();
        public List<VendingMachineMapMarker> eggVendMarker = new List<VendingMachineMapMarker>();
        public MapMarkerGenericRadius _marker;
        public Dictionary<string, Item> _spawnedItems = new Dictionary<string, Item>();
        public Dictionary<ulong, HackableLockedCrate> _spawnedCrates = new Dictionary<ulong, HackableLockedCrate>();
        readonly int blockLayer = LayerMask.GetMask("Player (Server)");
        private List<ulong> allowDraw = new List<ulong>();
        private List<uint> buildID = new List<uint>();
        public Vector3 pos, lastPosition, cratePos;
        void Init() {
            LoadData();
            AddCommands();
            Timer = timer;
            Unsubscribe(nameof(OnEntityTakeDamage));
            Unsubscribe(nameof(OnItemPickup));
            Unsubscribe(nameof(OnItemDropped));
            Unsubscribe(nameof(CanEntityTakeDamage));
            Unsubscribe(nameof(OnCollectiblePickup));
            Unsubscribe(nameof(OnHelicopterDropCrate));
            Unsubscribe(nameof(OnCrateDropped));
            Unsubscribe(nameof(CanHackCrate));
            Unsubscribe(nameof(OnPlayerCommand));
        }
        void OnServerInitialized(bool initial) {
            permission.RegisterPermission(permissionUse, this);
            _pluginConfig.EggRewards.Remove("item.one");
            _pluginConfig.EggRewards.Remove("item.two");
            _pluginConfig.EggRewards.Remove("etc");
            crateDrop = false;
            foreach (var ent in BaseNetworkable.serverEntities) {
                if (ent is StorageContainer) {
                    var container = (ent as StorageContainer)?.inventory?.itemList ?? null;
                    for (int j = 0; j < container.Count; j++) {
                        if (container[j].text == "6E657264") {
                            SaveDataTimer();
                            var playerID = (ent as StorageContainer).OwnerID;
                            var player = players.FindPlayerById(Convert.ToString(playerID));
                            var bPlayer = BasePlayer.FindAwakeOrSleeping(Convert.ToString(playerID));
                            priv = false;
                            if (bPlayer != null && _pluginConfig.NoPrivTime) priv = (ent as StorageContainer).inventory.entityOwner?.GetBuildingPrivilege()?.IsAuthed(bPlayer) ?? false;
                            if (_pluginConfig.TimeOfDay) {
                                TimeSpan tsStart = DateTime.Parse(_pluginConfig.StartTime).TimeOfDay;
                                TimeSpan tsEnd = DateTime.Parse(_pluginConfig.EndTime).TimeOfDay;
                                if (IsBetween(tsStart, tsEnd)) tod = true;
                            }
                            if ((!priv) && (!tod) && (ent.ShortPrefabName != "small_stash_deployed" || (ent.ShortPrefabName == "small_stash_deployed" && !_pluginConfig.BlockStashTime))) {
                                if (_pluginConfig.ServerPop == 0 || (covalence.Server.Players + ConVar.Admin.ServerInfo().Joining >= _pluginConfig.ServerPop)) storedData.OnEggMove(player);
                            }
                            pos = ent.transform.position;
                            eggUID = container[j].uid.Value;
                            itemName = String.IsNullOrEmpty(_pluginConfig.customItemS.ItemName) ? "The Golden Egg" : _pluginConfig.customItemS.ItemName;
                            if (!_spawnedItems.ContainsKey(container[j].text)) {
                                _spawnedItems.Add(container[j].text, container[j]);
                            }
                            Unsubscribe(nameof(CanLootEntity));
                            Subscribe(nameof(OnItemAddedToContainer));
                            Subscribe(nameof(OnItemRemovedFromContainer));
                            Subscribe(nameof(OnItemPickup));
                            Subscribe(nameof(OnItemDropped));
                            if (_pluginConfig.roamS.IncreasePickup) Subscribe(nameof(OnCollectiblePickup));
                            if (_pluginConfig.tpveS.DisableTruePVE) Subscribe(nameof(CanEntityTakeDamage));
                            if (_pluginConfig.BlockEggCrack) Subscribe(nameof(OnEntityTakeDamage));
                            if (_pluginConfig.crateS.crateEvent) {
                                Subscribe(nameof(OnHelicopterDropCrate));
                                Subscribe(nameof(OnCrateDropped));
                                Subscribe(nameof(CanHackCrate));
                            }
                            if (_pluginConfig.UseBlacklist) {
                                Subscribe(nameof(OnPlayerCommand));
                            }
                            if (_pluginConfig.markerS.boxMarker) {
                                CreateMarkers();
                                markerTimer = timer.Repeat(_pluginConfig.markerS.BoxMarkerRefreshTime, 0, () => {
                                    /*                                    if (ent == null)
                                                                       {
                                                                           if (markerTimer != null) markerTimer.Destroy();
                                                                           MarkerDelete();
                                                                           markerTimer = null;
                                                                       }
                                                                       else
                                                                       { */
                                    pos = ent.transform.position;
                                    CreateMarkers();
                                    //}
                                }
                                );
                            }
                            else {
                                if (markerTimer != null) {
                                    markerTimer.Destroy();
                                    markerTimer = null;
                                }
                                MarkerDelete();
                            }
                            resource = 0;
                            spawnTime = _pluginConfig.resourceS.ResourceSpawnTime;
                            for (int x = 0; x < container.Count; x++) {
                                var shortName = container[x].info.shortname;
                                cleanName = container[x].info.displayName.english;
                                if (ent.ShortPrefabName == "small_stash_deployed") return;
                                var isDone = false;
                                switch (shortName) {
                                    case "metal.refined" : case "lowgradefuel" : case "metal.fragments" : case "scrap" : resource = container[x].info.itemid;
                                    amount = GetResourceAmount(shortName);
                                    isDone = true;
                                    break;
                                    case "sulfur" : if (_pluginConfig.resourceS.AllowSulfurCooked) {
                                        resource = container[x].info.itemid;
                                        amount = GetResourceAmount(shortName);
                                        isDone = true;
                                    }
                                    break;
                                    case "sulfur.ore" : if (_pluginConfig.resourceS.AllowSulfurOre) {
                                        resource = container[x].info.itemid;
                                        amount = GetResourceAmount(shortName);
                                        isDone = true;
                                    }
                                    break;
                                }
                                if (isDone) break;
                                if (shortName == _pluginConfig.resourceS.CustomItem1) {
                                    resource = container[x].info.itemid;
                                    amount = _pluginConfig.resourceS.CustomAmount1;
                                    spawnTime = _pluginConfig.resourceS.CustomTime1;
                                    break;
                                }
                                else if (shortName == _pluginConfig.resourceS.CustomItem2) {
                                    resource = container[x].info.itemid;
                                    amount = _pluginConfig.resourceS.CustomAmount2;
                                    spawnTime = _pluginConfig.resourceS.CustomTime2;
                                    break;
                                }
                                else if (shortName == _pluginConfig.resourceS.CustomItem3) {
                                    resource = container[x].info.itemid;
                                    amount = _pluginConfig.resourceS.CustomAmount3;
                                    spawnTime = _pluginConfig.resourceS.CustomTime3;
                                    break;
                                }
                                else {
                                    continue;
                                }
                            }
                            if (resource == 0) {
                                resource = -932201673;
                                amount = GetResourceAmount("scrap");
                                cleanName = "Scrap";
                            }
                            if (rewardTimer != null) rewardTimer.Destroy();
                            startTime = DateTime.Now;
                            rewardTimer = timer.Repeat(spawnTime, 0, () => {
                                SpawnRewards(ent as BaseEntity, resource, amount);
                                startTime = DateTime.Now;
                            }
                            );
                            return;
                        }
                    }
                }
                else if (ent is BasePlayer basePlayer) {
                    List<Item> items = new List<Item>();
                    basePlayer.inventory.GetAllItems(items);
                    if (items != null && items.Count > 0) for (int j = 0; j < items.Count; j++) {
                        if (items[j].text == "6E657264") {
                            SaveDataTimer();
                            var playerID = (ent as BasePlayer).userID;
                            var player = players.FindPlayerById(Convert.ToString(playerID));
                            var bPlayer = BasePlayer.FindAwakeOrSleeping(Convert.ToString(playerID));
                            currentOwner = (ent as BasePlayer).UserIDString;
                            priv = false;
                            if (bPlayer != null && _pluginConfig.NoPrivTime) priv = bPlayer?.GetBuildingPrivilege()?.IsAuthed(bPlayer) ?? false;
                            if (!priv) {
                                if (_pluginConfig.ServerPop == 0 || (covalence.Server.Players + ConVar.Admin.ServerInfo().Joining >= _pluginConfig.ServerPop)) storedData.OnEggMove(player);
                            }
                            eggUID = items[j].uid.Value;
                            itemName = String.IsNullOrEmpty(_pluginConfig.customItemS.ItemName) ? "The Golden Egg" : _pluginConfig.customItemS.ItemName;
                            if (!_spawnedItems.ContainsKey(items[j].text)) {
                                _spawnedItems.Add(items[j].text, items[j]);
                            }
                            Unsubscribe(nameof(CanLootEntity));
                            Subscribe(nameof(OnItemAddedToContainer));
                            Subscribe(nameof(OnItemRemovedFromContainer));
                            Subscribe(nameof(OnItemPickup));
                            Subscribe(nameof(OnItemDropped));
                            if (_pluginConfig.roamS.IncreasePickup) Subscribe(nameof(OnCollectiblePickup));
                            if (_pluginConfig.tpveS.DisableTruePVE) Subscribe(nameof(CanEntityTakeDamage));
                            if (_pluginConfig.BlockEggCrack) Subscribe(nameof(OnEntityTakeDamage));
                            if (_pluginConfig.crateS.crateEvent) {
                                Subscribe(nameof(OnHelicopterDropCrate));
                                Subscribe(nameof(OnCrateDropped));
                                Subscribe(nameof(CanHackCrate));
                            }
                            if (_pluginConfig.UseBlacklist) {
                                Subscribe(nameof(OnPlayerCommand));
                            }
                            pos = ent.transform.position;
                            safezone = false;
                            inPriv = false;
                            pop = false;
                            tod = false;
                            CreateMarkers(bPlayer);
                            markerTimer = timer.Repeat(_pluginConfig.markerS.PlayerMarkerRefreshTime, 0, () => {
                                pos = ent.transform.position;
                                CreateMarkers(bPlayer);
                            }
                            );
                        }
                    }
                }
                else if (ent is DroppedItem) {
                    if (ent == null || ent.IsDestroyed) {
                        continue;
                    }
                    var drop = ent as DroppedItem;
                    if (drop.item.text == "6E657264") {
                        eggUID = drop.item.uid.Value;
                        itemName = String.IsNullOrEmpty(_pluginConfig.customItemS.ItemName) ? "The Golden Egg" : _pluginConfig.customItemS.ItemName;
                        if (!_spawnedItems.ContainsKey(drop.item.text)) {
                            _spawnedItems.Add(drop.item.text, drop.item);
                        }
                        Unsubscribe(nameof(CanLootEntity));
                        Subscribe(nameof(OnItemAddedToContainer));
                        Subscribe(nameof(OnItemRemovedFromContainer));
                        Subscribe(nameof(OnItemPickup));
                        Subscribe(nameof(OnItemDropped));
                        if (_pluginConfig.roamS.IncreasePickup) Subscribe(nameof(OnCollectiblePickup));
                        if (_pluginConfig.tpveS.DisableTruePVE) Subscribe(nameof(CanEntityTakeDamage));
                        if (_pluginConfig.BlockEggCrack) Subscribe(nameof(OnEntityTakeDamage));
                        if (_pluginConfig.crateS.crateEvent) {
                            Subscribe(nameof(OnHelicopterDropCrate));
                            Subscribe(nameof(OnCrateDropped));
                            Subscribe(nameof(CanHackCrate));
                        }
                        if (_pluginConfig.UseBlacklist) {
                            Subscribe(nameof(OnPlayerCommand));
                        }
                        pos = ent.transform.position;
                        safezone = false;
                        inPriv = false;
                        pop = false;
                        tod = false;
                        CreateMarkers();
                        markerTimer = timer.Repeat(_pluginConfig.markerS.PlayerMarkerRefreshTime, 0, () => {
                            pos = ent.transform.position;
                            CreateMarkers();
                        }
                        );
                    }
                }
            }
            if (eggUID == 0) {
                Subscribe(nameof(CanLootEntity));
                Unsubscribe(nameof(OnItemAddedToContainer));
                Unsubscribe(nameof(OnItemRemovedFromContainer));
                if (_pluginConfig.BlockEggCrack) Unsubscribe(nameof(OnEntityTakeDamage));
                if (_pluginConfig.tpveS.DisableTruePVE) Unsubscribe(nameof(CanEntityTakeDamage));
                if (_pluginConfig.roamS.IncreasePickup) Unsubscribe(nameof(OnCollectiblePickup));
                if (_pluginConfig.crateS.crateEvent) {
                    Unsubscribe(nameof(OnHelicopterDropCrate));
                    Unsubscribe(nameof(OnCrateDropped));
                    Unsubscribe(nameof(CanHackCrate));
                }
                if (_pluginConfig.UseBlacklist) {
                    Unsubscribe(nameof(OnPlayerCommand));
                }
            }
            if (_pluginConfig.KillTime != 0) timer.Every(60f, UpdateLoop);
            runEvent();
        }
        private void runEvent() {
            if (eggUID == 0) return;
            if (chinookID != 0) {
                Puts("The chinook event is already running");
                return;
            }
            if (_pluginConfig.crateS.crateEvent && _pluginConfig.crateS.crateRepeat && (covalence.Server.Players + ConVar.Admin.ServerInfo().Joining >= _pluginConfig.crateS.cratePop)) {
                crateEventTimer = timer.In(UnityEngine.Random.Range(_pluginConfig.crateS.minStartTime, _pluginConfig.crateS.maxStartTime), () => {
                    Puts("The chinook event has started");
                    chinookID = 0;
                    crateID.Clear();
                    _spawnedCrates.Clear();
                    if (_marker != null) {
                        _marker.Kill();
                        _marker.SendUpdate();
                    }
                    if (crateMarkTimer != null) crateMarkTimer.Destroy();
                    var chinook = GameManager.server.CreateEntity("assets/prefabs/npc/ch47/ch47scientists.entity.prefab") as CH47HelicopterAIController;
                    if (chinook == null) {
                        return;
                    }
                    chinook.numCrates = _pluginConfig.crateS.numCrates;
                    chinook.TriggeredEventSpawn();
                    chinook.Spawn();
                    chinookID = chinook.net.ID.Value;
                }
                );
            }
            return;
        }
        private void UpdateLoop() {
            if (String.IsNullOrEmpty(storedData._eggCreated)) return;
            if ((DateTime.Now - DateTime.Parse((string)storedData._eggCreated)).TotalMinutes < _pluginConfig.KillTime) return;
            if (_spawnedItems != null) {
                foreach (var _item in _spawnedItems.ToList()) {
                    if (_item.Key == "6E657264") {
                        Item item = _item.Value;
                        if (item != null) {
                            item.Remove();
                            _spawnedItems.Remove(_item.Key);
                        }
                    }
                }
            }
        }
        void Unload() {
            storedData.GetTotals();
            SaveData();
            Timer = null;
            ins = null;
            if (markerTimer != null) {
                markerTimer.Destroy();
                markerTimer = null;
            }
            if (rewardTimer != null) rewardTimer.Destroy();
            if (crateMarkTimer != null) crateMarkTimer.Destroy();
            if (_marker != null) {
                _marker.Kill();
                _marker.SendUpdate();
            }
            MarkerDelete();
        }
        void OnNewSave(string filename) {
            if (_pluginConfig.ClearData) {
                data.Clear();
                data.Save();
                storedData = data.ReadObject<StoredData>();
                if (storedData == null) {
                    storedData = new StoredData();
                }
                Log("Wiped player_data.json");
            }
        }
        object CanLootEntity(BasePlayer player, StorageContainer container) {
            if (player == null || container == null || eggUID != 0 || spamCheck.ContainsKey(player.userID) || player.IsNpc || !player.userID.IsSteamId()) return null;
            switch (container.ShortPrefabName) {
                case "codelockedhackablecrate" : case "chinooklockedcrate" : case "chinooklockedcratecodelocked" : case "codelockedhackablecrate_oilrig" : chance = _pluginConfig.LockedCrateEggChance;
                break;
                case "crate_elite" : case "bradley_crate" : chance = _pluginConfig.EliteCrateEggChance;
                break;
                case "crate_normal" : chance = _pluginConfig.MilitaryCrateEggChance;
                break;
                case "crate_normal_2" : chance = _pluginConfig.NormalCrateEggChance;
                break;
                default : return null;
            }
            var randomInt = UnityEngine.Random.Range(0f, 100f);
            AddSpamBlock(player.userID);
            if (randomInt <= chance) {
                Item item = ItemManager.CreateByItemID(-1002156085, 1);
                eggUID = item.uid.Value;
                if (_pluginConfig.customItemS.ItemSkin != 0) item.skin = _pluginConfig.customItemS.ItemSkin;
                SaveDataTimer();
                Subscribe(nameof(OnItemPickup));
                Subscribe(nameof(OnItemDropped));
                itemName = String.IsNullOrEmpty(_pluginConfig.customItemS.ItemName) ? "The Golden Egg" : _pluginConfig.customItemS.ItemName;
                item.name = itemName;
                item.text = "6E657264";
                item.MarkDirty();
                if (!_spawnedItems.ContainsKey(item.text)) {
                    _spawnedItems.Add(item.text, item);
                }
                if (player != null && player.userID.IsSteamId()) {
                    Puts($"{player.displayName} found the egg");
                    player.GiveItem(item);
                    runEvent();
                    storedData._eggCreated = DateTime.Now.ToString();
                    SaveData();
                    if (_pluginConfig.roamS.IncreaseHealth || _pluginConfig.roamS.IncreaseGather) SetModifiers(player);
                    Subscribe(nameof(OnItemAddedToContainer));
                    Subscribe(nameof(OnItemRemovedFromContainer));
                    if (_pluginConfig.BlockEggCrack) Subscribe(nameof(OnEntityTakeDamage));
                    if (_pluginConfig.tpveS.DisableTruePVE) Subscribe(nameof(CanEntityTakeDamage));
                    if (_pluginConfig.roamS.IncreasePickup) Subscribe(nameof(OnCollectiblePickup));
                    if (_pluginConfig.crateS.crateEvent) {
                        Subscribe(nameof(OnHelicopterDropCrate));
                        Subscribe(nameof(OnCrateDropped));
                        Subscribe(nameof(CanHackCrate));
                    }
                    if (_pluginConfig.UseBlacklist) {
                        Subscribe(nameof(OnPlayerCommand));
                    }
                    storedData.OnEggMove(player.IPlayer);
                    if (_pluginConfig.markerS.playerMarker) server.Broadcast($"{itemName} has been found!! Its location will appear on the map in {_pluginConfig.markerS.InitialMarkerDelay} seconds");
                    else server.Broadcast($"{itemName} has been found!!");
                    if (!String.IsNullOrEmpty(_pluginConfig.sendWebhook) && _pluginConfig.sendWebhook != "https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks") {
                        new DiscordWebhook().AddEmbed().SetDescription($"{itemName.ToUpper()} IS FOUND!").SetColor(3447003).AddField("Location", $"{(player.transform.position)}, but will soon be on the move!", true).SetTimestamp(DateTime.UtcNow).AddThumbnail(_pluginConfig.customItemS.ItemFoundDiscord).EndEmbed().Send(this, _pluginConfig.sendWebhook);
                    }
                    CuiHelper.DestroyUi(player, "EggUI");
                    CuiHelper.AddUi(player, CreateEggUI());
                    var effect = "assets/bundled/prefabs/fx/explosions/water_bomb.prefab";
                    EffectNetwork.Send(new Effect(effect, player, 0, new Vector3(), new Vector3()), player.Connection);
                    timer.Once(10f, () => {
                        CuiHelper.DestroyUi(player, "EggUI");
                    }
                    );
                    delayTimer = timer.Once(_pluginConfig.markerS.InitialMarkerDelay, () => {
                        var inv = new List<Item>();
                        player.inventory.GetAllItems(inv);
                        if (!inv.Contains(item)) {
                            return;
                        }
                        pos = player.transform.position;
                        safezone = false;
                        inPriv = false;
                        pop = false;
                        tod = false;
                        CreateMarkers(player);
                        markerTimer = timer.Repeat(_pluginConfig.markerS.PlayerMarkerRefreshTime, 0, () => {
                            pos = player.transform.position;
                            CreateMarkers(player);
                        }
                        );
                    }
                    );
                }
                Unsubscribe(nameof(CanLootEntity));
                return null;
            }
            return null;
        }
        void OnItemAddedToContainer(ItemContainer container, Item item) {
            if (container == null || item == null) return;
            switch (item.info.shortname) {
                case "metal.refined" : case "lowgradefuel" : case "metal.fragments" : case "scrap" : case "sulfur" : case "sulfur.ore" : HandleAdds(container, item);
                break;
            }
            if (item.info.shortname == _pluginConfig.resourceS.CustomItem1 || item.info.shortname == _pluginConfig.resourceS.CustomItem2 || item.info.shortname == _pluginConfig.resourceS.CustomItem3 ) {
                HandleAdds(container, item);
            }
            if (item.text == "6E657264") {
                var playerOwner = container.playerOwner;
                var contOwner = container.entityOwner;
                //if (markerTimer != null) markerTimer.Destroy();
                if (rewardTimer != null) rewardTimer.Destroy();
                if (playerOwner != null && (_pluginConfig.roamS.IncreaseHealth || _pluginConfig.roamS.IncreaseGather)) {
                    SetModifiers(playerOwner);
                    return;
                }
                if (markerTimer != null) {
                    markerTimer.Destroy();
                    markerTimer = null;
                    MarkerDelete();
                }
                pos = contOwner.transform.position;
                if (contOwner != null) {
                    var inventory = container.itemList.ToArray();
                    resource = 0;
                    spawnTime = _pluginConfig.resourceS.ResourceSpawnTime;
                    foreach (Item inv in inventory) {
                        var shortName = inv.info.shortname;
                        var isDone = false;
                        switch (shortName) {
                            case "metal.refined" : case "lowgradefuel" : case "metal.fragments" : case "scrap" : resource = inv.info.itemid;
                            amount = GetResourceAmount(shortName);
                            cleanName = inv.info.displayName.english;
                            isDone = true;
                            break;
                            case "sulfur" : if (_pluginConfig.resourceS.AllowSulfurCooked) {
                                resource = inv.info.itemid;
                                amount = GetResourceAmount(shortName);
                                cleanName = inv.info.displayName.english;
                                isDone = true;
                            }
                            break;
                            case "sulfur.ore" : if (_pluginConfig.resourceS.AllowSulfurOre) {
                                resource = inv.info.itemid;
                                amount = GetResourceAmount(shortName);
                                cleanName = inv.info.displayName.english;
                                isDone = true;
                            }
                            break;
                        }
                        if (isDone) break;
                        if (shortName == _pluginConfig.resourceS.CustomItem1) {
                            resource = inv.info.itemid;
                            amount = _pluginConfig.resourceS.CustomAmount1;
                            spawnTime = _pluginConfig.resourceS.CustomTime1;
                            cleanName = inv.info.displayName.english;
                            break;
                        }
                        else if (shortName == _pluginConfig.resourceS.CustomItem2) {
                            resource = inv.info.itemid;
                            amount = _pluginConfig.resourceS.CustomAmount2;
                            spawnTime = _pluginConfig.resourceS.CustomTime2;
                            cleanName = inv.info.displayName.english;
                            break;
                        }
                        else if (shortName == _pluginConfig.resourceS.CustomItem3) {
                            resource = inv.info.itemid;
                            amount = _pluginConfig.resourceS.CustomAmount3;
                            spawnTime = _pluginConfig.resourceS.CustomTime3;
                            cleanName = inv.info.displayName.english;
                            break;
                        }
                        else {
                            continue;
                        }
                    }
                    if (resource == 0) {
                        resource = -932201673;
                        amount = GetResourceAmount("scrap");
                        cleanName = "Scrap";
                    }
                    priv = false;
                    var ownerID = contOwner.OwnerID;
                    currentOwner = ownerID.ToString();
                    if (contOwner.ShortPrefabName != "small_stash_deployed" && amount != 0) {
                        var player = ownerID.IsSteamId() ? BasePlayer.FindAwakeOrSleeping(Convert.ToString(ownerID)) : null;
                        if (player != null && _pluginConfig.NoPrivTime) priv = container.entityOwner?.GetBuildingPrivilege()?.IsAuthed(player) ?? false;
                        if (player != null && player.currentTeam != 0UL) {
                            var teamMembers = player.Team.members.ToList();
                            foreach (var member in teamMembers) {
                                if (!String.IsNullOrEmpty(cleanName)) {
                                    var teamPlayer = players.FindPlayerById(Convert.ToString(member));
                                    if (teamPlayer.IsConnected) {
                                        var bPlayer = BasePlayer.FindByID(member);
                                        bPlayer.ChatMessage(String.Format(GetMsg("Generating", Convert.ToString(bPlayer.userID)), cleanName));
                                    }
                                }
                            }
                        }
                        if (player != null && player.currentTeam == 0 && amount != 0) {
                            if (!String.IsNullOrEmpty(cleanName)) player.ChatMessage(String.Format(GetMsg("Generating", Convert.ToString(player.userID)), cleanName));
                        }
                    }
                    if (_pluginConfig.TimeOfDay) {
                        tod = false;
                        TimeSpan tsStart = DateTime.Parse(_pluginConfig.StartTime).TimeOfDay;
                        TimeSpan tsEnd = DateTime.Parse(_pluginConfig.EndTime).TimeOfDay;
                        if (IsBetween(tsStart, tsEnd)) tod = true;
                    }
                    var playerI = players.FindPlayerById(Convert.ToString(ownerID));
                    if (playerI != null) currentOwner = playerI.Id;
                    if (contOwner.ShortPrefabName != "small_stash_deployed" || (contOwner.ShortPrefabName == "small_stash_deployed" && !_pluginConfig.BlockStashTime)) {
                        if (playerI != null && !priv && !tod) {
                            if (_pluginConfig.ServerPop == 0 || (covalence.Server.Players + ConVar.Admin.ServerInfo().Joining >= _pluginConfig.ServerPop)) storedData.OnEggMove(playerI);
                        }
                        if (rewardTimer != null) rewardTimer.Destroy();
                        startTime = DateTime.Now;
                        rewardTimer = timer.Repeat(spawnTime, 0, () => {
                            SpawnRewards(contOwner, resource, amount);
                            startTime = DateTime.Now;
                        }
                        );
                    }
                }
                if (_pluginConfig.markerS.boxMarker) {
                    CreateMarkers();
                    markerTimer = timer.Repeat(_pluginConfig.markerS.BoxMarkerRefreshTime, 0, () => {
                        /*                         if (contOwner == null)
                                                {
                                                    if (markerTimer != null) markerTimer.Destroy();
                                                    MarkerDelete();
                                                    markerTimer = null;
                                                }
                                                else
                                                { */
                        pos = contOwner.transform.position;
                        CreateMarkers();
                        //}
                    }
                    );
                }
                else {
                    if (markerTimer != null) {
                        markerTimer.Destroy();
                        markerTimer = null;
                    }
                    MarkerDelete();
                }
            }
            return;
        }
        void HandleAdds(ItemContainer container, Item item) {
            var contOwner = container.entityOwner;
            if (contOwner != null && contOwner.ShortPrefabName != "small_stash_deployed") {
                var inventory = container.itemList.ToArray();
                var itemID = item.info.itemid;
                foreach (Item inv in inventory) {
                    if (inv.text == "6E657264") {
                        if ((!_pluginConfig.resourceS.AllowSulfurCooked && item.info.shortname == "sulfur") || (!_pluginConfig.resourceS.AllowSulfurOre && item.info.shortname == "sulfur.ore")) break;
                        cleanName = item.info.displayName.english;
                        var ownerID = contOwner.OwnerID;
                        amount = GetResourceAmount(item.info.shortname);
                        var player = ownerID.IsSteamId() ? BasePlayer.FindAwakeOrSleeping(Convert.ToString(ownerID)) : null;
                        if (player != null && player.currentTeam != 0UL && amount != 0) {
                            var teamMembers = player.Team.members.ToList();
                            foreach (var member in teamMembers) {
                                var teamPlayer = players.FindPlayerById(Convert.ToString(member));
                                if (teamPlayer.IsConnected) {
                                    var bPlayer = BasePlayer.FindByID(member);
                                    bPlayer.ChatMessage(String.Format(GetMsg("Generating", Convert.ToString(bPlayer.userID)), cleanName));
                                }
                            }
                        }
                        if (player != null && player.currentTeam == 0 && amount != 0) {
                            player.ChatMessage(String.Format(GetMsg("Generating", Convert.ToString(player.userID)), cleanName));
                        }
                        spawnTime = GetSpawnTime(item.info.shortname);
                        if (rewardTimer != null) rewardTimer.Destroy();
                        startTime = DateTime.Now;
                        rewardTimer = timer.Repeat(spawnTime, 0, () => {
                            SpawnRewards(contOwner, itemID, amount);
                            startTime = DateTime.Now;
                        }
                        );
                        break;
                    }
                }
            }
            return;
        }
        object OnItemAction(Item item, string action, BasePlayer player) {
            Item eggItem;
            _spawnedItems.TryGetValue("6E657264", out eggItem);
            if (eggItem == null) return null;
            if (eggItem.GetOwnerPlayer() != null && eggItem.GetOwnerPlayer() == player && (action.Equals("consume")) && (item.info.shortname.StartsWith("maxhealthtea") || item.info.shortname.StartsWith("oretea") || item.info.shortname.StartsWith("woodtea"))) return true;
            if (item?.info?.shortname == null || item.text != "6E657264" || action != "unwrap") return null;
            if (_pluginConfig.BlockEggCrack && blockEggOpen) {
                var placeHolder = itemName != "The Golden Egg" ? "item" : "egg";
                player.ChatMessage(String.Format(GetMsg("Blocked", Convert.ToString(player.userID)), placeHolder));
                return true;
            }
            if (player != null && _pluginConfig.roamS.IncreaseHealth) {
                player.modifiers.Add(new List<ModifierDefintion> {
                    new ModifierDefintion {
                        type = Modifier.ModifierType.Max_Health, value = 0, duration = 0.1f, source = Modifier.ModifierSource.Tea
                    }
                }
                );
                player.modifiers.SendChangesToClient();
            }
            if (player != null && _pluginConfig.roamS.IncreaseGather) {
                player.modifiers.Add(new List<ModifierDefintion> {
                    new ModifierDefintion {
                        type = Modifier.ModifierType.Ore_Yield, value = 0, duration = 0.1f, source = Modifier.ModifierSource.Tea
                    }
                }
                );
                player.modifiers.SendChangesToClient();
            }
            storedData.DestroyTimers();
            if (markerTimer != null) {
                markerTimer.Destroy();
                markerTimer = null;
            }
            MarkerDelete();
            if (_pluginConfig.UseCustomList) {
                int index = UnityEngine.Random.Range(0, _pluginConfig.EggRewards.Count);
                try {
                    item.Remove();
                    player.SendNetworkUpdateImmediate();
                    var effect = "assets/bundled/prefabs/fx/gestures/eat_soft.prefab";
                    EffectNetwork.Send(new Effect(effect, player, 0, new Vector3(), new Vector3()), player.Connection);
                    var reward = ItemManager.CreateByName(_pluginConfig.EggRewards[index], 1);
                    player.GiveItem(reward);
                    return true;
                }
                catch {
                    return null;
                }
            }
            else {
                return null;
            }
        }
        void OnItemRemovedFromContainer(ItemContainer container, Item item) {
            if (container == null || item?.info?.shortname == null || item.text != "6E657264") return;
            var playerOwner = container.playerOwner;
            var newplayercontainer = item.GetOwnerPlayer();
            var contOwner = container.entityOwner;
            storedData.DestroyTimers();
            if (rewardTimer != null) rewardTimer.Destroy();
            if (delayTimer != null) delayTimer.Destroy();
            if (playerOwner != null && _pluginConfig.roamS.IncreaseHealth) {
                playerOwner.modifiers.Add(new List<ModifierDefintion> {
                    new ModifierDefintion {
                        type = Modifier.ModifierType.Max_Health, value = 0, duration = 0.1f, source = Modifier.ModifierSource.Tea
                    }
                }
                );
                playerOwner.modifiers.SendChangesToClient();
            }
            if (playerOwner != null && _pluginConfig.roamS.IncreaseGather) {
                playerOwner.modifiers.Add(new List<ModifierDefintion> {
                    new ModifierDefintion {
                        type = Modifier.ModifierType.Ore_Yield, value = 0, duration = 0.1f, source = Modifier.ModifierSource.Tea
                    }
                }
                );
                playerOwner.modifiers.SendChangesToClient();
            }
            NextTick(() => {
                var player = item.GetOwnerPlayer();
                if (player != null) {
                    var playerI = players.FindPlayerById(Convert.ToString(player.userID));
                    storedData.OnEggMove(playerI);
                    if (markerTimer != null) {
                        markerTimer.Destroy();
                        markerTimer = null;
                    }
                    if (delayTimer != null) delayTimer.Destroy();
                    MarkerDelete();
                    pos = player.transform.position;
                    safezone = false;
                    inPriv = false;
                    pop = false;
                    tod = false;
                    CreateMarkers(player);
                    markerTimer = timer.Repeat(_pluginConfig.markerS.PlayerMarkerRefreshTime, 0, () => {
                        pos = player.transform.position;
                        CreateMarkers(player);
                    }
                    );
                }
            }
            );
        }
        public static bool IsBetween(TimeSpan start, TimeSpan end) {
            var time = DateTime.Now.TimeOfDay;
            // Start time and end time are in the same day
            if (start <= end) return time >= start && time <= end;
            // Start time and end time are on different days
            return time >= start || time <= end;
        }
        private void SetModifiers(BasePlayer player) {
            if (_pluginConfig.roamS.RoamTod) {
                TimeSpan tsStart = DateTime.Parse(_pluginConfig.roamS.RoamStart).TimeOfDay;
                TimeSpan tsEnd = DateTime.Parse(_pluginConfig.roamS.RoamEnd).TimeOfDay;
                if (IsBetween(tsStart, tsEnd)) {
                    player.ChatMessage(String.Format(GetMsg("RoamDisabledTod", player.UserIDString), _pluginConfig.roamS.RoamStart, _pluginConfig.roamS.RoamEnd));
                    return;
                }
            }
            if (_pluginConfig.roamS.RoamPop != 0 && (covalence.Server.Players + ConVar.Admin.ServerInfo().Joining < _pluginConfig.roamS.RoamPop)) {
                player.ChatMessage(String.Format(GetMsg("RoamDisabledPop", player.UserIDString), _pluginConfig.roamS.RoamPop));
                return;
            }
            if (_pluginConfig.roamS.IncreaseHealth) {
                if (player == null || player.modifiers == null) return;
                var startHealth = player.StartMaxHealth();
                var maxHealth = _pluginConfig.roamS.TotalHealth;
                var healthMultiplier = (maxHealth - startHealth) / startHealth;
                /*                 float healthIncrease;
                                if ((healthIncrease = player.modifiers.GetValue(Modifier.ModifierType.Max_Health, -1000f)) > -1000f &&
                                    Math.Abs(healthIncrease - healthMultiplier) > 0.1f) healthMultiplier += healthIncrease; */
                player.modifiers.Add(new List<ModifierDefintion> {
                    new ModifierDefintion {
                        type = Modifier.ModifierType.Max_Health, value = healthMultiplier, duration = 2600f, source = Modifier.ModifierSource.Tea
                    }
                }
                );
                player.modifiers.SendChangesToClient();
            }
            if (_pluginConfig.roamS.IncreaseGather) {
                player.modifiers.Add(new List<ModifierDefintion> {
                    new ModifierDefintion {
                        type = Modifier.ModifierType.Ore_Yield, value = (_pluginConfig.roamS.GatherMultiplier / 2), duration = 2600f, source = Modifier.ModifierSource.Tea
                    }
                }
                );
                player.modifiers.SendChangesToClient();
            }
            return;
        }
        object OnItemPickup(Item item, BasePlayer player) {
            if (item == null || player == null || item.text != "6E657264") return null;
            currentOwner = player.UserIDString;
            player.ChatMessage(String.Format(GetMsg("Pickup", Convert.ToString(player.userID)), itemName));
            if (_pluginConfig.roamS.IncreaseHealth || _pluginConfig.roamS.IncreaseGather) SetModifiers(player);
            SaveDataTimer();
            priv = false;
            if (player != null && _pluginConfig.NoPrivTime) priv = player?.GetBuildingPrivilege()?.IsAuthed(player) ?? false;
            if (!priv) {
                if (_pluginConfig.ServerPop == 0 || (covalence.Server.Players + ConVar.Admin.ServerInfo().Joining >= _pluginConfig.ServerPop)) {
                    storedData.OnEggMove(player.IPlayer);
                }
            }
            if (markerTimer != null) {
                markerTim
// ... [Code preview truncated due to length. Full source in attached file] ...

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