Beispiel #1
0
        public bool Update(INonPlayableCreatureObject creature, Point position)
        {
            if (creature.Statuses.Contains(ParalyzedObjectStatus.StatusType))
            {
                return(true);
            }

            var visibleArea            = VisibilityHelper.GetVisibleArea(creature.VisibilityRange, position);
            var relativeTargetPosition = GetNearestTargetPosition(visibleArea);

            if (relativeTargetPosition == null)
            {
                return(true);
            }

            var absoluteTargetPosition = new Point(
                position.X - creature.VisibilityRange + relativeTargetPosition.X,
                position.Y - creature.VisibilityRange + relativeTargetPosition.Y);
            var adjustedTargetDirection = Point.GetAdjustedPointRelativeDirection(position, absoluteTargetPosition);

            if (adjustedTargetDirection.HasValue)
            {
                AttackTarget(creature, position, absoluteTargetPosition, adjustedTargetDirection.Value);
                return(true);
            }

            TryMoveToTarget(creature, position, absoluteTargetPosition);
            return(true);
        }
        public static bool GetIfPointIsVisible(Point position, int viewDistance, Point checkPoint)
        {
            if (!GetIfPointInVisibilityRange(position, viewDistance, checkPoint))
            {
                return(false);
            }

            var visibleArea = VisibilityHelper.GetVisibleArea(viewDistance, position);
            var relativeX   = checkPoint.X - position.X + viewDistance;
            var relativeY   = checkPoint.Y - position.Y + viewDistance;

            var checkCell = visibleArea.GetCell(relativeX, relativeY);

            if (checkCell == null)
            {
                return(false);
            }

            return(true);
        }