public HorseWrapper(Stable stable, HorseOverhaul mod, Chest saddleBag, int?stableID) { Stable = stable; // has to be assigned right now because the horse gets removed from the character list while it has a rider Horse = stable.getStableHorse(); this.mod = mod; SaddleBag = saddleBag; StableID = stableID; }
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 virtual void OnRequestHorseWarp(long uid) { if (!Game1.IsMasterGame) { return; } Farmer farmer = Game1.getFarmer(uid); Horse horse = null; foreach (Building b in Game1.getFarm().buildings) { if (b is Stable) { Stable stable = b as Stable; if (stable.getStableHorse() != null && stable.getStableHorse().getOwner() == farmer) { horse = stable.getStableHorse(); break; } } } if (horse == null || Utility.GetHorseWarpRestrictionsForFarmer(farmer) != 0) { return; } horse.mutex.RequestLock(delegate { horse.mutex.ReleaseLock(); GameLocation currentLocation = horse.currentLocation; Vector2 tileLocation = horse.getTileLocation(); for (int i = 0; i < 8; i++) { Game1.multiplayer.broadcastSprites(currentLocation, new TemporaryAnimatedSprite(10, new Vector2(tileLocation.X + Utility.RandomFloat(-1f, 1f), tileLocation.Y + Utility.RandomFloat(-1f, 0f)) * 64f, Color.White, 8, flipped: false, 50f) { layerDepth = 1f, motion = new Vector2(Utility.RandomFloat(-0.5f, 0.5f), Utility.RandomFloat(-0.5f, 0.5f)) }); } currentLocation.playSoundAt("wand", horse.getTileLocation()); currentLocation = farmer.currentLocation; tileLocation = farmer.getTileLocation(); currentLocation.playSoundAt("wand", tileLocation); for (int j = 0; j < 8; j++) { Game1.multiplayer.broadcastSprites(currentLocation, new TemporaryAnimatedSprite(10, new Vector2(tileLocation.X + Utility.RandomFloat(-1f, 1f), tileLocation.Y + Utility.RandomFloat(-1f, 0f)) * 64f, Color.White, 8, flipped: false, 50f) { layerDepth = 1f, motion = new Vector2(Utility.RandomFloat(-0.5f, 0.5f), Utility.RandomFloat(-0.5f, 0.5f)) }); } Game1.warpCharacter(horse, farmer.currentLocation, tileLocation); int num = 0; for (int num2 = (int)tileLocation.X + 3; num2 >= (int)tileLocation.X - 3; num2--) { Game1.multiplayer.broadcastSprites(currentLocation, new TemporaryAnimatedSprite(6, new Vector2(num2, tileLocation.Y) * 64f, Color.White, 8, flipped: false, 50f) { layerDepth = 1f, delayBeforeAnimationStart = num * 25, motion = new Vector2(-0.25f, 0f) }); num++; } }); }
public override bool checkAction(Farmer who, GameLocation l) { if (who != null && !who.canMove) { return(false); } if (rider == null) { mutex.RequestLock(delegate { if (who.mount != null || rider != null || who.FarmerSprite.PauseForSingleAnimation) { mutex.ReleaseLock(); } else if ((getOwner() == Game1.player || (getOwner() == null && (Game1.player.horseName.Value == null || Game1.player.horseName.Value.Length == 0 || Utility.findHorseForPlayer(Game1.player.UniqueMultiplayerID) == null))) && base.Name.Length <= 0) { foreach (Building current in (Game1.getLocationFromName("Farm") as Farm).buildings) { if ((int)current.daysOfConstructionLeft <= 0 && current is Stable) { Stable stable = current as Stable; if (stable.getStableHorse() == this) { stable.owner.Value = who.UniqueMultiplayerID; stable.updateHorseOwnership(); } else if ((long)stable.owner == who.UniqueMultiplayerID) { stable.owner.Value = 0L; stable.updateHorseOwnership(); } } } if (Game1.player.horseName.Value == null || Game1.player.horseName.Value.Length == 0) { Game1.activeClickableMenu = new NamingMenu(nameHorse, Game1.content.LoadString("Strings\\Characters:NameYourHorse"), Game1.content.LoadString("Strings\\Characters:DefaultHorseName")); } } else if (who.items.Count > who.CurrentToolIndex && who.items[who.CurrentToolIndex] != null && who.Items[who.CurrentToolIndex] is Hat) { if (hat.Value != null) { Game1.createItemDebris((Hat)hat, base.position, facingDirection); hat.Value = null; } else { Hat value = who.Items[who.CurrentToolIndex] as Hat; who.Items[who.CurrentToolIndex] = null; hat.Value = value; Game1.playSound("dirtyHit"); } mutex.ReleaseLock(); } else { rider = who; rider.freezePause = 5000; rider.synchronizedJump(6f); rider.Halt(); if (rider.Position.X < base.Position.X) { rider.faceDirection(1); } l.playSound("dwop"); mounting.Value = true; rider.isAnimatingMount = true; rider.completelyStopAnimatingOrDoingAction(); rider.faceGeneralDirection(Utility.PointToVector2(GetBoundingBox().Center), 0, opposite: false, useTileCalculations: false); } }); return(true); } dismounting.Value = true; rider.isAnimatingMount = true; farmerPassesThrough = false; rider.TemporaryPassableTiles.Clear(); Vector2 position = Utility.recursiveFindOpenTileForCharacter(rider, rider.currentLocation, rider.getTileLocation(), 8); base.Position = new Vector2(position.X * 64f + 32f - (float)(GetBoundingBox().Width / 2), position.Y * 64f + 4f); roomForHorseAtDismountTile = !base.currentLocation.isCollidingPosition(GetBoundingBox(), Game1.viewport, isFarmer: true, 0, glider: false, this); base.Position = rider.Position; dismounting.Value = false; rider.isAnimatingMount = false; Halt(); if (!position.Equals(Vector2.Zero) && Vector2.Distance(position, rider.getTileLocation()) < 2f) { rider.synchronizedJump(6f); l.playSound("dwop"); rider.freezePause = 5000; rider.Halt(); rider.xOffset = 0f; dismounting.Value = true; rider.isAnimatingMount = true; dismountTile = position; Game1.debugOutput = "dismount tile: " + position.ToString(); } else { dismount(); } return(true); }