当前位置: 首页>>代码示例>>C#>>正文


C# GameObject.IsWithinRadius方法代码示例

本文整理汇总了C#中DOL.GS.GameObject.IsWithinRadius方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.IsWithinRadius方法的具体用法?C# GameObject.IsWithinRadius怎么用?C# GameObject.IsWithinRadius使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DOL.GS.GameObject的用法示例。


在下文中一共展示了GameObject.IsWithinRadius方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LosCheck

		/// <summary>
		/// Check LoS and wait for a reply before returning
		/// </summary>
		/// <param name="player">Client used to make the LoS check</param>
		/// <param name="source">GameObject from witch LoS check start</param>
		/// <param name="target">GameObject to check LoS to</param>
		/// <param name="notifier">GameObject to Notify when Check is made</param>
		/// <param name="cached">Use a cached result</param>
		/// <param name="timeout">Cache Timeout, 0 = default</param>
		public void LosCheck(GamePlayer player, GameObject source, GameObject target, IDOLEventHandler notifier, bool cached = true, int timeout = 0)
		{			
			if(player == null || source == null || target == null)
				throw new LosUnavailableException();
			
			// FIXME debug
			if(LOSMGR_DEBUG_LEVEL >= LOSMGR_DEBUG_WARN)
				log.Warn("LOSMGR_W : Starting Los Check with - Player : "+player.Name+" Source : "+source.Name+" Target : "+target.Name+".");

			if(timeout <= 0)
				timeout = GetDefaultTimeouts(source, target);
			
			// check Threshold first
			if(source.IsWithinRadius(target, GetDefaultThreshold(source, target), false))
			{
				// FIXME debug
				if(LOSMGR_DEBUG_LEVEL >= LOSMGR_DEBUG_DEBUG)
					log.Warn("LOSMGR_D : Threshold hitted ("+GetDefaultThreshold(source, target)+") with - Player : "+player.Name+" Source : "+source.Name+" Target : "+target.Name+".");

				notifier.Notify(GameObjectEvent.FinishedLosCheck, player, new LosCheckData(source, target, GameTimer.GetTickCount(), true));
				return;
			}
			
			// check in cache then !
			if(cached)
			{	
				try
				{
					bool los = GetLosCheckFromCache(source, target, timeout);
					notifier.Notify(GameObjectEvent.FinishedLosCheck, player, new LosCheckData(source, target, GameTimer.GetTickCount(), los));
					return;
					
				}
				catch (LosUnavailableException)
				{
					// we have no cache
				}
			}

			// Check if a LoS is pending, or this player is already LoS Checking...
			Tuple<GameObject, GameObject> cacheKey = new Tuple<GameObject, GameObject>(source, target);
						
			// We need to lock the Pending list during the checks
			lock(((ICollection)PendingChecks).SyncRoot)
			{
				IEnumerable<Tuple<GamePlayer, ushort, ushort>> pendings = (from pending in PendingChecks where (pending.Key.Item2 == source.ObjectID && pending.Key.Item3 == target.ObjectID) || (pending.Key.Item2 == target.ObjectID && pending.Key.Item3 == source.ObjectID) select pending.Key).Take(1);

				// We have pending data not too old, Register this event handler
				foreach(Tuple<GamePlayer, ushort, ushort> pend in pendings)
				{
					// FIXME debug
					if(LOSMGR_DEBUG_LEVEL >= LOSMGR_DEBUG_INFO)
						log.Warn("LOSMGR_D : Registered to an other LoS with - Player : "+player.Name+" Source : "+source.Name+" Target : "+target.Name+".");

					AddRegisteredEvent(cacheKey, notifier);
					return;
				}
			}
			
			// Throttle
			if(IsPvpLosCheck(source, target) || IsAvailableForLosCheck(player, source, target)) {
				// Not pending, Not in Cache, let's work
				AddRegisteredEvent(cacheKey, notifier);
				EventNotifierLosCheck(player, source, target);
			}
			else
			{
				// Get best checker !
				GamePlayer checker = GetBestLosChecker(source, target);
				
				if(checker != null) 
				{
					// FIXME Debug
					if(LOSMGR_DEBUG_LEVEL >= LOSMGR_DEBUG_WARN)
						log.Warn("LOSMGR_D : Deferred LoSCheck to "+checker.Name+" From - Player : "+player.Name+" Source : "+source.Name+" Target : "+target.Name+".");

					AddRegisteredEvent(cacheKey, notifier);
					EventNotifierLosCheck(checker, source, target);
				}
				else
				{
					// the Player checker is unavailable to make this LosCheck
					throw new LosUnavailableException();
				}
			}
		}
