コード例 #1
0
ファイル: MoveNearTo.cs プロジェクト: Mixi59/Stump
        protected override RunStatus Run(object context)
        {
            if (!Fighter.CanMove())
            {
                return(RunStatus.Failure);
            }

            if (Target == null)
            {
                return(RunStatus.Failure);
            }

            var cellInfoProvider = new AIFightCellsInformationProvider(Fighter.Fight, Fighter);

            if (Fighter.Position.Point.IsAdjacentTo(Target.Position.Point))
            {
                return(RunStatus.Success);
            }

            // todo : avoid tackle
            var cell = Target.Position.Point.GetAdjacentCells(cellInfoProvider.IsCellWalkable).OrderBy(entry => entry.ManhattanDistanceTo(Fighter.Position.Point)).FirstOrDefault();

            if (cell == null)
            {
                return(RunStatus.Failure);
            }

            var moveAction = new MoveAction(Fighter, cell);

            return(moveAction.YieldExecute(context));
        }
コード例 #2
0
        protected override RunStatus Run(object context)
        {
            RunStatus result;

            if (!base.Fighter.CanMove())
            {
                result = RunStatus.Failure;
            }
            else
            {
                if (this.Target == null)
                {
                    result = RunStatus.Failure;
                }
                else
                {
                    AIFightCellsInformationProvider @object = new AIFightCellsInformationProvider(base.Fighter.Fight, base.Fighter);
                    if (base.Fighter.Position.Point.IsAdjacentTo(this.Target.Position.Point))
                    {
                        result = RunStatus.Success;
                    }
                    else
                    {
                        MapPoint mapPoint = (
                            from entry in this.Target.Position.Point.GetAdjacentCells(new Func <short, bool>(@object.IsCellWalkable))
                            orderby entry.DistanceToCell(base.Fighter.Position.Point)
                            select entry).FirstOrDefault <MapPoint>();
                        if (mapPoint == null)
                        {
                            result = RunStatus.Failure;
                        }
                        else
                        {
                            MoveAction moveAction = new MoveAction(base.Fighter, mapPoint);
                            result = moveAction.YieldExecute(context);
                        }
                    }
                }
            }
            return(result);
        }