本文整理汇总了C#中WoWPoint.Distance2DSqr方法的典型用法代码示例。如果您正苦于以下问题:C# WoWPoint.Distance2DSqr方法的具体用法?C# WoWPoint.Distance2DSqr怎么用?C# WoWPoint.Distance2DSqr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WoWPoint
的用法示例。
在下文中一共展示了WoWPoint.Distance2DSqr方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindLocationOriginal
/// <summary>
/// locates safe point away from enemies
/// </summary>
/// <param name="ptOrigin">start point for search</param>
/// <param name="minSafeDist">min distance to be safe</param>
/// <returns></returns>
public WoWPoint FindLocationOriginal(WoWPoint ptOrigin)
{
WoWPoint destinationLocation = new WoWPoint();
List<WoWPoint> mobLocations = new List<WoWPoint>();
int arcIncrement = 360 / RaysToCheck;
mobLocations = AllEnemyMobLocations;
double minSafeDistSqr = MinSafeDistance * MinSafeDistance;
double degreesFacing = (Me.RenderFacing * 180f) / Math.PI;
// Logger.WriteDebug( Color.Cyan, "Facing {0:F0}d {1:F2}r Searching for {2:F1} yard mob free area", degreesFacing, Me.RenderFacing, MinSafeDistance);
for (int arcIndex = 0; arcIndex < RaysToCheck ; arcIndex++)
{
float degreesFrom = 180;
if ((arcIndex & 1) == 0)
degreesFrom += (arcIndex >> 1) * arcIncrement;
else
degreesFrom -= (arcIndex >> 1) * arcIncrement;
for (float distFromOrigin = MinScanDistance; distFromOrigin <= MaxScanDistance ; distFromOrigin += IncrementScanDistance )
{
float heading = (float)(degreesFrom * Math.PI / 180f);
heading -= Me.RenderFacing;
destinationLocation = ptOrigin.RayCast((float)(degreesFrom * Math.PI / 180f), distFromOrigin);
double mobDistSqr = destinationLocation.Distance2DSqr(NearestMobLoc(destinationLocation, mobLocations));
if (mobDistSqr <= minSafeDistSqr)
continue;
//if (Navigator.CanNavigateFully(Me.Location, destinationLocation))
if (Navigator.GeneratePath(Me.Location, destinationLocation).Length <= 0)
{
// Logger.WriteDebug( Color.Cyan, "Mob-free location failed path check for degrees={0:F1} dist={1:F1}", degreesFrom, distFromOrigin);
continue;
}
if (!Styx.WoWInternals.World.GameWorld.IsInLineOfSight(Me.Location, destinationLocation))
{
// Logger.WriteDebug( Color.Cyan, "Mob-free location failed line of sight check for degrees={0:F1} dist={1:F1}", degreesFrom, distFromOrigin);
continue;
}
if (MobToRunFrom != null)
{
if (!Styx.WoWInternals.World.GameWorld.IsInLineOfSpellSight(destinationLocation, MobToRunFrom.Location))
{
// Logger.WriteDebug( Color.Cyan, "Mob-free location failed line of sight check for degrees={0:F1} dist={1:F1}", degreesFrom, distFromOrigin);
continue;
}
}
Logger.WriteDebug(Color.Cyan, "Found mob-free location ({0:F1} yd radius) at degrees={1:F1} dist={2:F1}", MinSafeDistance, degreesFrom, distFromOrigin);
return destinationLocation;
}
}
Logger.WriteDebug(Color.Cyan, "No mob-free location ({0:F1} yd radius) found within {1:F1} yds", MinSafeDistance, MaxScanDistance );
return WoWPoint.Empty;
}
示例2: FindLocation
//.........这里部分代码省略.........
spanNav = spanTrace;
}
else
{
start = DateTime.UtcNow;
failNav = !Navigator.CanNavigateFully(Me.Location, ptDestination);
spanNav += DateTime.UtcNow - start;
}
if (failTrace)
countFailTrace++;
if (failTrace != failNav)
countFailDiff++;
if (failNav)
{
// Logger.WriteDebug( Color.Cyan, "Safe Location failed navigation check for degrees={0:F1} dist={1:F1}", RadiansToDegrees(checkFacing), distFromOrigin);
countFailToPointNav++;
continue;
}
WoWPoint ptNearest = NearestMobLoc(ptDestination, mobLocations);
if (ptNearest == WoWPoint.Empty)
{
if (furthestNearMobDistSqr < minSafeDistSqr)
{
furthestNearMobDistSqr = minSafeDistSqr;
ptFurthest = ptDestination; // set best available if others fail
facingFurthest = checkFacing;
}
}
else
{
double mobDistSqr = ptDestination.Distance2DSqr(ptNearest);
if (furthestNearMobDistSqr < mobDistSqr)
{
furthestNearMobDistSqr = mobDistSqr;
ptFurthest = ptDestination; // set best available if others fail
facingFurthest = checkFacing;
}
if (mobDistSqr <= minSafeDistSqr)
{
countFailSafe++;
continue;
}
}
if (reallyCheckRangeToLineOfSightMob && RangeToLineOfSightMob < ptDestination.Distance(LineOfSightMob.Location) - LineOfSightMob.MeleeDistance())
{
countFailRange++;
continue;
}
if (CheckLineOfSightToSafeLocation)
{
WoWPoint ptAdjDest = ptDestination;
ptAdjDest.Z += 1f;
if (!Styx.WoWInternals.World.GameWorld.IsInLineOfSight(ptAdjOrigin, ptAdjDest))
{
// Logger.WriteDebug( Color.Cyan, "Mob-free location failed line of sight check for degrees={0:F1} dist={1:F1}", degreesFrom, distFromOrigin);
countFailToPointLoS++;
continue;
}
}
if (CheckSpellLineOfSightToMob && LineOfSightMob != null)
{
if (!Styx.WoWInternals.World.GameWorld.IsInLineOfSpellSight(ptDestination, LineOfSightMob.GetTraceLinePos()))
{
if (!Styx.WoWInternals.World.GameWorld.IsInLineOfSight(ptDestination, LineOfSightMob.GetTraceLinePos()))
{
// Logger.WriteDebug( Color.Cyan, "Mob-free location failed line of sight check for degrees={0:F1} dist={1:F1}", degreesFrom, distFromOrigin);
countFailToMobLoS++;
continue;
}
}
}
Logger.WriteDebug(Color.Cyan, "SafeArea: Found mob-free location ({0:F1} yd radius) at degrees={1:F1} dist={2:F1} on point check# {3} at {4}, {5}, {6}", MinSafeDistance, WoWMathHelper.RadiansToDegrees(checkFacing), distFromOrigin, countPointsChecked, ptDestination.X, ptDestination.Y, ptDestination.Z);
Logger.WriteDebug(Color.Cyan, "SafeArea: processing took {0:F0} ms", (DateTime.UtcNow - startFind).TotalMilliseconds);
Logger.WriteDebug(Color.Cyan, "SafeArea: meshtrace took {0:F0} ms / fullynav took {1:F0} ms", spanTrace.TotalMilliseconds, spanNav.TotalMilliseconds);
Logger.WriteDebug(Color.Cyan, "SafeArea: stats for ({0:F1} yd radius) found within {1:F1} yds ({2} checked, {3} nav, {4} not safe, {5} range, {6} pt los, {7} mob los, {8} mesh trace)", MinSafeDistance, MaxScanDistance, countPointsChecked, countFailToPointNav, countFailSafe, countFailRange, countFailToPointLoS, countFailToMobLoS, countFailTrace);
return ptDestination;
}
}
Logger.WriteDebug(Color.Cyan, "SafeArea: No mob-free location ({0:F1} yd radius) found within {1:F1} yds ({2} checked, {3} nav, {4} not safe, {5} range, {6} pt los, {7} mob los, {8} mesh trace)", MinSafeDistance, MaxScanDistance, countPointsChecked, countFailToPointNav, countFailSafe, countFailRange, countFailToPointLoS, countFailToMobLoS, countFailTrace);
if (ChooseSafestAvailable && ptFurthest != WoWPoint.Empty)
{
Logger.WriteDebug(Color.Cyan, "SafeArea: choosing best available spot in {0:F1} yd radius where closest mob is {1:F1} yds", MinSafeDistance, Math.Sqrt(furthestNearMobDistSqr));
Logger.WriteDebug(Color.Cyan, "SafeArea: processing took {0:F0} ms", (DateTime.UtcNow - startFind).TotalMilliseconds);
Logger.WriteDebug(Color.Cyan, "SafeArea: meshtrace took {0:F0} ms / fullynav took {1:F0} ms", spanTrace.TotalMilliseconds, spanNav.TotalMilliseconds);
return ChooseSafestAvailable ? ptFurthest : WoWPoint.Empty;
}
Logger.WriteDebug(Color.Cyan, "SafeArea: processing took {0:F0} ms", (DateTime.UtcNow - startFind).TotalMilliseconds);
Logger.WriteDebug(Color.Cyan, "SafeArea: meshtrace took {0:F0} ms / fullynav took {1:F0} ms", spanTrace.TotalMilliseconds, spanNav.TotalMilliseconds);
return WoWPoint.Empty;
}
示例3: FindLocation
public WoWPoint FindLocation(WoWPoint ptOrigin)
{
DateTime startFind = DateTime.Now;
int countPointsChecked = 0;
int countFailToPointNav = 0;
int countFailRange = 0;
int countFailSafe = 0;
int countFailToPointLoS = 0;
int countFailToMobLoS = 0;
double furthestNearMobDistSqr = 0f;
WoWPoint ptFurthest = WoWPoint.Empty;
bool reallyCheckRangeToLineOfSightMob = CheckRangeToLineOfSightMob && Me.GotTarget;
WoWPoint ptAdjOrigin = ptOrigin;
ptAdjOrigin.Z += 1f;
WoWPoint ptDestination = new WoWPoint();
List<WoWPoint> mobLocations = new List<WoWPoint>();
float arcIncrement = ((float)Math.PI * 2) / RaysToCheck;
mobLocations = AllEnemyMobLocationsToCheck;
double minSafeDistSqr = MinSafeDistance * MinSafeDistance;
float baseDestinationFacing = MobToRunFrom == null ?
Me.RenderFacing + (float)Math.PI
: Styx.Helpers.WoWMathHelper.CalculateNeededFacing(MobToRunFrom.Location, Me.Location);
// Logger.WriteDebug( Color.Cyan, "SafeArea: search near {0:F0}d @ {1:F1} yds for mob free area", RadiansToDegrees(baseDestinationFacing), MinSafeDistance);
for (int arcIndex = 0; arcIndex < RaysToCheck; arcIndex++)
{
// rather than tracing around the circle, toggle between clockwise and counter clockwise for each test
// .. so we favor a position furthest away from mob
float checkFacing = baseDestinationFacing;
if ((arcIndex & 1) == 0)
checkFacing += arcIncrement * (arcIndex >> 1);
else
checkFacing -= arcIncrement * ((arcIndex >> 1) + 1);
for (float distFromOrigin = MinScanDistance; distFromOrigin <= MaxScanDistance; distFromOrigin += IncrementScanDistance)
{
countPointsChecked++;
ptDestination = ptOrigin.RayCast(checkFacing, distFromOrigin);
if (!Navigator.CanNavigateFully(Me.Location, ptDestination))
{
// Logger.WriteDebug( Color.Cyan, "Safe Location failed navigation check for degrees={0:F1} dist={1:F1}", RadiansToDegrees(checkFacing), distFromOrigin);
countFailToPointNav++;
continue;
}
WoWPoint ptNearest = NearestMobLoc(ptDestination, mobLocations);
if (ptNearest == WoWPoint.Empty)
{
if (furthestNearMobDistSqr < minSafeDistSqr)
{
furthestNearMobDistSqr = minSafeDistSqr;
ptFurthest = ptDestination; // set best available if others fail
}
}
else
{
double mobDistSqr = ptDestination.Distance2DSqr(ptNearest);
if (furthestNearMobDistSqr < mobDistSqr)
{
furthestNearMobDistSqr = mobDistSqr;
ptFurthest = ptDestination; // set best available if others fail
}
if (mobDistSqr <= minSafeDistSqr)
{
countFailSafe++;
continue;
}
}
if (reallyCheckRangeToLineOfSightMob && RangeToLineOfSightMob < ptDestination.Distance(LineOfSightMob.Location) - LineOfSightMob.MeleeDistance())
{
countFailRange++;
continue;
}
if (CheckLineOfSightToSafeLocation)
{
WoWPoint ptAdjDest = ptDestination;
ptAdjDest.Z += 1f;
if (!Styx.WoWInternals.World.GameWorld.IsInLineOfSight(ptAdjOrigin, ptAdjDest))
{
// Logger.WriteDebug( Color.Cyan, "Mob-free location failed line of sight check for degrees={0:F1} dist={1:F1}", degreesFrom, distFromOrigin);
countFailToPointLoS++;
continue;
}
}
if (CheckSpellLineOfSightToMob && LineOfSightMob != null)
{
if (!Styx.WoWInternals.World.GameWorld.IsInLineOfSpellSight(ptDestination, LineOfSightMob.Location))
{
if (!Styx.WoWInternals.World.GameWorld.IsInLineOfSight(ptDestination, LineOfSightMob.Location))
{
// Logger.WriteDebug( Color.Cyan, "Mob-free location failed line of sight check for degrees={0:F1} dist={1:F1}", degreesFrom, distFromOrigin);
countFailToMobLoS++;
//.........这里部分代码省略.........
示例4: FindClusterTargets
/// <summary>Finds clustered targets</summary>
/// <param name="radius">radius</param>
/// <param name="minDistance">minimum distance</param>
/// <param name="maxDistance">maximum distance</param>
/// <param name="minTargets">minimum targets to qualify</param>
/// <param name="playersOnly">true for players only</param>
/// <returns>The find cluster targets.</returns>
public static WoWPoint FindClusterTargets(double radius, double minDistance, double maxDistance, int minTargets, bool playersOnly)
{
List<WoWUnit> hostile = ObjectManager.GetObjectsOfType<WoWUnit>(true, false);
var avoid = new List<WoWUnit>();
var maxDistance2 = (maxDistance + radius) * (maxDistance + radius);
if (playersOnly)
{
hostile = hostile.Where(x =>
x.IsPlayer &&
IsAttackable(x) && x.Distance2DSqr < maxDistance2).ToList();
}
else
{
hostile = hostile.Where(x =>
!x.IsPlayer &&
IsAttackable(x) && x.Distance2DSqr < maxDistance2).ToList();
avoid = hostile.Where(
x => // check for controlled units, like sheep etc
UnitIsControlled(x, true)).ToList();
}
if (hostile.Count < minTargets)
{
return WoWPoint.Empty;
}
var score = minTargets - 1;
var best = WoWPoint.Empty;
for (var x = Me.Location.X - maxDistance; x <= Me.Location.X + maxDistance; x++)
{
for (var y = Me.Location.Y - maxDistance; y <= Me.Location.Y + maxDistance; y++)
{
var spot = new WoWPoint(x, y, Me.Location.Z);
var dSquare = spot.Distance2DSqr(Me.Location);
if (dSquare > maxDistance * maxDistance || dSquare < minDistance * minDistance)
{
continue;
}
if (avoid.Any(t => t.Location.Distance2DSqr(spot) <= radius * radius))
{
continue;
}
var hits = hostile.Count(t => t.Location.DistanceSqr(spot) < radius * radius);
if (hits > score)
{
best = spot;
score = hits;
CLULogger.DiagnosticLog("ClusteredTargets(range=" + minDistance + "-" + maxDistance + ", radius=" + radius + ") => SCORE=" + score + " at " + spot);
foreach (var u in hostile.Where(t => t.Location.DistanceSqr(spot) < radius * radius))
CLULogger.DiagnosticLog(" -> " + CLULogger.SafeName(u) + " " + u.Level);
CLULogger.DiagnosticLog("---------------------");
}
}
}
return best;
}