public static Vector2 GetSpellProjection(this Spell spell, Vector2 pos, bool predictPos = false) { switch (spell.SpellType) { case SpellType.Line: if (predictPos) { var spellPos = spell.CurrentSpellPosition; var spellEndPos = spell.GetSpellEndPosition(); return(pos.ProjectOn(spellPos, spellEndPos).SegmentPoint); } return(pos.ProjectOn(spell.StartPos, spell.EndPos).SegmentPoint); case SpellType.Arc: if (predictPos) { var spellPos = spell.CurrentSpellPosition; var spellEndPos = spell.GetSpellEndPosition(); return(pos.ProjectOn(spellPos, spellEndPos).SegmentPoint); } return(pos.ProjectOn(spell.StartPos, spell.EndPos).SegmentPoint); case SpellType.Circular: return(spell.EndPos); case SpellType.Cone: break; } return(Vector2.Zero); }
public static bool LineIntersectLinearSpellEx(this Spell spell, Vector2 a, Vector2 b, out Vector2 intersection) //edited { var myBoundingRadius = ObjectManager.GetLocalPlayer().BoundingRadius; var spellDir = spell.Direction; var pSpellDir = spell.Direction.Perpendicular(); var spellRadius = spell.Radius; var spellPos = spell.CurrentSpellPosition - spellDir * myBoundingRadius; var endPos = spell.GetSpellEndPosition() + spellDir * myBoundingRadius; //leave some space at the front of spell var startRightPos = spellPos + pSpellDir * (spellRadius + myBoundingRadius); var startLeftPos = spellPos - pSpellDir * (spellRadius + myBoundingRadius); var endRightPos = endPos + pSpellDir * (spellRadius + myBoundingRadius); var endLeftPos = endPos - pSpellDir * (spellRadius + myBoundingRadius); var intersects = new List <Vector2Extensions.IntersectionResult>(); var heroPos = ObjectManager.GetLocalPlayer().ServerPosition.To2D(); intersects.Add(a.Intersection(b, startRightPos, startLeftPos)); intersects.Add(a.Intersection(b, endRightPos, endLeftPos)); intersects.Add(a.Intersection(b, startRightPos, endRightPos)); intersects.Add(a.Intersection(b, startLeftPos, endLeftPos)); var sortedIntersects = intersects.Where(i => i.Intersects).OrderBy(i => i.Point.Distance(heroPos)); //Get first intersection if (sortedIntersects.Any()) { intersection = sortedIntersects.First().Point; return(true); } intersection = Vector2.Zero; return(false); }
public static bool LineIntersectLinearSpell(this Spell spell, Vector2 a, Vector2 b) { var myBoundingRadius = ObjectManager.GetLocalPlayer().BoundingRadius; var spellDir = spell.Direction; var pSpellDir = spell.Direction.Perpendicular(); var spellRadius = spell.Radius; var spellPos = spell.CurrentSpellPosition; var endPos = spell.GetSpellEndPosition(); var startRightPos = spellPos + pSpellDir * (spellRadius + myBoundingRadius); var startLeftPos = spellPos - pSpellDir * (spellRadius + myBoundingRadius); var endRightPos = endPos + pSpellDir * (spellRadius + myBoundingRadius); var endLeftPos = endPos - pSpellDir * (spellRadius + myBoundingRadius); var int1 = MathUtils.CheckLineIntersection(a, b, startRightPos, startLeftPos); var int2 = MathUtils.CheckLineIntersection(a, b, endRightPos, endLeftPos); var int3 = MathUtils.CheckLineIntersection(a, b, startRightPos, endRightPos); var int4 = MathUtils.CheckLineIntersection(a, b, startLeftPos, endLeftPos); if (int1 || int2 || int3 || int4) { return(true); } return(false); }
public static bool CanHeroWalkIntoSpell(Spell spell) { if (!ObjectCache.MenuCache.Cache["AdvancedSpellDetection"].Enabled) { return true; } var heroPos = MyHero.Position.To2D(); var extraDist = MyHero.Distance(ObjectCache.MyHeroCache.ServerPos2D); switch (spell.SpellType) { case SpellType.Line: { var walkRadius = ObjectCache.MyHeroCache.MoveSpeed * (spell.EndTime - Environment.TickCount) / 1000 + ObjectCache.MyHeroCache.BoundingRadius + spell.Info.Radius + extraDist + 10; var spellPos = spell.CurrentSpellPosition; var spellEndPos = spell.GetSpellEndPosition(); var projection = heroPos.ProjectOn(spellPos, spellEndPos); return projection.SegmentPoint.Distance(heroPos) <= walkRadius; } case SpellType.Circular: { var walkRadius = ObjectCache.MyHeroCache.MoveSpeed * (spell.EndTime - Environment.TickCount) / 1000 + ObjectCache.MyHeroCache.BoundingRadius + spell.Info.Radius + extraDist + 10; if (heroPos.Distance(spell.EndPos) < walkRadius) { return true; } break; } case SpellType.Arc: { var spellRange = spell.StartPos.Distance(spell.EndPos); var midPoint = spell.StartPos + spell.Direction * (spellRange / 2); var arcRadius = spell.Info.Radius * (1 + spellRange / 100); var walkRadius = ObjectCache.MyHeroCache.MoveSpeed * (spell.EndTime - Environment.TickCount) / 1000 + ObjectCache.MyHeroCache.BoundingRadius + arcRadius + extraDist + 10; if (heroPos.Distance(midPoint) < walkRadius) { return true; } break; } } return false; }
public static BoundingBox GetLinearSpellBoundingBox(this Spell spell) { var myBoundingRadius = ObjectCache.MyHeroCache.BoundingRadius; var spellDir = spell.Direction; var pSpellDir = spell.Direction.Perpendicular(); var spellRadius = spell.Radius; var spellPos = spell.CurrentSpellPosition - spellDir * myBoundingRadius; var endPos = spell.GetSpellEndPosition() + spellDir * myBoundingRadius; var startRightPos = spellPos + pSpellDir * (spellRadius + myBoundingRadius); var endLeftPos = endPos - pSpellDir * (spellRadius + myBoundingRadius); return(new BoundingBox(new Vector3(endLeftPos.X, endLeftPos.Y, -1), new Vector3(startRightPos.X, startRightPos.Y, 1))); }