本文整理汇总了C#中WCell.RealmServer.Entities.Character.GetDistanceSq方法的典型用法代码示例。如果您正苦于以下问题:C# Character.GetDistanceSq方法的具体用法?C# Character.GetDistanceSq怎么用?C# Character.GetDistanceSq使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WCell.RealmServer.Entities.Character
的用法示例。
在下文中一共展示了Character.GetDistanceSq方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsInArea
/// <summary>
/// Returns whether the given object is within the bounds of this AreaTrigger.
/// </summary>
/// <param name="chr"></param>
/// <returns></returns>
public bool IsInArea(Character chr)
{
if (chr.Map.Id != MapId)
{
return false;
}
if (Radius > 0) // Sphere
{
var distSq = chr.GetDistanceSq(Position);
if (distSq > MaxDistSq)
{
LogManager.GetCurrentClassLogger().Warn("Character {0} tried to trigger {1} while being {2} yards away.",
chr, this, Math.Sqrt(distSq));
return false;
}
}
else // Box
{
// 2PI = 360 degrees. Keep in mind that in-game orientation is counter-clockwise.
var rotation = 2 * MathUtil.PI - BoxYaw;
var sinval = Math.Sin(rotation);
var cosval = Math.Cos(rotation);
var playerBoxDistX = chr.Position.X - Position.X;
var playerBoxDistY = chr.Position.Y - Position.Y;
var rotPlayerX = Position.X + playerBoxDistX * cosval - playerBoxDistY * sinval;
var rotPlayerY = Position.Y + playerBoxDistY * cosval + playerBoxDistX * sinval;
// Box edges are parallel to coordinate axis, so we can treat every dimension independently.
var dx = rotPlayerX - Position.X;
var dy = rotPlayerY - Position.Y;
var dz = chr.Position.Z - Position.Z;
if ((Math.Abs(dx) > BoxLength / 2 + tollerance) ||
(Math.Abs(dy) > BoxWidth / 2 + tollerance) ||
(Math.Abs(dz) > BoxHeight / 2 + tollerance))
{
return false;
}
}
return true;
}
示例2: SelectClosest
/// <summary>
/// Tries to select the nearest GO that is in front of the character
/// </summary>
/// <returns>The newly selected GO.</returns>
public GameObject SelectClosest(Character chr)
{
var gos = chr.GetObjectsInRadius(MaxSearchRadius, ObjectTypes.GameObject, true, 0);
var sqDist = float.MaxValue;
GameObject sel = null;
foreach (GameObject go in gos)
{
// TODO: Go by angle instead of distance
//var angle = chr.GetAngleTowards(go);
if (sel == null ||
(go.IsInFrontOf(chr) && chr.GetDistanceSq(go) < sqDist))
{
sel = go;
}
}
this[chr] = sel;
return sel;
}