Пример #1
0
 // Token: 0x06000BF2 RID: 3058 RVA: 0x000ED984 File Offset: 0x000EBB84
 public override void update(GameTime time, GameLocation location)
 {
     if (!location.Equals(Game1.currentLocation))
     {
         return;
     }
     if (!Game1.player.isRafting || !base.withinPlayerThreshold(4))
     {
         base.updateGlow();
         base.updateEmote(time);
         if (this.controller == null)
         {
             this.updateMovement(location, time);
         }
         if (this.controller != null && this.controller.update(time))
         {
             this.controller = null;
         }
     }
     this.behaviorAtGameTick(time);
     if (this.position.X < 0f || this.position.X > (float)(location.map.GetLayer("Back").LayerWidth *Game1.tileSize) || this.position.Y < 0f || this.position.Y > (float)(location.map.GetLayer("Back").LayerHeight *Game1.tileSize))
     {
         location.characters.Remove(this);
     }
 }
        public static bool Eat_Prefix(FarmAnimal __instance, GameLocation location)
        {
            Vector2 tilePosition = new Vector2(__instance.GetBoundingBox().Center.X / 64, __instance.GetBoundingBox().Center.Y / 64);

            __instance.isEating.Value = true;
            int weedsToEat      = __instance.isCoopDweller() ? 2 : 4;
            int fullnessPerWeed = (byte.MaxValue + 1) / weedsToEat;
            int weedsEaten      = weedsToEat;

            if (location.terrainFeatures.ContainsKey(tilePosition) && location.terrainFeatures[tilePosition] is Grass grass && grass.numberOfWeeds.Value > 0)
            {
                if (ModEntry.config.fixAnimalsEating)
                {
                    weedsToEat = (byte.MaxValue + 1 - __instance.fullness.Value) / fullnessPerWeed;
                    weedsEaten = Math.Min(grass.numberOfWeeds.Value, weedsToEat);
                }

                if (grass.reduceBy(weedsEaten, tilePosition, location.Equals(Game1.currentLocation)))
                {
                    location.terrainFeatures.Remove(tilePosition);
                }
            }
            __instance.Sprite.loop    = false;
            __instance.fullness.Value = (weedsEaten == weedsToEat) ? byte.MaxValue : (byte)(__instance.fullness.Value + (weedsEaten * fullnessPerWeed));

            if (__instance.fullness.Value >= byte.MaxValue && __instance.moodMessage.Value != 5 && __instance.moodMessage.Value != 6 && !Game1.isRaining)
            {
                __instance.happiness.Value = byte.MaxValue;
                __instance.friendshipTowardFarmer.Value = Math.Min(1000, __instance.friendshipTowardFarmer.Value + 8);
            }

            return(false);
        }
Пример #3
0
 public override void update(GameTime time, GameLocation location)
 {
     if (!location.Equals((object)Game1.currentLocation))
     {
         return;
     }
     if (!Game1.player.isRafting || !this.withinPlayerThreshold(4))
     {
         this.updateGlow();
         this.updateEmote(time);
         if (this.controller == null)
         {
             this.updateMovement(location, time);
         }
         if (this.controller != null && this.controller.update(time))
         {
             this.controller = (PathFindController)null;
         }
     }
     this.behaviorAtGameTick(time);
     if ((double)this.position.X >= 0.0 && (double)this.position.X <= (double)(location.map.GetLayer("Back").LayerWidth *Game1.tileSize) && ((double)this.position.Y >= 0.0 && (double)this.position.Y <= (double)(location.map.GetLayer("Back").LayerHeight *Game1.tileSize)))
     {
         return;
     }
     location.characters.Remove((NPC)this);
 }
Пример #4
0
 // Token: 0x06000C54 RID: 3156 RVA: 0x000F43F4 File Offset: 0x000F25F4
 public override void update(GameTime time, GameLocation location)
 {
     if (this.invincibleCountdown > 0)
     {
         this.invincibleCountdown -= time.ElapsedGameTime.Milliseconds;
         if (this.invincibleCountdown <= 0)
         {
             base.stopGlowing();
         }
     }
     if (!location.Equals(Game1.currentLocation))
     {
         return;
     }
     if (!Game1.player.isRafting || !base.withinPlayerThreshold(4))
     {
         base.update(time, location);
     }
     this.behaviorAtGameTick(time);
     if (this.controller != null && base.withinPlayerThreshold(3))
     {
         this.controller = null;
     }
     if (!this.isGlider && (this.position.X < 0f || this.position.X > (float)(location.map.GetLayer("Back").LayerWidth *Game1.tileSize) || this.position.Y < 0f || this.position.Y > (float)(location.map.GetLayer("Back").LayerHeight *Game1.tileSize)))
     {
         location.characters.Remove(this);
         return;
     }
     if (this.isGlider && this.position.X < -2000f)
     {
         this.health = -500;
     }
 }
Пример #5
0
 public bool Update(GameTime time, GameLocation location)
 {
     if (Game1.IsMasterGame)
     {
         position.X += (float)time.ElapsedGameTime.Milliseconds * speed;
     }
     wheelRotation += (float)time.ElapsedGameTime.Milliseconds * ((float)Math.PI / 256f);
     wheelRotation %= (float)Math.PI * 2f;
     if (!Game1.eventUp && location.Equals(Game1.currentLocation))
     {
         Farmer player = Game1.player;
         if (player.GetBoundingBox().Intersects(getBoundingBox()))
         {
             player.xVelocity = 8f;
             player.yVelocity = (float)(getBoundingBox().Center.Y - player.GetBoundingBox().Center.Y) / 4f;
             player.takeDamage(20, overrideParry: true, null);
             if (player.UsingTool)
             {
                 Game1.playSound("clank");
             }
         }
     }
     if (Game1.random.NextDouble() < 0.001 && location.Equals(Game1.currentLocation))
     {
         Game1.playSound("trainWhistle");
         whistleSteam = new TemporaryAnimatedSprite(27, new Vector2(position.X - 250f, 2624f), Color.White, 8, flipped: false, 100f, 0, 64, 1f, 64);
     }
     if (whistleSteam != null)
     {
         whistleSteam.Position = new Vector2(position.X - 258f, 2592f);
         if (whistleSteam.update(time))
         {
             whistleSteam = null;
         }
     }
     smokeTimer -= time.ElapsedGameTime.Milliseconds;
     if (smokeTimer <= 0f)
     {
         location.temporarySprites.Add(new TemporaryAnimatedSprite(25, new Vector2(position.X - 170f, 2496f), Color.White, 8, flipped: false, 100f, 0, 64, 1f, 128));
         smokeTimer = speed * 2000f;
     }
     if (position.X > (float)(cars.Count * 128 * 4 + 4480))
     {
         return(true);
     }
     return(false);
 }
Пример #6
0
 /// <summary>Whether any farmer in a specific game location has a specific profession.</summary>
 /// <param name="professionName">The name of the profession.</param>
 /// <param name="location">The game location to check.</param>
 public static bool AnyPlayerInLocationHasProfession(string professionName, GameLocation location)
 {
     if (!Game1.IsMultiplayer && location.Equals(Game1.currentLocation))
     {
         return(LocalPlayerHasProfession(professionName));
     }
     return(location.farmers.Any(farmer => SpecificPlayerHasProfession(professionName, farmer)));
 }
Пример #7
0
        public virtual void update(GameTime time, GameLocation location, long id, bool move)
        {
            position.UpdateExtrapolation(speed + addedSpeed);
            currentLocation = location;
            faceTowardFarmerEvent.Poll();
            if (yJumpOffset != 0)
            {
                yJumpVelocity += yJumpGravity;
                yJumpOffset   -= (int)yJumpVelocity;
                if (yJumpOffset >= 0)
                {
                    yJumpOffset   = 0;
                    yJumpVelocity = 0f;
                    if (!IsMonster && (location == null || location.Equals(Game1.currentLocation)) && wasJumpWithSound)
                    {
                        checkForFootstep();
                    }
                }
            }
            if (forceUpdateTimer > 0)
            {
                forceUpdateTimer -= time.ElapsedGameTime.Milliseconds;
            }
            updateGlow();
            updateEmote(time);
            updateFaceTowardsFarmer(time, location);
            bool is_event_controlled_character = false;

            if (location.currentEvent != null)
            {
                if (location.isTemp())
                {
                    is_event_controlled_character = true;
                }
                else if (location.currentEvent.actors.Contains(this))
                {
                    is_event_controlled_character = true;
                }
            }
            if (Game1.IsMasterGame | is_event_controlled_character)
            {
                if (controller == null && move && !freezeMotion)
                {
                    updateMovement(location, time);
                }
                if (controller != null && !freezeMotion && controller.update(time))
                {
                    controller = null;
                }
            }
            else
            {
                updateSlaveAnimation(time);
            }
            hasJustStartedFacingPlayer = false;
        }
Пример #8
0
 public static bool GetClosestAnimal(Vector2 positionTile, int acceptableDistanceFromScreenNonTile, GameLocation location = null)
 {
     if (location != null && !location.Equals(Game1.currentLocation))
     {
         return(false);
     }
     if (positionTile.X * 64 > Game1.viewport.X - acceptableDistanceFromScreenNonTile && positionTile.X * 64 < Game1.viewport.X + Game1.viewport.Width + acceptableDistanceFromScreenNonTile && positionTile.Y * 64 > Game1.viewport.Y - acceptableDistanceFromScreenNonTile)
     {
         return(positionTile.Y * 64 < Game1.viewport.Y + Game1.viewport.Height + acceptableDistanceFromScreenNonTile);
     }
     return(false);
 }
Пример #9
0
 // Token: 0x06000BC8 RID: 3016 RVA: 0x000EB20C File Offset: 0x000E940C
 public override void update(GameTime time, GameLocation location)
 {
     if (!location.Equals(Game1.currentLocation))
     {
         return;
     }
     if ((this.health > 8 || (this.hard && this.health >= this.maxHealth)) && !this.pupating)
     {
         base.update(time, location);
         return;
     }
     this.behaviorAtGameTick(time);
 }
Пример #10
0
 // Token: 0x06000C16 RID: 3094 RVA: 0x000EF4F4 File Offset: 0x000ED6F4
 public override void update(GameTime time, GameLocation location)
 {
     if (!location.Equals(Game1.currentLocation))
     {
         return;
     }
     if (!this.shellGone && !Game1.player.isRafting)
     {
         base.update(time, location);
         return;
     }
     if (!Game1.player.isRafting)
     {
         this.behaviorAtGameTick(time);
     }
 }
Пример #11
0
 public bool Update(GameTime time, GameLocation location)
 {
     this.position      = this.position + (float)time.ElapsedGameTime.Milliseconds * this.speed;
     this.wheelRotation = this.wheelRotation + (float)time.ElapsedGameTime.Milliseconds * ((float)Math.PI / 256f);
     this.wheelRotation = this.wheelRotation % 6.283185f;
     foreach (Farmer farmer1 in location.getFarmers())
     {
         Rectangle boundingBox = farmer1.GetBoundingBox();
         if (boundingBox.Intersects(this.getBoundingBox()))
         {
             farmer1.xVelocity = 8f;
             Farmer farmer2 = farmer1;
             boundingBox = this.getBoundingBox();
             int y1 = boundingBox.Center.Y;
             boundingBox = farmer1.GetBoundingBox();
             int    y2  = boundingBox.Center.Y;
             double num = (double)(y1 - y2) / 4.0;
             farmer2.yVelocity = (float)num;
             Game1.farmerTakeDamage(20, true, (Monster)null);
             if (farmer1.usingTool)
             {
                 Game1.playSound("clank");
             }
         }
     }
     if (Game1.random.NextDouble() < 0.001 && location.Equals((object)Game1.currentLocation))
     {
         Game1.playSound("trainWhistle");
         this.whistleSteam = new TemporaryAnimatedSprite(27, new Vector2(this.position - 250f, (float)(45 * Game1.tileSize - Game1.tileSize * 4)), Color.White, 8, false, 100f, 0, Game1.tileSize, 1f, Game1.tileSize, 0);
     }
     if (this.whistleSteam != null)
     {
         this.whistleSteam.Position = new Vector2(this.position - 258f, (float)(45 * Game1.tileSize - Game1.tileSize * 4 - 32));
         if (this.whistleSteam.update(time))
         {
             this.whistleSteam = (TemporaryAnimatedSprite)null;
         }
     }
     this.smokeTimer = this.smokeTimer - (float)time.ElapsedGameTime.Milliseconds;
     if ((double)this.smokeTimer <= 0.0)
     {
         location.temporarySprites.Add(new TemporaryAnimatedSprite(25, new Vector2(this.position - 170f, (float)(45 * Game1.tileSize - Game1.tileSize * 6)), Color.White, 8, false, 100f, 0, Game1.tileSize, 1f, Game1.tileSize * 2, 0));
         this.smokeTimer = this.speed * 2000f;
     }
     return((double)this.position > (double)(this.cars.Count * 128 * 4 + 70 * Game1.tileSize));
 }
Пример #12
0
        public override void update(GameTime time, GameLocation location)
        {
            base.update(time, location);

            if (!location.Equals(Game1.currentLocation))
            {
                Console.WriteLine($"Warping to path controller location: {Game1.currentLocation.Name}");
                Game1.warpCharacter(this, Game1.currentLocation.name, FindRandomPointAround(Game1.player.getTileLocationPoint()), false, this.currentLocation?.isOutdoors == true);
                this.controller = null; // reset
                if (Game1.currentLocation is FarmHouse)
                {
                    this.setTilePosition((this.currentLocation as FarmHouse).getEntryLocation());
                }
                //this.currentLocation = Game1.currentLocation;
                //warpToPathControllerDestination();
                return;
            }

            // Find a target if we don't have one or out current one is dead.
            if (this.CurrentEnemy == null || this.CurrentEnemy.health <= 0f)
            {
                // Choose the closest enemy or the player if there isn't one.
                this.CurrentTarget = GetClosestEnemy() ?? Game1.player as Character;
            }

            // Prevent our speed from being reset.
            this.speed = Game1.player.speed;

            if (this.CurrentTarget != null)
            {
                if (TooFarFromTarget())
                {
                    MoveTowardsTarget(time);
                }

                // Deal damage each damage tick.
                if (HasEnoughTimeElapsedMS(time, this.LastTimeDamageDealt, this.DamageTick))
                {
                    if (DamageIntersectingEnemies())
                    {
                        this.LastTimeDamageDealt = time.TotalGameTime;
                        Console.WriteLine("Dealt damage");
                    }
                }
            }
        }
Пример #13
0
 public override void update(GameTime time, GameLocation location)
 {
     if (this.invincibleCountdown > 0)
     {
         this.glowingColor        = Color.Cyan;
         this.invincibleCountdown = this.invincibleCountdown - time.ElapsedGameTime.Milliseconds;
         if (this.invincibleCountdown <= 0)
         {
             this.stopGlowing();
         }
     }
     if (!location.Equals((object)Game1.currentLocation))
     {
         return;
     }
     this.behaviorAtGameTick(time);
     if ((double)this.position.X < 0.0 || (double)this.position.X > (double)(location.map.GetLayer("Back").LayerWidth *Game1.tileSize) || ((double)this.position.Y < 0.0 || (double)this.position.Y > (double)(location.map.GetLayer("Back").LayerHeight *Game1.tileSize)))
     {
         location.characters.Remove((NPC)this);
     }
     this.updateGlow();
 }
