logancberrypie

draft FOL

Jul 3rd, 2021
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.61 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. public static InputField f1MenuInputField;
  13.  
  14. public static float DEFAULT_SAFE = 3;
  15. public static float DEFAULT_DAMEGE_RANGE = 8;
  16. public static float DEFAULT_DAMEGE_MOD = 1;
  17. public static float DEFAULT_OTHER_PLAYERS_NEEDED = 2;
  18.  
  19. public static Dictionary<int, playerStruct> playerIdDictionary = new Dictionary<int, playerStruct>();
  20.  
  21.  
  22. // Class -> [safe zone, warning zone, damege mod,minimumotherPlayersNeeded]
  23. public static Dictionary<PlayerClass, float[]> classInfomation = new Dictionary<PlayerClass, float[]>()
  24. {
  25. { PlayerClass.ArmyLineInfantry, new float[]{3,8,1,2} },
  26. { PlayerClass.NavalMarine, new float[]{3,8,1,2} },
  27. { PlayerClass.NavalCaptain, new float[]{3,8,1,2} },
  28. { PlayerClass.NavalSailor, new float[]{3,8,1,2} },
  29. { PlayerClass.NavalSailor2, new float[]{3,8,1,2} },
  30. { PlayerClass.ArmyInfantryOfficer, new float[]{3,8,1,2} },
  31. { PlayerClass.CoastGuard, new float[]{3,8,1,2} },
  32. { PlayerClass.Carpenter, new float[]{3,8,1,2} },
  33. { PlayerClass.Surgeon, new float[]{3,8,1,2} },
  34. { PlayerClass.Rifleman, new float[]{3,8,1, 2} },
  35. { PlayerClass.LightInfantry, new float[]{3,8,1, 2} },
  36. { PlayerClass.FlagBearer, new float[]{3,8,1, 2} },
  37. { PlayerClass.Customs, new float[]{3,8,1,2} },
  38. { PlayerClass.Drummer, new float[]{3,8,1,2} },
  39. { PlayerClass.Fifer, new float[]{3,8,1,2} },
  40. { PlayerClass.Guard, new float[]{3,8,1,2} },
  41. { PlayerClass.Violinist, new float[]{3,8,1, 2} },
  42. { PlayerClass.Grenadier, new float[]{3,8,1,2} },
  43. { PlayerClass.Bagpiper, new float[]{3,8,1,2} },
  44. { PlayerClass.Cannoneer, new float[]{3,8,1,2} },
  45. { PlayerClass.Rocketeer, new float[]{3,8,1,2} },
  46. { PlayerClass.Sapper, new float[]{3,8,1,2} },
  47. { PlayerClass.Hussar, new float[]{3,8,1,2} },
  48. { PlayerClass.CuirassierDragoon, new float[]{3,8,1, 2 } }
  49. };
  50.  
  51. //METHODS
  52.  
  53. public static void playerSpawned(int playerId, FactionCountry playerFaction, PlayerClass playerClass, int uniformId, GameObject playerObject, ulong steamId, string playerName)
  54. {
  55. playerStruct temp = new playerStruct()
  56. {
  57. _playerFaction = playerFaction,
  58. _playerClass = playerClass,
  59. _uniformId = uniformId,
  60. _playerObject = playerObject,
  61. _steamId = steamId,
  62. _playerName = playerName
  63. };
  64.  
  65. //check that its not already on dictionary -- danger is death evaders -- tut tut
  66. if (playerIdDictionary.ContainsKey(playerId))
  67. {
  68. playerIdDictionary[playerId] = temp;
  69. return;
  70. }
  71. playerIdDictionary.Add(playerId, temp);
  72. }
  73. public static void main_FOL(int playerId, bool dryShot)
  74. {
  75. if (dryShot) { return; }
  76. PlayerClass pClass = playerIdDictionary[playerId]._playerClass;
  77. var sZone = classInfomation[pClass][0];
  78. var dZone = classInfomation[pClass][1];
  79. var damegeMod = classInfomation[pClass][2];
  80. int playersNeeded = (int)classInfomation[pClass][3];
  81.  
  82. FOL_Detector(playerId, sZone, dZone, damegeMod, playersNeeded);
  83.  
  84.  
  85. }
  86. public static void FOL_Detector(int playerId, float safe_zone, float max_warning_distance,float damege_mod,int numberOfPlayersNeeded)
  87. {
  88. float playersInSafeZone = 0;
  89. float playersInDamegeZone = 0;
  90. float closestD = float.MaxValue;
  91. Vector3 playerPos = playerIdDictionary[playerId]._playerObject.transform.position;
  92.  
  93.  
  94. Collider[] hitColliders = Physics.OverlapSphere(playerPos, max_warning_distance);
  95. foreach (var hitCollider in hitColliders)
  96. {
  97. if (hitCollider.gameObject.layer == 11) //player layer
  98. {
  99. float dist = Vector3.Distance(hitCollider.gameObject.transform.position, playerIdDictionary[playerId]._playerObject.transform.position);
  100. if (dist < safe_zone && dist != 0)
  101. {
  102. playersInSafeZone += 1;
  103. }
  104. //if (dist >= safe_zone && dist < max_warning_distance)
  105. if (dist >= safe_zone)
  106. {
  107. playersInDamegeZone += 1;
  108. if (dist < closestD)
  109. {
  110. closestD = dist;
  111. }
  112. }
  113. }
  114. }
  115. if (playersInSafeZone >= numberOfPlayersNeeded) { return; } //will always interact with themself
  116.  
  117.  
  118. if (playersInSafeZone + playersInDamegeZone >= numberOfPlayersNeeded)
  119. {
  120. string reason = "You fired : " + closestD + "m out of line. Make sure to be shoulder to shoulder when firing.";
  121. int damege;
  122. if (numberOfPlayersNeeded == 0)
  123. {
  124. damege = (int)Mathf.Floor(damege_mod * Mathf.Max(100 / (max_warning_distance - safe_zone) * (closestD - safe_zone), 0));
  125. }
  126. else
  127. {
  128. damege = (int)Mathf.Floor(damege_mod * (1 - playersInSafeZone / numberOfPlayersNeeded) * Mathf.Max(100 / (max_warning_distance - safe_zone) * (closestD - safe_zone), 0));
  129. }
  130. slapPlayer(playerId, damege, reason);
  131. return;
  132. }
  133. //kill
  134. string slayReason = "you fired beyond the slap zone thus slain. Make sure to be shouldered when firing";
  135. slayPlayer(playerId, slayReason);
  136. //AutoAdmin.f1MenuInputField.onEndEdit.Invoke("function ended");
  137. }
  138.  
  139. private static void slayPlayer(int playerID, string reason)
  140. {
  141. if (f1MenuInputField == null) { return; }
  142.  
  143. var rcCommand = string.Format("serverAdmin slay {0} {1}", playerID, reason);
  144. f1MenuInputField.onEndEdit.Invoke(rcCommand);
  145. }
  146. private static void slapPlayer(int playerID, int damege, string reason)
  147. {
  148. if (f1MenuInputField == null) { return; }
  149. var rcCommand = string.Format("serverAdmin slap {0} {1} {2}", playerID, damege, reason);
  150. f1MenuInputField.onEndEdit.Invoke(rcCommand);
  151. }
  152.  
  153.  
  154. public struct playerStruct
  155. {
  156. public FactionCountry _playerFaction;
  157. public PlayerClass _playerClass;
  158. public int _uniformId;
  159. public GameObject _playerObject;
  160. public ulong _steamId;
  161. public string _playerName;
  162. }
  163.  
  164.  
  165.  
  166. }
  167.  
Add Comment
Please, Sign In to add comment