Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 69 additions & 83 deletions SEModAPIExtensions/API/ChatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -613,89 +613,75 @@ protected void Command_Delete(ChatEvent chatEvent)
//All entities
#region "All Entities"
if (paramCount > 1 && commandParts[1].ToLower().Equals("all"))
{
//All cube grids that have no beacon or only a beacon with no name
if (commandParts[2].ToLower().Equals("nobeacon"))
{
List<CubeGridEntity> entities = SectorObjectManager.Instance.GetTypedInternalData<CubeGridEntity>();
List<CubeGridEntity> entitiesToDispose = new List<CubeGridEntity>();
foreach (CubeGridEntity entity in entities)
{
while (entity.CubeBlocks.Count == 0)
{
Thread.Sleep(20);
}
List<CubeBlockEntity> blocks = entity.CubeBlocks;
if (blocks.Count > 0)
{
bool foundBeacon = false;
foreach (CubeBlockEntity cubeBlock in blocks)
{
if (cubeBlock is BeaconEntity)
{
foundBeacon = true;
break;
}
}
if (!foundBeacon)
{
entitiesToDispose.Add(entity);
}
}
}

foreach (CubeGridEntity entity in entitiesToDispose)
{
bool isLinkedShip = false;
List<CubeBlockEntity> blocks = entity.CubeBlocks;
foreach (CubeBlockEntity cubeBlock in blocks)
{
if (cubeBlock is MergeBlockEntity)
{
MergeBlockEntity block = (MergeBlockEntity)cubeBlock;
if (block.IsAttached)
{
if (!entitiesToDispose.Contains(block.AttachedCubeGrid))
{
isLinkedShip = true;
break;
}
}
}
if (cubeBlock is PistonEntity)
{
PistonEntity block = (PistonEntity)cubeBlock;
CubeBlockEntity topBlock = block.TopBlock;
if (topBlock != null)
{
if (!entitiesToDispose.Contains(topBlock.Parent))
{
isLinkedShip = true;
break;
}
}
}
if (cubeBlock is RotorEntity)
{
RotorEntity block = (RotorEntity)cubeBlock;
CubeBlockEntity topBlock = block.TopBlock;
if (topBlock != null)
{
if (!entitiesToDispose.Contains(topBlock.Parent))
{
isLinkedShip = true;
break;
}
}
}
}
if (isLinkedShip)
continue;

entity.Dispose();
}

SendPrivateChatMessage(remoteUserId, entitiesToDispose.Count.ToString() + " cube grids have been removed");
{
//All cube grids that have no beacon except for those attached to a grid with a beacon
if (commandParts[2].ToLower().Equals("nobeacon"))
{
while (SectorObjectManager.Instance.GetTypedInternalData<CubeGridEntity>().Count == 0)
{
Thread.Sleep(20);
}

List<CubeGridEntity> entities = SectorObjectManager.Instance.GetTypedInternalData<CubeGridEntity>();
List<CubeGridEntity> entitiesToDispose = SectorObjectManager.Instance.GetTypedInternalData<CubeGridEntity>();

if (entities.Count == 0)
{
ChatManager.Instance.SendPrivateChatMessage(remoteUserId, "No grids found. Try again later.");
return;
}

foreach (CubeGridEntity entity in entities)
{
while (entity.CubeBlocks.Count == 0)
{
Thread.Sleep(20);
}

List<CubeBlockEntity> blocks = entity.CubeBlocks;

//scan each grid for beacons
foreach (CubeBlockEntity cubeBlock in blocks)
{
if (cubeBlock is BeaconEntity)
{
entitiesToDispose.Remove(entity);

//if the grid has a beacon remove all grids from entitiesToDispose that are attached to it
foreach (CubeBlockEntity cubeBlock1 in blocks)
{
if (cubeBlock1 is PistonEntity)
{
PistonEntity piston = (PistonEntity)cubeBlock1;
CubeBlockEntity pistonTop = piston.TopBlock;

if (pistonTop != null)
{
entitiesToDispose.Remove(pistonTop.Parent);
}
}
else if (cubeBlock1 is RotorEntity)
{
RotorEntity rotor = (RotorEntity)cubeBlock1;
CubeBlockEntity rotorTop = rotor.TopBlock;
if (rotorTop != null)
{
entitiesToDispose.Remove(rotorTop.Parent);
}
}
}
//we dont need to scan for further beacons
break;
}
}
}

foreach (CubeGridEntity entity in entitiesToDispose)
{
entity.Dispose();
}

SendPrivateChatMessage(remoteUserId, entitiesToDispose.Count.ToString() + " cube grids have been removed.");
}
//All cube grids that have no power
else if (commandParts[2].ToLower().Equals("nopower"))
Expand Down