I am trying to calculate the amount of links between one destination and another in my game, the first method that gets called is CalculateRoute
and it returns a list of map routes.
At this point you're probably thinking "so whats wrong with the code you've shown?".
When the link is further than 1 room away, it doesn't take into account that it needs to get the links from the first two rooms and just ignores the rest...
Better explain, it only gets the link instructions from the room it starts from inside of the method GetRoutesForRoom
and this causes a big problem for the whole mechanism.
I'm already confused by this code so I'm just asking for some help to make it count the first parts of the link inside of the GetRoutesForRoom
method.
internal class MapRoute
{
private List<int> _arrowLinks;
public MapRoute(List<int> arrowLinks)
{
_arrowLinks = arrowLinks;
}
}
Here is the CalculateRoute
method...
public Dictionary<int, MapRoute> CalculateRoute(Player player, Room startLocation, Room endLocation)
{
var possibleRoutes = new Dictionary<int, MapRoute>();
var arrowsAtStart = startLocation.GetRoomItemHandler().GetFloor.Where(
x => x.GetBaseItem().InteractionType == InteractionType.ARROW);
foreach (var arrow in arrowsAtStart)
{
if (!ItemTeleporterFinder.IsTeleLinked(arrow.Id, startLocation))
{
continue;
}
var linkedRoomId = ItemTeleporterFinder.GetTeleRoomId(arrow.Id, startLocation);
if (linkedRoomId == endLocation.RoomId)
{
possibleRoutes.Add(possibleRoutes.Count + 1, new MapRoute(new List<int> { arrow.Id }));
}
else if (PlusEnvironment.GetGame().GetRoomManager().TryGetRoom(linkedRoomId, out var secondRoom))
{
foreach (var mapRoute in GetRoutesForRoom(secondRoom, startLocation.RoomId))
{
possibleRoutes.Add(possibleRoutes.Count + 1, mapRoute);
}
}
}
return possibleRoutes;
}
For calculating rooms further down the link, I use another method...
public List<MapRoute> GetRoutesForRoom(Room room, int destination)
{
var possibleRoutes = new List<MapRoute>();
var arrowsInRoom = room.GetRoomItemHandler().GetFloor.Where(
x => x.GetBaseItem().InteractionType == InteractionType.ARROW);
foreach (var arrow in arrowsInRoom)
{
if (!ItemTeleporterFinder.IsTeleLinked(arrow.Id, room))
{
continue;
}
var linkedRoomId = ItemTeleporterFinder.GetTeleRoomId(arrow.Id, room);
if (linkedRoomId == destination)
{
possibleRoutes.Add(new MapRoute(new List<int> { arrow.Id }));
}
else if (PlusEnvironment.GetGame().GetRoomManager().TryGetRoom(linkedRoomId, out var secondRoom))
{
foreach (var mapRoute in GetRoutesForRoom(secondRoom, destination))
{
possibleRoutes.Add(mapRoute);
}
}
}
return possibleRoutes;
}