Пример #14
0
 public bool Update(GameTime time, GameLocation location)
 {
     this.position      += (float)time.ElapsedGameTime.Milliseconds * this.speed;
     this.wheelRotation += (float)time.ElapsedGameTime.Milliseconds * 0.0122718466f;
     this.wheelRotation %= 6.28318548f;
     foreach (Farmer current in location.getFarmers())
     {
         if (current.GetBoundingBox().Intersects(this.getBoundingBox()))
         {
             current.xVelocity = 8f;
             current.yVelocity = (float)(this.getBoundingBox().Center.Y - current.GetBoundingBox().Center.Y) / 4f;
             Game1.farmerTakeDamage(20, true, null);
             if (current.usingTool)
             {
                 Game1.playSound("clank");
             }
         }
     }
     if (Game1.random.NextDouble() < 0.001 && location.Equals(Game1.currentLocation))
     {
         Game1.playSound("trainWhistle");
         this.whistleSteam = new TemporaryAnimatedSprite(27, new Vector2(this.position - 250f, (float)(45 * Game1.tileSize - Game1.tileSize * 4)), Color.White, 8, false, 100f, 0, Game1.tileSize, 1f, Game1.tileSize, 0);
     }
     if (this.whistleSteam != null)
     {
         this.whistleSteam.Position = new Vector2(this.position - 258f, (float)(45 * Game1.tileSize - Game1.tileSize * 4 - 32));
         if (this.whistleSteam.update(time))
         {
             this.whistleSteam = null;
         }
     }
     this.smokeTimer -= (float)time.ElapsedGameTime.Milliseconds;
     if (this.smokeTimer <= 0f)
     {
         location.temporarySprites.Add(new TemporaryAnimatedSprite(25, new Vector2(this.position - 170f, (float)(45 * Game1.tileSize - Game1.tileSize * 6)), Color.White, 8, false, 100f, 0, Game1.tileSize, 1f, Game1.tileSize * 2, 0));
         this.smokeTimer = this.speed * 2000f;
     }
     return(this.position > (float)(this.cars.Count * 128 * 4 + 70 * Game1.tileSize));
 }
Пример #15
0
 public override void update(GameTime time, GameLocation location)
 {
     if (this.invincibleCountdown > 0)
     {
         this.invincibleCountdown = this.invincibleCountdown - time.ElapsedGameTime.Milliseconds;
         if (this.invincibleCountdown <= 0)
         {
             this.stopGlowing();
         }
     }
     if (!location.Equals((object)Game1.currentLocation))
     {
         return;
     }
     if (!Game1.player.isRafting || !this.withinPlayerThreshold(4))
     {
         base.update(time, location);
     }
     this.behaviorAtGameTick(time);
     if (this.controller != null && this.withinPlayerThreshold(3))
     {
         this.controller = (PathFindController)null;
     }
     if (!this.isGlider && ((double)this.position.X < 0.0 || (double)this.position.X > (double)(location.map.GetLayer("Back").LayerWidth *Game1.tileSize) || ((double)this.position.Y < 0.0 || (double)this.position.Y > (double)(location.map.GetLayer("Back").LayerHeight *Game1.tileSize))))
     {
         location.characters.Remove((NPC)this);
     }
     else
     {
         if (!this.isGlider || (double)this.position.X >= -2000.0)
         {
             return;
         }
         this.health = -500;
     }
 }
Пример #16
0
        public override bool performToolAction(Tool t, int explosion, Vector2 tileLocation, GameLocation location = null)
        {
            if (location == null)
            {
                location = Game1.currentLocation;
            }
            if (explosion > 0)
            {
                this.tapped = false;
            }
            if (this.tapped)
            {
                return(false);
            }
            Console.WriteLine(string.Concat(new object[]
            {
                "TREE: IsClient:",
                Game1.IsClient.ToString(),
                " randomOutput: ",
                Game1.recentMultiplayerRandom.Next(9999)
            }));
            if (this.health <= -99f)
            {
                return(false);
            }
            if (this.growthStage >= 5)
            {
                if (t != null && t is Axe)
                {
                    Game1.playSound("axchop");
                    location.debris.Add(new Debris(12, Game1.random.Next(1, 3), t.getLastFarmerToUse().GetToolLocation(false) + new Vector2((float)(Game1.tileSize / 4), 0f), t.getLastFarmerToUse().position, 0, -1));
                    this.lastPlayerToHit = t.getLastFarmerToUse().uniqueMultiplayerID;
                }
                else if (explosion <= 0)
                {
                    return(false);
                }
                this.shake(tileLocation, true);
                float num = 1f;
                if (explosion > 0)
                {
                    num = (float)explosion;
                }
                else
                {
                    if (t == null)
                    {
                        return(false);
                    }
                    switch (t.upgradeLevel)
                    {
                    case 0:
                        num = 1f;
                        break;

                    case 1:
                        num = 1.25f;
                        break;

                    case 2:
                        num = 1.67f;
                        break;

                    case 3:
                        num = 2.5f;
                        break;

                    case 4:
                        num = 5f;
                        break;
                    }
                }
                this.health -= num;
                if (this.health <= 0f)
                {
                    if (!this.stump)
                    {
                        if ((t != null || explosion > 0) && location.Equals(Game1.currentLocation))
                        {
                            Game1.playSound("treecrack");
                        }
                        this.stump   = true;
                        this.health  = 5f;
                        this.falling = true;
                        if (t != null)
                        {
                            t.getLastFarmerToUse().gainExperience(2, 12);
                        }
                        if (t == null || t.getLastFarmerToUse() == null)
                        {
                            this.shakeLeft = true;
                        }
                        else
                        {
                            this.shakeLeft = (t.getLastFarmerToUse().getTileLocation().X > tileLocation.X || (t.getLastFarmerToUse().getTileLocation().Y < tileLocation.Y && tileLocation.X % 2f == 0f));
                        }
                    }
                    else
                    {
                        this.health = -100f;
                        Game1.createRadialDebris(location, 12, (int)tileLocation.X, (int)tileLocation.Y, Game1.random.Next(30, 40), false, -1, false, -1);
                        int index = (this.treeType == 7 && tileLocation.X % 7f == 0f) ? 422 : ((this.treeType == 7) ? 420 : 92);
                        if (Game1.IsMultiplayer)
                        {
                            Game1.recentMultiplayerRandom = new Random((int)tileLocation.X * 2000 + (int)tileLocation.Y);
                            Random arg_2D6_0 = Game1.recentMultiplayerRandom;
                        }
                        else
                        {
                            new Random((int)Game1.uniqueIDForThisGame + (int)Game1.stats.DaysPlayed + (int)tileLocation.X * 7 + (int)tileLocation.Y * 11);
                        }
                        if (t == null || t.getLastFarmerToUse() == null)
                        {
                            if (location.Equals(Game1.currentLocation))
                            {
                                Game1.createMultipleObjectDebris(92, (int)tileLocation.X, (int)tileLocation.Y, 2);
                            }
                            else
                            {
                                Game1.createItemDebris(new StardewValley.Object(92, 1, false, -1, 0), tileLocation * (float)Game1.tileSize, 2, location);
                                Game1.createItemDebris(new StardewValley.Object(92, 1, false, -1, 0), tileLocation * (float)Game1.tileSize, 2, location);
                            }
                        }
                        else if (Game1.IsMultiplayer)
                        {
                            Game1.createMultipleObjectDebris(index, (int)tileLocation.X, (int)tileLocation.Y, 1, this.lastPlayerToHit);
                            if (this.treeType != 7)
                            {
                                Game1.createRadialDebris(location, 12, (int)tileLocation.X, (int)tileLocation.Y, 4, true, -1, false, -1);
                            }
                        }
                        else
                        {
                            if (this.treeType != 7)
                            {
                                Game1.createRadialDebris(location, 12, (int)tileLocation.X, (int)tileLocation.Y, 5 + this.extraWoodCalculator(tileLocation), true, -1, false, -1);
                            }
                            Game1.createMultipleObjectDebris(index, (int)tileLocation.X, (int)tileLocation.Y, 1);
                        }
                        if (location.Equals(Game1.currentLocation))
                        {
                            Game1.playSound("treethud");
                        }
                        if (!this.falling)
                        {
                            return(true);
                        }
                    }
                }
            }
            else if (this.growthStage >= 3)
            {
                if (t != null && t.name.Contains("Ax"))
                {
                    Game1.playSound("axchop");
                    if (this.treeType != 7)
                    {
                        Game1.playSound("leafrustle");
                    }
                    location.debris.Add(new Debris(12, Game1.random.Next(t.upgradeLevel * 2, t.upgradeLevel * 4), t.getLastFarmerToUse().GetToolLocation(false) + new Vector2((float)(Game1.tileSize / 4), 0f), new Vector2((float)t.getLastFarmerToUse().GetBoundingBox().Center.X, (float)t.getLastFarmerToUse().GetBoundingBox().Center.Y), 0, -1));
                }
                else if (explosion <= 0)
                {
                    return(false);
                }
                this.shake(tileLocation, true);
                float num2 = 1f;
                if (Game1.IsMultiplayer)
                {
                    Random arg_51E_0 = Game1.recentMultiplayerRandom;
                }
                else
                {
                    new Random((int)(Game1.uniqueIDForThisGame + tileLocation.X * 7f + tileLocation.Y * 11f + Game1.stats.DaysPlayed + this.health));
                }
                if (explosion > 0)
                {
                    num2 = (float)explosion;
                }
                else
                {
                    switch (t.upgradeLevel)
                    {
                    case 0:
                        num2 = 2f;
                        break;

                    case 1:
                        num2 = 2.5f;
                        break;

                    case 2:
                        num2 = 3.34f;
                        break;

                    case 3:
                        num2 = 5f;
                        break;

                    case 4:
                        num2 = 10f;
                        break;
                    }
                }
                this.health -= num2;
                if (this.health <= 0f)
                {
                    Game1.createDebris(12, (int)tileLocation.X, (int)tileLocation.Y, 4, null);
                    Game1.createRadialDebris(location, 12, (int)tileLocation.X, (int)tileLocation.Y, Game1.random.Next(20, 30), false, -1, false, -1);
                    return(true);
                }
            }
            else if (this.growthStage >= 1)
            {
                if (explosion > 0)
                {
                    return(true);
                }
                if (location.Equals(Game1.currentLocation))
                {
                    Game1.playSound("cut");
                }
                if (t != null && t.name.Contains("Axe"))
                {
                    Game1.playSound("axchop");
                    Game1.createRadialDebris(location, 12, (int)tileLocation.X, (int)tileLocation.Y, Game1.random.Next(10, 20), false, -1, false, -1);
                }
                if (t is Axe || t is Pickaxe || t is Hoe || t is MeleeWeapon)
                {
                    Game1.createRadialDebris(location, 12, (int)tileLocation.X, (int)tileLocation.Y, Game1.random.Next(10, 20), false, -1, false, -1);
                    if (t.name.Contains("Axe") && Game1.recentMultiplayerRandom.NextDouble() < (double)((float)t.getLastFarmerToUse().ForagingLevel / 10f))
                    {
                        Game1.createDebris(12, (int)tileLocation.X, (int)tileLocation.Y, 1, null);
                    }
                    location.temporarySprites.Add(new TemporaryAnimatedSprite(17, tileLocation * (float)Game1.tileSize, Color.White, 8, false, 100f, 0, -1, -1f, -1, 0));
                    return(true);
                }
            }
            else
            {
                if (explosion > 0)
                {
                    return(true);
                }
                if (t.name.Contains("Axe") || t.name.Contains("Pick") || t.name.Contains("Hoe"))
                {
                    Game1.playSound("woodyHit");
                    Game1.playSound("axchop");
                    location.temporarySprites.Add(new TemporaryAnimatedSprite(17, tileLocation * (float)Game1.tileSize, Color.White, 8, false, 100f, 0, -1, -1f, -1, 0));
                    if (this.lastPlayerToHit != 0L && Game1.getFarmer(this.lastPlayerToHit).getEffectiveSkillLevel(2) >= 1)
                    {
                        Game1.createMultipleObjectDebris(308 + this.treeType, (int)tileLocation.X, (int)tileLocation.Y, 1, t.getLastFarmerToUse().uniqueMultiplayerID, location);
                    }
                    else if (!Game1.IsMultiplayer && Game1.player.getEffectiveSkillLevel(2) >= 1)
                    {
                        Game1.createMultipleObjectDebris(308 + this.treeType, (int)tileLocation.X, (int)tileLocation.Y, 1, t.getLastFarmerToUse().uniqueMultiplayerID, location);
                    }
                    return(true);
                }
            }
            return(false);
        }
Пример #17
0
        public static void SpawnJunimoAtPosition(GameLocation location, Vector2 pos, JunimoHut hut, int junimoNumber)
        {
            if (hut == null)
            {
                // BetterJunimos.SMonitor.Log($"SpawnJunimoAtPosition: hut is null", LogLevel.Warn);
                return;
            }

            /*
             * Added by Mizzion. This will set the color of the junimos based on what gem is inside the hut.
             */
            var isPrismatic = false;
            var gemColor    = GetGemColor(ref isPrismatic, hut);

            /*
             * End added By Mizzion
             */

            // BetterJunimos.SMonitor.Log($"SpawnJunimoAtPosition: spawning #{junimoNumber} in {location.Name} at [{pos.X} {pos.Y}]", LogLevel.Debug);

            var junimoHarvester = new JunimoHarvester(pos, hut, junimoNumber, gemColor);

            // the JunimoHarvester constructor sets the location to Farm and calls pathfindToRandomSpotAroundHut immediately
            // so we have to set the location explicitly then re-do pathfinding
            if (!location.Equals(Game1.getFarm()))
            {
                // BetterJunimos.SMonitor.Log($"SpawnJunimoAtPosition: forcing #{junimoNumber} to {location.Name} at [{pos.X} {pos.Y}]", LogLevel.Trace);

                Reflection.GetField <bool>(junimoHarvester, "destroy").SetValue(false);
                junimoHarvester.currentLocation = location;
                junimoHarvester.Position        = pos;
                junimoHarvester.pathfindToRandomSpotAroundHut();
            }


            // BetterJunimos.SMonitor.Log($"SpawnJunimoAtPosition: spawned #{junimoNumber} " +
            //                            $"in {junimoHarvester.currentLocation.Name} " +
            //                            $"at [{junimoHarvester.getTileX()} {junimoHarvester.getTileX()}]", LogLevel.Debug);

            junimoHarvester.isPrismatic.Value = isPrismatic; //Added by Mizzion, Fixes the Prismatic Junimos.
            location.characters.Add(junimoHarvester);
            hut.myJunimos.Add(junimoHarvester);

            if (Game1.isRaining)
            {
                var alpha = Reflection.GetField <float>(junimoHarvester, "alpha");
                alpha.SetValue(BetterJunimos.Config.FunChanges.RainyJunimoSpiritFactor);
            }

            // var destroy = Reflection.GetField<bool>(junimoHarvester, "destroy").GetValue();
            // var onscreen = Utility.isOnScreen(Utility.Vector2ToPoint(pos), 64, location);
            //
            // BetterJunimos.SMonitor.Log($"SpawnJunimoAtPosition: #{junimoNumber} general situation " +
            //                            $"destroy: {destroy} " +
            //                            $"isOnScreen: {onscreen} " +
            //                            $"controller: {junimoHarvester.controller is not null} " +
            //                            $"pathToEndPoint: {junimoHarvester.controller?.pathToEndPoint is not null} " +
            //                            $"at [{junimoHarvester.getTileX()} {junimoHarvester.getTileX()}]", LogLevel.Debug);

            if (!Utility.isOnScreen(Utility.Vector2ToPoint(pos), 64, location))
            {
                return;
            }
            location.playSound("junimoMeep1");
        }
