/// <summary> /// Performs the tree fall. /// </summary> /// <returns><c>true</c>, if tree fall was performed, <c>false</c> otherwise.</returns> /// <param name="t">Tool used</param> /// <param name="explosion">Explosion. (Not used)</param> /// <param name="tileLocation">Tile location.</param> /// <param name="location">Location.</param> public static bool performTreeFall(Tool t, int explosion, Vector2 tileLocation, GameLocation location) { ModMonitor.Log($"performTreeFall called with: t: {t} explosion: {explosion} tileLocation: {tileLocation} location: {location}", LogLevel.Trace); NetFloat health = tree.health; NetBool stump = tree.stump; NetInt treeType = tree.treeType; NetBool shakeLeft = tree.shakeLeft; NetLong lastPlayerToHit = ModHelper.Reflection.GetField <NetLong>(tree, "lastPlayerToHit").GetValue(); NetBool falling = ModHelper.Reflection.GetField <NetBool>(tree, "falling").GetValue(); string key = GetKeyForObject(treeType); //Code for calculation of tree fall position: (int)tileLocation.X + (((bool)shakeLeft) ? (-4) : 4) if ((bool)stump) { if (Config.TreeDrops[key].StumpDrops != null) { for (int i = 0; i < Config.TreeDrops[key].StumpDrops.Length / 2; i++) { if (Game1.IsMultiplayer) { Game1.createMultipleObjectDebris(Config.TreeDrops[key].StumpDrops[i, 0], (int)tileLocation.X, (int)tileLocation.Y, Config.TreeDrops[key].StumpDrops[i, 1], lastPlayerToHit, location); } else { Game1.createMultipleObjectDebris(Config.TreeDrops[key].StumpDrops[i, 0], (int)tileLocation.X, (int)tileLocation.Y, Config.TreeDrops[key].StumpDrops[i, 1], location); } } } } return(false); }
public static void PlayAnimalSound(FarmAnimal animal) { NetLong animalID = animal.myID; if (ModEntry.modifiedAnimalSounds.ContainsKey(animalID)) { string soundName = ModEntry.modifiedAnimalSounds[animalID]; if (ModEntry.modEntry.soundEffects.ContainsKey(soundName)) { int soundIndex = ModEntry.modEntry.rand.Next(0, ModEntry.modEntry.soundEffects[soundName].Count); ModEntry.modEntry.soundEffects[soundName][soundIndex].Play(); } } }
private static bool CheckUsingTool(Farmer player, NetLong playerId, NetString currentLocation) { if (player.UsingTool) { LastActions[playerId] = new PlayerLastActivity { Activity = player.CurrentTool?.Name.ToLower() ?? "N/A", When = Game1.timeOfDay, LocationName = currentLocation, Hidden = player.hidden.Value }; return(true); } return(false); }
private bool CheckCutscene(Farmer player, NetLong playerId, NetString currentLocation) { if (player.hidden != LastActions[playerId].Hidden && currentLocation == LastActions[playerId].LocationName && !(player.isRidingHorse())) { LastActions[playerId] = new PlayerLastActivity { Activity = player.hidden ? "startevent" : "endevent", When = Game1.timeOfDay, LocationName = currentLocation, Hidden = player.hidden?.Value ?? false }; return(true); } return(false); }
private static bool CheckLocationChange(NetString currentLocation, NetLong playerId) { if (currentLocation != LastActions[playerId].LocationName) { LastActions[playerId] = new PlayerLastActivity { Activity = "warped", LocationName = currentLocation, When = Game1.timeOfDay, Hidden = false }; return(true); } return(false); }
private void ReplaceCustomAnimalSound(FarmAnimal animal) { if (animal != null && animal.sound != null) { string animalSound = animal.sound.Value; if (soundEffects.ContainsKey(animalSound)) { NetLong animalID = animal.myID; animal.sound.Value = null; if (animalID != null && modifiedAnimalSounds != null && !modifiedAnimalSounds.ContainsKey(animalID)) { modifiedAnimalSounds.Add(animalID, animalSound); } } } }
private bool CheckCutscene(Farmer player, NetLong playerId, NetString currentLocation) { if (player.hidden != LastActions[playerId].Hidden && !(player.isRidingHorse())) { if (ConfigHelper.GetOptions().ShowCutsceneInfoInChatBox) { var verbed = player.hidden ? "entered a" : "finished the"; _helper.SelfInfoMessage($"{player.Name} has {verbed} cutscene."); } LastActions[playerId] = new PlayerLastActivity { Activity = "event", When = Game1.timeOfDay, LocationName = currentLocation, Hidden = player.hidden?.Value ?? false }; return(true); } return(false); }
/// <summary> /// Performs the sprout destroy. /// </summary> /// <param name="t">Tool used</param> /// <param name="tileLocation">Tile location.</param> /// <param name="location">Location.</param> private static void performSproutDestroy(Tool t, Vector2 tileLocation, GameLocation location) { ModMonitor.Log($"performSproutDestroy called with: t: {t} tileLocation: {tileLocation} location: {location}"); NetInt treeType = tree.treeType; string key = GetKeyForObject(treeType); if (Config.TreeDrops[key].SproutDrops != null) { for (int i = 0; i < Config.TreeDrops[key].SproutDrops.Length / 2; i++) { if (Game1.IsMultiplayer) { NetLong lastPlayerToHit = ModHelper.Reflection.GetField <NetLong>(tree, "lastPlayerToHit").GetValue(); Game1.createMultipleObjectDebris(Config.TreeDrops[key].SproutDrops[i, 0], (int)tileLocation.X, (int)tileLocation.Y, Config.TreeDrops[key].SproutDrops[i, 1], lastPlayerToHit, location); } else { Game1.createMultipleObjectDebris(Config.TreeDrops[key].SproutDrops[i, 0], (int)tileLocation.X, (int)tileLocation.Y, Config.TreeDrops[key].SproutDrops[i, 1], location); } } } }
/// <summary> /// "hook" of tickUpdate in StardewValley.TerrainFeatures.Tree /// </summary> /// <remarks>Warning: Gets called a lot</remarks> /// <returns><c>true</c> continue game code, <c>false</c> otherwise.</returns> /// <param name="time">current GameTime</param> /// <param name="tileLocation">location of tile to update</param> /// <param name="location">GameLocation</param> private static bool tickUpdate_Prefix(GameTime time, Vector2 tileLocation, GameLocation location) { //Skip if Mod isn't active if (!IsModActive) { return(true); } try { //skip if tree is unset or tileLocation isn't location of tree if (tree == null || !tileLocation.Equals(tree.currentTileLocation)) { return(true); } //ModMonitor.Log($"tickUpdate_Prefix called with: time: {time} tileLocation: {tileLocation} location: {location}"); NetBool falling = ModHelper.Reflection.GetField <NetBool>(tree, "falling").GetValue(); NetBool destroy = ModHelper.Reflection.GetField <NetBool>(tree, "destroy").GetValue(); if ((bool)destroy) { return(true); } if ((bool)falling) { NetBool shakeLeft = tree.shakeLeft; float shakeRotation = ModHelper.Reflection.GetField <float>(tree, "shakeRotation").GetValue(); float maxShake = ModHelper.Reflection.GetField <float>(tree, "maxShake").GetValue(); shakeRotation += (((bool)shakeLeft) ? (0f - maxShake * maxShake) : (maxShake * maxShake)); maxShake += 0.00153398083f; if ((double)Math.Abs(shakeRotation) > 1.5707963267948966) { NetInt treeType = tree.treeType; NetLong lastPlayerToHit = ModHelper.Reflection.GetField <NetLong>(tree, "lastPlayerToHit").GetValue(); string key = GetKeyForObject(treeType); if (Config.TreeDrops[key].TreeDrops != null) { for (int i = 0; i < Config.TreeDrops[key].TreeDrops.Length / 2; i++) { if (Game1.IsMultiplayer) { Game1.createMultipleObjectDebris(Config.TreeDrops[key].TreeDrops[i, 0], (int)tileLocation.X + (((bool)shakeLeft) ? (-4) : 4), (int)tileLocation.Y, Config.TreeDrops[key].TreeDrops[i, 1], lastPlayerToHit, location); } else { Game1.createMultipleObjectDebris(Config.TreeDrops[key].TreeDrops[i, 0], (int)tileLocation.X + (((bool)shakeLeft) ? (-4) : 4), (int)tileLocation.Y, Config.TreeDrops[key].TreeDrops[i, 1], location); } } } } else { maxShake -= 0.00153398083f; shakeRotation -= (((bool)shakeLeft) ? (0f - maxShake * maxShake) : (maxShake * maxShake)); } } return(true); } catch (Exception ex) { ModMonitor.Log($"Failed in {nameof(tickUpdate_Prefix)}:\n{ex}", LogLevel.Error); return(true); // run original logic } }