/// <summary> /// Swaps tools when icon is right clicked /// </summary> private void handleRightClick(object sender, EventArgsMouseStateChanged e) { if (Game1.player.CurrentItem is Tool == false || Game1.player.canMove == false || Game1.player.usingTool || Game1.activeClickableMenu != null || Game1.eventUp || isToolPartOfCustomToolInventory(Game1.player.CurrentTool) == false) { return; } // Only fire next code on first registered click if (e.NewState.RightButton == ButtonState.Released) { isHeld = false; } if (e.NewState.RightButton == ButtonState.Pressed && isHeld == false) { isHeld = true; foreach (var component in clickableComponents.ToArray()) { if (component.bounds.Contains(e.NewPosition.X, e.NewPosition.Y)) { // Name vars Item itemToSwapIn = component.item; int swapInItemIndex = Game1.player.CurrentToolIndex; int swapOutItemIndex = toolsAndTheirContainers[itemToSwapIn as Tool].IndexOf(itemToSwapIn); var containerToPlaceSwappedOutItem = toolsAndTheirContainers[itemToSwapIn as Tool]; if (swapOutItemIndex == -1) { ModEntry.Log("The item failed to update! Please replace the offending item inside a chest!"); return; } if (itemToSwapIn == Game1.player.CurrentItem) { return; } // Remove item Item itemToSwapOut = Game1.player.removeItemFromInventory(swapInItemIndex); // Swapp items Game1.player.items[swapInItemIndex] = itemToSwapIn; containerToPlaceSwappedOutItem[swapOutItemIndex] = itemToSwapOut; // Update containers toolsAndTheirContainers[itemToSwapIn as Tool] = Game1.player.items; toolsAndTheirContainers[itemToSwapOut as Tool] = containerToPlaceSwappedOutItem; // Only ignore next inv change if inventory is actually changed if (Game1.player.items != containerToPlaceSwappedOutItem) { justDidSwap = true; } return; } } } }
/// <summary> /// Removes your horse from its current location and places it next to the player /// </summary> private void callHorseOnButtonPress(object sender, EventArgsKeyPressed e) { // Do nothing // If riding horse // If player is indoors // If horse is already being called // If event up // If menu up // If keypress is not configured key ( defaults to z ) if (Game1.player.isRidingHorse() || Game1.currentLocation.isOutdoors == false || runningHorse != null || Game1.eventUp || Game1.activeClickableMenu != null || e.KeyPressed.ToString() != ModEntry.modConfig.summonHorseKey) { return; } Horse tempHorse = null; GameLocation horseLocation = null; // Find horse foreach (var location in Game1.locations) { foreach (var npc in location.characters) { // Only call horse if horse is in a different location if (location == Game1.currentLocation) { //continue; } if (npc is Horse) { if (tempHorse == null) { tempHorse = ( Horse )npc; horseLocation = location; } else { ModEntry.Log($"There are multiple horses! Calling {tempHorse.name} from {tempHorse.currentLocation.name}"); } } } } // No horse found if (tempHorse == null) { return; } // Do nothing if horse is close to farmer if (Utility.distance(tempHorse.position.X, Game1.player.position.X, tempHorse.position.Y, Game1.player.position.Y) < 600) { ModEntry.Log("Your horse is right next to you... don't be lazy, go walk up to it!"); return; } // Change horse location if (Game1.currentLocation.characters.Contains(tempHorse) == false && horseLocation.characters.Remove(tempHorse)) { Game1.currentLocation.characters.Add(tempHorse); tempHorse.currentLocation = Game1.currentLocation; } runningHorse = tempHorse; // Set horse start position int positionXToRunTo = Game1.player.getTileX() * Game1.tileSize; int positionYToRunTo = Game1.player.getTileY() * Game1.tileSize; positionToRunTo = new Vector2(positionXToRunTo, positionYToRunTo); //Game1.currentLocation.tile /* * int differenceBetweenPlayerAndHorse = ( Game1.player.sprite.spriteWidth - runningHorse.sprite.spriteWidth ) / 2 * Game1.pixelZoom + 6; * positionToRunTo = Game1.player.position; * positionToRunTo.X += differenceBetweenPlayerAndHorse; * runningHorse.position.Y = positionToRunTo.Y; * runningHorse.position.X = Game1.viewport.X - runningHorse.sprite.getWidth() * Game1.pixelZoom; */ float boundingBoxOffset = runningHorse.position.X - runningHorse.GetBoundingBox().X; runningHorse.position.X = positionToRunTo.X + boundingBoxOffset; //runningHorse.position.X = Game1.viewport.X - runningHorse.sprite.getWidth() * Game1.pixelZoom; runningHorse.position.Y = positionToRunTo.Y; // Set horse moving right runningHorse.facingDirection = 1; // Set starting variables currentRunSpeed = 30; speedToSlowPerRender = 1; runningHorse.sprite.currentAnimation = null; poofAnimator.position = runningHorse.position; poofAnimator.deathAnimation(); runningHorse = null; }