Пример #18
0
        /// <summary>The method to call before <see cref="FarmAnimal.behaviors"/>.</summary>
        public static bool Before_Behaviors(FarmAnimal __instance, GameTime time, GameLocation location, ref bool __result)
        {
            if (__instance.home == null)
            {
                __result = false;
                return(false);
            }
            if (__instance.isEating.Value)
            {
                if (__instance.home != null && __instance.home.getRectForAnimalDoor().Intersects(__instance.GetBoundingBox()))
                {
                    FarmAnimal.behaviorAfterFindingGrassPatch(__instance, location);
                    __instance.isEating.Value = false;
                    __instance.Halt();
                    __result = false;
                    return(false);
                }
                if (__instance.buildingTypeILiveIn.Contains("Barn"))
                {
                    __instance.Sprite.Animate(time, 16, 4, 100f);
                    if (__instance.Sprite.currentFrame >= 20)
                    {
                        __instance.isEating.Value      = false;
                        __instance.Sprite.loop         = true;
                        __instance.Sprite.currentFrame = 0;
                        __instance.faceDirection(2);
                    }
                }
                else
                {
                    __instance.Sprite.Animate(time, 24, 4, 100f);
                    if (__instance.Sprite.currentFrame >= 28)
                    {
                        __instance.isEating.Value      = false;
                        __instance.Sprite.loop         = true;
                        __instance.Sprite.currentFrame = 0;
                        __instance.faceDirection(2);
                    }
                }
                __result = true;
                return(false);
            }
            if (!Game1.IsClient)
            {
                if (__instance.controller != null)
                {
                    __result = true;
                    return(false);
                }
                if (location.IsOutdoors && __instance.fullness.Value < 195 && (Game1.random.NextDouble() < 0.002 && FarmAnimal.NumPathfindingThisTick < FarmAnimal.MaxPathfindingPerTick))
                {
                    ++FarmAnimal.NumPathfindingThisTick;
                    __instance.controller = new PathFindController(__instance, location, FarmAnimal.grassEndPointFunction, -1, false, FarmAnimal.behaviorAfterFindingGrassPatch, 200, Point.Zero);
                }
                if (Game1.timeOfDay >= 1700 && location.IsOutdoors && (__instance.controller == null && Game1.random.NextDouble() < 0.002))
                {
                    if (location.farmers.Count == 0)
                    {
                        (location as Farm).animals.Remove(__instance.myID.Value);
                        (__instance.home.indoors.Value as AnimalHouse).animals.Add(__instance.myID.Value, __instance);
                        __instance.setRandomPosition(__instance.home.indoors.Value);
                        __instance.faceDirection(Game1.random.Next(4));
                        __instance.controller = null;
                        __result = true;
                        return(false);
                    }
                    if (FarmAnimal.NumPathfindingThisTick < FarmAnimal.MaxPathfindingPerTick)
                    {
                        ++FarmAnimal.NumPathfindingThisTick;
                        __instance.controller = new PathFindController(__instance, location, PathFindController.isAtEndPoint, 0, false, null, 200, new Point(__instance.home.tileX.Value + __instance.home.animalDoor.X, __instance.home.tileY.Value + __instance.home.animalDoor.Y));
                    }
                }
                if (location.IsOutdoors && !Game1.isRaining && (!Game1.currentSeason.Equals("winter") && __instance.currentProduce.Value != -1) && (__instance.age.Value >= __instance.ageWhenMature.Value && __instance.type.Value.Contains("Pig") && Game1.random.NextDouble() < 0.0002))
                {
                    Rectangle boundingBox = __instance.GetBoundingBox();
                    for (int corner = 0; corner < 4; ++corner)
                    {
                        Vector2 cornersOfThisRectangle = Utility.getCornersOfThisRectangle(ref boundingBox, corner);
                        Vector2 key = new Vector2((int)(cornersOfThisRectangle.X / 64.0), (int)(cornersOfThisRectangle.Y / 64.0));
                        if (location.terrainFeatures.ContainsKey(key) || location.objects.ContainsKey(key))
                        {
                            __result = false;
                            return(false);
                        }
                    }
                    if (Game1.player.currentLocation.Equals(location))
                    {
                        DelayedAction.playSoundAfterDelay("dirtyHit", 450);
                        DelayedAction.playSoundAfterDelay("dirtyHit", 900);
                        DelayedAction.playSoundAfterDelay("dirtyHit", 1350);
                    }
                    if (location.Equals(Game1.currentLocation))
                    {
                        var findTruffleDelegate = (AnimatedSprite.endOfAnimationBehavior)Delegate.CreateDelegate(typeof(AnimatedSprite.endOfAnimationBehavior), Mod.Instance.Helper.Reflection.GetMethod(__instance, "findTruffle").MethodInfo);

                        switch (__instance.FacingDirection)
                        {
                        case 0:
                            __instance.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>
                            {
                                new(9, 250),
                                new(11, 250),
                                new(9, 250),
                                new(11, 250),
                                new(9, 250),
                                new(11, 250, false, false, findTruffleDelegate)
                            });
                            break;
Пример #19
0
        public static bool Prefix(FarmAnimal __instance, GameTime time, GameLocation location, ref bool __result)
        {
            NetBool isEating = Mod.instance.Helper.Reflection.GetField <NetBool>(__instance, "isEating").GetValue();

            if (__instance.home == null)
            {
                __result = false;
                return(false);
            }
            if (( bool )(NetFieldBase <bool, NetBool>)isEating)
            {
                if (__instance.home != null && __instance.home.getRectForAnimalDoor().Intersects(__instance.GetBoundingBox()))
                {
                    FarmAnimal.behaviorAfterFindingGrassPatch(( Character )__instance, location);
                    isEating.Value = false;
                    __instance.Halt();
                    __result = false;
                    return(false);
                }
                if (__instance.buildingTypeILiveIn.Contains("Barn"))
                {
                    __instance.Sprite.Animate(time, 16, 4, 100f);
                    if (__instance.Sprite.currentFrame >= 20)
                    {
                        isEating.Value                 = false;
                        __instance.Sprite.loop         = true;
                        __instance.Sprite.currentFrame = 0;
                        __instance.faceDirection(2);
                    }
                }
                else
                {
                    __instance.Sprite.Animate(time, 24, 4, 100f);
                    if (__instance.Sprite.currentFrame >= 28)
                    {
                        isEating.Value                 = false;
                        __instance.Sprite.loop         = true;
                        __instance.Sprite.currentFrame = 0;
                        __instance.faceDirection(2);
                    }
                }
                __result = true;
                return(false);
            }
            if (!Game1.IsClient)
            {
                if (__instance.controller != null)
                {
                    __result = true;
                    return(false);
                }
                if (location.IsOutdoors && ( byte )(NetFieldBase <byte, NetByte>)__instance.fullness < ( byte )195 && (Game1.random.NextDouble() < 0.002 && FarmAnimal.NumPathfindingThisTick < FarmAnimal.MaxPathfindingPerTick))
                {
                    ++FarmAnimal.NumPathfindingThisTick;
                    __instance.controller = new PathFindController(( Character )__instance, location, new PathFindController.isAtEnd(FarmAnimal.grassEndPointFunction), -1, false, new PathFindController.endBehavior(FarmAnimal.behaviorAfterFindingGrassPatch), 200, Point.Zero, true);
                }
                if (Game1.timeOfDay >= 1700 && location.IsOutdoors && (__instance.controller == null && Game1.random.NextDouble() < 0.002))
                {
                    if (location.farmers.Count == 0)
                    {
                        (location as Farm).animals.Remove(( long )__instance.myID);
                        (__instance.home.indoors.Value as AnimalHouse).animals.Add(( long )__instance.myID, __instance);
                        __instance.setRandomPosition(( GameLocation )(NetFieldBase <GameLocation, NetRef <GameLocation> >)__instance.home.indoors);
                        __instance.faceDirection(Game1.random.Next(4));
                        __instance.controller = ( PathFindController )null;
                        __result = true;
                        return(false);
                    }
                    if (FarmAnimal.NumPathfindingThisTick < FarmAnimal.MaxPathfindingPerTick)
                    {
                        ++FarmAnimal.NumPathfindingThisTick;
                        __instance.controller = new PathFindController(( Character )__instance, location, new PathFindController.isAtEnd(PathFindController.isAtEndPoint), 0, false, (PathFindController.endBehavior)null, 200, new Point(( int )(NetFieldBase <int, NetInt>)__instance.home.tileX + __instance.home.animalDoor.X, ( int )(NetFieldBase <int, NetInt>)__instance.home.tileY + __instance.home.animalDoor.Y), true);
                    }
                }
                if (location.IsOutdoors && !Game1.isRaining && (!Game1.currentSeason.Equals("winter") && ( int )(NetFieldBase <int, NetInt>)__instance.currentProduce != -1) && (( int )(NetFieldBase <int, NetInt>)__instance.age >= ( int )( byte )(NetFieldBase <byte, NetByte>)__instance.ageWhenMature && __instance.type.Value.Contains("Pig") && Game1.random.NextDouble() < 0.0002))
                {
                    Microsoft.Xna.Framework.Rectangle boundingBox = __instance.GetBoundingBox();
                    for (int corner = 0; corner < 4; ++corner)
                    {
                        Vector2 cornersOfThisRectangle = Utility.getCornersOfThisRectangle(ref boundingBox, corner);
                        Vector2 key = new Vector2((float)(int)((double)cornersOfThisRectangle.X / 64.0), (float)(int)((double)cornersOfThisRectangle.Y / 64.0));
                        if (location.terrainFeatures.ContainsKey(key) || location.objects.ContainsKey(key))
                        {
                            __result = false;
                            return(false);
                        }
                    }
                    if (Game1.player.currentLocation.Equals(location))
                    {
                        DelayedAction.playSoundAfterDelay("dirtyHit", 450, ( GameLocation )null, -1);
                        DelayedAction.playSoundAfterDelay("dirtyHit", 900, ( GameLocation )null, -1);
                        DelayedAction.playSoundAfterDelay("dirtyHit", 1350, ( GameLocation )null, -1);
                    }
                    if (location.Equals(Game1.currentLocation))
                    {
                        var findTruffleDelegate = (AnimatedSprite.endOfAnimationBehavior)Delegate.CreateDelegate(typeof(AnimatedSprite.endOfAnimationBehavior), Mod.instance.Helper.Reflection.GetMethod(__instance, "findTruffle").MethodInfo);

                        switch (__instance.FacingDirection)
                        {
                        case 0:
                            __instance.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                            {
                                new FarmerSprite.AnimationFrame(9, 250),
                                new FarmerSprite.AnimationFrame(11, 250),
                                new FarmerSprite.AnimationFrame(9, 250),
                                new FarmerSprite.AnimationFrame(11, 250),
                                new FarmerSprite.AnimationFrame(9, 250),
                                new FarmerSprite.AnimationFrame(11, 250, false, false, findTruffleDelegate, false)
                            });
                            break;

                        case 1:
                            __instance.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                            {
                                new FarmerSprite.AnimationFrame(5, 250),
                                new FarmerSprite.AnimationFrame(7, 250),
                                new FarmerSprite.AnimationFrame(5, 250),
                                new FarmerSprite.AnimationFrame(7, 250),
                                new FarmerSprite.AnimationFrame(5, 250),
                                new FarmerSprite.AnimationFrame(7, 250, false, false, findTruffleDelegate, false)
                            });
                            break;

                        case 2:
                            __instance.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                            {
                                new FarmerSprite.AnimationFrame(1, 250),
                                new FarmerSprite.AnimationFrame(3, 250),
                                new FarmerSprite.AnimationFrame(1, 250),
                                new FarmerSprite.AnimationFrame(3, 250),
                                new FarmerSprite.AnimationFrame(1, 250),
                                new FarmerSprite.AnimationFrame(3, 250, false, false, findTruffleDelegate, false)
                            });
                            break;

                        case 3:
                            __instance.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                            {
                                new FarmerSprite.AnimationFrame(5, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                                new FarmerSprite.AnimationFrame(7, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                                new FarmerSprite.AnimationFrame(5, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                                new FarmerSprite.AnimationFrame(7, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                                new FarmerSprite.AnimationFrame(5, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                                new FarmerSprite.AnimationFrame(7, 250, false, true, findTruffleDelegate, false)
                            });
                            break;
                        }
                        __instance.Sprite.loop = false;
                    }
                    else
                    {
                        Mod.instance.Helper.Reflection.GetMethod(__instance, "findTruffle").Invoke(Game1.player);
                    }
                }
            }
            __result = false;
            return(false);
        }
Пример #20
0
            private bool behaviors(GameTime time, GameLocation location)
            {
                if (this.home == null)
                {
                    return(false);
                }
                if (this.isEating)
                {
                    if (this.home != null && this.home.getRectForAnimalDoor().Intersects(this.GetBoundingBox()))
                    {
                        FarmAnimal.behaviorAfterFindingGrassPatch((Character)this, location);
                        this.isEating = false;
                        this.Halt();
                        return(false);
                    }
                    if (this.buildingTypeILiveIn.Contains("Barn"))
                    {
                        this.sprite.Animate(time, 16, 4, 100f);
                        if (this.sprite.CurrentFrame >= 20)
                        {
                            this.isEating            = false;
                            this.sprite.loop         = true;
                            this.sprite.CurrentFrame = 0;
                            this.faceDirection(2);
                        }
                    }
                    else
                    {
                        this.sprite.Animate(time, 24, 4, 100f);
                        if (this.sprite.CurrentFrame >= 28)
                        {
                            this.isEating            = false;
                            this.sprite.loop         = true;
                            this.sprite.CurrentFrame = 0;
                            this.faceDirection(2);
                        }
                    }
                    return(true);
                }
                if (!Game1.IsClient)
                {
                    if (this.controller != null)
                    {
                        return(true);
                    }
                    if (location.IsOutdoors && (int)this.fullness < 195 && Game1.random.NextDouble() < 0.002)
                    {
                        this.controller = new PathFindController((Character)this, location, new PathFindController.isAtEnd(FarmAnimal.grassEndPointFunction), -1, false, new PathFindController.endBehavior(FarmAnimal.behaviorAfterFindingGrassPatch), 200, Point.Zero);
                    }
                    if (Game1.timeOfDay >= 1700 && location.IsOutdoors && (this.controller == null && Game1.random.NextDouble() < 0.002))
                    {
                        this.controller = new PathFindController((Character)this, location, new PathFindController.isAtEnd(PathFindController.isAtEndPoint), 0, false, (PathFindController.endBehavior)null, 200, new Point(this.home.tileX + this.home.animalDoor.X, this.home.tileY + this.home.animalDoor.Y));
                        if (location.getFarmersCount() == 0)
                        {
                            ((AnimalHouse)this.home.indoors).animals.Add(this.myID, this);
                            this.setRandomPosition(this.home.indoors);
                            this.faceDirection(Game1.random.Next(4));
                            this.controller = (PathFindController)null;
                            (location as Farm).animals.Remove(this.myID);
                            return(true);
                        }
                    }
                    if (location.IsOutdoors && !Game1.isRaining && (!Game1.currentSeason.Equals("winter") && this.currentProduce != -1) && (this.age >= (int)this.ageWhenMature && this.type.Contains("Pig") && Game1.random.NextDouble() < 0.0002))
                    {
                        Microsoft.Xna.Framework.Rectangle boundingBox = this.GetBoundingBox();
                        for (int corner = 0; corner < 4; ++corner)
                        {
                            Vector2 cornersOfThisRectangle = Utility.getCornersOfThisRectangle(ref boundingBox, corner);
                            Vector2 key = new Vector2((float)(int)((double)cornersOfThisRectangle.X / (double)Game1.tileSize), (float)(int)((double)cornersOfThisRectangle.Y / (double)Game1.tileSize));
                            if (location.terrainFeatures.ContainsKey(key) || location.objects.ContainsKey(key))
                            {
                                return(false);
                            }
                        }
                        if (Game1.player.currentLocation.Equals((object)location))
                        {
                            DelayedAction.playSoundAfterDelay("dirtyHit", 450);
                            DelayedAction.playSoundAfterDelay("dirtyHit", 900);
                            DelayedAction.playSoundAfterDelay("dirtyHit", 1350);
                        }
                        if (location.Equals((object)Game1.currentLocation))
                        {
                            switch (this.FacingDirection)
                            {
                            case 0:
                                this.sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                                {
                                    new FarmerSprite.AnimationFrame(9, 250),
                                    new FarmerSprite.AnimationFrame(11, 250),
                                    new FarmerSprite.AnimationFrame(9, 250),
                                    new FarmerSprite.AnimationFrame(11, 250),
                                    new FarmerSprite.AnimationFrame(9, 250),
                                    new FarmerSprite.AnimationFrame(11, 250, false, false, new AnimatedSprite.endOfAnimationBehavior(this.findTruffle), false)
                                });
                                break;

                            case 1:
                                this.sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                                {
                                    new FarmerSprite.AnimationFrame(5, 250),
                                    new FarmerSprite.AnimationFrame(7, 250),
                                    new FarmerSprite.AnimationFrame(5, 250),
                                    new FarmerSprite.AnimationFrame(7, 250),
                                    new FarmerSprite.AnimationFrame(5, 250),
                                    new FarmerSprite.AnimationFrame(7, 250, false, false, new AnimatedSprite.endOfAnimationBehavior(this.findTruffle), false)
                                });
                                break;

                            case 2:
                                this.sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                                {
                                    new FarmerSprite.AnimationFrame(1, 250),
                                    new FarmerSprite.AnimationFrame(3, 250),
                                    new FarmerSprite.AnimationFrame(1, 250),
                                    new FarmerSprite.AnimationFrame(3, 250),
                                    new FarmerSprite.AnimationFrame(1, 250),
                                    new FarmerSprite.AnimationFrame(3, 250, false, false, new AnimatedSprite.endOfAnimationBehavior(this.findTruffle), false)
                                });
                                break;

                            case 3:
                                this.sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                                {
                                    new FarmerSprite.AnimationFrame(5, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                                    new FarmerSprite.AnimationFrame(7, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                                    new FarmerSprite.AnimationFrame(5, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                                    new FarmerSprite.AnimationFrame(7, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                                    new FarmerSprite.AnimationFrame(5, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                                    new FarmerSprite.AnimationFrame(7, 250, false, true, new AnimatedSprite.endOfAnimationBehavior(this.findTruffle), false)
                                });
                                break;
                            }
                            this.sprite.loop = false;
                        }
                        else
                        {
                            this.findTruffle(Game1.player);
                        }
                    }
                }
                return(false);
            }
Пример #21
0
 public bool MoveNext()
 {
     if (_done == 2)
     {
         _done = 1;
         if (_locationFilter == null || (_player.currentLocation != null && _locationFilter.Equals(_player.currentLocation)))
         {
             _current = _player;
             return(true);
         }
     }
     while (_enumerator.MoveNext())
     {
         Farmer player = _enumerator.Current.Value.Value;
         if (player != _player && (_locationFilter == null || (player.currentLocation != null && _locationFilter.Equals(player.currentLocation))))
         {
             _current = player;
             return(true);
         }
     }
     _done    = 0;
     _current = null;
     return(false);
 }
Пример #22
0
        // This is to fix a problem with the vanilla other grass types
        // It references `Game1.mine.mineLevel`, but `Game1.mine` is null.
        public override bool performToolAction(Tool t, int explosion, Vector2 tileLocation, GameLocation location = null)
        {
            if (location == null)
            {
                location = Game1.currentLocation;
            }
            if (t != null && t is MeleeWeapon && ((MeleeWeapon)t).type.Value != 2 || explosion > 0)
            {
                if (t != null && (t as MeleeWeapon).type.Value != 1)
                {
                    DelayedAction.playSoundAfterDelay("daggerswipe", 50);
                }
                else if (location.Equals((object)Game1.currentLocation))
                {
                    Game1.playSound("swordswipe");
                }
                this.shake(3f * (float)Math.PI / 32f, (float)Math.PI / 40f, Game1.random.NextDouble() < 0.5);
                this.numberOfWeeds.Value = this.numberOfWeeds.Value - (explosion <= 0 ? 1 : Math.Max(1, explosion + 2 - Game1.recentMultiplayerRandom.Next(2)));
                Color color = Color.Green;
                switch (this.grassType.Value)
                {
                case 1:
                    string currentSeason = Game1.currentSeason;
                    if (!(currentSeason == "spring"))
                    {
                        if (!(currentSeason == "summer"))
                        {
                            if (currentSeason == "fall")
                            {
                                color = new Color(219, 102, 58);
                                break;
                            }
                            break;
                        }
                        color = new Color(110, 190, 24);
                        break;
                    }
                    color = new Color(60, 180, 58);
                    break;

                case 2:
                    color = new Color(148, 146, 71);
                    break;

                case 3:
                    color = new Color(216, 240, (int)byte.MaxValue);
                    break;

                case 4:
                    color = new Color(165, 93, 58);
                    break;
                }
                location.temporarySprites.Add(new TemporaryAnimatedSprite(28, tileLocation * (float)Game1.tileSize + new Vector2((float)Game1.random.Next(-Game1.pixelZoom * 4, Game1.pixelZoom * 4), (float)Game1.random.Next(-Game1.pixelZoom * 4, Game1.pixelZoom * 4)), color, 8, Game1.random.NextDouble() < 0.5, (float)Game1.random.Next(60, 100), 0, -1, -1f, -1, 0));
                if (this.numberOfWeeds.Value <= 0)
                {
                    if ((int)this.grassType.Value != 1)
                    {
                        Random random = Game1.IsMultiplayer ? Game1.recentMultiplayerRandom : new Random((int)((double)Game1.uniqueIDForThisGame + (double)tileLocation.X * 1000.0 + (double)tileLocation.Y * 11.0 + /*(double)Game1.mine.mineLevel +*/ (double)Game1.player.timesReachedMineBottom));
                        if (random.NextDouble() < 0.005)
                        {
                            Game1.createObjectDebris(114, (int)tileLocation.X, (int)tileLocation.Y, -1, 0, 1f, (GameLocation)null);
                        }
                        else if (random.NextDouble() < 0.01)
                        {
                            Game1.createDebris(4, (int)tileLocation.X, (int)tileLocation.Y, random.Next(1, 2), (GameLocation)null);
                        }
                        else if (random.NextDouble() < 0.02)
                        {
                            Game1.createDebris(92, (int)tileLocation.X, (int)tileLocation.Y, random.Next(2, 4), (GameLocation)null);
                        }
                    }
                    else if (t is MeleeWeapon && (t.Name.Contains("Scythe") || t.ParentSheetIndex == 47) && ((Game1.IsMultiplayer ? Game1.recentMultiplayerRandom : new Random((int)((double)Game1.uniqueIDForThisGame + (double)tileLocation.X * 1000.0 + (double)tileLocation.Y * 11.0))).NextDouble() < 0.5 && (Game1.getLocationFromName("Farm") as Farm).tryToAddHay(1) == 0))
                    {
                        t.getLastFarmerToUse().currentLocation.temporarySprites.Add(new TemporaryAnimatedSprite(Game1.objectSpriteSheetName, Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, 178, 16, 16), 750f, 1, 0, t.getLastFarmerToUse().position - new Vector2(0.0f, (float)(Game1.tileSize * 2)), false, false, t.getLastFarmerToUse().position.Y / 10000f, 0.005f, Color.White, (float)Game1.pixelZoom, -0.005f, 0.0f, 0.0f, false)
                        {
                            motion =
                            {
                                Y = -1f
                            },
                            layerDepth = (float)(1.0 - (double)Game1.random.Next(100) / 10000.0),
                            delayBeforeAnimationStart = Game1.random.Next(350)
                        });
                        Game1.addHUDMessage(new HUDMessage("Hay", 1, true, Color.LightGoldenrodYellow, (Item) new StardewValley.Object(178, 1, false, -1, 0)));
                    }
                    return(true);
                }
            }
            return(false);
        }
Пример #23
0
        /// <summary>The prefix for the Behaviors method.</summary>
        /// <param name="time">The GameTime object that contains time data about the game's frame time.</param>
        /// <param name="location">The current location of the <see cref="FarmAnimal"/> being patched.</param>
        /// <param name="__result">The return value of the original Bahaviors method.</param>
        /// <param name="__instance">The current <see cref="FarmAnimal"/> instance being patched.</param>
        /// <returns>False meaning the original method won't get ran.</returns>
        public static bool BehaviorsPrefix(GameTime time, GameLocation location, ref bool __result, FarmAnimal __instance)
        {
            // ensure animal has a house
            if (__instance.home == null)
            {
                __result = false;
                return(false);
            }

            // get isEating memeber
            var isEating = (NetBool)typeof(FarmAnimal).GetField("isEating", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);

            if (isEating)
            {
                if (__instance.home != null && __instance.home.getRectForAnimalDoor().Intersects(__instance.GetBoundingBox()))
                {
                    FarmAnimal.behaviorAfterFindingGrassPatch(__instance, location);
                    isEating.Value = false;
                    __instance.Halt();
                    __result = false;
                    return(false);
                }

                // sort out animation
                if (__instance.buildingTypeILiveIn.Contains("Barn"))
                {
                    __instance.Sprite.Animate(time, 16, 4, 100f);
                    if (__instance.Sprite.currentFrame >= 20)
                    {
                        isEating.Value                 = false;
                        __instance.Sprite.loop         = true;
                        __instance.Sprite.currentFrame = 0;
                        __instance.faceDirection(2);
                    }
                }
                else
                {
                    __instance.Sprite.Animate(time, 24, 4, 100f);
                    if (__instance.Sprite.currentFrame >= 28)
                    {
                        isEating.Value                 = false;
                        __instance.Sprite.loop         = true;
                        __instance.Sprite.currentFrame = 0;
                        __instance.faceDirection(2);
                    }
                }

                // set isEating member
                typeof(FarmAnimal).GetField("isEating", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(__instance, isEating);

                __result = true;
                return(false);
            }

            // only let the main behavior code be ran by the host
            if (Game1.IsClient)
            {
                __result = false;
                return(false);
            }

            // ensure animal isn't currently on a path
            if (__instance.controller != null)
            {
                __result = true;
                return(false);
            }

            // make animal go to grass if it's hungry
            if (location.IsOutdoors && __instance.fullness < 195 && (Game1.random.NextDouble() < 0.002 && FarmAnimal.NumPathfindingThisTick < FarmAnimal.MaxPathfindingPerTick))
            {
                FarmAnimal.NumPathfindingThisTick++;
                __instance.controller = new PathFindController(__instance, location, new PathFindController.isAtEnd(FarmAnimal.grassEndPointFunction), -1, false, new PathFindController.endBehavior(FarmAnimal.behaviorAfterFindingGrassPatch), 200, Point.Zero, true);
            }

            // teleport the animals inside at night
            if (Game1.timeOfDay >= 1700 && location.IsOutdoors && (__instance.controller == null && Game1.random.NextDouble() < 0.002))
            {
                if (location.farmers.Count == 0)
                {
                    (location as Farm).animals.Remove(__instance.myID);
                    (__instance.home.indoors.Value as AnimalHouse).animals.Add(__instance.myID, __instance);
                    __instance.setRandomPosition(__instance.home.indoors);
                    __instance.faceDirection(Game1.random.Next(4));
                    __instance.controller = null;

                    __result = true;
                    return(false);
                }

                if (FarmAnimal.NumPathfindingThisTick < FarmAnimal.MaxPathfindingPerTick)
                {
                    ++FarmAnimal.NumPathfindingThisTick;
                    __instance.controller = new PathFindController(__instance, location, new PathFindController.isAtEnd(PathFindController.isAtEndPoint), 0, false, null, 200, new Point(__instance.home.tileX + __instance.home.animalDoor.X, __instance.home.tileY + __instance.home.animalDoor.Y), true);
                }
            }

            // check if animal can forage for produce
            if (location.IsOutdoors && !Game1.isRaining && __instance.currentProduce != -1 && !__instance.isBaby() && Game1.random.NextDouble() < 0.0002)
            {
                // check if animal has produce that can be foraged
                var subType = ModEntry.Instance.Api.GetAnimalSubTypeByName(__instance.type);
                if (subType != null)
                {
                    // get the forage items count
                    var productCount = subType.Produce?.AllSeasons?.Products.Where(product => product.HarvestType == HarvestType.Forage).Select(product => product.Id).Count() ?? 0;
                    switch (Game1.currentSeason)
                    {
                    case "spring":
                    {
                        productCount += subType.Produce?.Spring?.Products.Where(produce => produce.HarvestType == HarvestType.Forage).Select(produce => produce.Id).Count() ?? 0;
                        productCount += subType.Produce?.Spring?.DeluxeProducts.Where(produce => produce.HarvestType == HarvestType.Forage).Select(produce => produce.Id).Count() ?? 0;
                        break;
                    }

                    case "summer":
                    {
                        productCount = subType.Produce?.Spring?.Products.Where(produce => produce.HarvestType == HarvestType.Forage).Select(produce => produce.Id).Count() ?? 0;
                        productCount = subType.Produce?.Spring?.DeluxeProducts.Where(produce => produce.HarvestType == HarvestType.Forage).Select(produce => produce.Id).Count() ?? 0;
                        break;
                    }

                    case "fall":
                    {
                        productCount = subType.Produce?.Spring?.Products.Where(produce => produce.HarvestType == HarvestType.Forage).Select(produce => produce.Id).Count() ?? 0;
                        productCount = subType.Produce?.Spring?.DeluxeProducts.Where(produce => produce.HarvestType == HarvestType.Forage).Select(produce => produce.Id).Count() ?? 0;
                        break;
                    }

                    case "winter":
                    {
                        productCount = subType.Produce?.Spring?.Products.Where(produce => produce.HarvestType == HarvestType.Forage).Select(produce => produce.Id).Count() ?? 0;
                        productCount = subType.Produce?.Spring?.DeluxeProducts.Where(produce => produce.HarvestType == HarvestType.Forage).Select(produce => produce.Id).Count() ?? 0;
                        break;
                    }
                    }

                    // ensure there is a valid product for the animal
                    if (productCount == 0)
                    {
                        __result = false;
                        return(false);
                    }
                }

                // amke sure the place is blank for spawning the foraged item
                var boundingBox = __instance.GetBoundingBox();
                for (int corner = 0; corner < 4; ++corner)
                {
                    var cornersOfThisRectangle = Utility.getCornersOfThisRectangle(ref boundingBox, corner);
                    var position = new Vector2(cornersOfThisRectangle.X / 64f, cornersOfThisRectangle.Y / 64f);
                    if (location.terrainFeatures.ContainsKey(position) || location.objects.ContainsKey(position))
                    {
                        __result = false;
                        return(false);
                    }
                }

                // play forage sounds
                if (Game1.player.currentLocation.Equals(location))
                {
                    DelayedAction.playSoundAfterDelay("dirtyHit", 450, null, -1);
                    DelayedAction.playSoundAfterDelay("dirtyHit", 900, null, -1);
                    DelayedAction.playSoundAfterDelay("dirtyHit", 1350, null, -1);
                }

                // animate the animal is the player is there
                var findTruffle = typeof(FarmAnimal).GetMethod("findTruffle", BindingFlags.NonPublic | BindingFlags.Instance);
                if (location.Equals(Game1.currentLocation))
                {
                    switch (__instance.FacingDirection)
                    {
                    case 0:
                        __instance.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                        {
                            new FarmerSprite.AnimationFrame(9, 250),
                            new FarmerSprite.AnimationFrame(11, 250),
                            new FarmerSprite.AnimationFrame(9, 250),
                            new FarmerSprite.AnimationFrame(11, 250),
                            new FarmerSprite.AnimationFrame(9, 250),
                            new FarmerSprite.AnimationFrame(11, 250, false, false, new AnimatedSprite.endOfAnimationBehavior((farmer) => { findTruffle.Invoke(__instance, new object[] { farmer }); }), false)
                        });
                        break;

                    case 1:
                        __instance.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                        {
                            new FarmerSprite.AnimationFrame(5, 250),
                            new FarmerSprite.AnimationFrame(7, 250),
                            new FarmerSprite.AnimationFrame(5, 250),
                            new FarmerSprite.AnimationFrame(7, 250),
                            new FarmerSprite.AnimationFrame(5, 250),
                            new FarmerSprite.AnimationFrame(7, 250, false, false, new AnimatedSprite.endOfAnimationBehavior((farmer) => { findTruffle.Invoke(__instance, new object[] { farmer }); }), false)
                        });
                        break;

                    case 2:
                        __instance.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                        {
                            new FarmerSprite.AnimationFrame(1, 250),
                            new FarmerSprite.AnimationFrame(3, 250),
                            new FarmerSprite.AnimationFrame(1, 250),
                            new FarmerSprite.AnimationFrame(3, 250),
                            new FarmerSprite.AnimationFrame(1, 250),
                            new FarmerSprite.AnimationFrame(3, 250, false, false, new AnimatedSprite.endOfAnimationBehavior((farmer) => { findTruffle.Invoke(__instance, new object[] { farmer }); }), false)
                        });
                        break;

                    case 3:
                        __instance.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                        {
                            new FarmerSprite.AnimationFrame(5, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                            new FarmerSprite.AnimationFrame(7, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                            new FarmerSprite.AnimationFrame(5, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                            new FarmerSprite.AnimationFrame(7, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                            new FarmerSprite.AnimationFrame(5, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                            new FarmerSprite.AnimationFrame(7, 250, false, true, new AnimatedSprite.endOfAnimationBehavior((farmer) => { findTruffle.Invoke(__instance, new object[] { farmer }); }), false)
                        });
                        break;
                    }

                    __instance.Sprite.loop = false;
                }
                else
                {
                    findTruffle.Invoke(__instance, new object[] { Game1.player });
                }
            }

            __result = false;
            return(false);
        }
        //We need to call the base NPC update, but we don't want to call JunimoHarvester's update function since we're replacing that. Sadly, the only way to
        //do this is to copy the code from NPC because we have no reference to the base update function.
        private void NPCUpdate(GameTime time, GameLocation location)
        {
            if (this.freturningToEndPoint.GetValue())
            {
                this.returnToEndPoint();
                this.MovePosition(time, Game1.viewport, location);
            }
            else if (this.temporaryController != null)
            {
                if (this.temporaryController.update(time))
                {
                    this.temporaryController = (PathFindController)null;
                }
                this.updateEmote(time);
            }
            else
            {
                base.update(time, location);
            }
            if (this.textAboveHeadTimer > 0)
            {
                if (this.textAboveHeadPreTimer > 0)
                {
                    this.textAboveHeadPreTimer = this.textAboveHeadPreTimer - time.ElapsedGameTime.Milliseconds;
                }
                else
                {
                    this.textAboveHeadTimer = this.textAboveHeadTimer - time.ElapsedGameTime.Milliseconds;
                    this.textAboveHeadAlpha = this.textAboveHeadTimer <= 500 ? Math.Max(0.0f, this.textAboveHeadAlpha - 0.04f) : Math.Min(1f, this.textAboveHeadAlpha + 0.1f);
                }
            }
            if (this.fisWalkingInSquare.GetValue() && !this.freturningToEndPoint.GetValue())
            {
                this.randomSquareMovement(time);
            }
            if (this.Sprite != null && this.Sprite.currentAnimation != null && (!Game1.eventUp && this.Sprite.animateOnce(time)))
            {
                this.Sprite.currentAnimation = (List <FarmerSprite.AnimationFrame>)null;
            }
            TimeSpan timeSpan;

            if (this.movementPause > 0 && (!Game1.dialogueUp || this.controller != null))
            {
                this.freezeMotion = true;
                int movementPause = this.movementPause;
                timeSpan = time.ElapsedGameTime;
                int milliseconds = timeSpan.Milliseconds;
                this.movementPause = movementPause - milliseconds;
                if (this.movementPause <= 0)
                {
                    this.freezeMotion = false;
                }
            }
            if (this.shakeTimer > 0)
            {
                int shakeTimer = this.shakeTimer;
                timeSpan = time.ElapsedGameTime;
                int milliseconds = timeSpan.Milliseconds;
                this.shakeTimer = shakeTimer - milliseconds;
            }
            if (this.lastPosition.Equals(this.position))
            {
                double sinceLastMovement = (double)this.timerSinceLastMovement;
                timeSpan = time.ElapsedGameTime;
                double milliseconds = (double)timeSpan.Milliseconds;
                this.timerSinceLastMovement = (float)(sinceLastMovement + milliseconds);
            }
            else
            {
                this.timerSinceLastMovement = 0.0f;
            }
            if (!this.swimming)
            {
                return;
            }
            timeSpan     = time.TotalGameTime;
            this.yOffset = (float)Math.Cos(timeSpan.TotalMilliseconds / 2000.0) * (float)Game1.pixelZoom;
            float  swimTimer1 = this.swimTimer;
            double swimTimer2 = (double)this.swimTimer;

            timeSpan = time.ElapsedGameTime;
            double milliseconds1 = (double)timeSpan.Milliseconds;

            this.swimTimer = (float)(swimTimer2 - milliseconds1);
            if ((double)this.timerSinceLastMovement == 0.0)
            {
                if ((double)swimTimer1 > 400.0 && (double)this.swimTimer <= 400.0 && location.Equals((object)Game1.currentLocation))
                {
                    location.temporarySprites.Add(new TemporaryAnimatedSprite(Game1.animations, new Microsoft.Xna.Framework.Rectangle(0, 0, Game1.tileSize, Game1.tileSize), (float)(150.0 - ((double)Math.Abs(this.xVelocity) + (double)Math.Abs(this.yVelocity)) * 3.0), 8, 0, new Vector2(this.position.X, (float)(this.getStandingY() - Game1.tileSize / 2)), false, Game1.random.NextDouble() < 0.5, 0.01f, 0.01f, Color.White, 1f, 3f / 1000f, 0.0f, 0.0f, false));
                    Game1.playSound("slosh");
                }
                if ((double)this.swimTimer >= 0.0)
                {
                    return;
                }
                this.swimTimer = 800f;
                if (!location.Equals((object)Game1.currentLocation))
                {
                    return;
                }
                Game1.playSound("slosh");
                location.temporarySprites.Add(new TemporaryAnimatedSprite(Game1.animations, new Microsoft.Xna.Framework.Rectangle(0, 0, Game1.tileSize, Game1.tileSize), (float)(150.0 - ((double)Math.Abs(this.xVelocity) + (double)Math.Abs(this.yVelocity)) * 3.0), 8, 0, new Vector2(this.position.X, (float)(this.getStandingY() - Game1.tileSize / 2)), false, Game1.random.NextDouble() < 0.5, 0.01f, 0.01f, Color.White, 1f, 3f / 1000f, 0.0f, 0.0f, false));
            }
            else
            {
                if ((double)this.swimTimer >= 0.0)
                {
                    return;
                }
                this.swimTimer = 100f;
            }
        }
Пример #25
0
        private void export(RenderQueueEntry render)
        {
            GameLocation loc = render.loc;

            //int oldZoom = Game1.pixelZoom;
            //Game1.pixelZoom = 4;
            SpriteBatch    b          = Game1.spriteBatch; // new SpriteBatch(Game1.graphics.GraphicsDevice);
            GraphicsDevice dev        = Game1.graphics.GraphicsDevice;
            var            display    = Game1.mapDisplayDevice;
            RenderTarget2D output     = null;
            RenderTarget2D oldOutput  = null;
            RenderTarget2D myLighting = null;
            Stream         stream     = null;
            bool           begun      = false;
            Rectangle      oldView    = new Rectangle();
            float          oldZoomL   = Game1.options.zoomLevel;

            Game1.options.desiredBaseZoomLevel = 0.25f;
            try
            {
                Log.info("Rendering " + loc.Name + "...");
                output = new RenderTarget2D(dev, loc.map.DisplayWidth / 4, loc.map.DisplayHeight / 4);
                RectangleX viewportX = new RectangleX(0, 0, output.Width, output.Height);
                Rectangle  viewport  = new Rectangle(0, 0, output.Width * 4, output.Height * 4);
                oldView        = Game1.viewport;
                Game1.viewport = viewport;

                Matrix transform = Matrix.CreateScale(0.25f);

                if (loc is DecoratableLocation)
                {
                    foreach (Furniture f in (loc as DecoratableLocation).furniture)
                    {
                        f.updateDrawPosition();
                    }
                }

                if (render.Lighting)
                {
                    int   num1 = 32;
                    float num2 = 1f;
                    if (Game1.options != null)
                    {
                        num1 = Game1.options.lightingQuality;
                        num2 = Game1.options.zoomLevel;
                    }

                    int width  = (int)(output.Width * (1.0 / num2) + Game1.tileSize) / (num1 / 2);
                    int height = (int)(output.Height * (1.0 / num2) + Game1.tileSize) / (num1 / 2);
                    myLighting = new RenderTarget2D(dev, width, height, false, SurfaceFormat.Color, DepthFormat.None, 0,
                                                    RenderTargetUsage.PreserveContents);
                    if (Game1.drawLighting)
                    {
                        dev.SetRenderTarget(myLighting);
                        dev.Clear(Color.White * 0f);
                        b.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, null,
                                null, null, transform);
                        b.Draw(Game1.staminaRect, myLighting.Bounds,
                               loc.Name.Equals("UndergroundMine")
                                ? Game1.mine.getLightingColor(null /*gameTime*/)
                                : ((!Game1.ambientLight.Equals(Color.White) && (!Game1.isRaining || !loc.IsOutdoors))
                                    ? Game1.ambientLight
                                    : Game1.outdoorLight));
                        for (int i = 0; i < Game1.currentLightSources.Count; i++)
                        {
                            //if (Utility.isOnScreen(Game1.currentLightSources.ElementAt(i).position, (int)(Game1.currentLightSources.ElementAt(i).radius * (float)Game1.tileSize * 4f)))
                            {
                                b.Draw(Game1.currentLightSources.ElementAt(i).lightTexture,
                                       Game1.currentLightSources.ElementAt(i).position.Value /
                                       (Game1.options.lightingQuality / 2),
                                       Game1.currentLightSources.ElementAt(i).lightTexture.Bounds,
                                       Game1.currentLightSources.ElementAt(i).color.Value, 0f,
                                       new Vector2(Game1.currentLightSources.ElementAt(i).lightTexture.Bounds.Center.X,
                                                   Game1.currentLightSources.ElementAt(i).lightTexture.Bounds.Center.Y),
                                       Game1.currentLightSources.ElementAt(i).radius.Value /
                                       (Game1.options.lightingQuality / 2), SpriteEffects.None, 0.9f);
                            }
                        }

                        b.End();
                        //dev.SetRenderTarget((Game1.options.zoomLevel == 1f) ? null : this.screen);
                    }

                    if (Game1.bloomDay && Game1.bloom != null)
                    {
                        Game1.bloom.BeginDraw();
                    }
                }

                dev.SetRenderTarget(output);
                dev.Clear(Color.Black);
                {
                    if (!loc.Equals(Game1.currentLocation))
                    {
                        loc.map.LoadTileSheets(display);
                    }

                    b.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null,
                            transform);
                    begun = true;
                    if (render.Tiles)
                    {
                        display.BeginScene(b);
                        loc.map.GetLayer("Back")
                        .Draw(Game1.mapDisplayDevice, new Rectangle(0, 0, output.Width * 4, output.Height * 4),
                              Location.Origin, false, 4);
                        loc.drawWater(b);
                    }

                    if (render.Characters)
                    {
                        var chars = loc.characters.ToList();
                        if (render.Event && Game1.CurrentEvent != null && loc.Equals(Game1.currentLocation))
                        {
                            chars = Game1.CurrentEvent.actors;
                        }

                        foreach (NPC npc in chars)
                        {
                            if (!npc.swimming.Value && !npc.HideShadow && !npc.IsInvisible &&
                                !loc.shouldShadowBeDrawnAboveBuildingsLayer(npc.getTileLocation()))
                            {
                                b.Draw(Game1.shadowTexture,
                                       Game1.GlobalToLocal(viewport,
                                                           npc.position + new Vector2(npc.Sprite.SpriteWidth * Game1.pixelZoom / 2f,
                                                                                      npc.GetBoundingBox().Height + (npc.IsMonster ? 0 : (Game1.pixelZoom * 3)))),
                                       Game1.shadowTexture.Bounds, Color.White, 0f,
                                       new Vector2(Game1.shadowTexture.Bounds.Center.X,
                                                   Game1.shadowTexture.Bounds.Center.Y),
                                       (Game1.pixelZoom + npc.yJumpOffset / 40f) * npc.Scale, SpriteEffects.None,
                                       Math.Max(0f, npc.getStandingY() / 10000f) - 1E-06f);
                            }
                        }
                    }

                    if (render.Player && Game1.currentLocation.Equals(loc))
                    {
                        if (Game1.displayFarmer && !Game1.player.swimming.Value && !Game1.player.isRidingHorse() &&
                            !Game1.currentLocation.shouldShadowBeDrawnAboveBuildingsLayer(
                                Game1.player.getTileLocation()))
                        {
                            b.Draw(Game1.shadowTexture,
                                   Game1.GlobalToLocal(Game1.player.position + new Vector2(32f, 24f)),
                                   Game1.shadowTexture.Bounds, Color.White, 0f,
                                   new Vector2(Game1.shadowTexture.Bounds.Center.X, Game1.shadowTexture.Bounds.Center.Y),
                                   4f - (((Game1.player.running || Game1.player.UsingTool) &&
                                          Game1.player.FarmerSprite.currentAnimationIndex > 1)
                                    ? (Math.Abs(
                                           FarmerRenderer.featureYOffsetPerFrame
                                           [Game1.player.FarmerSprite.CurrentFrame]) *
                                       0.5f)
                                    : 0f), SpriteEffects.None, 0f);
                        }
                    }

                    if (render.Tiles)
                    {
                        loc.map.GetLayer("Buildings")
                        .Draw(Game1.mapDisplayDevice, new Rectangle(0, 0, output.Width * 4, output.Height * 4),
                              Location.Origin, false, 4);
                        display.EndScene();
                    }

                    b.End();
                    begun = false;

                    b.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, null, null,
                            null, transform);
                    begun = true;
                    if (render.Characters)
                    {
                        var chars = loc.characters.ToList();
                        if (render.Event && Game1.CurrentEvent != null && loc.Equals(Game1.currentLocation))
                        {
                            chars = Game1.CurrentEvent.actors;
                        }

                        foreach (NPC npc in chars)
                        {
                            if (!npc.swimming.Value && !npc.HideShadow && !npc.IsInvisible &&
                                !loc.shouldShadowBeDrawnAboveBuildingsLayer(npc.getTileLocation()))
                            {
                                b.Draw(Game1.shadowTexture,
                                       Game1.GlobalToLocal(viewport,
                                                           npc.position + new Vector2(npc.Sprite.SpriteWidth * Game1.pixelZoom / 2f,
                                                                                      npc.GetBoundingBox().Height + (npc.IsMonster ? 0 : (Game1.pixelZoom * 3)))),
                                       Game1.shadowTexture.Bounds, Color.White, 0f,
                                       new Vector2(Game1.shadowTexture.Bounds.Center.X,
                                                   Game1.shadowTexture.Bounds.Center.Y),
                                       (Game1.pixelZoom + npc.yJumpOffset / 40f) * npc.Scale, SpriteEffects.None,
                                       Math.Max(0f, npc.getStandingY() / 10000f) - 1E-06f);
                            }
                        }
                    }

                    if (render.Player && Game1.currentLocation.Equals(loc))
                    {
                        if (Game1.displayFarmer && !Game1.player.swimming.Value && !Game1.player.isRidingHorse() &&
                            Game1.currentLocation
                            .shouldShadowBeDrawnAboveBuildingsLayer(Game1.player.getTileLocation()))
                        {
                            b.Draw(Game1.shadowTexture,
                                   Game1.GlobalToLocal(Game1.player.position + new Vector2(32f, 24f)),
                                   Game1.shadowTexture.Bounds, Color.White, 0f,
                                   new Vector2(Game1.shadowTexture.Bounds.Center.X, Game1.shadowTexture.Bounds.Center.Y),
                                   4f - (((Game1.player.running || Game1.player.UsingTool) &&
                                          Game1.player.FarmerSprite.currentAnimationIndex > 1)
                                    ? (Math.Abs(
                                           FarmerRenderer.featureYOffsetPerFrame
                                           [Game1.player.FarmerSprite.CurrentFrame]) *
                                       0.5f)
                                    : 0f), SpriteEffects.None,
                                   Math.Max(0.0001f, Game1.player.getStandingY() / 10000f + 0.00011f) - 0.0001f);
                        }

                        if (Game1.displayFarmer)
                        {
                            Game1.player.draw(b);
                        }
                    }

                    if (render.Event && loc.Equals(Game1.currentLocation))
                    {
                        if ((Game1.eventUp || Game1.killScreen) && !Game1.killScreen &&
                            Game1.currentLocation.currentEvent != null)
                        {
                            loc.currentEvent.draw(b);
                        }
                    }

                    if (render.Location)
                    {
                        if (Game1.player.currentUpgrade != null &&
                            Game1.player.currentUpgrade.daysLeftTillUpgradeDone <= 3 && loc.Name.Equals("Farm"))
                        {
                            b.Draw(Game1.player.currentUpgrade.workerTexture,
                                   Game1.GlobalToLocal(viewport, Game1.player.currentUpgrade.positionOfCarpenter),
                                   Game1.player.currentUpgrade.getSourceRectangle(), Color.White, 0f, Vector2.Zero, 1f,
                                   SpriteEffects.None,
                                   (Game1.player.currentUpgrade.positionOfCarpenter.Y + Game1.tileSize * 3 / 4) / 10000f);
                        }

                        var charsField   = Helper.Reflection.GetField <NetCollection <NPC> >(loc, "characters");
                        var farmersField = Helper.Reflection.GetField <FarmerCollection>(loc, "farmers");
                        var chars        = loc.characters;
                        var farmers      = loc.farmers;
                        try
                        {
                            if (!render.Player)
                            {
                                var type = typeof(Game1).Assembly.GetType("StardewValley.Network.FarmerCollection");
                                var val  = (FarmerCollection)type.GetConstructor(new[] { typeof(GameLocation) })
                                           .Invoke(new object[] { loc });
                                farmersField.SetValue(val);
                            }

                            if (!render.Characters)
                            {
                                charsField.SetValue(new NetCollection <NPC>());
                            }

                            loc.draw(b);
                        }
                        finally
                        {
                            farmersField.SetValue(farmers);
                            charsField.SetValue(chars);
                        }
                    }

                    if (render.Player && Game1.currentLocation.Equals(loc))
                    {
                        if (Game1.player.ActiveObject == null && (Game1.player.UsingTool || Game1.pickingTool) &&
                            Game1.player.CurrentTool != null &&
                            (!Game1.player.CurrentTool.Name.Equals("Seeds") || Game1.pickingTool))
                        {
                            Game1.drawTool(Game1.player);
                        }
                    }

                    if (render.Location)
                    {
                        if (loc.Name.Equals("Farm"))
                        {
                            Helper.Reflection.GetMethod(Game1.game1, "drawFarmBuildings").Invoke();
                        }
                    }

                    if (render.Location)
                    {
                        if (Game1.tvStation >= 0)
                        {
                            b.Draw(Game1.tvStationTexture,
                                   Game1.GlobalToLocal(viewport,
                                                       new Vector2(6 * Game1.tileSize + Game1.tileSize / 4,
                                                                   2 * Game1.tileSize + Game1.tileSize / 2)),
                                   new RectangleX(Game1.tvStation * 24, 0, 24, 15), Color.White, 0f, Vector2.Zero, 4f,
                                   SpriteEffects.None, 1E-08f);
                        }
                    }

                    if (render.Tiles)
                    {
                        display.BeginScene(b);
                        loc.map.GetLayer("Front")
                        .Draw(Game1.mapDisplayDevice, new Rectangle(0, 0, output.Width * 4, output.Height * 4),
                              Location.Origin, false, 4);
                        display.EndScene();
                    }

                    if (render.Location)
                    {
                        loc.drawAboveFrontLayer(b);
                    }

                    b.End();
                    begun = false;

                    b.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null,
                            transform);
                    begun = true;
                    if (render.Location)
                    {
                        if (loc.Name.Equals("Farm") && Game1.stats.SeedsSown >= 200u)
                        {
                            b.Draw(Game1.debrisSpriteSheet,
                                   Game1.GlobalToLocal(viewport,
                                                       new Vector2(3 * Game1.tileSize + Game1.tileSize / 4,
                                                                   Game1.tileSize + Game1.tileSize / 3)),
                                   Game1.getSourceRectForStandardTileSheet(Game1.debrisSpriteSheet, 16), Color.White);
                            b.Draw(Game1.debrisSpriteSheet,
                                   Game1.GlobalToLocal(viewport,
                                                       new Vector2(4 * Game1.tileSize + Game1.tileSize,
                                                                   2 * Game1.tileSize + Game1.tileSize)),
                                   Game1.getSourceRectForStandardTileSheet(Game1.debrisSpriteSheet, 16), Color.White);
                            b.Draw(Game1.debrisSpriteSheet,
                                   Game1.GlobalToLocal(viewport, new Vector2(5 * Game1.tileSize, 2 * Game1.tileSize)),
                                   Game1.getSourceRectForStandardTileSheet(Game1.debrisSpriteSheet, 16), Color.White);
                            b.Draw(Game1.debrisSpriteSheet,
                                   Game1.GlobalToLocal(viewport,
                                                       new Vector2(3 * Game1.tileSize + Game1.tileSize / 2, 3 * Game1.tileSize)),
                                   Game1.getSourceRectForStandardTileSheet(Game1.debrisSpriteSheet, 16), Color.White);
                            b.Draw(Game1.debrisSpriteSheet,
                                   Game1.GlobalToLocal(viewport,
                                                       new Vector2(5 * Game1.tileSize - Game1.tileSize / 4, Game1.tileSize)),
                                   Game1.getSourceRectForStandardTileSheet(Game1.debrisSpriteSheet, 16), Color.White);
                            b.Draw(Game1.debrisSpriteSheet,
                                   Game1.GlobalToLocal(viewport,
                                                       new Vector2(4 * Game1.tileSize, 3 * Game1.tileSize + Game1.tileSize / 6)),
                                   Game1.getSourceRectForStandardTileSheet(Game1.debrisSpriteSheet, 16), Color.White);
                            b.Draw(Game1.debrisSpriteSheet,
                                   Game1.GlobalToLocal(viewport,
                                                       new Vector2(4 * Game1.tileSize + Game1.tileSize / 5,
                                                                   2 * Game1.tileSize + Game1.tileSize / 3)),
                                   Game1.getSourceRectForStandardTileSheet(Game1.debrisSpriteSheet, 16), Color.White);
                        }
                    }

                    if (render.Player && Game1.currentLocation.Equals(loc))
                    {
                        var meth = typeof(Game1).GetMethod("checkBigCraftableBoundariesForFrontLayer",
                                                           BindingFlags.NonPublic | BindingFlags.Instance);
                        if (Game1.displayFarmer && Game1.player.ActiveObject != null &&
                            Game1.player.ActiveObject.bigCraftable.Value &&
                            (bool)meth.Invoke(Game1.game1, new object[] { }) && Game1.currentLocation.Map
                            .GetLayer("Front")
                            .PickTile(new Location(Game1.player.getStandingX(), Game1.player.getStandingY()),
                                      viewport.Size) == null)
                        {
                            Game1.drawPlayerHeldObject(Game1.player);
                        }
                        else if (Game1.displayFarmer && Game1.player.ActiveObject != null &&
                                 ((Game1.currentLocation.Map.GetLayer("Front")
                                   .PickTile(
                                       new Location((int)Game1.player.position.X,
                                                    (int)Game1.player.position.Y - Game1.tileSize * 3 / 5),
                                       viewport.Size) !=
                                   null &&
                                   !Game1.currentLocation.Map.GetLayer("Front")
                                   .PickTile(
                                       new Location((int)Game1.player.position.X,
                                                    (int)Game1.player.position.Y - Game1.tileSize * 3 / 5), viewport.Size)
                                   .TileIndexProperties.ContainsKey("FrontAlways")) ||
                                  (Game1.currentLocation.Map.GetLayer("Front")
                                   .PickTile(
                                       new Location(Game1.player.GetBoundingBox().Right,
                                                    (int)Game1.player.position.Y - Game1.tileSize * 3 / 5),
                                       viewport.Size) !=
                                   null && !Game1.currentLocation.Map.GetLayer("Front")
                                   .PickTile(
                                       new Location(Game1.player.GetBoundingBox().Right,
                                                    (int)Game1.player.position.Y - Game1.tileSize * 3 / 5),
                                       viewport.Size)
                                   .TileIndexProperties.ContainsKey("FrontAlways"))))
                        {
                            Game1.drawPlayerHeldObject(Game1.player);
                        }

                        if ((Game1.player.UsingTool || Game1.pickingTool) && Game1.player.CurrentTool != null &&
                            (!Game1.player.CurrentTool.Name.Equals("Seeds") || Game1.pickingTool) &&
                            Game1.currentLocation.Map.GetLayer("Front")
                            .PickTile(
                                new Location(Game1.player.getStandingX(),
                                             (int)Game1.player.position.Y - Game1.tileSize * 3 / 5), viewport.Size) !=
                            null && Game1.currentLocation.Map.GetLayer("Front")
                            .PickTile(new Location(Game1.player.getStandingX(), Game1.player.getStandingY()),
                                      viewport.Size) == null)
                        {
                            Game1.drawTool(Game1.player);
                        }
                    }

                    if (render.Tiles)
                    {
                        if (loc.map.GetLayer("AlwaysFront") != null)
                        {
                            display.BeginScene(b);
                            loc.map.GetLayer("AlwaysFront")
                            .Draw(Game1.mapDisplayDevice, new Rectangle(0, 0, output.Width * 4, output.Height * 4),
                                  Location.Origin, false, 4);
                            display.EndScene();
                        }
                    }

                    if (render.Player && Game1.currentLocation.Equals(loc))
                    {
                        if (Game1.toolHold > 400f && Game1.player.CurrentTool.UpgradeLevel >= 1 &&
                            Game1.player.canReleaseTool)
                        {
                            Color color = Color.White;
                            switch ((int)(Game1.toolHold / 600f) + 2)
                            {
                            case 1:
                                color = Tool.copperColor;
                                break;

                            case 2:
                                color = Tool.steelColor;
                                break;

                            case 3:
                                color = Tool.goldColor;
                                break;

                            case 4:
                                color = Tool.iridiumColor;
                                break;
                            }

                            b.Draw(Game1.littleEffect,
                                   new RectangleX((int)Game1.player.getLocalPosition(viewport).X - 2,
                                                  (int)Game1.player.getLocalPosition(viewport).Y -
                                                  (Game1.player.CurrentTool.Name.Equals("Watering Can") ? 0 : Game1.tileSize) - 2,
                                                  (int)(Game1.toolHold % 600f * 0.08f) + 4, Game1.tileSize / 8 + 4), Color.Black);
                            b.Draw(Game1.littleEffect,
                                   new RectangleX((int)Game1.player.getLocalPosition(viewport).X,
                                                  (int)Game1.player.getLocalPosition(viewport).Y -
                                                  (Game1.player.CurrentTool.Name.Equals("Watering Can") ? 0 : Game1.tileSize),
                                                  (int)(Game1.toolHold % 600f * 0.08f), Game1.tileSize / 8), color);
                        }
                    }

                    if (render.Weather)
                    {
                        if (Game1.isDebrisWeather && loc.IsOutdoors && !loc.ignoreDebrisWeather.Value &&
                            !loc.Name.Equals("Desert") && viewport.X > -10)
                        {
                            using (List <WeatherDebris> .Enumerator enumerator4 = Game1.debrisWeather.GetEnumerator())
                            {
                                while (enumerator4.MoveNext())
                                {
                                    enumerator4.Current.draw(b);
                                }
                            }
                        }
                    }

                    if (render.Event)
                    {
                        if (Game1.farmEvent != null)
                        {
                            Game1.farmEvent.draw(b);
                        }
                    }

                    if (render.Lighting)
                    {
                        if (loc.LightLevel > 0f && Game1.timeOfDay < 2000)
                        {
                            b.Draw(Game1.fadeToBlackRect, output.Bounds, Color.Black * loc.LightLevel);
                        }

                        if (Game1.screenGlow)
                        {
                            b.Draw(Game1.fadeToBlackRect, output.Bounds, Game1.screenGlowColor * Game1.screenGlowAlpha);
                        }
                    }

                    if (render.Location)
                    {
                        loc.drawAboveAlwaysFrontLayer(b);
                    }

                    if (render.Player && Game1.currentLocation.Equals(loc))
                    {
                        if (Game1.player.CurrentTool != null && Game1.player.CurrentTool is FishingRod &&
                            ((Game1.player.CurrentTool as FishingRod).isTimingCast ||
                             (Game1.player.CurrentTool as FishingRod).castingChosenCountdown > 0f ||
                             (Game1.player.CurrentTool as FishingRod).fishCaught ||
                             (Game1.player.CurrentTool as FishingRod).showingTreasure))
                        {
                            Game1.player.CurrentTool.draw(b);
                        }
                    }

                    if (render.Weather)
                    {
                        if (Game1.isRaining && loc.IsOutdoors && !loc.Name.Equals("Desert") && !(loc is Summit) &&
                            (!Game1.eventUp || loc.isTileOnMap(new Vector2(viewport.X / Game1.tileSize,
                                                                           viewport.Y / Game1.tileSize))))
                        {
                            for (int ix = 0; ix < output.Bounds.Width / oldView.Width * 4; ++ix)
                            {
                                for (int iy = 0; iy < output.Bounds.Height / oldView.Height * 4; ++iy)
                                {
                                    var offset = new Vector2(ix * oldView.Width, iy * oldView.Height);
                                    for (int j = 0; j < Game1.rainDrops.Length; j++)
                                    {
                                        b.Draw(Game1.rainTexture, offset + Game1.rainDrops[j].position,
                                               Game1.getSourceRectForStandardTileSheet(Game1.rainTexture,
                                                                                       Game1.rainDrops[j].frame), Color.White);
                                    }
                                }
                            }
                        }
                    }

                    b.End();
                    begun = false;

                    if (render.Event && Game1.currentLocation.Equals(loc))
                    {
                        b.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, null, null,
                                null, transform);
                        begun = true;
                        if (Game1.eventUp && Game1.currentLocation.currentEvent != null)
                        {
                            foreach (NPC current7 in Game1.currentLocation.currentEvent.actors)
                            {
                                if (current7.isEmoting)
                                {
                                    Vector2 localPosition = current7.getLocalPosition(viewport);
                                    localPosition.Y -= Game1.tileSize * 2 + Game1.pixelZoom * 3;
                                    if (current7.Age == 2)
                                    {
                                        localPosition.Y += Game1.tileSize / 2;
                                    }
                                    else if (current7.Gender == 1)
                                    {
                                        localPosition.Y += Game1.tileSize / 6;
                                    }

                                    b.Draw(Game1.emoteSpriteSheet, localPosition,
                                           new RectangleX(
                                               current7.CurrentEmoteIndex * (Game1.tileSize / 4) %
                                               Game1.emoteSpriteSheet.Width,
                                               current7.CurrentEmoteIndex * (Game1.tileSize / 4) /
                                               Game1.emoteSpriteSheet.Width * (Game1.tileSize / 4), Game1.tileSize / 4,
                                               Game1.tileSize / 4), Color.White, 0f, Vector2.Zero, 4f, SpriteEffects.None,
                                           current7.getStandingY() / 10000f);
                                }
                            }
                        }

                        b.End();
                        begun = false;
                    }

                    if (render.Lighting)
                    {
                        if (Game1.drawLighting)
                        {
                            b.Begin(SpriteSortMode.Deferred,
                                    Helper.Reflection.GetField <BlendState>(Game1.game1, "lightingBlend").GetValue(),
                                    SamplerState.LinearClamp, null, null, null, transform);
                            begun = true;
                            b.Draw(myLighting, Vector2.Zero, myLighting.Bounds, Color.White, 0f, Vector2.Zero,
                                   (float)(Game1.options.lightingQuality / 2) * 4, SpriteEffects.None, 1f);
                            if (render.Weather && Game1.isRaining && loc.IsOutdoors && !(loc is Desert))
                            {
                                b.Draw(Game1.staminaRect, output.Bounds, Color.OrangeRed * 0.45f);
                            }

                            b.End();
                            begun = false;
                        }
                    }
                }

                // This fixes the saved texture being transparent when there is lighting
                // Not a very CLEAN fix... But it works
                oldOutput = output;
                output    = new RenderTarget2D(dev, oldOutput.Width, oldOutput.Height);
                dev.SetRenderTarget(output);
                dev.Clear(Color.Black);
                b.Begin();
                begun = true;
                b.Draw(oldOutput, new Vector2(0, 0), Color.White);
                b.End();
                begun = false;
                dev.SetRenderTarget(null);

                string name = loc.Name;
                if (loc.uniqueName.Value != null)
                {
                    name = loc.uniqueName.Value;
                }

                string dirPath   = Path.Combine(Constants.ExecutionPath, "MapExport");
                string imagePath = Path.Combine(dirPath, $"{name}.png");
                Log.info($"Saving {name} to {Path.GetFullPath(imagePath)}...");

                if (!Directory.Exists(dirPath))
                {
                    Directory.CreateDirectory(dirPath);
                }

                stream = File.Create(imagePath);
                output.SaveAsPng(stream, output.Width, output.Height);
                stream.Dispose();
            }
            catch (Exception e)
            {
                Log.error("Exception: " + e);
            }
            finally
            {
                display.EndScene();
                if (begun)
                {
                    b.End();
                }
                dev.SetRenderTarget(null);
                stream?.Dispose();
                oldOutput?.Dispose();
                output?.Dispose();
                myLighting?.Dispose();
                //Game1.pixelZoom = oldZoom;
                Game1.viewport = oldView;
                Game1.options.desiredBaseZoomLevel = oldZoomL;
            }

            if (loc is DecoratableLocation location)
            {
                foreach (Furniture f in location.furniture)
                {
                    f.updateDrawPosition();
                }
            }
        }
Пример #26
0
 private bool performTreeFall(Tool t, int explosion, Vector2 tileLocation, GameLocation location)
 {
     if (!stump)
     {
         if (t != null || explosion > 0)
         {
             location.playSound("treecrack");
         }
         stump.Value   = true;
         health.Value  = 5f;
         falling.Value = true;
         if (t != null && t.getLastFarmerToUse().IsLocalPlayer)
         {
             t?.getLastFarmerToUse().gainExperience(2, 12);
             if (t == null || t.getLastFarmerToUse() == null)
             {
                 shakeLeft.Value = true;
             }
             else
             {
                 shakeLeft.Value = (t.getLastFarmerToUse().getTileLocation().X > tileLocation.X || (t.getLastFarmerToUse().getTileLocation().Y < tileLocation.Y && tileLocation.X % 2f == 0f));
             }
         }
     }
     else
     {
         if (t != null && (float)health != -100f && t.getLastFarmerToUse().IsLocalPlayer)
         {
             t?.getLastFarmerToUse().gainExperience(2, 1);
         }
         health.Value = -100f;
         Game1.createRadialDebris(location, 12, (int)tileLocation.X, (int)tileLocation.Y, Game1.random.Next(30, 40), resource: false, -1, item: false, ((int)treeType == 7) ? 10000 : (-1));
         int whatToDrop = ((int)treeType == 7 && tileLocation.X % 7f == 0f) ? 422 : (((int)treeType == 7) ? 420 : 92);
         if (Game1.IsMultiplayer)
         {
             Game1.recentMultiplayerRandom = new Random((int)tileLocation.X * 2000 + (int)tileLocation.Y);
             _ = Game1.recentMultiplayerRandom;
         }
         else
         {
             new Random((int)Game1.uniqueIDForThisGame + (int)Game1.stats.DaysPlayed + (int)tileLocation.X * 7 + (int)tileLocation.Y * 11);
         }
         if (t == null || t.getLastFarmerToUse() == null)
         {
             if (location.Equals(Game1.currentLocation))
             {
                 Game1.createMultipleObjectDebris(92, (int)tileLocation.X, (int)tileLocation.Y, 2, location);
             }
             else
             {
                 Game1.createItemDebris(new Object(92, 1), tileLocation * 64f, 2, location);
                 Game1.createItemDebris(new Object(92, 1), tileLocation * 64f, 2, location);
             }
         }
         else if (Game1.IsMultiplayer)
         {
             Game1.createMultipleObjectDebris(whatToDrop, (int)tileLocation.X, (int)tileLocation.Y, 1, lastPlayerToHit, location);
             if ((int)treeType != 7)
             {
                 Game1.createRadialDebris(location, 12, (int)tileLocation.X, (int)tileLocation.Y, (int)((Game1.getFarmer(lastPlayerToHit).professions.Contains(12) ? 1.25 : 1.0) * 4.0), resource: true);
             }
         }
         else
         {
             if ((int)treeType != 7)
             {
                 Game1.createRadialDebris(location, 12, (int)tileLocation.X, (int)tileLocation.Y, (int)((Game1.getFarmer(lastPlayerToHit).professions.Contains(12) ? 1.25 : 1.0) * (double)(5 + extraWoodCalculator(tileLocation))), resource: true);
             }
             Game1.createMultipleObjectDebris(whatToDrop, (int)tileLocation.X, (int)tileLocation.Y, 1, location);
         }
         location.playSound("treethud");
         if (!falling)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #27
0
        // Token: 0x060009CF RID: 2511 RVA: 0x000D0F24 File Offset: 0x000CF124
        public override bool performToolAction(Tool t, int explosion, Vector2 tileLocation, GameLocation location = null)
        {
            if (location == null)
            {
                location = Game1.currentLocation;
            }
            if ((t != null && t is MeleeWeapon && ((MeleeWeapon)t).type != 2) || explosion > 0)
            {
                if (t != null && (t as MeleeWeapon).type != 1)
                {
                    DelayedAction.playSoundAfterDelay("daggerswipe", 50);
                }
                else if (location.Equals(Game1.currentLocation))
                {
                    Game1.playSound("swordswipe");
                }
                this.shake(0.2945243f, 0.07853982f, Game1.random.NextDouble() < 0.5);
                int numberOfWeedsToDestroy;
                if (explosion > 0)
                {
                    numberOfWeedsToDestroy = Math.Max(1, explosion + 2 - Game1.recentMultiplayerRandom.Next(2));
                }
                else
                {
                    numberOfWeedsToDestroy = 1;
                }
                this.numberOfWeeds -= numberOfWeedsToDestroy;
                Color c = Color.Green;
                switch (this.grassType)
                {
                case 1:
                {
                    string currentSeason = Game1.currentSeason;
                    if (!(currentSeason == "spring"))
                    {
                        if (!(currentSeason == "summer"))
                        {
                            if (currentSeason == "fall")
                            {
                                c = new Color(219, 102, 58);
                            }
                        }
                        else
                        {
                            c = new Color(110, 190, 24);
                        }
                    }
                    else
                    {
                        c = new Color(60, 180, 58);
                    }
                    break;
                }

                case 2:
                    c = new Color(148, 146, 71);
                    break;

                case 3:
                    c = new Color(216, 240, 255);
                    break;

                case 4:
                    c = new Color(165, 93, 58);
                    break;
                }
                location.temporarySprites.Add(new TemporaryAnimatedSprite(28, tileLocation * (float)Game1.tileSize + new Vector2((float)Game1.random.Next(-Game1.pixelZoom * 4, Game1.pixelZoom * 4), (float)Game1.random.Next(-Game1.pixelZoom * 4, Game1.pixelZoom * 4)), c, 8, Game1.random.NextDouble() < 0.5, (float)Game1.random.Next(60, 100), 0, -1, -1f, -1, 0));
                if (this.numberOfWeeds <= 0)
                {
                    if (this.grassType != 1)
                    {
                        Random grassRandom = Game1.IsMultiplayer ? Game1.recentMultiplayerRandom : new Random((int)(Game1.uniqueIDForThisGame + tileLocation.X * 1000f + tileLocation.Y * 11f + (float)Game1.mine.mineLevel + (float)Game1.player.timesReachedMineBottom));
                        if (grassRandom.NextDouble() < 0.005)
                        {
                            Game1.createObjectDebris(114, (int)tileLocation.X, (int)tileLocation.Y, -1, 0, 1f, null);
                        }
                        else if (grassRandom.NextDouble() < 0.01)
                        {
                            Game1.createDebris(4, (int)tileLocation.X, (int)tileLocation.Y, grassRandom.Next(1, 2), null);
                        }
                        else if (grassRandom.NextDouble() < 0.02)
                        {
                            Game1.createDebris(92, (int)tileLocation.X, (int)tileLocation.Y, grassRandom.Next(2, 4), null);
                        }
                    }
                    else if (t is MeleeWeapon && (t.Name.Contains("Scythe") || t.parentSheetIndex == 47) && (Game1.IsMultiplayer ? Game1.recentMultiplayerRandom : new Random((int)(Game1.uniqueIDForThisGame + tileLocation.X * 1000f + tileLocation.Y * 11f))).NextDouble() < 0.5 && (Game1.getLocationFromName("Farm") as Farm).tryToAddHay(1) == 0)
                    {
                        TemporaryAnimatedSprite tmpSprite = new TemporaryAnimatedSprite(Game1.objectSpriteSheet, Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, 178, 16, 16), 750f, 1, 0, t.getLastFarmerToUse().position - new Vector2(0f, (float)(Game1.tileSize * 2)), false, false, t.getLastFarmerToUse().position.Y / 10000f, 0.005f, Color.White, (float)Game1.pixelZoom, -0.005f, 0f, 0f, false);
                        tmpSprite.motion.Y   = -1f;
                        tmpSprite.layerDepth = 1f - (float)Game1.random.Next(100) / 10000f;
                        tmpSprite.delayBeforeAnimationStart = Game1.random.Next(350);
                        t.getLastFarmerToUse().currentLocation.temporarySprites.Add(tmpSprite);
                        Game1.addHUDMessage(new HUDMessage("Hay", 1, true, Color.LightGoldenrodYellow, new Object(178, 1, false, -1, 0)));
                    }
                    return(true);
                }
            }
            return(false);
        }
Пример #28
0
 public virtual void update(GameTime time, GameLocation location, long id, bool move)
 {
     if (this.yJumpOffset != 0)
     {
         this.yJumpVelocity -= 0.5f;
         this.yJumpOffset   -= (int)this.yJumpVelocity;
         if (this.yJumpOffset >= 0)
         {
             this.yJumpOffset   = 0;
             this.yJumpVelocity = 0f;
             if (!this.IsMonster && (location == null || location.Equals(Game1.currentLocation)))
             {
                 FarmerSprite.checkForFootstep(this);
             }
         }
     }
     if (this.faceTowardFarmerTimer > 0)
     {
         this.faceTowardFarmerTimer -= time.ElapsedGameTime.Milliseconds;
         if (!this.faceTowardFarmer && this.faceTowardFarmerTimer > 0 && Utility.tileWithinRadiusOfPlayer((int)this.getTileLocation().X, (int)this.getTileLocation().Y, this.faceTowardFarmerRadius, this.whoToFace))
         {
             this.faceTowardFarmer = true;
         }
         else if (!Utility.tileWithinRadiusOfPlayer((int)this.getTileLocation().X, (int)this.getTileLocation().Y, this.faceTowardFarmerRadius, this.whoToFace) || this.faceTowardFarmerTimer <= 0)
         {
             this.faceDirection(this.facingDirectionBeforeSpeakingToPlayer);
             if (this.faceTowardFarmerTimer <= 0)
             {
                 this.facingDirectionBeforeSpeakingToPlayer = -1;
                 this.faceTowardFarmer      = false;
                 this.faceAwayFromFarmer    = false;
                 this.faceTowardFarmerTimer = 0;
             }
         }
     }
     if (this.forceUpdateTimer > 0)
     {
         this.forceUpdateTimer -= time.ElapsedGameTime.Milliseconds;
     }
     this.updateGlow();
     this.updateEmote(time);
     if (!Game1.IsMultiplayer || Game1.IsServer || this.ignoreMultiplayerUpdates)
     {
         if (this.faceTowardFarmer && this.whoToFace != null)
         {
             this.faceGeneralDirection(this.whoToFace.getStandingPosition(), 0);
             if (this.faceAwayFromFarmer)
             {
                 this.faceDirection((this.facingDirection + 2) % 4);
             }
         }
         if ((this.controller == null & move) && !this.freezeMotion)
         {
             this.updateMovement(location, time);
         }
         if (this.controller != null && !this.freezeMotion && this.controller.update(time))
         {
             this.controller = null;
         }
         if (Game1.IsServer && !Game1.isFestival() && Game1.random.NextDouble() < 0.2)
         {
             MultiplayerUtility.broadcastNPCMove((int)this.position.X, (int)this.position.Y, id, location);
             return;
         }
     }
     else if (!Game1.eventUp)
     {
         this.lerpPosition(this.positionToLerpTo);
         if (this.distanceFromLastServerPosition() >= 8f)
         {
             this.animateInFacingDirection(time);
         }
     }
 }
Пример #29
0
        public override bool performToolAction(
            Tool t,
            int explosion,
            Vector2 tileLocation,
            GameLocation location)
        {
            if (location == null)
            {
                location = Game1.currentLocation;
            }
            if (explosion > 0)
            {
                this.tapped.Value = false;
            }
            if (this.tapped.Value)
            {
                return(false);
            }
            Console.WriteLine("TREE: IsClient:" + Game1.IsClient.ToString() + " randomOutput: " + (object)Game1.recentMultiplayerRandom.Next(9999));
            if ((double)this.health.Value <= -99.0)
            {
                return(false);
            }
            if (this.growthStage.Value >= 5)
            {
                if (t != null && t is Axe)
                {
                    location.playSound("axchop");
                    location.debris.Add(new Debris(12, Game1.random.Next(1, 3), t.getLastFarmerToUse().GetToolLocation(false) + new Vector2(16f, 0.0f), t.getLastFarmerToUse().Position, 0, -1));
                    this.lastPlayerToHit.Value = t.getLastFarmerToUse().UniqueMultiplayerID;
                    if (!this.stump.Value && t.getLastFarmerToUse() != null && (t.getLastFarmerToUse().hasMagnifyingGlass&& Game1.random.NextDouble() < 0.005))
                    {
                        StardewValley.Object unseenSecretNote = location.tryToCreateUnseenSecretNote(t.getLastFarmerToUse());
                        if (unseenSecretNote != null)
                        {
                            Game1.createItemDebris((Item)unseenSecretNote, new Vector2(tileLocation.X, tileLocation.Y - 3f) * 64f, -1, (GameLocation)null, Game1.player.getStandingY() - 32);
                        }
                    }
                }
                else if (explosion <= 0)
                {
                    return(false);
                }
                this.shake(tileLocation, true);
                float num = 1f;
                if (explosion > 0)
                {
                    num = (float)explosion;
                }
                else
                {
                    if (t == null)
                    {
                        return(false);
                    }
                    switch (t.UpgradeLevel)
                    {
                    case 0:
                        num = 1f;
                        break;

                    case 1:
                        num = 1.25f;
                        break;

                    case 2:
                        num = 1.67f;
                        break;

                    case 3:
                        num = 2.5f;
                        break;

                    case 4:
                        num = 5f;
                        break;
                    }
                }
                this.health.Value -= num;
                if ((double)this.health.Value <= 0.0)
                {
                    if (!this.stump.Value)
                    {
                        if (t != null || explosion > 0)
                        {
                            location.playSound("treecrack");
                        }
                        this.stump.Value   = true;
                        this.health.Value  = 5f;
                        this.falling.Value = true;
                        if (t != null && t.getLastFarmerToUse().IsLocalPlayer)
                        {
                            t?.getLastFarmerToUse().gainExperience(2, 12);
                            if (t == null || t.getLastFarmerToUse() == null)
                            {
                                this.shakeLeft.Value = true;
                            }
                            else
                            {
                                this.shakeLeft.Value = (double)t.getLastFarmerToUse().getTileLocation().X > (double)tileLocation.X || (double)t.getLastFarmerToUse().getTileLocation().Y < (double)tileLocation.Y && (double)tileLocation.X % 2.0 == 0.0;
                            }
                        }
                    }
                    else
                    {
                        if (t != null && (double)this.health.Value != -100.0 && (t.getLastFarmerToUse().IsLocalPlayer&& t != null))
                        {
                            t.getLastFarmerToUse().gainExperience(2, 1);
                        }
                        this.health.Value = -100f;
                        Game1.createRadialDebris(location, 12, (int)tileLocation.X, (int)tileLocation.Y, Game1.random.Next(30, 40), false, -1, false, -1);

                        //this produces eitehr sap or mushrooms currently.  Tweak perhaps to drop voidshroom bark to process into wood? Just drop wood directly?
                        int index = (double)tileLocation.X % 7.0 != 0.0 ? 388 : 709;
                        if (Game1.IsMultiplayer)
                        {
                            Game1.recentMultiplayerRandom = new Random((int)tileLocation.X * 2000 + (int)tileLocation.Y);
                            Random multiplayerRandom = Game1.recentMultiplayerRandom;
                        }
                        else
                        {
                            Random random = new Random((int)Game1.uniqueIDForThisGame + (int)Game1.stats.DaysPlayed + (int)tileLocation.X * 7 + (int)tileLocation.Y * 11);
                        }
                        if (t == null || t.getLastFarmerToUse() == null)
                        {
                            if (location.Equals(Game1.currentLocation))
                            {
                                Game1.createMultipleObjectDebris(92, (int)tileLocation.X, (int)tileLocation.Y, 2);
                            }
                            else
                            {
                                Game1.createItemDebris((Item) new StardewValley.Object(92, 1, false, -1, 0), tileLocation * 64f, 2, location, -1);
                                Game1.createItemDebris((Item) new StardewValley.Object(92, 1, false, -1, 0), tileLocation * 64f, 2, location, -1);
                            }
                        }
                        else if (Game1.IsMultiplayer)
                        {
                            Game1.createMultipleObjectDebris(index, (int)tileLocation.X, (int)tileLocation.Y, 1, this.lastPlayerToHit.Value);

                            Game1.createRadialDebris(location, 12, (int)tileLocation.X, (int)tileLocation.Y, 4, true, -1, false, -1);
                        }
                        else
                        {
                            Game1.createRadialDebris(location, 12, (int)tileLocation.X, (int)tileLocation.Y, 5 + this.extraWoodCalculator(tileLocation), true, -1, false, -1);
                            Game1.createMultipleObjectDebris(index, (int)tileLocation.X, (int)tileLocation.Y, 1);
                        }
                        location.playSound("treethud");
                        if (!this.falling.Value)
                        {
                            return(true);
                        }
                    }
                }
            }
            else if (this.growthStage.Value >= 3)
            {
                if (t != null && t.BaseName.Contains("Ax"))
                {
                    location.playSound("axchop");
                    location.debris.Add(new Debris(12, Game1.random.Next(t.UpgradeLevel * 2, t.UpgradeLevel * 4), t.getLastFarmerToUse().GetToolLocation(false) + new Vector2(16f, 0.0f), new Vector2((float)t.getLastFarmerToUse().GetBoundingBox().Center.X, (float)t.getLastFarmerToUse().GetBoundingBox().Center.Y), 0, -1));
                }
                else if (explosion <= 0)
                {
                    return(false);
                }
                this.shake(tileLocation, true);
                float num = 1f;
                if (Game1.IsMultiplayer)
                {
                    Random multiplayerRandom = Game1.recentMultiplayerRandom;
                }
                else
                {
                    Random random = new Random((int)((double)Game1.uniqueIDForThisGame + (double)tileLocation.X * 7.0 + (double)tileLocation.Y * 11.0 + (double)Game1.stats.DaysPlayed + (double)this.health.Value));
                }
                if (explosion > 0)
                {
                    num = (float)explosion;
                }
                else
                {
                    switch (t.UpgradeLevel)
                    {
                    case 0:
                        num = 2f;
                        break;

                    case 1:
                        num = 2.5f;
                        break;

                    case 2:
                        num = 3.34f;
                        break;

                    case 3:
                        num = 5f;
                        break;

                    case 4:
                        num = 10f;
                        break;
                    }
                }
                this.health.Value -= num;
                if ((double)this.health.Value <= 0.0)
                {
                    Game1.createDebris(12, (int)tileLocation.X, (int)tileLocation.Y, 4, (GameLocation)null);
                    Game1.createRadialDebris(location, 12, (int)tileLocation.X, (int)tileLocation.Y, Game1.random.Next(20, 30), false, -1, false, -1);
                    return(true);
                }
            }
            else if (this.growthStage.Value >= 1)
            {
                if (explosion > 0)
                {
                    return(true);
                }
                location.playSound("cut");
                if (t != null && t.BaseName.Contains("Axe"))
                {
                    location.playSound("axchop");
                    Game1.createRadialDebris(location, 12, (int)tileLocation.X, (int)tileLocation.Y, Game1.random.Next(10, 20), false, -1, false, -1);
                }
                if (t is Axe || t is Pickaxe || (t is Hoe || t is MeleeWeapon))
                {
                    Game1.createRadialDebris(location, 12, (int)tileLocation.X, (int)tileLocation.Y, Game1.random.Next(10, 20), false, -1, false, -1);
                    if (t.BaseName.Contains("Axe") && Game1.recentMultiplayerRandom.NextDouble() < (double)t.getLastFarmerToUse().ForagingLevel / 10.0)
                    {
                        Game1.createDebris(12, (int)tileLocation.X, (int)tileLocation.Y, 1, (GameLocation)null);
                    }
                    //TODO: come back and figure out this sprite broadcasting thing
                    //Game1.multiplayer.broadcastSprites(location, new TemporaryAnimatedSprite(17, tileLocation * 64f, Color.White, 8, false, 100f, 0, -1, -1f, -1, 0));
                    return(true);
                }
            }
            else
            {
                if (explosion > 0)
                {
                    return(true);
                }
                if (t.BaseName.Contains("Axe") || t.BaseName.Contains("Pick") || t.BaseName.Contains("Hoe"))
                {
                    location.playSound("woodyHit");
                    location.playSound("axchop");
                    //TODO: come back and figure out this sprite broadcasting thing
                    //Game1.multiplayer.broadcastSprites(location, new TemporaryAnimatedSprite(17, tileLocation * 64f, Color.White, 8, false, 100f, 0, -1, -1f, -1, 0));
                    int seedIndex = VoidshroomSpore.getIndex();
                    if ((long)this.lastPlayerToHit.Value != 0L && Game1.getFarmer((long)this.lastPlayerToHit.Value).getEffectiveSkillLevel(2) >= 1 && seedIndex != -1)
                    {
                        Game1.createMultipleObjectDebris(seedIndex, (int)tileLocation.X, (int)tileLocation.Y, 1, t.getLastFarmerToUse().UniqueMultiplayerID, location);
                    }
                    else if (Game1.player.getEffectiveSkillLevel(2) >= 1 && seedIndex != -1)
                    {
                        Game1.createMultipleObjectDebris(seedIndex, (int)tileLocation.X, (int)tileLocation.Y, 1, (long)t.getLastFarmerToUse().UniqueMultiplayerID, location);
                    }

                    return(true);
                }
            }
            return(false);
        }
Пример #30
0
 public virtual void update(GameTime time, GameLocation location, long id, bool move)
 {
     position.UpdateExtrapolation(speed + addedSpeed);
     currentLocation = location;
     faceTowardFarmerEvent.Poll();
     if (yJumpOffset != 0)
     {
         yJumpVelocity -= 0.5f;
         yJumpOffset   -= (int)yJumpVelocity;
         if (yJumpOffset >= 0)
         {
             yJumpOffset   = 0;
             yJumpVelocity = 0f;
             if (!IsMonster && (location == null || location.Equals(Game1.currentLocation)))
             {
                 checkForFootstep();
             }
         }
     }
     if (faceTowardFarmerTimer > 0)
     {
         faceTowardFarmerTimer -= time.ElapsedGameTime.Milliseconds;
         if (whoToFace.Value != null)
         {
             if (!faceTowardFarmer && faceTowardFarmerTimer > 0 && Utility.tileWithinRadiusOfPlayer((int)getTileLocation().X, (int)getTileLocation().Y, faceTowardFarmerRadius, whoToFace))
             {
                 faceTowardFarmer = true;
             }
             else if (!Utility.tileWithinRadiusOfPlayer((int)getTileLocation().X, (int)getTileLocation().Y, faceTowardFarmerRadius, whoToFace) || faceTowardFarmerTimer <= 0)
             {
                 faceDirection(facingDirectionBeforeSpeakingToPlayer.Value);
                 if (faceTowardFarmerTimer <= 0)
                 {
                     facingDirectionBeforeSpeakingToPlayer.Value = -1;
                     faceTowardFarmer         = false;
                     faceAwayFromFarmer.Value = false;
                     faceTowardFarmerTimer    = 0;
                 }
             }
         }
     }
     if (forceUpdateTimer > 0)
     {
         forceUpdateTimer -= time.ElapsedGameTime.Milliseconds;
     }
     updateGlow();
     updateEmote(time);
     if (Game1.IsMasterGame || location.currentEvent != null)
     {
         if (faceTowardFarmer && whoToFace.Value != null)
         {
             faceGeneralDirection(whoToFace.Value.getStandingPosition());
             if ((bool)faceAwayFromFarmer)
             {
                 faceDirection((FacingDirection + 2) % 4);
             }
         }
         if (controller == null && move && !freezeMotion)
         {
             updateMovement(location, time);
         }
         if (controller != null && !freezeMotion && controller.update(time))
         {
             controller = null;
         }
     }
     else
     {
         updateSlaveAnimation(time);
     }
 }