开发者ID:mynew4,项目名称:DAoC,代码行数:95,代码来源:LosCheckMgr.cs

示例2: LosCheckVincinity

		/// <summary>
		/// LoscheckVincinity can be used when source player isn't available to check Los
		/// </summary>
		/// <param name="source">GameObject from witch LoS check start</param>
		/// <param name="target">GameObject to check LoS to</param>
		/// <param name="notifier">GameObject to Notify when Check is made</param>
		/// <param name="cached">Use a cached result</param>
		/// <param name="timeout">Cache Timeout, 0 = default</param>
		public void LosCheckVincinity(GameObject source, GameObject target, IDOLEventHandler notifier, bool cached = true, int timeout = 0) 
		{			
			// FIXME debug
			if(LOSMGR_DEBUG_LEVEL >= LOSMGR_DEBUG_WARN)
				log.Warn("LOSMGR_W : Starting Vincinity Los Check Between - Source : "+source.Name+" Target : "+target.Name+".");
			
			if(timeout == 0)
				timeout = GetDefaultTimeouts(source, target);
			
			// check Threshold first
			if(source.IsWithinRadius(target, GetDefaultThreshold(source, target), false))
			{
				//we need an arbitrary player
				foreach(GamePlayer player in source.GetPlayersInRadius(WorldMgr.VISIBILITY_DISTANCE))
				{
					if(player.ObjectState == GameNPC.eObjectState.Active) 
					{
						// FIXME debug
						if(LOSMGR_DEBUG_LEVEL >= LOSMGR_DEBUG_DEBUG)
							log.Warn("LOSMGR_D : Vincinity Hitted Treshold ("+GetDefaultThreshold(source, target)+") - Source : "+source.Name+" Target : "+target.Name+".");
						
						notifier.Notify(GameObjectEvent.FinishedLosCheck, player, new LosCheckData(source, target, GameTimer.GetTickCount(), true));
						return;
					}
				}
			}
			
			// check cache then !
			if(cached)
			{			
				try
				{
					bool los = GetLosCheckFromCache(source, target, timeout);
					//we need an arbitrary player
					foreach(GamePlayer player in source.GetPlayersInRadius(WorldMgr.VISIBILITY_DISTANCE))
					{
						if(player.ObjectState == GameNPC.eObjectState.Active) 
						{
							notifier.Notify(GameObjectEvent.FinishedLosCheck, player, new LosCheckData(source, target, GameTimer.GetTickCount(), los));
							return;
						}
						
					}
				}
				catch (LosUnavailableException)
				{
					// we have no cache
				}
			}
			
			// check pending
			lock(((ICollection)PendingChecks).SyncRoot)
			{
				IEnumerable<Tuple<GamePlayer, ushort, ushort>> pendings = (from pending in PendingChecks where (pending.Key.Item2 == source.ObjectID && pending.Key.Item3 == target.ObjectID) || (pending.Key.Item2 == target.ObjectID && pending.Key.Item3 == source.ObjectID) select pending.Key).Take(1);
				foreach(Tuple<GamePlayer, ushort, ushort> pend in pendings)
				{
					// FIXME debug
					if(LOSMGR_DEBUG_LEVEL >= LOSMGR_DEBUG_INFO)
						log.Warn("LOSMGR_I : Vincinity Registered to an other LoS - Source : "+source.Name+" Target : "+target.Name+".");
					
					AddRegisteredEvent(new Tuple<GameObject, GameObject>(source, target), notifier);
					return;
				}
			}
						
			// check if source is player and available for Los check
			if(IsAvailableForLosCheck(source, source, target))
			{
				LosCheck((GamePlayer)source, source, target, notifier, cached, timeout);
				return;
			}
			
			// check if target is player and available for Los check
			if(IsAvailableForLosCheck(target, source, target))
			{
				LosCheck((GamePlayer)target, source, target, notifier, cached, timeout);
				return;
			}
			
			// check if source has an available owner
			if(source is GameNPC && ((GameNPC)source).Brain != null && ((GameNPC)source).Brain is IControlledBrain)
			{
				GamePlayer owner = ((IControlledBrain)((GameNPC)source).Brain).GetPlayerOwner();
				if(owner != null && IsAvailableForLosCheck(owner, source, target)) {
					LosCheck(owner, source, target, notifier, cached, timeout);
					return;
				}	
			}
			
			// check if target has an available owner
			if(target is GameNPC && ((GameNPC)target).Brain != null && ((GameNPC)target).Brain is IControlledBrain)
			{
//.........这里部分代码省略.........
开发者ID:mynew4,项目名称:DAoC,代码行数:101,代码来源:LosCheckMgr.cs

示例3: GetBestLosChecker

		private GamePlayer GetBestLosChecker(GameObject source, GameObject target) 
		{
			// Stealthed Player can't be third-party los Checked
			// FIXME could use player who can detect the Stealther (Realm mate) for a third party check
			if(source is GamePlayer && ((GamePlayer)source).IsStealthed)
			{
				// FIXME Debug
				if(LOSMGR_DEBUG_LEVEL >= LOSMGR_DEBUG_DEBUG)
					log.Warn("LOSMGR_D : Vincinity Player choosen because source is stealthed - "+source.Name);
				
				return (GamePlayer)source;
			}
			
			if(target is GamePlayer && ((GamePlayer)target).IsStealthed)
			{
				// FIXME Debug
				if(LOSMGR_DEBUG_LEVEL >= LOSMGR_DEBUG_DEBUG)
					log.Warn("LOSMGR_D : Vincinity Player choosen because target is stealthed - "+target.Name);
				
				return (GamePlayer)target;
			}
			
			
			// Get all players around able to check LoS
			IEnumerable<GamePlayer> playersQuery = (from GamePlayer player in source.GetPlayersInRadius(WorldMgr.VISIBILITY_DISTANCE) select player);
			
			List<GamePlayer> players = new List<GamePlayer>();
			
			foreach(GamePlayer test in playersQuery)
			{
				if(target.IsWithinRadius(test, WorldMgr.VISIBILITY_DISTANCE))
				   players.Add(test);
			}
			
			// first get all players that haven't done anything
			lock(((ICollection)ClientChecks).SyncRoot)
			{
				IEnumerable<GamePlayer> checkers = (from checker in players where !ClientChecks.ContainsKey(checker) || !ClientStats.ContainsKey(checker)
				                                    select checker).Take(1);
			
				// Pick one that isn't in cache
				foreach(GamePlayer choosed in checkers)
				{
					// FIXME Debug
					if(LOSMGR_DEBUG_LEVEL >= LOSMGR_DEBUG_DEBUG)
						log.Warn("LOSMGR_D : Vincinity Player choosen because inactive - "+choosed.Name);
					
					return choosed;
				}
			}
			
			lock(((ICollection)ClientStats).SyncRoot)
			{
				long currentTime = GameTimer.GetTickCount();
				// We don't have player that aren't in cache try selecting available ones (lowest count && best instant checker)
				IEnumerable<GamePlayer> bestavails = (from best in ClientStats.Keys where players.Contains(best) && 
				                                      (ClientChecks.ContainsKey(best) && (currentTime-ClientChecks[best]) > LOSMGR_PLAYER_CHECK_FREQUENCY)
				            orderby ClientStats[best].Item1, ClientStats[best].Item3 descending
				            select best).Take(1);
				
				// Pick the best
				foreach(GamePlayer choosed in bestavails)
				{
					// FIXME Debug
					if(LOSMGR_DEBUG_LEVEL >= LOSMGR_DEBUG_DEBUG)
						log.Warn("LOSMGR_D : Vincinity Player choosen because available and best checker - "+choosed.Name);
					
					return choosed;
				}
				
				// All of them are busy pick the fastest instant checker
				IEnumerable<GamePlayer> betters = (from best in ClientStats.Keys where players.Contains(best)
				            orderby ClientStats[best].Item3 descending, ClientStats[best].Item2 descending
				            select best).Take(1);
				
				// Pick the best
				foreach(GamePlayer choosed in betters)
				{
					// FIXME Debug
					if(LOSMGR_DEBUG_LEVEL >= LOSMGR_DEBUG_DEBUG)
						log.Warn("LOSMGR_D : Vincinity Player choosen because best checker even if not available - "+choosed.Name);
					
					return choosed;
				}
			}
		
			// Return any default players
			foreach(GamePlayer choosed in players)
			{
				// FIXME Debug
				if(LOSMGR_DEBUG_LEVEL >= LOSMGR_DEBUG_DEBUG)
					log.Warn("LOSMGR_D : Vincinity Player choosen because there was no one else - "+choosed.Name);
				
				return choosed;
			}
			
			// FIXME Debug
			if(LOSMGR_DEBUG_LEVEL >= LOSMGR_DEBUG_DEBUG) 
			{
				string concat = "";
//.........这里部分代码省略.........
开发者ID:mynew4,项目名称:DAoC,代码行数:101,代码来源:LosCheckMgr.cs


注:本文中的DOL.GS.GameObject.IsWithinRadius方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。