Exemple #1
0
 public void unload()
 {
     if (chargeSound != null)
     {
         chargeSound.Stop(AudioStopOptions.Immediate);
         chargeSound = null;
     }
     Game1.stopMusicTrack(Game1.MusicContext.MiniGame);
     Game1.player.faceDirection(0);
 }
        /// <summary>Make a new Sound Manager to play and manage sounds in a modded wave bank.</summary>
        /// <param name="newWaveBank">The reference to the wave bank in the mod's asset folder.</param>
        /// <param name="newSoundBank">The reference to the sound bank in the mod's asset folder.</param>
        public XACTSound(WaveBank newWaveBank, ISoundBank newSoundBank, string soundName)
        {
            this.waveBank  = newWaveBank;
            this.soundBank = newSoundBank;

            this.vanillaSoundBank = Game1.soundBank;
            this.vanillaWaveBank  = Game1.waveBank;
            this.soundName        = soundName;
            this.song             = this.soundBank.GetCue(this.soundName);
        }
Exemple #3
0
            public void activate()
            {
                glowTimer  = 1000f;
                shakeTimer = 100f;
                ICue cue = Game1.soundBank.GetCue("crystal");

                cue.SetVariable("Pitch", pitch);
                cue.Play();
                currentColor = color;
            }
Exemple #4
0
        public Leafbeast(CropTile cropTile, bool primary)
            : base(cropTile, primary, primary, !primary)
        {
            Slipperiness = 18 + Game1.random.Next(-8, 8);
            Halt();
            IsWalkingTowardPlayer = false;
            HideShadow            = true;

            sound = Game1.soundBank.GetCue("batFlap");
        }
Exemple #5
0
        // Tries to stop a sound cue, but uses reflection and ignores the
        // nonexistence of the method since some players have a version of the
        // game and/or XNA that doesn't like this.
        public static void TryStopCue(ICue cue)
        {
            IReflectedMethod stop =
                Helper.Reflection.GetMethod(cue, "Stop", false);

            if (stop != null)
            {
                stop.Invoke(AudioStopOptions.AsAuthored);
            }
        }
Exemple #6
0
 protected override void updateAnimation(GameTime time)
 {
     if (base.focusedOnFarmers || withinPlayerThreshold(6) || (bool)seenPlayer || magmaSprite.Value)
     {
         Sprite.Animate(time, 0, 4, 80f);
         if (Sprite.currentFrame % 3 == 0 && Utility.isOnScreen(base.Position, 512) && (batFlap == null || !batFlap.IsPlaying) && Game1.soundBank != null && base.currentLocation == Game1.currentLocation && !cursedDoll)
         {
             batFlap = Game1.soundBank.GetCue("batFlap");
             batFlap.Play();
         }
         if (cursedDoll.Value)
         {
             shakeTimer -= time.ElapsedGameTime.Milliseconds;
             if (shakeTimer < 0)
             {
                 shakeTimer = 50;
                 if (magmaSprite.Value)
                 {
                     shakeTimer = ((lungeTimer > 0) ? 50 : 100);
                     base.currentLocation.temporarySprites.Add(new TemporaryAnimatedSprite("Characters\\Monsters\\Magma Sprite", new Rectangle(0, 64, 8, 8), position + new Vector2(Game1.random.Next(32), -16 - Game1.random.Next(32)), flipped: false, 0f, Color.White)
                     {
                         scale              = 4f,
                         scaleChange        = -0.05f,
                         motion             = new Vector2((lungeTimer > 0) ? ((float)Game1.random.Next(-30, 31) / 10f) : 0f, (0f - maxSpeed) / ((lungeTimer > 0) ? 2f : 8f)),
                         layerDepth         = 0.9f,
                         animationLength    = 6,
                         totalNumberOfLoops = 1,
                         interval           = 50f,
                         xPeriodic          = (lungeTimer <= 0),
                         xPeriodicLoopTime  = Game1.random.Next(500, 800),
                         xPeriodicRange     = 4 * ((lungeTimer <= 0) ? 1 : 2)
                     });
                 }
                 else if (!hauntedSkull.Value)
                 {
                     base.currentLocation.temporarySprites.Add(new TemporaryAnimatedSprite("Maps\\springobjects", Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, 103, 16, 16), position + new Vector2(0f, -32f), flipped: false, 0.1f, new Color(255, 50, 255) * 0.8f)
                     {
                         scale = 4f
                     });
                 }
             }
             previousPositions.Add(base.Position);
             if (previousPositions.Count > 8)
             {
                 previousPositions.RemoveAt(0);
             }
         }
     }
     else
     {
         Sprite.currentFrame = 4;
         Halt();
     }
     resetAnimationSpeed();
 }
Exemple #7
0
        public Coffeebeast(CropTile cropTile, bool primary)
            : base(cropTile, primary, primary, !primary)
        {
            IsWalkingTowardPlayer = false;
            chargingFarmer        = Game1.random.NextDouble() < 0.8;
            Sprite.interval       = 100f;
            HideShadow            = true;

            // Randomly vary the size and meeping pitch.
            Scale       = Game1.random.Next(75, 101) / 100f;
            meep        = Game1.soundBank.GetCue("dustMeep");
            voice.Value = (byte)Game1.random.Next(1, 24);
        }
