Skip to content

Commit

Permalink
Made the logic cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
kamronbatman committed Jan 27, 2025
1 parent c31871f commit a6ad4ec
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 45 deletions.
70 changes: 34 additions & 36 deletions Projects/Server/Maps/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,6 @@ public bool LineOfSight(Point3D origin, Point3D destination)
(origin, destination) = (destination, origin);
}

int height;
Point3D p;
var path = new Point3DList();
TileFlag flags;
Expand Down Expand Up @@ -1087,15 +1086,15 @@ public bool LineOfSight(Point3D origin, Point3D destination)
var id = TileData.ItemTable[t.ID & TileData.MaxItemValue];

flags = id.Flags;
height = id.CalcHeight;

if (t.Z <= pointTop && t.Z + height >= point.Z && (flags & (TileFlag.Window | TileFlag.NoShoot)) != 0)
if (
t.Z <= pointTop && t.Z + id.CalcHeight >= point.Z &&
(flags & (TileFlag.Window | TileFlag.NoShoot)) != 0 &&
(point.X != destination.X ||
point.Y != destination.Y ||
t.Z > endTop || t.Z + id.CalcHeight < destination.Z)
)
{
if (point.X == destination.X && point.Y == destination.Y && t.Z <= endTop && t.Z + height >= destination.Z)
{
continue;
}

return false;
}
}
Expand Down Expand Up @@ -1140,41 +1139,40 @@ public bool LineOfSight(Point3D origin, Point3D destination)
continue;
}

height = id.CalcHeight;

var losBlocked = false;

var count = path.Count;

for (var j = 0; j < count; ++j)
for (var i = 0; i < path.Count; ++i)
{
var pathPoint = path[j];
var pathPoint = path[i];
var pointTop = pathPoint.Z + 1;
var itemLocation = item.Location;

if (itemLocation.X == pathPoint.X && itemLocation.Y == pathPoint.Y //item is on same tile as this point along the LOSpath
&& itemLocation.Z <= pointTop && itemLocation.Z + height >= pathPoint.Z //item rests on the same level as the path
//Fix door bugging monsters- if door is at the START or END of the LOS path, then allow LOS
&& !(flags.HasFlag(TileFlag.Door)
&& (itemLocation.X == origin.X && itemLocation.Y == origin.Y)
|| (itemLocation.X == destination.X && itemLocation.Y == destination.Y)))
if (
// Item is on same tile as this point along the LOS path
itemLocation.X == pathPoint.X &&
itemLocation.Y == pathPoint.Y &&
itemLocation.Z <= pointTop &&

// Item rests on the same level as the path
itemLocation.Z + id.CalcHeight >= pathPoint.Z &&

// Fix door bugging monsters when door is at the START or END of the LOS path by allowing LOS
!(flags.HasFlag(TileFlag.Door) &&
itemLocation.X == origin.X && itemLocation.Y == origin.Y ||
itemLocation.X == destination.X && itemLocation.Y == destination.Y) &&

// Item is at some point along the path BEFORE the target
(itemLocation.X != destination.X ||
itemLocation.Y != destination.Y ||

// Item is diagonally looking DOWN at the target
itemLocation.Z > endTop ||

// Item is diagonally looking UP at the target
itemLocation.Z + id.CalcHeight < destination.Z)
)
{
if (itemLocation.X != destination.X || itemLocation.Y != destination.Y //at some point along the path BEFORE the target
|| itemLocation.Z > endTop //item is diagonally looking DOWN at the target
|| itemLocation.Z + height < destination.Z) //item is diagonally looking UP at the target
{
losBlocked = true;
break;
}
return false;
}
}

if (!losBlocked)
{
continue;
}

return false;
}

return true;
Expand Down
15 changes: 6 additions & 9 deletions Projects/UOContent/Gumps/Houses/HouseGumpAOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,15 @@ public HouseGumpAOS(HouseGumpPageAOS page, Mobile from, BaseHouse house) : base(

AddImage(10, 10, 100);

if (m_House.Sign != null)
{
var lines = m_House.Sign.GetName().Wrap(10, 6);
var lines = m_House.Sign?.GetName().Wrap(10, 6);

if (lines != null)
if (lines != null)
{
for (int i = 0, y = (114 - lines.Count * 14) / 2; i < lines.Count; ++i, y += 14)
{
for (int i = 0, y = (114 - lines.Count * 14) / 2; i < lines.Count; ++i, y += 14)
{
var s = lines[i];
var s = lines[i];

AddLabel(10 + (160 - s.Length * 8) / 2, y, 0, s);
}
AddLabel(10 + (160 - s.Length * 8) / 2, y, 0, s);
}
}

Expand Down

0 comments on commit a6ad4ec

Please sign in to comment.