//// /// <summary> /// Drops player's currently equipped item. /// </summary> /// <param name="player"></param> /// <returns></returns> public static bool UnhandItem(Player player) { bool isUnhanded = false; // Drop mouse item always if (player.selectedItem == PlayerItemLibraries.VanillaInventorySelectedSlot) { PlayerItemLibraries.DropInventoryItem(player, PlayerItemLibraries.VanillaInventorySelectedSlot); isUnhanded = true; } // Preferably select a blank slot if (!isUnhanded) { for (int i = 0; i < player.inventory.Length; i++) { if (player.inventory[i] == null || player.inventory[i].IsAir) { player.selectedItem = i; isUnhanded = true; break; } } } // Otherwise select a non-usable item if (!isUnhanded) { for (int i = 0; i < player.inventory.Length; i++) { Item item = player.inventory[i]; if (item != null && item.holdStyle == 0 && item.createTile == -1 && !item.potion && item.useStyle == 0) { player.selectedItem = i; isUnhanded = true; break; } } } // Otherwise select a non-held item if (!isUnhanded) { for (int i = 12; i < player.inventory.Length; i++) { Item item = player.inventory[i]; if (item != null && item.holdStyle == 0) { player.selectedItem = i; isUnhanded = true; break; } } } player.noItems = true; return(isUnhanded); }
//////////////// /// <summary> /// Gets world position of the tip of a player's wielded item. /// </summary> /// <param name="player"></param> /// <returns></returns> public static Vector2 TipOfHeldItem(Player player) { Item item = player.HeldItem; if (item == null || item.IsAir) { return(Vector2.Zero); } return(PlayerItemLibraries.TipOfHeldItem(player, item, item.useStyle, Vector2.Zero) ?? Vector2.Zero); }