Exemple #8
0
 public void PlayTrainApproach()
 {
     if ((bool)Game1.currentLocation.isOutdoors && !Game1.isFestival() && Game1.currentLocation.GetLocationContext() == LocationContext.Default)
     {
         Game1.showGlobalMessage(Game1.content.LoadString("Strings\\Locations:Railroad_TrainComing"));
         if (Game1.soundBank != null)
         {
             ICue cue = Game1.soundBank.GetCue("distantTrain");
             cue.SetVariable("Volume", 100f);
             cue.Play();
         }
     }
 }
        public static void PlaySingingStone(SObject @object)
        {
            if (Game1.soundBank is not null)
            {
                @object.shakeTimer = 100;

                ICue cue   = Game1.soundBank.GetCue("crystal");
                int  pitch = Game1.random.Next(2400);
                pitch -= pitch % 100;
                cue.SetVariable("Pitch", pitch);
                cue.Play();
            }
        }
Exemple #10
0
 public override void loadSprite()
 {
     try
     {
         if (Game1.soundBank != null)
         {
             grassSound = Game1.soundBank.GetCue("grassyStep");
         }
         if ((byte)grassType == 1)
         {
             string seasonForLocation = Game1.GetSeasonForLocation(currentLocation);
             if (!(seasonForLocation == "spring"))
             {
                 if (!(seasonForLocation == "summer"))
                 {
                     if (seasonForLocation == "fall")
                     {
                         grassSourceOffset.Value = 40;
                     }
                 }
                 else
                 {
                     grassSourceOffset.Value = 20;
                 }
             }
             else
             {
                 grassSourceOffset.Value = 0;
             }
         }
         else if ((byte)grassType == 2)
         {
             grassSourceOffset.Value = 60;
         }
         else if ((byte)grassType == 3)
         {
             grassSourceOffset.Value = 80;
         }
         else if ((byte)grassType == 4)
         {
             grassSourceOffset.Value = 100;
         }
         else
         {
             grassSourceOffset.Value = ((byte)grassType + 1) * 20;
         }
     }
     catch (Exception)
     {
     }
 }
        public static bool prefix_playTrainApproach()
        {
            bool showMessage = true;
            bool playSound   = true;

            if (!Game1.currentLocation.IsOutdoors || Game1.isFestival())
            {
                return(false);
            }

            if (BetterTrainLootMod.Instance.config.enableMod)
            {
                if (!BetterTrainLootMod.Instance.config.showTrainIsComingMessage ||
                    (Game1.player.currentLocation.Name == "Desert" && !BetterTrainLootMod.Instance.config.showDesertTrainIsComingMessage) ||
                    (Game1.player.currentLocation is IslandLocation && !BetterTrainLootMod.Instance.config.showIslandTrainIsComingMessage)
                    )
                {
                    showMessage = false;
                }

                if (showMessage)
                {
                    Game1.showGlobalMessage(Game1.content.LoadString("Strings\\Locations:Railroad_TrainComing"));
                }

                if (Game1.soundBank == null)
                {
                    return(false);
                }

                if (!BetterTrainLootMod.Instance.config.enableTrainWhistle ||
                    (Game1.player.currentLocation.Name == "Desert" && !BetterTrainLootMod.Instance.config.enableDesertTrainWhistle) ||
                    (Game1.player.currentLocation is IslandLocation && !BetterTrainLootMod.Instance.config.enableIslandTrainWhistle)
                    )
                {
                    playSound = false;
                }

                if (playSound)
                {
                    ICue cue = Game1.soundBank.GetCue("distantTrain");
                    cue.SetVariable("Volume", 100f);
                    cue.Play();
                }
                return(false);
            }
            return(true);
        }
 protected override void updateAnimation(GameTime time)
 {
     Sprite.AnimateDown(time);
     if (yJumpOffset == 0)
     {
         jumpWithoutSound();
         yJumpVelocity = (float)Game1.random.Next(50, 70) / 10f;
         if (Game1.random.NextDouble() < 0.1 && (meep == null || !meep.IsPlaying) && Utility.isOnScreen(base.Position, 64) && Game1.soundBank != null && Game1.currentLocation == base.currentLocation)
         {
             meep = Game1.soundBank.GetCue("dustMeep");
             meep.SetVariable("Pitch", voice * 100 + Game1.random.Next(-100, 100));
             meep.Play();
         }
     }
     resetAnimationSpeed();
 }
 public OldMineCart(int whichTheme, int mode)
 {
     changeScreenSize();
     maxJumpHeight = (float)(64 / pixelScale) * 5f;
     texture       = Game1.content.Load <Texture2D>("Minigames\\MineCart");
     if (Game1.soundBank != null)
     {
         minecartLoop = Game1.soundBank.GetCue("minecartLoop");
         minecartLoop.Play();
     }
     ytileOffset = screenHeight / 2 / tileSize;
     gameMode    = mode;
     setGameModeParameters();
     setUpTheme(whichTheme);
     createBeginningOfLevel();
     screenDarkness = 1f;
 }
        /// <summary>Initializes and enables this class.</summary>
        /// <param name="helper">The <see cref="IModHelper"/> provided by SMAPI. Used for events and other API access.</param>
        /// <param name="monitor">The <see cref="IMonitor"/> provided by SMAPI. Used for log messages.</param>
        public static void Enable(IModHelper helper, IMonitor monitor)
        {
            if (!Enabled) //if not already enabled
            {
                //store SMAPI tools
                Helper  = helper;
                Monitor = monitor;

                //replace ambient engine sound with a custom wrapper
                Monitor.Log($"Replacing sound cue \"{nameof(AmbientLocationSounds)}.engine\" with a wrapper for volume control.", LogLevel.Trace);
                var  engineField = Helper.Reflection.GetField <ICue>(typeof(AmbientLocationSounds), "engine", true); //reflect the field
                ICue engine      = engineField.GetValue();                                                           //get the cue
                engineField.SetValue(new CueWrapper(engine));                                                        //create a wrapper and replace the original with it

                Enabled = true;
            }
        }
