private static bool IsCondemnable(Vector2 from, Obj_AI_Base unit, int range) { if(from.ToVector3().GetTumbleEndPos().Distance(unit) < 300 || !from.IsInRange(unit, 425)) return false; var position = Prediction.Position.GetPrediction(unit, new Prediction.Position.PredictionData(Prediction.Position.PredictionData.PredictionType.Linear, Settings.PushDistance, 80, 0, 550, 1800)).UnitPosition.To2D(); for (var i = range; i >= 100; i -= 100) { var vec = position.Extend(from, -i); const int var = 18 * 4 / 100; var left = position.Extend( vec + (position - vec).Normalized().Rotated((float) Helpers.ToRadian(Math.Max(0, var)))* Math.Abs(i < 200 ? 50 : 60*4), i); var right = position.Extend( vec + (position - vec).Normalized().Rotated((float) Helpers.ToRadian(-Math.Max(0, var)))* Math.Abs(i < 200 ? 50 : 60*4), i); if (left.IsWall() && right.IsWall() && vec.IsWall()) { return true; } } return false; }
/// <summary> /// Initializes a new instance of the <see cref="FixedCamera2D" /> class. /// </summary> /// <param name="name">The name.</param> /// <param name="position">The camera position</param> public FixedCamera2D(string name, Vector2 position) { this.InitEntity(name); Vector3 position3D = position.ToVector3(-10); this.entity.FindComponent<Transform3D>(false).Position = position3D; }
public static bool Condemn360(Obj_AI_Hero unit, int push, Vector2 pos = new Vector2()) { if (unit.HasBuffOfType(BuffType.SpellImmunity) || unit.HasBuffOfType(BuffType.SpellShield) || _lastCheck + 50 > Environment.TickCount || ObjectManager.Player.IsDashing()) { return false; } var prediction = E.GetPrediction(unit); var predictionsList = pos.IsValid() ? new List<Vector3>() { pos.ToVector3() } : new List<Vector3> { unit.ServerPosition, unit.Position, prediction.CastPosition, prediction.UnitPosition }; var wallsFound = 0; _points = new List<Vector2>(); foreach (var position in predictionsList) { for (var i = 0; i < push; i += (int)unit.BoundingRadius) // 420 = push distance { var cPos = ObjectManager.Player.Position.Extend(position, ObjectManager.Player.Distance(position) + i).ToVector2(); _points.Add(cPos); if (NavMesh.GetCollisionFlags(cPos.ToVector3()).HasFlag(CollisionFlags.Wall) || NavMesh.GetCollisionFlags(cPos.ToVector3()).HasFlag(CollisionFlags.Building)) { wallsFound++; break; } } } // ReSharper disable once PossibleLossOfFraction if ((wallsFound / predictionsList.Count) >= 33 / 100f) { return true; } return false; }
/// <summary> /// Initializes a new instance of the <see cref="FixedCamera2D" /> class. /// </summary> /// <param name="name">The name.</param> /// <param name="position">The camera position</param> public FixedCamera2D(string name, Vector2 position) { this.entity = new Entity(name) .AddComponent(new Camera2D() { Position = position.ToVector3(0), }); }
/// <summary> /// Returns Collision List /// </summary> /// <param name="fromVector2"> /// From Vector3 Source /// </param> /// <param name="to"> /// To Vector3 Source /// </param> /// <param name="delayOverride"> /// Delay Override /// </param> /// <returns> /// Collision List /// </returns> public List<Obj_AI_Base> GetCollision(Vector2 fromVector2, List<Vector2> to, float delayOverride = -1) { return SDK.Collision.GetCollision( to.Select(h => h.ToVector3()).ToList(), new PredictionInput { From = fromVector2.ToVector3(), Type = this.Type, Radius = this.Width, Delay = delayOverride > 0 ? delayOverride : this.Delay, Speed = this.Speed }); }
/// <summary> /// Returns if the angle is orthogonal. /// </summary> /// <param name="vector2">Extended SharpDX Vector2</param> /// <param name="toVector2">SharpDX Vector2</param> /// <returns>The <see cref="bool" />.</returns> public static bool IsOrthogonal(this Vector2 vector2, Vector2 toVector2) { return IsOrthogonal(vector2, toVector2.ToVector3()); }
/// <summary> /// Returns if the position is in the range of the Item. /// </summary> /// <param name="position"> /// Position to be checked. /// </param> /// <returns> /// The <see cref="bool" /> /// </returns> public bool IsInRange(Vector2 position) { return this.IsInRange(position.ToVector3()); }
private static void DaggerUltForceStaffCombo(Hero me, Ability r, bool hasForceStaffForUse, Vector2 bestPointToPort) { var bestEnemy = ObjectMgr.GetEntities<Hero>().Where (x => x.Team != me.Team && x.IsValid && x.Distance2D(bestPointToPort.ToVector3()) <= r.CastRange).OrderBy(x => x.Health).FirstOrDefault(); #region blink dagger -> ultimate -> force staff if (bestEnemy != null) { MyItems.BlinkDagger.TheItem.UseAbility(bestPointToPort.ToVector3()); Vector3 lastPosBeforeCastingUltimate = bestPointToPort.ToVector3(); DelayHandler.Add(delegate { r.UseAbility(bestEnemy); }, stdCastDelay, DelayHandler.Descriptions.Ultimate); DelayHandler.UltimateInAutomaticUse = true; DelayHandler.Add(delegate { //me.Move(lastPosBeforeCastingUltimate); DelayHandler.MoveSpammer.Involke(lastPosBeforeCastingUltimate, stdCastDelay * 2); }, stdCastDelay + 250, DelayHandler.Descriptions.Move); /*ultimate -> force staff or blink dagger*/ if (hasForceStaffForUse) { DelayHandler.Add(delegate { MyItems.ForceStaff.TheItem.UseAbility(me); }, stdCastDelay + 250 + stdCastDelay * 2, DelayHandler.Descriptions.ForceStaffCast); } #endregion blink dagger -> ultimate -> force staff } else { CheckUltimateOffensiveWith_TP_Zepter(2, me, r); } }
private static ParticleEffect DrawLine(Vector2 position, float size, int horizontal = 0, int vertical = 0) { var position3 = position.ToVector3(); var effect = new ParticleEffect(@"particles\ui_mouseactions\drag_selected_ring.vpcf", position3); effect.SetControlPoint(1, new Vector3( Program.GetMenuValue("red"), Program.GetMenuValue("green"), Program.GetMenuValue("blue"))); effect.SetControlPoint(2, new Vector3(size, 255, 0)); effect.SetControlPointOrientation(4, new Vector3(horizontal, 0, 0), new Vector3(vertical, 0, 0), new Vector3(0, 0, 0)); return effect; }
/// <summary> /// Get Tile coordinates (x, y) by world position /// </summary> /// <param name="position">The world position</param> /// <param name="tileX">Out tile X coordinate</param> /// <param name="tileY">Out tile Y coordinate</param> public void GetTileCoordinatesByWorldPosition(Vector2 position, out int tileX, out int tileY) { int sideLengthX = 0; int sideLengthY = 0; bool staggerX = this.StaggerAxis == TiledMapStaggerAxisType.X; bool staggerEven = this.StaggerIndex == TiledMapStaggerIndexType.Even; if (this.Orientation == TiledMapOrientationType.Hexagonal) { if (this.StaggerAxis == TiledMapStaggerAxisType.X) { sideLengthX = this.HexSideLength; } else { sideLengthY = this.HexSideLength; } } position = Vector3.Transform(position.ToVector3(this.transform.DrawOrder), this.transform.WorldInverseTransform).ToVector2(); Vector2 referencePosition = new Vector2( position.X / (this.TileWidth + sideLengthX), position.Y / (this.TileHeight + sideLengthY)); if (referencePosition.X < 0) { referencePosition.X -= 1; } if (referencePosition.Y < 0) { referencePosition.Y -= 1; } switch (this.Orientation) { case TiledMapOrientationType.Orthogonal: tileX = (int)referencePosition.X; tileY = (int)referencePosition.Y; break; case TiledMapOrientationType.Isometric: float halfHeight = this.Height * 0.5f; tileX = (int)(-halfHeight + (referencePosition.X + referencePosition.Y)); float y = halfHeight + (-referencePosition.X + referencePosition.Y); y = (y >= 0) ? y : y - 1; tileY = (int)y; break; case TiledMapOrientationType.Staggered: if (staggerEven) { if (staggerX) { referencePosition.Y -= 0.5f; } else { referencePosition.X -= 0.5f; } } int coordX = (int)(-0.5f + (referencePosition.X + referencePosition.Y)); y = 0.5f + (-referencePosition.X + referencePosition.Y); y = (y >= 0) ? y : y - 1; int coordY = (int)y; int evenOffset = staggerEven ? 1 : 0; if (staggerX) { tileX = coordX - coordY; tileY = (coordX + coordY + evenOffset) / 2; } else { tileX = (coordX - coordY + evenOffset) / 2; tileY = coordX + coordY; } break; case TiledMapOrientationType.Hexagonal: Vector2 tileCoordinates = Vector2.Zero; var sideOffsetX = (this.TileWidth - sideLengthX) / 2; var sideOffsetY = (this.TileHeight - sideLengthY) / 2; if (staggerX) { position.X -= staggerEven ? this.TileWidth : sideOffsetX; } else { position.Y -= staggerEven ? this.TileHeight : sideOffsetY; } referencePosition = new Vector2( (float)Math.Floor(position.X / (this.TileWidth + sideLengthX)), (float)Math.Floor(position.Y / (this.TileHeight + sideLengthY))); // Relative x and y position on the base square of the grid-aligned tile Vector2 rel = new Vector2( position.X - referencePosition.X * (this.TileWidth + sideLengthX), position.Y - referencePosition.Y * (this.TileHeight + sideLengthY)); // Adjust the reference point to the correct tile coordinates // Determine the nearest hexagon tile by the distance to the center Vector2[] centers = new Vector2[4]; var columnWidth = sideOffsetX + sideLengthX; var rowHeight = sideOffsetY + sideLengthY; if (staggerX) { int left = sideLengthX / 2; int centerX = left + columnWidth; int centerY = this.TileHeight / 2; centers[0] = new Vector2(left, centerY); centers[1] = new Vector2(centerX, centerY - rowHeight); centers[2] = new Vector2(centerX, centerY + rowHeight); centers[3] = new Vector2(centerX + columnWidth, centerY); referencePosition.X *= 2; if (staggerEven) { referencePosition.X += 1; } } else { int top = sideLengthY / 2; int centerX = this.TileWidth / 2; int centerY = top + rowHeight; centers[0] = new Vector2(centerX, top); centers[1] = new Vector2(centerX - columnWidth, centerY); centers[2] = new Vector2(centerX + columnWidth, centerY); centers[3] = new Vector2(centerX, centerY + rowHeight); referencePosition.Y *= 2; if (staggerEven) { referencePosition.Y += 1; } } int nearest = 0; float minDist = float.MaxValue; for (int i = 0; i < 4; ++i) { Vector2 center = centers[i]; float dc = (center - rel).LengthSquared(); if (dc < minDist) { minDist = dc; nearest = i; } } var offsetsStaggerX = new Vector2[]{ new Vector2( 0, 0), new Vector2(+1, -1), new Vector2(+1, 0), new Vector2(+2, 0), }; var offsetsStaggerY = new Vector2[]{ new Vector2( 0, 0), new Vector2(-1, +1), new Vector2( 0, +1), new Vector2( 0, +2), }; var offsets = staggerX ? offsetsStaggerX : offsetsStaggerY; tileCoordinates = referencePosition + offsets[nearest]; tileX = (int)tileCoordinates.X; tileY = (int)tileCoordinates.Y; break; default: tileX = 0; tileY = 0; break; } }
private static void ComboInAction(Hero me, Hero target) { if (!Utils.SleepCheck("nextAction")) return; var dist = me.Distance2D(target); switch (_stage) { case 0: if (target.Modifiers.Any(x => x.Name == "modifier_earth_spirit_magnetize") && !CanCastCombo()) { _stage = 5; } if (Menu.Item("dagger").GetValue<StringList>().SelectedIndex == (int)DaggerStage.OnStartCombo) { var blink = me.FindItem("item_blink"); if (dist >= Pull.CastRange && blink != null && blink.CanBeCasted()) { if (dist >= Pull.CastRange + 1100) { me.Move(target.Position); Utils.Sleep(200, "nextAction"); break; } var ang = me.FindAngleBetween(target.Position, true); var p = new Vector2((float)(me.Position.X + 1100 * Math.Cos(ang)), (float)(me.Position.Y + 1100 * Math.Sin(ang))); blink.UseAbility(p.ToVector3(true)); Utils.Sleep(100, "nextAction"); break; } } if (AnyStoneNear(me) && dist <= 1900) { if (Menu.Item("debug").GetValue<bool>()) PrintInfo("stone near you finded"); _stage++; break; } if (Remnant.CanBeCasted()) { if (dist <= 1900) { if (me.NetworkActivity == NetworkActivity.Move) me.Stop(); Remnant.UseAbility(Prediction.InFront(me, 100)); Utils.Sleep(50 + Remnant.FindCastPoint(), "nextAction"); _stage++; if (Menu.Item("debug").GetValue<bool>()) PrintInfo("remnant create"); } else { me.Move(target.Position); Utils.Sleep(50 + Remnant.FindCastPoint(), "nextAction"); } } break; case 1: if (Push.CanBeCasted()) { var last = GetLastRemnant(me); if (last != null) { if (Menu.Item("debug").GetValue<bool>()) PrintInfo("push casted"); Push.UseAbility(target.Position); Utils.Sleep(100 + Push.FindCastPoint(), "nextAction"); } } else _stage++; break; case 2: if (Pull.CanBeCasted()) { var last = GetLastRemnant(me); if (last != null) { if (target.Distance2D(last) <= 400) { if (me.Distance2D(target) <= Pull.CastRange) { /*var pos = new Vector3( (float) (last.Position.X + (1200*Game.Ping/1000+30)* Math.Cos(me.FindAngleBetween(last.Position))), (float) (last.Position.Y + (1200*Game.Ping/1000+30)* Math.Sin(me.FindAngleBetween(last.Position))), 0); */ Pull.UseAbility(Prediction.InFront(me, (float) (me.Distance2D(last) + (1200 * 0.1 + Game.Ping / 1000)))); if (Menu.Item("debug").GetValue<bool>()) { Game.PrintMessage((1200*0.1 + Game.Ping / 1000).ToString(), MessageType.ChatMessage); //globalPos = pos; PrintInfo("last pos: " + last.Position.X); PrintInfo("pull casted. Distance: " + target.Distance2D(last)); } //Utils.Sleep(Game.Ping + Pull.FindCastPoint(), "nextAction"); } else /*if (_shouldUseDagger)*/ { var blink = me.FindItem("item_blink"); if (dist >= Pull.CastRange && blink != null && blink.CanBeCasted()) { if (dist >= Pull.CastRange + 1100) { me.Move(target.Position); Utils.Sleep(200, "nextAction"); break; } if (Menu.Item("dagger").GetValue<StringList>().SelectedIndex == (int) DaggerStage.AfterSmash) { var ang = me.FindAngleBetween(target.Position, true); var p = new Vector2((float) (me.Position.X + 1100*Math.Cos(ang)), (float) (me.Position.Y + 1100*Math.Sin(ang))); blink.UseAbility(p.ToVector3(true)); Utils.Sleep(100, "nextAction"); if (Menu.Item("debug").GetValue<bool>()) PrintInfo("dagger is used"); } } } } } else { if (Remnant.CanBeCasted()) { if (me.NetworkActivity == NetworkActivity.Move) me.Stop(); Remnant.UseAbility(target.Position); if (Menu.Item("debug").GetValue<bool>()) PrintInfo("remnant create"); } } } else _stage++; break; case 3: if (Roll.CanBeCasted() && !Pull.CanBeCasted()) { Roll.UseAbility(target.Position); Utils.Sleep(100 + Roll.FindCastPoint(), "nextAction"); if (Menu.Item("debug").GetValue<bool>()) PrintInfo("roll casted"); } else _stage++; break; case 4: if (Magnetize.CanBeCasted()) { if (me.Distance2D(target) < 300) { Magnetize.UseAbility(); Utils.Sleep(100 + Magnetize.FindCastPoint(), "nextAction"); _stage++; if (Menu.Item("debug").GetValue<bool>()) PrintInfo("Magnetize casted"); } } break; case 5: if (Remnant.CanBeCasted() && Menu.Item("supult").GetValue<bool>()) { var mod = target.Modifiers.FirstOrDefault(x => x.Name == "modifier_earth_spirit_magnetize"); if (mod != null && mod.RemainingTime <= 0.5+Game.Ping && me.Distance2D(target)<=Remnant.CastRange) { Remnant.UseAbility(target.Position); Utils.Sleep(1000, "nextAction"); me.Attack(target,true); break; } if (Utils.SleepCheck("attackcd")) { me.Attack(target); Utils.Sleep(150, "attackcd"); } } else if (Utils.SleepCheck("attackcd")) { me.Attack(target); Utils.Sleep(200, "attackcd"); } if (Menu.Item("killsteal").GetValue<bool>() && Push.CanBeCasted() && target.DamageTaken(50 * Push.Level, DamageType.Magical, me) > target.Health) { Push.UseAbility(target); Utils.Sleep(500, "nextAction"); me.Attack(target, true); break; } if (Menu.Item("rolling").GetValue<bool>() && Roll.CanBeCasted()) { Roll.UseAbility(target.Position); Utils.Sleep(500, "nextAction"); } break; } if (Menu.Item("items").GetValue<bool>()) { LetsUseItems(me, target); } }
private static void LetAghanimCombo(Hero me,Hero target) { if (!Utils.SleepCheck("nextAction")) return; var ability = me.FindSpell("earth_spirit_petrify"); if (ability==null) return; if (ability.Level==0) return; var inStone = target.Modifiers.Any(x=>x.Name=="modifier_earthspirit_petrify"); var dist = me.Distance2D(target); if (ability.CanBeCasted() && !inStone) { if (Menu.Item("dagger").GetValue<StringList>().SelectedIndex == (int)DaggerStage.OnStartCombo || Menu.Item("dagger").GetValue<StringList>().SelectedIndex == (int)DaggerStage.AfterSmash) { var blink = me.FindItem("item_blink"); if (dist >= ability.CastRange && blink!=null && blink.CanBeCasted()) { var ang = me.FindAngleBetween(target.Position, true); var p = new Vector2((float)(target.Position.X - 100 * Math.Cos(ang)), (float)(target.Position.Y - 100 * Math.Sin(ang))); blink.UseAbility(p.ToVector3(true)); } } ability.UseAbility(target); Utils.Sleep(150 + ability.FindCastPoint(), "nextAction"); return; } if (Pull != null && Pull.CanBeCasted() && inStone) { Pull.UseAbility(target.Position); //PrintInfo(Roll.CastSkillShot(target).ToString()); Utils.Sleep(300 + Pull.FindCastPoint(), "nextAction"); return; } if (Push != null && Push.CanBeCasted() && inStone && dist<=150) { Push.UseAbility(Game.MousePosition); if (Roll != null && Roll.CanBeCasted()) { if (Remnant != null && Remnant.CanBeCasted()) { var ang = me.FindAngleBetween(Game.MousePosition, true); var p = new Vector2((float) (me.Position.X + 100 * Math.Cos(ang)), (float) (me.Position.Y + 100 * Math.Sin(ang))); Remnant.UseAbility(p.ToVector3(true)); } Roll.UseAbility(Game.MousePosition,true); } Utils.Sleep(300 + Push.FindCastPoint(), "nextAction"); } }
private static void LetsPush() { var me = ObjectMgr.LocalHero; if (!Push.CanBeCasted() || !Utils.SleepCheck("preComboW8")) return; if (AnyStoneNear(me,new Vector3(),200F)) { } else if (Remnant.CanBeCasted()) { var ang = me.FindAngleBetween(Game.MousePosition, true); var p = new Vector2((float)(me.Position.X + 50 * Math.Cos(ang)), (float)(me.Position.Y + 50 * Math.Sin(ang))); Remnant.UseAbility(p.ToVector3(true)); } else { return; } var pos = Game.MousePosition; if (AnyStoneNear(me, pos)) { var ang = me.FindAngleBetween(pos, true); pos = new Vector2((float)(pos.X + 300 * Math.Cos(ang)), (float)(pos.Y + 300 * Math.Sin(ang))).ToVector3(true); } Push.UseAbility(pos); Utils.Sleep(500, "preComboW8"); }
private static void LetsRoll() { if (!Roll.CanBeCasted() || !Utils.SleepCheck("preComboW8")) return; var me = ObjectMgr.LocalHero; if (AnyStoneNear(me)) { } else if (Remnant.CanBeCasted()) { var ang = me.FindAngleBetween(Game.MousePosition, true); var p = new Vector2((float)(me.Position.X + 200 * Math.Cos(ang)), (float)(me.Position.Y + 100 * Math.Sin(ang))); Remnant.UseAbility(p.ToVector3(true)); } else { return; } Roll.UseAbility(Game.MousePosition); Utils.Sleep(500, "preComboW8"); }
/// <summary> /// Calculates the squared distance between two vectors. /// </summary> /// <param name="vector3">Extended SharpDX Vector3</param> /// <param name="toVector2">SharpDX Vector2</param> /// <returns>The squared distance between the two vectors.</returns> public static float DistanceSquared(this Vector3 vector3, Vector2 toVector2) { return Vector3.DistanceSquared(vector3, toVector2.ToVector3()); }
private static void AssasinMode() { var target = TargetSelector.GetSelectedTarget(); if (Orb.CanMove) Player.IssueOrder(GameObjectOrder.MoveTo, Game.CursorPos); if (target.IsValidTarget() && !target.IsZombie) { var targetpos = Movement.GetPrediction(target, 0.25f).UnitPosition.ToVector2(); var distance = targetpos.Distance(Player.Position.ToVector2()); if (Ignite.IsReady() && target.IsValidTarget(450)) { Player.Spellbook.CastSpell(Ignite, target); } if (!R.IsReady(3000) || Player.IsDashing()) { if (W.IsReady() && Player.Distance(target.Position) <= W.Range) { W.Cast(); } } if (R.IsReady() && AhriOrbReturn == null && AhriOrb == null && Variables.TickCount - Rcount >= 500) { Vector2 intersec = new Vector2(); for (int i = 450; i >= 0; i = i - 50) { for (int j = 50; j <= 600; j = j + 50) { var vectors = BadaoAIO.Orbwalker.Geometry.CircleCircleIntersection(Player.Position.ToVector2(), targetpos, i, j); foreach (var x in vectors) { if (!Collide(x, target) && !x.IsWall()) { intersec = x; goto ABC; } } } } ABC: if (intersec.IsValid()) R.Cast(intersec.ToVector3()); } else if (R.IsReady() && AhriOrbReturn != null && Player.Distance(targetpos) < Player.Distance(AhriOrbReturn.Position.ToVector2()) && Variables.TickCount - Rcount >= 0) { var OrbPosition = AhriOrbReturn.Position.ToVector2(); var dis = OrbPosition.Distance(targetpos); Vector2 castpos = new Vector2(); for (int i = 450; i >= 200; i = i - 50) { if (OrbPosition.Extend(targetpos, dis + i).Distance(Player.Position.ToVector2()) <= R.Range && !OrbPosition.Extend(targetpos, dis + i).IsWall()) { castpos = OrbPosition.Extend(targetpos, dis + i); break; } } if (castpos.IsValid()) R.Cast(castpos.ToVector3()); } if (Orb.CanAttack && target.InAutoAttackRange()) { Player.IssueOrder(GameObjectOrder.AttackUnit, target); //Orbwalking.LastAACommandTick = Utils.GameTimeTickCount - 4; Orb.Movement = false; DelayAction.Add(Player.AttackCastDelay*900,() => Orb.Movement = true); } } }
/// <summary> /// Returns if the angle is orthogonal. /// </summary> /// <param name="vector3">Extended SharpDX Vector3</param> /// <param name="toVector2">SharpDX Vector2</param> /// <returns>Returns if the angle is orthogonal</returns> public static bool IsOrthogonal(Vector3 vector3, Vector2 toVector2) { return IsOrthogonal(vector3, toVector2.ToVector3()); }
private static bool Collide(Vector2 pos, Obj_AI_Hero target) { E2.UpdateSourcePosition(pos.ToVector3(), pos.ToVector3()); return E2.GetBadaoPrediction(target).CollisionObjects.Any(); }
/// <summary> /// Casts the item on a Vector2 position. /// </summary> /// <param name="id"> /// Id of the Item. /// </param> /// <param name="position"> /// Position of the Item cast. /// </param> /// <returns> /// The <see cref="bool" />. /// </returns> public static bool UseItem(int id, Vector2 position) { return UseItem(id, position.ToVector3()); }
/// <summary> /// Get Tile coordinates (x, y) by world position /// </summary> /// <param name="position">The world position</param> /// <param name="tileX">Out tile X coordinate</param> /// <param name="tileY">Out tile Y coordinate</param> public void GetTileCoordinatesByPosition(Vector2 position, out int tileX, out int tileY) { position = Vector3.Transform(position.ToVector3(this.transform.DrawOrder), this.transform.WorldInverseTransform).ToVector2(); position.X /= this.TileWidth; position.Y /= this.TileHeight; switch (this.Orientation) { case TiledMapOrientationType.Orthogonal: tileX = (int)position.X; tileY = (int)position.Y; break; case TiledMapOrientationType.Isometric: float halfHeight = this.Height * 0.5f; tileX = (int)(-halfHeight + (position.X + position.Y)); float y = halfHeight + (-position.X + position.Y); y = (y >= 0) ? y : y - 1; tileY = (int)y; break; case TiledMapOrientationType.Staggered: int coordX = (int)(-0.5f + (position.X + position.Y)); y = 0.5f + (-position.X + position.Y); y = (y >= 0) ? y : y - 1; int coordY = (int)y; tileX = (coordX - coordY) / 2; tileY = coordX + coordY; break; default: tileX = 0; tileY = 0; break; } }
/// <summary> /// Extends a Vector3 to a Vector2. /// </summary> /// <param name="vector3">Extended SharpDX Vector3 (From)</param> /// <param name="toVector2">SharpDX Vector2 (To)</param> /// <param name="distance">Distance (float units)</param> /// <returns>Extended Vector3</returns> public static Vector3 Extend(this Vector3 vector3, Vector2 toVector2, float distance) { return vector3 + (distance * (toVector2.ToVector3(vector3.Z) - vector3).Normalized()); }
/// <summary> /// Cast Spell from a Vector2 to another Vector2 boundaries /// </summary> /// <param name="fromPosition"> /// From Position /// </param> /// <param name="toPosition"> /// To Position /// </param> /// <returns> /// Was Spell Casted /// </returns> public bool Cast(Vector2 fromPosition, Vector2 toPosition) { return this.Cast(fromPosition.ToVector3(), toPosition.ToVector3()); }
/// <summary> /// Returns the angle between two vectors. /// </summary> /// <param name="vector2">Extended SharpDX Vector2</param> /// <param name="toVector2">SharpDX Vector2</param> /// <returns>Angle between two vectors in float-units</returns> public static float AngleBetween(this Vector2 vector2, Vector2 toVector2) { return AngleBetween(vector2, toVector2.ToVector3()); }
/// <summary> /// Cast Spell to a Vector2 /// </summary> /// <param name="position"> /// The Position /// </param> /// <returns> /// Was Spell Casted /// </returns> public bool Cast(Vector2 position) { return this.Cast(position.ToVector3()); }
internal static PredictionOutput GetConePrediction(PredictionInput input) { var mainTargetPrediction = input.GetPrediction(false, true); var posibleTargets = new List<PossibleTarget> { new PossibleTarget { Position = mainTargetPrediction.UnitPosition.ToVector2(), Unit = input.Unit } }; if (mainTargetPrediction.Hitchance >= HitChance.Medium) { posibleTargets.AddRange(GetPossibleTargets(input)); } if (posibleTargets.Count > 1) { var candidates = new List<Vector2>(); foreach (var target in posibleTargets) { target.Position = target.Position - input.From.ToVector2(); } for (var i = 0; i < posibleTargets.Count; i++) { for (var j = 0; j < posibleTargets.Count; j++) { if (i != j) { var p = (posibleTargets[i].Position + posibleTargets[j].Position) * 0.5f; if (!candidates.Contains(p)) { candidates.Add(p); } } } } var bestCandidateHits = -1; var bestCandidate = new Vector2(); var positionsList = posibleTargets.Select(i => i.Position).ToList(); foreach (var candidate in candidates) { var hits = GetHits(candidate, input.Range, input.Radius, positionsList); if (hits > bestCandidateHits) { bestCandidate = candidate; bestCandidateHits = hits; } } if (bestCandidateHits > 1 && input.From.ToVector2().DistanceSquared(bestCandidate) > 50 * 50) { return new PredictionOutput { Hitchance = mainTargetPrediction.Hitchance, AoeHitCount = bestCandidateHits, UnitPosition = mainTargetPrediction.UnitPosition, CastPosition = bestCandidate.ToVector3(), Input = input }; } } return mainTargetPrediction; }
/// <summary> /// Cuts vector near wall /// </summary> /// <param name="from">vector2 position</param> /// <returns></returns> public static Vector3 CutVectorNearWall(Vector2 from) { var distance = Player.Instance.Position.Distance(from); var x = from.Shorten(Player.Instance.Position.To2D(), distance); var output = new Vector2(); for (var i = 0; i < 1000; i++) { var vec = Player.Instance.Position.Extend(x, i); if (!vec.IsWall()) continue; output = vec; break; } return output.ToVector3(); }