private void OneSecondUpdateTicking(object sender, OneSecondUpdateTickingEventArgs e) { if (!Context.IsWorldReady) { return; } if (_data != null && _data.Buildings.Count > 0) { foreach (KeyValuePair <string, bool> b in _data.Buildings) { IEnumerable <Building> bb = Game1.getFarm().buildings .Where(bbb => bbb.indoors.Value.uniqueName.Value.Equals(b.Key)); foreach (Building build in bb) { int pop = (build.buildingType.Value.Contains("Deluxe Barn") ? Config.MaxBarnPopulation : Config.MaxCoopPopulation); if (((AnimalHouse)build.indoors.Value).animalLimit.Value != pop) { DoPopChange(build, showLog: true, doRestore: true); } } } } if (Config.Cheats.EnableFree) { DoPopChange(Config.MaxBarnPopulation, Config.MaxCoopPopulation); } }
/// ************************************************************************************************************************************************** /// CALLBACK METHODS /// Updates the fridge remotely if there are nobody in the location. private void RemoteFridgeUpdate(object sender, OneSecondUpdateTickingEventArgs e) { if (this.location.farmers.Count <= 0 && Game1.currentLocation != null) { this.mutex.Update(Game1.currentLocation); } }
internal void OnOneSecondUpdateTicking(object sender, OneSecondUpdateTickingEventArgs args) { // Skip OverwriteRogueRandom if we already do it per tick if (Config.ExperimentalForcePerTick) { return; } OverwriteRogueRandomIfNeeded(); }
private void SonaRandomeMewo(object sender, OneSecondUpdateTickingEventArgs e) { Cat sona = GetSona(); if (sona == null) { return; } foreach (GameLocation location in Game1.locations) { if (location is Farm || location is FarmHouse) { if (IsSonaThere(location) && Game1.currentLocation == location && rand.NextDouble() < 0.05f) { sona.playContentSound(); } } } }
/// <summary>Manages the buffs applied when swimming at the Grandpa's Grove location.</summary> private static void OneSecondUpdateTicking_GrandpasGroveBuff(object sender, OneSecondUpdateTickingEventArgs e) { if (!Context.IsPlayerFree || !Game1.game1.IsActive) //if the player is occupied or the game is inactive { return; //do nothing } if (Game1.player.swimming.Value && Game1.currentLocation?.NameOrUniqueName == "GrandpasGrove") //if the player is currently swimming at Grandpa's Grove { secondsSpentSwimming++; //increment swim timer } else //if the player is NOT swimming there { secondsSpentSwimming = 0; //reset swim timer return; //skip the rest of this method } if (secondsSpentSwimming >= secondsBeforeBuffIsApplied) //if the buff should be applied { ApplyGrandpasGroveBuff(); } }
private void GameLoop_OneSecondUpdateTicking(object sender, OneSecondUpdateTickingEventArgs e) { if (!Context.IsWorldReady) { return; } if (!Context.IsMainPlayer) { return; } if (!hasPassedOut) { // Skip the pass-out check time if (Game1.timeOfDay >= 2550) { Game1.timeOfDay = Game1.timeOfDay - 2400; this.savedEveningColor = Game1.outdoorLight; } } if (Game1.timeOfDay < 600) { // Set the outdoor light til morning float timeTilMorning = 400f; // From 2am til 6am var eveningColorVec = savedEveningColor.ToVector4(); var ambientColorVec = Game1.ambientLight.ToVector4(); float progressTime = (float)Math.Abs((Game1.timeOfDay <= 600 ? Game1.timeOfDay + 2400 : Game1.timeOfDay) - 3000) / timeTilMorning; Color progressColor = Color.Lerp(savedEveningColor, Game1.morningColor, 1.0f - progressTime); var progressVec = progressColor.ToVector4(); Game1.outdoorLight = new Color(new Vector4(ambientColorVec.X * progressVec.X, ambientColorVec.Y * progressVec.Y, ambientColorVec.Z * progressVec.Z, ambientColorVec.W * progressVec.W)); isLateNight = true; } else { isLateNight = false; } //this.Log( "Tick!" ); }
private static PerScreen <int> secondsSpentSwimming = new PerScreen <int>(() => 0); //set each player's value to 0 /// <summary>Manage the buffs applied when swimming at certain locations.</summary> private static void GameLoop_OneSecondUpdateTicking(object sender, OneSecondUpdateTickingEventArgs e) { if (!Context.IsPlayerFree || !Game1.game1.IsActive) //if the player is occupied or the game is inactive { return; //do nothing } if (Game1.player.swimming.Value && (Game1.currentLocation?.NameOrUniqueName == ("Custom_GrandpasGrove") || Game1.currentLocation?.NameOrUniqueName == "Custom_SpriteSpring2")) //if the player is currently swimming at Grandpa's Grove { secondsSpentSwimming.Value++; //increment swim timer } else //if the player is NOT swimming there { secondsSpentSwimming.Value = 0; //reset swim timer return; //skip the rest of this method } if (secondsSpentSwimming.Value >= secondsBeforeBuffIsApplied) //if the buff should be applied { Monitor.VerboseLog($"{nameof(CustomBuffs)}: Local player has been swimming at {Game1.currentLocation?.NameOrUniqueName ?? "[null location?]"} for at least {secondsBeforeBuffIsApplied} seconds. Applying (or updating) the local buff."); ApplyGrandpasGroveBuff(); secondsSpentSwimming.Value = 0; //reset the swim timer } }
/* OnOneSecondUpdateTicking * This isn't ideal, it will keep trying to load the sprite if the mod fails, * but this is my current solution for executing this code after Content Patcher packs are ready. */ private void OnOneSecondUpdateTicking(object sender, OneSecondUpdateTickingEventArgs e) { if (updateNeeded && Context.IsWorldReady) { FarmHouse farmHouse = Utility.getHomeOfFarmer(Game1.player); foreach (NPC childCopy in copies.Values) { //Try to load child sprite try { childCopy.Sprite = new AnimatedSprite("Characters/" + childCopy.Name, 0, 16, 32); } catch (Exception) { } //Try to load DefaultPosition from dispositions try { Dictionary <string, string> dispositions = Game1.content.Load <Dictionary <string, string> >("Data\\NPCDispositions"); if (dispositions.ContainsKey(childCopy.Name)) { string[] defaultPosition = dispositions[childCopy.Name].Split('/')[10].Split(' '); Vector2 location = new Vector2(int.Parse(defaultPosition[1]) * 64f, int.Parse(defaultPosition[2]) * 64f); childCopy.Position = location; childCopy.DefaultPosition = location; farmHouse.characters.Remove(childCopy); farmHouse.addCharacter(childCopy); } } catch (Exception) { } } updateNeeded = false; } }
/// <summary> /// Raised every second. /// </summary> /// <param name="sender">Unknown, used by SMAPI.</param> /// <param name="e">OneSecondUpdate params.</param> /// <remarks>Currently handles: grabbing new recently completed special orders.</remarks> private void OneSecondUpdateTicking(object?sender, OneSecondUpdateTickingEventArgs e) { RecentSOManager.GrabNewRecentlyCompletedOrders(); }
/// <summary>Raised once per second before the game state is updated.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> protected virtual void OnOneSecondUpdateTicking(object sender, OneSecondUpdateTickingEventArgs e) { }
private void OnOneSecondUpdateTicking(object sender, OneSecondUpdateTickingEventArgs e) { if (!Context.IsWorldReady || !IsPlayerOnTrawler() || _isTripEnding.Value) { return; } if (Game1.activeClickableMenu != null && !Context.IsMultiplayer) { // Allow pausing in singleplayer via menu return; } // Iterate the fishing trip timer if (fishingTripTimer.Value > 0f) { fishingTripTimer.Value -= 1000; } // Update the track if needed if (themeSongUpdated) { themeSongUpdated = false; _trawlerCabin.Value.miniJukeboxTrack.Value = String.IsNullOrEmpty(trawlerThemeSong) ? null : trawlerThemeSong; _trawlerHull.Value.miniJukeboxTrack.Value = String.IsNullOrEmpty(trawlerThemeSong) ? null : trawlerThemeSong; _trawlerSurface.Value.miniJukeboxTrack.Value = String.IsNullOrEmpty(trawlerThemeSong) ? null : trawlerThemeSong; } if (IsMainDeckhand()) { // Every 5 seconds recalculate the amount of fish caught / lost if (e.IsMultipleOf(300)) { _trawlerSurface.Value.UpdateFishCaught(_trawlerCabin.Value.AreAllPipesLeaking()); SyncTrawler(SyncType.FishCaught, _trawlerSurface.Value.fishCaughtQuantity, GetFarmersOnTrawler()); } // Every random interval check for new event (leak, net tearing, etc.) on Trawler if (e.IsMultipleOf(_eventSecondInterval)) { string message = String.Empty; // Check if the player gets lucky and skips getting an event, otherwise create the event(s) if (Game1.random.NextDouble() < 0.05) { message = i18n.Get("status_message.sea_favors_us"); } else { message = CreateTrawlerEventsAndGetMessage(); } // Check for empty string if (String.IsNullOrEmpty(message)) { message = i18n.Get("status_message.default"); } if (_activeNotification != message) { _activeNotification = message; BroadcastNotification(message, GetFarmersOnTrawler()); } _eventSecondInterval = (uint)Game1.random.Next(config.eventFrequencyLower, config.eventFrequencyUpper + 1) * 100; } } if (fishingTripTimer.Value <= 0f) { // Set the status as successful Game1.player.modData[MURPHY_WAS_TRIP_SUCCESSFUL_KEY] = "true"; Game1.player.modData[MURPHY_SAILED_TODAY_KEY] = "true"; // End trip due to timer finishing Game1.player.currentLocation.playSound("trainWhistle"); Game1.player.CanMove = false; Game1.addHUDMessage(new HUDMessage(i18n.Get("game_message.trip_succeeded"), null)); EndTrip(); } }