Exemple #15
0
 public Intro()
 {
     texture         = Game1.content.Load <Texture2D>("Minigames\\Intro");
     roadsideTexture = Game1.content.Load <Texture2D>("Maps\\spring_outdoorsTileSheet");
     cloudTexture    = Game1.content.Load <Texture2D>("Minigames\\Clouds");
     transformMatrix = Matrix.CreateScale(3f);
     skyColor        = new Color(64, 136, 248);
     roadColor       = new Color(130, 130, 130);
     createBeginningOfLevel();
     Game1.player.FarmerSprite.SourceRect = new Rectangle(0, 0, 16, 32);
     bigCloudPosition = cloudTexture.Width;
     if (Game1.soundBank != null)
     {
         roadNoise = Game1.soundBank.GetCue("roadnoise");
     }
     currentState = 1;
     Game1.changeMusicTrack("spring_day_ambient");
 }
Exemple #16
0
        private void AttemptToWarp(TrainStop stop)
        {
            if (!TryToChargeMoney(stop.Cost))
            {
                Game1.drawObjectDialogue(Helper.Translation.Get("NotEnoughMoney", new { DestinationName = stop.TranslatedName }));
                return;
            }
            LocationRequest request = Game1.getLocationRequest(stop.TargetMapName);

            request.OnWarp    += Request_OnWarp;
            destinationMessage = Helper.Translation.Get("ArrivalMessage", new { DestinationName = stop.TranslatedName });

            Game1.warpFarmer(request, stop.TargetX, stop.TargetY, stop.FacingDirectionAfterWarp);

            cue = Game1.soundBank.GetCue("trainLoop");
            cue.SetVariable("Volume", 100f);
            cue.Play();
        }
Exemple #17
0
        private ICue FixCue(SoundBank newSoundBank, ICue cue)
        {
            ICue fixedCue = null;

            if (cue != null)
            {
                fixedCue = new CueWrapper(newSoundBank.GetCue(cue.Name));
                if (cue.IsPaused)
                {
                    fixedCue.Play();
                    fixedCue.Pause();
                }
                if (cue.IsPlaying)
                {
                    fixedCue.Play();
                }
            }
            return(fixedCue);
        }
Exemple #18
0
        /// <summary>Raised after the game state is updated (≈60 times per second).</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
        {
            if (this.Cue != null)
            {
                ICue sound = this.Cue;
                sound.SetVariable("Volume", 100);
                sound.SetVariable("Frequency", this.Frequency);
                sound.SetVariable("Pitch", this.Pitch);
                if (!sound.IsPlaying)
                {
                    sound.Play();
                }

                if (e.IsMultipleOf(30))
                {
                    this.Monitor.Log($"Playing {sound.Name} from {this.Source} @ freq: {sound.GetVariable("Frequency")}, vol: {sound.GetVariable("Volume")}, pitch: {sound.GetVariable("Pitch")}, state: {this.GetPlaybackState(sound)}");
                }
            }
        }
Exemple #19
0
 protected override void updateAnimation(GameTime time)
 {
     if (base.focusedOnFarmers || withinPlayerThreshold(6) || (bool)seenPlayer)
     {
         Sprite.Animate(time, 0, 4, 80f);
         if (Sprite.currentFrame % 3 == 0 && Utility.isOnScreen(base.Position, 512) && (batFlap == null || !batFlap.IsPlaying) && Game1.soundBank != null && base.currentLocation == Game1.currentLocation && !cursedDoll)
         {
             batFlap = Game1.soundBank.GetCue("batFlap");
             batFlap.Play();
         }
         if (cursedDoll.Value)
         {
             shakeTimer -= time.ElapsedGameTime.Milliseconds;
             if (shakeTimer < 0)
             {
                 if (!hauntedSkull.Value)
                 {
                     base.currentLocation.temporarySprites.Add(new TemporaryAnimatedSprite("Maps\\springobjects", Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, 103, 16, 16), position + new Vector2(0f, -32f), flipped: false, 0.1f, new Color(255, 50, 255) * 0.8f)
                     {
                         scale = 4f
                     });
                 }
                 shakeTimer = 50;
             }
             previousPositions.Add(base.Position);
             if (previousPositions.Count > 8)
             {
                 previousPositions.RemoveAt(0);
             }
         }
     }
     else
     {
         Sprite.currentFrame = 4;
         Halt();
     }
     resetAnimationSpeed();
 }
Exemple #20
0
        public Beam(Farmer who, Vector2 aim)
        {
            this.Shooter = who;
            this.BasePos = this.Shooter.getStandingPosition();
            this.Sound   = Game1.soundBank.GetCue("throwDownITem");
            this.Sound.Play();

            switch (who.FacingDirection)
            {
            case 2: this.BasePos.X += 44; this.BasePos.Y += 12; break;

            case 0: this.BasePos.X += -26; this.BasePos.Y += -100; break;

            case 3: this.BasePos.X += -40; this.BasePos.Y += -90; break;

            case 1: this.BasePos.X += 40; this.BasePos.Y += -90; break;
            }

            this.Angle = (float)Math.Atan2(this.BasePos.Y - aim.Y, this.BasePos.X - aim.X);

            Mod.Instance.Helper.Events.GameLoop.UpdateTicked += this.Update;
            Mod.Instance.Helper.Events.Display.RenderedWorld += this.Render;
        }
