/** * Returns true if the given player has any of the given item types in thier inventory. * index : Is set to the index of the item found. If it isn't found, it is set to -1. * counts : the minimum stack per item needed for HasItem to return true. * includeAmmo : true if you wish to include the ammo slots. * includeCoins : true if you wish to include the coin slots. */ public static bool HasItem(Player player, int[] types, ref int index, int[] counts = default, bool includeAmmo = false, bool includeCoins = false) { if (types == null || types.Length == 0) { return(false); //no types to check! } if (counts == null || counts.Length == 0) { counts = BaseUtility.FillArray(new int[types.Length], 1); } int countIndex = -1; if (includeCoins) { for (int m = 50; m < 54; m++) { Item item = player.inventory[m]; if (item != null && BaseUtility.InArray(types, item.type, ref countIndex) && item.stack >= counts[countIndex]) { index = m; return(true); } } } if (includeAmmo) { for (int m = 54; m < 58; m++) { Item item = player.inventory[m]; if (item != null && BaseUtility.InArray(types, item.type, ref countIndex) && item.stack >= counts[countIndex]) { index = m; return(true); } } } for (int m = 0; m < 50; m++) { Item item = player.inventory[m]; if (item != null && BaseUtility.InArray(types, item.type, ref countIndex) && item.stack >= counts[countIndex]) { index = m; return(true); } } return(false); }
public static Color GetTimedColor(Color tColor, Color color, float min, float max, bool clamp) { Color glowColor = BaseUtility.ColorMult(tColor, BaseUtility.MultiLerp(glowTick / (float)glowMax, min, max, min)); if (clamp) { if (color.R > glowColor.R) { glowColor.R = color.R; } if (color.G > glowColor.G) { glowColor.G = color.G; } if (color.B > glowColor.B) { glowColor.B = color.B; } } return(glowColor); }
public static Color GetGradientColor(Color tColor1, Color tColor2, Color color, bool clamp) { Color glowColor = Color.Lerp(tColor1, tColor2, BaseUtility.MultiLerp(glowTick / (float)glowMax, 0f, 1f, 0f)); if (clamp) { if (color.R > glowColor.R) { glowColor.R = color.R; } if (color.G > glowColor.G) { glowColor.G = color.G; } if (color.B > glowColor.B) { glowColor.B = color.B; } } return(glowColor); }
/* * Returns the total itemstack sum of a specific item in the player's inventory. * * typeIsAmmo : If true, types are considered ammo types. Else, types are considered item types. */ public static int GetItemstackSum(Player player, int[] types, bool typeIsAmmo = false, bool includeAmmo = false, bool includeCoins = false) { int stackCount = 0; if (includeCoins) { for (int m = 50; m < 54; m++) { Item item = player.inventory[m]; if (item != null && (typeIsAmmo ? BaseUtility.InArray(types, item.ammo) : BaseUtility.InArray(types, item.type))) { stackCount += item.stack; } } } if (includeAmmo) { for (int m = 54; m < 58; m++) { Item item = player.inventory[m]; if (item != null && (typeIsAmmo ? BaseUtility.InArray(types, item.ammo) : BaseUtility.InArray(types, item.type))) { stackCount += item.stack; } } } for (int m = 0; m < 50; m++) { Item item = player.inventory[m]; if (item != null && (typeIsAmmo ? BaseUtility.InArray(types, item.ammo) : BaseUtility.InArray(types, item.type))) { stackCount += item.stack; } } return(stackCount); }
public static int GoreType(this Mod mod, string name, IDictionary <string, int> gores = null) { return(BaseUtility.CheckForGore(mod, name, gores)); }
public static bool Meteor(int i, int j) { if (i < 50 || i > Main.maxTilesX - 50) { return(false); } if (j < 50 || j > Main.maxTilesY - 50) { return(false); } int num = 35; Rectangle rectangle = new Rectangle((i - num) * 16, (j - num) * 16, num * 2 * 16, num * 2 * 16); for (int k = 0; k < 255; k++) { if (Main.player[k].active) { Rectangle value = new Rectangle((int)(Main.player[k].position.X + Main.player[k].width / 2 - NPC.sWidth / 2 - NPC.safeRangeX), (int)(Main.player[k].position.Y + Main.player[k].height / 2 - NPC.sHeight / 2 - NPC.safeRangeY), NPC.sWidth + NPC.safeRangeX * 2, NPC.sHeight + NPC.safeRangeY * 2); if (rectangle.Intersects(value)) { return(false); } } } for (int l = 0; l < 200; l++) { if (Main.npc[l].active) { Rectangle value2 = new Rectangle((int)Main.npc[l].position.X, (int)Main.npc[l].position.Y, Main.npc[l].width, Main.npc[l].height); if (rectangle.Intersects(value2)) { return(false); } } } for (int m = i - num; m < i + num; m++) { for (int n = j - num; n < j + num; n++) { if (Main.tile[m, n].active() && Main.tile[m, n].type == 21) { return(false); } } } num = WorldGen.genRand.Next(17, 23); for (int num2 = i - num; num2 < i + num; num2++) { for (int num3 = j - num; num3 < j + num; num3++) { if (num3 > j + Main.rand.Next(-2, 3) - 5) { float num4 = Math.Abs(i - num2); float num5 = Math.Abs(j - num3); float num6 = (float)Math.Sqrt(num4 * num4 + num5 * num5); if (num6 < num * 0.9 + Main.rand.Next(-4, 5)) { if (!Main.tileSolid[Main.tile[num2, num3].type]) { Main.tile[num2, num3].active(false); } Main.tile[num2, num3].type = (ushort)ModContent.TileType <CometOre>(); } } } } num = WorldGen.genRand.Next(8, 14); for (int num7 = i - num; num7 < i + num; num7++) { for (int num8 = j - num; num8 < j + num; num8++) { if (num8 > j + Main.rand.Next(-2, 3) - 4) { float num9 = Math.Abs(i - num7); float num10 = Math.Abs(j - num8); float num11 = (float)Math.Sqrt(num9 * num9 + num10 * num10); if (num11 < num * 0.8 + Main.rand.Next(-3, 4)) { Main.tile[num7, num8].active(false); } } } } num = WorldGen.genRand.Next(25, 35); for (int num12 = i - num; num12 < i + num; num12++) { for (int num13 = j - num; num13 < j + num; num13++) { float num14 = Math.Abs(i - num12); float num15 = Math.Abs(j - num13); float num16 = (float)Math.Sqrt(num14 * num14 + num15 * num15); if (num16 < num * 0.7) { if (Main.tile[num12, num13].type == 5 || Main.tile[num12, num13].type == 32 || Main.tile[num12, num13].type == 352) { WorldGen.KillTile(num12, num13, false, false, false); } Main.tile[num12, num13].liquid = 0; } if (Main.tile[num12, num13].type == (ushort)ModContent.TileType <CometOre>()) { if (!WorldGen.SolidTile(num12 - 1, num13) && !WorldGen.SolidTile(num12 + 1, num13) && !WorldGen.SolidTile(num12, num13 - 1) && !WorldGen.SolidTile(num12, num13 + 1)) { Main.tile[num12, num13].active(false); } else if ((Main.tile[num12, num13].halfBrick() || Main.tile[num12 - 1, num13].topSlope()) && !WorldGen.SolidTile(num12, num13 + 1)) { Main.tile[num12, num13].active(false); } } WorldGen.SquareTileFrame(num12, num13, true); WorldGen.SquareWallFrame(num12, num13, true); } } num = WorldGen.genRand.Next(23, 32); for (int num17 = i - num; num17 < i + num; num17++) { for (int num18 = j - num; num18 < j + num; num18++) { if (num18 > j + WorldGen.genRand.Next(-3, 4) - 3 && Main.tile[num17, num18].active() && Main.rand.Next(10) == 0) { float num19 = Math.Abs(i - num17); float num20 = Math.Abs(j - num18); float num21 = (float)Math.Sqrt(num19 * num19 + num20 * num20); if (num21 < num * 0.8) { if (Main.tile[num17, num18].type == 5 || Main.tile[num17, num18].type == 32 || Main.tile[num17, num18].type == 352) { WorldGen.KillTile(num17, num18, false, false, false); } Main.tile[num17, num18].type = (ushort)ModContent.TileType <CometOre>(); WorldGen.SquareTileFrame(num17, num18, true); } } } } num = WorldGen.genRand.Next(30, 38); for (int num22 = i - num; num22 < i + num; num22++) { for (int num23 = j - num; num23 < j + num; num23++) { if (num23 > j + WorldGen.genRand.Next(-2, 3) && Main.tile[num22, num23].active() && Main.rand.Next(20) == 0) { float num24 = Math.Abs(i - num22); float num25 = Math.Abs(j - num23); float num26 = (float)Math.Sqrt(num24 * num24 + num25 * num25); if (num26 < num * 0.85) { if (Main.tile[num22, num23].type == 5 || Main.tile[num22, num23].type == 32 || Main.tile[num22, num23].type == 352) { WorldGen.KillTile(num22, num23, false, false, false); } Main.tile[num22, num23].type = (ushort)ModContent.TileType <CometOre>(); WorldGen.SquareTileFrame(num22, num23, true); } } } } string cometText = "The sky has fallen somewhere in the world"; if (Main.netMode != NetmodeID.MultiplayerClient) { BaseUtility.Chat(cometText, new Color(136, 151, 255), true); } if (Main.netMode != NetmodeID.MultiplayerClient) { NetMessage.SendTileSquare(-1, i, j, 40, TileChangeType.None); } return(true); }
public static bool HasAllItems(Player player, int[] types, ref int[] indicies, int[] counts = default, bool includeAmmo = false, bool includeCoins = false) { if (types == null || types.Length == 0) { return(false); //no types to check! } if (counts == null || counts.Length == 0) { counts = BaseUtility.FillArray(new int[types.Length], 1); } int[] indexArray = new int[types.Length]; bool[] foundItem = new bool[types.Length]; if (includeCoins) { for (int m = 50; m < 54; m++) { for (int m2 = 0; m2 < types.Length; m2++) { if (foundItem[m2]) { continue; } Item item = player.inventory[m]; if (item != null && item.type == types[m2] && item.stack >= counts[m2]) { foundItem[m2] = true; indexArray[m2] = m; } } } } if (includeAmmo) { for (int m = 54; m < 58; m++) { for (int m2 = 0; m2 < types.Length; m2++) { if (foundItem[m2]) { continue; } Item item = player.inventory[m]; if (item != null && item.type == types[m2] && item.stack >= counts[m2]) { foundItem[m2] = true; indexArray[m2] = m; } } } } for (int m = 0; m < 50; m++) { for (int m2 = 0; m2 < types.Length; m2++) { if (foundItem[m2]) { continue; } Item item = player.inventory[m]; if (item != null && item.type == types[m2] && item.stack >= counts[m2]) { foundItem[m2] = true; indexArray[m2] = m; } } } foreach (bool f in foundItem) { if (!f) { return(false); } } return(true); }