C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System.Collections.Generic;
using System.Collections;
using Oxide.Core.Configuration;
using Newtonsoft.Json;
using Oxide.Core.Plugins;
using UnityEngine;
using System.Linq;
using Oxide.Core;
using System;
using Oxide.Game.Rust.Cui;
using UnityEngine.SceneManagement;
using System.Text.RegularExpressions;
using Color = UnityEngine.Color;
using UnityEngine.AI;
using Facepunch;
using VLB;
using System.Globalization;
using ProtoBuf;
using Newtonsoft.Json.Linq;
namespace Oxide.Plugins {
[Info("RandomRaids", "Razor", "1.4.5")]
[Description("Npc's that randomly raid bases")]
public class RandomRaids : RustPlugin {
#region Loading
public static bool debug = false;
public const string BlockName = "RandomRaidsTimer";
private Coroutine QueuedRoutine;
private Coroutine QueuedRoutinePlayer;
private Dictionary<string, string> itemNameToConfig = new Dictionary<string, string>();
private Dictionary<ulong, string> entitySkinToConfig = new Dictionary<ulong, string>();
private List<string> itemLootSpawn = new List<string>();
private const string adminPerm = "randomraids.admin";
// private const string easyPerm = "randomraids.easy";
// private const string hardPerm = "randomraids.hard";
// private const string expertPerm = "randomraids.expert";
// private const string nightmarePerm = "randomraids.nightmare";
private const string usePerm = "randomraids.use";
PlayerEntity pcdData;
private DynamicConfigFile PCDDATA;
RaidData raidData;
private DynamicConfigFile RAIDDATA;
LogData logData;
private DynamicConfigFile LOGDATA;
[PluginReference]
private Plugin Kits, TruePVE, RaidableBases, CustomLoot, BotReSpawn;
public static RandomRaids _;
private Dictionary<Vector3, DateTime> raidLocations = new Dictionary<Vector3, DateTime>();
public static double GrabCurrentTime() => DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;
public static List<MLRS> mlrs = new List<MLRS>();
static int obstructionMask = LayerMask.GetMask(new[] {
"World", "Terrain"
}
);
private static int groundLayer;
private static int terainLayer;
private static int BuildingLayer;
private static Vector3 Vector3Down;
public class eventList {
public string type;
public Vector3 location;
public DateTime lastraidedTime;
}
private object CanModifyCustomNPC(BaseEntity entity) {
if (entity.GetType().ToString() == "RandomRaider") return false;
return null;
}
private void Init() {
_ = this;
permission.RegisterPermission(adminPerm, this);
permission.RegisterPermission(usePerm, this);
PCDDATA = Interface.Oxide.DataFileSystem.GetFile(Name + "/PlayersTC");
RAIDDATA = Interface.Oxide.DataFileSystem.GetFile(Name + "/RaidData");
LOGDATA = Interface.Oxide.DataFileSystem.GetFile(Name + "/PlayerLog");
LoadData();
if (configData.raidSettings.raidTypes.Count <= 0) {
configData.raidSettings.raidTypes.Add("easy", new raidConfig(1, 10, true, 100, 640, new List<string>(), new List<string>() {
"explosive.timed", "explosive.satchel"
}
, 1, 1.0, false, new List<string>() {
"easy"
}
));
configData.raidSettings.raidTypes.Add("medium", new raidConfig(2, 15, true, 200, 900, new List<string>(), new List<string>() {
"explosive.timed", "explosive.satchel"
}
, 1, 1.0, true, new List<string>() {
"easy"
}
));
configData.raidSettings.raidTypes.Add("hard", new raidConfig(3, 20, true, 400, 1200, new List<string>(), new List<string>() {
"explosive.timed", "explosive.satchel"
}
, 1, 1.0, true, new List<string>() {
"easy"
}
));
configData.raidSettings.raidTypes.Add("expert", new raidConfig(4, 30, true, 400, 1500, new List<string>(), new List<string>() {
"explosive.timed", "explosive.satchel"
}
, 1, 1.0, true, new List<string>() {
"medium"
}
));
configData.raidSettings.raidTypes.Add("nightmare", new raidConfig(5, 30, true, 400, 2100, new List<string>(), new List<string>() {
"explosive.timed", "explosive.satchel"
}
, 1, 1.0, true, new List<string>() {
"medium"
}
));
SaveConfig();
}
foreach (var jconfigs in configData.raidSettings.raidTypes.Values) {
if (jconfigs.juggernaut == null) {
jconfigs.juggernaut = new List<string>() {
"easy"
}
;
SaveConfig();
}
}
if (configData.copterSettings.copterProfile.Count <= 0) {
configData.copterSettings.copterProfile.Add("easy", new copterConfig(1000, 2));
SaveConfig();
}
if (configData.settingsRB.raidSettings.Count <= 0) {
configData.settingsRB.raidSettings.Add(0, new RBConfig(3, 10, 320, new List<string>() {
"easy"
}
));
configData.settingsRB.raidSettings.Add(1, new RBConfig(3, 10, 320, new List<string>() {
"easy", "medium"
}
));
configData.settingsRB.raidSettings.Add(2, new RBConfig(3, 10, 320, new List<string>() {
"easy", "medium"
}
));
configData.settingsRB.raidSettings.Add(3, new RBConfig(3, 10, 320, new List<string>() {
"easy", "medium", "hard"
}
));
configData.settingsRB.raidSettings.Add(4, new RBConfig(3, 10, 320, new List<string>() {
"hard", "expert", "nightmare"
}
));
SaveConfig();
}
if (configData.settingsNPCKILLS == null) configData.settingsNPCKILLS = new ConfigData.SettingsNPCKILLS();
if (configData.settingsNPCKILLS.npcSettings == null) configData.settingsNPCKILLS.npcSettings = new Dictionary<string, NPCConfig>();
if (configData.settingsNPCKILLS.npcSettings.Count <= 0) {
configData.settingsNPCKILLS.npcSettings.Add("scientistnpc_heavy", new NPCConfig(30, 10, 320, new List<string>() {
"medium"
}
));
configData.settingsNPCKILLS.npcSettings.Add("scientistnpc_oilrig", new NPCConfig(60, 10, 320, new List<string>() {
"easy"
}
));
configData.settingsNPCKILLS.npcSettings.Add("scientistnpc_patrol", new NPCConfig(60, 10, 320, new List<string>() {
"easy"
}
));
configData.settingsNPCKILLS.npcSettings.Add("scientistnpc_junkpile", new NPCConfig(60, 10, 320, new List<string>() {
"easy"
}
));
SaveConfig();
}
if (configData.juggernautProfile.Count <= 0) {
configData.juggernautProfile.Add("easy", new juggernautConfig(new Dictionary<int, int>() {
{
1, 1
}
}
, 500f, new List<string>()));
configData.juggernautProfile.Add("medium", new juggernautConfig(new Dictionary<int, int>() {
{
1, 2
}
}
, 700f, new List<string>()));
SaveConfig();
}
if (configData.itemProfile.Count <= 0) {
configData.itemProfile.Add("easy", new itemConfig(2893480896, "Npc Raid Level 1", 5, new List<string>() {
"crate_normal", "crate_normal_2"
}
));
configData.itemProfile.Add("medium", new itemConfig(2893480635, "Npc Raid Level 2", 5, new List<string>() {
"crate_normal", "crate_normal_2", "heli_crate"
}
));
configData.itemProfile.Add("hard", new itemConfig(2893481009, "Npc Raid Level 3", 5, new List<string>() {
"bradley_crate", "crate_elite"
}
));
configData.itemProfile.Add("expert", new itemConfig(2893481137, "Npc Raid Level 4", 5, new List<string>() {
"bradley_crate", "crate_elite"
}
));
configData.itemProfile.Add("nightmare", new itemConfig(2893482048, "Npc Raid Level 5", 5, new List<string>() {
"bradley_crate", "crate_elite"
}
));
SaveConfig();
}
if (configData.itemProfile != null && configData.itemProfile.Count > 0) {
foreach (var itemName in configData.itemProfile) {
if (configData.raidSettings.raidTypes.ContainsKey(itemName.Key) && !entitySkinToConfig.ContainsKey(itemName.Value.itemSkin)) entitySkinToConfig.Add(itemName.Value.itemSkin, itemName.Key);
if (configData.raidSettings.raidTypes.ContainsKey(itemName.Key) && !itemNameToConfig.ContainsKey(itemName.Value.itemName)) itemNameToConfig.Add(itemName.Value.itemName, itemName.Key);
if (itemName.Value.SpawnEnabled && configData.raidSettings.raidTypes.ContainsKey(itemName.Key)) itemLootSpawn.Add(itemName.Key);
}
}
}
private void Unload() {
stopSearch();
StopAllRaids();
foreach (BasePlayer current in BasePlayer.activePlayerList.ToList()) CuiHelper.DestroyUi(current, "RtimerS" + BlockName);
_ = null;
}
private void StopAllRaids() {
foreach (var eventRunning in EventRandomManager._AllRaids.ToList()) {
eventRunning.Destroy();
}
EventRandomManager._AllRaids.Clear();
}
private void OnServerInitialized() {
groundLayer = LayerMask.GetMask("Construction", "Terrain", "World");
terainLayer = LayerMask.GetMask("Terrain", "World", "Water");
BuildingLayer = LayerMask.GetMask("Construction");
Vector3Down = new Vector3(0f, -1f, 0f);
//Regenerate TC Data
pcdData.tcData.Clear();
foreach (BuildingPrivlidge find in BaseNetworkable.serverEntities.OfType<BuildingPrivlidge>()) {
if (Convert.ToBoolean(RaidableBases?.CallHook("EventTerritory", find.transform.position))) continue;
foreach (var playerNameID in find.authorizedPlayers) {
if (!pcdData.tcData.ContainsKey(playerNameID.userid)) pcdData.tcData.Add(playerNameID.userid, new List<ulong>() {
find.net.ID.Value
}
);
else if (!pcdData.tcData[playerNameID.userid].Contains(find.net.ID.Value)) pcdData.tcData[playerNameID.userid].Add(find.net.ID.Value);
}
}
SaveData();
if (configData.settings.randomTimer) {
timer.Every(configData.settings.cooldownSeconds, () => startRestartSearch());
}
}
#endregion
#region Data
private void LoadData() {
try {
pcdData = Interface.GetMod().DataFileSystem.ReadObject<PlayerEntity>(Name + "/PlayersTC");
}
catch {
PrintWarning("Couldn't load Player data, creating new Playerfile");
pcdData = new PlayerEntity();
}
try {
raidData = Interface.GetMod().DataFileSystem.ReadObject<RaidData>(Name + "/RaidData");
}
catch {
PrintWarning("Couldn't load Raid data, creating new RaidData file");
raidData = new RaidData();
}
try {
logData = Interface.GetMod().DataFileSystem.ReadObject<LogData>(Name + "/PlayerLog");
}
catch {
PrintWarning("Couldn't load log data, creating new log file");
logData = new LogData();
}
}
public class PlayerEntity {
public Dictionary<ulong, List<ulong>> tcData = new Dictionary<ulong, List<ulong>>();
}
public class RaidData {
public Dictionary<ulong, rData> data = new Dictionary<ulong, rData>();
}
public class LogData {
public Dictionary<ulong, lData> pLogs = new Dictionary<ulong, lData>();
}
public class lData {
public Dictionary<string, int> NPCKILLS = new Dictionary<string, int>();
}
public class rData {
public DateTime LastRaided;
public Dictionary<Vector3, DateTime> raidLocations = new Dictionary<Vector3, DateTime>();
public List<string> info = new List<string>();
public List<ulong> info1 = new List<ulong>();
public List<ulong> info2 = new List<ulong>();
}
public void SaveData() {
PCDDATA.WriteObject(pcdData);
}
public void SaveRaidData() {
RAIDDATA.WriteObject(raidData);
}
public void SaveLogData() {
LOGDATA.WriteObject(logData);
}
#endregion
#region Config
private ConfigData configData;
class ConfigData {
[JsonProperty(PropertyName = "Random settings")]
public Settings settings {
get;
set;
}
[JsonProperty(PropertyName = "All Random Raid Types")]
public RaidSettings raidSettings {
get;
set;
}
[JsonProperty(PropertyName = "AttackCopter profiles")]
public CopterSettings copterSettings {
get;
set;
}
[JsonProperty(PropertyName = "Block Random raid in colider")]
public BlockedColliders blockedColliders {
get;
set;
}
[JsonProperty(PropertyName = "Raidable Base plugin settings")]
public SettingsRB settingsRB {
get;
set;
}
[JsonProperty(PropertyName = "Trigger by npc kills")]
public SettingsNPCKILLS settingsNPCKILLS {
get;
set;
}
[JsonProperty(PropertyName = "Juggernaut profiles")]
public Dictionary<string, juggernautConfig> juggernautProfile {
get;
set;
}
= new Dictionary<string, juggernautConfig>();
[JsonProperty(PropertyName = "Item profiles")]
public Dictionary<string, itemConfig> itemProfile {
get;
set;
}
= new Dictionary<string, itemConfig>();
public class Settings {
[JsonProperty(PropertyName = "A player on the tc must be online")]
public bool mustBeOnlinePlayer {
get;
set;
}
[JsonProperty(PropertyName = "Use random raid timer")]
public bool randomTimer {
get;
set;
}
[JsonProperty(PropertyName = "Random raid timer time")]
public int cooldownSeconds {
get;
set;
}
[JsonProperty(PropertyName = "Chance of random raid at time (1-100)")]
public int chanceTime {
get;
set;
}
[JsonProperty(PropertyName = "Authorized players Cooldown minutes before random raided again by chance")]
public int raidAgainCooldown {
get;
set;
}
[JsonProperty(PropertyName = "The maximum amount of time a rocket will fly before exploding")]
public float RocketExplodeTime {
get;
set;
}
[JsonProperty(PropertyName = "Npc spawn damage delay")]
public float damageDelay {
get;
set;
}
[JsonProperty(PropertyName = "Display global chat message on raid start")]
public bool useChat {
get;
set;
}
[JsonProperty(PropertyName = "Display global map marker on raid start")]
public bool useMarker {
get;
set;
}
[JsonProperty(PropertyName = "Display Gui to base owners")]
public bool useGUI {
get;
set;
}
[JsonProperty(PropertyName = "GUI AnchorMin")]
public string AnchorMin = "0.807 0.96";
[JsonProperty(PropertyName = "GUI AnchorMax")]
public string AnchorMax = "0.996 0.99";
[JsonProperty(PropertyName = "Use GameTip announcement to player")]
public bool gameTip {
get;
set;
}
[JsonProperty(PropertyName = "GameTip display time in seconds")]
public float gameTipTime = 2f;
[JsonProperty(PropertyName = "Taunt players with.mp3 voices")]
public List<string> tauntList {
get;
set;
}
[JsonProperty(PropertyName = "Wait until all NPC are dead before sending in next wave")]
public bool pauseWave {
get;
set;
}
[JsonProperty(PropertyName = "Player must have randomraids.use inorder to get raided")]
public bool musthavePerm {
get;
set;
}
[JsonProperty(PropertyName = "Use world text to show base location")]
public bool worldMarker {
get;
set;
}
[JsonProperty(PropertyName = "World text display time")]
public float worldMarkerTime {
get;
set;
}
}
public class SettingsRB {
[JsonProperty(PropertyName = "Raid player on Raidable Base Completed")]
public bool raidableBaseComplete {
get;
set;
}
[JsonProperty(PropertyName = "Warn player in chat of upcoming revenge on them")]
public bool warnPlayer {
get;
set;
}
[JsonProperty(PropertyName = "Raidable Base Settings")]
public Dictionary<int, RBConfig> raidSettings {
get;
set;
}
}
public class RaidSettings {
[JsonProperty(PropertyName = "Random raid types")]
public Dictionary<string, raidConfig> raidTypes {
get;
set;
}
}
public class CopterSettings {
[JsonProperty(PropertyName = "Profile Names")]
public Dictionary<string, copterConfig> copterProfile {
get;
set;
}
}
public class BlockedColliders {
public List<string> Blocked {
get;
set;
}
}
public class SettingsNPCKILLS {
[JsonProperty(PropertyName = "Enable log kills and random raid on kills")]
public bool enableKills {
get;
set;
}
[JsonProperty(PropertyName = "Reset npc kills on player raided.")]
public bool resetKills {
get;
set;
}
[JsonProperty(PropertyName = "Warn player in chat of upcoming revenge on them")]
public bool warnPlayer {
get;
set;
}
[JsonProperty(PropertyName = "Npc kills settings")]
public Dictionary<string, NPCConfig> npcSettings {
get;
set;
}
}
public Oxide.Core.VersionNumber Version {
get;
set;
}
}
protected override void LoadConfig() {
base.LoadConfig();
configData = Config.ReadObject<ConfigData>();
if (configData.Version < Version) UpdateConfigValues();
Config.WriteObject(configData, true);
}
protected override void LoadDefaultConfig() => configData = GetBaseConfig();
private ConfigData GetBaseConfig() {
return new ConfigData {
settings = new ConfigData.Settings {
mustBeOnlinePlayer = true, randomTimer = false, cooldownSeconds = 3600, chanceTime = 10, raidAgainCooldown = 1440, RocketExplodeTime = 4.0f, damageDelay = 2f, useChat = true, useMarker = true, tauntList = new List<string>(),
/*{ "https://dl.dropboxusercontent.com/s/61743zv8vh6r8j8/088512791-fantasy-lizard-monster-voice-i.mp3",
"https://dl.dropboxusercontent.com/s/a6t5uv26qcz5nhs/111605736-demon-voice-nice-try.mp3https://dl.dropboxusercontent.com/s/a6t5uv26qcz5nhs/111605736-demon-voice-nice-try.mp3",
"https://dl.dropboxusercontent.com/s/zh2jp80zoy9oinp/145014836-male-vocal-video-game-taunt-5.mp3" }*/
pauseWave = false, musthavePerm = false, worldMarker = false, worldMarkerTime = 60f
}
, settingsRB = new ConfigData.SettingsRB {
raidSettings = new Dictionary<int, RBConfig>()
}
, raidSettings = new ConfigData.RaidSettings {
raidTypes = new Dictionary<string, raidConfig>()
}
, copterSettings = new ConfigData.CopterSettings {
copterProfile = new Dictionary<string, copterConfig>()
}
, blockedColliders = new ConfigData.BlockedColliders {
Blocked = new List<string>() {
"iceberg", "ice_berg", "ice_sheet", "icesheet", "cliff", "cave"
}
}
, Version = Version
}
;
}
protected override void SaveConfig() => Config.WriteObject(configData, true);
private void UpdateConfigValues() {
PrintWarning("Version update detected!");
ConfigData baseConfig = GetBaseConfig();
if (configData.Version < new VersionNumber(1, 0, 0)) {
configData = baseConfig;
PrintWarning("Config update was needed and now completed!");
}
configData.Version = Version;
PrintWarning("Version update completed!");
}
public class raidConfig {
[JsonProperty(PropertyName = "Total auth players on tc needed")]
public int TotalAuth;
[JsonProperty(PropertyName = "Total npcs per wave")]
public int TotalNpcs;
[JsonProperty(PropertyName = "How many extra waves")]
public int TotalNpcWaves;
[JsonProperty(PropertyName = "Seconds untell next wave")]
public int NextWaveSeconds;
[JsonProperty(PropertyName = "Npc fires Mlrs at base")]
public bool FireMlrs;
[JsonProperty(PropertyName = "Send in Attack Copter support")]
public bool attackCopter;
[JsonProperty(PropertyName = "Total event time in seconds")]
public int RunTimeSeconds;
[JsonProperty(PropertyName = "Npc drop loot on death")]
public bool NpcDropLoot;
[JsonProperty(PropertyName = "Spawn health of the npc")]
public float Health;
[JsonProperty(PropertyName = "Total rockets npc can fire")]
public int rockets;
[JsonProperty(PropertyName = "Total explosives npc can toss")]
public int explosives;
[JsonProperty(PropertyName = "Total AirDrops on event win")]
public int WinDrop;
[JsonProperty(PropertyName = "Rocket damage scale")]
public double DamageScale;
[JsonProperty(PropertyName = "Player damage scale from npc")]
public float playerDamage;
[JsonProperty(PropertyName = "Auto turret damage scale to npc")]
public float AutoTurretDamage;
[JsonProperty(PropertyName = "Raiders aimConeScale")]
public float aimConeScale;
[JsonProperty(PropertyName = "Throw Explosive item shortnames")]
public List<string> explosive;
[JsonProperty(PropertyName = "Spawn Attack Heli profile")]
public List<string> spawnCopter;
[JsonProperty(PropertyName = "Spawn kits for the npcs")]
public List<string> kits;
[JsonProperty(PropertyName = "Names to give the npcs")]
public List<string> NpcNames;
[JsonProperty(PropertyName = "CustomLoot config profile name")]
public List<string> lootProfile;
[JsonProperty(PropertyName = "CustomLoot config profile names for AirDrop")]
public List<string> lootProfileAirDrop;
[JsonProperty(PropertyName = "Juggernaut config")]
public List<string> juggernaut;
public raidConfig(int TotalAuth, int TotalNpcs, bool OnlyAuthedMembers, float Health, int RunTimeSeconds, List<string> kits, List<string> explosive, int waves, double damage, bool attackCopter, List<string> jconfig) {
this.TotalAuth = TotalAuth;
this.TotalNpcs = TotalNpcs;
this.NpcDropLoot = OnlyAuthedMembers;
this.Health = Health;
this.rockets = 20;
this.explosives = 10;
this.attackCopter = attackCopter;
this.kits = kits;
this.RunTimeSeconds = RunTimeSeconds;
this.explosive = explosive;
this.TotalNpcWaves = waves;
this.NextWaveSeconds = 120;
this.NpcNames = new List<string>() {
"Cobalt Scientist"
}
;
this.DamageScale = damage;
this.AutoTurretDamage = 1.0f;
this.FireMlrs = false;
this.playerDamage = 1.0f;
this.aimConeScale = 2f;
this.spawnCopter = new List<string>() {
"easy"
}
;
this.juggernaut = jconfig;
this.lootProfile = new List<string>();
this.lootProfileAirDrop = new List<string>();
this.WinDrop = 1;
}
}
public class copterConfig {
[JsonProperty(PropertyName = "Heli float health")]
public float startHealth;
[JsonProperty(PropertyName = "Total crates to drop")]
public int maxCratesToSpawn;
[JsonProperty(PropertyName = "Heli strafe cooldown")]
public float strafeTime;
[JsonProperty(PropertyName = "Heli can strafe x times")]
public int totalStrafe;
public copterConfig(float startHealth1, int maxCratesToSpawn1) {
this.startHealth = startHealth1;
this.maxCratesToSpawn = maxCratesToSpawn1;
this.totalStrafe = 3;
this.strafeTime = 50;
}
}
public class RBConfig {
[JsonProperty(PropertyName = "Total amount of mode complete before ever has chance")]
public int totalRaids;
[JsonProperty(PropertyName = "Raidable Base Completed Delay Before Raid chance happens")]
public float raidableBaseCompleteDelay;
[JsonProperty(PropertyName = "raid chance (1-100)")]
public int raidChance;
[JsonProperty(PropertyName = "Random raid to send them if chance")]
public List<string> sendRaids;
public RBConfig(int totalRaids1, int raidChance1, float raidableBaseCompleteDelay1, List<string> sendRaids1) {
this.totalRaids = totalRaids1;
this.raidableBaseCompleteDelay = raidableBaseCompleteDelay1;
this.raidChance = raidChance1;
this.sendRaids = sendRaids1;
}
}
public class NPCConfig {
[JsonProperty(PropertyName = "Total amount of Npc killed before chance can happen")]
public int totalRaids;
[JsonProperty(PropertyName = "Delay before chance happens")]
public float raidDelay;
[JsonProperty(PropertyName = "Raid chance (1-100)")]
public int raidChance;
[JsonProperty(PropertyName = "Cooldown minutes before chance can happen again")]
public int chanceCooldown;
[JsonProperty(PropertyName = "Random raid to send them if chance")]
public List<string> sendRaids;
public NPCConfig(int totalRaids1, int raidChance1, float raidDelay1, List<string> sendRaids1) {
this.totalRaids = totalRaids1;
this.raidDelay = raidDelay1;
this.chanceCooldown = 1440;
this.raidChance = raidChance1;
this.sendRaids = sendRaids1;
}
}
public class juggernautConfig {
[JsonProperty(PropertyName = "Juggernaut spawns on witch Wave number/Total to spawn")]
public Dictionary<int, int> juggernautOnWaves;
[JsonProperty(PropertyName = "Spawn health of the juggernaut")]
public float Health;
[JsonProperty(PropertyName = "Player damage scale from the juggernaut")]
public float playerDamage;
[JsonProperty(PropertyName = "juggernaut aimConeScale")]
public float aimConeScale;
[JsonProperty(PropertyName = "Names to give the juggernaut")]
public List<string> NpcNames;
[JsonProperty(PropertyName = "Spawn kits for the juggernaut")]
public List<string> kits;
public juggernautConfig(Dictionary<int, int> juggernautOnWaves, float Health, List<string> kits) {
this.juggernautOnWaves = juggernautOnWaves;
this.Health = Health;
this.kits = kits;
this.NpcNames = new List<string>() {
"Juggernaut Raider"
}
;
this.playerDamage = 1.0f;
this.aimConeScale = 2f;
}
}
public class itemConfig {
[JsonProperty(PropertyName = "Raid call item skin")]
public ulong itemSkin;
[JsonProperty(PropertyName = "Raid call item name")]
public string itemName;
[JsonProperty(PropertyName = "LootContainer Spawn enabled")]
public bool SpawnEnabled;
[JsonProperty(PropertyName = "Can Spawn In LootContainer types")]
public List<string> LootContainers;
[JsonProperty(PropertyName = "LootContainer Spawn Chance 1-100")]
public float SpawnChance;
public itemConfig(ulong itemSkin, string itemName, float SpawnChance, List<string> lootContainers) {
this.itemSkin = itemSkin;
this.itemName = itemName;
this.SpawnEnabled = false;
this.SpawnChance = SpawnChance;
this.LootContainers = lootContainers;
}
}
#endregion Config
#region EventRandomManager
public static float ProjectileDistToGravity(float x, float y, float θ, float v) {
float f1 = θ * ((float)Math.PI / 180f);
float f2 = (float)(((double)v * (double)v * (double)x * (double)Mathf.Sin(2f * f1) - 2.0 * (double)v * (double)v * (double)y * (double)Mathf.Cos(f1) * (double)Mathf.Cos(f1)) / ((double)x * (double)x));
if (float.IsNaN(f2) || (double)f2 < 0.00999999977648258) f2 = -Physics.gravity.y;
return f2;
}
public class RaidThinkManager : MonoBehaviour {
EventRandomManager RM {
get;
set;
}
public void Setup(EventRandomManager R) {
RM = R;
}
public void Update() {
if (RM != null && !RM.isDestroyed) RM.update();
else if (this.gameObject != null) Destroy(this);
}
}
public class EventRandomManager {
internal static List<EventRandomManager> _AllRaids = new List<EventRandomManager>();
internal static List<RandomRaider> _AllMembers = new List<RandomRaider>();
internal List<juggernautConfig> jconfig = new List<juggernautConfig>();
internal static bool isFireingMlrs;
internal List<BuildingBlock> _AllFoundations = new List<BuildingBlock>();
internal List<ulong> _authedPlayers = new List<ulong>();
internal List<RandomRaider> members;
internal bool isDestroyed = false;
internal Vector3 location;
internal raidConfig config;
internal string waveType;
internal bool newWave;
internal Coroutine QueuedRoutine;
internal BuildingPrivlidge building;
internal BaseCombatEntity tc;
internal RaidThinkManager timerObject;
internal float EndEventTime;
internal float nextWaveTime = 0;
internal int totalWaves = 0;
internal float MlrsEventTime;
internal bool active = false;
internal int totalCopters = 3;
internal GameObject thetimerObject;
internal PatrolHelicopter heli;
internal MapMarkerExplosion marker;
internal DateTime lastTaunt;
internal DeployableBoomBox boombox;
internal List<Vector3> savedPosition = new List<Vector3>();
internal List<BasePlayer> _onlinePlayers = new List<BasePlayer>();
internal DateTime activeTime = DateTime.Now;
internal int Duration;
internal DateTime time = DateTime.Now;
internal TimeSpan timeOffset;
internal DateTime lastBlock = DateTime.Now;
internal DateTime lastNotification = DateTime.MinValue;
internal DateTime lastUINotification = DateTime.MinValue;
internal int currentWave = 0;
internal bool sendGUI = false;
internal bool showFinle = false;
internal bool curentlySawning = false;
internal bool showInfinity = false;
internal static EventRandomManager Create(Vector3 l, raidConfig c, string t, RaidThinkManager timer, List<ulong> authedPlayers, GameObject gobj, List<BuildingBlock> blocks) {
EventRandomManager manager = new EventRandomManager {
members = Pool.GetList<RandomRaider>(), newWave = true, config = c, waveType = t, location = l, timerObject = timer, _authedPlayers = authedPlayers, thetimerObject = gobj, _AllFoundations = blocks, lastTaunt = DateTime.Now.AddSeconds(20)
}
;
_AllRaids.Add(manager);
if (c != null && c.juggernaut != null && c.juggernaut.Count > 0) {
foreach (var jconfigs in c.juggernaut) {
if (_.configData.juggernautProfile.ContainsKey(jconfigs)) {
manager.jconfig.Add(_.configData.juggernautProfile[jconfigs]);
}
}
}
manager.sendGUI = _.configData.settings.useGUI;
return manager;
}
internal void Start() {
Interface.Oxide.CallHook("OnRandomRaidStart", waveType, location);
MlrsEventTime = Time.time + UnityEngine.Random.Range(15f, 30f);
EndEventTime = Time.time + config.RunTimeSeconds;
nextWaveTime = Time.time + 3800;
QueuedRoutine = ServerMgr.Instance.StartCoroutine(GenerateEventMembers());
if (config.attackCopter && config.spawnCopter.Count > 0) {
string copterProfile = config.spawnCopter.GetRandom();
if (_.configData.copterSettings.copterProfile.ContainsKey(copterProfile)) heli = spawnHeli(this, location, _.configData.copterSettings.copterProfile[copterProfile]);
}
if (_.configData.settings.useMarker) marker = SpawnRaidMarker(location, EndEventTime);
if (_.configData.settings.useChat) _.notifyChat(location);
if (config.TotalNpcWaves <= 0) Duration = config.RunTimeSeconds;
else if (_.configData.settings.pauseWave) {
Duration = 10;
}
else Duration = config.NextWaveSeconds;
nextWaveTime = Time.time + config.NextWaveSeconds;
}
private static MapMarkerExplosion SpawnRaidMarker(Vector3 vector, float timeLimit) {
MapMarkerExplosion explosionMarker = null;
explosionMarker = GameManager.server.CreateEntity(StringPool.Get(4060989661), vector) as MapMarkerExplosion;
if (explosionMarker != null) {
explosionMarker.enableSaving = false;
explosionMarker.Spawn();
explosionMarker.SetDuration(timeLimit);
}
return explosionMarker;
}
public static void ChangeUrlAndPlay(BoomBox boxController, string url, Vector3 npcLoc, Quaternion rotation) {
if (boxController != null) {
if (!boxController.IsPowered()) (boxController.baseEntity as IOEntity).UpdateFromInput(100, 0);
boxController.CurrentRadioIp = url;
boxController.ServerTogglePlay(false);
boxController.baseEntity.ClientRPC<string>(null, "OnRadioIPChanged", boxController.CurrentRadioIp);
boxController.baseEntity.transform.position = npcLoc + Vector3.down * 3;
boxController.baseEntity.transform.rotation = rotation;
boxController.baseEntity.transform.hasChanged = true;
boxController.baseEntity.SendNetworkUpdateImmediate();
_.NextTick(() => {
if (boxController != null) {
boxController.ServerTogglePlay(true);
}
}
);
}
}
// Thanks to HellFire on UMOD
internal static void setupMlrs(EventRandomManager man) {
if (isFireingMlrs || man == null) return;
_.timer.Repeat(0.5f, 6, () => {
if (man == null || man.location == Vector3.zero) return;
float baseGravity;
Vector3 posUP = man.location;
posUP.y = posUP.y + 240f;
Vector3 posFire = new Vector3(man.location.x + UnityEngine.Random.Range(-2.0f, 2.0f), man.location.y, man.location.z + UnityEngine.Random.Range(-2.0f, 2.0f));
Vector3 aimToTarget = GetAimToTarget(posUP, posFire, out baseGravity);
var startPoint = posUP;
startPoint.y += 30f;
ServerProjectile projectile;
if (CreateAndSpawnRocket(startPoint, aimToTarget, out projectile) == false) return;
TimedExplosive component = projectile.GetComponent<TimedExplosive>();
if (_AllMembers.Count > 0) component.creatorEntity = _AllMembers.GetRandom();
projectile.gravityModifier = 1.5f;
//baseGravity / (0f - Physics.gravity.y);
}
);
}
internal static Vector3 GetAimToTarget(Vector3 startPosition, Vector3 targetPos, out float baseGravity) {
Vector3 vector = targetPos - startPosition;
//vector = new Vector3(4.8654f, 2.6241f, 1.3869f);
float num = 90f;
float num2 = vector.Magnitude2D();
float y = vector.y;
float num5 = 40f;
baseGravity = ProjectileDistToGravity(Mathf.Max(num2, 50f), y, num5, num);
vector.Normalize();
vector.y = 0f;
Vector3 axis = Vector3.Cross(vector, Vector3.up);
vector = Quaternion.AngleAxis(num5, axis) * vector;
return vector;
}
internal static bool CreateAndSpawnRocket(Vector3 firingPos, Vector3 firingDir, out ServerProjectile mlrsRocketProjectile) {
RaycastHit hitInfo;
float launchOffset = 0f;
if (Physics.Raycast(firingPos, firingDir, out hitInfo, launchOffset, 1236478737)) launchOffset = hitInfo.distance - 0.1f;
var mlrsRocketEntity = GameManager.server.CreateEntity("assets/content/vehicles/mlrs/rocket_mlrs.prefab", firingPos + firingDir * launchOffset);
if (mlrsRocketEntity == null) {
mlrsRocketProjectile = null;
return false;
}
mlrsRocketProjectile = mlrsRocketEntity.GetComponent<ServerProjectile>();
var velocityVector = mlrsRocketProjectile.initialVelocity + firingDir * mlrsRocketProjectile.speed;
mlrsRocketProjectile.InitializeVelocity(velocityVector);
var mlrsRocket = mlrsRocketEntity as MLRSRocket;
if (mlrsRocket == null) return false;
mlrsRocket.OwnerID = 0;
mlrsRocket.Spawn();
return true;
}
internal void update() {
ulong id = 0UL;
if (isDestroyed || !active) return;
if (EndEventTime < Time.time) {
_.PrintWarning($"Ending event at {location}");
Destroy();
return;
}
if (sendGUI) {
bool send = false;
if (lastUINotification == DateTime.MinValue) {
lastUINotification = DateTime.Now;
send = true;
}
else {
TimeSpan ts = DateTime.Now - lastUINotification;
if (ts.TotalSeconds > 1) {
send = true;
}
else {
send = false;
}
}
if (send) {
lastUINotification = DateTime.Now;
if (_onlinePlayers.Count <= 0) {
updatePlayers();
}
else {
foreach (BasePlayer onPlayers in _onlinePlayers) if (onPlayers != null && onPlayers.IsConnected) SendClockGUI(onPlayers);
}
}
}
if (config.FireMlrs && MlrsEventTime < Time.time && !EventRandomManager.isFireingMlrs && MlrsEventTime != 0) {
MlrsEventTime = 0;
setupMlrs(this);
}
if (!_.configData.settings.pauseWave) {
if (config.TotalNpcWaves > 0 && totalWaves <= config.TotalNpcWaves && nextWaveTime < Time.time) {
nextWaveTime = Time.time + config.NextWaveSeconds;
if (currentWave >= config.TotalNpcWaves) {
time = DateTime.Now;
int totalMinus = config.NextWaveSeconds * currentWave;
Duration = config.RunTimeSeconds - totalMinus;
TimeSpan timeOffset = new TimeSpan();
lastBlock = DateTime.Now;
lastNotification = DateTime.MinValue;
lastUINotification = DateTime.MinValue;
}
else {
Duration = config.NextWaveSeconds;
TimeSpan timeOffset = new TimeSpan();
lastBlock = DateTime.Now;
lastNotification = DateTime.MinValue;
lastUINotification = DateTime.MinValue;
}
if (QueuedRoutine != null) stopSpawning();
QueuedRoutine = ServerMgr.Instance.StartCoroutine(GenerateEventMembers());
return;
}
}
else {
if (!newWave && config.TotalNpcWaves > 0 && totalWaves <= config.TotalNpcWaves && members.Count <= 0 && !curentlySawning) {
curentlySawning = true;
nextWaveTime = Time.time + config.NextWaveSeconds;
if (currentWave >= config.TotalNpcWaves) {
time = DateTime.Now;
// int totalMinus = config.NextWaveSeconds * currentWave;
Dur
// ... [Code preview truncated due to length. Full source in attached file] ...