public MapNeighbour ChangeMap(MapNeighbour neighbour = MapNeighbour.Any) { m_nextMap = null; PathFinder pathFinder = new PathFinder(Map, false); // Select a random cell in the set of all reachable cells that allow map change in the right direction. Cell destCell = pathFinder.FindConnectedCells(Cell, false, true, cell => (cell.Cell.MapChangeData & Map.MapChangeDatas[neighbour]) != 0).GetRandom(); if (destCell == null) return MapNeighbour.None; neighbour = Map.GetDirectionOfTransitionCell(destCell); if (neighbour == MapNeighbour.None) { SendMessage(String.Format("Can't find any linked map from {0}", this), Color.Red); return MapNeighbour.None; } if (destCell.Id != Cell.Id) { if (Move(destCell, pathFinder, 0, true)) { m_nextMap = GetNeighbourId(neighbour); SendMessage(String.Format("Moving at the {2} of map {0} to map {1}", this, m_nextMap, neighbour), Color.Pink); return neighbour; } else return MapNeighbour.None; } else { Bot.AddMessage(() => Bot.SendToServer(new ChangeMapMessage(GetNeighbourId(neighbour)))); m_previousMap = Map.Id; SendMessage(String.Format("Moving at the {2} of map {0} to map {1} (direct)", this, m_nextMap, neighbour), Color.Pink); } return neighbour; }
public bool ChangeMap(MapNeighbour neighbour, Predicate<CellInfo> cellSelector) { try { m_nextMap = null; PathFinder pathFinder = new PathFinder(Map, false); // Select a random cell in the set of all reachable cells that allow map change in the right direction. Cell destCell = pathFinder.FindConnectedCells(Cell, false, true, cell => (cell.Cell.MapChangeData & Map.MapChangeDatas[neighbour]) != 0 && cellSelector(cell)).GetRandom(); if (destCell == null) return false; neighbour = Map.GetDirectionOfTransitionCell(destCell); if (neighbour == MapNeighbour.None) return false; if (Move(destCell, pathFinder, 0, true)) { m_nextMap = GetNeighbourId(neighbour); m_previousMap = Map.Id; return true; } return false; } finally { if (m_nextMap == null) SendMessage(String.Format("Can't find any linked map from {0}", this), Color.Red); else SendMessage(String.Format("Moving at the {2} of map {0} to map {1}", this, m_nextMap, neighbour), Color.Pink); } }
private void InternalChangeMap() { _changingMap = true; if (IsFighting()) { SendWarning("InternalChangeMap : I'm fighting => stop it !"); _changingMap = false; return; } if (_srcLeaderMap != Map.Id) { SendWarning("I'm not on the proper map to follow leader on the next map"); _changingMap = false; return; } if (_pivotLeaderCell != Cell.Id) { PathFinder pathFinder = new PathFinder(Map, false); if (!Move(_pivotLeaderCell, pathFinder, 0, true)) { if (_nbTryLeft > 0) { SendWarning("InternalChangeMap : Can't join the leader yet, try later"); _nbTryLeft--; Bot.CallDelayed(6000, InternalChangeMap); } else if (_nbTryLeft > -6) { MapNeighbour neighbour = Map.GetDirectionOfTransitionCell(Map.Cells[_pivotLeaderCell]); Cell destCell = pathFinder.FindConnectedCells(Cell, false, true, cell => (cell.Cell.MapChangeData & Map.MapChangeDatas[neighbour]) != 0).GetRandom(); if (destCell == null) SendWarning("InternalChangeMap : Can't join the leader, no try left. Can't even find any alternate path to go {0}", neighbour); else { SendWarning("InternalChangeMap : Can't join the leader, no try left. Trying alternative path to go {0} : cell {1}", neighbour, destCell); _pivotLeaderCell = destCell.Id; } _nbTryLeft--; Bot.CallDelayed(2000, InternalChangeMap); } else { SendError("InternalChangeMap : Can't find any path to join the leader. Trying again later. "); _changingMap = false; } return; } SendWarning("InternalChangeMap : Move from {0} to {1} succeeded. When move is complete, should go from map {2} to map {3}. ", Cell, Map.Cells[_pivotLeaderCell], Map.ToString(), new Map(_dstLeaderMap)); _changingMap = false; m_nextMap = _dstLeaderMap; return; } SendError("I'm already on the good Cell, just try to jump to the other map."); Bot.CallDelayed(400, () => Bot.AddMessage(() => Bot.SendToServer(new ChangeMapMessage(_dstLeaderMap)))); m_previousMap = Map.Id; _changingMap = false; return; }