Exemplo n.º 1
0
        public GameCell BuildPrefabCell(char terrain, Pos2D point, PrefabData sourcePrefab)
        {
            var mapping = sourcePrefab.Mapping?.FirstOrDefault(m => m.Char == terrain);

            if (mapping == null)
            {
                return(BuildCell(terrain, point));
            }

            var cell = new GameCell
            {
                FloorType = FloorType.Normal,
                Pos       = point
            };

            // This makes debugging a bit easier
            if (terrain == '<' || terrain == '>')
            {
                cell.FloorType = FloorType.DecorativeTile;
            }

            var obj = GameObjectFactory.CreateObject(mapping.ObjId, mapping.ObjType, point);

            cell.AddObject(obj);

            return(cell);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Builds out a <see cref="GameCell" /> for the given parameters and returns that object.
        /// </summary>
        /// <param name="terrain">The type of terrain at that cell.</param>
        /// <param name="point">The absolute location of the cell within the level.</param>
        /// <returns>The constructed <see cref="GameCell" /> instance.</returns>
        public GameCell BuildCell(char terrain, Pos2D point)
        {
            var cell = new GameCell
            {
                FloorType = GetFloorTypeFromTerrain(terrain),
                Pos       = point
            };

            var obj = GetGameObjectFromCellTerrain(terrain, point);

            if (obj != null)
            {
                cell.AddObject(obj);
            }

            return(cell);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generates an encounter from the given encounter elements and adds game objects to vacant cells as needed.
        /// </summary>
        /// <param name="encounterElements">The encounter elements.</param>
        /// <param name="cells">The cells. These can be vacant or unvacant.</param>
        /// <returns>A collection of generated elements</returns>
        public static IEnumerable <GameObjectBase> AddEncounterElementsToCells(IEnumerable <EncounterElement> encounterElements, IEnumerable <GameCell> cells, IRandomization randomization)
        {
            IList <GameCell> remainingCells = cells.Where(c => !c.HasObstacle).ToList();

            var entities = new List <GameObjectBase>();

            foreach (EncounterElement element in encounterElements)
            {
                GameCell matchedCell = remainingCells.GetRandomElement(randomization);
                if (matchedCell == null)
                {
                    break;
                }

                remainingCells.Remove(matchedCell);

                var gameObject = GameObjectFactory.CreateObject(element.ObjectId, element.ObjectType, matchedCell.Pos);
                matchedCell.AddObject(gameObject);

                entities.Add(gameObject);
            }

            return(entities);
        }