FuelStream

BradleyControl 0.2.6

Sep 2nd, 2021
1,403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 19.99 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Reflection;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6.  
  7. namespace Oxide.Plugins
  8. {
  9.     [Info("BradleyControl", "Mattparks (edited by Steenamaroo)", "0.2.6")]
  10.     [Description("A plugin that controls Bradley properties.")]
  11.     class BradleyControl : RustPlugin
  12.     {
  13.         #region Fields
  14.  
  15.         FieldInfo tooHotUntil = typeof(HelicopterDebris).GetField("tooHotUntil", (BindingFlags.Instance | BindingFlags.NonPublic));
  16.  
  17.         private System.Random random = new System.Random();
  18.         private List<BradleyAPC> bradleys = new List<BradleyAPC>();
  19.         private List<FireBall> fireBalls = new List<FireBall>();
  20.         private List<HelicopterDebris> gibs = new List<HelicopterDebris>();
  21.         private List<LockedByEntCrate> lockedCrates = new List<LockedByEntCrate>();
  22.         private float lastBradleyDeath = 0.0f;
  23.  
  24.         #endregion
  25.  
  26.         #region Configuration
  27.  
  28.         public class Options
  29.         {
  30.             public bool bradleyEnabled = true; // Enables Bradley spawning.
  31.             public float respawnDelay = 5.0f; // The delay (minutes) before respawning the Bradley after its death.
  32.             public float startHealth = 1000.0f; // How much health the Bradley starts with.
  33.             public float maxTurretRange = 100.0f; // The range of the turrets.
  34.             public float gunAccuracy = 1.0f; // The guns accuracy (scale of 0 to 1).
  35.             public float gunDamage = 1.0f; // The guns damage (scale of 0 to 1).
  36.             public float speed = 1.0f; // The speed of movement.
  37.             public bool targetsNakeds = true; // If the Bradley will only target if you have explosives, more than 2 clothing or a radsuit, or a weapon better than a crossbow.
  38.             public bool ammoDoesDamage = false; // If ammo does damage to the Bradley.
  39.             public int maxLootCrates = 2; // How many loot boxes are dropped.
  40.             public bool customLootTables = false; // If the custom loot tables will be used.
  41.             public bool enableNapalm = true; // If there is napalm at all after death (makes boxes unlocked).
  42.             public int napamWaterRequired = -1; // How much water is needed to extengwish the napalm.
  43.             public float lootAccessDelay = -1.0f; // How long (in seconds) before the dropped boxes can be accessed.
  44.             public bool enableGibs = true; // If the Bradley will drop parts on destruction.
  45.             public float gibsHotDelay = -1.0f; // How long (in seconds) the gibs parts will be unminable and 'hot'.
  46.             public float gibsHealth = 500.0f; // How much health the gibs parts will have, more health will give more resources.
  47.  
  48.             public bool disableStartSearch = false; // Some dumb thing causing people issues.
  49.         }
  50.  
  51.         public class LootTables
  52.         {
  53.             public Dictionary<string, string[]> bradleyCrate = new Dictionary<string, string[]>();
  54.         }
  55.  
  56.         public class Targetable
  57.         {
  58.             public int mostClothing = 2;
  59.             public List<string> targetable = new List<string>();
  60.             public List<string> nonTargetable = new List<string>();
  61.         }
  62.  
  63.         public class ConfigData
  64.         {
  65.             public Options options = new Options();
  66.             public LootTables lootTables = new LootTables();
  67.             public Targetable targetable = new Targetable();
  68.         }
  69.  
  70.         private ConfigData configs;
  71.  
  72.         private void LoadDefaultConfig()
  73.         {
  74.             Puts("Creating a new config file!");
  75.             configs = new ConfigData();
  76.             SaveConfig();
  77.         }
  78.  
  79.         private void LoadVariables()
  80.         {
  81.             configs = Config.ReadObject<ConfigData>();
  82.  
  83.             if (configs == null)
  84.             {
  85.                 LoadDefaultConfig();
  86.             }
  87.  
  88.             if (configs.options.customLootTables && configs.lootTables.bradleyCrate.Count == 0)
  89.             {
  90.                 configs.lootTables.bradleyCrate = new Dictionary<string, string[]>() {
  91.                 //  {"explosive.timed", new string[]{ "1", "0", "1" } },
  92.                     { "ammo.rocket.basic", new string[]{ "1", "0", "1" } },
  93.                     { "ammo.rocket.fire", new string[]{ "1", "0", "2" } },
  94.                     { "ammo.rocket.hv", new string[]{ "1", "0", "2" } },
  95.                     { "ammo.rifle", new string[]{ "100", "0", "3" } },
  96.                     { "ammo.pistol", new string[]{ "100", "0", "3" } },
  97.                     { "ammo.rifle.incendiary", new string[]{ "100", "0", "3" } },
  98.                     { "ammo.rifle.explosive", new string[]{ "100", "0", "3" } },
  99.                     { "ammo.rifle.hv", new string[]{ "100", "0", "3" } },
  100.                     { "ammo.pistol.fire", new string[]{ "100", "0", "3" } },
  101.                     { "ammo.pistol.hv", new string[]{ "100", "0", "3" } },
  102.                     { "lmg.m249", new string[]{ "1", "0", "1" } },
  103.                     { "pistol.m92", new string[]{ "1", "0", "2" } },
  104.                     { "rifle.ak", new string[]{ "1", "0", "2" } },
  105.                     { "smg.2", new string[]{ "1", "0", "2" } },
  106.                     { "smg.mp5", new string[]{ "1", "0", "2" } },
  107.                     { "weapon.mod.holosight", new string[]{ "1", "0", "3" } },
  108.                     { "weapon.mod.silencer", new string[]{ "1", "0", "3" } },
  109.                     { "weapon.mod.flashlight", new string[]{ "1", "0", "3" } },
  110.                     { "weapon.mod.lasersight", new string[]{ "1", "0", "3" } },
  111.                     { "weapon.mod.small.scope", new string[]{ "1", "0", "3" } },
  112.                     { "targeting.computer", new string[]{ "1", "0", "3" } },
  113.                     { "cctv.camera", new string[]{ "1", "0", "3" } },
  114.                 };
  115.             }
  116.  
  117.             if (!configs.options.targetsNakeds && configs.targetable.targetable.Count == 0)
  118.             {
  119.                 configs.targetable.targetable = new List<string>() {
  120.                     "hazmatsuit",
  121.                     "explosive.timed",
  122.                     "rocket.launcher"
  123.                 };
  124.             }
  125.  
  126.             if (!configs.options.targetsNakeds && configs.targetable.nonTargetable.Count == 0)
  127.             {
  128.                 configs.targetable.nonTargetable = new List<string>() {
  129.                     "bone.club",
  130.                     "knife.bone",
  131.                     "bow.hunting",
  132.                     "longsword",
  133.                     "mace",
  134.                     "machete",
  135.                     "salvaged.cleaver",
  136.                     "salvaged.sword",
  137.                     "spear.stone",
  138.                     "spear.wooden"
  139.                 };
  140.             }
  141.  
  142.             SaveConfig();
  143.         }
  144.  
  145.         private void SaveConfig()
  146.         {
  147.             Config.WriteObject(configs, true);
  148.         }
  149.  
  150.         private void LoadMessages()
  151.         {
  152.             // English messages.
  153.             lang.RegisterMessages(new Dictionary<string, string>
  154.             {
  155.                 ["BRADLEY_ABOUT"] = "<color=#ff3b3b>Bradley Control {Version}</color>: by <color=green>mattparks</color>. Bradley Control is a plugin that controls Bradley properties. Use the /bradley command as follows: \n <color=#1586db>•</color> /bradley - Displays Bradley Control about and help. \n <color=#1586db>•</color> /bradley reset - Resets the Bradley in the area. \n <color=#1586db>•</color> /bradley clearGibs - Clears all Bradley gibs/parts. \n <color=#1586db>•</color> /bradley clearFire - Clears all Bradley fire. \n <color=#1586db>•</color> /bradley clearCrates - Clears all Bradley crates. \n <color=#1586db>•</color> /bradley unlockCrates - Unlocks all Bradley crates. \n <color=#1586db>•</color> /bradley clearAll - Clears all Bradley stuff.",
  156.                 ["BRADLEY_RESET"] = "<color=#ff3b3b>Resetting the Bradley!</color>",
  157.                 ["BRADLEY_RESET_FAIL"] = "<color=#ff3b3b>Failed to reset the Bradley!</color>",
  158.                 ["BRADLEY_REMOVE_GIBS"] = "<color=#ff3b3b>Removing Bradley gibs from the world!</color>",
  159.                 ["BRADLEY_REMOVE_FIRE"] = "<color=#ff3b3b>Removing Bradley fire from the world!</color>",
  160.                 ["BRADLEY_UNLOCK_CRATES"] = "<color=#ff3b3b>Unlocking Bradley crates!</color>",
  161.                 ["BRADLEY_REMOVE_CRATES"] = "<color=#ff3b3b>Removing Bradley crates!</color>",
  162.                 ["BRADLEY_REMOVE_ALL"] = "<color=#ff3b3b>Removing all Bradleys, parts, fires, and crates!</color>",
  163.                 ["BRADLEY_COUNT"] = "There are {Count} Bradleys.",
  164.             }, this, "en");
  165.         }
  166.  
  167.         #endregion
  168.  
  169.         #region Hooks
  170.  
  171.         private void Init()
  172.         {
  173.             LoadVariables();
  174.             LoadMessages();
  175.             permission.RegisterPermission("bradleycontrol.allow", this);
  176.         }
  177.  
  178.         bool isAllowed(BasePlayer player, string perm) => permission.UserHasPermission(player.UserIDString, perm);
  179.  
  180.         private void OnServerInitialized()
  181.         {
  182.             if (configs.options.disableStartSearch)
  183.             {
  184.                 return;
  185.             }
  186.  
  187.             foreach (var gobject in UnityEngine.Object.FindObjectsOfType<BaseEntity>())
  188.             {
  189.                 //  var nearGibs = new List<ServerGib>();
  190.                 //  Vis.Entities<ServerGib>(gobject.transform.position, 7.0f, nearGibs);
  191.  
  192.                 // if (nearGibs?.Any(p => (p?.ShortPrefabName).Contains("bradley")) ?? false)
  193.                 // {
  194.                 var prefabName = gobject?.ShortPrefabName ?? string.Empty;
  195.                 var bradley = gobject?.GetComponent<BradleyAPC>() ?? null;
  196.                 var debris = gobject?.GetComponent<HelicopterDebris>() ?? null;
  197.                 var fireball = gobject?.GetComponent<FireBall>() ?? null;
  198.                 var crate = gobject?.GetComponent<LockedByEntCrate>() ?? null;
  199.  
  200.                 if (bradley != null)
  201.                 {
  202.                     bradleys.Add(bradley);
  203.                 }
  204.  
  205.                 if (crate != null)
  206.                 {
  207.                     lockedCrates.Add(crate);
  208.                 }
  209.  
  210.                 if (fireball != null && (prefabName.Contains("napalm") || prefabName.Contains("oil")))
  211.                 {
  212.                     fireBalls.Add(fireball);
  213.                 }
  214.  
  215.                 if (debris != null)
  216.                 {
  217.                     gibs.Add(debris);
  218.                 }
  219.                 // }
  220.             }
  221.  
  222.             if (BradleySpawner.singleton != null && configs.options.respawnDelay != -1.0f)
  223.             {
  224.                 BradleySpawner.singleton.minRespawnTimeMinutes = configs.options.respawnDelay;
  225.                 BradleySpawner.singleton.maxRespawnTimeMinutes = configs.options.respawnDelay;
  226.             }
  227.         }
  228.  
  229.         private void OnEntitySpawned(BaseNetworkable entity)
  230.         {
  231.             var prefabname = entity.name;
  232.  
  233.             if (prefabname.Contains("bradleyapc"))
  234.             {
  235.                 bradleys.Add(entity as BradleyAPC);
  236.             }
  237.  
  238.             if (lastBradleyDeath == 0.0f || Time.realtimeSinceStartup - lastBradleyDeath > 2.0f) // TODO: Check if around a Bradley instead.
  239.             {
  240.                 lastBradleyDeath = 0.0f;
  241.                 return;
  242.             }
  243.  
  244.             var debris = entity?.GetComponent<HelicopterDebris>() ?? null;
  245.             gibs.Add(debris);
  246.  
  247.             if (prefabname.Contains("servergibs_bradley"))
  248.             {
  249.                 NextTick(() =>
  250.                 {
  251.                     if (debris == null || entity.IsDestroyed)
  252.                     {
  253.                         return;
  254.                     }
  255.  
  256.                     debris.InitializeHealth(configs.options.gibsHealth, configs.options.gibsHealth);
  257.  
  258.                     if (configs.options.gibsHotDelay != -1.0f)
  259.                     {
  260.                         debris.tooHotUntil = Time.realtimeSinceStartup + configs.options.gibsHotDelay;
  261.                     }
  262.  
  263.                     if (!configs.options.enableGibs)
  264.                     {
  265.                         entity.Kill();
  266.                     }
  267.  
  268.                     debris.SendNetworkUpdate();
  269.                 });
  270.             }
  271.  
  272.             if ((prefabname.Contains("napalm") || prefabname.Contains("oilfireball")) && !prefabname.Contains("rocket"))
  273.             {
  274.                 fireBalls.Add(entity as FireBall);
  275.  
  276.                 NextTick(() =>
  277.                 {
  278.                     var fireball = entity?.GetComponent<FireBall>() ?? null;
  279.  
  280.                     if (fireball == null || (entity?.IsDestroyed ?? true))
  281.                     {
  282.                         return;
  283.                     }
  284.  
  285.                     if (configs.options.lootAccessDelay != -1)
  286.                     {
  287.                         fireball.lifeTimeMin = configs.options.lootAccessDelay - 10.0f;
  288.                         fireball.lifeTimeMax = configs.options.lootAccessDelay + 10.0f;
  289.                     }
  290.  
  291.                     if (configs.options.napamWaterRequired != -1)
  292.                     {
  293.                         fireball.waterToExtinguish = configs.options.napamWaterRequired;
  294.                     }
  295.  
  296.                     if (!configs.options.enableNapalm)
  297.                     {
  298.                         fireball.enableSaving = false;
  299.                         entity.Kill();
  300.                     }
  301.  
  302.                     fireball.SendNetworkUpdate();
  303.                 });
  304.             }
  305.  
  306.             if (prefabname.Contains("bradley_crate"))
  307.             {
  308.                 var loot = entity?.GetComponent<LootContainer>() ?? null;
  309.                 lockedCrates.Add(entity?.GetComponent<LockedByEntCrate>() ?? null);
  310.  
  311.                 if (configs.options.customLootTables && configs.lootTables.bradleyCrate.Count != 0)
  312.                 {
  313.                     loot.inventory.itemList.Clear();
  314.  
  315.                     for (int i = 0; i < 6; i++)
  316.                     {
  317.                         var keys = Enumerable.ToList(configs.lootTables.bradleyCrate.Keys);
  318.                         int t = i == 0 ? 1 : i < 3 ? 2 : 3;
  319.                         int r = random.Next(keys.Count);
  320.                         var val = configs.lootTables.bradleyCrate[keys[r]];
  321.                         int j = 0;
  322.  
  323.                         while ((Convert.ToInt32(val[2]) != t || Convert.ToInt32(val[0]) == 0) && j != 20)
  324.                         {
  325.                             r = random.Next(keys.Count);
  326.                             val = configs.lootTables.bradleyCrate[keys[r]];
  327.                             j++;
  328.                         }
  329.  
  330.                         var item = ItemManager.CreateByItemID(ItemManager.FindItemDefinition(keys[r]).itemid, Convert.ToInt32(val[0]), Convert.ToUInt64(val[1]));
  331.                         item.MoveToContainer(loot.inventory);
  332.                     }
  333.  
  334.                     loot.inventory.MarkDirty();
  335.                 }
  336.  
  337.                 if (configs.options.lootAccessDelay != -1.0f)
  338.                 {
  339.                     timer.Once(configs.options.lootAccessDelay, () =>
  340.                     {
  341.                         var crate = entity?.GetComponent<LockedByEntCrate>() ?? null;
  342.  
  343.                         if (crate == null || (entity?.IsDestroyed ?? true))
  344.                         {
  345.                             return;
  346.                         }
  347.  
  348.                         var lockingEnt = (crate?.lockingEnt != null) ? crate.lockingEnt.GetComponent<FireBall>() : null;
  349.  
  350.                         if (lockingEnt != null && !(lockingEnt?.IsDestroyed ?? true))
  351.                         {
  352.                             lockingEnt.enableSaving = false;
  353.                             lockingEnt.CancelInvoke(lockingEnt.Extinguish);
  354.                             lockingEnt.Invoke(lockingEnt.Extinguish, 30.0f);
  355.                         }
  356.  
  357.                         crate.CancelInvoke(crate.Think);
  358.                         crate.SetLocked(false);
  359.                         crate.lockingEnt = null;
  360.                     });
  361.                 }
  362.             }
  363.         }
  364.  
  365.         private void OnEntityDeath(BaseCombatEntity victim, HitInfo info)
  366.         {
  367.             var prefabname = victim.name;
  368.  
  369.             var crate = victim?.GetComponent<LockedByEntCrate>() ?? null;
  370.  
  371.             if (crate != null && lockedCrates.Contains(crate))
  372.             {
  373.                 lockedCrates.Remove(crate);
  374.             }
  375.  
  376.             if (prefabname.Contains("servergibs_bradley"))
  377.             {
  378.                 var debris = victim?.GetComponent<HelicopterDebris>() ?? null;
  379.  
  380.                 if (debris != null && gibs.Contains(debris))
  381.                 {
  382.                     gibs.Remove(debris);
  383.                 }
  384.             }
  385.  
  386.             if (prefabname.Contains("bradleyapc"))
  387.             {
  388.                 var bradley = victim?.GetComponent<BradleyAPC>() ?? null;
  389.  
  390.                 if (bradley != null && bradleys.Contains(bradley))
  391.                 {
  392.                     bradleys.Remove(bradley);
  393.                 }
  394.  
  395.                 lastBradleyDeath = Time.realtimeSinceStartup;
  396.             }
  397.         }
  398.  
  399.         private object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
  400.         {
  401.             if (info?.Initiator is BradleyAPC && entity is BasePlayer)
  402.             {
  403.                 float rand = (float)random.Next(1, 100) / 100.0f;
  404.  
  405.                 if (configs.options.gunAccuracy < rand)
  406.                 {
  407.                     return true;
  408.                 }
  409.                 else
  410.                 {
  411.                     info.damageTypes.ScaleAll(configs.options.gunDamage);
  412.                     return null;
  413.                 }
  414.             }
  415.  
  416.             return null;
  417.         }
  418.  
  419.         private void OnBradleyApcInitialize(BradleyAPC bradley)
  420.         {
  421.             bradley._maxHealth = configs.options.startHealth;
  422.             bradley.health = bradley._maxHealth;
  423.             bradley.viewDistance = configs.options.maxTurretRange;
  424.             bradley.searchRange = configs.options.maxTurretRange;
  425.             bradley.throttle = configs.options.speed; // TODO: Ensure Bradley speed.
  426.             bradley.leftThrottle = bradley.throttle;
  427.             bradley.rightThrottle = bradley.throttle;
  428.             bradley.maxCratesToSpawn = configs.options.maxLootCrates;
  429.             bradley.DoAI = true;
  430.             bradley.DoSimpleAI();
  431.  
  432.             if (!configs.options.bradleyEnabled)
  433.             {
  434.                 bradley.Kill();
  435.             }
  436.         }
  437.  
  438.         private object CanBradleyApcTarget(BradleyAPC bradley, BaseEntity target)
  439.         {
  440.             if (target is NPCPlayer)
  441.             {
  442.                 return false;
  443.             }
  444.  
  445.             var player = target as BasePlayer;
  446.  
  447.             if (player != null)
  448.             {
  449.                 Vector3 mainTurretPosition = bradley.mainTurret.transform.position;
  450.  
  451.                 if (!(player.IsVisible(mainTurretPosition, bradley.CenterPoint()) || player.IsVisible(mainTurretPosition, player.eyes.position) || player.IsVisible(mainTurretPosition, player.transform.position)))
  452.                 {
  453.                     return false;
  454.                 }
  455.  
  456.                 if (!configs.options.targetsNakeds)
  457.                 {
  458.                     foreach (var item in player.inventory.containerWear.itemList)
  459.                     {
  460.                         if (configs.targetable.targetable.Contains(item.info.shortname) && !configs.targetable.nonTargetable.Contains(item.info.shortname))
  461.                         {
  462.                             return true;
  463.                         }
  464.                     }
  465.  
  466.                     if (player.inventory.containerWear.itemList.Count > configs.targetable.mostClothing)
  467.                     {
  468.                         return true;
  469.                     }
  470.  
  471.                     foreach (var item in player.inventory.containerBelt.itemList)
  472.                     {
  473.                         if (configs.targetable.targetable.Contains(item.info.shortname) && !configs.targetable.nonTargetable.Contains(item.info.shortname))
  474.                         {
  475.                             return true;
  476.                         }
  477.                     }
  478.  
  479.                     return false;
  480.                 }
  481.             }
  482.  
  483.             return bradley.IsVisible(target.CenterPoint());
  484.         }
  485.  
  486.         #endregion
  487.  
  488.         #region Chat/Console Commands
  489.  
  490.         [ChatCommand("bradley")]
  491.         private void CommandBradley(BasePlayer player, string command, string[] args)
  492.         {
  493.             if (!player.IsAdmin && !(isAllowed(player, "bradleycontrol.allow")))
  494.             {
  495.                 MessagePlayer(Lang("No Permission", player), player);
  496.                 return;
  497.             }
  498.  
  499.             if (args.Length == 0)
  500.             {
  501.                 MessagePlayer(Lang("BRADLEY_ABOUT", player).Replace("{Version}", Version.ToString()), player);
  502.             }
  503.             else
  504.             {
  505.                 if (args[0].ToLower() == "reset")
  506.                 {
  507.                     if (configs.options.bradleyEnabled)
  508.                     {
  509.                         MessagePlayer(Lang("BRADLEY_RESET", player), player);
  510.                         ResetBradley();
  511.                     }
  512.                     else
  513.                     {
  514.                         MessagePlayer(Lang("BRADLEY_RESPAWN_FAIL", player), player);
  515.                     }
  516.                 }
  517.                 else if (args[0].ToLower() == "unlockcrates")
  518.                 {
  519.                     foreach (var crate in lockedCrates)
  520.                     {
  521.                         UnlockCrate(crate);
  522.                     }
  523.  
  524.                     //   lockedCrates.Clear();
  525.                     MessagePlayer(Lang("BRADLEY_UNLOCK_CRATES", player), player);
  526.                 }
  527.                 else if (args[0].ToLower() == "clearcrates")
  528.                 {
  529.                     foreach (var crate in lockedCrates)
  530.                     {
  531.                         RemoveCrate(crate);
  532.                     }
  533.  
  534.                     lockedCrates.Clear();
  535.                     MessagePlayer(Lang("BRADLEY_REMOVE_CRATES", player), player);
  536.                 }
  537.                 else if (args[0].ToLower() == "cleargibs")
  538.                 {
  539.                     foreach (var gib in gibs)
  540.                     {
  541.                         RemoveGib(gib);
  542.                     }
  543.  
  544.                     gibs.Clear();
  545.                     MessagePlayer(Lang("BRADLEY_REMOVE_GIBS", player), player);
  546.                 }
  547.                 else if (args[0].ToLower() == "clearfire")
  548.                 {
  549.                     foreach (var ball in fireBalls)
  550.                     {
  551.                         RemoveFireBall(ball);
  552.                     }
  553.  
  554.                     fireBalls.Clear();
  555.                     MessagePlayer(Lang("BRADLEY_REMOVE_FIRE", player), player);
  556.                 }
  557.                 else if (args[0].ToLower() == "clearall")
  558.                 {
  559.                     foreach (var crate in lockedCrates)
  560.                     {
  561.                         RemoveCrate(crate);
  562.                     }
  563.  
  564.                     foreach (var gib in gibs)
  565.                     {
  566.                         RemoveGib(gib);
  567.                     }
  568.  
  569.                     foreach (var ball in fireBalls)
  570.                     {
  571.                         RemoveFireBall(ball);
  572.                     }
  573.  
  574.                     foreach (var bradley in bradleys)
  575.                     {
  576.                         RemoveBradley(bradley);
  577.                     }
  578.  
  579.                     lockedCrates.Clear();
  580.                     gibs.Clear();
  581.                     fireBalls.Clear();
  582.                     bradleys.Clear();
  583.                     MessagePlayer(Lang("BRADLEY_REMOVE_ALL", player), player);
  584.                 }
  585.             }
  586.         }
  587.  
  588.         [ConsoleCommand("bradleycontrol.reset")]
  589.         private void CommandBradley()
  590.         {
  591.             ResetBradley();
  592.             Puts("Bradley Reset");
  593.         }
  594.  
  595.         [ConsoleCommand("bradley.count")]
  596.         void CommandTagsPlayers()
  597.         {
  598.             Puts(Lang("BRADLEY_COUNT", null).Replace("{Count}", bradleys.Count.ToString()));
  599.         }
  600.  
  601.         #endregion
  602.  
  603.         #region BradleyControl
  604.  
  605.         private void ResetBradley()
  606.         {
  607.             BradleySpawner singleton = BradleySpawner.singleton;
  608.  
  609.             if (singleton == null)
  610.             {
  611.                 Puts("No Bradley Spawner!");
  612.             }
  613.             else
  614.             {
  615.                 if ((bool)singleton.spawned)
  616.                 {
  617.                     singleton.spawned.Kill(BaseNetworkable.DestroyMode.None);
  618.                 }
  619.  
  620.                 singleton.spawned = null;
  621.                 singleton.DoRespawn();
  622.             }
  623.         }
  624.  
  625.         private void UnlockCrate(LockedByEntCrate crate)
  626.         {
  627.             if (crate == null || (crate?.IsDestroyed ?? true))
  628.             {
  629.                 return;
  630.             }
  631.  
  632.             var lockingEnt = (crate?.lockingEnt != null) ? crate.lockingEnt.GetComponent<FireBall>() : null;
  633.  
  634.             if (lockingEnt != null && !(lockingEnt?.IsDestroyed ?? true))
  635.             {
  636.                 lockingEnt.enableSaving = false; //again trying to fix issue with savelist
  637.                 lockingEnt.CancelInvoke(lockingEnt.Extinguish);
  638.                 lockingEnt.Invoke(lockingEnt.Extinguish, 30.0f);
  639.             }
  640.  
  641.             crate.CancelInvoke(crate.Think);
  642.             crate.SetLocked(false);
  643.             crate.lockingEnt = null;
  644.         }
  645.          
  646.         private void RemoveCrate(LockedByEntCrate crate)
  647.         {
  648.             if (crate == null || (crate?.IsDestroyed ?? true))
  649.             {
  650.                 return;
  651.             }
  652.  
  653.             crate.Kill();
  654.         }
  655.  
  656.         private void RemoveGib(HelicopterDebris gib)
  657.         {
  658.             if (gib == null || (gib?.IsDestroyed ?? true))
  659.             {
  660.                 return;
  661.             }
  662.  
  663.             gib.Kill();
  664.         }
  665.  
  666.         private void RemoveFireBall(FireBall fireBall)
  667.         {
  668.             if (fireBall == null || (fireBall?.IsDestroyed ?? true))
  669.             {
  670.                 return;
  671.             }
  672.  
  673.             fireBall.Kill();
  674.         }
  675.  
  676.         private void RemoveBradley(BradleyAPC bradley)
  677.         {
  678.             if (bradley == null || (bradley?.IsDestroyed ?? true))
  679.             {
  680.                 return;
  681.             }
  682.  
  683.             bradley.Kill();
  684.         }
  685.  
  686.         #endregion
  687.  
  688.         #region Helpers
  689.  
  690.         private string Lang(string key, BasePlayer player)
  691.         {
  692.             var userString = player == null ? "null" : player.UserIDString;
  693.             return lang.GetMessage(key, this, userString);
  694.         }
  695.  
  696.         private void MessagePlayer(string message, BasePlayer player)
  697.         {
  698.             player.ChatMessage(message);
  699.         }
  700.  
  701.         #endregion
  702.     }
  703. }
Advertisement
Add Comment
Please, Sign In to add comment