Beispiel #1
0
        public static bool Prefix(ref PathFindController __instance, Character ___character, GameTime time)
        {
            if (!ModEntry.IsChildNPC(___character))
            {
                return(true);
            }

            Rectangle rectangle = new Rectangle(__instance.pathToEndPoint.Peek().X * 64, __instance.pathToEndPoint.Peek().Y * 64, 64, 64);

            rectangle.Inflate(-2, 0);
            Rectangle boundingBox = ___character.GetBoundingBox();

            if ((rectangle.Contains(boundingBox) || boundingBox.Width > rectangle.Width && rectangle.Contains(boundingBox.Center)) && rectangle.Bottom - boundingBox.Bottom >= 2)
            {
                __instance.timerSinceLastCheckPoint = 0;
                __instance.pathToEndPoint.Pop();
                ___character.stopWithoutChangingFrame();
                if (__instance.pathToEndPoint.Count != 0)
                {
                    return(false);
                }
                ___character.Halt();
                if (__instance.finalFacingDirection != -1)
                {
                    ___character.faceDirection(__instance.finalFacingDirection);
                }
                if (__instance.NPCSchedule)
                {
                    (___character as NPC).DirectionsToNewLocation = null;
                    (___character as NPC).endOfRouteMessage.Value = (___character as NPC).nextEndOfRouteMessage;
                }
                if (__instance.endBehaviorFunction == null)
                {
                    return(false);
                }
                __instance.endBehaviorFunction(___character, __instance.location);
                return(false);
            }
            else
            {
                foreach (NPC character in __instance.location.characters)
                {
                    if (!character.Equals(___character) && character.GetBoundingBox().Intersects(boundingBox) && character.isMoving() && string.Compare(character.Name, ___character.Name) < 0)
                    {
                        ___character.Halt();
                        return(false);
                    }
                }
                if (boundingBox.Left < rectangle.Left && boundingBox.Right < rectangle.Right)
                {
                    ___character.SetMovingRight(true);
                }
                else if (boundingBox.Right > rectangle.Right && boundingBox.Left > rectangle.Left)
                {
                    ___character.SetMovingLeft(true);
                }
                else if (boundingBox.Top <= rectangle.Top)
                {
                    ___character.SetMovingDown(true);
                }
                else if (boundingBox.Bottom >= rectangle.Bottom - 2)
                {
                    ___character.SetMovingUp(true);
                }
                ___character.MovePosition(time, Game1.viewport, __instance.location);
                if (!__instance.NPCSchedule)
                {
                    return(false);
                }
                Warp warp = __instance.location.isCollidingWithWarpOrDoor(___character.nextPosition(___character.getDirection()));
                if (warp == null)
                {
                    return(false);
                }

                //This is the point where character needs to be married, I'm fixing.
                if (___character is NPC /*&& (___character as NPC).isMarried() */ && (___character as NPC).followSchedule)
                {
                    NPC character = ___character as NPC;
                    if (__instance.location is FarmHouse)
                    {
                        warp = new Warp(warp.X, warp.Y, "BusStop", 0, 23, false);
                    }

                    if (__instance.location is BusStop && warp.X <= 0)
                    {
                        warp = new Warp(warp.X, warp.Y, character.getHome().Name, (character.getHome() as FarmHouse).getEntryLocation().X, (character.getHome() as FarmHouse).getEntryLocation().Y, false);
                    }
                    if (character.temporaryController != null && character.controller != null)
                    {
                        character.controller.location = Game1.getLocationFromName(warp.TargetName);
                    }
                }

                Game1.warpCharacter(___character as NPC, warp.TargetName, new Vector2((float)warp.TargetX, (float)warp.TargetY));
                if (__instance.isPlayerPresent() && __instance.location.doors.ContainsKey(new Point(warp.X, warp.Y)))
                {
                    __instance.location.playSoundAt("doorClose", new Vector2((float)warp.X, (float)warp.Y));
                }
                __instance.location = Game1.getLocationFromName(warp.TargetName);
                if (__instance.isPlayerPresent() && __instance.location.doors.ContainsKey(new Point(warp.TargetX, warp.TargetY - 1)))
                {
                    __instance.location.playSoundAt("doorClose", new Vector2((float)warp.TargetX, (float)warp.TargetY));
                }
                if (__instance.pathToEndPoint.Count > 0)
                {
                    __instance.pathToEndPoint.Pop();
                }
                while (__instance.pathToEndPoint.Count > 0 && (Math.Abs(__instance.pathToEndPoint.Peek().X - ___character.getTileX()) > 1 || Math.Abs(__instance.pathToEndPoint.Peek().Y - ___character.getTileY()) > 1))
                {
                    __instance.pathToEndPoint.Pop();
                }

                return(false);
            }
        }
        public static bool Prefix(Rectangle position, PathFindController __instance, Character ___character)
        {
            if (!ModEntry.IsChildNPC(___character))
            {
                return(true);
            }

            Warp warp = __instance.location.isCollidingWithWarpOrDoor(position);

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

            if (warp.TargetName == "Trailer" && Game1.MasterPlayer.mailReceived.Contains("pamHouseUpgrade"))
            {
                warp = new Warp(warp.X, warp.Y, "Trailer_Big", 13, 24, false);
            }

            //This is normally only for married NPCs
            if (___character is NPC && (___character as NPC).followSchedule)
            {
                NPC character = ___character as NPC;
                if (__instance.location is FarmHouse)
                {
                    warp = new Warp(warp.X, warp.Y, "BusStop", 0, 23, false);
                }
                if (__instance.location is BusStop && warp.X <= 0)
                {
                    warp = new Warp(warp.X, warp.Y, character.getHome().Name, (character.getHome() as FarmHouse).getEntryLocation().X, (character.getHome() as FarmHouse).getEntryLocation().Y, false);
                }
                if (character.temporaryController != null && character.controller != null)
                {
                    character.controller.location = Game1.getLocationFromName(warp.TargetName);
                }
            }

            __instance.location = Game1.getLocationFromName(warp.TargetName);
            //This is normally only for married NPCs
            if (___character is NPC && (warp.TargetName == "FarmHouse" || warp.TargetName == "Cabin"))
            {
                __instance.location = Utility.getHomeOfFarmer(Game1.getFarmer(ModEntry.GetFarmerParentId(___character)));
                warp = new Warp(warp.X, warp.Y, __instance.location.Name, (__instance.location as FarmHouse).getEntryLocation().X, (__instance.location as FarmHouse).getEntryLocation().Y, false);
                if ((___character as NPC).temporaryController != null && (___character as NPC).controller != null)
                {
                    (___character as NPC).controller.location = __instance.location;
                }
            }
            Game1.warpCharacter(___character as NPC, __instance.location, new Vector2(warp.TargetX, warp.TargetY));

            if (__instance.isPlayerPresent() && __instance.location.doors.ContainsKey(new Point(warp.X, warp.Y)))
            {
                __instance.location.playSoundAt("doorClose", new Vector2(warp.X, warp.Y), NetAudio.SoundContext.NPC);
            }
            if (__instance.isPlayerPresent() && __instance.location.doors.ContainsKey(new Point(warp.TargetX, warp.TargetY - 1)))
            {
                __instance.location.playSoundAt("doorClose", new Vector2(warp.TargetX, warp.TargetY), NetAudio.SoundContext.NPC);
            }
            if (__instance.pathToEndPoint.Count > 0)
            {
                __instance.pathToEndPoint.Pop();
            }
            while (__instance.pathToEndPoint.Count > 0 && (Math.Abs(__instance.pathToEndPoint.Peek().X - ___character.getTileX()) > 1 || Math.Abs(__instance.pathToEndPoint.Peek().Y - ___character.getTileY()) > 1))
            {
                __instance.pathToEndPoint.Pop();
            }

            return(false);
        }