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

FREE AutoFarm : 3.2.3 3.2.3

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System.Collections.Generic;
using Oxide.Core.Configuration;
using Oxide.Game.Rust.Cui;
using Oxide.Core.Plugins;
using Newtonsoft.Json;
using UnityEngine;
using System.Linq;
using Oxide.Core;
using System;
using VLB;
using Rust;
using Facepunch;
using HarmonyLib;
namespace Oxide.Plugins {
    [Info("Auto Farm", "Razor", "3.2.3")]
    [Description("Auto Farm The PlanterBoxes")]
    public class AutoFarm : RustPlugin {
#region Init
        [PluginReference]
        private Plugin Ganja;
        FarmEntity pcdData;
        private DynamicConfigFile PCDDATA;
        static System.Random random = new System.Random();
        private static AutoFarm _;
        public Dictionary<ulong, int> playerTotals = new Dictionary<ulong, int>();
        public Dictionary<ulong, bool> disabledFarmPlayer = new Dictionary<ulong, bool>();
        public List<ulong> GametipShown = new List<ulong>();
        void Init() {
            _ = this;
            RegisterPermissions();
            PCDDATA = Interface.Oxide.DataFileSystem.GetFile(Name + "/Farm_Data");
            LoadData();
        }
        private void OnServerInitialized() {
            if (configData.vipInformation == null) {
                configData.vipInformation = new Dictionary<string, vipInfo>() {
                    {
                        "autofarm.allow", new vipInfo() {
                            AddSprinkler = false, AddStorageAdapter = false, BoxStorageSlots = 6, heatExposure = false, lightExposure = false, SprinklerNeedsWater = true, totalFarms = 5, seedStorageSlots = 6, cloneList = new Dictionary<string, string>() {
                                {
                                    "orchid", "Sapling"
                                }
                                , {
                                    "sunflower", "Sapling"
                                }
                                , {
                                    "wheat", "Sapling"
                                }
                                , {
                                    "rose", "Sapling"
                                }
                                , {
                                    "blue_berry", "Sapling"
                                }
                                , {
                                    "white_berry", "Sapling"
                                }
                                , {
                                    "red_berry", "Sapling"
                                }
                                , {
                                    "green_berry", "Sapling"
                                }
                                , {
                                    "black_berry", "Sapling"
                                }
                                , {
                                    "yellow_berry", "Sapling"
                                }
                                , {
                                    "pumpkin", "Sapling"
                                }
                                , {
                                    "potato", "Sapling"
                                }
                                , {
                                    "hemp", "Sapling"
                                }
                                , {
                                    "corn", "Sapling"
                                }
                            }
                            , knifeList = new Dictionary<int, int>() {
                                {
                                    1814288539, 0
                                }
                                , {
                                    -194509282, 0
                                }
                                , {
                                    2040726127, 0
                                }
                                , {
                                    -2073432256, 0
                                }
                            }
                            , seedsAllowedAndMultiplier = new Dictionary<int, int>() {
                                {
                                    122783240, 1
                                }
                                , {
                                    -1037472336, 1
                                }
                                , {
                                    803954639, 1
                                }
                                , {
                                    998894949, 1
                                }
                                , {
                                    1911552868, 1
                                }
                                , {
                                    -1776128552, 1
                                }
                                , {
                                    -237809779, 1
                                }
                                , {
                                    -2084071424, 1
                                }
                                , {
                                    -1511285251, 1
                                }
                                , {
                                    830839496, 1
                                }
                                , {
                                    -992286106, 1
                                }
                                , {
                                    -520133715, 1
                                }
                                , {
                                    838831151, 1
                                }
                                , {
                                    -778875547, 1
                                }
                                , {
                                    -1305326964, 1
                                }
                                , {
                                    -886280491, 1
                                }
                                , {
                                    1512054436, 1
                                }
                                , {
                                    1898094925, 1
                                }
                                , {
                                    2133269020, 1
                                }
                                , {
                                    1533551194, 1
                                }
                                , {
                                    390728933, 1
                                }
                                , {
                                    -798662404, 1
                                }
                                , {
                                    1004843240, 1
                                }
                                , {
                                    912235912, 1
                                }
                                , {
                                    1412103380, 1
                                }
                                , {
                                    924598634, 1
                                }
                                , {
                                    -1790885730, 1
                                }
                                , {
                                    -19360132, 1
                                }
                            }
                        }
                    }
                    , {
                        "autofarm.vip", new vipInfo() {
                            AddSprinkler = false, AddStorageAdapter = false, BoxStorageSlots = 6, heatExposure = false, lightExposure = false, SprinklerNeedsWater = true, totalFarms = 5, seedStorageSlots = 6, cloneList = new Dictionary<string, string>() {
                                {
                                    "orchid", "Sapling"
                                }
                                , {
                                    "sunflower", "Sapling"
                                }
                                , {
                                    "wheat", "Sapling"
                                }
                                , {
                                    "rose", "Sapling"
                                }
                                , {
                                    "blue_berry", "Sapling"
                                }
                                , {
                                    "white_berry", "Sapling"
                                }
                                , {
                                    "red_berry", "Sapling"
                                }
                                , {
                                    "green_berry", "Sapling"
                                }
                                , {
                                    "black_berry", "Sapling"
                                }
                                , {
                                    "yellow_berry", "Sapling"
                                }
                                , {
                                    "pumpkin", "Sapling"
                                }
                                , {
                                    "potato", "Sapling"
                                }
                                , {
                                    "hemp", "Sapling"
                                }
                                , {
                                    "corn", "Sapling"
                                }
                            }
                            , knifeList = new Dictionary<int, int>() {
                                {
                                    1814288539, 0
                                }
                                , {
                                    -194509282, 0
                                }
                                , {
                                    2040726127, 0
                                }
                                , {
                                    -2073432256, 0
                                }
                            }
                            , seedsAllowedAndMultiplier = new Dictionary<int, int>() {
                                {
                                    122783240, 1
                                }
                                , {
                                    -1037472336, 1
                                }
                                , {
                                    803954639, 1
                                }
                                , {
                                    998894949, 1
                                }
                                , {
                                    1911552868, 1
                                }
                                , {
                                    -1776128552, 1
                                }
                                , {
                                    -237809779, 1
                                }
                                , {
                                    -2084071424, 1
                                }
                                , {
                                    -1511285251, 1
                                }
                                , {
                                    830839496, 1
                                }
                                , {
                                    -992286106, 1
                                }
                                , {
                                    -520133715, 1
                                }
                                , {
                                    838831151, 1
                                }
                                , {
                                    -778875547, 1
                                }
                                , {
                                    -1305326964, 1
                                }
                                , {
                                    -886280491, 1
                                }
                                , {
                                    1512054436, 1
                                }
                                , {
                                    1898094925, 1
                                }
                                , {
                                    2133269020, 1
                                }
                                , {
                                    1533551194, 1
                                }
                                , {
                                    390728933, 1
                                }
                                , {
                                    -798662404, 1
                                }
                                , {
                                    1004843240, 1
                                }
                                , {
                                    912235912, 1
                                }
                                , {
                                    1412103380, 1
                                }
                                , {
                                    924598634, 1
                                }
                                , {
                                    -1790885730, 1
                                }
                                , {
                                    -19360132, 1
                                }
                            }
                        }
                    }
                    , {
                        "autofarm.advanced", new vipInfo() {
                            AddSprinkler = true, AddStorageAdapter = true, BoxStorageSlots = 12, heatExposure = false, lightExposure = false, SprinklerNeedsWater = false, totalFarms = 10, seedStorageSlots = 12, cloneList = new Dictionary<string, string>() {
                                {
                                    "orchid", "Sapling"
                                }
                                , {
                                    "sunflower", "Sapling"
                                }
                                , {
                                    "wheat", "Sapling"
                                }
                                , {
                                    "rose", "Sapling"
                                }
                                , {
                                    "blue_berry", "Sapling"
                                }
                                , {
                                    "white_berry", "Sapling"
                                }
                                , {
                                    "red_berry", "Sapling"
                                }
                                , {
                                    "green_berry", "Sapling"
                                }
                                , {
                                    "black_berry", "Sapling"
                                }
                                , {
                                    "yellow_berry", "Sapling"
                                }
                                , {
                                    "pumpkin", "Sapling"
                                }
                                , {
                                    "potato", "Sapling"
                                }
                                , {
                                    "hemp", "Sapling"
                                }
                                , {
                                    "corn", "Sapling"
                                }
                            }
                            , knifeList = new Dictionary<int, int>() {
                                {
                                    1814288539, 0
                                }
                                , {
                                    -194509282, 0
                                }
                                , {
                                    2040726127, 0
                                }
                                , {
                                    -2073432256, 0
                                }
                            }
                            , seedsAllowedAndMultiplier = new Dictionary<int, int>() {
                                {
                                    122783240, 1
                                }
                                , {
                                    -1037472336, 1
                                }
                                , {
                                    803954639, 1
                                }
                                , {
                                    998894949, 1
                                }
                                , {
                                    1911552868, 1
                                }
                                , {
                                    -1776128552, 1
                                }
                                , {
                                    -237809779, 1
                                }
                                , {
                                    -2084071424, 1
                                }
                                , {
                                    -1511285251, 1
                                }
                                , {
                                    830839496, 1
                                }
                                , {
                                    -992286106, 1
                                }
                                , {
                                    -520133715, 1
                                }
                                , {
                                    838831151, 1
                                }
                                , {
                                    -778875547, 1
                                }
                                , {
                                    -1305326964, 1
                                }
                                , {
                                    -886280491, 1
                                }
                                , {
                                    1512054436, 1
                                }
                                , {
                                    1898094925, 1
                                }
                                , {
                                    2133269020, 1
                                }
                                , {
                                    1533551194, 1
                                }
                                , {
                                    390728933, 1
                                }
                                , {
                                    -798662404, 1
                                }
                                , {
                                    1004843240, 1
                                }
                                , {
                                    912235912, 1
                                }
                                , {
                                    1412103380, 1
                                }
                                , {
                                    924598634, 1
                                }
                                , {
                                    -1790885730, 1
                                }
                                , {
                                    -19360132, 1
                                }
                            }
                        }
                    }
                }
                ;
                SaveConfig();
            }
            if (configData.settings.SprinklerRadius <= 0.0f) {
                configData.settings.SprinklerRadius = 1;
                SaveConfig();
            }
            if (configData.settings.LargePlanterSprinklerMinSoilSaturation <= 0) {
                configData.settings.LargePlanterSprinklerMinSoilSaturation = 5100;
                configData.settings.LargePlanterSprinklerMaxSoilSaturation = 6000;
                configData.settings.SmallPlanterSprinklerMinSoilSaturation = 1650;
                configData.settings.SmallPlanterSprinklerMaxSoilSaturation = 1750;
                SaveConfig();
            }
            NextTick(() => {
                int removeCount = 0;
                int totalPlanters = 0;
                if (pcdData.Planters.Count <= 0) return;
                for (int i = 0; i < pcdData.Planters.Count; i++) {
                    var element = pcdData.Planters.ElementAt(i);
                    var networkable = FindEntity(element.Key);
                    if (networkable == null || !(networkable is PlanterBox)) {
                        pcdData.Planters.Remove(element.Key);
                        removeCount++;
                    }
                    else {
                        totalPlanters++;
                        planterBoxBehavior mono = networkable.GetComponent<planterBoxBehavior>();
                        if (mono != null) UnityEngine.Object.DestroyImmediate(mono);
                        AddTheComponent(networkable, element.Value.configPerm);
                    }
                }
                SaveData();
                PrintWarning($"Removed {removeCount} planters not found from datafile, and reactivated {totalPlanters}");
            }
            );
        }
        private void AddTheComponent(BaseNetworkable networkable, string config) {
            if (string.IsNullOrEmpty(config) || !configData.vipInformation.ContainsKey(config)) config = configData.vipInformation.Keys.First();
            if (string.IsNullOrEmpty(config)) return;
            planterBoxBehavior mono = networkable.gameObject.AddComponent<planterBoxBehavior>();
            mono.config = configData.vipInformation[config];
            timer.Once(5, () => {
                if (_ != null && mono != null) mono.autoFill();
            }
            );
        }
        private void Unload() {
            foreach (BasePlayer player in BasePlayer.activePlayerList) CuiHelper.DestroyUi(player, Ui.Overlay.Screen.Panel);
            foreach (planterBoxBehavior Controler in planterBoxBehavior._AllPlanters) UnityEngine.Object.DestroyImmediate(Controler);
            foreach (BasePlayer player in BasePlayer.activePlayerList) {
                player.SendConsoleCommand("gametip.hidegametip");
            }
            _ = null;
        }
        private void RegisterPermissions() {
            if (configData.vipInformation != null && configData.vipInformation.Count > 0) foreach (var permVip in configData.vipInformation) permission.RegisterPermission(permVip.Key, this);
        }
#endregion
#region Config
        private ConfigData configData;
        class ConfigData {
            [JsonProperty(PropertyName = "Settings")]
            public Settings settings {
                get;
                set;
            }
            [JsonProperty(PropertyName = "Permission needed and options")]
            public Dictionary<string, vipInfo> vipInformation {
                get;
                set;
            }
            public class Settings {
                [JsonProperty(PropertyName = "Disable autofarm placement by default /autofarm")]
                public bool DisablePlacementByDefault {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "How far can sprinkler water")]
                public float SprinklerRadius {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Large Box Sprinkler On Soil Saturation Level")]
                public int LargePlanterSprinklerMinSoilSaturation {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Large Box Sprinkler OFF Soil Saturation Level")]
                public int LargePlanterSprinklerMaxSoilSaturation {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Small Box Sprinkler On Soil Saturation Level")]
                public int SmallPlanterSprinklerMinSoilSaturation {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Small Box Sprinkler OFF Soil Saturation Level")]
                public int SmallPlanterSprinklerMaxSoilSaturation {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Enable for use in plugins that require CallHookOnCollectiblePickup")]
                public bool CallHookOnCollectiblePickup {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Enable weed pick from Ganja plugin")]
                public bool GanjaPluginEnable {
                    get;
                    set;
                }
            }
            public Oxide.Core.VersionNumber Version {
                get;
                set;
            }
        }
        protected override void LoadConfig() {
            base.LoadConfig();
            configData = Config.ReadObject<ConfigData>();
            if (configData.Version < Version) UpdateConfigValues();
            Config.WriteObject(configData, true);
        }
        protected override void LoadDefaultConfig() => configData = GetBaseConfig();
        private ConfigData GetBaseConfig() {
            return new ConfigData {
                settings = new ConfigData.Settings {
                    DisablePlacementByDefault = false, SprinklerRadius = 1.0f, LargePlanterSprinklerMinSoilSaturation = 5100, LargePlanterSprinklerMaxSoilSaturation = 6000, SmallPlanterSprinklerMinSoilSaturation = 1650, SmallPlanterSprinklerMaxSoilSaturation = 1750, CallHookOnCollectiblePickup = false, GanjaPluginEnable = false,
                }
                , Version = Version
            }
            ;
        }
        protected override void SaveConfig() => Config.WriteObject(configData, true);
        private void UpdateConfigValues() {
            PrintWarning("Config update detected! Updating config values...");
            ConfigData baseConfig = GetBaseConfig();
            if (configData.Version < new VersionNumber(3, 0, 0)) configData = baseConfig;
            configData.Version = Version;
            PrintWarning("Config update completed!");
        }
        public class vipInfo {
            [JsonProperty(PropertyName = "How many auto farms they allowed to have")]
            public int totalFarms {
                get;
                set;
            }
            [JsonProperty(PropertyName = "How many slots in seed container")]
            public int seedStorageSlots {
                get;
                set;
            }
            [JsonProperty(PropertyName = "How many slots in output container")]
            public int BoxStorageSlots {
                get;
                set;
            }
            [JsonProperty(PropertyName = "Add sprinkler to planter")]
            public bool AddSprinkler {
                get;
                set;
            }
            [JsonProperty(PropertyName = "Sprinkler needs water hookup to work")]
            public bool SprinklerNeedsWater {
                get;
                set;
            }
            [JsonProperty(PropertyName = "Add storage adapters")]
            public bool AddStorageAdapter {
                get;
                set;
            }
            [JsonProperty(PropertyName = "Always Light Exposure 100%")]
            public bool lightExposure {
                get;
                set;
            }
            [JsonProperty(PropertyName = "Always Temperature Exposure 100%")]
            public bool heatExposure {
                get;
                set;
            }
            [JsonProperty(PropertyName = "Allowed seed itemID's and multiplier amount to get on auto gather")]
            public Dictionary<int, int> seedsAllowedAndMultiplier {
                get;
                set;
            }
            [JsonProperty(PropertyName = "Enable cloning with knife")]
            public bool enableCloning {
                get;
                set;
            }
            [JsonProperty(PropertyName = "Allowed To Clone And Stage ")]
            public Dictionary<string, string> cloneList {
                get;
                set;
            }
            [JsonProperty(PropertyName = "Available tools And Clone Multiplier")]
            public Dictionary<int, int> knifeList {
                get;
                set;
            }
        }
#endregion Config
#region planerBox
        private struct PlanterConfig {
            public static PlanterConfig Small = new PlanterConfig {
                SprinklerPos = new Vector3(0f, 0.11f, 0f), SplitterPos = new Vector3(0, 0.1f, 0.5f), SplitterRot = Quaternion.Euler(0, 0, 0), FertilizerAdapterPos = new Vector3(0.5f, 0.30f, 0.0f), FertilizerAdapterRot = Quaternion.Euler(0, 0, 0), InputStoragePos = new Vector3(0.5f, 0.20f, 0.50f), InputStorageRot = Quaternion.Euler(0, 0, 90), InputAdapterPos = new Vector3(1.1f, 0.20f, 0.50f), InputAdapterRot = Quaternion.Euler(90, 0, 0), OutputStoragePos = new Vector3(-0.5f, 0.20f, 0.50f), OutputStorageRot = Quaternion.Euler(0, 0, 270), OutputAdapterPos = new Vector3(-1.1f, .20f, 0.50f), OutputAdapterRot = Quaternion.Euler(90, 0, 0),
            }
            ;
            public static PlanterConfig Minecart = new PlanterConfig {
                SprinklerPos = new Vector3(0f, 0.55f, 0f), SplitterPos = new Vector3(0, 0.36f, 0.75f), SplitterRot = Quaternion.Euler(0, 0, 0), FertilizerAdapterPos = new Vector3(0.55f, 0.75f, 0.3f), FertilizerAdapterRot = Quaternion.Euler(0, 0, 0), InputStoragePos = new Vector3(0.183f, 0.60f, 0.50f), InputStorageRot = Quaternion.Euler(0, 0, 0), InputAdapterPos = new Vector3(0.58f, 0.60f, 0.50f), InputAdapterRot = Quaternion.Euler(90, 0, 0), OutputStoragePos = new Vector3(-0.183f, 0.60f, 0.50f), OutputStorageRot = Quaternion.Euler(0, 0, 0), OutputAdapterPos = new Vector3(-0.58f, 0.60f, 0.50f), OutputAdapterRot = Quaternion.Euler(90, 0, 0),
            }
            ;
            public static PlanterConfig Bathtub = new PlanterConfig {
                SprinklerPos = new Vector3(0f, 0.35f, 0f), SplitterPos = new Vector3(0, 0.12f, 0.75f), SplitterRot = Quaternion.Euler(0, 0, 0), FertilizerAdapterPos = new Vector3(0.58f, 0.55f, 0.3f), FertilizerAdapterRot = Quaternion.Euler(0, 0, 0), InputStoragePos = new Vector3(0.183f, 0.32f, 0.50f), InputStorageRot = Quaternion.Euler(0, 0, 0), InputAdapterPos = new Vector3(0.58f, 0.40f, 0.50f), InputAdapterRot = Quaternion.Euler(90, 0, 0), OutputStoragePos = new Vector3(-0.183f, 0.32f, 0.50f), OutputStorageRot = Quaternion.Euler(0, 0, 0), OutputAdapterPos = new Vector3(-0.58f, 0.40f, 0.50f), OutputAdapterRot = Quaternion.Euler(90, 0, 0),
            }
            ;
            public static PlanterConfig Railroad = new PlanterConfig {
                SprinklerPos = new Vector3(0f, 0.13f, 0f), SplitterPos = new Vector3(0, 0.1f, 1.5f), SplitterRot = Quaternion.Euler(0, 0, 0), FertilizerAdapterPos = new Vector3(0.5f, 0.30f, 1.0f), FertilizerAdapterRot = Quaternion.Euler(0, 0, 0), InputStoragePos = new Vector3(0.5f, 0.20f, 1.40f), InputStorageRot = Quaternion.Euler(0, 0, 90), InputAdapterPos = new Vector3(1.1f, 0.20f, 1.42f), InputAdapterRot = Quaternion.Euler(90, 0, 0), OutputStoragePos = new Vector3(-0.5f, 0.20f, 1.40f), OutputStorageRot = Quaternion.Euler(0, 0, 270), OutputAdapterPos = new Vector3(-1.1f, 0.20f, 1.42f), OutputAdapterRot = Quaternion.Euler(90, 0, 0),
            }
            ;
            public static PlanterConfig Large = new PlanterConfig {
                SprinklerPos = new Vector3(0f, 0.11f, 0f), SplitterPos = new Vector3(0, 0.1f, 1.425f), SplitterRot = Quaternion.Euler(0, 0, 0), FertilizerAdapterPos = new Vector3(0.5f, 0.30f, 1.0f), FertilizerAdapterRot = Quaternion.Euler(0, 0, 0), InputStoragePos = new Vector3(0.5f, 0.20f, 1.40f), InputStorageRot = Quaternion.Euler(0, 0, 90), InputAdapterPos = new Vector3(1.1f, 0.20f, 1.40f), InputAdapterRot = Quaternion.Euler(90, 0, 0), OutputStoragePos = new Vector3(-0.5f, 0.20f, 1.40f), OutputStorageRot = Quaternion.Euler(0, 0, 270), OutputAdapterPos = new Vector3(-1.1f, 0.20f, 1.40f), OutputAdapterRot = Quaternion.Euler(90, 0, 0),
            }
            ;
            public static PlanterConfig Triangle = new PlanterConfig {
                SprinklerPos = new Vector3(-0.45f, 0.11f, 0f), SplitterPos = new Vector3(0.56f, 0.1f, 0f), SplitterRot = Quaternion.Euler(0, 90, 0), FertilizerAdapterPos = new Vector3(0.3f, 0.30f, 0.0f), FertilizerAdapterRot = Quaternion.Euler(0, 90, 0), InputStoragePos = new Vector3(0.55f, 0.20f, -0.50f), InputStorageRot = Quaternion.Euler(0, 90, 90), InputAdapterPos = new Vector3(0.55f, 0.20f, -0.98f), InputAdapterRot = Quaternion.Euler(90, 90, 0), OutputStoragePos = new Vector3(0.55f, 0.20f, 0.50f), OutputStorageRot = Quaternion.Euler(0, 90, 270), OutputAdapterPos = new Vector3(0.55f, 0.20f, 0.98f), OutputAdapterRot = Quaternion.Euler(90, 90, 0),
            }
            ;
            public Vector3 SprinklerPos;
            public Vector3 SplitterPos;
            public Quaternion SplitterRot;
            public Vector3 FertilizerAdapterPos;
            public Quaternion FertilizerAdapterRot;
            public Vector3 InputStoragePos;
            public Quaternion InputStorageRot;
            public Vector3 InputAdapterPos;
            public Quaternion InputAdapterRot;
            public Vector3 OutputStoragePos;
            public Quaternion OutputStorageRot;
            public Vector3 OutputAdapterPos;
            public Quaternion OutputAdapterRot;
        }
        private static PlanterConfig GetPlanterConfig(PlanterBox planterBox) {
            _.Puts(planterBox.ShortPrefabName);
            switch (planterBox.ShortPrefabName) {
                case "planter.small.deployed" : return PlanterConfig.Small;
                case "minecart.planter.deployed" : return PlanterConfig.Minecart;
                case "bathtub.planter.deployed" : return PlanterConfig.Bathtub;
                case "railroadplanter.deployed" : return PlanterConfig.Railroad;
                case "planter.triangle.deployed" : return PlanterConfig.Triangle;
                case "triangle_railroad_planter.deployed" : return PlanterConfig.Triangle;
                default : return PlanterConfig.Large;
            }
        }
        class planterBoxBehavior : FacepunchBehaviour {
            public static List<planterBoxBehavior> _AllPlanters = new List<planterBoxBehavior>();
            public static Dictionary<ulong, planterBoxBehavior> _AllLootingPlayers = new Dictionary<ulong, planterBoxBehavior>();
            public PlanterBox planterBox {
                get;
                set;
            }
            public ulong ownerplayer {
                get;
                set;
            }
            public vipInfo config {
                get;
                set;
            }
            private StorageContainer container {
                get;
                set;
            }
            private StorageContainer containerSeeds {
                get;
                set;
            }
            private Sprinkler sprinkler {
                get;
                set;
            }
            private Splitter waterSource {
                get;
                set;
            }
            private ItemDefinition itemDefinition {
                get;
                set;
            }
            private DateTime lastRotate {
                get;
                set;
            }
            private int totalslotsAvailable = 11;
            private float splashRadius = 6f;
            private int soilSaturationON {
                get;
                set;
            }
            private int soilSaturationOFF {
                get;
                set;
            }
            private float nextAutofiltime {
                get;
                set;
            }
            public Item cloningItem {
                get;
                set;
            }
            public bool currentState {
                get;
                set;
            }
            public PlanterConfig planterConfig {
                get;
                set;
            }
            public IndustrialStorageAdaptor OutputAdapter {
                get;
                set;
            }
            public IndustrialStorageAdaptor InputAdapter {
                get;
                set;
            }
            public IndustrialStorageAdaptor FertilizerAdapter {
                get;
                set;
            }
            public bool getAlwaysLight {
                get;
                set;
            }
            public bool getAlwaysTemp {
                get;
                set;
            }
            private void Awake() {
                planterBox = GetComponent<PlanterBox>();
                _AllPlanters.Add(this);
                planterConfig = GetPlanterConfig(planterBox);
                if (!_.playerTotals.ContainsKey(planterBox.OwnerID)) _.playerTotals.Add(planterBox.OwnerID, 1);
                else _.playerTotals[planterBox.OwnerID]++;
                ownerplayer = planterBox.OwnerID;
                splashRadius = _.configData.settings.SprinklerRadius;
                _.timer.Once(1, () => {
                    if (config.lightExposure) getAlwaysLight = true;
                    if (config.heatExposure) getAlwaysTemp = true;
                    generateStorage();
                    float delay = random.Next(300, 600);
                    currentState = _.pcdData.Planters[planterBox.net.ID.Value].currentState;
                    if (!currentState) {
                        if (config.seedStorageSlots > 0 && config.BoxStorageSlots > 0) InvokeRepeating("isPlanterFull", delay, 601);
                    }
                    else {
                        if (!config.SprinklerNeedsWater && IsInvoking("WaterPlants")) CancelInvoke("WaterPlants");
                    }
                    if (config.seedStorageSlots > 0 && config.BoxStorageSlots > 0) autoFill();
                }
                );
            }
            public void SetPlant(GrowableEntity plant) {
                if (getAlwaysLight || getAlwaysTemp) plant.GetOrAddComponent<plantBoxBehavior>().SetUp(getAlwaysLight, getAlwaysTemp);
            }
            private void setTotalAvailableSlots() {
                switch (planterBox.ShortPrefabName) {
                    case "planter.triangle.deployed" : totalslotsAvailable = 4;
                    soilSaturationON = _.configData.settings.SmallPlanterSprinklerMinSoilSaturation;
                    soilSaturationOFF = _.configData.settings.SmallPlanterSprinklerMaxSoilSaturation;
                    break;
                    case "triangle_railroad_planter.deployed" : case "minecart.planter.deployed" : totalslotsAvailable = 4;
                    soilSaturationON = _.configData.settings.SmallPlanterSprinklerMinSoilSaturation;
                    soilSaturationOFF = _.configData.settings.SmallPlanterSprinklerMaxSoilSaturation;
                    break;
                    case "planter.small.deployed" : case "bathtub.planter.deployed" : totalslotsAvailable = 5;
                    soilSaturationON = _.configData.settings.SmallPlanterSprinklerMinSoilSaturation;
                    soilSaturationOFF = _.configData.settings.SmallPlanterSprinklerMaxSoilSaturation;
                    break;
                    default : soilSaturationON = _.configData.settings.LargePlanterSprinklerMinSoilSaturation;
                    soilSaturationOFF = _.configData.settings.LargePlanterSprinklerMaxSoilSaturation;
                    break;
                }
                if (OutputAdapter != null) totalslotsAvailable++;
                if (InputAdapter != null) totalslotsAvailable++;
                if (FertilizerAdapter != null) totalslotsAvailable++;
                if (sprinkler != null) totalslotsAvailable++;
                if (waterSource != null) totalslotsAvailable++;
            }
            public void switchState(BasePlayer player, bool newState) {
                currentState = newState;
                _.pcdData.Planters[planterBox.net.ID.Value].currentState = newState;
                _.SaveData();
                if (newState == true) {
                    if (!config.SprinklerNeedsWater && IsInvoking("WaterPlants")) {
                        CancelInvoke("WaterPlants");
                        if (sprinkler != null && sprinkler.IsOn()) {
                            sprinkler.TurnOff();
                            if (this.IsInvoking(new Action(DoSplash))) this.CancelInvoke(new Action(DoSplash));
                        }
                    }
                    if (IsInvoking("isPlanterFull")) CancelInvoke("isPlanterFull");
                }
                else {
                    float delay = random.Next(300, 600);
                    if (!config.SprinklerNeedsWater && !IsInvoking("WaterPlants")) InvokeRepeating("WaterPlants", 10, 30);
                    if (!IsInvoking("isPlanterFull") && config.seedStorageSlots > 0 && config.BoxStorageSlots > 0) InvokeRepeating("isPlanterFull", delay, 601);
                    autoFill();
                }
            }
            public void Rotate() {
                if (lastRotate < DateTime.Now) {
                    var degrees = 90;
                    if (planterBox.ShortPrefabName == "planter.triangle.deployed" || planterBox.ShortPrefabName == "triangle_railroad_planter.deployed") degrees = 120;
                    lastRotate = DateTime.Now.AddSeconds(2);
                    transform.Rotate(0, degrees, 0);
                    if (sprinkler != null) UpdateLocalPositionAndRotation(transform, sprinkler, planterConfig.SprinklerPos, Quaternion.identity, true);
                    planterBox.SendNetworkUpdateImmediate(true);
                }
            }
            public bool pickUpPlanter(BasePlayer player) {
                if (containerSeeds != null) {
                    if (containerSeeds.inventory.itemList.Count > 0) {
                        _.GameTips(player, _.lang.GetMessage("noPickup", _, player.UserIDString));
                        return false;
                    }
                    else if (container.inventory.itemList.Count > 0) {
                        _.GameTips(player, _.lang.GetMessage("noPickup", _, player.UserIDString));
                        return false;
                    }
                    else if (planterBox.inventory.itemList.Count > 0) {
                        _.GameTips(player, _.lang.GetMessage("noPickup", _, player.UserIDString));
                        return false;
                    }
                    int itemIdToGet;
                    switch (planterBox.ShortPrefabName) {
                        case "minecart.planter.deployed" : itemIdToGet = 1361520181;
                        break;
                        case "planter.small.deployed" : itemIdToGet = 1903654061;
                        break;
                        case "bathtub.planter.deployed" : itemIdToGet = -1274093662;
                        break;
                        case "railroadplanter.deployed" : itemIdToGet = 615112838;
                        break;
                        case "triangle_railroad_planter.deployed" : itemIdToGet = 647240052;
                        break;
                        case "planter.triangle.deployed" : itemIdToGet = -280812482;
                        break;
                        default : itemIdToGet = 1581210395;
                        break;
                    }
                    var planterItem = ItemManager.CreateByItemID(itemIdToGet, 1, 0);
                    _.NextTick(() => {
                        if (planterItem != null) {
                            player.GiveItem(planterItem, BaseEntity.GiveItemReason.PickedUp);
                            planterBox.Kill();
                        }
                    }
                    );
                }
                return true;
            }
            private void generateStorage() {
                // Search radius, for entities that are not parented to the planter.var entitySearchRadius = 0.1f;
                bool fertilizerBoxAdapter = false;
                if (config.AddSprinkler) {
                    var sprinklerOld = GetNearbyEntity<Sprinkler>(planterBox.transform.TransformPoint(planterConfig.SprinklerPos), entitySearchRadius) ?? GetNearbyEntity<Sprinkler>(planterBox.transform.TransformPoint(PlanterConfig.Large.SprinklerPos), entitySearchRadius);
                    if (sprinklerOld != null && sprinklerOld.GetComponentInParent<PlanterBox>() == null) {
                        sprinklerOld.SetParent(planterBox, true);
                        UpdateLocalPositionAndRotation(transform, sprinklerOld, planterConfig.SprinklerPos, Quaternion.identity);
                    }
                }
                if (config.SprinklerNeedsWater && config.AddSprinkler) {
                    var waterSourceOld = GetNearbyEntity<Splitter>(planterBox.transform.TransformPoint(planterConfig.SplitterPos), entitySearchRadius) ?? GetNearbyEntity<Splitter>(planterBox.transform.TransformPoint(PlanterConfig.Large.SplitterPos), entitySearchRadius);
                    if (waterSourceOld != null && waterSourceOld.GetComponentInParent<PlanterBox>() == null) {
                        waterSourceOld.SetParent(planterBox, true);
                        UpdateLocalPositionAndRotation(transform, waterSourceOld, planterConfig.SplitterPos, planterConfig.SplitterRot);
                    }
                }
                List <BaseEntity> tampEntity = Pool.Get<List<BaseEntity>>();
                tampEntity.AddRange(planterBox.children);
                foreach (BaseEntity child in tampEntity) {
                    if (child == null) continue;
                    if (child is IndustrialStorageAdaptor) {
                        UpdateLocalPositionAndRotation(transform, child, planterConfig.FertilizerAdapterPos, planterConfig.FertilizerAdapterRot);
                        if (child.name != "NoPickUp") {
                            child.name = "NoPickUp";
                        }
                        FertilizerAdapter = child as IndustrialStorageAdaptor;
   
// ... [Code preview truncated due to length. Full source in attached file] ...

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