public static IList<Item> SetupStartInventory(Player player) { IList<Item> items = new List<Item>(); Item item = new Item(); item.SetDefaults("Copper Shortsword"); item.Prefix(-1); items.Add(item); item = new Item(); item.SetDefaults("Copper Pickaxe"); item.Prefix(-1); items.Add(item); item = new Item(); item.SetDefaults("Copper Axe"); item.Prefix(-1); items.Add(item); foreach (ModPlayer modPlayer in player.modPlayers) { modPlayer.SetupStartInventory(items); } IDictionary<int, int> counts = new Dictionary<int, int>(); foreach (Item item0 in items) { if (item0.maxStack > 1) { if (!counts.ContainsKey(item0.netID)) { counts[item0.netID] = 0; } counts[item0.netID] += item0.stack; } } int k = 0; while (k < items.Count) { bool flag = true; int id = items[k].netID; if (counts.ContainsKey(id)) { items[k].stack = counts[id]; if (items[k].stack > items[k].maxStack) { items[k].stack = items[k].maxStack; } counts[id] -= items[k].stack; if (items[k].stack <= 0) { items.RemoveAt(k); flag = false; } } if (flag) { k++; } } return items; }
TextSnippet ITagHandler.Parse(string text, Color baseColor, string options) { Item item = new Item(); int type; if (int.TryParse(text, out type)) { item.netDefaults(type); } else { item.SetDefaults(text); } if (item.type <= 0) { return new TextSnippet(text); } item.stack = 1; if (options != null) { string[] array = options.Split(new char[] { ',' }); for (int i = 0; i < array.Length; i++) { if (array[i].Length != 0) { char c = array[i][0]; int value2; if (c != 'p') { int value; if ((c == 's' || c == 'x') && int.TryParse(array[i].Substring(1), out value)) { item.stack = Utils.Clamp<int>(value, 1, item.maxStack); } } else if (int.TryParse(array[i].Substring(1), out value2)) { item.Prefix((int)((byte)Utils.Clamp<int>(value2, 0, 84))); } } } } string str = ""; if (item.stack > 1) { str = " (" + item.stack + ")"; } return new ItemTagHandler.ItemSnippet(item) { Text = "[" + item.AffixName() + str + "]", CheckForHover = true, DeleteWhole = true }; }
public void AddIngredient(string itemName, int stack = 1) { Item item = new Item(); item.SetDefaults(itemName); if (item.type == 0) { throw new RecipeException("No item is named " + itemName); } item.stack = stack; items.Add(item); }
public void AddIngredient(int itemID, int stack = 1) { if (itemID <= 0 || itemID >= ItemLoader.ItemCount) { throw new RecipeException("No item has ID " + itemID); } Item item = new Item(); item.SetDefaults(itemID, false); item.stack = stack; items.Add(item); }
public void Process(int start, int length, int num, int whoAmI, byte[] readBuffer, byte bufferData) { int playerIndex; if (Main.netMode == 2) { playerIndex = whoAmI; } else { playerIndex = (int)readBuffer[start + 1]; } if (playerIndex != Main.myPlayer) { Player player = Main.players[playerIndex]; lock (player) { int inventorySlot = (int)readBuffer[start + 2]; int stack = (int)readBuffer[start + 3]; string itemName = Encoding.ASCII.GetString(readBuffer, start + 4, length - 4); Item item = new Item(); item.SetDefaults(itemName); item.Stack = stack; if (inventorySlot < 44) { player.inventory[inventorySlot] = item; } else { player.armor[inventorySlot - 44] = item; } if (Main.netMode == 2) { NetMessage.SendData(5, -1, whoAmI, itemName, playerIndex, (float)inventorySlot); } } } }
public static void SetStartInventory(Player player, IList<Item> items) { if (items.Count <= 50) { for (int k = 0; k < items.Count; k++) { player.inventory[k] = items[k]; } } else { for (int k = 0; k < 49; k++) { player.inventory[k] = items[k]; } Item bag = new Item(); bag.SetDefaults(ModLoader.GetMod("ModLoader").ItemType("StartBag")); for (int k = 49; k < items.Count; k++) { ((StartBag)bag.modItem).AddItem(items[k]); } player.inventory[49] = bag; } }
// Modded version of Terraria's Original private bool TryToStoreItemInNearbyChest(TSPlayer player, Vector2 playerPosition, Item itemToStore, IChest chest) { float quickStackRange = this.Config.QuickStackNearbyRange * 16; if (Chest.isLocked(chest.Location.X, chest.Location.Y)) return false; Vector2 vector2 = new Vector2((chest.Location.X * 16 + 16), (chest.Location.Y * 16 + 16)); if ((vector2 - playerPosition).Length() > quickStackRange) return false; ProtectionEntry protection; if (this.ProtectionManager.CheckBlockAccess(player, chest.Location, false, out protection)) { bool isRefillChest = (protection != null && protection.RefillChestData != null); bool isTradeChest = (protection != null && protection.TradeChestData != null); if (!isRefillChest && !isTradeChest) { bool isBankChest = (protection != null && protection.BankChestKey != BankChestDataKey.Invalid); bool hasEmptySlot = false; bool containsSameItem = false; for (int i = 0; i < Chest.maxItems; i++) { ItemData chestItem = chest.Items[i]; if (chestItem.Type <= 0 || chestItem.StackSize <= 0) hasEmptySlot = true; else if (itemToStore.netID == (int)chestItem.Type) { int remainingStack = itemToStore.maxStack - chestItem.StackSize; if (remainingStack > 0) { if (remainingStack > itemToStore.stack) remainingStack = itemToStore.stack; itemToStore.stack = itemToStore.stack - remainingStack; chestItem.StackSize = chestItem.StackSize + remainingStack; if (isBankChest) this.ServerMetadataHandler.EnqueueUpdateBankChestItem(protection.BankChestKey, i, chestItem); if (itemToStore.stack <= 0) { itemToStore.SetDefaults(); return true; } } containsSameItem = true; } } if (containsSameItem && hasEmptySlot && itemToStore.stack > 0) { for (int i = 0; i < Chest.maxItems; i++) { ItemData chestItem = chest.Items[i]; if (chestItem.Type == 0 || chestItem.StackSize == 0) { ItemData itemDataToStore = ItemData.FromItem(itemToStore); chest.Items[i] = itemDataToStore; if (isBankChest) this.ServerMetadataHandler.EnqueueUpdateBankChestItem(protection.BankChestKey, i, itemDataToStore); itemToStore.SetDefaults(); return true; } } } } } return false; }
// Modded version of Terraria's Original private Item PutItemInNearbyChest(TSPlayer player, Item item, Vector2 position) { float quickStackRange = this.Config.QuickStackNearbyRange * 16; for (int i = 0; i < Main.chest.Length; i++) { Chest chest = Main.chest[i]; if (chest == null || !Main.tile[chest.x, chest.y].active()) continue; bool containsSameItem = false; bool hasEmptySlot = false; bool isPlayerInChest = false; for (int j = 0; j < 255; j++) { if (Main.player[j].chest == i) { isPlayerInChest = true; break; } } if (!isPlayerInChest && !Chest.isLocked(chest.x, chest.y)) { Vector2 vector2 = new Vector2((chest.x * 16 + 16), (chest.y * 16 + 16)); if ((vector2 - position).Length() < quickStackRange) { ProtectionEntry protection; if (this.ProtectionManager.CheckBlockAccess(player, new DPoint(chest.x, chest.y), false, out protection)) { bool isRefillChest = (protection != null && protection.RefillChestData != null); if (!isRefillChest) { bool isBankChest = (protection != null && protection.BankChestKey != BankChestDataKey.Invalid); for (int j = 0; j < chest.item.Length; j++) { Item chestItem = chest.item[j]; if (chestItem.type <= 0 || chestItem.stack <= 0) hasEmptySlot = true; else if (item.IsTheSameAs(chestItem)) { containsSameItem = true; int stackLeft = chestItem.maxStack - chestItem.stack; if (stackLeft > 0) { if (stackLeft > item.stack) stackLeft = item.stack; item.stack = item.stack - stackLeft; chestItem.stack = chestItem.stack + stackLeft; if (isBankChest) this.ServerMetadataHandler.EnqueueUpdateBankChestItem(protection.BankChestKey, j, ItemData.FromItem(chestItem)); if (item.stack <= 0) { item.SetDefaults(); return item; } } } } if (containsSameItem && hasEmptySlot && item.stack > 0) { for (int k = 0; k < chest.item.Length; k++) { Item chestItem = chest.item[k]; if (chestItem.type == 0 || chestItem.stack == 0) { chest.item[k] = item.Clone(); if (isBankChest) this.ServerMetadataHandler.EnqueueUpdateBankChestItem(protection.BankChestKey, k, ItemData.FromItem(item)); item.SetDefaults(); return item; } } } } } } } } return item; }
public virtual bool IsVanitySet(int head, int body, int legs) { Item headItem = new Item(); if (head >= 0) { headItem.SetDefaults(Item.headType[head], true); } Item bodyItem = new Item(); if (body >= 0) { bodyItem.SetDefaults(Item.bodyType[body], true); } Item legItem = new Item(); if (legs >= 0) { legItem.SetDefaults(Item.legType[legs], true); } return IsArmorSet(headItem, bodyItem, legItem); }
public override void SetupStartInventory(IList<Item> items) { if (AprilFools.CheckAprilFools()) { Item item = new Item(); item.SetDefaults(mod.ItemType("AprilFools")); items.Add(item); } }
//in Terraria.UI.ItemSlot in block from CanRightClick call ItemLoader.RightClick(inv[slot], player) public static void RightClick(Item item, Player player) { if (Main.mouseRightRelease) { item.modItem?.RightClick(player); foreach (var hook in HookRightClick) { hook(item, player); } item.stack--; if (item.stack == 0) { item.SetDefaults(); } Main.PlaySound(7); Main.stackSplit = 30; Main.mouseRightRelease = false; Recipe.FindRecipes(); } }
static ItemLoader() { for (int k = 0; k < ItemID.Count; k++) { Item item = new Item(); item.SetDefaults(k); if (item.wingSlot > 0) { vanillaWings[item.wingSlot] = k; } } }
public static Item GetWing(Player player) { Item item = null; for (int k = 3; k < 8 + player.extraAccessorySlots; k++) { if (player.armor[k].wingSlot == player.wingsLogic) { item = player.armor[k]; } } if (item != null) { return item; } if (player.wingsLogic > 0 && player.wingsLogic < Main.maxWings) { item = new Item(); item.SetDefaults(vanillaWings[player.wingsLogic]); return item; } if (player.wingsLogic >= Main.maxWings) { EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Wings, player.wingsLogic); if (texture != null) { return texture.item.item; } } return null; }
public static bool TryPlacingInChest(Item I, bool justCheck) { bool flag = false; Player player = Main.player[Main.myPlayer]; Item[] item = player.bank.item; if (player.chest > -1) { item = Main.chest[player.chest].item; flag = (Main.netMode == 1); } else if (player.chest == -2) { item = player.bank.item; } else if (player.chest == -3) { item = player.bank2.item; } bool flag2 = false; if (I.maxStack > 1) { for (int i = 0; i < 40; i++) { if (item[i].stack < item[i].maxStack && I.IsTheSameAs(item[i])) { int num = I.stack; if (I.stack + item[i].stack > item[i].maxStack) { num = item[i].maxStack - item[i].stack; } if (justCheck) { flag2 = (flag2 || num > 0); break; } I.stack -= num; item[i].stack += num; Main.PlaySound(7, -1, -1, 1); if (I.stack <= 0) { I.SetDefaults(0, false); if (flag) { NetMessage.SendData(32, -1, -1, "", player.chest, (float)i, 0f, 0f, 0, 0, 0); break; } break; } else { if (item[i].type == 0) { item[i] = I.Clone(); I.SetDefaults(0, false); } if (flag) { NetMessage.SendData(32, -1, -1, "", player.chest, (float)i, 0f, 0f, 0, 0, 0); } } } } } if (I.stack > 0) { int j = 0; while (j < 40) { if (item[j].stack == 0) { if (justCheck) { flag2 = true; break; } Main.PlaySound(7, -1, -1, 1); item[j] = I.Clone(); I.SetDefaults(0, false); if (flag) { NetMessage.SendData(32, -1, -1, "", player.chest, (float)j, 0f, 0f, 0, 0, 0); break; } break; } else { j++; } } } return flag2; }
private void ItemSetup(Item item, String itemName, int stackSize, float x, float y, float vX, float vY) { item.SetDefaults(itemName); item.Stack = (int)stackSize; item.Position.X = x; item.Position.Y = y; item.Velocity.X = vX; item.Velocity.Y = vY; item.Active = true; }
public void Process(int start, int length, int num, int whoAmI, byte[] readBuffer, byte bufferData) { short itemIndex = BitConverter.ToInt16(readBuffer, num); num += 2; float x = BitConverter.ToSingle(readBuffer, num); num += 4; float y = BitConverter.ToSingle(readBuffer, num); num += 4; float vX = BitConverter.ToSingle(readBuffer, num); num += 4; float vY = BitConverter.ToSingle(readBuffer, num); num += 4; byte stackSize = readBuffer[num++]; string itemName = Encoding.ASCII.GetString(readBuffer, num, length - num + start); Item item = Main.item[(int)itemIndex]; if (Main.netMode == 1) { if (itemName == "0") { item.Active = false; return; } ItemSetup(item, itemName, stackSize, x, y, vX, vY); item.Wet = Collision.WetCollision(item.Position, item.Width, item.Height); } else if (itemName == "0") { if (itemIndex < 200) { item.Active = false; NetMessage.SendData(21, -1, -1, "", (int)itemIndex); } } else { bool isNewItem = false; if (itemIndex == 200) { isNewItem = true; Item newItem = new Item(); newItem.SetDefaults(itemName); itemIndex = (short)Item.NewItem((int)x, (int)y, newItem.Width, newItem.Height, newItem.Type, (int)stackSize, true); item = Main.item[(int)itemIndex]; } ItemSetup(item, itemName, stackSize, x, y, vX, vY); item.Owner = Main.myPlayer; if (isNewItem) { NetMessage.SendData(21, -1, -1, "", (int)itemIndex); item.OwnIgnore = whoAmI; item.OwnTime = 100; item.FindOwner((int)itemIndex); return; } NetMessage.SendData(21, -1, whoAmI, "", (int)itemIndex); } }