Adds style cop (#109)

This commit is contained in:
Kamron Batman 2020-04-26 00:16:02 -07:00 committed by GitHub
parent 3e715bcb60
commit 556a17aba8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1725 changed files with 33831 additions and 38046 deletions

View file

@ -23,7 +23,7 @@ namespace Server.Multis
private const int YardSize = 5;
// Any land tile which matches one of these ID numbers is considered a road and cannot be placed over.
private static int[] m_RoadIDs =
private static readonly int[] m_RoadIDs =
{
0x0071, 0x0078,
0x00E8, 0x00EB,
@ -84,190 +84,190 @@ namespace Server.Multis
*/
for (int x = 0; x < mcl.Width; ++x)
for (int y = 0; y < mcl.Height; ++y)
{
int tileX = start.X + x;
int tileY = start.Y + y;
StaticTile[] addTiles = mcl.Tiles[x][y];
if (addTiles.Length == 0)
continue; // There are no tiles here, continue checking somewhere else
Point3D testPoint = new Point3D(tileX, tileY, center.Z);
Region reg = Region.Find(testPoint, map);
if (!reg.AllowHousing(from, testPoint)) // Cannot place houses in dungeons, towns, treasure map areas etc
for (int y = 0; y < mcl.Height; ++y)
{
if (reg.IsPartOf<TempNoHousingRegion>())
return HousePlacementResult.BadRegionTemp;
int tileX = start.X + x;
int tileY = start.Y + y;
if (reg.IsPartOf<TreasureRegion>() || reg.IsPartOf<HouseRegion>())
return HousePlacementResult.BadRegionHidden;
StaticTile[] addTiles = mcl.Tiles[x][y];
if (reg.IsPartOf<HouseRaffleRegion>())
return HousePlacementResult.BadRegionRaffle;
if (addTiles.Length == 0)
continue; // There are no tiles here, continue checking somewhere else
return HousePlacementResult.BadRegion;
}
Point3D testPoint = new Point3D(tileX, tileY, center.Z);
LandTile landTile = map.Tiles.GetLandTile(tileX, tileY);
int landID = landTile.ID & TileData.MaxLandValue;
Region reg = Region.Find(testPoint, map);
StaticTile[] oldTiles = map.Tiles.GetStaticTiles(tileX, tileY, true);
Sector sector = map.GetSector(tileX, tileY);
items.Clear();
for (int i = 0; i < sector.Items.Count; ++i)
{
Item item = sector.Items[i];
if (item.Visible && item.X == tileX && item.Y == tileY)
items.Add(item);
}
mobiles.Clear();
for (int i = 0; i < sector.Mobiles.Count; ++i)
{
Mobile m = sector.Mobiles[i];
if (m.X == tileX && m.Y == tileY)
mobiles.Add(m);
}
int landStartZ = 0, landAvgZ = 0, landTopZ = 0;
map.GetAverageZ(tileX, tileY, ref landStartZ, ref landAvgZ, ref landTopZ);
bool hasFoundation = false;
for (int i = 0; i < addTiles.Length; ++i)
{
StaticTile addTile = addTiles[i];
if (addTile.ID == 0x1) // Nodraw
continue;
TileFlag addTileFlags = TileData.ItemTable[addTile.ID & TileData.MaxItemValue].Flags;
bool isFoundation = addTile.Z == 0 && (addTileFlags & TileFlag.Wall) != 0;
bool hasSurface = false;
if (isFoundation)
hasFoundation = true;
int addTileZ = center.Z + addTile.Z;
int addTileTop = addTileZ + addTile.Height;
if ((addTileFlags & TileFlag.Surface) != 0)
addTileTop += 16;
if (addTileTop > landStartZ && landAvgZ > addTileZ)
return HousePlacementResult.BadLand; // Broke rule #2
if (isFoundation &&
(TileData.LandTable[landTile.ID & TileData.MaxLandValue].Flags & TileFlag.Impassable) == 0 &&
landAvgZ == center.Z)
hasSurface = true;
for (int j = 0; j < oldTiles.Length; ++j)
if (!reg.AllowHousing(from, testPoint)) // Cannot place houses in dungeons, towns, treasure map areas etc
{
StaticTile oldTile = oldTiles[j];
ItemData id = TileData.ItemTable[oldTile.ID & TileData.MaxItemValue];
if (reg.IsPartOf<TempNoHousingRegion>())
return HousePlacementResult.BadRegionTemp;
if ((id.Impassable || id.Surface && (id.Flags & TileFlag.Background) == 0) &&
addTileTop > oldTile.Z && oldTile.Z + id.CalcHeight > addTileZ)
return HousePlacementResult.BadStatic; // Broke rule #2
/*else if ( isFoundation && !hasSurface && (id.Flags & TileFlag.Surface) != 0 && (oldTile.Z + id.CalcHeight) == center.Z )
hasSurface = true;*/
if (reg.IsPartOf<TreasureRegion>() || reg.IsPartOf<HouseRegion>())
return HousePlacementResult.BadRegionHidden;
if (reg.IsPartOf<HouseRaffleRegion>())
return HousePlacementResult.BadRegionRaffle;
return HousePlacementResult.BadRegion;
}
for (int j = 0; j < items.Count; ++j)
LandTile landTile = map.Tiles.GetLandTile(tileX, tileY);
int landID = landTile.ID & TileData.MaxLandValue;
StaticTile[] oldTiles = map.Tiles.GetStaticTiles(tileX, tileY, true);
Sector sector = map.GetSector(tileX, tileY);
items.Clear();
for (int i = 0; i < sector.Items.Count; ++i)
{
Item item = items[j];
ItemData id = item.ItemData;
Item item = sector.Items[i];
if (addTileTop > item.Z && item.Z + id.CalcHeight > addTileZ)
{
if (item.Movable)
toMove.Add(item);
else if (id.Impassable || id.Surface && (id.Flags & TileFlag.Background) == 0)
return HousePlacementResult.BadItem; // Broke rule #2
}
/*else if ( isFoundation && !hasSurface && (id.Flags & TileFlag.Surface) != 0 && (item.Z + id.CalcHeight) == center.Z )
{
hasSurface = true;
}*/
if (item.Visible && item.X == tileX && item.Y == tileY)
items.Add(item);
}
if (isFoundation && !hasSurface)
return HousePlacementResult.NoSurface; // Broke rule #4
mobiles.Clear();
for (int j = 0; j < mobiles.Count; ++j)
for (int i = 0; i < sector.Mobiles.Count; ++i)
{
Mobile m = mobiles[j];
Mobile m = sector.Mobiles[i];
if (addTileTop > m.Z && m.Z + 16 > addTileZ)
toMove.Add(m);
}
}
for (int i = 0; i < m_RoadIDs.Length; i += 2)
if (landID >= m_RoadIDs[i] && landID <= m_RoadIDs[i + 1])
return HousePlacementResult.BadLand; // Broke rule #5
if (hasFoundation)
{
for (int xOffset = -1; xOffset <= 1; ++xOffset)
for (int yOffset = -YardSize; yOffset <= YardSize; ++yOffset)
{
Point2D yardPoint = new Point2D(tileX + xOffset, tileY + yOffset);
if (!yard.Contains(yardPoint))
yard.Add(yardPoint);
if (m.X == tileX && m.Y == tileY)
mobiles.Add(m);
}
for (int xOffset = -1; xOffset <= 1; ++xOffset)
for (int yOffset = -1; yOffset <= 1; ++yOffset)
int landStartZ = 0, landAvgZ = 0, landTopZ = 0;
map.GetAverageZ(tileX, tileY, ref landStartZ, ref landAvgZ, ref landTopZ);
bool hasFoundation = false;
for (int i = 0; i < addTiles.Length; ++i)
{
if (xOffset == 0 && yOffset == 0)
StaticTile addTile = addTiles[i];
if (addTile.ID == 0x1) // Nodraw
continue;
// To ease this rule, we will not add to the border list if the tile here is under a base floor (z<=8)
TileFlag addTileFlags = TileData.ItemTable[addTile.ID & TileData.MaxItemValue].Flags;
int vx = x + xOffset;
int vy = y + yOffset;
bool isFoundation = addTile.Z == 0 && (addTileFlags & TileFlag.Wall) != 0;
bool hasSurface = false;
if (vx >= 0 && vx < mcl.Width && vy >= 0 && vy < mcl.Height)
if (isFoundation)
hasFoundation = true;
int addTileZ = center.Z + addTile.Z;
int addTileTop = addTileZ + addTile.Height;
if ((addTileFlags & TileFlag.Surface) != 0)
addTileTop += 16;
if (addTileTop > landStartZ && landAvgZ > addTileZ)
return HousePlacementResult.BadLand; // Broke rule #2
if (isFoundation &&
(TileData.LandTable[landTile.ID & TileData.MaxLandValue].Flags & TileFlag.Impassable) == 0 &&
landAvgZ == center.Z)
hasSurface = true;
for (int j = 0; j < oldTiles.Length; ++j)
{
StaticTile[] breakTiles = mcl.Tiles[vx][vy];
bool shouldBreak = false;
StaticTile oldTile = oldTiles[j];
ItemData id = TileData.ItemTable[oldTile.ID & TileData.MaxItemValue];
for (int i = 0; !shouldBreak && i < breakTiles.Length; ++i)
{
StaticTile breakTile = breakTiles[i];
if (breakTile.Height == 0 && breakTile.Z <= 8 &&
TileData.ItemTable[breakTile.ID & TileData.MaxItemValue].Surface)
shouldBreak = true;
}
if (shouldBreak)
continue;
if ((id.Impassable || (id.Surface && (id.Flags & TileFlag.Background) == 0)) &&
addTileTop > oldTile.Z && oldTile.Z + id.CalcHeight > addTileZ)
return HousePlacementResult.BadStatic; // Broke rule #2
/*else if (isFoundation && !hasSurface && (id.Flags & TileFlag.Surface) != 0 && (oldTile.Z + id.CalcHeight) == center.Z)
hasSurface = true;*/
}
Point2D borderPoint = new Point2D(tileX + xOffset, tileY + yOffset);
for (int j = 0; j < items.Count; ++j)
{
Item item = items[j];
ItemData id = item.ItemData;
if (!borders.Contains(borderPoint))
borders.Add(borderPoint);
if (addTileTop > item.Z && item.Z + id.CalcHeight > addTileZ)
{
if (item.Movable)
toMove.Add(item);
else if (id.Impassable || (id.Surface && (id.Flags & TileFlag.Background) == 0))
return HousePlacementResult.BadItem; // Broke rule #2
}
/*else if (isFoundation && !hasSurface && (id.Flags & TileFlag.Surface) != 0 && (item.Z + id.CalcHeight) == center.Z)
{
hasSurface = true;
}*/
}
if (isFoundation && !hasSurface)
return HousePlacementResult.NoSurface; // Broke rule #4
for (int j = 0; j < mobiles.Count; ++j)
{
Mobile m = mobiles[j];
if (addTileTop > m.Z && m.Z + 16 > addTileZ)
toMove.Add(m);
}
}
for (int i = 0; i < m_RoadIDs.Length; i += 2)
if (landID >= m_RoadIDs[i] && landID <= m_RoadIDs[i + 1])
return HousePlacementResult.BadLand; // Broke rule #5
if (hasFoundation)
{
for (int xOffset = -1; xOffset <= 1; ++xOffset)
for (int yOffset = -YardSize; yOffset <= YardSize; ++yOffset)
{
Point2D yardPoint = new Point2D(tileX + xOffset, tileY + yOffset);
if (!yard.Contains(yardPoint))
yard.Add(yardPoint);
}
for (int xOffset = -1; xOffset <= 1; ++xOffset)
for (int yOffset = -1; yOffset <= 1; ++yOffset)
{
if (xOffset == 0 && yOffset == 0)
continue;
// To ease this rule, we will not add to the border list if the tile here is under a base floor (z<=8)
int vx = x + xOffset;
int vy = y + yOffset;
if (vx >= 0 && vx < mcl.Width && vy >= 0 && vy < mcl.Height)
{
StaticTile[] breakTiles = mcl.Tiles[vx][vy];
bool shouldBreak = false;
for (int i = 0; !shouldBreak && i < breakTiles.Length; ++i)
{
StaticTile breakTile = breakTiles[i];
if (breakTile.Height == 0 && breakTile.Z <= 8 &&
TileData.ItemTable[breakTile.ID & TileData.MaxItemValue].Surface)
shouldBreak = true;
}
if (shouldBreak)
continue;
}
Point2D borderPoint = new Point2D(tileX + xOffset, tileY + yOffset);
if (!borders.Contains(borderPoint))
borders.Add(borderPoint);
}
}
}
}
for (int i = 0; i < borders.Count; ++i)
{
@ -290,8 +290,8 @@ namespace Server.Multis
StaticTile tile = tiles[j];
ItemData id = TileData.ItemTable[tile.ID & TileData.MaxItemValue];
if (id.Impassable || id.Surface && (id.Flags & TileFlag.Background) == 0 &&
tile.Z + id.CalcHeight > center.Z + 2)
if (id.Impassable || (id.Surface && (id.Flags & TileFlag.Background) == 0 &&
tile.Z + id.CalcHeight > center.Z + 2))
return HousePlacementResult.BadStatic; // Broke rule #1
}
@ -307,8 +307,8 @@ namespace Server.Multis
ItemData id = item.ItemData;
if (id.Impassable || id.Surface && (id.Flags & TileFlag.Background) == 0 &&
item.Z + id.CalcHeight > center.Z + 2)
if (id.Impassable || (id.Surface && (id.Flags & TileFlag.Background) == 0 &&
item.Z + id.CalcHeight > center.Z + 2))
return HousePlacementResult.BadItem; // Broke rule #1
}
}
@ -345,7 +345,7 @@ namespace Server.Multis
{
for ( int j = 0; j < tile.Length; ++j )
{
if ( (TileData.ItemTable[tile[j].ID & TileData.MaxItemValue].Flags & (TileFlag.Impassable | TileFlag.Surface)) != 0 )
if ((TileData.ItemTable[tile[j].ID & TileData.MaxItemValue].Flags & (TileFlag.Impassable | TileFlag.Surface)) != 0)
{
eable.Free();
return HousePlacementResult.BadStatic; // Broke rule #3