Exemple #21
0
        public Beam(Farmer who, Vector2 aim)
        {
            shooter = who;
            basePos = shooter.getStandingPosition();
            sound   = Game1.soundBank.GetCue("throwDownITem");
            sound.Play();

            switch (who.FacingDirection)
            {
            case 2: basePos.X += 44; basePos.Y += 12; break;

            case 0: basePos.X += -26; basePos.Y += -100; break;

            case 3: basePos.X += -40; basePos.Y += -90; break;

            case 1: basePos.X += 40; basePos.Y += -90; break;
            }

            angle = (float)Math.Atan2(basePos.Y - aim.Y, basePos.X - aim.X);

            Mod.instance.Helper.Events.GameLoop.UpdateTicked += update;
            Mod.instance.Helper.Events.Display.RenderedWorld += render;
        }
Exemple #22
0
        public void run(TV tv, Channel channel)
        {
            currentTV      = tv;
            currentChannel = channel;

            if (beforeAction != null)
            {
                beforeAction.Invoke();
            }

            Game1.changeMusicTrack(musicTrack ?? "none", false,
                                   Game1.MusicContext.Event);

            if (soundAsset != null &&
                Constants.TargetPlatform != GamePlatform.Android)
            {
                playCustomSound($"{soundAsset}.wav");
            }
            else if (soundCue != null)
            {
                ICue cue = Game1.soundBank.GetCue(soundCue);
                if (soundCue == "distantTrain")
                {
                    cue.SetVariable("Volume", 100f);
                }
                cue.Play();
            }


            Helper.Reflection.GetField <TemporaryAnimatedSprite> (tv, "screen")
            .SetValue(background);
            Helper.Reflection.GetField <TemporaryAnimatedSprite> (tv, "screenOverlay")
            .SetValue(overlay);
            Game1.drawObjectDialogue(Game1.parseText(message));

            Game1.afterDialogues = end;
        }
Exemple #23
0
 public override void doCollisionAction(Rectangle positionOfCollider, int speedOfCollision, Vector2 tileLocation, Character who, GameLocation location)
 {
     if (location != Game1.currentLocation)
     {
         return;
     }
     if (speedOfCollision > 0 && maxShake == 0f && positionOfCollider.Intersects(getBoundingBox(tileLocation)))
     {
         if ((who == null || !(who is FarmAnimal)) && grassSound != null && !grassSound.IsPlaying && Utility.isOnScreen(new Point((int)tileLocation.X, (int)tileLocation.Y), 2, location) && Game1.soundBank != null)
         {
             grassSound = Game1.soundBank.GetCue("grassyStep");
             grassSound.Play();
         }
         shake((float)Math.PI / 8f / (float)((5 + Game1.player.addedSpeed) / speedOfCollision), (float)Math.PI / 80f / (float)((5 + Game1.player.addedSpeed) / speedOfCollision), (float)positionOfCollider.Center.X > tileLocation.X * 64f + 32f);
     }
     if (who is Farmer && Game1.player.CurrentTool != null && Game1.player.CurrentTool is MeleeWeapon && ((MeleeWeapon)Game1.player.CurrentTool).isOnSpecial && (int)((MeleeWeapon)Game1.player.CurrentTool).type == 0 && Math.Abs(shakeRotation) < 0.001f && performToolAction(Game1.player.CurrentTool, -1, tileLocation, location))
     {
         Game1.currentLocation.terrainFeatures.Remove(tileLocation);
     }
     if (who is Farmer)
     {
         (who as Farmer).temporarySpeedBuff = -1f;
     }
 }
        public override void DoFunction(GameLocation location, int x, int y, int power, StardewValley.Farmer who)
        {
            base.DoFunction(location, x, y, power, who);
            who.Stamina -= ((float)4f - (float)who.FarmingLevel * 0.2f);
            if (this._animal != null && !MeatController.CanGetMeatFrom(this._animal))
            {
                return;
            }

            if (this._animal != null && this._animal.age.Value >= (int)this._animal.ageWhenMature.Value)
            {
                (this._animal.home.indoors.Value as AnimalHouse)?.animalsThatLiveHere.Remove(this._animal.myID.Value);
                this._animal.health.Value = -1;
                int         numClouds   = this._animal.frontBackSourceRect.Width / 2;
                int         cloudSprite = !DataLoader.ModConfig.Softmode ? 5 : 10;
                Multiplayer multiplayer = DataLoader.Helper.Reflection.GetField <Multiplayer>(typeof(Game1), "multiplayer").GetValue();
                for (int i = 0; i < numClouds; i++)
                {
                    int   nonRedness = Game1.random.Next(0, 80);
                    Color cloudColor = new Color(255, 255 - nonRedness, 255 - nonRedness);;



                    multiplayer.broadcastSprites(
                        Game1.player.currentLocation
                        , new TemporaryAnimatedSprite[1] {
                        new TemporaryAnimatedSprite
                        (
                            cloudSprite
                            , this._animal.position + new Vector2(Game1.random.Next(-Game1.tileSize / 2, this._animal.frontBackSourceRect.Width * 3)
                                                                  , Game1.random.Next(-Game1.tileSize / 2, this._animal.frontBackSourceRect.Height * 3))
                            , cloudColor
                            , 8
                            , false,
                            Game1.random.NextDouble() < .5 ? 50 : Game1.random.Next(30, 200), 0, Game1.tileSize
                            , -1
                            , Game1.tileSize, Game1.random.NextDouble() < .5 ? 0 : Game1.random.Next(0, 600)
                        )
                        {
                            scale  = Game1.random.Next(2, 5) * .25f,
                            alpha  = Game1.random.Next(2, 5) * .25f,
                            motion = new Vector2(0, (float)-Game1.random.NextDouble())
                        }
                    }
                        );
                }
                Color animalColor;
                float alfaFade;
                if (!DataLoader.ModConfig.Softmode)
                {
                    animalColor = Color.LightPink;
                    alfaFade    = .025f;
                }
                else
                {
                    animalColor = Color.White;
                    alfaFade    = .050f;
                }
                multiplayer.broadcastSprites(
                    Game1.player.currentLocation
                    , new TemporaryAnimatedSprite[1] {
                    new TemporaryAnimatedSprite
                    (
                        this._animal.Sprite.textureName.Value
                        , this._animal.Sprite.SourceRect
                        , this._animal.position
                        , this._animal.FacingDirection == Game1.left
                        , alfaFade
                        , animalColor
                    )
                    {
                        scale = 4f
                    }
                }
                    );
                if (!DataLoader.ModConfig.Softmode)
                {
                    Game1.playSound("killAnimal");
                }
                else
                {
                    ICue warptSound = Game1.soundBank.GetCue("wand");
                    warptSound.SetVariable("Pitch", 1800);
                    warptSound.Play();
                }

                MeatController.ThrowItem(MeatController.CreateMeat(this._animal), this._animal);
                who.gainExperience(0, 5);
                this._animal     = (FarmAnimal)null;
                this._tempAnimal = (FarmAnimal)null;
            }
        }
