Ejemplo n.º 1
0
        public override void Update(long gameTime, NamelessGame namelessGame)
        {
            IEntity        worldEntity   = namelessGame.TimelineEntity;
            IWorldProvider worldProvider = null;

            if (worldEntity != null)
            {
                worldProvider = worldEntity.GetComponentOfType <TimeLine>().CurrentTimelineLayer.Chunks;
                while (namelessGame.Commander.DequeueCommand(out DropItemCommand dropCommand))
                {
                    var tile = worldProvider.GetTile(dropCommand.WhereToDrop.X, dropCommand.WhereToDrop.Y);

                    foreach (var dropCommandItem in dropCommand.Items)
                    {
                        tile.AddEntity((Entity)dropCommandItem);
                        dropCommand.Holder.Items.Remove(dropCommandItem);
                        dropCommandItem.GetComponentOfType <Drawable>().Visible = true;
                        var position = dropCommandItem.GetComponentOfType <Position>();
                        position.Point = new Point(dropCommand.WhereToDrop.X, dropCommand.WhereToDrop.Y);
                    }
                }
                while (namelessGame.Commander.DequeueCommand(out PickUpItemCommand pickupCommand))
                {
                    if (pickupCommand != null)
                    {
                        foreach (var pickupCommandItem in pickupCommand.Items)
                        {
                            var tile = worldProvider.GetTile(pickupCommand.WhereToPickUp.X,
                                                             pickupCommand.WhereToPickUp.Y);
                            tile.RemoveEntity((Entity)pickupCommandItem);
                            pickupCommandItem.GetComponentOfType <Drawable>().Visible = false;
                            var ammo = pickupCommandItem.GetComponentOfType <Ammo>();
                            if (ammo != null)
                            {
                                var itemsEntities = pickupCommand.Holder.Items;
                                var itemsWithAmmo = itemsEntities.Select(x => x).Where(i => i.GetComponentOfType <Ammo>() != null);
                                var sameTypeItem  = itemsWithAmmo.FirstOrDefault(x => x.GetComponentOfType <Ammo>().Type.Name == ammo.Type.Name);
                                if (sameTypeItem != null)
                                {
                                    sameTypeItem.GetComponentOfType <Item>().Amount +=
                                        pickupCommandItem.GetComponentOfType <Item>().Amount;
                                    namelessGame.RemoveEntity(pickupCommandItem);
                                }
                                else
                                {
                                    pickupCommand.Holder.Items.Add(pickupCommandItem);
                                }
                            }
                            else
                            {
                                pickupCommand.Holder.Items.Add(pickupCommandItem);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static List <Tile> PlotLineAA(Point point0, Point point1, IWorldProvider world)
        {
            var result = new List <Tile>();
            int dx = Math.Abs(point1.X - point0.X), sx = point0.X < point1.X ? 1 : -1;
            int dy = Math.Abs(point1.Y - point0.Y), sy = point0.Y < point1.Y ? 1 : -1;
            int err = dx - dy, e2, x2; /* error value e_xy */

            int ed = (int)(dx + dy == 0 ? 1 : Math.Sqrt((float)dx * dx + (float)dy * dy));

            for (;;)
            {
                /* pixel loop */
                //setPixelAA(point0.X, point0.Y, 255 * abs(err - dx + dy) / ed);
                result.Add(world.GetTile(point0.X, point0.Y));
                e2 = err;
                x2 = point0.X;
                if (2 * e2 >= -dx)
                {
                    /* x step */
                    if (point0.X == point1.X)
                    {
                        break;
                    }
                    if (e2 + dy < ed)
                    {
                        result.Add(world.GetTile(point0.X, point0.Y + sy));
                        // setPixelAA(point0.X, point0.Y + sy, 255 * (e2 + dy) / ed);
                    }

                    err      -= dy;
                    point0.X += sx;
                }

                if (2 * e2 <= dy)
                {
                    /* y step */
                    if (point0.Y == point1.Y)
                    {
                        break;
                    }
                    if (dx - e2 < ed)
                    {
                        result.Add(world.GetTile(x2 + sx, point0.Y + sy));
                        //  setPixelAA(x2 + sx, point0.Y, 255 * (dx - e2) / ed);
                    }

                    err      += dx;
                    point0.Y += sy;
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        private void FillcharacterBuffersWithWorld(Screen screen, ConsoleCamera camera, GameSettings settings,
                                                   IWorldProvider world)
        {
            int camX = camera.getPosition().X;
            int camY = camera.getPosition().Y;

            if (angle > 360)
            {
                angle = 0;
            }

            angle += step;

            for (int x = camX; x < settings.GetWidthZoomed() + camX; x++)
            {
                for (int y = camY; y < settings.GetHeightZoomed() + camY; y++)
                {
                    Point screenPoint = camera.PointToScreen(x, y);
                    if (screen.ScreenBuffer[screenPoint.Y, screenPoint.X].isVisible)
                    {
                        Tile tileToDraw = world.GetTile(x, y);
                        GetTerrainTile(screen, TerrainLibrary.Terrains[tileToDraw.Terrain], screenPoint);
                    }
                    else
                    {
                        screen.ScreenBuffer[screenPoint.Y, screenPoint.X].Char            = ' ';
                        screen.ScreenBuffer[screenPoint.Y, screenPoint.X].BackGroundColor = new Color();
                    }
                }
            }
        }
            public bool IsBlocked(AStarNavigator.Tile coord)
            {
                counter++;
                //  return false;
                var tile = _worlldProvider.GetTile((int)coord.X, (int)coord.Y);

                if (counter >= maxSearches)
                {
                    return(true);
                }

                if (coord.X == _destination.X && coord.Y == _destination.Y)
                {
                    return(false);
                }

                if (coord.X == _start.X && coord.Y == _start.Y)
                {
                    return(false);
                }


                var isBlocked = !tile.IsPassable();

                return(isBlocked);
            }
        private void FillcharacterBufferVisibility(NamelessGame game, Screen screen, ConsoleCamera camera,
                                                   GameSettings settings, IWorldProvider world)
        {
            int         camX           = camera.getPosition().X;
            int         camY           = camera.getPosition().Y;
            Position    playerPosition = game.PlayerEntity.GetComponentOfType <Position>();
            BoundingBox b = new BoundingBox(camera.getPosition(),
                                            new Point(settings.GetWidthZoomed() + camX, settings.GetHeightZoomed() + camY));

            for (int x = 0; x < settings.GetWidthZoomed(); x++)
            {
                for (int y = 0; y < settings.GetHeightZoomed(); y++)
                {
                    screen.ScreenBuffer[x, y].isVisible = false;
                }
            }

            //return;

            if (fov == null)
            {
                {
                    fov = new PermissiveVisibility((x, y) => { return(!world.GetTile(x, y).GetBlocksVision(game)); },
                                                   (x, y) =>
                    {
                        Stopwatch s           = Stopwatch.StartNew();
                        var lambdaLocalScreen = game.CameraEntity.GetComponentOfType <Screen>();
                        s.Stop();
                        s.ToString();

                        Point screenPoint = camera.PointToScreen(x, y);
                        if (screenPoint.X >= 0 && screenPoint.X < settings.GetWidthZoomed() && screenPoint.Y >= 0 &&
                            screenPoint.Y < settings.GetHeightZoomed())
                        {
                            lambdaLocalScreen.ScreenBuffer[screenPoint.X, screenPoint.Y].isVisible = true;
                        }
                    }, (x, y) =>
                    {
                        if (Math.Abs(x) > 60 || Math.Abs(y) > 60)
                        {
                            return(10000);
                        }
                        //   return (int)((x*x) + (y*y));
                        return(Math.Abs(x) + Math.Abs(y));
                    }
                                                   );
                }
            }
            fov.Compute(playerPosition.Point, 60);
        }
Ejemplo n.º 6
0
        public static IEntity CreateDummyBuilding(int x, int y, int width ,int height, NamelessGame namelessGame)
        {

            IEntity worldEntity = namelessGame.TimelineEntity;
            IWorldProvider worldProvider = null;
            if (worldEntity != null)
            {
                worldProvider = worldEntity.GetComponentOfType<TimeLine>().CurrentTimelineLayer.Chunks;
            }

            IEntity building = new Entity();

            building.AddComponent(new Description("",""));
            building.AddComponent(new Position(x,y));

            Building buildingComponent = new Building();

            for (int i = 0;i< width; i++)
            {
                for (int j = 0;j< height; j++)
                {
                    var tile = worldProvider.GetTile(x + i, y + j);
                    tile.Terrain = TerrainTypes.Road;
                    tile.Biome = Biomes.None;
                    if (i == 0 || j == 0 || i == width - 1 || j == height - 1)
                    {
                        if (i == width / 2)
                        {
                            IEntity door = CreateDoor(x + i, y + j);
                            buildingComponent.getBuildingParts().Add(door);
                            namelessGame.AddEntity(door);
                            tile.AddEntity((Entity) door);
                        }
                        else
                        {
                            var wall = TerrainFurnitureFactory.WallEntity;
                            tile.AddEntity(wall);
                            namelessGame.AddEntity(wall);
                        }
                    }
                }



            }
            building.AddComponent(buildingComponent);
            return building;

        }
Ejemplo n.º 7
0
        public override void Update(long gameTime, NamelessGame namelessGame)
        {
            while (namelessGame.Commander.DequeueCommand(out DeathCommand command))
            {
                IEntity entityToKill = command.getToKill();
                entityToKill.AddComponent(new Dead());

                Drawable drawable = entityToKill.GetComponentOfType <Drawable>();
                if (drawable != null)
                {
                    drawable.Representation = '%';
                }

                IEntity        worldEntity   = namelessGame.TimelineEntity;
                IWorldProvider worldProvider = null;
                if (worldEntity != null)
                {
                    worldProvider = worldEntity.GetComponentOfType <TimeLine>().CurrentTimelineLayer.Chunks;
                }

                Position     position     = entityToKill.GetComponentOfType <Position>();
                OccupiesTile occupiesTile = entityToKill.GetComponentOfType <OccupiesTile>();
                if (occupiesTile != null && position != null)
                {
                    Tile tile = worldProvider.GetTile(position.Point.Y, position.Point.X);
                    tile.RemoveEntity((Entity)entityToKill);
                }

                entityToKill.RemoveComponentOfType <OccupiesTile>();

                Description d = entityToKill.GetComponentOfType <Description>();

                if (d != null)
                {
                    // namelessGame.WriteLineToConsole(d.Name + " is dead!");
                }
            }
        }
Ejemplo n.º 8
0
        private void FillcharacterBuffersWithTileObjects(Screen screen, ConsoleCamera camera, GameSettings settings,
                                                         NamelessGame game, IWorldProvider world)
        {
            int camX = camera.getPosition().X;
            int camY = camera.getPosition().Y;

            if (angle > 360)
            {
                angle = 0;
            }

            angle += step;

            for (int x = camX; x < settings.GetWidthZoomed() + camX; x++)
            {
                for (int y = camY; y < settings.GetHeightZoomed() + camY; y++)
                {
                    Point screenPoint = camera.PointToScreen(x, y);
                    if (screen.ScreenBuffer[screenPoint.Y, screenPoint.X].isVisible)
                    {
                        Tile tileToDraw = world.GetTile(x, y);

                        foreach (var entity in tileToDraw.GetEntities())
                        {
                            var furniture = entity.GetComponentOfType <Furniture>();
                            var drawable  = entity.GetComponentOfType <Drawable>();
                            if (furniture != null && drawable != null)
                            {
                                screen.ScreenBuffer[screenPoint.Y, screenPoint.X].Char      = drawable.Representation;
                                screen.ScreenBuffer[screenPoint.Y, screenPoint.X].CharColor = drawable.CharColor;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        private void FillcharacterBufferVisibility(NamelessGame game, Screen screen, ConsoleCamera camera,
                                                   GameSettings settings, IWorldProvider world)
        {
            int         camX           = camera.getPosition().X;
            int         camY           = camera.getPosition().Y;
            Position    playerPosition = game.PlayerEntity.GetComponentOfType <Position>();
            BoundingBox b = new BoundingBox(camera.getPosition(),
                                            new Point(settings.GetWidthZoomed() + camX, settings.GetHeightZoomed() + camY));

            for (int x = 0; x < settings.GetWidthZoomed(); x++)
            {
                for (int y = 0; y < settings.GetHeightZoomed(); y++)
                {
                    screen.ScreenBuffer[y, x].isVisible = true;
                }
            }

            return;

            if (fov == null)
            {
                fov = new PermissiveVisibility((x, y) => { return(!world.GetTile(x, y).GetBlocksVision(game)); },
                                               (x, y) =>
                {
                    Point screenPoint = camera.PointToScreen(x, y);
                    if (screenPoint.X >= 0 && screenPoint.X < settings.GetWidth() && screenPoint.Y >= 0 &&
                        screenPoint.Y < settings.GetHeight())
                    {
                        screen.ScreenBuffer[screenPoint.X, screenPoint.Y].isVisible = true;
                    }
                }, (x, y) => { return(Math.Abs(x) + Math.Abs(y)); }
                                               );
            }

            fov.Compute(playerPosition.Point, 60);
        }
Ejemplo n.º 10
0
        public override void Update(long gameTime, NamelessGame namelessGame)
        {
            foreach (IEntity entity in RegisteredEntities)
            {
                InputComponent inputComponent = entity.GetComponentOfType <InputComponent>();
                if (inputComponent != null)
                {
                    var playerEntity = namelessGame.PlayerEntity;
                    foreach (Intent intent in inputComponent.Intents)
                    {
                        switch (intent.Intention)
                        {
                        case IntentEnum.MoveUp:
                        case IntentEnum.MoveDown:
                        case IntentEnum.MoveLeft:
                        case IntentEnum.MoveRight:
                        case IntentEnum.MoveTopLeft:
                        case IntentEnum.MoveTopRight:
                        case IntentEnum.MoveBottomLeft:
                        case IntentEnum.MoveBottomRight:
                        {
                            Position position     = playerEntity.GetComponentOfType <Position>();
                            var      actionPoints = playerEntity.GetComponentOfType <ActionPoints>();
                            if (position != null && actionPoints.Points >= 100)
                            {
                                int newX =
                                    intent.Intention == IntentEnum.MoveLeft || intent.Intention == IntentEnum.MoveBottomLeft ||
                                    intent.Intention == IntentEnum.MoveTopLeft ? position.Point.X - 1 :
                                    intent.Intention == IntentEnum.MoveRight || intent.Intention == IntentEnum.MoveBottomRight ||
                                    intent.Intention == IntentEnum.MoveTopRight ? position.Point.X + 1 :
                                    position.Point.X;
                                int newY =
                                    intent.Intention == IntentEnum.MoveDown || intent.Intention == IntentEnum.MoveBottomLeft ||
                                    intent.Intention == IntentEnum.MoveBottomRight ? position.Point.Y - 1 :
                                    intent.Intention == IntentEnum.MoveUp || intent.Intention == IntentEnum.MoveTopLeft ||
                                    intent.Intention == IntentEnum.MoveTopRight ? position.Point.Y + 1 :
                                    position.Point.Y;

                                IEntity        worldEntity   = namelessGame.TimelineEntity;
                                IWorldProvider worldProvider = null;
                                if (worldEntity != null)
                                {
                                    worldProvider = worldEntity.GetComponentOfType <TimeLine>().CurrentTimelineLayer.Chunks;
                                }

                                Tile tileToMoveTo = worldProvider.GetTile(newX, newY);


                                IEntity entityThatOccupiedTile = null;
                                foreach (IEntity tileEntity in tileToMoveTo.GetEntities())
                                {
                                    OccupiesTile occupiesTile =
                                        tileEntity.GetComponentOfType <OccupiesTile>();
                                    if (occupiesTile != null)
                                    {
                                        entityThatOccupiedTile = tileEntity;
                                        break;
                                    }
                                }


                                if (entityThatOccupiedTile != null)
                                {
                                    Door      door = entityThatOccupiedTile.GetComponentOfType <Door>();
                                    Character characterComponent =
                                        entityThatOccupiedTile.GetComponentOfType <Character>();
                                    if (door != null)
                                    {
                                        SimpleSwitch simpleSwitch =
                                            entityThatOccupiedTile.GetComponentOfType <SimpleSwitch>();
                                        if (simpleSwitch != null == simpleSwitch.isSwitchActive())
                                        {
                                            entityThatOccupiedTile.GetComponentOfType <Drawable>()
                                            .Representation = 'o';
                                            entityThatOccupiedTile.RemoveComponentOfType <BlocksVision>();
                                            entityThatOccupiedTile.RemoveComponentOfType <OccupiesTile>();

                                            namelessGame.Commander.EnqueueCommand(
                                                new ChangeSwitchStateCommand(simpleSwitch, false));
                                            var ap = playerEntity.GetComponentOfType <ActionPoints>();
                                            ap.Points -= Constants.ActionsMovementCost;
                                            //   playerEntity.RemoveComponentOfType<HasTurn>();
                                        }
                                        else
                                        {
                                            worldProvider.MoveEntity(playerEntity,
                                                                     new Point(newX, newY));
                                            var ap = playerEntity.GetComponentOfType <ActionPoints>();
                                            ap.Points -= Constants.ActionsMovementCost;
                                        }
                                    }

                                    if (characterComponent != null)
                                    {
                                        //TODO: if hostile
                                        namelessGame.Commander.EnqueueCommand(new AttackCommand(playerEntity,
                                                                                                entityThatOccupiedTile));

                                        var ap = playerEntity.GetComponentOfType <ActionPoints>();
                                        ap.Points -= Constants.ActionsAttackCost;
                                        // playerEntity.RemoveComponentOfType<HasTurn>();

                                        //TODO: do something else if friendly: chat, trade, etc
                                    }
                                }
                                else
                                {
                                    worldProvider.MoveEntity(playerEntity,
                                                             new Point(newX, newY));
                                    var ap = playerEntity.GetComponentOfType <ActionPoints>();
                                    ap.Points -= Constants.ActionsMovementCost;
                                }
                            }
                        }

                        break;

                        case IntentEnum.LookAtMode:
                            //InputReceiver receiver = new InputReceiver();
                            //Player player = entity.GetComponentOfType<Player>();
                            //cursor = entity.GetComponentOfType<Cursor>();
                            //entity.RemoveComponentOfType<InputReceiver>();
                            //if (player != null)
                            //{
                            //    IEntity cursorEntity = namelessGame.CursorEntity;
                            //    cursorEntity.AddComponent(receiver);
                            //    Drawable cursorDrawable = cursorEntity.GetComponentOfType<Drawable>();
                            //    cursorDrawable.setVisible(true);
                            //    Position cursorPosition = cursorEntity.GetComponentOfType<Position>();
                            //    Position playerPosition = entity.GetComponentOfType<Position>();
                            //    cursorPosition.p.X = (playerPosition.p.X);
                            //    cursorPosition.p.Y = (playerPosition.p.Y);

                            //}
                            //else if (cursor != null)
                            //{
                            //    IEntity playerEntity = namelessGame.PlayerEntity;
                            //    playerEntity.AddComponent(receiver);
                            //    Drawable cursorDrawable = entity.GetComponentOfType<Drawable>();
                            //    cursorDrawable.setVisible(false);

                            //}

                            break;

                        case IntentEnum.PickUpItem:
                        {
                            var actionPoints = playerEntity.GetComponentOfType <ActionPoints>();

                            if (actionPoints.Points >= 100)
                            {
                                IEntity        worldEntity   = namelessGame.TimelineEntity;
                                IWorldProvider worldProvider = null;
                                if (worldEntity != null)
                                {
                                    worldProvider = worldEntity.GetComponentOfType <TimeLine>().CurrentTimelineLayer
                                                    .Chunks;
                                }


                                var position   = playerEntity.GetComponentOfType <Position>();
                                var itemHolder = playerEntity.GetComponentOfType <ItemsHolder>();
                                var tile       = worldProvider.GetTile(position.Point.X, position.Point.Y);

                                List <IEntity> itemsToPickUp = new List <IEntity>();
                                foreach (var entityOnTIle in tile.GetEntities())
                                {
                                    var itemComponent = entityOnTIle.GetComponentOfType <Item>();
                                    if (itemComponent != null)
                                    {
                                        itemsToPickUp.Add(entityOnTIle);
                                    }
                                }

                                if (itemsToPickUp.Any())
                                {
                                    if (itemsToPickUp.Count > 1)
                                    {
                                        namelessGame.ContextToSwitch =
                                            ContextFactory.GetPickUpItemContext(namelessGame);
                                        UiFactory.PickUpItemsScreen.FillItems(namelessGame);
                                        if (UiFactory.PickUpItemsScreen.ItemsTable.Items.Any())
                                        {
                                            UiFactory.PickUpItemsScreen.ItemsTable.SelectedIndex = 0;
                                        }
                                    }
                                    else
                                    {
                                        StringBuilder builder      = new StringBuilder();
                                        var           itemsCommand = new PickUpItemCommand(itemsToPickUp, itemHolder,
                                                                                           position.Point);
                                        namelessGame.Commander.EnqueueCommand(itemsCommand);

                                        foreach (var entity1 in itemsToPickUp)
                                        {
                                            var desc = entity1.GetComponentOfType <Description>();
                                            if (desc != null)
                                            {
                                                builder.Append($"Picked up: {desc.Name} \n");
                                            }
                                        }

                                        var logCommand = new HudLogMessageCommand();
                                        logCommand.LogMessage += builder.ToString();
                                        namelessGame.Commander.EnqueueCommand(logCommand);
                                    }

                                    var ap = playerEntity.GetComponentOfType <ActionPoints>();
                                    ap.Points -= Constants.ActionsPickUpCost;
                                    //playerEntity.RemoveComponentOfType<HasTurn>();
                                }
                            }

                            break;
                        }

                        case IntentEnum.SkipTurn:
                        {
                            var actionPoints = playerEntity.GetComponentOfType <ActionPoints>();

                            if (actionPoints.Points >= 100)
                            {
                                var ap = entity.GetComponentOfType <ActionPoints>();
                                ap.Points -= Constants.ActionsMovementCost;
                                var logCommand = new HudLogMessageCommand();
                                logCommand.LogMessage += "Waiting";
                                namelessGame.Commander.EnqueueCommand(logCommand);

                                //   playerEntity.RemoveComponentOfType<HasTurn>();
                            }
                        }
                        break;

                        case IntentEnum.Quicksave:
                            namelessGame.ScheduleSave();
                            break;

                        case IntentEnum.Quickload:
                            namelessGame.ScheduleLoad();
                            break;

                        case IntentEnum.ZoomIn:
                            var zoomCommand = new ZoomCommand(false);
                            namelessGame.Commander.EnqueueCommand(zoomCommand);
                            break;

                        case IntentEnum.ZoomOut:
                            var zoomOutCommand = new ZoomCommand();
                            namelessGame.Commander.EnqueueCommand(zoomOutCommand);
                            break;

                        default:
                            break;
                        }
                    }

                    inputComponent.Intents.Clear();
                }
            }
        }
Ejemplo n.º 11
0
        public static IEntity CreateBuilding(int x, int y, BuildingBlueprint blueprint, NamelessGame namelessGame, IWorldProvider worldProvider, InternalRandom random)
        {
            IEntity building = new Entity();

            building.AddComponent(new Description("", ""));
            building.AddComponent(new Position(x, y));

            Building buildingComponent = new Building();

            

            for (int i = 0; i < blueprint.Matrix.Length; i++)
            {
                for (int j = 0; j < blueprint.Matrix[i].Length; j++)
                {
                    var tile = worldProvider.GetTile(x + j, y + i);
                    tile.Terrain = TerrainTypes.Road;
                    tile.Biome = Biomes.None;

                    var bluepringCell = blueprint.Matrix[i][j];
                    switch (bluepringCell)
                    {
                        case BlueprintCell.Wall:
                        {
                            AddToTileAndGame(tile, TerrainFurnitureFactory.WallEntity, namelessGame);
                                break;
                        }
                        case BlueprintCell.Door:
                        {
                            IEntity door = CreateDoor(x + j, y + i);
                            buildingComponent.getBuildingParts().Add(door);
                            AddToTileAndGame(tile, door, namelessGame);
                            break;

                        }
                        case BlueprintCell.Window:
                        {
                            AddToTileAndGame(tile, TerrainFurnitureFactory.WindowEntity, namelessGame);
                            break;
                        }
                        case BlueprintCell.Bed:
                        {
                            AddToTileAndGame(tile, TerrainFurnitureFactory.BedEntity, namelessGame);
                            break;
                        }
                        case BlueprintCell.IndoorsFurniture:
                        {
                            AddToTileAndGame(tile, TerrainFurnitureFactory.BedEntity, namelessGame);
                            break;
                        }

                    }


                }
            }


            {
                //BSPTree tree = new BSPTree(new Rectangle(x,y,width,height));

                //tree.Split(random,3);

                //{
                //    BSPTree child = tree.ChildA;
                //    for (int i = 0; i < child.Bounds.Width; i++)
                //    {
                //        for (int j = 0; j < child.Bounds.Height; j++)
                //        {
                //            var tile = worldProvider.GetTile(child.Bounds.X + i, child.Bounds.Y + j);
                //            tile.Terrain = TerrainLibrary.Terrains[TerrainTypes.Road];
                //            tile.Biome = BiomesLibrary.Biomes[Biomes.None];

                //            if (i == 0 || j == 0 || i == child.Bounds.Width - 1 || j == child.Bounds.Height - 1)
                //            {
                //                if (i == child.Bounds.Width / 2)
                //                {
                //                    IEntity door = CreateDoor(child.Bounds.X + i, child.Bounds.Y + j);
                //                    buildingComponent.getBuildingParts().Add(door);
                //                    namelessGame.GetEntities().Add(door);
                //                    tile.getEntitiesOnTile().Add((Entity)door);
                //                }
                //                else
                //                {
                //                    tile.getEntitiesOnTile().Add(TerrainFurnitureFactory.WallEntity);
                //                }
                //            }

                //        }
                //    }
                //}

                //{
                //    BSPTree child = tree.ChildB;
                //    for (int i = 0; i < child.Bounds.Width; i++)
                //    {
                //        for (int j = 0; j < child.Bounds.Height; j++)
                //        {
                //            var tile = worldProvider.GetTile(child.Bounds.X + i, child.Bounds.Y + j);
                //            tile.Terrain = TerrainLibrary.Terrains[TerrainTypes.Road];
                //            tile.Biome = BiomesLibrary.Biomes[Biomes.None];

                //            if (i == 0 || j == 0 || i == child.Bounds.Width - 1 || j == child.Bounds.Height - 1)
                //            {
                //                if (i == child.Bounds.Width / 2)
                //                {
                //                    IEntity door = CreateDoor(child.Bounds.X + i, child.Bounds.Y + j);
                //                    buildingComponent.getBuildingParts().Add(door);
                //                    namelessGame.GetEntities().Add(door);
                //                    tile.getEntitiesOnTile().Add((Entity)door);
                //                }
                //                else
                //                {
                //                    tile.getEntitiesOnTile().Add(TerrainFurnitureFactory.WallEntity);
                //                }
                //            }

                //        }
                //    }
                //}
            }

            building.AddComponent(buildingComponent);
            return building;

        }
Ejemplo n.º 12
0
        public void FillItems(NamelessGame namelessGame)
        {
            var selectedIndex = SelectedTable?.Items.IndexOf(SelectedItem);

            ItemsTable.Items.Clear();

            var playerEntity = game.PlayerEntity;

            var itemsHolder = playerEntity.GetComponentOfType <ItemsHolder>();
            var equipment   = playerEntity.GetComponentOfType <EquipmentSlots>();

            char hotkey = Char.MinValue;

            var headerItem = new TableItem(4);

            headerItem.Cells[0].Widgets.Add(new Label()
            {
                Text = "Hotkey", HorizontalAlignment = HorizontalAlignment.Center
            });
            headerItem.Cells[1].Widgets.Add(new Label()
            {
                Text = "Name",
            });
            headerItem.Cells[2].Widgets.Add(new Label()
            {
                Text = "Weight",
            });
            headerItem.Cells[3].Widgets.Add(new Label()
            {
                Text = "Type",
            });
            ItemsTable.Items.Add(headerItem);


            IEntity        worldEntity   = namelessGame.TimelineEntity;
            IWorldProvider worldProvider = null;

            if (worldEntity != null)
            {
                worldProvider = worldEntity.GetComponentOfType <TimeLine>().CurrentTimelineLayer
                                .Chunks;
            }


            var position   = playerEntity.GetComponentOfType <Position>();
            var itemHolder = playerEntity.GetComponentOfType <ItemsHolder>();
            var tile       = worldProvider.GetTile(position.Point.X, position.Point.Y);

            List <IEntity> itemsToPickUp = new List <IEntity>();

            foreach (var entityOnTIle in tile.GetEntities())
            {
                var itemComponent = entityOnTIle.GetComponentOfType <Item>();
                if (itemComponent != null)
                {
                    itemsToPickUp.Add(entityOnTIle);
                }
            }



            List <IEntity> list = itemsToPickUp;

            for (int i = 0; i < list.Count; i++)
            {
                IEntity entity = list[i];

                if (i == 0)
                {
                    hotkey = HotkeyHelper.alphabet.First();
                }
                else
                {
                    hotkey = HotkeyHelper.GetNextKey(hotkey);
                }

                Description desc = entity.GetComponentOfType <Description>();
                Item        item = entity.GetComponentOfType <Item>();

                var tableItem = new TableItem(4);
                tableItem.Tag    = entity;
                tableItem.Hotkey = hotkey;
                tableItem.Cells[0].Widgets.Add(new Label()
                {
                    Text = hotkey.ToString(), HorizontalAlignment = HorizontalAlignment.Center
                });
                tableItem.Cells[1].Widgets.Add(new Label()
                {
                    Text = desc.Name,
                });
                tableItem.Cells[2].Widgets.Add(new Label()
                {
                    Text = item.Weight.ToString(),
                });
                tableItem.Cells[3].Widgets.Add(new Label()
                {
                    Text = item.Type.ToString(),
                });
                ItemsTable.Items.Add(tableItem);
            }


            if (selectedIndex > SelectedTable?.Items.Count)
            {
                if (SelectedTable != null)
                {
                    SelectedTable.SelectedIndex = 0;
                    SelectedItem = SelectedTable.SelectedItem;
                }
            }
            else
            {
                if (SelectedTable != null)
                {
                    SelectedTable.SelectedIndex = selectedIndex;
                    SelectedItem = SelectedTable.SelectedItem;
                }
            }
        }
Ejemplo n.º 13
0
        public void MoveTo(IEntity movableEntity, NamelessGame namelessGame, Point destination, bool moveBesides)
        {
            IEntity        worldEntity   = namelessGame.TimelineEntity;
            IWorldProvider worldProvider = null;

            if (worldEntity != null)
            {
                worldProvider = worldEntity.GetComponentOfType <TimeLine>().CurrentTimelineLayer.Chunks;
            }

            Position position = movableEntity.GetComponentOfType <Position>();
            BasicAi  basicAi  = movableEntity.GetComponentOfType <BasicAi>();
            var      route    = basicAi.Route;

            if (!route.Any())
            {
                AStarPathfinderSimple pathfinder = new AStarPathfinderSimple();
                List <Point>          path       = pathfinder.FindPath(position.Point,
                                                                       new Point(destination.X, destination.Y), worldProvider,
                                                                       namelessGame);
                if (moveBesides)
                {
                    basicAi.Route = new Queue <Point>(path.Take(path.Count - 1));
                }
                else
                {
                    basicAi.Route = new Queue <Point>(path);
                }

                basicAi.DestinationPoint = destination;
            }

            route = basicAi.Route;
            if (route.Any())
            {
                Point nextPosition = route.Dequeue();
                Tile  tileToMoveTo = worldProvider.GetTile(nextPosition.X, nextPosition.Y);
                if (!tileToMoveTo.IsPassable() || destination != basicAi.DestinationPoint)
                {
                    AStarPathfinderSimple pathfinder = new AStarPathfinderSimple();
                    List <Point>          path       = pathfinder.FindPath(position.Point,
                                                                           destination, worldProvider, namelessGame);
                    path = path.Skip(1)
                           .ToList(); // we dont need the first point in the path because its the point we are standing on currently
                    if (path.Any())
                    {
                        basicAi.Route = new Queue <Point>(path);

                        if (moveBesides)
                        {
                            basicAi.Route = new Queue <Point>(path.Take(path.Count - 1));
                        }
                        else
                        {
                            basicAi.Route = new Queue <Point>(path);
                        }
                    }
                    else
                    {
                        basicAi.Route = new Queue <Point>();
                        nextPosition  = position.Point;
                    }

                    basicAi.DestinationPoint = destination;
                }

                worldProvider.MoveEntity(movableEntity,
                                         new Point(nextPosition.X, nextPosition.Y));

                var ap = movableEntity.GetComponentOfType <ActionPoints>();
                ap.Points -= Constants.ActionsMovementCost;
            }

            if (route.Count == 0)
            {
                var ap = movableEntity.GetComponentOfType <ActionPoints>();
                ap.Points = 0;
            }
        }