public override bool performUseAction(Vector2 tileLocation, GameLocation location) { if (Game1.soundBank != null) { Random random = new Random((int)((float)Game1.uniqueIDForThisGame + tileLocation.X * 7f + tileLocation.Y * 11f + (float)Game1.CurrentMineLevel)); ICue c = Game1.soundBank.GetCue("crystal"); int pitch = random.Next(2400); pitch -= pitch % 100; c.SetVariable("Pitch", pitch); c.Play(); } glow.Value = 0.7f; Color glowColor = ((glow.Value > 0f) ? new Color(color.R + (int)(glow.Value * 50f), color.G + (int)(glow.Value * 50f), color.B + (int)(glow.Value * 50f)) : ((Color)color)); glowColor *= 0.3f + glow.Value; Utility.removeLightSource((int)(tileLocation.X * 1000f + tileLocation.Y)); if ((int)bigness < 2) { Game1.currentLightSources.Add(new LightSource(4, new Vector2(tileLocation.X * 64f + 32f, tileLocation.Y * 64f + 32f), 1f, Utility.getOppositeColor(glowColor), (int)(tileLocation.X * 1000f + tileLocation.Y), LightSource.LightContext.None, 0L)); } else if ((int)bigness >= 2) { Game1.currentLightSources.Add(new LightSource(4, new Vector2(tileLocation.X * 64f + 32f, tileLocation.Y * 64f + 32f), 1f, Utility.getOppositeColor(glowColor), (int)(tileLocation.X * 1000f + tileLocation.Y), LightSource.LightContext.None, 0L)); } return(false); }
public static void InitShared() { if (Game1.soundBank != null) { if (babblingBrook == null) { babblingBrook = Game1.soundBank.GetCue("babblingBrook"); babblingBrook.Play(); babblingBrook.Pause(); } if (cracklingFire == null) { cracklingFire = Game1.soundBank.GetCue("cracklingFire"); cracklingFire.Play(); cracklingFire.Pause(); } if (engine == null) { engine = Game1.soundBank.GetCue("heavyEngine"); engine.Play(); engine.Pause(); } if (cricket == null) { cricket = Game1.soundBank.GetCue("cricketsAmbient"); cricket.Play(); cricket.Pause(); } } shortestDistanceForCue = new float[4]; }
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; if ((byte)grassType == 6) { (who as Farmer).temporarySpeedBuff = -3f; } } }
public override bool update(GameTime time) { if (light != null) { Utility.repositionLightSource(id, position); } yVelocity += 0.3f; position += new Vector2(xVelocity, yVelocity); rotation += rotationSpeed; if (position.Y >= (float)groundYLevel) { position.Y = groundYLevel - 1; yVelocity = 0f - yVelocity; yVelocity *= 0.45f; xVelocity *= 0.45f; rotationSpeed *= 0.225f; if (Game1.soundBank != null && !tapSound.IsPlaying) { tapSound = Game1.soundBank.GetCue(tapSound.Name); tapSound.Play(); } disappearTimer--; } if (disappearTimer < timeToDisappearAfterReachingGround) { disappearTimer -= time.ElapsedGameTime.Milliseconds; if (disappearTimer <= 0) { Utility.removeLightSource(id); return(true); } } return(false); }
public static bool prefix_playTrainApproach() { 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.Name == "Desert")) { 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.Name == "Desert")) { ICue cue = Game1.soundBank.GetCue("distantTrain"); cue.SetVariable("Volume", 100f); cue.Play(); } return(false); } return(true); }
private void jump() { if (!(minecartDY < 1f) || respawnCounter > 0) { return; } if (!isJumping) { movingOnSlope = 0; minecartPositionBeforeJump = mineCartYPosition; isJumping = true; if (minecartLoop != null) { minecartLoop.Stop(AudioStopOptions.Immediate); } if (Game1.soundBank != null) { ICue cue = Game1.soundBank.GetCue("pickUpItem"); cue.SetVariable("Pitch", 200); cue.Play(); } } if (!reachedJumpApex) { minecartDY = Math.Max(-4.5f, minecartDY - 0.6f); if (minecartDY <= -4.5f) { reachedJumpApex = true; } } }
public static bool playSoundPitched_prePatch_GekoX_ShutUp(string cueName, int pitch) { try { if (ModEntry.config.sounds.Contains(cueName)) { if (ModEntry.config.showDebugSpam) { ModEntry.monitor.Log($"Shutting {cueName} up", LogLevel.Info); } return(false); } if (Game1.soundBank != null) { try { ICue cue = Game1.soundBank.GetCue(cueName); cue.SetVariable("Pitch", pitch); cue.Play(); } catch (Exception ex) { Game1.debugOutput = Game1.parseText(ex.Message); Console.WriteLine(ex); } } return(false); } catch (Exception e) { ModEntry.monitor.Log($"Failed in {nameof(playSoundPitched_prePatch_GekoX_ShutUp)}:\n{e}", LogLevel.Error); return(true); } }
public virtual void SetGameState(GameState new_state) { if (currentGameState == GameState.Scoring) { previousPoints = points; shakeScore = false; alternateTextString = ""; } if (currentGameState == GameState.Charging && chargeSound != null) { chargeSound.Stop(AudioStopOptions.Immediate); chargeSound = null; } currentGameState = new_state; if (currentGameState == GameState.Aiming) { dartTime = -1f; if (Game1.options.gamepadControls) { Game1.setMousePosition(Utility.Vector2ToPoint(TransformDraw(new Vector2(screenWidth / 2, screenHeight / 2)))); } } else if (currentGameState == GameState.Charging) { if (chargeSound == null && Game1.soundBank != null) { chargeSound = Game1.soundBank.GetCue("SinWave"); chargeSound.Play(); } chargeTime = 1f; chargeDirection = -1f; canCancelShot = true; } else if (currentGameState == GameState.Firing) { throwStartPosition = dartBoardCenter + new Vector2(Utility.RandomFloat(-64f, 64f), 200f); Game1.playSound("FishHit"); hangTime = 0.25f; } else if (currentGameState == GameState.ShowScore) { stateTimer = 1f; } else if (currentGameState == GameState.GameOver) { if (points == 0) { gameOverString = Game1.content.LoadString("Strings\\StringsFromCSFiles:CalicoJack.cs.11943"); Game1.playSound("yoba"); } else { gameOverString = Game1.content.LoadString("Strings\\StringsFromCSFiles:CalicoJack.cs.11946"); Game1.playSound("slimedead"); } stateTimer = 3f; } }
// Tries to play a sound cue, but intercepts and discards // InvalidOperationException in case it was already playing but somehow // didn't register as IsPlaying, which can apparently happen. public static void TryPlayCue(ICue cue) { try { cue.Play(); } catch (InvalidOperationException) {} }
public override void updateEvenIfFarmerIsntHere(GameTime time, bool skipWasUpdatedFlush = false) { base.updateEvenIfFarmerIsntHere(time, skipWasUpdatedFlush); if (train.Value != null && train.Value.Update(time, this) && Game1.IsMasterGame) { train.Value = null; } if (!Game1.IsMasterGame) { return; } if (Game1.timeOfDay == trainTime - trainTime % 10 && (int)trainTimer == 0 && !Game1.isFestival() && train.Value == null) { setTrainComing(15000); } if ((int)trainTimer > 0) { trainTimer.Value -= time.ElapsedGameTime.Milliseconds; if ((int)trainTimer <= 0) { train.Value = new Train(); playSound("trainWhistle"); } if ((int)trainTimer < 3500 && Game1.currentLocation == this && Game1.soundBank != null && (trainLoop == null || !trainLoop.IsPlaying)) { trainLoop = Game1.soundBank.GetCue("trainLoop"); trainLoop.SetVariable("Volume", 0f); trainLoop.Play(); } } if (train.Value != null) { if (Game1.currentLocation == this && Game1.soundBank != null && (trainLoop == null || !trainLoop.IsPlaying)) { trainLoop = Game1.soundBank.GetCue("trainLoop"); trainLoop.SetVariable("Volume", 0f); trainLoop.Play(); } if (trainLoop != null && trainLoop.GetVariable("Volume") < 100f) { trainLoop.SetVariable("Volume", trainLoop.GetVariable("Volume") + 0.5f); } } else if (trainLoop != null && (int)trainTimer <= 0) { trainLoop.SetVariable("Volume", trainLoop.GetVariable("Volume") - 0.15f); if (trainLoop.GetVariable("Volume") <= 0f) { trainLoop.Stop(AudioStopOptions.Immediate); trainLoop = null; } } else if ((int)trainTimer > 0 && trainLoop != null) { trainLoop.SetVariable("Volume", trainLoop.GetVariable("Volume") + 0.15f); } }
public void activate() { glowTimer = 1000f; shakeTimer = 100f; ICue cue = Game1.soundBank.GetCue("crystal"); cue.SetVariable("Pitch", pitch); cue.Play(); currentColor = color; }
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(); }
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(); } }
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(); } } }
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; }
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(); }
/// <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)}"); } } }
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(); }
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; }
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; }
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(); } }
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); }
public static bool DoFunction(Axe __instance, GameLocation location, int x, int y, int power, StardewValley.Farmer who) { if (!IsMeatCleaver(__instance)) { return(true); } string meatCleaverId = __instance.modData[MeatCleaverKey]; BaseToolDoFunction(__instance, location, x, y, power, who); if (!__instance.IsEfficient) { who.Stamina -= ((float)4f - (float)who.FarmingLevel * 0.2f); } if (!Animals.ContainsKey(meatCleaverId)) { return(false); } FarmAnimal farmAnimal = Animals[meatCleaverId]; if (farmAnimal == null || !MeatController.CanGetMeatFrom(Animals[meatCleaverId]) || farmAnimal.age.Value < (int)farmAnimal.ageWhenMature.Value) { return(false); } (farmAnimal.home.indoors.Value as AnimalHouse)?.animalsThatLiveHere.Remove(farmAnimal.myID.Value); farmAnimal.health.Value = -1; int numClouds = farmAnimal.frontBackSourceRect.Width / 2; int cloudSprite = !DataLoader.ModConfig.Softmode ? 5 : 10; for (int i = 0; i < numClouds; i++) { int nonRedness = Game1.random.Next(0, 80); Color cloudColor = new Color(255, 255 - nonRedness, 255 - nonRedness); location.temporarySprites.Add( new TemporaryAnimatedSprite ( cloudSprite , farmAnimal.position + new Vector2(Game1.random.Next(-Game1.tileSize / 2, farmAnimal.frontBackSourceRect.Width * 3), Game1.random.Next(-Game1.tileSize / 2, farmAnimal.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; } location.temporarySprites.Add( new TemporaryAnimatedSprite ( farmAnimal.Sprite.textureName.Value , farmAnimal.Sprite.SourceRect , farmAnimal.position , farmAnimal.FacingDirection == Game1.left , alfaFade , animalColor ) { scale = 4f } ); if (!DataLoader.ModConfig.Softmode) { location.playSound("killAnimal"); } else { ICue warptSound = Game1.soundBank.GetCue("wand"); warptSound.SetVariable("Pitch", 1800); warptSound.Play(); } MeatController.ThrowItem(MeatController.CreateMeat(farmAnimal), farmAnimal); who.gainExperience(0, 5); Animals[meatCleaverId] = (FarmAnimal)null; TempAnimals[meatCleaverId] = (FarmAnimal)null; return(false); }
public override void receiveLeftClick(int x, int y, bool playSound = true) { if (Game1.globalFade || this.freeze) { return; } if (this.okButton != null && this.okButton.containsPoint(x, y) && this.readyToClose()) { if (this.onFarm) { Game1.globalFadeToBlack(new Game1.afterFadeFunction(this.setUpForReturnToShopMenu), 0.02f); Game1.playSound("smallSelect"); } else { Game1.exitActiveMenu(); Game1.playSound("bigDeSelect"); } } if (this.onFarm) { Vector2 tile = new Vector2((float)((x + Game1.viewport.X) / Game1.tileSize), (float)((y + Game1.viewport.Y) / Game1.tileSize)); Building buildingAt = currentFarm.getBuildingAt(tile); if (buildingAt != null && !this.namingAnimal) { if (buildingAt.buildingType.Contains(this.animalBeingPurchased.buildingTypeILiveIn.Value)) { if ((buildingAt.indoors.Value as AnimalHouse).isFull()) { Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11321", new object[0])); } else if (this.animalBeingPurchased.harvestType.Value != 2) { this.namingAnimal = true; this.newAnimalHome = buildingAt; if (this.animalBeingPurchased.sound.Value != null && Game1.soundBank != null) { ICue expr_15B = Game1.soundBank.GetCue(this.animalBeingPurchased.sound.Value); expr_15B.SetVariable("Pitch", (float)(1200 + Game1.random.Next(-200, 201))); expr_15B.Play(); } this.textBox.OnEnterPressed += this.e; this.textBox.Text = this.animalBeingPurchased.displayName; Game1.keyboardDispatcher.Subscriber = this.textBox; if (Game1.options.SnappyMenus) { this.currentlySnappedComponent = base.getComponentWithID(104); this.snapCursorToCurrentSnappedComponent(); } } else if (Game1.player.Money >= this.priceOfAnimal) { this.newAnimalHome = buildingAt; this.animalBeingPurchased.home = this.newAnimalHome; this.animalBeingPurchased.homeLocation.Value = new Vector2((float)this.newAnimalHome.tileX.Value, (float)this.newAnimalHome.tileY.Value); this.animalBeingPurchased.setRandomPosition(this.animalBeingPurchased.home.indoors.Value); (this.newAnimalHome.indoors.Value as AnimalHouse).animals.Add(this.animalBeingPurchased.myID.Value, this.animalBeingPurchased); (this.newAnimalHome.indoors.Value as AnimalHouse).animalsThatLiveHere.Add(this.animalBeingPurchased.myID.Value); this.newAnimalHome = null; this.namingAnimal = false; if (this.animalBeingPurchased.sound.Value != null && Game1.soundBank != null) { ICue expr_2DC = Game1.soundBank.GetCue(this.animalBeingPurchased.sound.Value); expr_2DC.SetVariable("Pitch", (float)(1200 + Game1.random.Next(-200, 201))); expr_2DC.Play(); } Game1.player.Money -= this.priceOfAnimal; Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11324", new object[] { this.animalBeingPurchased.displayType }), Color.LimeGreen, 3500f)); this.animalBeingPurchased = new FarmAnimal(this.animalBeingPurchased.type.Value, ModEntry.ModHelper.Multiplayer.GetNewID(), Game1.player.UniqueMultiplayerID); } else if (Game1.player.Money < this.priceOfAnimal) { Game1.dayTimeMoneyBox.moneyShakeTimer = 1000; } } else { Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11326", new object[] { this.animalBeingPurchased.displayType })); } } if (this.namingAnimal) { if (this.doneNamingButton.containsPoint(x, y)) { this.textBoxEnter(this.textBox); Game1.playSound("smallSelect"); } else if (this.namingAnimal && this.randomButton.containsPoint(x, y)) { this.animalBeingPurchased.Name = Dialogue.randomName(); this.animalBeingPurchased.displayName = this.animalBeingPurchased.Name; this.textBox.Text = this.animalBeingPurchased.displayName; this.randomButton.scale = this.randomButton.baseScale; Game1.playSound("drumkit6"); } this.textBox.Update(); return; } } else { if (this.previousFarmButton.containsPoint(x, y)) { currentFarm = framework.swapFarm(currentFarm); this.populateAnimalStock(); this.previousFarmButton.scale = this.previousFarmButton.baseScale; } if (this.nextFarmButton.containsPoint(x, y)) { currentFarm = framework.swapFarm(currentFarm); this.populateAnimalStock(); this.nextFarmButton.scale = this.nextFarmButton.baseScale; } foreach (ClickableTextureComponent current in this.animalsToPurchase) { if (current.containsPoint(x, y) && (current.item as Object).Type == null) { int num = current.item.salePrice(); if (Game1.player.Money >= num) { Game1.globalFadeToBlack(new Game1.afterFadeFunction(this.setUpForAnimalPlacement), 0.02f); Game1.playSound("smallSelect"); this.onFarm = true; this.animalBeingPurchased = new FarmAnimal(current.hoverText, ModEntry.ModHelper.Multiplayer.GetNewID(), Game1.player.UniqueMultiplayerID); this.priceOfAnimal = num; } else { Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11325", new object[0]), Color.Red, 3500f)); } } } } }
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)); } } } } }
public bool tick(GameTime time) { if (hasQuit) { return(true); } if (quit && !hasQuit) { Game1.warpFarmer("BusStop", 12, 11, flip: false); if (roadNoise != null) { roadNoise.Stop(AudioStopOptions.Immediate); } Game1.exitActiveMenu(); hasQuit = true; return(true); } switch (currentState) { case 0: updateUpperClouds(time); break; case 1: globalYPanDY = Math.Min(4f, globalYPanDY + (float)time.ElapsedGameTime.Milliseconds * (speed / 140f)); globalYPan -= globalYPanDY; updateUpperClouds(time); if (globalYPan < -1f) { globalYPan = screenHeight * 3; currentState = 2; transformMatrix = Matrix.CreateScale(3f); transformMatrix.Translation = new Vector3(0f, globalYPan, 0f); if (Game1.soundBank != null && roadNoise != null) { roadNoise.SetVariable("Volume", 0); roadNoise.Play(); } Game1.loadForNewGame(); } break; case 2: { int startPanY = screenHeight * 3; int endPanY = -Math.Max(0, 900 - (int)((float)Game1.viewport.Height * Game1.options.zoomLevel)); globalYPanDY = Math.Max(0.5f, globalYPan / 100f); globalYPan -= globalYPanDY; if (globalYPan <= (float)endPanY) { globalYPan = endPanY; } transformMatrix = Matrix.CreateScale(3f); transformMatrix.Translation = new Vector3(0f, globalYPan, 0f); updateRoad(time); if (Game1.soundBank != null && roadNoise != null) { float vol = (globalYPan - (float)startPanY) / (float)(endPanY - startPanY) * 10f + 90f; roadNoise.SetVariable("Volume", vol); } if (globalYPan <= (float)endPanY) { currentState = 3; } break; } case 3: updateRoad(time); drivingTimer += time.ElapsedGameTime.Milliseconds; if (drivingTimer > 5700f) { drivingTimer = 0f; currentState = 4; } break; case 4: updateRoad(time); drivingTimer += time.ElapsedGameTime.Milliseconds; if (!(drivingTimer > 2000f)) { break; } busPosition.X += (float)time.ElapsedGameTime.Milliseconds / 8f; if (Game1.soundBank != null && roadNoise != null) { roadNoise.SetVariable("Volume", Math.Max(0f, roadNoise.GetVariable("Volume") - 1f)); } speed = Math.Max(0f, speed - (float)time.ElapsedGameTime.Milliseconds / 70000f); if (!addedSign) { addedSign = true; roadsideObjects.RemoveAt(roadsideObjects.Count - 1); roadsideObjects.Add(5); Game1.playSound("busDriveOff"); } if (speed <= 0f && birdPosition.Equals(Vector2.Zero)) { int position = 0; for (int i = 0; i < roadsideObjects.Count; i++) { if (roadsideObjects[i] == 5) { position = i; break; } } birdPosition = new Vector2((float)(position * 16) - roadPosition - 32f + 16f, -16f); Game1.playSound("SpringBirds"); fadeAlpha = 0f; } if (!birdPosition.Equals(Vector2.Zero) && birdPosition.Y < 116f) { float dy = Math.Max(0.5f, (116f - birdPosition.Y) / 116f * 2f); birdPosition.Y += dy; birdPosition.X += (float)Math.Sin((double)birdXTimer / (Math.PI * 16.0)) * dy / 2f; birdTimer += time.ElapsedGameTime.Milliseconds; birdXTimer += time.ElapsedGameTime.Milliseconds; if (birdTimer >= 100) { birdFrame = (birdFrame + 1) % 4; birdTimer = 0; } } else if (!birdPosition.Equals(Vector2.Zero)) { birdFrame = ((birdTimer > 1500) ? 5 : 4); birdTimer += time.ElapsedGameTime.Milliseconds; if (birdTimer > 2400 || (birdTimer > 1800 && Game1.random.NextDouble() < 0.006)) { birdTimer = 0; if (Game1.random.NextDouble() < 0.5) { Game1.playSound("SpringBirds"); birdPosition.Y -= 4f; } } } if (!(drivingTimer > 14000f)) { break; } fadeAlpha += (float)time.ElapsedGameTime.Milliseconds * 0.1f / 128f; if (fadeAlpha >= 1f) { Game1.warpFarmer("BusStop", 12, 11, flip: false); if (roadNoise != null) { roadNoise.Stop(AudioStopOptions.Immediate); } Game1.exitActiveMenu(); return(true); } break; } return(false); }
public override void update(GameTime time) { if (sparkleText != null && sparkleText.update(time)) { sparkleText = null; } if (everythingShakeTimer > 0f) { everythingShakeTimer -= time.ElapsedGameTime.Milliseconds; everythingShake = new Vector2((float)Game1.random.Next(-10, 11) / 10f, (float)Game1.random.Next(-10, 11) / 10f); if (everythingShakeTimer <= 0f) { everythingShake = Vector2.Zero; } } if (fadeIn) { scale += 0.05f; if (scale >= 1f) { scale = 1f; fadeIn = false; } } else if (fadeOut) { if (everythingShakeTimer > 0f || sparkleText != null) { return; } scale -= 0.05f; if (scale <= 0f) { scale = 0f; fadeOut = false; int bait = (Game1.player.CurrentTool != null && Game1.player.CurrentTool is FishingRod && (Game1.player.CurrentTool as FishingRod).attachments[0] != null) ? ((int)(Game1.player.CurrentTool as FishingRod).attachments[0].parentSheetIndex) : (-1); bool caughtDouble = !bossFish && bait == 774 && Game1.random.NextDouble() < 0.25 + Game1.player.DailyLuck / 2.0; if (distanceFromCatching > 0.9f && Game1.player.CurrentTool is FishingRod) { (Game1.player.CurrentTool as FishingRod).pullFishFromWater(whichFish, fishSize, fishQuality, (int)difficulty, treasureCaught, perfect, fromFishPond, caughtDouble); } else { Game1.player.completelyStopAnimatingOrDoingAction(); if (Game1.player.CurrentTool != null && Game1.player.CurrentTool is FishingRod) { (Game1.player.CurrentTool as FishingRod).doneFishing(Game1.player, consumeBaitAndTackle: true); } } Game1.exitActiveMenu(); Game1.setRichPresence("location", Game1.currentLocation.Name); } } else { if (Game1.random.NextDouble() < (double)(difficulty * (float)((motionType != 2) ? 1 : 20) / 4000f) && (motionType != 2 || bobberTargetPosition == -1f)) { float spaceBelow = 548f - bobberPosition; float spaceAbove = bobberPosition; float percent = Math.Min(99f, difficulty + (float)Game1.random.Next(10, 45)) / 100f; bobberTargetPosition = bobberPosition + (float)Game1.random.Next(-(int)spaceAbove, (int)spaceBelow) * percent; } if (motionType == 4) { floaterSinkerAcceleration = Math.Max(floaterSinkerAcceleration - 0.01f, -1.5f); } else if (motionType == 3) { floaterSinkerAcceleration = Math.Min(floaterSinkerAcceleration + 0.01f, 1.5f); } if (Math.Abs(bobberPosition - bobberTargetPosition) > 3f && bobberTargetPosition != -1f) { bobberAcceleration = (bobberTargetPosition - bobberPosition) / ((float)Game1.random.Next(10, 30) + (100f - Math.Min(100f, difficulty))); bobberSpeed += (bobberAcceleration - bobberSpeed) / 5f; } else if (motionType != 2 && Game1.random.NextDouble() < (double)(difficulty / 2000f)) { bobberTargetPosition = bobberPosition + (float)((Game1.random.NextDouble() < 0.5) ? Game1.random.Next(-100, -51) : Game1.random.Next(50, 101)); } else { bobberTargetPosition = -1f; } if (motionType == 1 && Game1.random.NextDouble() < (double)(difficulty / 1000f)) { bobberTargetPosition = bobberPosition + (float)((Game1.random.NextDouble() < 0.5) ? Game1.random.Next(-100 - (int)difficulty * 2, -51) : Game1.random.Next(50, 101 + (int)difficulty * 2)); } bobberTargetPosition = Math.Max(-1f, Math.Min(bobberTargetPosition, 548f)); bobberPosition += bobberSpeed + floaterSinkerAcceleration; if (bobberPosition > 532f) { bobberPosition = 532f; } else if (bobberPosition < 0f) { bobberPosition = 0f; } bobberInBar = (bobberPosition + 12f <= bobberBarPos - 32f + (float)bobberBarHeight && bobberPosition - 16f >= bobberBarPos - 32f); if (bobberPosition >= (float)(548 - bobberBarHeight) && bobberBarPos >= (float)(568 - bobberBarHeight - 4)) { bobberInBar = true; } bool num = buttonPressed; buttonPressed = (Game1.oldMouseState.LeftButton == ButtonState.Pressed || Game1.isOneOfTheseKeysDown(Game1.oldKBState, Game1.options.useToolButton) || (Game1.options.gamepadControls && (Game1.oldPadState.IsButtonDown(Buttons.X) || Game1.oldPadState.IsButtonDown(Buttons.A)))); if (!num && buttonPressed) { Game1.playSound("fishingRodBend"); } float gravity = buttonPressed ? (-0.25f) : 0.25f; if (buttonPressed && gravity < 0f && (bobberBarPos == 0f || bobberBarPos == (float)(568 - bobberBarHeight))) { bobberBarSpeed = 0f; } if (bobberInBar) { gravity *= ((whichBobber == 691) ? 0.3f : 0.6f); if (whichBobber == 691) { if (bobberPosition + 16f < bobberBarPos + (float)(bobberBarHeight / 2)) { bobberBarSpeed -= 0.2f; } else { bobberBarSpeed += 0.2f; } } } float oldPos = bobberBarPos; bobberBarSpeed += gravity; bobberBarPos += bobberBarSpeed; if (bobberBarPos + (float)bobberBarHeight > 568f) { bobberBarPos = 568 - bobberBarHeight; bobberBarSpeed = (0f - bobberBarSpeed) * 2f / 3f * ((whichBobber == 692) ? 0.1f : 1f); if (oldPos + (float)bobberBarHeight < 568f) { Game1.playSound("shiny4"); } } else if (bobberBarPos < 0f) { bobberBarPos = 0f; bobberBarSpeed = (0f - bobberBarSpeed) * 2f / 3f; if (oldPos > 0f) { Game1.playSound("shiny4"); } } bool treasureInBar = false; if (treasure) { float oldTreasureAppearTimer = treasureAppearTimer; treasureAppearTimer -= time.ElapsedGameTime.Milliseconds; if (treasureAppearTimer <= 0f) { if (treasureScale < 1f && !treasureCaught) { if (oldTreasureAppearTimer > 0f) { treasurePosition = ((bobberBarPos > 274f) ? Game1.random.Next(8, (int)bobberBarPos - 20) : Game1.random.Next(Math.Min(528, (int)bobberBarPos + bobberBarHeight), 500)); Game1.playSound("dwop"); } treasureScale = Math.Min(1f, treasureScale + 0.1f); } treasureInBar = (treasurePosition + 12f <= bobberBarPos - 32f + (float)bobberBarHeight && treasurePosition - 16f >= bobberBarPos - 32f); if (treasureInBar && !treasureCaught) { treasureCatchLevel += 0.0135f; treasureShake = new Vector2(Game1.random.Next(-2, 3), Game1.random.Next(-2, 3)); if (treasureCatchLevel >= 1f) { Game1.playSound("newArtifact"); treasureCaught = true; } } else if (treasureCaught) { treasureScale = Math.Max(0f, treasureScale - 0.1f); } else { treasureShake = Vector2.Zero; treasureCatchLevel = Math.Max(0f, treasureCatchLevel - 0.01f); } } } if (bobberInBar) { distanceFromCatching += 0.002f; reelRotation += (float)Math.PI / 8f; fishShake.X = (float)Game1.random.Next(-10, 11) / 10f; fishShake.Y = (float)Game1.random.Next(-10, 11) / 10f; barShake = Vector2.Zero; Rumble.rumble(0.1f, 1000f); if (unReelSound != null) { unReelSound.Stop(AudioStopOptions.Immediate); } if (Game1.soundBank != null && (reelSound == null || reelSound.IsStopped || reelSound.IsStopping)) { reelSound = Game1.soundBank.GetCue("fastReel"); } if (reelSound != null && !reelSound.IsPlaying && !reelSound.IsStopping) { reelSound.Play(); } } else if (!treasureInBar || treasureCaught || whichBobber != 693) { if (!fishShake.Equals(Vector2.Zero)) { Game1.playSound("tinyWhip"); perfect = false; Rumble.stopRumbling(); } fishSizeReductionTimer -= time.ElapsedGameTime.Milliseconds; if (fishSizeReductionTimer <= 0) { fishSize = Math.Max(minFishSize, fishSize - 1); fishSizeReductionTimer = 800; } if ((Game1.player.fishCaught != null && Game1.player.fishCaught.Count() != 0) || Game1.currentMinigame != null) { distanceFromCatching -= ((whichBobber == 694 || beginnersRod) ? 0.002f : 0.003f); } float distanceAway = Math.Abs(bobberPosition - (bobberBarPos + (float)(bobberBarHeight / 2))); reelRotation -= (float)Math.PI / Math.Max(10f, 200f - distanceAway); barShake.X = (float)Game1.random.Next(-10, 11) / 10f; barShake.Y = (float)Game1.random.Next(-10, 11) / 10f; fishShake = Vector2.Zero; if (reelSound != null) { reelSound.Stop(AudioStopOptions.Immediate); } if (Game1.soundBank != null && (unReelSound == null || unReelSound.IsStopped)) { unReelSound = Game1.soundBank.GetCue("slowReel"); unReelSound.SetVariable("Pitch", 600); } if (unReelSound != null && !unReelSound.IsPlaying && !unReelSound.IsStopping) { unReelSound.Play(); } } distanceFromCatching = Math.Max(0f, Math.Min(1f, distanceFromCatching)); if (Game1.player.CurrentTool != null) { Game1.player.CurrentTool.tickUpdate(time, Game1.player); } if (distanceFromCatching <= 0f) { fadeOut = true; everythingShakeTimer = 500f; Game1.playSound("fishEscape"); handledFishResult = true; if (unReelSound != null) { unReelSound.Stop(AudioStopOptions.Immediate); } if (reelSound != null) { reelSound.Stop(AudioStopOptions.Immediate); } } else if (distanceFromCatching >= 1f) { everythingShakeTimer = 500f; Game1.playSound("jingle1"); fadeOut = true; handledFishResult = true; if (unReelSound != null) { unReelSound.Stop(AudioStopOptions.Immediate); } if (reelSound != null) { reelSound.Stop(AudioStopOptions.Immediate); } if (perfect) { sparkleText = new SparklingText(Game1.dialogueFont, Game1.content.LoadString("Strings\\UI:BobberBar_Perfect"), Color.Yellow, Color.White, rainbow: false, 0.1, 1500); if (Game1.isFestival()) { Game1.CurrentEvent.perfectFishing(); } } else if (fishSize == maxFishSize) { fishSize--; } } } if (bobberPosition < 0f) { bobberPosition = 0f; } if (bobberPosition > 548f) { bobberPosition = 548f; } }
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)); } } } } }
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; } }