コード例 #1
0
        public static void NpcMoveAlongPath(int MapNum, int MapNpcNum)
        {
            int x, y;

            // make sure we're not at end of path
            if (modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc >= 1)
            {
                x = modTypes.MapNpc[MapNum].Npc[MapNpcNum].arPath[modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc - 1].x;
                y = modTypes.MapNpc[MapNum].Npc[MapNpcNum].arPath[modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc - 1].y;

                // Do 8 Directional First
                // up Left
                if (y < modTypes.MapNpc[MapNum].Npc[MapNpcNum].Y && x < modTypes.MapNpc[MapNum].Npc[MapNpcNum].X)
                {
                    if (S_Npc.CanNpcMove(MapNum, MapNpcNum, (int)DirectionType.UpLeft))
                    {
                        S_Npc.NpcMove(MapNum, MapNpcNum, (int)DirectionType.UpLeft, (int)MovementType.Walking);
                        modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc -= 1;
                        return;
                    }
                }
                // Up Right
                else if (y < modTypes.MapNpc[MapNum].Npc[MapNpcNum].Y && x > modTypes.MapNpc[MapNum].Npc[MapNpcNum].X)
                {
                    if (S_Npc.CanNpcMove(MapNum, MapNpcNum, (int)DirectionType.UpRight))
                    {
                        S_Npc.NpcMove(MapNum, MapNpcNum, (int)DirectionType.UpRight, (int)MovementType.Walking);
                        modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc -= 1;
                        return;
                    }
                }
                // Down Left
                else if (y > modTypes.MapNpc[MapNum].Npc[MapNpcNum].Y && x < modTypes.MapNpc[MapNum].Npc[MapNpcNum].X)
                {
                    if (S_Npc.CanNpcMove(MapNum, MapNpcNum, (int)DirectionType.DownLeft))
                    {
                        S_Npc.NpcMove(MapNum, MapNpcNum, (int)DirectionType.DownLeft, (int)MovementType.Walking);
                        modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc -= 1;
                        return;
                    }
                }
                // Down Right
                else if (y > modTypes.MapNpc[MapNum].Npc[MapNpcNum].Y && x > modTypes.MapNpc[MapNum].Npc[MapNpcNum].X)
                {
                    if (S_Npc.CanNpcMove(MapNum, MapNpcNum, (int)DirectionType.DownRight))
                    {
                        S_Npc.NpcMove(MapNum, MapNpcNum, (int)DirectionType.DownRight, (int)MovementType.Walking);
                        modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc -= 1;
                        return;
                    }
                }

                // up
                else if (y < modTypes.MapNpc[MapNum].Npc[MapNpcNum].Y)
                {
                    if (S_Npc.CanNpcMove(MapNum, MapNpcNum, (int)DirectionType.Up))
                    {
                        S_Npc.NpcMove(MapNum, MapNpcNum, (int)DirectionType.Up, (int)MovementType.Walking);
                        modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc -= 1;
                        return;
                    }
                }
                // down
                if (y > modTypes.MapNpc[MapNum].Npc[MapNpcNum].Y)
                {
                    if (S_Npc.CanNpcMove(MapNum, MapNpcNum, (int)DirectionType.Down))
                    {
                        S_Npc.NpcMove(MapNum, MapNpcNum, (int)DirectionType.Down, (int)MovementType.Walking);
                        modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc -= 1;
                        return;
                    }
                }
                // left
                if (x < modTypes.MapNpc[MapNum].Npc[MapNpcNum].X)
                {
                    if (S_Npc.CanNpcMove(MapNum, MapNpcNum, (int)DirectionType.Left))
                    {
                        S_Npc.NpcMove(MapNum, MapNpcNum, (int)DirectionType.Left, (int)MovementType.Walking);
                        modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc -= 1;
                        return;
                    }
                }
                // right
                if (x > modTypes.MapNpc[MapNum].Npc[MapNpcNum].X)
                {
                    if (S_Npc.CanNpcMove(MapNum, MapNpcNum, (int)DirectionType.Right))
                    {
                        S_Npc.NpcMove(MapNum, MapNpcNum, (int)DirectionType.Right, (int)MovementType.Walking);
                        modTypes.MapNpc[MapNum].Npc[MapNpcNum].pathLoc -= 1;
                        return;
                    }
                }
            }
        }