public static int GetXYWallPercentage(string walltype, int X, int Y, int Width, int Height) { double amountofmatchedwalls = 0; double totalwallcount = 0; byte type; if (QTools.GetWallTypeFromName(walltype, out type)) { for (int i = X; i < (X + Width); i++) { for (int j = Y; j < (Y + Height); j++) { if (Main.tile[i, j].active && Main.tile[i, j].type == type) { amountofmatchedwalls++; } totalwallcount++; } } } if (totalwallcount != 0) { return((int)((amountofmatchedwalls / totalwallcount) * 100)); } return(0); }
public static int GetRegionWallPercentage(string walltype, string regionname) { double amountofmatchedwalls = 0; double totalwallcount = 0; TShockAPI.DB.Region r; byte type; if (QTools.GetWallTypeFromName(walltype, out type)) { if ((r = TShock.Regions.ZacksGetRegionByName(regionname)) != null) { for (int i = r.Area.X; i < (r.Area.X + r.Area.Width); i++) { for (int j = r.Area.Y; j < (r.Area.Y + r.Area.Height); j++) { if (Main.tile[i, j].active && Main.tile[i, j].wall == type) { amountofmatchedwalls++; } totalwallcount++; } } } } if (totalwallcount != 0) { return((int)((amountofmatchedwalls / totalwallcount) * 100)); } return(0); }