logancberrypie

Working state

Jul 12th, 2021
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.25 KB | None | 0 0
  1. using HoldfastSharedMethods;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. //using System.Linq; -- this causes an error?????????? WTF
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8.  
  9. public class AutoAdmin : MonoBehaviour
  10. {
  11.  
  12.  
  13.  
  14. public static InputField f1MenuInputField;
  15. public static float currentTime = -1;
  16. public static float FOL_TIME_CHECK_AMOUNT = 2; // seconds
  17.  
  18.  
  19.  
  20. public static float DEFAULT_SAFE = 3;
  21. public static float DEFAULT_DAMEGE_RANGE = 8;
  22. public static float DEFAULT_DAMEGE_MOD = 1;
  23. public static float DEFAULT_OTHER_PLAYERS_NEEDED = 2;
  24. public static float DEFAULT_MAX_WARNING_DAMEGE = 33;
  25.  
  26. public static string MESSAGE_PREFIT = "AUTOMOD: ";
  27.  
  28.  
  29.  
  30.  
  31. public static Dictionary<int, playerStruct> playerIdDictionary = new Dictionary<int, playerStruct>();
  32. public static Dictionary<int, joinStruct> playerJoinedDictionary = new Dictionary<int, joinStruct>();
  33.  
  34.  
  35. private static int PLAYER_LAYER = 11;
  36.  
  37. // Class -> [safe zone, warning zone, damege mod,minimumotherPlayersNeeded,maxWarningDamege]
  38. public static Dictionary<PlayerClass, float[]> classInfomation = new Dictionary<PlayerClass, float[]>()
  39. {
  40. { PlayerClass.ArmyLineInfantry, new float[]{3,8,1,2,25} },
  41. { PlayerClass.NavalMarine, new float[]{3,8,1,2, 25 } },
  42. { PlayerClass.NavalCaptain, new float[]{3,8,1,2, 25 } },
  43. { PlayerClass.NavalSailor, new float[]{3,8,1,2, 25 } },
  44. { PlayerClass.NavalSailor2, new float[]{3,8,1,2, 25 } },
  45. { PlayerClass.ArmyInfantryOfficer, new float[]{3,8,1,2, 25 } },
  46. { PlayerClass.CoastGuard, new float[]{3,8,1,2, 25 } },
  47. { PlayerClass.Carpenter, new float[]{3,8,1,2, 25 } },
  48. { PlayerClass.Surgeon, new float[]{3,8,1,2, 25 } },
  49. { PlayerClass.Rifleman, new float[]{3,8,1, 2, 25 } },
  50. { PlayerClass.LightInfantry, new float[]{3,8,1, 2, 25 } },
  51. { PlayerClass.FlagBearer, new float[]{3,8,1, 2, 25 } },
  52. { PlayerClass.Customs, new float[]{3,8,1,2, 25 } },
  53. { PlayerClass.Drummer, new float[]{3,8,1,2, 25 } },
  54. { PlayerClass.Fifer, new float[]{3,8,1,2, 25 } },
  55. { PlayerClass.Guard, new float[]{3,8,1,2, 25 } },
  56. { PlayerClass.Violinist, new float[]{3,8,1, 2, 25 } },
  57. { PlayerClass.Grenadier, new float[]{3,8,1,2, 25 } },
  58. { PlayerClass.Bagpiper, new float[]{3,8,1,2, 25 } },
  59. { PlayerClass.Cannoneer, new float[]{3,8,1,2, 25 } },
  60. { PlayerClass.Rocketeer, new float[]{3,8,1,2, 25 } },
  61. { PlayerClass.Sapper, new float[]{3,8,1,2, 25 } },
  62. { PlayerClass.Hussar, new float[]{3,8,1,2, 25 } },
  63. { PlayerClass.CuirassierDragoon, new float[]{3,8,1, 2, 25 } }
  64. };
  65.  
  66.  
  67.  
  68.  
  69. //METHODS
  70.  
  71.  
  72.  
  73. public static void TextCommandController(int playerId, TextChatChannel channel, string text)
  74. {
  75. if (channel != TextChatChannel.Admin) { return; }
  76.  
  77. string[] temp = text.Split(' ');
  78. switch(temp[0])
  79. {
  80. case "ac":
  81. if (temp.Length != 2) { break; }
  82. allCharge(temp[1]);
  83. break;
  84. default:
  85. break;
  86. }
  87. }
  88.  
  89. private static void allCharge(string v)
  90. {
  91. broadcast("enumerator method");
  92. float timer;
  93. if (float.TryParse(v, out timer))
  94. {
  95. broadcast(timer.ToString());
  96. if (timer >= 0)
  97. {
  98. broadcast("current time: " + currentTime);
  99. float timeForAC = currentTime - timer;
  100. float minutes = Mathf.Floor(timeForAC / 60); //could also use int division
  101. float seconds = timeForAC - 60 * minutes; //could also use mod.
  102. var message = MESSAGE_PREFIT + " All charge at " + minutes + ":" + seconds;
  103. broadcast(message);
  104.  
  105. var acCommand = MESSAGE_PREFIT + " All charge - Cav dismount;set allowFiring false";
  106. var temp = new allCharge(timer, acCommand);
  107. //broadcast(acCommand);
  108. }
  109. }
  110. }
  111.  
  112. public static void PlayerJoined(int playerId, ulong steamId, string name, string regimentTag, bool isBot)
  113. {
  114. joinStruct temp = new joinStruct()
  115. {
  116. _steamId = steamId,
  117. _name = name,
  118. _regimentTag = regimentTag,
  119. _isBot = isBot
  120. };
  121. playerJoinedDictionary.Add(playerId, temp);
  122. }
  123.  
  124. public static void PlayerLeft(int playerId)
  125. {
  126. playerJoinedDictionary.Remove(playerId);
  127. playerIdDictionary.Remove(playerId);
  128. }
  129.  
  130. public static void playerSpawned(int playerId, FactionCountry playerFaction, PlayerClass playerClass, int uniformId, GameObject playerObject)
  131. {
  132. playerStruct temp = new playerStruct()
  133. {
  134. _playerFaction = playerFaction,
  135. _playerClass = playerClass,
  136. _uniformId = uniformId,
  137. _playerObject = playerObject
  138. };
  139.  
  140. //check that its not already on dictionary -- danger is death evaders -- tut tut
  141. if (playerIdDictionary.ContainsKey(playerId))
  142. {
  143. playerIdDictionary[playerId] = temp;
  144. return;
  145. }
  146. playerIdDictionary.Add(playerId, temp);
  147. }
  148. public static void main_FOL(int playerId, bool dryShot)
  149. {
  150. if (dryShot) { return; }
  151. PlayerClass pClass = playerIdDictionary[playerId]._playerClass;
  152. var sZone = classInfomation[pClass][0];
  153. var dZone = classInfomation[pClass][1];
  154. var damegeMod = classInfomation[pClass][2];
  155. int playersNeeded = (int)classInfomation[pClass][3];
  156. int maxWarningDamege = (int)classInfomation[pClass][4];
  157.  
  158. FOL_Detector(playerId, sZone, dZone, damegeMod, playersNeeded, maxWarningDamege);
  159.  
  160.  
  161. }
  162.  
  163. public static void playerKilled(int killerPlayerId, int victimPlayerId, EntityHealthChangedReason reason, string additionalDetails)
  164. {
  165. if (reason != EntityHealthChangedReason.ShotByFirearm) { return; }
  166.  
  167. //this should never run, but just incase
  168. if (!playerIdDictionary.ContainsKey(killerPlayerId)) { return; }
  169.  
  170. float maxTimeDiffrence = 2;
  171.  
  172.  
  173. //was it an FOL?
  174. var killerInfo = playerIdDictionary[killerPlayerId].shotInfo;
  175.  
  176. broadcast("current time: " + currentTime + " , FOL time: " + killerInfo._timeRemaining);
  177.  
  178. if (killerInfo._timeRemaining == 0) { return; }
  179.  
  180. if (killerInfo._timeRemaining - currentTime > maxTimeDiffrence || killerInfo._timeRemaining == 0) { return; }
  181.  
  182. // if so slay and revive player.
  183. string msgReason = MESSAGE_PREFIT + "You fired : " + killerInfo._distance + "m out of line. Make sure to be shoulder to shoulder when firing.";
  184. slayPlayer(killerPlayerId, msgReason);
  185.  
  186. revivePlayer(victimPlayerId, "Killed by an FOL");
  187. }
  188.  
  189. private static void revivePlayer(int playerID, string reason)
  190. {
  191. if (f1MenuInputField == null) { return; }
  192.  
  193. var rcCommand = string.Format("serverAdmin revive {0}", playerID, reason);
  194. f1MenuInputField.onEndEdit.Invoke(rcCommand);
  195. }
  196.  
  197. public static void FOL_Detector(int playerId, float safe_zone, float max_warning_distance,float damege_mod,int numberOfPlayersNeeded,int maxWarningDamege)
  198. {
  199. if (numberOfPlayersNeeded <= 0 || damege_mod == 0) { return; }
  200.  
  201.  
  202. float playersInSafeZone = 0;
  203. float playersInDamegeZone = 0;
  204. float closestD = float.MaxValue;
  205. Vector3 playerPos = playerIdDictionary[playerId]._playerObject.transform.position;
  206.  
  207. Collider[] hitColliders = Physics.OverlapSphere(playerPos, max_warning_distance,1 << PLAYER_LAYER); // when using layer mask , this returns empty. Weird.
  208.  
  209. foreach (var hitCollider in hitColliders)
  210. {
  211. //if (hitCollider.gameObject.layer != PLAYER_LAYER) { continue; }
  212.  
  213. broadcast(hitCollider.gameObject.name);
  214. float dist = Vector3.Distance(hitCollider.gameObject.transform.position, playerIdDictionary[playerId]._playerObject.transform.position);
  215. broadcast("distance: " + dist + " safezone dist: " + safe_zone + " , warning dist: " + max_warning_distance);
  216. if (dist < safe_zone && dist != 0)
  217. {
  218. playersInSafeZone += 1;
  219. }
  220. //if (dist >= safe_zone && dist < max_warning_distance)
  221. if (dist >= safe_zone)
  222. {
  223. playersInDamegeZone += 1;
  224. if (dist < closestD)
  225. {
  226. closestD = dist;
  227. }
  228. }
  229. }
  230.  
  231. if (playersInSafeZone >= numberOfPlayersNeeded) { return; } //will always interact with themself
  232.  
  233. string reason;
  234. int damege;
  235.  
  236.  
  237. if (playersInSafeZone + playersInDamegeZone >= numberOfPlayersNeeded)
  238. {
  239. //apply damege scaling
  240. reason = MESSAGE_PREFIT + "You fired : " + closestD + "m out of line. Make sure to be shoulder to shoulder when firing.";
  241. damege = (int)Mathf.Floor(damege_mod * (1 - playersInSafeZone / numberOfPlayersNeeded) * Mathf.Max(maxWarningDamege / (max_warning_distance - safe_zone) * (closestD - safe_zone), 0));
  242. updateShotInfomation(playerId, closestD);
  243. slapPlayer(playerId, damege, reason);
  244. return;
  245. }
  246. //apply max damege
  247. reason = MESSAGE_PREFIT + "You fired without " +numberOfPlayersNeeded + " players within a radius of " +max_warning_distance+ "m. Make sure to be shoulder to shoulder with atleast " + numberOfPlayersNeeded + " other players before firing.";
  248. damege = (int)Mathf.Floor(damege_mod * maxWarningDamege);
  249. updateShotInfomation(playerId, closestD);
  250. slapPlayer(playerId, damege, reason);
  251. return;
  252.  
  253. #region Old system
  254. /*
  255.  
  256. if (playersInSafeZone + playersInDamegeZone >= numberOfPlayersNeeded)
  257. {
  258. string reason = "You fired : " + closestD + "m out of line. Make sure to be shoulder to shoulder when firing.";
  259. int damege;
  260. if (numberOfPlayersNeeded == 0)
  261. {
  262. damege = (int)Mathf.Floor(damege_mod * Mathf.Max(maxWarningDamege / (max_warning_distance - safe_zone) * (closestD - safe_zone), 0));
  263. }
  264. else
  265. {
  266. damege = (int)Mathf.Floor(damege_mod * (1 - playersInSafeZone / numberOfPlayersNeeded) * Mathf.Max(maxWarningDamege / (max_warning_distance - safe_zone) * (closestD - safe_zone), 0));
  267. }
  268.  
  269.  
  270. slapPlayer(playerId, damege, reason);
  271. updateShotInfomation(playerId, closestD);
  272. return;
  273. }
  274. //Apply max damege
  275.  
  276. //kill
  277. string slayReason = "you fired beyond the slap zone thus max slap damege applied. Make sure to be shouldered when firing";
  278. updateShotInfomation(playerId, closestD);
  279. slapPlayer(playerId,(int)Mathf.Floor(damege_mod * maxWarningDamege) , slayReason);
  280. */
  281. #endregion
  282. }
  283.  
  284. private static void updateShotInfomation(int playerID, float distance)
  285. {
  286. shotStruct temp = new shotStruct()
  287. {
  288. _timeRemaining = currentTime,
  289. _distance = distance
  290. };
  291. var change = playerIdDictionary[playerID];
  292. change.shotInfo = temp;
  293. playerIdDictionary[playerID] = change;
  294. }
  295.  
  296.  
  297. private static void slayPlayer(int playerID, string reason)
  298. {
  299. if (f1MenuInputField == null) { return; }
  300.  
  301. var rcCommand = string.Format("serverAdmin slay {0} {1}", playerID, reason);
  302. f1MenuInputField.onEndEdit.Invoke(rcCommand);
  303. }
  304. private static void slapPlayer(int playerID, int damege, string reason)
  305. {
  306. if (f1MenuInputField == null) { return; }
  307. var rcCommand = string.Format("serverAdmin slap {0} {1} {2}", playerID, damege, reason);
  308. f1MenuInputField.onEndEdit.Invoke(rcCommand);
  309. }
  310. public static void broadcast(string message)
  311. {
  312. if (f1MenuInputField == null) { return; }
  313. f1MenuInputField.onEndEdit.Invoke("broadcast "+message);
  314. }
  315.  
  316. public static bool CustomContains(string[] array, string obj)
  317. {
  318. foreach(var e in array)
  319. {
  320. if (e==obj)
  321. {
  322. return true;
  323. }
  324. }
  325. return false;
  326. }
  327.  
  328. public static void PassConfigVariables(string[] value)
  329. {
  330. string modID = "2531692643";
  331. int numberOfVariables = 5;
  332. for (int i = 0; i < value.Length; i++)
  333. {
  334. var splitData = value[i].Split(':');
  335. if (splitData.Length != 3)
  336. {
  337. Debug.LogError("invalid number of variables");
  338. continue;
  339. }
  340.  
  341. //so first variable should be the mod id
  342. if (splitData[0] == modID)
  343. {
  344. //Debug.Log("correect mod ID");
  345. string[] classTypes = System.Enum.GetNames(typeof(PlayerClass));
  346. if (!AutoAdmin.CustomContains(classTypes, splitData[1])) { continue; }
  347. PlayerClass variableClass = (PlayerClass)System.Enum.Parse(typeof(PlayerClass), splitData[1]);
  348. var variableSplit = splitData[2].Split(',');
  349. //should have 4 data parameters
  350. if (variableSplit.Length != numberOfVariables) { continue; }
  351.  
  352.  
  353. float safe = AutoAdmin.DEFAULT_SAFE;
  354. float range = AutoAdmin.DEFAULT_DAMEGE_RANGE;
  355. float damegeMod = AutoAdmin.DEFAULT_DAMEGE_MOD;
  356. float numberOfPlayers = AutoAdmin.DEFAULT_OTHER_PLAYERS_NEEDED;
  357. float maxWarningDamege = AutoAdmin.DEFAULT_MAX_WARNING_DAMEGE;
  358.  
  359. float safe_temp;
  360. float range_temp;
  361. float damegeMod_temp;
  362. float numberOfPlayers_temp;
  363. float maxWarningDamege_temp;
  364.  
  365. if (float.TryParse(variableSplit[0], out safe_temp))
  366. {
  367. if (safe_temp > 0)
  368. {
  369. //Debug.Log("safe: " + safe_temp);
  370. safe = safe_temp;
  371. }
  372. }
  373. if (float.TryParse(variableSplit[1], out range_temp))
  374. {
  375. if (range_temp > safe)
  376. {
  377. //Debug.Log("range: " + range_temp);
  378. range = range_temp;
  379. }
  380. }
  381. if (float.TryParse(variableSplit[2], out damegeMod_temp))
  382. {
  383. if (damegeMod_temp >= 0)
  384. {
  385. //Debug.Log("damegeMod: " + damegeMod_temp);
  386. damegeMod = damegeMod_temp;
  387. }
  388. }
  389. if (float.TryParse(variableSplit[3], out numberOfPlayers_temp))
  390. {
  391. if (numberOfPlayers_temp >= 0)
  392. {
  393. //Debug.Log("numPlayers: " + numberOfPlayers_temp);
  394. numberOfPlayers = numberOfPlayers_temp;
  395. }
  396. }
  397. if (float.TryParse(variableSplit[4], out maxWarningDamege_temp))
  398. {
  399. if (maxWarningDamege_temp >= 0)
  400. {
  401. //Debug.Log("maxDMG: " + maxWarningDamege_temp);
  402. maxWarningDamege = maxWarningDamege_temp;
  403. }
  404. }
  405. AutoAdmin.classInfomation[variableClass] = new float[] { safe, range, damegeMod, numberOfPlayers, maxWarningDamege };
  406. //Debug.Log("done");
  407. }
  408. }
  409. }
  410.  
  411.  
  412. public struct playerStruct
  413. {
  414. public FactionCountry _playerFaction;
  415. public PlayerClass _playerClass;
  416. public int _uniformId;
  417. public GameObject _playerObject;
  418.  
  419. public shotStruct shotInfo;
  420. }
  421.  
  422. public struct shotStruct
  423. {
  424. public float _timeRemaining;
  425. public float _distance;
  426. }
  427.  
  428. public struct joinStruct
  429. {
  430. public ulong _steamId;
  431. public string _name;
  432. public string _regimentTag;
  433. public bool _isBot;
  434. }
  435.  
  436.  
  437.  
  438. }
  439.  
Add Comment
Please, Sign In to add comment