Exemple #25
0
 public AnimalQueryMenu(FarmAnimal animal)
     : base(Game1.uiViewport.Width / 2 - width / 2, Game1.uiViewport.Height / 2 - height / 2, width, height)
 {
     Game1.player.Halt();
     Game1.player.faceGeneralDirection(animal.Position, 0, opposite: false, useTileCalculations: false);
     width          = 384;
     height         = 512;
     this.animal    = animal;
     textBox        = new TextBox(null, null, Game1.dialogueFont, Game1.textColor);
     textBox.X      = Game1.uiViewport.Width / 2 - 128 - 12;
     textBox.Y      = yPositionOnScreen - 4 + 128;
     textBox.Width  = 256;
     textBox.Height = 192;
     textBoxCC      = new ClickableComponent(new Microsoft.Xna.Framework.Rectangle(textBox.X, textBox.Y, textBox.Width, 64), "")
     {
         myID           = 110,
         downNeighborID = 104
     };
     textBox.Text = animal.displayName;
     Game1.keyboardDispatcher.Subscriber = textBox;
     textBox.Selected = false;
     if ((long)animal.parentId != -1)
     {
         FarmAnimal parent = Utility.getAnimal(animal.parentId);
         if (parent != null)
         {
             parentName = parent.displayName;
         }
     }
     if (animal.sound.Value != null && Game1.soundBank != null && !Game1.options.muteAnimalSounds)
     {
         ICue cue = Game1.soundBank.GetCue(animal.sound.Value);
         cue.SetVariable("Pitch", 1200 + Game1.random.Next(-200, 201));
         cue.Play();
     }
     okButton = new ClickableTextureComponent(new Microsoft.Xna.Framework.Rectangle(xPositionOnScreen + width + 4, yPositionOnScreen + height - 64 - IClickableMenu.borderWidth, 64, 64), Game1.mouseCursors, Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 46), 1f)
     {
         myID         = 101,
         upNeighborID = -99998
     };
     sellButton = new ClickableTextureComponent(new Microsoft.Xna.Framework.Rectangle(xPositionOnScreen + width + 4, yPositionOnScreen + height - 192 - IClickableMenu.borderWidth, 64, 64), Game1.mouseCursors, new Microsoft.Xna.Framework.Rectangle(0, 384, 16, 16), 4f)
     {
         myID           = 103,
         downNeighborID = -99998,
         upNeighborID   = 104
     };
     moveHomeButton = new ClickableTextureComponent(new Microsoft.Xna.Framework.Rectangle(xPositionOnScreen + width + 4, yPositionOnScreen + height - 256 - IClickableMenu.borderWidth, 64, 64), Game1.mouseCursors, new Microsoft.Xna.Framework.Rectangle(16, 384, 16, 16), 4f)
     {
         myID           = 104,
         downNeighborID = 103,
         upNeighborID   = 110
     };
     if (!animal.isBaby() && !animal.isCoopDweller() && animal.CanHavePregnancy())
     {
         allowReproductionButton = new ClickableTextureComponent(new Microsoft.Xna.Framework.Rectangle(xPositionOnScreen + width + 16, yPositionOnScreen + height - 128 - IClickableMenu.borderWidth + 8, 36, 36), Game1.mouseCursors, new Microsoft.Xna.Framework.Rectangle(animal.allowReproduction ? 128 : 137, 393, 9, 9), 4f)
         {
             myID           = 106,
             downNeighborID = 101,
             upNeighborID   = 103
         };
     }
     love = new ClickableTextureComponent(Math.Round((double)(int)animal.friendshipTowardFarmer, 0) / 10.0 + "<", new Microsoft.Xna.Framework.Rectangle(xPositionOnScreen + IClickableMenu.spaceToClearSideBorder + 32 + 16, yPositionOnScreen - 32 + IClickableMenu.spaceToClearTopBorder + 256 - 32, width - 128, 64), null, "Friendship", Game1.mouseCursors, new Microsoft.Xna.Framework.Rectangle(172, 512, 16, 16), 4f)
     {
         myID = 102
     };
     loveHover = new ClickableComponent(new Microsoft.Xna.Framework.Rectangle(xPositionOnScreen + IClickableMenu.spaceToClearSideBorder, yPositionOnScreen + IClickableMenu.spaceToClearTopBorder + 192 - 32, width, 64), "Friendship")
     {
         myID = 109
     };
     fullnessLevel = (float)(int)(byte)animal.fullness / 255f;
     if (animal.home != null && animal.home.indoors.Value != null)
     {
         int piecesHay = animal.home.indoors.Value.numberOfObjectsWithName("Hay");
         if (piecesHay > 0)
         {
             int numAnimals = (animal.home.indoors.Value as AnimalHouse).animalsThatLiveHere.Count;
             fullnessLevel = Math.Min(1.0, fullnessLevel + (double)piecesHay / (double)numAnimals);
         }
     }
     else
     {
         Utility.fixAllAnimals();
     }
     happinessLevel = (float)(int)(byte)animal.happiness / 255f;
     loveLevel      = (float)(int)animal.friendshipTowardFarmer / 1000f;
     if (Game1.options.SnappyMenus)
     {
         populateClickableComponentList();
         snapToDefaultClickableComponent();
     }
 }
