Exemplo n.º 1
0
        private void setNextWalk(IObject target, IFollowSettings settings, IWalkComponent walk)
        {
            if (isInAllowedDistance(target, settings) && MathUtils.Random().Next(100) <= settings.StayPutPercentage)
            {
                return;
            }

            PointF targetPoint = PointF.Empty;
            int    retries     = 3;

            while (retries > 0)
            {
                targetPoint = getFollowTargetPoint(target, settings);
                if (isWalkingDistanceValid(targetPoint, settings))
                {
                    break;
                }
                retries--;
            }

            if (retries <= 0)
            {
                Debug.WriteLine($"FollowComponent: Failed to get a target point which is not too close");
                return;
            }

            _currentWalk = walk.WalkAsync(new Position(targetPoint.X, targetPoint.Y));
        }
Exemplo n.º 2
0
        private PointF follow(IObject target, IFollowSettings settings)
        {
            float x = getPointInRange(settings.MinXOffset, settings.MaxXOffset, _obj.X, target.X, -1f, -1f, settings.StayOnTheSameSideForXPercentage);
            float y = getPointInRange(settings.MinYOffset, settings.MaxYOffset, _obj.Y, target.Y, -1f, -1f, settings.StayOnTheSameSideForYPercentage);

            return(new PointF(x, y));
        }
Exemplo n.º 3
0
        private PointF getFollowTargetPoint(IObject target, IFollowSettings settings)
        {
            if (MathUtils.Random().Next(100) <= settings.WanderOffPercentage)
            {
                return(wanderOff(target, settings));
            }

            return(follow(target, settings));
        }
Exemplo n.º 4
0
        private PointF follow(IObject target, IFollowSettings settings)
        {
            float yOffset = MathUtils.Lerp(0f, settings.MinYOffset, 1f, settings.MaxYOffset, (float)MathUtils.Random().NextDouble());
            float xOffset = MathUtils.Lerp(0f, settings.MinXOffset, 1f, settings.MaxXOffset, (float)MathUtils.Random().NextDouble());

            float x = _obj.X > target.X ? target.X + xOffset : target.X - xOffset;
            float y = _obj.Y > target.Y ? target.Y + yOffset : target.Y - yOffset;

            return(new PointF(x, y));
        }
Exemplo n.º 5
0
		public void Follow (IObject obj, IFollowSettings settings)
		{
            var currentTarget = obj;
            if (currentTarget != null)
            {
                FollowTag.RemoveTag(currentTarget, _follower);
            }
            TargetBeingFollowed = obj;
            FollowTag.AddTag(obj, _follower);
			_followSettings = settings ?? new AGSFollowSettings ();
		}
Exemplo n.º 6
0
        public void Follow(IObject obj, IFollowSettings settings)
        {
            var currentTarget = obj;

            if (currentTarget != null)
            {
                FollowTag.RemoveTag(currentTarget, _follower);
            }
            TargetBeingFollowed = obj;
            FollowTag.AddTag(obj, _follower);
            _followSettings = settings ?? new AGSFollowSettings();
        }
Exemplo n.º 7
0
        private PointF wanderOff(IObject target, IFollowSettings settings)
        {
            var   room            = _game.State.Room;
            bool  isLimitlessRoom = room == null || MathUtils.FloatEquals(room.Limits.Width, float.MaxValue);
            float minRoomX        = isLimitlessRoom ? 0f : room.Limits.X;
            float maxRoomX        = isLimitlessRoom ? _game.Settings.VirtualResolution.Width : room.Limits.X + room.Limits.Width;
            float minRoomY        = isLimitlessRoom ? 0f : room.Limits.Y;
            float maxRoomY        = isLimitlessRoom ? _game.Settings.VirtualResolution.Height : room.Limits.Y + room.Limits.Height;
            float x = getPointInRange(settings.MinXOffsetForWanderOff, settings.MaxXOffsetForWanderOff, _obj.X, target.X, minRoomX, maxRoomX, settings.StayOnTheSameSideForXPercentage);
            float y = getPointInRange(settings.MinYOffsetForWanderOff, settings.MaxYOffsetForWanderOff, _obj.Y, target.Y, minRoomY, maxRoomY, settings.StayOnTheSameSideForYPercentage);

            return(new PointF(x, y));
        }
Exemplo n.º 8
0
        private void setNextWalk(IObject target, IFollowSettings settings, IWalkComponent walk)
        {
            PointF targetPoint;

            if (MathUtils.Random().Next(100) <= settings.WanderOffPercentage)
            {
                targetPoint = wanderOff();
            }
            else
            {
                targetPoint = follow(target, settings);
            }

            _currentWalk = walk.WalkAsync(new Position(targetPoint.X, targetPoint.Y));
        }
Exemplo n.º 9
0
 private bool isWalkingDistanceValid(PointF targetPoint, IFollowSettings settings) => MathUtils.Distance((_obj.X, _obj.Y), targetPoint) >= settings.MinimumWalkingDistance;
Exemplo n.º 10
0
 private bool isInAllowedDistance(IObject target, IFollowSettings settings)
 {
     return(_obj.X.IsBetween(target.X + settings.MinXOffset, target.X + settings.MaxXOffset) &&
            _obj.Y.IsBetween(target.Y + settings.MinYOffset, target.Y + settings.MaxYOffset));
 }
Exemplo n.º 11
0
 public void Follow(IObject obj, IFollowSettings settings)
 {
     _followBehavior.Follow(obj, settings);
 }
Exemplo n.º 12
0
 public void Follow(IObject obj, IFollowSettings settings)
 {
     _followComponent.Follow(obj, settings);
 }
Exemplo n.º 13
0
 public void Follow(IObject obj, IFollowSettings settings)
 {
     _followBehavior.Follow(obj, settings);
 }
Exemplo n.º 14
0
		private void setNextWalk (IObject target, IFollowSettings settings)
		{
			PointF targetPoint;
			if (MathUtils.Random ().Next (100) <= settings.WanderOffPercentage) 
			{
				targetPoint = wanderOff ();
			} 
			else targetPoint = follow (target, settings);

			_currentWalk = _walk.WalkAsync (new AGSLocation (targetPoint.X, targetPoint.Y));
		}
Exemplo n.º 15
0
		private PointF follow(IObject target, IFollowSettings settings)
		{
			float yOffset = MathUtils.Lerp (0f, settings.MinYOffset, 1f, settings.MaxYOffset, (float)MathUtils.Random ().NextDouble ());
			float xOffset = MathUtils.Lerp (0f, settings.MinXOffset, 1f, settings.MaxXOffset, (float)MathUtils.Random ().NextDouble ());

			float x = _obj.X > target.X ? target.X + xOffset : target.X - xOffset;
			float y = _obj.Y > target.Y ? target.Y + yOffset : target.Y - yOffset;
			return new PointF (x, y);
		}