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

FREE DeployableNature : 1.0.15 1.0.15

Нет прав для скачивания
C#:
using Facepunch;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Configuration;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
/* Add NPC spawn option for shop access.* 
 * 
 */
/* 1.0.15 changes
 * Added config option to change the item drop chance from per hit to per node.* Added support for GatherRewards
 * Stopped those pesky horses from eating your deployed entities.*/
namespace Oxide.Plugins {
    [Info("DeployableNature", "imthenewguy", "1.0.15")]
    [Description("Makes nature deployable.")]
    class DeployableNature : RustPlugin {
#region Config
        private Configuration config;
        public class Configuration {
            [JsonProperty("Maximum number of rocks that a player can deploy [0 = no limit]")]
            public int max_rocks = 0;
            [JsonProperty("Maximum number of trees that a player can deploy [0 = no limit]")]
            public int max_trees = 0;
            [JsonProperty("Maximum number of bushes that a player can deploy [0 = no limit]")]
            public int max_bushes = 0;
            [JsonProperty("Maximum number of animals that a player can deploy [0 = no limit]")]
            public int max_animals = 3;
            [JsonProperty("Mining node drop rate [%] - [0 = off]")]
            public int drop_rate_from_node = 1;
            [JsonProperty("Tree drop rate [%] - [0 = off]")]
            public int drop_rate_from_tree = 1;
            [JsonProperty("Animal drop rate [%] - [0 = off]")]
            public int drop_rate_from_animal = 1;
            [JsonProperty("Roll the chance on each hit [false - will only roll once per tree/node/corpse]")]
            public bool roll_chance_on_each_hit = true;
            [JsonProperty("Animals only drop from their corpse type [bear only drops from harvesting bear corpses]?")]
            public bool animal_specific_drops = true;
            [JsonProperty("Prevent wild animals from targeting and killing deployed animals?")]
            public bool prevent_animal_targeting = true;
            [JsonProperty("Collectable plant drop rate [%] - [0 = off]")]
            public int drop_rate_from_collectables = 5;
            [JsonProperty("Chance for loot to be added to a minecart when it spawns [%] - [0 = off]")]
            public int drop_rate_from_minecart = 10;
            [JsonProperty("Allow players to hold sprint while placing a rock to have it embed into the ground?")]
            public bool shift_place = true;
            [JsonProperty("How much deeper should the rock sink when shift-placing?")]
            public float depth_modifier = 0.5f;
            [JsonProperty("Currency to use [SCRAP, ECONOMICS, SR, CUSTOM]")]
            public string currency = "SCRAP";
            [JsonProperty("Custom currency details")]
            public CustomCurrency custom_currency = new CustomCurrency();
            [JsonProperty("Enable players to buy prfabs from the market?")]
            public bool market_enabled = true;
            [JsonProperty("Nature market command")]
            public string market_cmd = "naturemarket";
            [JsonProperty("How often should the chat message post telling players how to access the deployable nature market? (seconds) 0 = off")]
            public float chat_delay = 600f;
            [JsonProperty("Prevent deployable items from being recycled")]
            public bool prevent_recycling = true;
            [JsonProperty("Display a chat message when a player pulls out a hammer for the first time, reminding them that they can remove deployables")]
            public bool notify_player_with_hammer = false;
            [JsonProperty("Notify how to remove items after first deploy")]
            public bool notify_after_first_Deploy = true;
            [JsonProperty("Allow players to use their middle mouse button to remove an item with a hammer (they can still use chat command regardless if they have perms)")]
            public bool use_input_command = true;
            [JsonProperty("Automatically add new types to the config?")]
            public bool auto_update = false;
            [JsonProperty("Respawn delay when an entity is collected that isnt supposed to be")]
            public float collectible_respawn_delay = 1f;
            [JsonProperty("Kill all deployed nature when the associated cupboard is deployed?")]
            public bool cupboard_kill = false;
            [JsonProperty("Allow team mates to pickup their members items")]
            public bool team_pickup = true;
            [JsonProperty("Allow TC authed players to pickup items")]
            public bool auth_pickup = true;
            [JsonProperty("Allow DeployableNature to control stack sizes? [Set to false if using a stacks plugin]")]
            public bool manage_stacks = true;
            [JsonProperty("Names of HumanNPCs that will open the market")]
            public List<string> market_npcs = new List<string>() {
                "Nature Market"
            }
            ;
            [JsonProperty("IDs of HumanNPCs that will open the market")]
            public List<ulong> market_npc_ids = new List<ulong>();
            [JsonProperty("Permissions that will receive a discount on the store cost when purchasing [1.0 is full price].Prefix with deployablenature.")]
            public Dictionary<string, float> discount_permissions = new Dictionary<string, float>();
            [JsonProperty("Prefab information", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<ulong, ItemInfo> Prefabs = new Dictionary<ulong, ItemInfo>();
            [JsonProperty("Tree prefabs", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<TreeType, TreeInfo> trees = new Dictionary<TreeType, TreeInfo>();
            [JsonProperty("Bush prefabs", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<BushType, BushInfo> bushes = new Dictionary<BushType, BushInfo>();
            public string ToJson() => JsonConvert.SerializeObject(this);
            public Dictionary<string, object> ToDictionary() => JsonConvert.DeserializeObject<Dictionary<string, object>>(ToJson());
        }
        protected override void LoadDefaultConfig() {
            config = new Configuration() {
                Prefabs = DefaultPrefabs, trees = DefaultTrees, bushes = DefaultBushes, custom_currency = new CustomCurrency() {
                    name = "cash", skinID = 2661030582, shortname = "blood"
                }
                , discount_permissions = new Dictionary<string, float>() {
                    ["deployablenature.vip"]
                    = 1.0f
                }
            }
            ;
        }
        private Dictionary<ulong, ItemInfo> DefaultPrefabs {
            get {
                return new Dictionary<ulong, ItemInfo> {
                    [2609145017]
                    = new ItemInfo(true, "medium clutter rock", "electric.teslacoil", "assets/bundled/prefabs/modding/admin/admin_rock_clutter_medium_d.prefab", 10, true, true, false, 3, 20, PrefabType.Rock, true, 10, "https://www.dropbox.com/s/lit5qotrz3dzo5s/medium%20clutter%20rock.png?dl=1"), [2668227876] = new ItemInfo(true, "small quarry rock", "electric.teslacoil", "assets/bundled/prefabs/modding/admin/admin_rock_quarry_small_a.prefab", 15, true, true, false, 3, 20, PrefabType.Rock, true, 10, "https://www.dropbox.com/s/hgd4lwzopde6zkv/small%20quarry%20rock.png?dl=1"), [2668228341] = new ItemInfo(true, "small rock formation", "electric.teslacoil", "assets/bundled/prefabs/modding/admin/admin_rock_formation_small_c.prefab", 15, true, true, false, 3, 20, PrefabType.Rock, true, 10, "https://www.dropbox.com/s/uvggj6pu9g0liwm/small%20rock%20formation.png?dl=1"), [2668228500] = new ItemInfo(true, "medium rock formation", "electric.teslacoil", "assets/bundled/prefabs/modding/admin/admin_rock_formation_medium_a.prefab", 15, true, true, false, 3, 20, PrefabType.Rock, true, 10, "https://www.dropbox.com/s/6dr34rizrmc1cyb/medium%20rock%20formation.png?dl=1"), [2668228817] = new ItemInfo(true, "arid medium cliff", "electric.teslacoil", "assets/bundled/prefabs/modding/admin/admin_cliff_medium_arc_arid_small.prefab", 15, true, true, false, 3, 20, PrefabType.Rock, true, 10, "https://www.dropbox.com/s/b7pvwgzrlej5p3x/arid%20medium%20cliff.png?dl=1"), [2668228981] = new ItemInfo(true, "large cliff", "electric.teslacoil", "assets/bundled/prefabs/modding/admin/admin_cliff_low_arc.prefab", 15, true, true, false, 3, 20, PrefabType.Rock, true, 10, "https://www.dropbox.com/s/ocbf43brdm9shio/large%20cliff.png?dl=1"), [2806644689] = new ItemInfo(true, "polar bear", "telephone", "assets/rust.ai/agents/bear/polarbear.prefab", 15, true, true, false, 1, 20, PrefabType.Animal, true, 10, "https://www.dropbox.com/s/4btmzlc8nr2shpo/polar%20bear.png?dl=1"), [2806645092] = new ItemInfo(true, "wolf", "telephone", "assets/rust.ai/agents/wolf/wolf.prefab", 15, true, true, false, 1, 20, PrefabType.Animal, true, 10, "https://www.dropbox.com/s/h7uagud141osqlc/wolf.png?dl=1"), [2806645210] = new ItemInfo(true, "stag", "telephone", "assets/rust.ai/agents/stag/stag.prefab", 15, true, true, false, 1, 20, PrefabType.Animal, true, 10, "https://www.dropbox.com/s/2kgljzh1b0plx67/stag.png?dl=1"), [2806645341] = new ItemInfo(true, "chicken", "telephone", "assets/rust.ai/agents/chicken/chicken.prefab", 15, true, true, false, 1, 20, PrefabType.Animal, true, 10, "https://www.dropbox.com/s/kwxi8x7knk83g27/chicken.png?dl=1"), [2806645547] = new ItemInfo(true, "bear", "telephone", "assets/rust.ai/agents/bear/bear.prefab", 15, true, true, false, 1, 20, PrefabType.Animal, true, 10, "https://www.dropbox.com/s/04faw4m5yul2o1v/bear.png?dl=1"), [2806645796] = new ItemInfo(true, "boar", "telephone", "assets/rust.ai/agents/boar/boar.prefab", 15, true, true, false, 1, 20, PrefabType.Animal, true, 10, "https://www.dropbox.com/s/s7bvbtctorqb1qo/boar.png?dl=1"), [2668843731] = new ItemInfo(true, "oak tree", "electric.teslacoil", TreeType.Oak, 15, true, true, false, 3, 20, PrefabType.Tree, true, 10, "https://www.dropbox.com/s/7bn4ptx2g3v8jyk/oak%20tree.png?dl=1"), [2668843336] = new ItemInfo(true, "beech tree", "electric.teslacoil", TreeType.Beech, 15, true, true, false, 3, 20, PrefabType.Tree, true, 10, "https://www.dropbox.com/s/py0m2m8i3yfocru/beech%20tree.png?dl=1"), [2668843556] = new ItemInfo(true, "birch tree", "electric.teslacoil", TreeType.Birch, 15, true, true, false, 3, 20, PrefabType.Tree, true, 10, "https://www.dropbox.com/s/q3f6wyuopgwzgfa/birch%20tree.png?dl=1"), [2668843841] = new ItemInfo(true, "palm tree", "electric.teslacoil", TreeType.Palm, 15, true, true, false, 3, 20, PrefabType.Tree, true, 10, "https://www.dropbox.com/s/5705n6xakmznd8o/palm%20tree.png?dl=1"), [2668843981] = new ItemInfo(true, "pine tree", "electric.teslacoil", TreeType.Pine, 15, true, true, false, 3, 20, PrefabType.Tree, true, 10, "https://www.dropbox.com/s/zq62yzmia8h1cmc/pine%20tree.png?dl=1"), [2668844123] = new ItemInfo(true, "swamp tree", "electric.teslacoil", TreeType.Swamp, 15, true, true, false, 3, 20, PrefabType.Tree, true, 10, "https://www.dropbox.com/s/r16q8nva7mvnvh1/swamp%20tree.png?dl=1"), [2830312612] = new ItemInfo(true, "cactus", "electric.teslacoil", TreeType.Cacti, 5, true, true, false, 3, 20, PrefabType.Tree, true, 10, "https://www.dropbox.com/s/nx6arvwerzfts7h/cactus.png?dl=1"), [2668860584] = new ItemInfo(true, "creosote bush", "electric.teslacoil", BushType.Creosote, 0, true, true, false, 3, 20, PrefabType.Bush, true, 10, "https://www.dropbox.com/s/4e651sbeodroqup/creosote%20bush.png?dl=1"), [2668861030] = new ItemInfo(true, "snow willow bush", "electric.teslacoil", BushType.Willow_snow, 0, true, true, false, 3, 20, PrefabType.Bush, true, 10, "https://www.dropbox.com/s/41k3rwsxg6847vb/snow%20willow%20bush.png?dl=1"), [2668861281] = new ItemInfo(true, "willow bush", "electric.teslacoil", BushType.Willow, 0, true, true, false, 3, 20, PrefabType.Bush, true, 10, "https://www.dropbox.com/s/xlu9mtasvov59g1/willow%20bush.png?dl=1"), [2668861630] = new ItemInfo(true, "spice bush", "electric.teslacoil", BushType.Spice, 0, true, true, false, 3, 20, PrefabType.Bush, true, 10, "https://www.dropbox.com/s/rlr5wb59rhx1u5z/spice%20bush.png?dl=1"), [2668861850] = new ItemInfo(true, "snow spice bush", "electric.teslacoil", BushType.Spice_snow, 0, true, true, false, 3, 20, PrefabType.Bush, true, 10, "https://www.dropbox.com/s/u8i0kihsqdhzcgw/snow%20spice%20bush.png?dl=1"), [2668807382] = new ItemInfo(true, "decorative corn", "electric.teslacoil", "assets/bundled/prefabs/autospawn/collectable/corn/corn-collectable.prefab", 0, true, true, false, 3, 20, PrefabType.Bush, true, 10, "https://www.dropbox.com/s/36k8im1ifr573m7/decorative%20corn.png?dl=1"), [2668906806] = new ItemInfo(true, "decorative pumpkin", "electric.teslacoil", "assets/bundled/prefabs/autospawn/collectable/pumpkin/pumpkin-collectable.prefab", 0, true, true, false, 3, 20, PrefabType.Bush, true, 10, "https://www.dropbox.com/s/pv45u1lmlg4e9y5/decorative%20pumpkin.png?dl=1"), [2668914014] = new ItemInfo(true, "decorative potato", "electric.teslacoil", "assets/bundled/prefabs/autospawn/collectable/potato/potato-collectable.prefab", 0, true, true, false, 3, 20, PrefabType.Bush, true, 10, "https://www.dropbox.com/s/35fbck53pzqwaku/decorative%20potato.png?dl=1"), [2668913894] = new ItemInfo(true, "decorative berries", "electric.teslacoil", BushType.Berries, 0, true, true, false, 3, 20, PrefabType.Bush, true, 10, "https://www.dropbox.com/s/wxgale7lp49205w/decorative%20berries.png?dl=1"), [2668914545] = new ItemInfo(true, "dect' mushroom", "electric.teslacoil", BushType.Mushrooms, 0, true, true, false, 3, 20, PrefabType.Bush, true, 10, "https://www.dropbox.com/s/azcodsqthlkqaju/dect%27%20mushroom.png?dl=1"), [2726178501] = new ItemInfo(true, "dect' hemp plant", "electric.teslacoil", "assets/bundled/prefabs/autospawn/collectable/hemp/hemp-collectable.prefab", 0, true, true, false, 3, 20, PrefabType.Bush, true, 10, "https://www.dropbox.com/s/e45sb8ocf6ymck2/dect%27%20hemp%20plant.png?dl=1")
                }
                ;
            }
        }
        private Dictionary<TreeType, TreeInfo> DefaultTrees {
            get {
                return new Dictionary<TreeType, TreeInfo> {
                    [TreeType.Beech]
                    = new TreeInfo(new List<string>() {
                        "assets/bundled/prefabs/autospawn/resource/v3_temp_field/american_beech_d.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_field/american_beech_e.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forest/american_beech_a.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forest/american_beech_a_dead.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forest/american_beech_b.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forest/american_beech_c.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forest_pine/american_beech_a.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forest_pine/american_beech_b.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forest_pine/american_beech_c.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forestside/american_beech_d.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forestside/american_beech_e.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forestside/american_beech_e_dead.prefab"
                    }
                    ), [TreeType.Birch] = new TreeInfo(new List<string>() {
                        "assets/bundled/prefabs/autospawn/resource/v3_temp_beachside/birch_small_temp.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_beachside/birch_tiny_temp.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_field/birch_small_temp.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_field/birch_tiny_temp.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forest/birch_big_temp.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forest/birch_large_temp.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forest/birch_medium_temp.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forest_pine/birch_big_temp.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forest_pine/birch_large_temp.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forestside/birch_medium_temp.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forestside/birch_small_temp.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forestside/birch_tiny_temp.prefab"
                    }
                    ), [TreeType.Oak] = new TreeInfo(new List<string>() {
                        "assets/bundled/prefabs/autospawn/resource/v3_temp_field/oak_e.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_field/oak_f.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_field_large/oak_b.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_field_large/oak_c.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_field_large/oak_d.prefab"
                    }
                    ), [TreeType.Palm] = new TreeInfo(new List<string>() {
                        "assets/bundled/prefabs/autospawn/resource/v3_arid_beachside/palm_tree_short_a_entity.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_beachside/palm_tree_short_b_entity.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_beachside/palm_tree_short_c_entity.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_beachside/palm_tree_small_a_entity.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_beachside/palm_tree_small_b_entity.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_beachside/palm_tree_small_c_entity.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_field/palm_tree_short_a_entity.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_field/palm_tree_short_b_entity.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_field/palm_tree_short_c_entity.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_field/palm_tree_small_b_entity.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_field/palm_tree_small_c_entity.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_forest/palm_tree_med_a_entity.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_forest/palm_tree_short_a_entity.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_forest/palm_tree_short_b_entity.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_forest/palm_tree_short_c_entity.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_forest/palm_tree_tall_a_entity.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_forest/palm_tree_tall_b_entity.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_forestside/palm_tree_short_a_entity.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_forestside/palm_tree_short_b_entity.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_forestside/palm_tree_short_c_entity.prefab"
                    }
                    ), [TreeType.Pine] = new TreeInfo(new List<string>() {
                        "assets/bundled/prefabs/autospawn/resource/v3_temp_field/pine_b.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_field/pine_d.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forest_pine/pine_a.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forest_pine/pine_c.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forestside_pine/pine_b.prefab", "assets/bundled/prefabs/autospawn/resource/v3_temp_forestside_pine/pine_d.prefab", "assets/bundled/prefabs/autospawn/resource/v3_tundra_field/pine_dead_d.prefab", "assets/bundled/prefabs/autospawn/resource/v3_tundra_field/pine_dead_e.prefab", "assets/bundled/prefabs/autospawn/resource/v3_tundra_field/pine_dead_f.prefab", "assets/bundled/prefabs/autospawn/resource/v3_tundra_field_pines/pine_a.prefab", "assets/bundled/prefabs/autospawn/resource/v3_tundra_field_pines/pine_b.prefab", "assets/bundled/prefabs/autospawn/resource/v3_tundra_field_pines/pine_d.prefab", "assets/bundled/prefabs/autospawn/resource/v3_tundra_forest/pine_a.prefab", "assets/bundled/prefabs/autospawn/resource/v3_tundra_forest/pine_c.prefab"
                    }
                    ), [TreeType.Swamp] = new TreeInfo(new List<string>() {
                        "assets/bundled/prefabs/autospawn/resource/swamp-trees/swamp_tree_a.prefab", "assets/bundled/prefabs/autospawn/resource/swamp-trees/swamp_tree_b.prefab", "assets/bundled/prefabs/autospawn/resource/swamp-trees/swamp_tree_c.prefab", "assets/bundled/prefabs/autospawn/resource/swamp-trees/swamp_tree_d.prefab", "assets/bundled/prefabs/autospawn/resource/swamp-trees/swamp_tree_e.prefab", "assets/bundled/prefabs/autospawn/resource/swamp-trees/swamp_tree_f.prefab"
                    }
                    ), [TreeType.Cacti] = new TreeInfo(new List<string>() {
                        "assets/bundled/prefabs/autospawn/resource/v3_arid_cactus/cactus-1.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_cactus/cactus-2.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_cactus/cactus-3.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_cactus/cactus-4.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_cactus/cactus-5.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_cactus/cactus-6.prefab", "assets/bundled/prefabs/autospawn/resource/v3_arid_cactus/cactus-7.prefab"
                    }
                    )
                }
                ;
            }
        }
        private Dictionary<BushType, BushInfo> DefaultBushes {
            get {
                return new Dictionary<BushType, BushInfo> {
                    [BushType.Creosote]
                    = new BushInfo(new List<string>() {
                        "assets/bundled/prefabs/autospawn/resource/v3_bushes_arid_desert/creosote_bush_c.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_arid_desert/creosote_bush_d.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_arid_dry/creosote_bush_dry_a.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_arid_dry/creosote_bush_dry_b.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_arid_grass/creosote_bush_a.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_arid_grass/creosote_bush_b.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_arid_grass/creosote_bush_c.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_arid_grass/creosote_bush_d.prefab"
                    }
                    ), [BushType.Spice] = new BushInfo(new List<string>() {
                        "assets/bundled/prefabs/autospawn/resource/v3_bushes_temp/bush_spicebush_a.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_temp/bush_spicebush_b.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_temp/bush_spicebush_c.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_temp/bush_spicebush_d.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_tundra/bush_spicebush_a.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_tundra/bush_spicebush_b.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_tundra/bush_spicebush_c.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_tundra/bush_spicebush_d.prefab"
                    }
                    ), [BushType.Spice_snow] = new BushInfo(new List<string>() {
                        "assets/bundled/prefabs/autospawn/resource/v3_bushes_arctic_forest/bush_spicebush_a_snow.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_arctic_forest/bush_spicebush_c_snow.prefab"
                    }
                    ), [BushType.Willow] = new BushInfo(new List<string>() {
                        "assets/bundled/prefabs/autospawn/resource/v3_bushes_temp/bush_willow_a.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_temp/bush_willow_b.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_temp/bush_willow_c.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_temp/bush_willow_d.prefab"
                    }
                    ), [BushType.Willow_snow] = new BushInfo(new List<string>() {
                        "assets/bundled/prefabs/autospawn/resource/v3_bushes_arctic/bush_willow_snow_a.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_arctic/bush_willow_snow_b.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_arctic/bush_willow_snow_c.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_arctic/bush_willow_snow_d.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_arctic/bush_willow_snow_small_a.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_arctic/bush_willow_snow_small_b.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_arctic_forest/bush_willow_snow_a.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_arctic_forest/bush_willow_snow_b.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_arctic_forest/bush_willow_snow_c.prefab", "assets/bundled/prefabs/autospawn/resource/v3_bushes_arctic_forest/bush_willow_snow_d.prefab"
                    }
                    ), [BushType.Berries] = new BushInfo(new List<string>() {
                        "assets/bundled/prefabs/autospawn/collectable/berry-black/berry-black-collectable.prefab", "assets/bundled/prefabs/autospawn/collectable/berry-blue/berry-blue-collectable.prefab", "assets/bundled/prefabs/autospawn/collectable/berry-green/berry-green-collectable.prefab", "assets/bundled/prefabs/autospawn/collectable/berry-red/berry-red-collectable.prefab", "assets/bundled/prefabs/autospawn/collectable/berry-white/berry-white-collectable.prefab", "assets/bundled/prefabs/autospawn/collectable/berry-yellow/berry-yellow-collectable.prefab"
                    }
                    ), [BushType.Mushrooms] = new BushInfo(new List<string>() {
                        "assets/bundled/prefabs/autospawn/collectable/mushrooms/mushroom-cluster-5.prefab", "assets/bundled/prefabs/autospawn/collectable/mushrooms/mushroom-cluster-6.prefab"
                    }
                    )
                }
                ;
            }
        }
        protected override void LoadConfig() {
            base.LoadConfig();
            try {
                config = Config.ReadObject<Configuration>();
                if (!config.ToDictionary().Keys.SequenceEqual(Config.ToDictionary(x => x.Key, x => x.Value).Keys)) {
                    PrintToConsole("Configuration appears to be outdated; updating and saving");
                }
            }
            catch (Exception ex) {
                Debug.LogException(ex);
                LoadDefaultConfig();
            }
            SaveConfig();
        }
        protected override void SaveConfig() {
            PrintToConsole($"Configuration changes saved to {Name}.json");
            Config.WriteObject(config, true);
        }
#endregion
#region Data
        PlayerEntity pcdData;
        private DynamicConfigFile PCDDATA;
        void Init() {
            PCDDATA = Interface.Oxide.DataFileSystem.GetFile(this.Name);
            permission.RegisterPermission("deployablenature.admin", this);
            permission.RegisterPermission("deployablenature.ignore.restrictions", this);
            permission.RegisterPermission("deployablenature.market.chat", this);
            permission.RegisterPermission("deployablenature.gather", this);
            permission.RegisterPermission("deployablenature.free", this);
            permission.RegisterPermission("deployablenature.use", this);
            if (!config.cupboard_kill) Unsubscribe("OnEntityDeath");
            var updated = false;
            if (config.auto_update) {
                if (UpdateBushes()) updated = true;
                if (UpdateTrees()) updated = true;
                if (UpdateItems()) updated = true;
            }
            if (updated) SaveConfig();
            if (!config.prevent_animal_targeting) Unsubscribe(nameof(OnNpcTarget));
            if (config.drop_rate_from_node == 0 && config.drop_rate_from_animal == 0 && config.drop_rate_from_collectables == 0) {
                Unsubscribe(nameof(OnDispenserBonus));
                Unsubscribe(nameof(OnDispenserGather));
            }
            else if (config.roll_chance_on_each_hit) Unsubscribe(nameof(OnDispenserBonus));
        }
        bool UpdateBushes() {
            var result = false;
            foreach (var def in DefaultBushes) {
                if (!config.bushes.ContainsKey(def.Key)) {
                    config.bushes.Add(def.Key, def.Value);
                    Puts($"Added new bush type: {def.Key}");
                    result = true;
                }
                else {
                    foreach (var path in def.Value.prefabs) {
                        if (!config.bushes[def.Key].prefabs.Contains(path)) {
                            config.bushes[def.Key].prefabs.Add(path);
                            Puts($"Added new bush to {def.Key}: {path}");
                            result = true;
                        }
                    }
                }
            }
            return result;
        }
        bool UpdateTrees() {
            var result = false;
            foreach (var def in DefaultTrees) {
                if (!config.trees.ContainsKey(def.Key)) {
                    config.trees.Add(def.Key, def.Value);
                    Puts($"Added new tree type: {def.Key}");
                    result = true;
                }
                else {
                    foreach (var path in def.Value.prefabs) {
                        if (!config.trees[def.Key].prefabs.Contains(path)) {
                            config.trees[def.Key].prefabs.Add(path);
                            Puts($"Added new tree to {def.Key}: {path}");
                            result = true;
                        }
                    }
                }
            }
            return result;
        }
        bool UpdateItems() {
            var result = false;
            foreach (var def in DefaultPrefabs) {
                if (!config.Prefabs.ContainsKey(def.Key)) {
                    config.Prefabs.Add(def.Key, def.Value);
                    result = true;
                    Puts($"Added new item: {def.Value.displayName}[{def.Key}]");
                }
            }
            return result;
        }
        void Unload() {
            SaveData();
            foreach (var player in BasePlayer.activePlayerList) {
                CuiHelper.DestroyUi(player, "NatureMarket");
                CuiHelper.DestroyUi(player, "MenuBackPanel");
            }
        }
        void Loaded() {
            LoadData();
        }
        void SaveData() {
            PCDDATA.WriteObject(pcdData);
        }
        void LoadData() {
            try {
                pcdData = Interface.Oxide.DataFileSystem.ReadObject<PlayerEntity>(this.Name);
            }
            catch {
                Puts("Couldn't load player data, creating new Playerfile");
                pcdData = new PlayerEntity();
            }
        }
        class PlayerEntity {
            public Dictionary<ulong, PCDInfo> pEntity = new Dictionary<ulong, PCDInfo>();
            public Dictionary<uint, PrefabInfo> rEntity = new Dictionary<uint, PrefabInfo>();
            public bool purgeEnabled = false;
        }
        public class CustomCurrency {
            public string name = null;
            public ulong skinID = 0;
            public string shortname = null;
        }
        class PCDInfo {
            public int deployed_rocks;
            public int deployed_trees;
            public int deployed_bushes;
            public int deployed_animals;
        }
        class PrefabInfo {
            public bool AuthDamageOnly;
            public int hits_taken;
            public int max_hits;
            public ulong skinID;
            public bool prevent_gather;
            public PrefabType type;
            public ulong ownerID;
            public Vector3 loc;
            public Vector3 rot;
            public string path;
            public uint tool_cupboard_id;
        }
        public class ItemInfo {
            public bool enabled;
            public string displayName;
            public string item_shortname;
            public string prefab_path;
            public int prefab_durability;
            public bool TCAuthRequired;
            public bool canBePickedUp;
            public bool authDamageOnly;
            public int max_spawn_quantity;
            public int max_stack_size;
            public PrefabType prefab_type;
            public bool prevent_gather;
            public TreeType treeType = TreeType.None;
            public BushType bushType = BushType.None;
            public double market_price;
            public string img_url;
            [JsonConstructor]
            public ItemInfo() {
            }
            public ItemInfo(bool enabled, string displayName, string item_shortname, string prefab_path, int prefab_durability, bool TCAuthRequired, bool canBePickedUp, bool authDamageOnly, int max_spawn_quantity, int max_stack_size, PrefabType prefab_type, bool prevent_gather, float market_price, string img_url) {
                this.enabled = enabled;
                this.displayName = displayName;
                this.item_shortname = item_shortname;
                this.prefab_path = prefab_path;
                this.prefab_durability = prefab_durability;
                this.TCAuthRequired = TCAuthRequired;
                this.canBePickedUp = canBePickedUp;
                this.authDamageOnly = authDamageOnly;
                this.max_spawn_quantity = max_spawn_quantity;
                this.max_stack_size = max_stack_size;
                this.prefab_type = prefab_type;
                this.prevent_gather = prevent_gather;
                this.market_price = market_price;
                this.img_url = img_url;
            }
            public ItemInfo(bool enabled, string displayName, string item_shortname, TreeType treeType, int prefab_durability, bool TCAuthRequired, bool canBePickedUp, bool authDamageOnly, int max_spawn_quantity, int max_stack_size, PrefabType prefab_type, bool prevent_gather, float market_price, string img_url) {
                this.enabled = enabled;
                this.displayName = displayName;
                this.item_shortname = item_shortname;
                this.treeType = treeType;
                this.prefab_durability = prefab_durability;
                this.TCAuthRequired = TCAuthRequired;
                this.canBePickedUp = canBePickedUp;
                this.authDamageOnly = authDamageOnly;
                this.max_spawn_quantity = max_spawn_quantity;
                this.max_stack_size = max_stack_size;
                this.prefab_type = prefab_type;
                this.prevent_gather = prevent_gather;
                this.market_price = market_price;
                this.img_url = img_url;
            }
            public ItemInfo(bool enabled, string displayName, string item_shortname, BushType bushType, int prefab_durability, bool TCAuthRequired, bool canBePickedUp, bool authDamageOnly, int max_spawn_quantity, int max_stack_size, PrefabType prefab_type, bool prevent_gather, float market_price, string img_url) {
                this.enabled = enabled;
                this.displayName = displayName;
                this.item_shortname = item_shortname;
                this.bushType = bushType;
                this.prefab_durability = prefab_durability;
                this.TCAuthRequired = TCAuthRequired;
                this.canBePickedUp = canBePickedUp;
                this.authDamageOnly = authDamageOnly;
                this.max_spawn_quantity = max_spawn_quantity;
                this.max_stack_size = max_stack_size;
                this.prefab_type = prefab_type;
                this.prevent_gather = prevent_gather;
                this.market_price = market_price;
                this.img_url = img_url;
            }
        }
        public class TreeInfo {
            public List<string> prefabs = new List<string>();
            public TreeInfo(List<string> prefabs) {
                this.prefabs = prefabs;
            }
        }
        public class BushInfo {
            public List<string> prefabs = new List<string>();
            public BushInfo(List<string> prefabs) {
                this.prefabs = prefabs;
            }
        }
        public enum PrefabType {
            Rock, Tree, Bush, Animal
        }
        public enum TreeType {
            None, Palm, Oak, Swamp, Birch, Beech, Pine, Cacti
        }
        public enum BushType {
            None, Willow, Willow_snow, Spice, Spice_snow, Creosote, Berries, Mushrooms
        }
        public string Prefix;
        public Dictionary<ulong, ItemInfo> loot_table_rocks = new Dictionary<ulong, ItemInfo>();
        public Dictionary<ulong, ItemInfo> loot_table_animals = new Dictionary<ulong, ItemInfo>();
        public Dictionary<ulong, ItemInfo> loot_table_trees = new Dictionary<ulong, ItemInfo>();
        public Dictionary<ulong, ItemInfo> loot_table_bushes = new Dictionary<ulong, ItemInfo>();
        public Dictionary<TreeType, List<string>> trees = new Dictionary<TreeType, List<string>>();
#endregion;
#region Localization
        protected override void LoadDefaultMessages() {
            lang.RegisterMessages(new Dictionary<string, string> {
                ["Prefix"]
                = "<color=#DFF008>[DN]</color>", ["WarnMarketCooldown"] = "{0} Please wait a second before buying another item.", ["NoPickup"] = "{0} You cannot collect this entity as it is decorative.", ["NoGather"] = "{0} You cannot gather from this entity as it is decorative.", ["PlacementLimit"] = "{0} You have reached your placement limit for this item type.", ["BuildAuthReq"] = "{0} You must have building auth in order to deploy this item.", ["NP"] = "{0} You cannot pick this entity up.", ["WP"] = "{0} Please wait a second before picking up another entity.", ["GiveItem"] = "{0} You Received {1}x {2}.", ["NotifyConsoleInvalid"] = "{0} Invalid skin: {1}.A list of valid keys has been printed to console.", ["NotifyOfConsole"] = "{0} Usage: /giveprefab <skin id> <optional: quantity>\nA list of valid keys has been printed to console.", ["NotifyInConsole"] = "{0}", ["NEC"] = "{0} You do not have enough {1} to purchase {2}x {3}.", ["broadcastmsg"] = "{0} You can type <color=#51ff00>/{1}</color> to access the Nature Market and purchase deployable nature items.", ["itemDisabled"] = "{0} This item has been disabled.", ["dnkillentities"] = "Removed all deployable nature entities", ["dnkillentitiesdata"] = "Removed all deployable nature entities and cleared data.", ["NoUsePerms"] = "You do not have permission to use Deployable Nature items.", ["PickupNotify"] = "You can collect your deployable nature items by looking at them with your <color=#ff8300>{0}</color> active, and pressing your <color=#ff8300>middle mouse button</color>, or by using the <color=#ff8300>/dnpickup</color> command.\nYou can also adjust the deployment height of the entity by holding down <color=#ff8300>shift</color> while deploying.", ["PickupNotifyNoInput"] = "You can collect your deployable nature items by looking at them while using the <color=#ff8300>/dnpickup</color> command.\nYou can also adjust the deployment height of the entity by holding down <color=#ff8300>shift</color> while deploying.", ["dnkillentitiesplayer"] = "Deleted {0} entities for {1}.", ["PurgeEnabled"] = "Purge enabled: {0}.\nYou can enable/disable with dnpurge true/false.", ["PurgeEnabledAnnouncement"] = "Purge is enabled and all deployable nature items have been deleted.", ["PurgeDisabledAnnouncement"] = "Purge is no longer enabled.You can now deploy nature entities."
            }
            , this);
        }
#endregion
#region Hooks
        List<ulong> shown = new List<ulong>();
        void OnActiveItemChanged(BasePlayer player, Item oldItem, Item newItem) {
            if (newItem != null && (newItem.info.shortname == "hammer" || newItem.info.shortname == "toolgun") && permission.UserHasPermission(player.UserIDString, "deployablenature.use") && !shown.Contains(player.userID)) {
                PrintToChat(player, config.use_input_command ? string.Format(lang.GetMessage("PickupNotify", this, player.UserIDString), newItem.info.displayName.english) : lang.GetMessage("PickupNotifyNoInput", this, player.UserIDString));
                shown.Add(player.userID);
            }
        }
        object CanNpcEat(BaseNpc npc, BaseEntity target) {
            if (npc == null || target == null) return null;
            if (IsDeployableNature(target)) return false;
            return null;
        }
        object OnItemRecycle(Item item, Recycler recycler) {
            if (config.Prefabs.ContainsKey(item.skin)) return false;
            return null;
        }
        object OnDispenserGather(ResourceDispenser dispenser, BasePlayer player, Item item) {
            if (dispenser == null) return null;
            if (config.roll_chance_on_each_hit) return HandleDispenserGather(dispenser, player, item);
            if (dispenser.gatherType != ResourceDispenser.GatherType.Flesh) return null;
            bool isFinalHit = true;
            foreach (var i in dispenser.containedItems) {
                if (i.amount > 0) {
                    isFinalHit = false;
                    break;
                }
            }
            if (isFinalHit) return HandleDispenserGather(dispenser, player, item);
            return null;
        }
        object OnDispenserBonus(ResourceDispenser dispenser, BasePlayer player, Item item) {
            return HandleDispenserGather(dispenser, player, item);
        }
        object HandleDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item) {
            object result = null;
            var player = entity as BasePlayer;
            PrefabInfo prefabData;
            if (pcdData.rEntity.TryGetValue(dispenser.baseEntity.net.ID, out prefabData) && prefabData.prevent_gather) {
                PrintToChat(player, string.Format(lang.GetMessage("NoGather", this, player.UserIDString), Prefix));
                result = false;
            }
            if (!permission.UserHasPermission(player.UserIDString, "deployablenature.gather")) return result;
            if (dispenser.gatherType == ResourceDispenser.GatherType.Ore && result == null && config.drop_rate_from_node > 0) {
                var roll = UnityEngine.Random.Range(1, 101);
                if (roll <= config.drop_rate_from_node) {
                    var randomRock = loot_table_rocks.ToList().GetRandom();
                    GiveItem(player, randomRock.Key, UnityEngine.Random.Range(1, randomRock.Value.max_spawn_quantity + 1));
                }
            }
            if (dispenser.gatherType == ResourceDispenser.GatherType.Tree && result == null && config.drop_rate_from_tree > 0) {
                var roll = UnityEngine.Random.Range(1, 101);
                if (roll <= config.drop_rate_from_tree) {
                    var randomTree = loot_table_trees.ToList().GetRandom();
                    GiveItem(player, randomTree.Key, UnityEngine.Random.Range(1, randomTree.Value.max_spawn_quantity + 1));
                }
            }
            if (dispenser.gatherType == ResourceDispenser.GatherType.Flesh && result == null && config.drop_rate_from_animal > 0) {
                var roll = UnityEngine.Random.Range(1, 101);
                if (roll <= config.drop_rate_from_animal) {
                    if (!config.animal_specific_drops) {
                        var randomAnimal = loot_table_animals.ToList().GetRandom();
                        GiveItem(player, randomAnimal.Key, UnityEngine.Random.Range(1, randomAnimal.Value.max_spawn_quantity + 1));
                    }
                    else {
                        var prefab = GetAnimalPrefab(dispenser.baseEntity.ShortPrefabName);
                        if (!string.IsNullOrEmpty(prefab)) {
                            foreach (var kvp in loot_table_animals) {
                                if (kvp.Value.prefab_path == prefab) {
                                    GiveItem(player, kvp.Key, UnityEngine.Random.Range(1, kvp.Value.max_spawn_quantity + 1));
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            return result;
        }
        string GetAnimalPrefab(string corpse_shortname) {
            switch (corpse_shortname) {
                case "bear.corpse" : return "assets/rust.ai/agents/bear/polarbear.prefab";
                case "polarbear.corpse" : return "assets/rust.ai/agents/bear/polarbear.prefab";
                case "chicken.corpse" : return "assets/rust.ai/agents/chicken/chicken.prefab";
                case "stag.corpse" : return "assets/rust.ai/agents/stag/stag.prefab";
                case "boar.corpse" : return "assets/rust.ai/agents/boar/boar.prefab";
                case "wolf.corpse" : return "assets/rust.ai/agents/wolf/wolf.prefab";
                default : return null;
            }
        }
        List<uint> old_net_IDs = new List<uint>();
        class CreationInfo {
            public string PrefabName;
            public Vector3 pos;
            public Quaternion rot;
            public ulong skinID;
            public ulong ownerID;
            public CreationInfo(string PrefabName, Vector3 pos, Quaternion rot, ulong skinID, ulong ownerID) {
                this.PrefabName = PrefabName;
                this.pos = pos;
                this.rot = rot;
                this.skinID = skinID;
                this.ownerID = ownerID;
            }
        }
        object OnCollectiblePickup(CollectibleEntity collectible, BaseRidableAnimal horse) {
            if (collectible == null || collectible.itemList == null || collectible.itemList.Length == 0) return null;
            PrefabInfo prefabData;
            if (pcdData.rEntity.TryGetValue(collectible.net.ID, out prefabData) && prefabData.prevent_gather) {
                return true;
            }
            return null;
        }
        object OnCollectiblePickup(CollectibleEntity collectible, BasePlayer player) {
            if (collectible == null || collectible.itemList == null || collectible.itemList.Length == 0 || player == null || player.IsNpc) return null;
            object result = null;
            PrefabInfo prefabData;
            if (pcdData.rEntity.TryGetValue(collectible.net.ID, out prefabData) && prefabData.prevent_gather && collectible.itemList != null) {
                PrintToChat(player, string.Format(lang.GetMessage("NoPickup", this, player.UserIDString), Prefix));
                result = true;
            }
            else {
                if (old_net_IDs.Contains(collectible.net.ID)) {
                    result = true;
                    old_net_IDs.Remove(collectible.net.ID);
                }
            }
            if (!permission.UserHasPermission(player.UserIDString, "deployable
// ... [Code preview truncated due to length. Full source in attached file] ...

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

Другие ресурсы пользователя 15FPS

Сверху