Exemple #26
0
        public static bool beginUsing(MilkPail __instance, GameLocation location, int x, int y, StardewValley.Farmer who, ref bool __result)
        {
            if (!IsInseminationSyringe(__instance))
            {
                return(true);
            }

            string inseminationSyringeId = __instance.modData[InseminationSyringeKey];

            x = (int)who.GetToolLocation(false).X;
            y = (int)who.GetToolLocation(false).Y;
            Rectangle rectangle = new Rectangle(x - Game1.tileSize / 2, y - Game1.tileSize / 2, Game1.tileSize, Game1.tileSize);

            if (!DataLoader.ModConfig.DisablePregnancy)
            {
                if (location is Farm)
                {
                    foreach (FarmAnimal farmAnimal in (location as Farm).animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            Animals[inseminationSyringeId] = farmAnimal;
                            break;
                        }
                    }
                }
                else if (location is AnimalHouse)
                {
                    foreach (FarmAnimal farmAnimal in (location as AnimalHouse).animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            Animals[inseminationSyringeId] = farmAnimal;
                            break;
                        }
                    }
                }
            }

            Animals.TryGetValue(inseminationSyringeId, out FarmAnimal animal);
            if (animal != null)
            {
                string dialogue = "";
                if (__instance.attachments[0] == null)
                {
                    Game1.showRedMessage(DataLoader.i18n.Get("Tool.InseminationSyringe.Empty"));
                    Animals[inseminationSyringeId] = null;
                }
                else if (AnimalExtension.GetAnimalFromType(animal.type.Value) == null)
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.CantBeInseminated", new { animalName = animal.displayName });
                }
                else if (IsEggAnimal(animal))
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.EggAnimal", new { animalName = animal.displayName });
                }
                else if (!((ImpregnatableAnimalItem)DataLoader.AnimalData.GetAnimalItem(animal)).MinimumDaysUtillBirth.HasValue)
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.CantBeInseminated", new { animalName = animal.displayName });
                }
                else if (animal.isBaby())
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.TooYoung", new { animalName = animal.displayName });
                }
                else if (PregnancyController.IsAnimalPregnant(animal))
                {
                    int daysUntilBirth = animal.GetDaysUntilBirth().Value;
                    if (daysUntilBirth > 1)
                    {
                        dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.AlreadyPregnant", new { animalName = animal.displayName, numberOfDays = daysUntilBirth });
                    }
                    else
                    {
                        dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.ReadyForBirth", new { animalName = animal.displayName });
                    }
                }
                else if (!CheckCorrectProduct(animal, __instance.attachments[0]))
                {
                    var    data        = DataLoader.Helper.Content.Load <Dictionary <int, string> >(@"Data\ObjectInformation.xnb", ContentSource.GameContent);
                    string produceName = data[animal.defaultProduceIndex.Value].Split('/')[4];
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.CorrectItem", new { itemName = produceName });
                }
                else if (PregnancyController.CheckBuildingLimit(animal))
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.BuildingLimit", new { buildingType = animal.displayHouse });
                }
                else
                {
                    animal.doEmote(16, true);
                    if (who != null && Game1.player.Equals(who))
                    {
                        if (animal.sound.Value != null)
                        {
                            ICue animalSound = Game1.soundBank.GetCue(animal.sound.Value);
                            animalSound.Play();
                        }

                        DelayedAction.playSoundAfterDelay("fishingRodBend", 300, location);
                        DelayedAction.playSoundAfterDelay("fishingRodBend", 1200, location);
                    }
                    animal.pauseTimer = 1500;
                }
                if (dialogue.Length > 0)
                {
                    if (who != null && Game1.player.Equals(who))
                    {
                        DelayedAction.showDialogueAfterDelay(dialogue, 150);
                    }
                    Animals[inseminationSyringeId] = null;
                }
            }

            who.Halt();
            int currentFrame = who.FarmerSprite.currentFrame;

            if (animal != null)
            {
                who.FarmerSprite.animateOnce(287 + who.FacingDirection, 50f, 4);
            }
            else
            {
                who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] {
                    new FarmerSprite.AnimationFrame(currentFrame, 0, false, who.FacingDirection == 3, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true)
                });
            }
            who.FarmerSprite.oldFrame = currentFrame;
            who.UsingTool             = true;
            who.CanMove = false;

            __result = true;
            return(false);
        }
