當前位置: 首頁>>代碼示例>>C#>>正文


C# Character.GetDistanceSq方法代碼示例

本文整理匯總了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;
		}
開發者ID:remixod,項目名稱:netServer,代碼行數:51,代碼來源:AreaTrigger.cs

示例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;
		}
開發者ID:ray2006,項目名稱:WCell,代碼行數:25,代碼來源:GOSelectMgr.cs


注:本文中的WCell.RealmServer.Entities.Character.GetDistanceSq方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。