public static bool CheckHorseInteraction(HorseOverhaul mod, GameLocation currentLocation, int mouseX, int mouseY, bool ignoreMousePosition) { foreach (Horse horse in currentLocation.characters.OfType <Horse>()) { // check if the interaction was a mouse click on a horse or a button press near a horse if (horse != null && !horse.IsTractor() && IsInRange(horse, mouseX, mouseY, ignoreMousePosition)) { HorseWrapper horseW = null; mod.Horses.Where(h => h?.Horse?.HorseId == horse.HorseId).Do(h => horseW = h); if (Game1.player.CurrentItem != null && mod.Config.Feeding) { Item currentItem = Game1.player.CurrentItem; if (mod.Config.NewFoodSystem) { var potentialhorseFood = HorseFoodData.ClassifyHorseFood(currentItem); if (potentialhorseFood.IsHorseFood) { int friendship = potentialhorseFood.FriendshipOnFeed; FeedHorse(mod, horseW, currentItem, friendship); return(true); } else if (potentialhorseFood.ReplyOnFeed != null) { Game1.drawObjectDialogue(mod.Helper.Translation.Get(potentialhorseFood.ReplyOnFeed)); return(false); } // don't return here so we can fall into the saddle bag case } else if (FoodData.IsGenericEdible(currentItem)) { int friendship = FoodData.CalculateGenericFriendshipGain(currentItem, horseW.Friendship); FeedHorse(mod, horseW, currentItem, friendship); return(true); } } if (Context.IsWorldReady && Context.CanPlayerMove && Context.IsPlayerFree && mod.Config.SaddleBag) { if (horseW.SaddleBag != null) { horseW.SaddleBag.ShowMenu(); return(true); } } } } return(false); }
public HorseMenu(HorseOverhaul mod, HorseWrapper horse) : base((Game1.viewport.Width / 2) - (HorseMenu.width / 2), (Game1.viewport.Height / 2) - (HorseMenu.height / 2), HorseMenu.width, HorseMenu.height, false) { this.mod = mod; Game1.player.Halt(); HorseMenu.width = Game1.tileSize * 6; HorseMenu.height = Game1.tileSize * 8; this.textBox = new TextBox((Texture2D)null, (Texture2D)null, Game1.dialogueFont, Game1.textColor); this.textBox.X = (Game1.viewport.Width / 2) - (Game1.tileSize * 2) - 12; this.textBox.Y = this.yPositionOnScreen - 4 + (Game1.tileSize * 2); this.textBox.Width = Game1.tileSize * 4; this.textBox.Height = Game1.tileSize * 3; this.textBoxCC = new ClickableComponent(new Rectangle(this.textBox.X, this.textBox.Y, this.textBox.Width, Game1.tileSize), string.Empty) { myID = 110, downNeighborID = 104 }; this.textBox.Text = Game1.player.horseName; this.textBox.Selected = false; var yPos1 = this.yPositionOnScreen + HorseMenu.height - Game1.tileSize - IClickableMenu.borderWidth; var yPos2 = this.yPositionOnScreen - (Game1.tileSize / 2) + IClickableMenu.spaceToClearTopBorder + (Game1.tileSize * 4) - (Game1.tileSize / 2); ClickableTextureComponent textureComponent1 = new ClickableTextureComponent(new Rectangle(this.xPositionOnScreen + HorseMenu.width + 4, yPos1, Game1.tileSize, Game1.tileSize), Game1.mouseCursors, Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 46, -1, -1), 1f, false) { myID = 101, upNeighborID = 103 }; this.okayButton = textureComponent1; ClickableTextureComponent textureComponent5 = new ClickableTextureComponent( (horse.Friendship / 10.0).ToString() + "<", new Rectangle(this.xPositionOnScreen + IClickableMenu.spaceToClearSideBorder + (Game1.tileSize / 2) + 16, yPos2, HorseMenu.width - (Game1.tileSize * 2), Game1.tileSize), (string)null, mod.Helper.Translation.Get("Friendship"), Game1.mouseCursors, new Rectangle(172, 512, 16, 16), 4f, false) { myID = 102 }; this.love = textureComponent5; this.loveHover = new ClickableComponent(new Rectangle(this.xPositionOnScreen + IClickableMenu.spaceToClearSideBorder, this.yPositionOnScreen + IClickableMenu.spaceToClearTopBorder + (Game1.tileSize * 3) - (Game1.tileSize / 2), HorseMenu.width, Game1.tileSize), "Friendship") { myID = 109 }; this.horse = horse; if (!Game1.options.SnappyMenus) { return; } this.populateClickableComponentList(); this.snapToDefaultClickableComponent(); }
public StateMessage(HorseWrapper wrapper) { HorseID = wrapper.Stable.HorseId; GotWater = wrapper.GotWater; GotFed = wrapper.GotFed; WasPet = wrapper.WasPet; Friendship = wrapper.Friendship; StableID = wrapper.StableID; HasHeater = wrapper.HasHeater; }
private void OpenHorseMenu(int?x = null, int?y = null) { if (x == null && y == null) { HorseWrapper horse = null; Horses.Where(h => h.Horse.getOwner() == Game1.player && h.Horse.getName() == Game1.player.horseName).Do(h => horse = h); if (horse != null) { Game1.activeClickableMenu = new HorseMenu(this, horse); } } }
public static bool CheckForPetting(ref Horse __instance, ref bool __result, ref Farmer who) { try { if (!mod.Config.Petting || HorseOverhaul.IsTractor(__instance)) { return(true); } HorseWrapper horseW = null; foreach (var item in mod.Horses) { if (item.Horse == __instance) { horseW = item; break; } } if (__instance.getOwner() == who && horseW != null && !horseW.WasPet) { horseW.JustGotPetted(); if (mod.Config.ThinHorse) { __instance.doEmote(Character.heartEmote); } __result = true; return(false); } else { return(true); } } catch (Exception e) { mod.ErrorLog("There was an exception in a patch", e); return(true); } }
public static void FeedHorse(HorseOverhaul mod, HorseWrapper horseW, Item currentItem, int friendship) { if (horseW.GotFed && !mod.Config.AllowMultipleFeedingsADay) { Game1.drawObjectDialogue(mod.Helper.Translation.Get("AteEnough", new { name = horseW.Horse.displayName })); } else { string translation = mod.Helper.Translation.Get("AteFood", new { name = horseW.Horse.displayName, foodName = currentItem.DisplayName }); if (mod.Config.NewFoodSystem) { string translationKey; if (friendship <= 5) { translationKey = "AteFoodDislike"; } else if (friendship >= 15) { translationKey = "AteFoodLove"; } else { translationKey = "AteFoodLike"; } translation += " " + mod.Helper.Translation.Get(translationKey); } Game1.drawObjectDialogue(translation); if (mod.Config.ThinHorse) { horseW.Horse.doEmote(Character.happyEmote); } Game1.player.reduceActiveItemByOne(); horseW.JustGotFood(friendship); } }
public static bool SaveItemsFromDemolition(Stable __instance) { try { if (HorseOverhaul.IsGarage(__instance)) { return(true); } HorseWrapper horseW = null; mod.Horses.Where(x => x.Horse == __instance.getStableHorse()).Do(x => horseW = x); if (horseW != null && horseW.SaddleBag != null) { if (horseW.SaddleBag.items.Count > 0) { foreach (var item in horseW.SaddleBag.items) { Game1.player.team.returnedDonations.Add(item); Game1.player.team.newLostAndFoundItems.Value = true; } horseW.SaddleBag.items.Clear(); } horseW.SaddleBag = null; } return(true); } catch (Exception e) { mod.ErrorLog("There was an exception in a patch", e); return(true); } }
public HorseMenu(HorseOverhaul mod, HorseWrapper horse) : base((Game1.viewport.Width / 2) - (HorseMenu.width / 2), (Game1.viewport.Height / 2) - (HorseMenu.height / 2), HorseMenu.width, HorseMenu.height, false) { this.mod = mod; this.horse = horse; Game1.player.Halt(); HorseMenu.width = Game1.tileSize * 6; HorseMenu.height = Game1.tileSize * 8; this.textBox = new TextBox(null, null, Game1.dialogueFont, Game1.textColor); this.textBox.X = (Game1.viewport.Width / 2) - (Game1.tileSize * 2) - 12; this.textBox.Y = this.yPositionOnScreen - 4 + (Game1.tileSize * 2); this.textBox.Width = Game1.tileSize * 4; this.textBox.Height = Game1.tileSize * 3; this.textBox.Text = Game1.player.horseName; this.textBox.Selected = false; var yPos = this.yPositionOnScreen + HorseMenu.height - Game1.tileSize - IClickableMenu.borderWidth; this.okayButton = new ClickableTextureComponent(new Rectangle(this.xPositionOnScreen + HorseMenu.width + 4, yPos, Game1.tileSize, Game1.tileSize), Game1.mouseCursors, Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 46, -1, -1), 1f, false) { myID = okButtonID }; if (!Game1.options.SnappyMenus) { return; } this.populateClickableComponentList(); this.snapToDefaultClickableComponent(); }
public HorseMenu(HorseOverhaul mod, HorseWrapper horse) : base(Game1.player.horseName.Value) { this.mod = mod; this.horse = horse; }
private bool CheckHorseInteraction(GameLocation currentLocation, int x, int y, bool wasController) { // Find if click was on Horse foreach (Horse horse in currentLocation.characters.OfType <Horse>()) { // Can only feed your own horse if (horse.getOwner() != Game1.player || IsTractor(horse)) { continue; } HorseWrapper horseW = null; Horses.Where(h => h.Horse == horse).Do(h => horseW = h); if (horseW == null) { continue; } if (IsInRange(horse, x, y, wasController)) { if (Game1.player.CurrentItem != null && Config.Feeding) { // Holding food Item currentItem = Game1.player.CurrentItem; if (IsEdible(currentItem)) { if (horseW.GotFed) { Game1.drawObjectDialogue(Helper.Translation.Get("AteEnough", new { name = horse.displayName })); } else { Game1.drawObjectDialogue(Helper.Translation.Get("AteFood", new { name = horse.displayName, foodName = currentItem.DisplayName })); if (Config.ThinHorse) { horse.doEmote(Character.happyEmote); } Game1.player.reduceActiveItemByOne(); horseW.JustGotFood(CalculateExpGain(currentItem, horseW.Friendship)); } return(true); } } if (Context.IsWorldReady && Context.CanPlayerMove && Context.IsPlayerFree && Config.SaddleBag) { if (horseW.SaddleBag != null) { horseW.SaddleBag.ShowMenu(); return(true); } } } } return(false); }
private void SaveChestsAndReset() { foreach (Building building in Game1.getFarm().buildings) { if (building is Stable stable && !IsGarage(stable) && stable.getStableHorse() != null) { stable.getStableHorse().forceOneTileWide.Value = false; if (Config.SaddleBag) { HorseWrapper horse = null; Horses.Where(x => x.Horse == stable.getStableHorse()).Do(x => horse = x); if (horse != null && horse.SaddleBag != null) { // find the first free position int stableID = -1; int i = 0; while (i < 10) { if (!Game1.getFarm().Objects.ContainsKey(new Vector2(i, 0))) { stableID = i; break; } i++; } if (stableID == -1) { ErrorLog("Couldn't find a spot to save the saddle bag chest"); if (horse.SaddleBag.items.Count > 0) { foreach (var item in horse.SaddleBag.items) { Game1.player.team.returnedDonations.Add(item); Game1.player.team.newLostAndFoundItems.Value = true; } horse.SaddleBag.items.Clear(); } horse.SaddleBag = null; return; } if (stable.modData.ContainsKey($"{ModManifest.UniqueID}/stableID")) { stable.modData[$"{ModManifest.UniqueID}/stableID"] = stableID.ToString(); } else { stable.modData.Add($"{ModManifest.UniqueID}/stableID", stableID.ToString()); } if (horse.SaddleBag != null) { horse.SaddleBag.TileLocation = new Vector2(stableID, 0); } Game1.getFarm().Objects.Add(new Vector2(stableID, 0), horse.SaddleBag); } } } } }
private void CheckHorseInteraction(GameLocation currentLocation, int x, int y, bool wasController) { // Find if click was on Horse foreach (Horse horse in currentLocation.characters.OfType <Horse>()) { // Can only feed your own horse if (horse.getOwner() != Game1.player || IsTractor(horse)) { continue; } HorseWrapper horseW = null; Horses.Where(h => h.Horse == horse).Do(h => horseW = h); if (horseW == null) { continue; } if (IsInRange(horse, x, y, wasController)) { if (Game1.player.CurrentItem != null && Config.Feeding) { // Holding food Item currentItem = Game1.player.CurrentItem; if (IsEdible(currentItem)) { Item food = Game1.player.CurrentItem; if (horseW.GotFed) { Game1.drawObjectDialogue(Helper.Translation.Get("AteEnough", new { name = horse.displayName })); } else { Game1.drawObjectDialogue(Helper.Translation.Get("AteFood", new { name = horse.displayName, foodName = food.DisplayName })); if (Config.ThinHorse) { horse.doEmote(Character.happyEmote); } Game1.player.reduceActiveItemByOne(); horseW.JustGotFood(CalculateExpGain(currentItem, horseW.Friendship)); } return; } } if (Context.IsWorldReady && Context.CanPlayerMove && Context.IsPlayerFree && Config.SaddleBag) { if (horseW.SaddleBag != null) { horseW.SaddleBag.ShowMenu(); return; } } } } if (Config.PetFeeding && Game1.player.hasPet()) { Pet pet = Game1.player.getPet(); if (pet != null) { if (IsInRange(pet, x, y, wasController)) { if (Game1.player.CurrentItem != null) { // Holding food Item currentItem = Game1.player.CurrentItem; if (IsEdible(currentItem)) { Item food = Game1.player.CurrentItem; if (pet?.modData?.TryGetValue($"{ModManifest.UniqueID}/gotFed", out _) == true) { Game1.drawObjectDialogue(Helper.Translation.Get("AteEnough", new { name = pet.displayName })); } else { pet.modData.Add($"{ModManifest.UniqueID}/gotFed", "fed"); Game1.drawObjectDialogue(Helper.Translation.Get("AteFood", new { name = pet.displayName, foodName = food.DisplayName })); pet.doEmote(Character.happyEmote); Game1.player.reduceActiveItemByOne(); pet.friendshipTowardFarmer.Set(Math.Min(1000, pet.friendshipTowardFarmer.Value + CalculateExpGain(currentItem, pet.friendshipTowardFarmer.Value))); } return; } } } } } }