fix: Cleans up movement code (#787)

* Removes FastMovementImpl since it isn't used and I am not convinced it is better.
* Moves some of the new movement logic from FastMovementImpl to MovementImpl
* Makes MovementImpl more readable
This commit is contained in:
Kamron Batman 2021-09-16 23:23:22 -07:00 • committed by GitHub
parent 7785f7e06c
commit 73c65a43ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 312 additions and 989 deletions

View file

@ -1471,7 +1471,7 @@ namespace Server.Multis
var data = TileData.ItemTable[id];
// Slanted roofs do not count; they overhang blocking south and east sides of the multi
if ((data.Flags & TileFlag.Roof) != 0)
if (data.Roof)
{
continue;
}

View file

@ -185,13 +185,13 @@ namespace Server.Multis
var data = TileData.ItemTable[entry.ItemId & TileData.MaxItemValue];
// door
if ((data.Flags & TileFlag.Door) != 0)
if (data.Door)
{
AddDoor(entry.ItemId, entry.OffsetX, entry.OffsetY, entry.OffsetZ);
}
else
{
Item st = new Static((int)entry.ItemId);
Item st = new Static(entry.ItemId);
st.MoveToWorld(new Point3D(X + entry.OffsetX, Y + entry.OffsetY, entry.OffsetZ), Map);
AddFixture(st);

View file

@ -1305,7 +1305,7 @@ namespace Server.Multis
public static bool ValidPiece(int itemID, bool roof = false)
{
itemID &= TileData.MaxItemValue;
return roof != ((TileData.ItemTable[itemID].Flags & TileFlag.Roof) == 0) && Verification.IsItemValid(itemID);
return roof == TileData.ItemTable[itemID].Roof && Verification.IsItemValid(itemID);
}
public static bool IsStairBlock(int id)
@ -1479,12 +1479,12 @@ namespace Server.Multis
}
/* Client chose to delete a component
* - Read data detailing which component to delete
* - Verify component is deletable
* - Remove the component
* - If needed, replace removed component with a dirt tile
* - Update revision
*/
* - Read data detailing which component to delete
* - Verify component is deletable
* - Remove the component
* - If needed, replace removed component with a dirt tile
* - Update revision
*/
// Read data detailing which component to delete
var itemID = reader.ReadInt32();
@ -1502,9 +1502,9 @@ namespace Server.Multis
if (z == 0 && ax >= 0 && ax < mcl.Width && ay >= 0 && ay < mcl.Height - 1)
{
/* Component is not deletable
* - Resend design state
* - Return without further processing
*/
* - Resend design state
* - Return without further processing
*/
design.SendDetailedInfoTo(state);
return;
@ -1644,10 +1644,10 @@ namespace Server.Multis
}
/* Client chose to add a component
* - Read data detailing component graphic and location
* - Add component
* - Update revision
*/
* - Read data detailing component graphic and location
* - Add component
* - Update revision
*/
// Read data detailing component graphic and location
var itemID = reader.ReadInt32();
@ -1690,13 +1690,13 @@ namespace Server.Multis
}
/* Client closed his house design window
* - Remove design context
* - Notify the client that customization has ended
* - Refresh client with current visible design state
* - If a signpost is needed, add it
* - Eject all from house
* - Restore relocated entities
*/
* - Remove design context
* - Notify the client that customization has ended
* - Refresh client with current visible design state
* - If a signpost is needed, add it
* - Eject all from house
* - Restore relocated entities
*/
// Remove design context
DesignContext.Remove(from);
@ -1739,13 +1739,13 @@ namespace Server.Multis
}
/* Client is moving to a new floor level
* - Read data detailing the target level
* - Validate target level
* - Update design context with new level
* - Teleport mobile to new level
* - Update client
*
*/
* - Read data detailing the target level
* - Validate target level
* - Update design context with new level
* - Teleport mobile to new level
* - Update client
*
*/
// Read data detailing the target level
var newLevel = reader.ReadInt32();
@ -1823,7 +1823,7 @@ namespace Server.Multis
if (mte.OffsetX == x && mte.OffsetY == y &&
GetZLevel(mte.OffsetZ, context.Foundation) == context.Level &&
(TileData.ItemTable[mte.ItemId & TileData.MaxItemValue].Flags & TileFlag.Roof) != 0)
TileData.ItemTable[mte.ItemId & TileData.MaxItemValue].Roof)
{
mcl.Remove(mte.ItemId, x, y, mte.OffsetZ);
}
@ -1856,7 +1856,7 @@ namespace Server.Multis
var design = context.Foundation.DesignState;
var mcl = design.Components;
if ((TileData.ItemTable[itemID & TileData.MaxItemValue].Flags & TileFlag.Roof) == 0)
if (!TileData.ItemTable[itemID & TileData.MaxItemValue].Roof)
{
design.SendDetailedInfoTo(state);
return;

View file

@ -177,9 +177,9 @@ namespace Server.Multis
continue;
}
var addTileFlags = TileData.ItemTable[addTile.ID & TileData.MaxItemValue].Flags;
var addTileData = TileData.ItemTable[addTile.ID & TileData.MaxItemValue];
var isFoundation = addTile.Z == 0 && (addTileFlags & TileFlag.Wall) != 0;
var isFoundation = addTile.Z == 0 && addTileData.Wall;
var hasSurface = false;
if (isFoundation)
@ -190,7 +190,7 @@ namespace Server.Multis
var addTileZ = center.Z + addTile.Z;
var addTileTop = addTileZ + addTile.Height;
if ((addTileFlags & TileFlag.Surface) != 0)
if (addTileData.Surface)
{
addTileTop += 16;
}
@ -212,7 +212,7 @@ namespace Server.Multis
var oldTile = oldTiles[j];
var id = TileData.ItemTable[oldTile.ID & TileData.MaxItemValue];
if ((id.Impassable || id.Surface && (id.Flags & TileFlag.Background) == 0) &&
if ((id.Impassable || id.Surface && !id.Background) &&
addTileTop > oldTile.Z && oldTile.Z + id.CalcHeight > addTileZ)
{
return HousePlacementResult.BadStatic; // Broke rule #2
@ -233,7 +233,7 @@ namespace Server.Multis
{
toMove.Add(item);
}
else if (id.Impassable || id.Surface && (id.Flags & TileFlag.Background) == 0)
else if (id.Impassable || id.Surface && !id.Background)
{
return HousePlacementResult.BadItem; // Broke rule #2
}
@ -359,8 +359,7 @@ namespace Server.Multis
var tile = tiles[j];
var 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.Background && tile.Z + id.CalcHeight > center.Z + 2)
{
return HousePlacementResult.BadStatic; // Broke rule #1
}
@ -380,8 +379,7 @@ namespace Server.Multis
var 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.Background && item.Z + id.CalcHeight > center.Z + 2)
{
return HousePlacementResult.BadItem; // Broke rule #1
}