Exemple #27
0
 public CosmeticDebris(Texture2D texture, Vector2 startingPosition, float rotationSpeed, float xVelocity, float yVelocity, int groundYLevel, Rectangle sourceRect, Color color, ICue tapSound, LightSource light, int lightTailLength, int disappearTime)
 {
     timeToDisappearAfterReachingGround = disappearTime;
     disappearTimer     = timeToDisappearAfterReachingGround;
     this.texture       = texture;
     position           = startingPosition;
     this.rotationSpeed = rotationSpeed;
     this.xVelocity     = xVelocity;
     this.yVelocity     = yVelocity;
     this.sourceRect    = sourceRect;
     this.groundYLevel  = groundYLevel;
     this.color         = color;
     this.tapSound      = tapSound;
     this.light         = light;
     id = Game1.random.Next();
     if (light != null)
     {
         light.Identifier = id;
         Game1.currentLightSources.Add(light);
     }
     if (lightTailLength > 0)
     {
         lightTail            = new Queue <Vector2>();
         this.lightTailLength = lightTailLength;
     }
 }
        public override void receiveLeftClick(int x, int y, bool playSound = true)
        {
            if (Game1.globalFade || this.Freeze)
            {
                return;
            }

            if (this.BackButton != null && this.BackButton.containsPoint(x, y))
            {
                this.BackButton.scale = this.BackButton.baseScale;
                this.BackButtonPressed();
            }

            if (this.OkButton != null && this.OkButton.containsPoint(x, y) && this.readyToClose())
            {
                if (this.OnFarm)
                {
                    Game1.globalFadeToBlack(this.SetUpForReturnToShopMenu);
                    Game1.playSound("smallSelect");
                }
                else
                {
                    Game1.exitActiveMenu();
                    Game1.playSound("bigDeSelect");
                }
            }
            if (this.OnFarm)
            {
                Building building = Game1.getFarm().getBuildingAt(new Vector2((x + Game1.viewport.X) / Game1.tileSize, (y + Game1.viewport.Y) / Game1.tileSize));
                if (building != null && !this.NamingAnimal)
                {
                    if (building.buildingType.Contains(this.AnimalBeingPurchased.buildingTypeILiveIn.Value))
                    {
                        AnimalHouse animalHouse = (AnimalHouse)building.indoors.Value;
                        if (animalHouse.isFull())
                        {
                            Game1.showRedMessage("That Building Is Full");
                        }
                        else if (this.AnimalBeingPurchased.harvestType.Value != 2)
                        {
                            this.NamingAnimal  = true;
                            this.NewAnimalHome = building;
                            if (this.AnimalBeingPurchased.sound.Value != null && Game1.soundBank != null)
                            {
                                ICue cue = Game1.soundBank.GetCue(this.AnimalBeingPurchased.sound.Value);
                                cue.SetVariable("Pitch", 1200 + Game1.random.Next(-200, 201));
                                cue.Play();
                            }
                            this.TextBox.OnEnterPressed        += this.TextBoxEvent;
                            Game1.keyboardDispatcher.Subscriber = this.TextBox;
                            this.TextBox.Text     = this.AnimalBeingPurchased.Name;
                            this.TextBox.Selected = true;
                        }
                        else if (Game1.player.Money >= this.PriceOfAnimal)
                        {
                            this.NewAnimalHome             = building;
                            this.AnimalBeingPurchased.home = this.NewAnimalHome;
                            this.AnimalBeingPurchased.homeLocation.Value = new Vector2(this.NewAnimalHome.tileX.Value, this.NewAnimalHome.tileY.Value);
                            this.AnimalBeingPurchased.setRandomPosition(this.AnimalBeingPurchased.home.indoors.Value);
                            ((AnimalHouse)this.NewAnimalHome.indoors.Value).animals.Add(this.AnimalBeingPurchased.myID.Value, this.AnimalBeingPurchased);
                            ((AnimalHouse)this.NewAnimalHome.indoors.Value).animalsThatLiveHere.Add(this.AnimalBeingPurchased.myID.Value);
                            this.NewAnimalHome = null;
                            this.NamingAnimal  = false;
                            if (this.AnimalBeingPurchased.sound.Value != null && Game1.soundBank != null)
                            {
                                ICue cue = Game1.soundBank.GetCue(this.AnimalBeingPurchased.sound.Value);
                                cue.SetVariable("Pitch", 1200 + Game1.random.Next(-200, 201));
                                cue.Play();
                            }
                            Game1.player.Money -= this.PriceOfAnimal;
                            Game1.addHUDMessage(new HUDMessage("Purchased " + this.AnimalBeingPurchased.type.Value, Color.LimeGreen, 3500f));
                            this.AnimalBeingPurchased = new FarmAnimal(this.AnimalBeingPurchased.type.Value, this.GetNewId(), Game1.player.UniqueMultiplayerID);
                        }
                        else if (Game1.player.Money < this.PriceOfAnimal)
                        {
                            Game1.dayTimeMoneyBox.moneyShakeTimer = 1000;
                        }
                    }
                    else
                    {
                        Game1.showRedMessage(this.AnimalBeingPurchased.type.Value.Split(' ').Last() + "s Can't Live There.");
                    }
                }
                if (this.NamingAnimal && this.DoneNamingButton.containsPoint(x, y))
                {
                    this.TextBoxEnter(this.TextBox);
                    Game1.playSound("smallSelect");
                }
                else
                {
                    if (!this.NamingAnimal || !this.RandomButton.containsPoint(x, y))
                    {
                        return;
                    }
                    this.AnimalBeingPurchased.Name = Dialogue.randomName();
                    this.TextBox.Text       = this.AnimalBeingPurchased.Name;
                    this.RandomButton.scale = this.RandomButton.baseScale;
                    Game1.playSound("drumkit6");
                }
            }
            else
            {
                foreach (ClickableTextureComponent textureComponent in this.AnimalsToPurchase)
                {
                    if (textureComponent.containsPoint(x, y) && ((Object)textureComponent.item).Type == null)
                    {
                        int int32 = Convert.ToInt32(textureComponent.name);
                        if (Game1.player.Money >= int32)
                        {
                            Game1.globalFadeToBlack(this.SetUpForAnimalPlacement);
                            Game1.playSound("smallSelect");
                            this.OnFarm = true;
                            this.AnimalBeingPurchased = new FarmAnimal(textureComponent.hoverText, this.GetNewId(), Game1.player.UniqueMultiplayerID);
                            this.PriceOfAnimal        = int32;
                        }
                        else
                        {
                            Game1.addHUDMessage(new HUDMessage("Not Enough Money", Color.Red, 3500f));
                        }
                    }
                }
            }
        }
