예제 #1
0
        public bool CanChangeMap(short cellId, MapChangeDirections direction)
        {
            switch (direction)
            {
            case MapChangeDirections.LEFT:
                return((_account.Game.Map.Data.Cells[cellId].c & (int)direction) > 0 && cellId % 14 == 0);

            case MapChangeDirections.RIGHT:
                return((_account.Game.Map.Data.Cells[cellId].c & (int)direction) > 0 && cellId % 14 == 13);

            case MapChangeDirections.TOP:
                return((_account.Game.Map.Data.Cells[cellId].c & (int)direction) > 0 && cellId < 28);

            default:     // BOTTOM
                return((_account.Game.Map.Data.Cells[cellId].c & (int)direction) > 0 && cellId > 531);
            }
        }
예제 #2
0
        public bool ChangeMap(MapChangeDirections direction)
        {
            if (_account.IsBusy || _neighbourMapId != 0)
            {
                _account.Logger.LogWarning("MovementsManager", $"Is busy ({_account.State}) or is already changing the map.");
                return(false);
            }

            // TODO: Maybe make this not sot random (pick the closest cell to change map)
            var changeMapCells = GetChangeMapCells(direction);

            while (changeMapCells.Count > 0)
            {
                short cellId = changeMapCells[Randomize.GetRandomInt(0, changeMapCells.Count)];

                // Ignore this cell if a group of monsters is on it
                if (_account.Game.Map.MonstersGroups.FirstOrDefault(mg => mg.CellId == cellId) != null)
                {
                    continue;
                }

                long neighbourMapId = GetNeighbourMapId(direction);

                if (neighbourMapId <= 0)
                {
                    _account.Logger.LogWarning("MovementsManager", "Invalid Neighbour MapId.");
                    return(false);
                }

                _neighbourMapId = (int)neighbourMapId;

                // Only return true so that if one cell fails, we try the others
                if (MoveToChangeMap(cellId))
                {
                    return(true);
                }

                changeMapCells.Remove(cellId);
            }

            _account.Logger.LogWarning("MovementsManager", "No change map cells found.");
            return(false);
        }
예제 #3
0
        private long GetNeighbourMapId(MapChangeDirections direction)
        {
            switch (direction)
            {
            case MapChangeDirections.BOTTOM:
                return(_account.Game.Map.Data.BottomNeighbourId);

            case MapChangeDirections.LEFT:
                return(_account.Game.Map.Data.LeftNeighbourId);

            case MapChangeDirections.RIGHT:
                return(_account.Game.Map.Data.RightNeighbourId);

            case MapChangeDirections.TOP:
                return(_account.Game.Map.Data.TopNeighbourId);

            default:
                return(0);
            }
        }
예제 #4
0
        public bool ChangeMap(MapChangeDirections direction, short cellId)
        {
            if (_account.IsBusy || _neighbourMapId != 0)
            {
                return(false);
            }

            if (!CanChangeMap(cellId, direction))
            {
                return(false);
            }

            long neighbourMapId = GetNeighbourMapId(direction);

            if (neighbourMapId <= 0)
            {
                _account.Logger.LogWarning("MovementsManager", "Invalid Neighbour MapId.");
                return(false);
            }

            _neighbourMapId = (int)neighbourMapId;

            return(MoveToChangeMap(cellId));
        }
예제 #5
0
 private List <short> GetChangeMapCells(MapChangeDirections direction)
 => Enumerable.Range(0, 560).Select(c => (short)c).Where(c => CanChangeMap(c, direction)).ToList();
예제 #6
0
 // Constructor
 internal ChangeMapAction(MapChangeDirections direction, short cellId)
 {
     Direction = direction;
     CellId    = cellId;
 }