Col


SUBMITTED BY: Alerand

DATE: May 7, 2016, 11:03 a.m.

FORMAT: Text only

SIZE: 10.8 kB

HITS: 9797

  1. #region
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using LeagueSharp;
  6. using LeagueSharp.Common;
  7. using SharpDX;
  8. #endregion
  9. namespace Marksman.Evade
  10. {
  11. public enum CollisionObjectTypes
  12. {
  13. Minion,
  14. Champions,
  15. YasuoWall,
  16. }
  17. internal class FastPredResult
  18. {
  19. public Vector2 CurrentPos;
  20. public bool IsMoving;
  21. public Vector2 PredictedPos;
  22. }
  23. internal class DetectedCollision
  24. {
  25. public float Diff;
  26. public float Distance;
  27. public Vector2 Position;
  28. public CollisionObjectTypes Type;
  29. public Obj_AI_Base Unit;
  30. }
  31. internal static class Collision
  32. {
  33. private static int WallCastT;
  34. private static Vector2 YasuoWallCastedPos;
  35. public static void Init()
  36. {
  37. Obj_AI_Base.OnProcessSpellCast += Obj_AI_Hero_OnProcessSpellCast;
  38. }
  39. private static void Obj_AI_Hero_OnProcessSpellCast(Obj_AI_Base sender, GameObjectProcessSpellCastEventArgs args)
  40. {
  41. if (sender.IsValid && sender.Team == ObjectManager.Player.Team && args.SData.Name == "YasuoWMovingWall")
  42. {
  43. WallCastT = Utils.TickCount;
  44. YasuoWallCastedPos = sender.ServerPosition.To2D();
  45. }
  46. }
  47. public static FastPredResult FastPrediction(Vector2 from, Obj_AI_Base unit, int delay, int speed)
  48. {
  49. var tDelay = delay / 1000f + (from.Distance(unit) / speed);
  50. var d = tDelay * unit.MoveSpeed;
  51. var path = unit.GetWaypoints();
  52. if (path.PathLength() > d)
  53. {
  54. return new FastPredResult
  55. {
  56. IsMoving = true,
  57. CurrentPos = unit.ServerPosition.To2D(),
  58. PredictedPos = path.CutPath((int) d)[0],
  59. };
  60. }
  61. return new FastPredResult
  62. {
  63. IsMoving = false,
  64. CurrentPos = path[path.Count - 1],
  65. PredictedPos = path[path.Count - 1],
  66. };
  67. }
  68. public static Vector2 GetCollisionPoint(Skillshot skillshot)
  69. {
  70. var collisions = new List<DetectedCollision>();
  71. var from = skillshot.GetMissilePosition(0);
  72. skillshot.ForceDisabled = false;
  73. foreach (var cObject in skillshot.SpellData.CollisionObjects)
  74. {
  75. switch (cObject)
  76. {
  77. case CollisionObjectTypes.Minion:
  78. if (!Config.Menu.Item("MinionCollision").GetValue<bool>())
  79. {
  80. break;
  81. }
  82. foreach (var minion in
  83. MinionManager.GetMinions(
  84. from.To3D(), 1200, MinionTypes.All,
  85. skillshot.Unit.Team == ObjectManager.Player.Team
  86. ? MinionTeam.NotAlly
  87. : MinionTeam.NotAllyForEnemy))
  88. {
  89. var pred = FastPrediction(
  90. from, minion,
  91. Math.Max(0, skillshot.SpellData.Delay - (Utils.TickCount - skillshot.StartTick)),
  92. skillshot.SpellData.MissileSpeed);
  93. var pos = pred.PredictedPos;
  94. var w = skillshot.SpellData.RawRadius + (!pred.IsMoving ? (minion.BoundingRadius - 15) : 0) -
  95. pos.Distance(from, skillshot.End, true);
  96. if (w > 0)
  97. {
  98. collisions.Add(
  99. new DetectedCollision
  100. {
  101. Position =
  102. pos.ProjectOn(skillshot.End, skillshot.Start).LinePoint +
  103. skillshot.Direction * 30,
  104. Unit = minion,
  105. Type = CollisionObjectTypes.Minion,
  106. Distance = pos.Distance(from),
  107. Diff = w,
  108. });
  109. }
  110. }
  111. break;
  112. case CollisionObjectTypes.Champions:
  113. if (!Config.Menu.Item("HeroCollision").GetValue<bool>())
  114. {
  115. break;
  116. }
  117. foreach (var hero in
  118. ObjectManager.Get<Obj_AI_Hero>()
  119. .Where(
  120. h =>
  121. (h.IsValidTarget(1200, false) && h.Team == ObjectManager.Player.Team && !h.IsMe ||
  122. Config.TestOnAllies && h.Team != ObjectManager.Player.Team)))
  123. {
  124. var pred = FastPrediction(
  125. from, hero,
  126. Math.Max(0, skillshot.SpellData.Delay - (Utils.TickCount - skillshot.StartTick)),
  127. skillshot.SpellData.MissileSpeed);
  128. var pos = pred.PredictedPos;
  129. var w = skillshot.SpellData.RawRadius + 30 - pos.Distance(from, skillshot.End, true);
  130. if (w > 0)
  131. {
  132. collisions.Add(
  133. new DetectedCollision
  134. {
  135. Position =
  136. pos.ProjectOn(skillshot.End, skillshot.Start).LinePoint +
  137. skillshot.Direction * 30,
  138. Unit = hero,
  139. Type = CollisionObjectTypes.Minion,
  140. Distance = pos.Distance(from),
  141. Diff = w,
  142. });
  143. }
  144. }
  145. break;
  146. case CollisionObjectTypes.YasuoWall:
  147. if (!Config.Menu.Item("YasuoCollision").GetValue<bool>())
  148. {
  149. break;
  150. }
  151. if (
  152. !ObjectManager.Get<Obj_AI_Hero>()
  153. .Any(
  154. hero =>
  155. hero.IsValidTarget(float.MaxValue, false) &&
  156. hero.Team == ObjectManager.Player.Team && hero.ChampionName == "Yasuo"))
  157. {
  158. break;
  159. }
  160. GameObject wall = null;
  161. foreach (var gameObject in ObjectManager.Get<GameObject>())
  162. {
  163. if (gameObject.IsValid &&
  164. System.Text.RegularExpressions.Regex.IsMatch(
  165. gameObject.Name, "_w_windwall.\\.troy",
  166. System.Text.RegularExpressions.RegexOptions.IgnoreCase))
  167. {
  168. wall = gameObject;
  169. }
  170. }
  171. if (wall == null)
  172. {
  173. break;
  174. }
  175. var level = wall.Name.Substring(wall.Name.Length - 6, 1);
  176. var wallWidth = (300 + 50 * Convert.ToInt32(level));
  177. var wallDirection = (wall.Position.To2D() - YasuoWallCastedPos).Normalized().Perpendicular();
  178. var wallStart = wall.Position.To2D() + wallWidth / 2 * wallDirection;
  179. var wallEnd = wallStart - wallWidth * wallDirection;
  180. var wallPolygon = new Geometry.Rectangle(wallStart, wallEnd, 75).ToPolygon();
  181. var intersection = new Vector2();
  182. var intersections = new List<Vector2>();
  183. for (var i = 0; i < wallPolygon.Points.Count; i++)
  184. {
  185. var inter =
  186. wallPolygon.Points[i].Intersection(
  187. wallPolygon.Points[i != wallPolygon.Points.Count - 1 ? i + 1 : 0], from,
  188. skillshot.End);
  189. if (inter.Intersects)
  190. {
  191. intersections.Add(inter.Point);
  192. }
  193. }
  194. if (intersections.Count > 0)
  195. {
  196. intersection = intersections.OrderBy(item => item.Distance(from)).ToList()[0];
  197. var collisionT = Utils.TickCount +
  198. Math.Max(
  199. 0,
  200. skillshot.SpellData.Delay -
  201. (Utils.TickCount - skillshot.StartTick)) + 100 +
  202. (1000 * intersection.Distance(from)) / skillshot.SpellData.MissileSpeed;
  203. if (collisionT - WallCastT < 4000)
  204. {
  205. if (skillshot.SpellData.Type != SkillShotType.SkillshotMissileLine)
  206. {
  207. skillshot.ForceDisabled = true;
  208. }
  209. return intersection;
  210. }
  211. }
  212. break;
  213. }
  214. }
  215. Vector2 result;
  216. if (collisions.Count > 0)
  217. {
  218. result = collisions.OrderBy(c => c.Distance).ToList()[0].Position;
  219. }
  220. else
  221. {
  222. result = new Vector2();
  223. }
  224. return result;
  225. }
  226. }
  227. }

comments powered by Disqus