Exemple #29
0
 public Trellisbeast()
 {
     sound = Game1.soundBank.GetCue("batFlap");
 }
Exemple #30
0
 public override void receiveLeftClick(int x, int y, bool playSound = true)
 {
     if (Game1.globalFade || freeze)
     {
         return;
     }
     if (okButton != null && okButton.containsPoint(x, y) && readyToClose())
     {
         if (onFarm)
         {
             setUpForReturnToShopMenu();
             Game1.playSound("smallSelect");
         }
         else
         {
             Game1.exitActiveMenu();
             Game1.playSound("bigDeSelect");
         }
     }
     if (onFarm)
     {
         Vector2  clickTile = new Vector2((x + Game1.viewport.X) / 64, (y + Game1.viewport.Y) / 64);
         Building selection = (Game1.getLocationFromName("Farm") as Farm).getBuildingAt(clickTile);
         if (selection != null && !namingAnimal)
         {
             if (selection.buildingType.Value.Contains(animalBeingPurchased.buildingTypeILiveIn.Value))
             {
                 if ((selection.indoors.Value as AnimalHouse).isFull())
                 {
                     Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11321"));
                 }
                 else if ((byte)animalBeingPurchased.harvestType != 2)
                 {
                     namingAnimal  = true;
                     newAnimalHome = selection;
                     if (animalBeingPurchased.sound.Value != null && Game1.soundBank != null)
                     {
                         ICue cue = Game1.soundBank.GetCue(animalBeingPurchased.sound.Value);
                         cue.SetVariable("Pitch", 1200 + Game1.random.Next(-200, 201));
                         cue.Play();
                     }
                     textBox.OnEnterPressed += e;
                     textBox.Text            = animalBeingPurchased.displayName;
                     Game1.keyboardDispatcher.Subscriber = textBox;
                     if (Game1.options.SnappyMenus)
                     {
                         currentlySnappedComponent = getComponentWithID(104);
                         snapCursorToCurrentSnappedComponent();
                     }
                 }
                 else if (Game1.player.Money >= priceOfAnimal)
                 {
                     newAnimalHome             = selection;
                     animalBeingPurchased.home = newAnimalHome;
                     animalBeingPurchased.homeLocation.Value = new Vector2((int)newAnimalHome.tileX, (int)newAnimalHome.tileY);
                     animalBeingPurchased.setRandomPosition(animalBeingPurchased.home.indoors);
                     (newAnimalHome.indoors.Value as AnimalHouse).animals.Add(animalBeingPurchased.myID, animalBeingPurchased);
                     (newAnimalHome.indoors.Value as AnimalHouse).animalsThatLiveHere.Add(animalBeingPurchased.myID);
                     newAnimalHome = null;
                     namingAnimal  = false;
                     if (animalBeingPurchased.sound.Value != null && Game1.soundBank != null)
                     {
                         ICue cue2 = Game1.soundBank.GetCue(animalBeingPurchased.sound.Value);
                         cue2.SetVariable("Pitch", 1200 + Game1.random.Next(-200, 201));
                         cue2.Play();
                     }
                     Game1.player.Money -= priceOfAnimal;
                     Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11324", animalBeingPurchased.displayType), Color.LimeGreen, 3500f));
                     animalBeingPurchased = new FarmAnimal(animalBeingPurchased.type, Game1.multiplayer.getNewID(), Game1.player.uniqueMultiplayerID);
                 }
                 else if (Game1.player.Money < priceOfAnimal)
                 {
                     Game1.dayTimeMoneyBox.moneyShakeTimer = 1000;
                 }
             }
             else
             {
                 Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11326", animalBeingPurchased.displayType));
             }
         }
         if (namingAnimal)
         {
             if (doneNamingButton.containsPoint(x, y))
             {
                 textBoxEnter(textBox);
                 Game1.playSound("smallSelect");
             }
             else if (namingAnimal && randomButton.containsPoint(x, y))
             {
                 animalBeingPurchased.Name        = Dialogue.randomName();
                 animalBeingPurchased.displayName = animalBeingPurchased.Name;
                 textBox.Text       = animalBeingPurchased.displayName;
                 randomButton.scale = randomButton.baseScale;
                 Game1.playSound("drumkit6");
             }
             textBox.Update();
         }
     }
     else
     {
         foreach (ClickableTextureComponent c in animalsToPurchase)
         {
             if (c.containsPoint(x, y) && (c.item as Object).Type == null)
             {
                 int price = c.item.salePrice();
                 if (Game1.player.Money >= price)
                 {
                     Game1.globalFadeToBlack(setUpForAnimalPlacement);
                     Game1.playSound("smallSelect");
                     onFarm = true;
                     animalBeingPurchased = new FarmAnimal(c.hoverText, Game1.multiplayer.getNewID(), Game1.player.UniqueMultiplayerID);
                     priceOfAnimal        = price;
                 }
                 else
                 {
                     Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11325"), Color.Red, 3500f));
                 }
             }
         }
     }
 }