MrWolfRanger

Airstrike Fixed

Apr 5th, 2021
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using Newtonsoft.Json;
  4. using Oxide.Core;
  5. using Oxide.Core.Configuration;
  6. using Oxide.Core.Plugins;
  7. using UnityEngine;
  8. using System.Linq;
  9. using System.Reflection;
  10.  
  11. namespace Oxide.Plugins
  12. {
  13. [Info("Airstrike", "k1lly0u", "0.3.6", ResourceId = 1489)]
  14. class Airstrike : RustPlugin
  15. {
  16. #region Fields
  17. [PluginReference] Plugin Economics, ServerRewards;
  18.  
  19. StoredData storedData;
  20. private DynamicConfigFile data;
  21.  
  22. private Dictionary<ulong, StrikeType> toggleList = new Dictionary<ulong, StrikeType>();
  23.  
  24. private Dictionary<string, int> shortnameToId = new Dictionary<string, int>();
  25. private Dictionary<string, string> shortnameToDn = new Dictionary<string, string>();
  26.  
  27. private static Airstrike ins;
  28.  
  29. const string cargoPlanePrefab = "assets/prefabs/npc/cargo plane/cargo_plane.prefab";
  30. const string basicRocket = "assets/prefabs/ammo/rocket/rocket_basic.prefab";
  31. const string fireRocket = "assets/prefabs/ammo/rocket/rocket_fire.prefab";
  32.  
  33. enum StrikeType { Strike, Squad }
  34. #endregion
  35.  
  36. #region Oxide Hooks
  37. private void Loaded()
  38. {
  39. data = Interface.Oxide.DataFileSystem.GetFile("airstrike_data");
  40.  
  41. lang.RegisterMessages(Messages, this);
  42. permission.RegisterPermission("airstrike.signal.strike", this);
  43. permission.RegisterPermission("airstrike.signal.squad", this);
  44. permission.RegisterPermission("airstrike.purchase.strike", this);
  45. permission.RegisterPermission("airstrike.purchase.squad", this);
  46. permission.RegisterPermission("airstrike.chat.strike", this);
  47. permission.RegisterPermission("airstrike.chat.squad", this);
  48. permission.RegisterPermission("airstrike.ignorecooldown", this);
  49. }
  50.  
  51. private void OnServerInitialized()
  52. {
  53. ins = this;
  54. LoadVariables();
  55. LoadData();
  56.  
  57. shortnameToId = ItemManager.itemList.ToDictionary(x => x.shortname, y => y.itemid);
  58. shortnameToDn = ItemManager.itemList.ToDictionary(x => x.shortname, y => y.displayName.translated);
  59.  
  60. CallRandomStrike();
  61. }
  62.  
  63. private void Unload()
  64. {
  65. ins = null;
  66. SaveData();
  67.  
  68. var objects = UnityEngine.Object.FindObjectsOfType<StrikePlane>();
  69. if (objects != null)
  70. {
  71. foreach (var obj in objects)
  72. UnityEngine.Object.Destroy(obj);
  73. }
  74. }
  75.  
  76. private void OnServerSave() => SaveData();
  77.  
  78. private void OnExplosiveThrown(BasePlayer player, BaseEntity entity)
  79. {
  80. if (toggleList.ContainsKey(player.userID) && entity is SupplySignal)
  81. {
  82. StrikeType type = toggleList[player.userID];
  83. toggleList.Remove(player.userID);
  84.  
  85. entity.CancelInvoke((entity as SupplySignal).Explode);
  86. entity.Invoke(entity.KillMessage, 30f);
  87. timer.Once(3, () =>
  88. {
  89. Effect.server.Run("assets/bundled/prefabs/fx/smoke_signal_full.prefab", entity, 0, new Vector3(), new Vector3());
  90. Vector3 pos = entity.transform.position;
  91. switch (type)
  92. {
  93. case StrikeType.Strike:
  94. SendReply(player, string.Format(msg("strikeConfirmed", player.UserIDString), pos));
  95. CallStrike(pos);
  96. return;
  97. case StrikeType.Squad:
  98. SendReply(player, string.Format(msg("strikeConfirmed", player.UserIDString), pos));
  99. CallSquad(pos);
  100. return;
  101. }
  102. });
  103. }
  104. }
  105. #endregion
  106.  
  107. #region Plane Control
  108. private class StrikePlane : MonoBehaviour
  109. {
  110. private CargoPlane entity;
  111. private Vector3 targetPos;
  112.  
  113. private RocketOptions rocketOptions;
  114.  
  115. private Vector3 startPos;
  116. private Vector3 endPos;
  117. private float secondsToTake;
  118.  
  119. private int rocketsFired;
  120. private float fireDistance;
  121. private bool isFiring;
  122.  
  123. private void Awake()
  124. {
  125. entity = GetComponent<CargoPlane>();
  126. rocketOptions = ins.configData.Rocket;
  127. fireDistance = ins.configData.Plane.Distance;
  128.  
  129. entity.dropped = true;
  130. enabled = false;
  131. }
  132.  
  133. private void Update()
  134. {
  135. if (!isFiring && Vector3.Distance(transform.position, targetPos) <= fireDistance)
  136. {
  137. isFiring = true;
  138. FireRocketLoop();
  139. }
  140. }
  141.  
  142. private void OnDestroy()
  143. {
  144. entity.CancelInvoke(LaunchRocket);
  145. }
  146.  
  147. public void InitializeFlightPath(Vector3 targetPos)
  148. {
  149. this.targetPos = targetPos;
  150.  
  151. float size = TerrainMeta.Size.x;
  152. float highestPoint = 170f + ins.configData.Plane.Height;
  153.  
  154. startPos = Vector3Ex.Range(-1f, 1f);
  155. startPos.y = 0f;
  156. startPos.Normalize();
  157. startPos = startPos * (size * 2f);
  158. startPos.y = highestPoint;
  159.  
  160. endPos = startPos * -1f;
  161. endPos.y = startPos.y;
  162. startPos = startPos + targetPos;
  163. endPos = endPos + targetPos;
  164.  
  165. secondsToTake = (Vector3.Distance(startPos, endPos) / ins.configData.Plane.Speed) * UnityEngine.Random.Range(0.95f, 1.05f);
  166.  
  167. entity.transform.position = startPos;
  168. entity.transform.rotation = Quaternion.LookRotation(endPos - startPos);
  169.  
  170. entity.startPos = startPos;
  171. entity.endPos = endPos;
  172. entity.dropPosition = targetPos;
  173. entity.secondsToTake = secondsToTake;
  174.  
  175. enabled = true;
  176. }
  177.  
  178. public void GetFlightData(out Vector3 startPos, out Vector3 endPos, out float secondsToTake)
  179. {
  180. startPos = this.startPos;
  181. endPos = this.endPos;
  182. secondsToTake = this.secondsToTake;
  183. }
  184.  
  185. public void SetFlightData(Vector3 startPos, Vector3 endPos, Vector3 targetPos, float secondsToTake)
  186. {
  187. this.startPos = startPos;
  188. this.endPos = endPos;
  189. this.targetPos = targetPos;
  190. this.secondsToTake = secondsToTake;
  191.  
  192. entity.transform.position = startPos;
  193. entity.transform.rotation = Quaternion.LookRotation(endPos - startPos);
  194.  
  195. entity.startPos = startPos;
  196. entity.endPos = endPos;
  197. entity.dropPosition = targetPos;
  198. entity.secondsToTake = secondsToTake;
  199.  
  200. enabled = true;
  201. }
  202.  
  203. private void FireRocketLoop()
  204. {
  205. entity.InvokeRepeating(LaunchRocket, 0, rocketOptions.Interval);
  206. }
  207.  
  208. private void LaunchRocket()
  209. {
  210. if (rocketsFired >= rocketOptions.Amount)
  211. {
  212. entity.CancelInvoke(LaunchRocket);
  213. return;
  214. }
  215. var rocketType = rocketOptions.Type == "Normal" ? basicRocket : fireRocket;
  216. if (rocketOptions.Mixed && UnityEngine.Random.Range(1, rocketOptions.FireChance) == 1)
  217. rocketType = fireRocket;
  218.  
  219. Vector3 launchPos = entity.transform.position;
  220. Vector3 newTarget = Quaternion.Euler(GetRandom(), GetRandom(), GetRandom()) * targetPos;
  221.  
  222. BaseEntity rocket = GameManager.server.CreateEntity(rocketType, launchPos, new Quaternion(), true);
  223.  
  224. TimedExplosive rocketExplosion = rocket.GetComponent<TimedExplosive>();
  225. ServerProjectile rocketProjectile = rocket.GetComponent<ServerProjectile>();
  226.  
  227. rocketProjectile.speed = rocketOptions.Speed;
  228. rocketProjectile.gravityModifier = 0;
  229. rocketExplosion.timerAmountMin = 60;
  230. rocketExplosion.timerAmountMax = 60;
  231. for (int i = 0; i < rocketExplosion.damageTypes.Count; i++)
  232. rocketExplosion.damageTypes[i].amount *= rocketOptions.Damage;
  233.  
  234. Vector3 newDirection = (newTarget - launchPos);
  235.  
  236. rocket.SendMessage("InitializeVelocity", (newDirection));
  237. rocket.Spawn();
  238. ++rocketsFired;
  239. }
  240.  
  241. private float GetRandom() => UnityEngine.Random.Range(-rocketOptions.Accuracy * 0.2f, rocketOptions.Accuracy * 0.2f);
  242. }
  243. #endregion
  244.  
  245. #region Functions
  246. private void CallRandomStrike()
  247. {
  248. if (!configData.Other.RandomStrikes && !configData.Other.RandomSquads) return;
  249.  
  250. timer.In(UnityEngine.Random.Range(configData.Other.RandomTimer[0], configData.Other.RandomTimer[1]), () =>
  251. {
  252. StrikeType type;
  253. if (configData.Other.RandomStrikes && configData.Other.RandomSquads)
  254. type = UnityEngine.Random.Range(1, 2) == 1 ? type = StrikeType.Strike : type = StrikeType.Squad;
  255. else if (configData.Other.RandomStrikes)
  256. type = StrikeType.Strike;
  257. else type = StrikeType.Squad;
  258.  
  259. if (type == StrikeType.Strike)
  260. CallStrike(GetRandomPosition());
  261. else CallSquad(GetRandomPosition());
  262.  
  263. CallRandomStrike();
  264. });
  265. }
  266. private void CallStrike(Vector3 position)
  267. {
  268. CargoPlane entity = CreatePlane();
  269. entity.Spawn();
  270.  
  271. StrikePlane plane = entity.gameObject.AddComponent<StrikePlane>();
  272. plane.InitializeFlightPath(position);
  273.  
  274. if (configData.Other.Broadcast)
  275. PrintToChat(msg("strikeInbound"));
  276. }
  277. private void CallSquad(Vector3 position)
  278. {
  279. CargoPlane leaderEnt = CreatePlane();
  280. leaderEnt.Spawn();
  281.  
  282. StrikePlane leaderPlane = leaderEnt.gameObject.AddComponent<StrikePlane>();
  283. leaderPlane.InitializeFlightPath(position);
  284.  
  285. Vector3 startPos;
  286. Vector3 endPos;
  287. float secondsToTake;
  288. leaderPlane.GetFlightData(out startPos, out endPos, out secondsToTake);
  289.  
  290. CargoPlane leftEnt = CreatePlane();
  291. leftEnt.Spawn();
  292. StrikePlane leftPlane = leftEnt.gameObject.AddComponent<StrikePlane>();
  293. Vector3 leftOffset = (leaderEnt.transform.right * 70) + (-leaderEnt.transform.forward * 80);
  294. leftPlane.SetFlightData(startPos + leftOffset, endPos + leftOffset, position + (leftOffset / 4), secondsToTake);
  295.  
  296. CargoPlane rightEnt = CreatePlane();
  297. rightEnt.Spawn();
  298. StrikePlane rightPlane = rightEnt.gameObject.AddComponent<StrikePlane>();
  299. Vector3 rightOffset = (-leaderEnt.transform.right * 70) + (-leaderEnt.transform.forward * 80);
  300. rightPlane.SetFlightData(startPos + rightOffset, endPos + rightOffset, position + (rightOffset / 4), secondsToTake);
  301.  
  302. if (configData.Other.Broadcast)
  303. PrintToChat(msg("squadInbound"));
  304. }
  305.  
  306. private bool CanBuyStrike(BasePlayer player, StrikeType type)
  307. {
  308. Dictionary<string, int> costToBuy = type == StrikeType.Strike ? configData.Buy.StrikeCost : configData.Buy.SquadCost;
  309.  
  310. foreach(var item in costToBuy)
  311. {
  312. if (item.Key == "RP")
  313. {
  314. if (ServerRewards)
  315. {
  316. if ((int)ServerRewards.Call("CheckPoints", player.userID) < item.Value)
  317. {
  318. SendReply(player, string.Format(msg("buyItem", player.UserIDString), item.Value, item.Key));
  319. Effect.server.Run("assets/prefabs/locks/keypad/effects/lock.code.denied.prefab", player.transform.position);
  320. return false;
  321. }
  322. }
  323. }
  324. if (item.Key == "Economics")
  325. {
  326. if (Economics)
  327. {
  328. if ((double)Economics.Call("GetPlayerMoney", player.userID) < item.Value)
  329. {
  330. SendReply(player, string.Format(msg("buyItem", player.UserIDString), item.Value, item.Key));
  331. Effect.server.Run("assets/prefabs/locks/keypad/effects/lock.code.denied.prefab", player.transform.position);
  332. return false;
  333. }
  334. }
  335. }
  336. if (shortnameToId.ContainsKey(item.Key))
  337. {
  338. if (player.inventory.GetAmount(shortnameToId[item.Key]) < item.Value)
  339. {
  340. SendReply(player, string.Format(msg("buyItem", player.UserIDString), item.Value, shortnameToDn[item.Key]));
  341. Effect.server.Run("assets/prefabs/locks/keypad/effects/lock.code.denied.prefab", player.transform.position);
  342. return false;
  343. }
  344. }
  345. }
  346. Effect.server.Run("assets/prefabs/locks/keypad/effects/lock.code.updated.prefab", player.transform.position);
  347. return true;
  348. }
  349.  
  350. private void BuyStrike(BasePlayer player, StrikeType type)
  351. {
  352. Dictionary<string, int> costToBuy = type == StrikeType.Strike ? configData.Buy.StrikeCost : configData.Buy.SquadCost;
  353.  
  354. foreach (var item in costToBuy)
  355. {
  356. if (item.Key == "RP")
  357. {
  358. if (ServerRewards)
  359. ServerRewards.Call("TakePoints", player.userID, item.Value);
  360. }
  361. if (item.Key == "Economics")
  362. {
  363. if (Economics)
  364. Economics.Call("Withdraw", player.userID, (double)item.Value);
  365. }
  366. if (shortnameToId.ContainsKey(item.Key))
  367. player.inventory.Take(null, shortnameToId[item.Key], item.Value);
  368. }
  369. if (type == StrikeType.Strike)
  370. {
  371. CallStrike(player.transform.position);
  372. SendReply(player, string.Format(msg("strikeConfirmed", player.UserIDString), player.transform.position));
  373. }
  374. else
  375. {
  376. CallSquad(player.transform.position);
  377. SendReply(player, string.Format(msg("squadConfirmed", player.UserIDString), player.transform.position));
  378. }
  379. }
  380. #endregion
  381.  
  382. #region Helpers
  383. private double GrabCurrentTime() => DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;
  384. private CargoPlane CreatePlane() => (CargoPlane)GameManager.server.CreateEntity(cargoPlanePrefab, new Vector3(), new Quaternion(), true);
  385. private bool isStrikePlane(CargoPlane plane) => plane.GetComponent<StrikePlane>();
  386. private bool HasPermission(BasePlayer player, string perm) => permission.UserHasPermission(player.UserIDString, perm);
  387.  
  388. private Vector3 GetRandomPosition()
  389. {
  390. float mapSize = (TerrainMeta.Size.x / 2) - 600f;
  391.  
  392. float randomX = UnityEngine.Random.Range(-mapSize, mapSize);
  393. float randomY = UnityEngine.Random.Range(-mapSize, mapSize);
  394.  
  395. return new Vector3(randomX, 0f, randomY);
  396. }
  397.  
  398. private string FormatTime(double time)
  399. {
  400. TimeSpan dateDifference = TimeSpan.FromSeconds((float)time);
  401. var days = dateDifference.Days;
  402. var hours = dateDifference.Hours;
  403. hours += (days * 24);
  404. var mins = dateDifference.Minutes;
  405. var secs = dateDifference.Seconds;
  406. return string.Format("{0:00}:{1:00}:{2:00}", hours, mins, secs);
  407. }
  408. private List<BasePlayer> FindPlayer(string arg)
  409. {
  410. var foundPlayers = new List<BasePlayer>();
  411.  
  412. ulong steamid;
  413. ulong.TryParse(arg, out steamid);
  414. string lowerarg = arg.ToLower();
  415.  
  416. foreach (var player in BasePlayer.activePlayerList)
  417. {
  418. if (steamid != 0L)
  419. {
  420. if (player.userID == steamid)
  421. {
  422. foundPlayers.Clear();
  423. foundPlayers.Add(player);
  424. return foundPlayers;
  425. }
  426. }
  427. string lowername = player.displayName.ToLower();
  428. if (lowername.Contains(lowerarg))
  429. {
  430. foundPlayers.Add(player);
  431. }
  432. }
  433. return foundPlayers;
  434. }
  435. #endregion
  436.  
  437. #region Commands
  438. [ChatCommand("airstrike")]
  439. private void cmdAirstrike(BasePlayer player, string command, string[] args)
  440. {
  441. if (args.Length == 0)
  442. {
  443. SendReply(player, string.Format("Airstrike v.{0}", Version));
  444. if (HasPermission(player, "airstrike.signal.strike"))
  445. SendReply(player, msg("help1", player.UserIDString));
  446. if (HasPermission(player, "airstrike.signal.squad"))
  447. SendReply(player, msg("help2", player.UserIDString));
  448. if (HasPermission(player, "airstrike.purchase.strike"))
  449. SendReply(player, msg("help3", player.UserIDString));
  450. if (HasPermission(player, "airstrike.purchase.squad"))
  451. SendReply(player, msg("help4", player.UserIDString));
  452. if (HasPermission(player, "airstrike.chat.strike"))
  453. {
  454. SendReply(player, msg("help5", player.UserIDString));
  455. SendReply(player, msg("help6", player.UserIDString));
  456. SendReply(player, msg("help7", player.UserIDString));
  457. }
  458. if (HasPermission(player, "airstrike.chat.squad"))
  459. {
  460. SendReply(player, msg("help8", player.UserIDString));
  461. SendReply(player, msg("help9", player.UserIDString));
  462. SendReply(player, msg("help10", player.UserIDString));
  463. }
  464. return;
  465. }
  466. if (args.Length >= 2)
  467. {
  468. var time = GrabCurrentTime();
  469. StrikeType type = args[1].ToLower() == "squad" ? StrikeType.Squad : StrikeType.Strike;
  470.  
  471. if (!HasPermission(player, "airstrike.ignorecooldown"))
  472. {
  473. if (configData.Cooldown.Enabled)
  474. {
  475. CooldownData data;
  476. if (storedData.cooldowns.TryGetValue(player.userID, out data))
  477. {
  478. double nextUse = type == StrikeType.Strike ? data.strikeCd : data.squadCd;
  479. if (nextUse > time)
  480. {
  481. double remaining = nextUse - time;
  482. SendReply(player, string.Format(msg("onCooldown", player.UserIDString), FormatTime(remaining)));
  483. return;
  484. }
  485. }
  486. }
  487. }
  488. switch (args[0].ToLower())
  489. {
  490. case "signal":
  491. if ((type == StrikeType.Strike && configData.Other.SignalStrike) || (type == StrikeType.Squad && configData.Other.SignalSquad))
  492. {
  493. if (!HasPermission(player, $"airstrike.signal.{type.ToString().ToLower()}"))
  494. {
  495. SendReply(player, msg("noPerms", player.UserIDString));
  496. return;
  497. }
  498. }
  499. if (toggleList.ContainsKey(player.userID))
  500. toggleList[player.userID] = type;
  501. else toggleList.Add(player.userID, type);
  502. SendReply(player, msg("signalReady", player.UserIDString));
  503. return;
  504. case "buy":
  505. if ((type == StrikeType.Strike && configData.Buy.PermissionStrike) || (type == StrikeType.Squad && configData.Buy.PermissionSquad))
  506. {
  507. if (!HasPermission(player, $"airstrike.purchase.{type.ToString().ToLower()}"))
  508. {
  509. SendReply(player, msg("noPerms", player.UserIDString));
  510. return;
  511. }
  512. }
  513. if (CanBuyStrike(player, type))
  514. {
  515. BuyStrike(player, type);
  516. }
  517. return;
  518. case "call":
  519. if (HasPermission(player, $"airstrike.chat.{type.ToString().ToLower()}"))
  520. {
  521. Vector3 position;
  522. if (args.Length == 4)
  523. {
  524. float x, z;
  525. if (!float.TryParse(args[2], out x) || !float.TryParse(args[3], out z))
  526. {
  527. SendReply(player, msg("invCoords", player.UserIDString));
  528. return;
  529. }
  530. else position = new Vector3(x, 0, z);
  531. }
  532. else if (args.Length == 3)
  533. {
  534. var players = FindPlayer(args[2]);
  535. if (players.Count > 1)
  536. {
  537. SendReply(player, msg("multiplePlayers", player.UserIDString));
  538. return;
  539. }
  540. else if (players.Count == 0)
  541. {
  542. SendReply(player, msg("noPlayers", player.UserIDString));
  543. return;
  544. }
  545. else position = players[0].transform.position;
  546. }
  547. else position = player.transform.position;
  548.  
  549. if (type == StrikeType.Strike)
  550. {
  551. CallStrike(position);
  552. SendReply(player, string.Format(msg("strikeConfirmed", player.UserIDString), position));
  553. }
  554. else
  555. {
  556. CallSquad(position);
  557. SendReply(player, string.Format(msg("squadConfirmed", player.UserIDString), position));
  558. }
  559. }
  560. else SendReply(player, msg("noPerms", player.UserIDString));
  561. return;
  562. default:
  563. break;
  564. }
  565. }
  566. }
  567.  
  568. [ConsoleCommand("airstrike")]
  569. private void ccmdAirstrike(ConsoleSystem.Arg arg)
  570. {
  571. if (arg.Connection != null)
  572. return;
  573.  
  574. if (arg.Args == null || arg.Args.Length == 0)
  575. {
  576. SendReply(arg, "airstrike strike <x> <z> - Call a airstrike to the target position");
  577. SendReply(arg, "airstrike squad <x> <z> - Call a squadstrike to the target position");
  578. SendReply(arg, "airstrike strike <playername> - Call a airstrike to the target player");
  579. SendReply(arg, "airstrike squad <playername> - Call a squadstrike to the target player");
  580. SendReply(arg, "airstrike strike random - Call a random airstrike");
  581. SendReply(arg, "airstrike squad random - Call a random squadstrike");
  582. return;
  583. }
  584.  
  585. StrikeType type = arg.Args[0].ToLower() == "squad" ? StrikeType.Squad : StrikeType.Strike;
  586.  
  587. Vector3 position = Vector3.zero;
  588.  
  589. if (arg.Args.Length == 3)
  590. {
  591. float x, z;
  592. if (!float.TryParse(arg.Args[1], out x) || !float.TryParse(arg.Args[2], out z))
  593. {
  594. SendReply(arg, "Invalid co-ordinates set. You must enter number values for X and Z");
  595. return;
  596. }
  597. else position = new Vector3(x, 0, z);
  598. }
  599. else if (arg.Args.Length == 2)
  600. {
  601. if (arg.Args[1].ToLower() == "random")
  602. position = GetRandomPosition();
  603. else
  604. {
  605. var players = FindPlayer(arg.Args[1]);
  606. if (players.Count > 1)
  607. {
  608. SendReply(arg, "Multiple players found");
  609. return;
  610. }
  611. else if (players.Count == 0)
  612. {
  613. SendReply(arg, "No players found");
  614. return;
  615. }
  616. else position = players[0].transform.position;
  617. }
  618. }
  619.  
  620. if (type == StrikeType.Strike)
  621. {
  622. CallStrike(position);
  623. SendReply(arg, string.Format("Airstrike confirmed at co-ordinates: {0}!", position));
  624. }
  625. else
  626. {
  627. CallSquad(position);
  628. SendReply(arg, string.Format("Squadstrike confirmed at co-ordinates: {0}!", position));
  629. }
  630. }
  631. #endregion
  632.  
  633. #region Config
  634. private ConfigData configData;
  635. class RocketOptions
  636. {
  637. [JsonProperty(PropertyName = "Speed of the rocket")]
  638. public float Speed { get; set; }
  639. [JsonProperty(PropertyName = "Damage modifier")]
  640. public float Damage { get; set; }
  641. [JsonProperty(PropertyName = "Accuracy of rocket (a lower number is more accurate)")]
  642. public float Accuracy { get; set; }
  643. [JsonProperty(PropertyName = "Interval between rockets (seconds)")]
  644. public float Interval { get; set; }
  645. [JsonProperty(PropertyName = "Type of rocket (Normal, Napalm)")]
  646. public string Type { get; set; }
  647. [JsonProperty(PropertyName = "Use both rocket types")]
  648. public bool Mixed { get; set; }
  649. [JsonProperty(PropertyName = "Chance of a fire rocket (when using both types)")]
  650. public int FireChance { get; set; }
  651. [JsonProperty(PropertyName = "Amount of rockets to fire")]
  652. public int Amount { get; set; }
  653. }
  654.  
  655. class CooldownOptions
  656. {
  657. [JsonProperty(PropertyName = "Use cooldown timers")]
  658. public bool Enabled { get; set; }
  659. [JsonProperty(PropertyName = "Strike cooldown time (seconds)")]
  660. public int Strike { get; set; }
  661. [JsonProperty(PropertyName = "Squad cooldown time (seconds)")]
  662. public int Squad { get; set; }
  663. }
  664.  
  665. class PlaneOptions
  666. {
  667. [JsonProperty(PropertyName = "Flight speed (meters per second)")]
  668. public float Speed { get; set; }
  669. [JsonProperty(PropertyName = "Distance from target to engage")]
  670. public float Distance { get; set; }
  671. [JsonProperty(PropertyName = "Height modifier")]
  672. public float Height { get; set; }
  673. }
  674.  
  675. class BuyOptions
  676. {
  677. [JsonProperty(PropertyName = "Can purchase standard strike")]
  678. public bool StrikeEnabled { get; set; }
  679. [JsonProperty(PropertyName = "Can purchase squad strike")]
  680. public bool SquadEnabled { get; set; }
  681. [JsonProperty(PropertyName = "Require permission to purchase strike")]
  682. public bool PermissionStrike { get; set; }
  683. [JsonProperty(PropertyName = "Require permission to purchase squad strike")]
  684. public bool PermissionSquad { get; set; }
  685. [JsonProperty(PropertyName = "Cost to purchase a standard strike (shortname, amount)")]
  686. public Dictionary<string, int> StrikeCost { get; set; }
  687. [JsonProperty(PropertyName = "Cost to purchase a squad strike (shortname, amount)")]
  688. public Dictionary<string, int> SquadCost { get; set; }
  689. }
  690.  
  691. class OtherOptions
  692. {
  693. [JsonProperty(PropertyName = "Broadcast strikes to chat")]
  694. public bool Broadcast { get; set; }
  695. [JsonProperty(PropertyName = "Can call standard strikes using a supply signal")]
  696. public bool SignalStrike { get; set; }
  697. [JsonProperty(PropertyName = "Can call squad strikes using a supply signal")]
  698. public bool SignalSquad { get; set; }
  699. [JsonProperty(PropertyName = "Use random airstrikes")]
  700. public bool RandomStrikes { get; set; }
  701. [JsonProperty(PropertyName = "Use random squad strikes")]
  702. public bool RandomSquads { get; set; }
  703. [JsonProperty(PropertyName = "Random timer (minimum, maximum. In seconds)")]
  704. public int[] RandomTimer { get; set; }
  705. }
  706.  
  707. class ConfigData
  708. {
  709. [JsonProperty(PropertyName = "Rocket Options")]
  710. public RocketOptions Rocket { get; set; }
  711. [JsonProperty(PropertyName = "Cooldown Options")]
  712. public CooldownOptions Cooldown { get; set; }
  713. [JsonProperty(PropertyName = "Plane Options")]
  714. public PlaneOptions Plane { get; set; }
  715. [JsonProperty(PropertyName = "Purchase Options")]
  716. public BuyOptions Buy { get; set; }
  717. [JsonProperty(PropertyName = "Other Options")]
  718. public OtherOptions Other { get; set; }
  719. }
  720.  
  721. private void LoadVariables()
  722. {
  723. LoadConfigVariables();
  724. SaveConfig();
  725. }
  726.  
  727. protected override void LoadDefaultConfig()
  728. {
  729. var config = new ConfigData
  730. {
  731. Buy = new BuyOptions
  732. {
  733. SquadCost = new Dictionary<string, int>
  734. {
  735. ["metal.refined"] = 100,
  736. ["techparts"] = 50,
  737. ["targeting.computer"] = 1
  738. },
  739. SquadEnabled = true,
  740. PermissionSquad = true,
  741. StrikeCost = new Dictionary<string, int>
  742. {
  743. ["metal.refined"] = 50,
  744. ["targeting.computer"] = 1
  745. },
  746. StrikeEnabled = true,
  747. PermissionStrike = true
  748. },
  749. Cooldown = new CooldownOptions
  750. {
  751. Enabled = true,
  752. Squad = 3600,
  753. Strike = 3600
  754. },
  755. Other = new OtherOptions
  756. {
  757. Broadcast = true,
  758. SignalSquad = true,
  759. SignalStrike = true,
  760. RandomSquads = true,
  761. RandomStrikes = true,
  762. RandomTimer = new int[] { 1800, 3600 }
  763. },
  764. Plane = new PlaneOptions
  765. {
  766. Distance = 900,
  767. Speed = 105,
  768. Height = 0
  769. },
  770. Rocket = new RocketOptions
  771. {
  772. Accuracy = 1.5f,
  773. Amount = 15,
  774. Damage = 1.0f,
  775. FireChance = 4,
  776. Interval = 0.6f,
  777. Mixed = true,
  778. Speed = 110f,
  779. Type = "Normal"
  780. }
  781. };
  782. SaveConfig(config);
  783. }
  784.  
  785. private void LoadConfigVariables() => configData = Config.ReadObject<ConfigData>();
  786.  
  787. private void SaveConfig(ConfigData config) => Config.WriteObject(config, true);
  788. #endregion
  789.  
  790. #region Data Management
  791. private void SaveData() => data.WriteObject(storedData);
  792.  
  793. private void LoadData()
  794. {
  795. try
  796. {
  797. storedData = data.ReadObject<StoredData>();
  798. }
  799. catch
  800. {
  801. storedData = new StoredData();
  802. }
  803. }
  804.  
  805. private void ClearData()
  806. {
  807. storedData = new StoredData();
  808. SaveData();
  809. }
  810.  
  811. class StoredData
  812. {
  813. public Dictionary<ulong, CooldownData> cooldowns = new Dictionary<ulong, CooldownData>();
  814. }
  815.  
  816. class CooldownData
  817. {
  818. public double strikeCd, squadCd;
  819. }
  820. #endregion
  821.  
  822. #region Localization
  823. string msg(string key, string playerId = null) => lang.GetMessage(key, this, playerId);
  824.  
  825. Dictionary<string, string> Messages = new Dictionary<string, string>
  826. {
  827. ["strikeConfirmed"] = "Airstrike confirmed at co-ordinates: {0}",
  828. ["squadConfirmed"] = "Squadstrike confirmed at co-ordinates: {0}",
  829. ["strikeInbound"] = "Airstrike inbound!",
  830. ["squadInbound"] = "Squadstrike inbound!",
  831. ["buyItem"] = "You need another {0} {1} to buy this strike",
  832. ["help1"] = "/airstrike signal strike - Use a supply signal to mark a airstrike position",
  833. ["help2"] = "/airstrike signal squad - Use a supply signal to mark a squadstrike position",
  834. ["help3"] = "/airstrike buy strike - Purchase a airstrike on your position",
  835. ["help4"] = "/airstrike buy squad - Purchase a squadstrike on your position",
  836. ["help5"] = "/airstrike call strike - Call a airstrike on your position",
  837. ["help6"] = "/airstrike call strike <x> <z> - Call a airstrike to the target position",
  838. ["help7"] = "/airstrike call strike <player name> - Call a airstrike to the target player",
  839. ["help8"] = "/airstrike call squad - Call a squadstrike on your position",
  840. ["help9"] = "/airstrike call squad <x> <z> - Call a squadstrike to the target position",
  841. ["help10"] = "/airstrike call squad <player name> - Call a squadstrike to the target player",
  842. ["onCooldown"] = "You must wait another {0} before calling this type again",
  843. ["noPerms"] = "You do not have permission to use that strike type",
  844. ["signalReady"] = "Throw a supply signal to call a strike",
  845. ["invCoords"] = "Invalid co-ordinates set. You must enter number values for X and Z",
  846. ["multiplePlayers"] = "Multiple players found",
  847. ["noPlayers"] = "No players found"
  848. };
  849. #endregion
  850. }
  851. }
  852.  
Advertisement
Add Comment
Please, Sign In to add comment