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

FREE TugMe : 1.0.3 1.0.3

Нет прав для скачивания
C#:
// Reference: 0Harmony
/*
 ▄▄▄▄    ███▄ ▄███▓  ▄████  ▄▄▄██▀▀▀▓█████▄▄▄█████▓
▓█████▄ ▓██▒▀█▀ ██▒ ██▒ ▀█▒   ▒██   ▓█   ▀▓  ██▒ ▓▒
▒██▒ ▄██▓██    ▓██░▒██░▄▄▄░   ░██   ▒███  ▒ ▓██░ ▒░
▒██░█▀  ▒██    ▒██ ░▓█  ██▓▓██▄██▓  ▒▓█  ▄░ ▓██▓ ░ 
░▓█  ▀█▓▒██▒   ░██▒░▒▓███▀▒ ▓███▒   ░▒████▒ ▒██▒ ░ 
░▒▓███▀▒░ ▒░   ░  ░ ░▒   ▒  ▒▓▒▒░   ░░ ▒░ ░ ▒ ░░   
▒░▒   ░ ░  ░      ░  ░   ░  ▒ ░▒░    ░ ░  ░   ░    
 ░    ░ ░      ░   ░ ░   ░  ░ ░ ░      ░    ░      
 ░             ░         ░  ░   ░      ░  ░
ToDo 1.0.4:
Mark Vendors on map option
Use kits for vendor attire option
Resources Buy SkinID Option
*/
using Facepunch;
using Harmony;
using Network;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Libraries;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using ProtoBuf;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Oxide.Plugins {
    [Info("TugMe", "bmgjet", "1.0.3")]
    [Description("Mod TugBoat")]
    class TugMe : RustPlugin {
        //Extenal Plugins
        [PluginReference]
        private Plugin ServerRewards, Economics;
        public static TugMe _plugin;
        //Self Reference
        private HarmonyInstance _harmony;
        //Harmony Instance
        //Variables
        Dictionary<NPCTalking, Vector3> TugDealers = new Dictionary<NPCTalking, Vector3>();
        //Store Tug sellers
        List<Tugboat> PoweredBoats = new List<Tugboat>();
        //Switch for powered tugboats to switch on IO
        List<Tugboat> EventBoats = new List<Tugboat>();
        //Current event tugboats
        List<ScientistNPC> ActiveNPCs = new List<ScientistNPC>();
        //List of active NPCs on server from this plugin
        Dictionary<BaseNetworkable, Tugboat> LootBoxes = new Dictionary<BaseNetworkable, Tugboat>();
        //List Of lootboxes
        List<Tugboat> PlayingEffect = new List<Tugboat>();
        //List of Tugboats playing Effect
        List<BasePlayer> VoicePlayers = new List<BasePlayer>();
        //List of NPCs used for VoiceOutput
        private List<MapMarkerGenericRadius> mapmarkersList = new List<MapMarkerGenericRadius>();
        //List of map markers
        List<Timer> timerList = new List<Timer>();
        //List Of running Timers
#region DataFile
        private StoredData storedData;
        private class StoredData {
            public List<ulong> AutoNav = new List<ulong>();
            //Users who have enabled auto nav
            public Dictionary<ulong, ulong> OwnedTugs = new Dictionary<ulong, ulong>();
            //networkID and OwnerID
        }
#endregion
#region CustomVendors
        //Setting for custom placed tugboat vendors
        public class CustomVendorPos {
            public Vector3 Position;
            public Vector3 Rotation;
            public Vector3 SpawnPoint;
            public CustomVendorPos init(Vector3 p, Vector3 r, Vector3 s) {
                Position = p;
                Rotation = r;
                SpawnPoint = s;
                return this;
            }
        }
#endregion
#region VendorsConfig
        //Setting for vendor positions
        public class VendorPos {
            public string PrefabPath;
            public Vector3 OffsetPosition;
            public Vector3 OffsetRotation;
            public Vector3 OffsetSpawnPoint;
            public VendorPos init(string m, Vector3 p, Vector3 r, Vector3 s) {
                PrefabPath = m;
                OffsetPosition = p;
                OffsetRotation = r;
                OffsetSpawnPoint = s;
                return this;
            }
        }
#endregion
#region TurretPositions
        //Setting for Turret Positions/Rotations
        public class TurretPos {
            public Vector3 Position;
            public Vector3 Rotation;
            public TurretPos init(Vector3 p, Vector3 r) {
                Position = p;
                Rotation = r;
                return this;
            }
        }
#endregion
#region Language
        protected override void LoadDefaultMessages() {
            lang.RegisterMessages(new Dictionary<string, string> {
                {
                    "Help", "Tugboat Help Info:"
                }
                , {
                    "Buy1", "You Can Buy Tug Boats @ "
                }
                , {
                    "H1", "Harbors "
                }
                , {
                    "FV", "Fishing Villages "
                }
                , {
                    "FT", "Ferry Terminals"
                }
                , {
                    "M1", "You can enable AutoNav with command /autonav"
                }
                , {
                    "M2", "It will take over driving if you dismount while full throttle."
                }
                , {
                    "M3", "You can spawn tug boat with command /tugboat"
                }
                , {
                    "M4", "You can remove tugs with command /tugremove ID"
                }
                , {
                    "M5", "You can place some things even while they show red"
                }
                , {
                    "M6", "You can mark owned tugs on the map with command /tugfind"
                }
                , {
                    "M7", "You can use horn while driving with mouse1"
                }
                , {
                    "M8", "There is a button while driving a tug that will let you toggle autonav"
                }
                , {
                    "M9", "Cannot spawn because you're <color=orange>building blocked!</color>"
                }
                , {
                    "M0", "Cannot spawn because you're <color=orange>below sea level</color>"
                }
                , {
                    "E1", "<color=red>Trying to spawn outside of terrain!</color>"
                }
                , {
                    "E2", "<color=red>You're trying to spawn it too far away!</color>"
                }
                , {
                    "E3", "Spawning this close will <color=red>KILL YOU!</color>"
                }
                , {
                    "E4", "<color=orange>Not enough open ocean area to spawn.</color>"
                }
                , {
                    "E5", "<color=orange>To close to a blocked prefab.</color>"
                }
                , {
                    "E6", "<color=orange>Tugboat already present within {0}m</color>"
                }
                , {
                    "E7", "<color=red>To close to a player</color>"
                }
                , {
                    "E8", "Spawned Tug Boat"
                }
                , {
                    "E9", "<color=orange>At Spawn Limit ({0})</color>"
                }
                , {
                    "E0", "Spawning Event @ {0}"
                }
                , {
                    "A0", "Killed TugID: {0} @ {1}"
                }
                , {
                    "A1", "You Don't Own This Tug Boat."
                }
                , {
                    "A2", "Not A Tug Boat"
                }
                , {
                    "A3", "Enter ID of tug to remove /tugremove ID"
                }
                , {
                    "A4", "TugID: {0} @ {1}"
                }
                , {
                    "A5", "You don't have TugMe.Remove Permission."
                }
                , {
                    "A6", "Found {0} tug boats."
                }
                , {
                    "A7", "You don't have TugMe.Find Permission."
                }
                , {
                    "A8", "Enabling AutoNav"
                }
                , {
                    "A9", "Disabling AutoNav"
                }
                , {
                    "B0", "You Don't Have AutoNav Permission"
                }
                , {
                    "B1", "AutoNav Requires The Engine To Be Running"
                }
                , {
                    "B2", "AutoNav Enabled"
                }
                , {
                    "B3", "AutoNav Disabled"
                }
                , {
                    "B4", "You need more resources:\n{0}"
                }
                , {
                    "B5", "ServerRewards not installed"
                }
                , {
                    "B6", "You can not afford to buy this"
                }
                , {
                    "B7", "Economics not installed"
                }
                , {
                    "B8", "Currency Type Not supported on this server"
                }
                , {
                    "B9", "Paid {0} for tug boat"
                }
                , {
                    "C0", "Buy Tug Boat\n"
                }
                , {
                    "C1", "Spawn New Tug Boat"
                }
                , {
                    "C2", "To close to {0}({1})"
                }
                , {
                    "C3", "You don't have TugMe.Buy Permission"
                }
                , {
                    "C4", "At Spawn Limit ({0})"
                }
                , {
                    "C5", "Bought Tug Boat."
                }
                , {
                    "C6", "Tug Event Started Near Grid {0}"
                }
                , {
                    "C7", "Teleported Tug: {0} To {1}"
                }
                , {
                    "C8", "You can teleport your tug to you with /tugtome"
                }
                , {
                    "C9", "You can rotate some deployables, hit with hammer + reload key"
                }
                , {
                    "D1", "Enter ID of tug to teleport /tugtome ID"
                }
                , {
                    "D2", "You don't have TugMe.Tome Permission."
                }
                ,
            }
            , this);
        }
        private string message(BasePlayer player, string key, params object[] args) {
            if (player == null) {
                return string.Format(lang.GetMessage(key, this), args);
            }
            return string.Format(lang.GetMessage(key, this, player.UserIDString), args);
        }
#endregion
#region Configuration
        private Configuration config;
        private class Configuration {
            [JsonProperty("Debug Mode")]
            public bool Debug = false;
            [JsonProperty("[Server] Block Native Tugboat Spawns")]
            public bool BlockNative = false;
            [JsonProperty("[Server] Enable PVE Support")]
            public bool PVESupport = false;
            [JsonProperty("[Server] Near Tug Radius")]
            public int NearTug = 35;
            [JsonProperty("[Chat] Message Icon (SteamID)")]
            public string AnnouncementIcon = "76561199381312678";
            [JsonProperty("[Chat] Message Name")]
            public string TugName = "<color=orange>TugBoat</color>";
            [JsonProperty("[MAP] Draw On Map TugBoats")]
            public bool MapFunction = false;
            [JsonProperty("[MAP] Refresh Rate")]
            public int MapRefresh = 60;
            [JsonProperty("[PirateTug] Number Of Tug Boats")]
            public int EventTug = 0;
            [JsonProperty("[PirateTug] End Event Timeout (sec)")]
            public int EventTimeout = 1800;
            [JsonProperty("[PirateTug] Refresh Tickrate (sec)")]
            public int EventTick = 120;
            [JsonProperty("[PirateTug] Announce Event Starts")]
            public bool SpawnAnnounce = false;
            [JsonProperty("[PirateTug] Announce Style")]
            public int AnnounceStyle = 1;
            [JsonProperty("[PirateTug] Mark Events On Map")]
            public bool MarkEvents = false;
            [JsonProperty("[PirateTug] Marker Alpha")]
            public float MarkerAlpha = 0.2f;
            [JsonProperty("[PirateTug] Marker Radius")]
            public float MarkerRadius = 0.5f;
            [JsonProperty("[PirateTug] Marker Color 1")]
            public string MarkerC1 = "#0098FF";
            [JsonProperty("[PirateTug] Marker Color 2")]
            public string MarkerC2 = "#FF0000";
            [JsonProperty("[PirateTug] Speed Multiplyer (Use Less Then 1 To Make NPC Tugs Slower)")]
            public float EventSpeed = 0.9f;
            [JsonProperty("[PirateTug] Loot Prefab (Used as loot profile)")]
            public string LootPrefab = "assets/prefabs/npc/patrol helicopter/heli_crate.prefab";
            [JsonProperty("[PirateTug] Loot Multiplyer")]
            public int LootMulti = 2;
            [JsonProperty("[PirateTug] Door Health")]
            public int DoorHealth = 8;
            [JsonProperty("[PirateTug] Start Fires After Loot Box Break (seconds)")]
            public int FireDelay = 10;
            [JsonProperty("[PirateTug] NPCs Health")]
            public int NPCHealth = 250;
            [JsonProperty("[PirateTug] NPCs AimScaler")]
            public int NPCAimScaler = 1;
            [JsonProperty("[PirateTug] NPCs DamageScaler")]
            public int NPCDamageScaler = 1;
            [JsonProperty("[PirateTug] NPCs Attack Range Multiplyer")]
            public int NPCAttackRange = 3;
            [JsonProperty("[PirateTug] NPCs Gun")]
            public string NPCGun = "rifle.semiauto";
            [JsonProperty("[PirateTug] NPCs Gun Attachment")]
            public string NPCGunAttachment = "weapon.mod.flashlight";
            [JsonProperty("[PirateTug] NPCs Attire")]
            public string NPCAttire = "hazmatsuit.diver";
            [JsonProperty("[PirateTug] NPCs Chatter Remote Asset")]
            public string ChatterURL = "";
            [JsonProperty("[PirateTug] NPCs Kill Remote Asset")]
            public string KillURL = "";
            [JsonProperty("[PirateTug] NPCs Death Remote Asset")]
            public string DeathURL = "";
            [JsonProperty("[PirateTug] NPC Spawn Positions")]
            public Vector3[] NPCSpawnPoints = new Vector3[] {
                new Vector3(2, 2.8f, -8), new Vector3(-2, 2.8f, -8), new Vector3(0, 6, 2.5f), new Vector3(0, 2.1f, 9), new Vector3(0, 8.7f, 2), new Vector3(0, 2.1f, 3.5f),
            }
            ;
            [JsonProperty("[PirateTug] AutoTurret Gun")]
            public string AutoTurretGun = "pistol.eoka";
            [JsonProperty("[PirateTug] AutoTurret Ammo Amount")]
            public int AutoTurretAmmo = 100;
            [JsonProperty("[PirateTug] AutoTurret Health")]
            public int AutoTurretHealth = 200;
            [JsonProperty("[PirateTug] AutoTurret Spawn Positions")]
            public TurretPos[] NPCAutoTurretPoints = new TurretPos[] {
                new TurretPos().init(new Vector3(0, 2, -1.49f), new Vector3(0, 180, 0)), new TurretPos().init(new Vector3(1.47f, 7.2f, -1.1f), new Vector3(0, 56, 0)), new TurretPos().init(new Vector3(-1.47f, 7.2f, -1.1f), new Vector3(0, 304, 0)),
            }
            ;
            [JsonProperty("[Boat Setting] Horn Remote Asset")]
            public string HornURL = "";
            [JsonProperty("[Boat Setting] Disable Tugboat Driver Check")]
            public bool DisableDriverCheck = false;
            [JsonProperty("[Boat Setting] No Fuel Requirement")]
            public bool DisableFuelRequirement = false;
            [JsonProperty(PropertyName = "[Boat Setting] Spawn With Fuel (-1 = default)")]
            public int FuelAmount = -1;
            [JsonProperty("[Boat Setting] Enable Global Broadcast")]
            public bool SpawnGlobal = true;
            [JsonProperty(PropertyName = "[Boat Setting] Fuel Per Sec (-1 = default)")]
            public float FuelPerSec = -1;
            [JsonProperty(PropertyName = "[Boat Setting] Engine Thrust (-1 = default)")]
            public float engineThrust = -1;
            [JsonProperty(PropertyName = "[Boat Setting] Tugboat Health (-1 = default)")]
            public float BoatHealth = -1;
            [JsonProperty("[AutoNav] Add AutoNav Button")]
            public bool AutoNavButton = false;
            [JsonProperty("[AutoNav] ButtonCUI")]
            public string ButtonCUIJson = @"[{""name"":""AutoNavButton"",""parent"":""Overlay"",""destroyUi"":""AutoNavButton"",""components"":[{""type"":""UnityEngine.UI.RawImage"",""color"":""1 1 1 1""},{""type"":""RectTransform"",""anchormin"":""0.92 0"",""anchormax"":""0.986 0.02"",""offsetmin"":""0 0"",""offsetmax"":""0 0""}]},{""name"":""Button"",""parent"":""AutoNavButton"",""components"":[{""type"":""UnityEngine.UI.Button"",""command"":""CMDAutoNav"",""color"":""0.26 0.39 0.53 1""},{""type"":""RectTransform"",""anchormin"":""0.0 0.0"",""anchormax"":""1 1""}]},{""parent"":""Button"",""components"":[{""type"":""UnityEngine.UI.Text"",""text"":""AutoNav"",""fontSize"":12,""align"":""MiddleCenter"",""color"":""0.905 0.882 0.807 1""},{""type"":""RectTransform""}]}]";
            [JsonProperty("[AutoNav] Enable AutoNav On Dismount")]
            public bool AllowAutoNav = false;
            [JsonProperty("[AutoNav] AutoNav Take Over Delay")]
            public int AutoNavDelay = 8;
            [JsonProperty("[AutoNav] AutoNav TickRate")]
            public int AutoNavTick = 2;
            [JsonProperty("[AutoNav] Remove Water Junkpiles On Collision (AutoNav Only)")]
            public bool JunkPileKill = true;
            [JsonProperty("[AutoNav] Water Junkpiles Scan Distance")]
            public float JunkPileScan = 8;
            [JsonProperty("[Spawners] Buy Window CUI")]
            public string BuyCUIJson = @"[{""name"":""BuyTugPannel"",""parent"":""Overlay"",""destroyUi"":""BuyTugPannel"",""components"":[{""type"":""UnityEngine.UI.Image"",""color"":""0.179 0.179 0.179 0.9""},{""type"":""RectTransform"",""anchormin"":""0 0"",""anchormax"":""1 1"",""offsetmin"":""380 220"",""offsetmax"":""-380 -220""},{""type"":""NeedsCursor""}]},{""name"":""BuyTextMsg"",""parent"":""BuyTugPannel"",""components"":[{""type"":""UnityEngine.UI.Text"",""text"":""{BUYTEXT}"",""fontSize"":40,""align"":""MiddleCenter"",""color"":""1 1 1 1""},{""type"":""UnityEngine.UI.Outline"",""color"":""0 0 0 1"",""distance"":""1 1""},{""type"":""RectTransform"",""anchormin"":""0 0"",""anchormax"":""1 1"",""offsetmin"":""0 -120"",""offsetmax"":""0 180""}]},{""name"":""YesButton"",""parent"":""BuyTugPannel"",""components"":[{""type"":""UnityEngine.UI.Button"",""command"":""BuyTugBoat"",""color"":""1 1 1 1""},{""type"":""RectTransform"",""anchormin"":""0.5 0.5"",""anchormax"":""0.5 0.5"",""offsetmin"":""-243 -127"",""offsetmax"":""-1 -100""}]},{""parent"":""YesButton"",""components"":[{""type"":""UnityEngine.UI.Text"",""text"":""Yes"",""fontSize"":15,""align"":""MiddleCenter"",""color"":""0 0 0 1""},{""type"":""RectTransform""}]},{""name"":""NoButton"",""parent"":""BuyTugPannel"",""components"":[{""type"":""UnityEngine.UI.Button"",""command"":""CloseTug"",""color"":""1 1 1 1""},{""type"":""RectTransform"",""anchormin"":""0.5 0.5"",""anchormax"":""0.5 0.5"",""offsetmin"":""1 -127"",""offsetmax"":""243 -100""}]},{""parent"":""NoButton"",""components"":[{""type"":""UnityEngine.UI.Text"",""text"":""No"",""fontSize"":15,""align"":""MiddleCenter"",""color"":""0 0 0 1""},{""type"":""RectTransform""}]}]";
            [JsonProperty("[Spawners] Max Alive Tugs Per Player")]
            public int MaxPerPlayer = 5;
            [JsonProperty("[Spawners] Adds NPC Spawners At Harbors")]
            public bool EnableTugSpawners = true;
            [JsonProperty("[Spawners] Adds NPCs Spawners At Fishing Villages")]
            public bool EnableTugSpawners2 = true;
            [JsonProperty("[Spawners] Adds NPC Spawner At Ferry Terminal")]
            public bool EnableTugSpawners3 = true;
            [JsonProperty("[Spawners] NPC Spawners Attire")]
            public string NPCVendorAttire = "hazmatsuit.diver";
            [JsonProperty("[Spawners] Spawn Block Radius")]
            public float SpawnBlockRadius = 20;
            [JsonProperty("[Spawners] Spawn Cost Type (serverrewards,economics,resources,free)")]
            public string Costtype = "free";
            [JsonProperty("[Spawners] Spawn Cost For (serverrewards,economics)")]
            public float Spawncost = 2000;
            [JsonProperty("[Spawners] Currency Symbol For (serverrewards,economics)")]
            public string CurrencySymbol = "$";
            [JsonProperty("[Spawners] Spawn Cost When Using Resources")]
            public Dictionary<string, int> SpawnCostResources = new Dictionary<string, int> {
                {
                    "scrap", 1300
                }
                ,
            }
            ;
            [JsonProperty("[Spawners] Vendor Positions (Offset from Center Of Monument)")]
            public VendorPos[] VendorPositions = new VendorPos[] {
                new VendorPos().init("assets/bundled/prefabs/autospawn/monument/harbor/ferry_terminal_1.prefab", new Vector3(3.896f, 0.217f, 43.764f), new Vector3(0, 80, 0), new Vector3(3, 0, 56)), new VendorPos().init("assets/bundled/prefabs/autospawn/monument/harbor/harbor_1.prefab", new Vector3(-66.4f, 2.36f, 46.8f), new Vector3(0, 0, 0), new Vector3(-74.5f, 0f, 50f)), new VendorPos().init("assets/bundled/prefabs/autospawn/monument/harbor/harbor_2.prefab", new Vector3(41.25f, 5.08f, 109f), new Vector3(0, 0, 0), new Vector3(50, 0, 120)), new VendorPos().init("assets/bundled/prefabs/autospawn/monument/fishing_village/fishing_village_a.prefab", new Vector3(0.48f, 2, 21.33f), new Vector3(0, 270, 0), new Vector3(-7, 0, 32.5f)), new VendorPos().init("assets/bundled/prefabs/autospawn/monument/fishing_village/fishing_village_b.prefab", new Vector3(-8.73f, 0.68f, 30.68f), new Vector3(0, 270, 0), new Vector3(-19, 0, 41.5f)), new VendorPos().init("assets/bundled/prefabs/autospawn/monument/fishing_village/fishing_village_c.prefab", new Vector3(-1.47f, 2.1f, 22.62f), new Vector3(0, 270, 0), new Vector3(-14, 0, 31.5f)),
            }
            ;
            [JsonProperty("[Spawners] Custom Vendor Positions (Position On The Map)")]
            public CustomVendorPos[] CustomPositions = new CustomVendorPos[] {
                new CustomVendorPos().init(new Vector3(0, 0, 0), new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
            }
            ;
            [JsonProperty("[Building] Allow Override Of Placement Check (White Listed Items Only)")]
            public bool OverrideAllow = false;
            [JsonProperty("[Building] Placement Distance Checking")]
            public float DistanceCheck = 1.5f;
            [JsonProperty("[Building] Power Electrical When Engine Running")]
            public bool PowerFromEngine = true;
            [JsonProperty("[Building] Boat Auth = Trap Auth (needed for gun and flame traps, Effects Autoturrets)")]
            public bool AuthFromBoat = true;
            [JsonProperty("[Building] White List Shortnames")]
            public string[] ItemOverride = new string[] {
                "autoturret", "samsite" , "water.catcher.small" , "barricade.concrete" , "composter" , "sign.pole.banner.large", "small.oil.refinery" , "trap.landmine", "trap.bear" , "searchlight" , "guntrap", "flameturret"
            }
            ;
            [JsonProperty("[Building] Rotation Amount (Per Hammer Hit)")]
            public int ItemAngle = 20;
            [JsonProperty("[Building] Allow Rotation On")]
            public string[] ItemRotation = new string[] {
                "autoturret_deployed", "barricade.concrete" , "composter" , "sign.pole.banner.large", "refinery_small_deployed" , "searchlight.deployed" , "guntrap.deployed", "flameturret.deployed",
            }
            ;
            public string ToJson() => JsonConvert.SerializeObject(this);
            public Dictionary<string, object> ToDictionary() => JsonConvert.DeserializeObject<Dictionary<string, object>>(ToJson());
        }
        protected override void LoadDefaultConfig() {
            config = new Configuration();
        }
        protected override void LoadConfig() {
            base.LoadConfig();
            try {
                config = Config.ReadObject<Configuration>();
                if (config == null) {
                    throw new JsonException();
                }
                if (!config.ToDictionary().Keys.SequenceEqual(Config.ToDictionary(x => x.Key, x => x.Value).Keys)) {
                    PrintWarning("Configuration appears to be outdated; updating and saving");
                    SaveConfig();
                }
            }
            catch {
                PrintWarning($"Configuration file {Name}.json is invalid; using defaults");
                LoadDefaultConfig();
            }
        }
        protected override void SaveConfig() {
            PrintWarning($"Configuration changes saved to {Name}.json");
            Config.WriteObject(config, true);
        }
#endregion Configuration
#region Commands
        [ChatCommand("tughelp")]
        private void tughelp(BasePlayer player)  //Help chat command
        {
            MessageIcon(player, "Help");
            if (permission.UserHasPermission(player.UserIDString, "TugMe.Buy")) {
                string buymsg = message(player, "Buy1");
                if (config.EnableTugSpawners) {
                    buymsg += message(player, "H1");
                }
                if (config.EnableTugSpawners) {
                    buymsg += message(player, "FV");
                }
                if (config.EnableTugSpawners3) {
                    buymsg += message(player, "FT");
                }
                rust.SendChatMessage(player, config.TugName, buymsg, config.AnnouncementIcon);
            }
            if (config.AllowAutoNav && permission.UserHasPermission(player.UserIDString, "TugMe.AutoNav")) {
                MessageIcon(player, "M1");
                MessageIcon(player, "M2");
            }
            if (permission.UserHasPermission(player.UserIDString, "TugMe.Spawn")) {
                MessageIcon(player, "M3");
            }
            if (permission.UserHasPermission(player.UserIDString, "TugMe.Remove")) {
                MessageIcon(player, "M4");
            }
            if (permission.UserHasPermission(player.UserIDString, "TugMe.Place")) {
                MessageIcon(player, "M5");
            }
            if (permission.UserHasPermission(player.UserIDString, "TugMe.Find")) {
                MessageIcon(player, "M6");
            }
            if (permission.UserHasPermission(player.UserIDString, "TugMe.Horn")) {
                MessageIcon(player, "M7");
            }
            if (permission.UserHasPermission(player.UserIDString, "TugMe.Button")) {
                MessageIcon(player, "M8");
            }
            if (permission.UserHasPermission(player.UserIDString, "TugMe.Tome")) {
                MessageIcon(player, "C8");
            }
            if (permission.UserHasPermission(player.UserIDString, "TugMe.Rotate")) {
                MessageIcon(player, "C9");
            }
        }
        [ChatCommand("tugboat")]
        private void SpawnTugBoat(BasePlayer player)  //Spawn command
        {
            if (permission.UserHasPermission(player.UserIDString, "TugMe.Spawn")) {
                if (player == null) return;
                Vector3 position = GetPosition(player);
                if(position == Vector3.zero) return;
                if (SpawnManager(player))  //Check not over spawn limit
                {
                    MessageIcon(player, "E8");
                    Tugboat boat = GameManager.server.CreateEntity("assets/content/vehicles/boats/tugboat/tugboat.prefab", position, player.transform.rotation, true) as Tugboat;
                    boat.OwnerID = player.userID;
                    boat.Spawn();
                    storedData.OwnedTugs.Add(boat.net.ID.Value, player.userID);
                    return;
                }
                MessageIcon(player, "E9", config.MaxPerPlayer.ToString());
            }
        }
        [ChatCommand("tugevent")]
        private void TugBoatEvent(BasePlayer player)  //Spawn event nearest cargo node to player
        {
            if (permission.UserHasPermission(player.UserIDString, "TugMe.Event")) {
                if (player == null) return;
                if (player.IsBuildingBlocked()) {
                    MessageIcon(player, "M9");
                    return;
                }
                if (player.transform.position.y < -5)  //Prevent spawning in train tunnels, caves ect
                {
                    MessageIcon(player, "M0");
                    return;
                }
                Vector3 vector = TerrainMeta.Path.OceanPatrolFar[GetClosestNodeToUs(player.transform.position)];
                MessageIcon(player, "E0", vector.ToString());
                Tugboat TB = NewTugBoat(vector, Quaternion.Euler(new Vector3(0, 0, 0)), 76561199381312678);
                TB.enableSaving = false;
                //Remove from entering save file
                if (TB != null) {
                    timer.Once(5, () => {
                        SetupEvent(TB);
                    }
                    );
                }
            }
        }
        [ChatCommand("tugtome")]
        private void TugToMe(BasePlayer player, string command, string[] args) {
            if(permission.UserHasPermission(player.UserIDString, "TugMe.Tome")) {
                if (args.Length == 1) {
                    ulong ID;
                    if (ulong.TryParse(args[0], out ID)) {
                        if (storedData.OwnedTugs.ContainsKey(ID)) {
                            if (storedData.OwnedTugs[ID] == player.userID || player.IsAdmin) {
                                BaseNetworkable bn = BaseNetworkable.serverEntities.Find(new NetworkableId(ID));
                                Vector3 vector = GetPosition(player);
                                if(vector == Vector3.zero) {
                                    return;
                                }
                                bn.transform.position = player.transform.position + (player.transform.forward * 6);
                                bn.SendNetworkUpdateImmediate();
                                MessageIcon(player, "C7", ID, PhoneController.PositionToGridCoord(bn.transform.position));
                            }
                            else {
                                MessageIcon(player, "A1");
                            }
                        }
                        else {
                            MessageIcon(player, "A2");
                        }
                    }
                    return;
                }
                MessageIcon(player, "D1");
                ListOwnedTugs(player);
                return;
            }
            MessageIcon(player, "D2");
        }
        [ChatCommand("tugremove")]
        private void TugRemove(BasePlayer player, string command, string[] args) {
            if (permission.UserHasPermission(player.UserIDString, "TugMe.Remove")) {
                if (args.Length == 1) {
                    ulong ID;
                    if (ulong.TryParse(args[0], out ID)) {
                        if (storedData.OwnedTugs.ContainsKey(ID)) {
                            if (storedData.OwnedTugs[ID] == player.userID) {
                                BaseNetworkable bn = BaseNetworkable.serverEntities.Find(new NetworkableId(ID));
                                bn.Kill();
                                MessageIcon(player, "A0", ID, PhoneController.PositionToGridCoord(bn.transform.position));
                            }
                            else {
                                MessageIcon(player, "A1");
                            }
                        }
                        else {
                            MessageIcon(player, "A2");
                        }
                    }
                    return;
                }
                MessageIcon(player, "A3");
                ListOwnedTugs(player);
                return;
            }
            MessageIcon(player, "A5");
        }
        [ChatCommand("tugfind")]
        private void TugFind(BasePlayer player)  //Mark tugboats owned on map
        {
            if (permission.UserHasPermission(player.UserIDString, "TugMe.Find")) {
                MessageIcon(player, "A6", UpdatePlayersTugIcon(player).ToString());
                return;
            }
            MessageIcon(player, "A7");
        }
        [ChatCommand("autonav")]
        private void TugBoatAutoNav(BasePlayer player)  //Toggle auto nav mode on/off
        {
            if (permission.UserHasPermission(player.UserIDString, "TugMe.AutoNav")) {
                if (!storedData.AutoNav.Contains(player.userID)) {
                    MessageIcon(player, "A8");
                    storedData.AutoNav.Add(player.userID);
                    return;
                }
                MessageIcon(player, "A9");
                storedData.AutoNav.Remove(player.userID);
                return;
            }
            MessageIcon(player, "B0");
        }
        [ConsoleCommand("starttugevent")]
        private void ConsoleTugEvent(ConsoleSystem.Arg arg)  //Create tug event at position from console/other plugin
        {
            if (arg.IsAdmin && arg.Args?.Length >= 3)  //Check there are 3 or more args
            {
                float x;
                float y;
                float z;
                if (float.TryParse(arg.Args[0], out x) && float.TryParse(arg.Args[1], out y) && float.TryParse(arg.Args[2], out z))  //Try convert to vector3
                {
                    Vector3 pos = new Vector3(x, y, z);
                    PrintToConsole("TugEvent @ " + pos);
                    Tugboat TB = NewTugBoat(pos, Quaternion.Euler(new Vector3(0, 0, 0)), 76561199381312678);
                    TB.enableSaving = false;
                    if (TB != null) {
                        timer.Once(5, () => {
                            SetupEvent(TB);
                        }
                        );
                    }
                }
            }
        }
        //CUI Close button
        [ConsoleCommand("CloseTug")]
        private void CloseCUI(ConsoleSystem.Arg arg) {
            if (arg.Player() != null) {
                CuiHelper.DestroyUi(arg.Player(), "BuyTugPannel");
            }
        }
        //CUI Buy button
        [ConsoleCommand("BuyTugBoat")]
        private void BuyCUI(ConsoleSystem.Arg arg) {
            if (arg.Player() != null) {
                CuiHelper.DestroyUi(arg.Player(), "BuyTugPannel");
                //Close CUI Window
                //Make sure NPC is nearby to stop console command exploiting
                List<NPCTalking> list = Pool.GetList<NPCTalking>();
                Vis.Entities<NPCTalking>(arg.Player().transform.position, 5, list);
                foreach (NPCTalking item in list)  //Check vis list
                {
                    if (TugDealers.ContainsKey(item)) {
                        if (!ChargePlayer(arg.Player())) {
                            return;
                        }
                        Tugboat tug = _plugin.NewTugBoat(_plugin.TugDealers[item], item.transform.rotation, arg.Player().userID);
                        storedData.OwnedTugs.Add(tug.net.ID.Value, arg.Player().userID);
                        return;
                    }
                }
                Pool.FreeList<NPCTalking>(ref list);
            }
        }
        //CUI AutoNav button
        [ConsoleCommand("CMDAutoNav")]
        private void AutoNavCUI(ConsoleSystem.Arg arg) {
            if (arg.Player() != null) {
                BasePlayer player = arg.Player();
                if (player.GetParentEntity() is Tugboat) {
                    Tugboat tugboat = player.GetParentEntity() as Tugboat;
                    if (tugboat != null && tugboat.GetDriver() == player) {
                        if (!tugboat.HasFlag(BaseEntity.Flags.Reserved1)) {
                            MessageIcon(player, "B1");
                            return;
                        }
                        AutoNavigation an = tugboat.gameObject.GetComponent<AutoNavigation>();
                        if (an == null)  //Add auto nav if missing
                        {
                            an = tugboat.gameObject.AddComponent<AutoNavigation>();
                            an.captin = player;
                            MessageIcon(player, "B2");
                        }
                        else {
                            an.RemoveMe();
                        }
                    }
                }
            }
        }
#endregion
#region TruePVEHook
        object CanEntityTakeDamage(BaseCombatEntity entity, HitInfo hitinfo) {
            if (config.PVESupport) {
                if (EventBoats.Contains(entity) || ActiveNPCs.Contains(entity) || (entity.GetParentEntity() is Tugboat && EventBoats.Contains(entity.GetParentEntity()))) {
                    return true;
                }
            }
            return null;
        }
#endregion
#region Hooks
        private void Init() {
            _plugin = this;
            //Set self reference
            storedData = Interface.Oxide.DataFileSystem.ReadObject<StoredData>("TugMe");
            bool dupes = false;
            CustomVendorPos[] c = config.CustomPositions.Distinct().ToArray();
            if (c.Length != config.CustomPositions.Length) {
                config.CustomPositions = c;
                dupes = true;
            }
            VendorPos[] v = config.VendorPositions.Distinct().ToArray();
            if (v.Length != config.VendorPositions.Length) {
                config.VendorPositions = v;
                dupes = true;
            }
            if (dupes) {
                PrintWarning("Configuration appears to have duplicates; fixed and saving");
                SaveConfig();
            }
            //Permissions
            permission.RegisterPermission("TugMe.Spawn", this);
            permission.RegisterPermission("TugMe.Remove", this);
            permission.RegisterPermission("TugMe.Event", this);
            permission.RegisterPermission("TugMe.Buy", this);
            permission.RegisterPermission("TugMe.AutoNav", this);
            permission.RegisterPermission("TugMe.Place", this);
            permission.RegisterPermission("TugMe.Find", this);
            permission.RegisterPermission("TugMe.Horn", this);
            permission.RegisterPermission("TugMe.Button", this);
            permission.RegisterPermission("TugMe.Announce", this);
            permission.RegisterPermission("TugMe.Tome", this);
            permission.RegisterPermission("TugMe.Rotate", this);
            //Patch in harmony
            _harmony = HarmonyInstance.Create(Name + "PATCH");
            Type[] patchType = {
                AccessTools.Inner(typeof(TugMe), "MotorRowboat_TimeSinceDriver"), AccessTools.Inner(typeof(TugMe), "NPCTalking_Server_BeginTalking"), AccessTools.Inner(typeof(TugMe), "Tugboat_VehicleFixedUpdate"),
            }
            ;
            foreach (var t in patchType) {
                new PatchProcessor(_harmony, t, HarmonyMethod.Merge(t.GetHarmonyMethods())).Patch();
            }
        }
        private void OnServerInitialized() {
            if (config.EnableTugSpawners || config.EnableTugSpawners2 || config.EnableTugSpawners3) {
                //Create NPC Tug boat spawners
                CreateNPCs();
                Puts("Spawned " + TugDealers.Count + " Tugboat Dealers.");
            }
            //Reapply mod to exsisting tugboats
            int tugs = 0;
            foreach (var t in BaseNetworkable.serverEntities.entityList.Values) {
                if (t != null && t is Tugboat) {
                    tugs++;
                    SetupTugSettings(t as Tugboat);
                }
            }
            Puts("Modded " + tugs + " Tugboats.");
            Puts("Starting TugMe Functions");
            timerList.Add(timer.Every(config.EventTick, () => {
                EventTick();
            }
            ));
            if (config.MapFunction) {
                timerList.Add(timer.Every(config.MapRefresh, () => {
                    MapTick();
                }
                ));
            }
            if (config.MarkEvents) {
                timerList.Add(timer.Every(config.MapRefresh, () => {
                    DrawMapfunction();
                }
                ));
            }
        }
        private void Unload() {
            Interface.Oxide.DataFileSystem.WriteObject("TugMe", storedData);
            //Save Datafile
            _harmony.UnpatchAll(Name + "PATCH");
            //Unpatch harmony
            foreach (var t in TugDealers.Keys) {
                if (t != null && !t.IsDestroyed) {
                    t.Kill();
                }
            }
            //Remove Tug NPCs
            foreach (var p in BasePlayer.activePlayerList) {
                CuiHelper.DestroyUi(p, "AutoNavButton");
                CuiHelper.DestroyUi(p, "BuyTugPannel");
            }
            //Remove CUI
            foreach (var b in PoweredBoats)  //Remove tugboat mods
            {
                if (b == null) {
                    continue;
                }
                AutoNavigation an = b.gameObject.GetComponent<AutoNavigation>();
                if (an != null) {
                    an.RemoveMe();
                }
                foreach (var be in b.children) {
                    _plugin.TogglePower(be, false);
                }
            }
            //Clear Running Timers
            if (timerList.Count > 0) {
                foreach (var timer in timerList) {
                    timer.Destroy();
                }
                timerList.Clear();
            }
            MarkerDisplayingDelete();
            foreach (var t in EventBoats) {
                if (t != null && !t.IsDestroyed) {
                    t.Kill();
                }
            }
            //Kill event tugs
            foreach (var n in ActiveNPCs) {
                if (n != null && !n.IsDestroyed) {
                    n.Kill();
                }
            }
            //Kill NPCs
            foreach (var v in VoicePlayers) {
                if (v != null && !v.IsDestroyed) {
                    v.Kill();
                }
            }
            //Kill VoiceNPCs
            _plugin = null;
        }
        void OnEntityMounted(BaseMountable entity, BasePlayer player) {
            if (entity.ShortPrefabName == "tugboatdriver")  //Mounted tugboat driver seat
            {
                Tugboat tugboat = player.GetParentEntity() as Tugboat;
                if (tugboat == null) {
                    return;
                }
                AutoNavigation an = tugboat.gameObject.GetComponent<AutoNavigation>();
                if (an != null) {
                    an.captin = player;
                }
                if (config.AutoNavButton && permission.UserHasPermission(player.UserIDString, "TugMe.AutoNav")) {
                    if (tugboat != null && permission.UserHasPermission(player.UserIDString, "TugMe.Button")) {
                        CuiHelper.AddUi(player, config.ButtonCUIJson);
                    }
                }
            }
        }
        void OnEntityDismounted(BaseMountable entity, BasePlayer player) {
            if (entity.ShortPrefabName == "tugboatdriver" && config.AutoNavButton)  //Dismounted tugboat driver seat
            {
                if (permission.UserHasPermission(player.UserIDString, "TugMe.Button")) {
                    CuiHelper.DestroyUi(player, "AutoNavButton");
                }
                if (storedData.AutoNav.Contains(player.userID) && permission.UserHasPermission(player.UserIDString, "TugMe.AutoNav")) {
                    Tugboat tugboat = player.GetParentEntity() as Tugboat;
                    if (tugboat != null && tugboat.HasFlag(BaseEntity.Flags.Reserved1))  //Check if engine on
                    {
                        AutoNavigation an = tugboat.gameObject.GetComponent<AutoNavigation>();
                        if (an == null)  //Add auto nav if missing
                        {
                            an = tugboat.gameObject.AddComponent<AutoNavigation>();
                            an.captin = player;
                            MessageIcon(player, "B2");
                        }
                    }
                }
            }
        }
        //Auth On Boat Gives Turret,Guntrap,Flame Auth
        object CanBeTargeted(BasePlayer player, BaseEntity entity) {
            if (config.AuthFromBoat && entity?.GetParentEntity() is Tugboat)  //Only effect if on tugboat
            {
                Tugboat tug = entity.GetParentEntity() as Tugboat;
                if (tug.IsAuthed(player) && !EventBoats.Contains(tug))  //Check player has auth and not event tug
                {
                    return false;
                    //Block targeting
                }
            }
            return null;
        }
        //Catch Hammer hitting to enable rotate mode
        object OnHammerHit(BasePlayer ownerPlayer, HitInfo info) {
            if (info == null || ownerPlayer == null || info?.Initiator?.ToPlayer() == null || !(info?.Initiator?.GetParentEntity() is Tugboat)) {
                return null;
            }
            //Check has reload down and permission
            if (info.Initiator.ToPlayer().serverInput.IsDown(BUTTON.RELOAD) && permission.UserHasPermission(info.Initiator.ToPlayer().UserIDString, "TugMe.Rotate")) {
                Tugboat tb = info.Initiator.GetParentEntity() as Tugboat;
                if (config.Debug) {
                    Puts(info.HitEntity.ShortPrefabName);
                }
                if (EventBoats.Contains(tb)) {
                    return null;
                }
                //Check isnt event tug
                if (tb.IsAuthed(info.Initiator.ToPlayer()) && config.ItemRotation.Contains(info?.HitEntity?.ShortPrefabName) && info.HitEntity?.GetParentEntity() == tb) {
                    info.HitEntity.transform.localRotation *= Quaternion.Euler(0, config.ItemAngle, 0);
                    info.HitEntity.SendNetworkUpdateImmediate();
                    return true;
                }
            }
            return null;
        }
        //Catch loot box death
        object OnEntityKill(BaseNetworkable entity) {
            if (LootBoxes.ContainsKey(entity)) {
                Tugboat boat = LootBoxes[entity];
                LootBoxes.Remove(entity);
                if (boat == null || boat.IsDestroyed) {
                    return null;
                }
                //Delay start fire
                timer.Once(config.FireDelay, () => {
                    AutoNavigation an = boat.gameObject.GetCom
// ... [Code preview truncated due to length. Full source in attached file] ...

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