Ejemplo n.º 1
0
 public static void ShouldPlayerMapRecalc(StateSpaceComponents spaceComponents, DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions, ref DijkstraMapTile[,] playerMap)
 {
     if(spaceComponents.PlayerComponent.PlayerTookTurn || spaceComponents.PlayerComponent.PlayerJustLoaded)
     {
         CreateDijkstraMapToPlayers(dungeonGrid, dungeonDimensions, spaceComponents, ref playerMap);
     }
 }
Ejemplo n.º 2
0
 public static void AIMovement(StateSpaceComponents spaceComponents, DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions, DijkstraMapTile[,] mapToPlayer)
 {
     if (spaceComponents.PlayerComponent.PlayerTookTurn)
     {
         // Handle Combat ready AI entities
         foreach (Guid id in spaceComponents.Entities.Where(c => ((c.ComponentFlags & ComponentMasks.CombatReadyAI) == ComponentMasks.CombatReadyAI)).Select(c => c.Id))
         {
             AIAlignment alignment = spaceComponents.AIAlignmentComponents[id];
             AIState state = spaceComponents.AIStateComponents[id];
             PositionComponent position = spaceComponents.PositionComponents[id];
             switch(state.State)
             {
                 case AIStates.STATE_ROAMING:
                     position = AISystem.AIRoam(id, position, dungeonGrid, dungeonDimensions, spaceComponents.random);
                     break;
                 case AIStates.STATE_ATTACKING:
                     position = AISystem.AIAttack(id, position, dungeonDimensions, mapToPlayer, spaceComponents.random);
                     break;
                 case AIStates.STATE_FLEEING:
                     position = AISystem.AIFlee(id, position, dungeonDimensions, mapToPlayer, spaceComponents.random);
                     break;
             }
             CollisionSystem.TryToMove(spaceComponents, dungeonGrid, position, id);
         }
     }
 }
Ejemplo n.º 3
0
        public static void CreateDungeonMonsters(StateSpaceComponents spaceComponents, DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions, int cellsize, List<Vector2> freeTiles)
        {
            int numberOfSpawns = 15; //Should be a formula based on depth level once a formula has been decided
            List<MonsterInfo> monsterPossibilities = new List<MonsterInfo>();
            //populate the monster possibility array based on how many slots a monster gets
            foreach (MonsterInfo monster in Monsters.MonsterCatalog.Where(x => x.SpawnDepthsAndChances.ContainsKey(spaceComponents.GameplayInfoComponent.FloorsReached)))
            {
                for (int i = 0; i < monster.SpawnDepthsAndChances[spaceComponents.GameplayInfoComponent.FloorsReached]; i++)
                {
                    monsterPossibilities.Add(monster);
                }
            }
            //Roll randomly in the index and add whatever monster it lands on
            if(monsterPossibilities.Count > 0)
            {
                for (int i = 0; i < numberOfSpawns; i++)
                {
                    monsterPossibilities[spaceComponents.random.Next(0, monsterPossibilities.Count)].SpawnFunction(spaceComponents, dungeonGrid, dungeonDimensions, cellsize, freeTiles);
                }
            }

            foreach (MonsterInfo monster in Monsters.MonsterCatalog.Where(x => x.IsRequiredSpawn))
            {
                monster.SpawnFunction(spaceComponents, dungeonGrid, dungeonDimensions, cellsize, freeTiles);
            }
        }
Ejemplo n.º 4
0
        private static void DrawEntities(List<Guid> drawableEntities, StateSpaceComponents spaceComponents, DungeonTile[,] dungeonGrid, Matrix cameraMatrix, bool inWater, bool inFire, SpriteBatch spriteBatch, Texture2D spriteSheet, SpriteFont font, Camera camera, DungeonColorInfo colorInfo)
        {
            foreach (Guid id in drawableEntities)
            {
                DisplayComponent display = spaceComponents.DisplayComponents[id];
                Vector2 gridPos = spaceComponents.PositionComponents[id].Position;
                Vector2 position = new Vector2(spaceComponents.PositionComponents[id].Position.X * DevConstants.Grid.CellSize, spaceComponents.PositionComponents[id].Position.Y * DevConstants.Grid.CellSize);
                if (dungeonGrid[(int)spaceComponents.PositionComponents[id].Position.X, (int)spaceComponents.PositionComponents[id].Position.Y].InRange || display.AlwaysDraw)
                {
                    Vector2 bottomRight = Vector2.Transform(new Vector2((position.X) + DevConstants.Grid.CellSize, (position.Y) + DevConstants.Grid.CellSize), cameraMatrix);
                    Vector2 topLeft = Vector2.Transform(new Vector2(position.X, position.Y), cameraMatrix);
                    Rectangle cameraBounds = new Rectangle((int)topLeft.X, (int)topLeft.Y, (int)bottomRight.X - (int)topLeft.X, (int)bottomRight.Y - (int)topLeft.Y);

                    if (camera.IsInView(cameraMatrix, cameraBounds))
                    {
                        //If the item is in water, you need to tint it, and if the player is in water and the object isn't (or vice versa) it must be hidden unless it's the observer.
                        display = dungeonGrid[(int)gridPos.X, (int)gridPos.Y].Type == TileType.TILE_WATER == inWater || (spaceComponents.Entities.Where(x => (x.Id == id)).First().ComponentFlags & ComponentMasks.Observer) == ComponentMasks.Observer ? display : DevConstants.ConstantComponents.UnknownDisplay;
                        Color displayColor = dungeonGrid[(int)gridPos.X, (int)gridPos.Y].Type == TileType.TILE_WATER || inWater ? Color.Lerp(display.Color, colorInfo.WaterInRange, .5f) : display.Color;
                        if(!inWater && dungeonGrid[(int)gridPos.X, (int)gridPos.Y].Type != TileType.TILE_WATER)
                        {
                            displayColor = dungeonGrid[(int)gridPos.X, (int)gridPos.Y].FireIllumination || inFire ? Color.Lerp(display.Color, colorInfo.FireInRange, .5f) : display.Color;
                        }

                        spriteBatch.Draw(spriteSheet, position, display.SpriteSource, displayColor * display.Opacity, display.Rotation, display.Origin, display.Scale, display.SpriteEffect, 0f);
                        if (!string.IsNullOrEmpty(display.Symbol))
                        {
                            Vector2 size = font.MeasureString(display.Symbol);
                            spriteBatch.DrawString(font, display.Symbol, new Vector2(((int)position.X + (int)display.SpriteSource.Center.X), ((int)position.Y + (int)display.SpriteSource.Center.Y)),
                                display.SymbolColor, 0f, new Vector2((int)(size.X / 2), (int)(size.Y / 2) - 3), 1f, SpriteEffects.None, 0f);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static void CreateDungeonDrops(StateSpaceComponents spaceComponents, DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions, List<Vector2> freeTiles)
        {
            //These should be a formula based on level once a formula has been decided.
            int numberOfArtifacts = 5;
            int numberOfConsumablesAndGold = 25;
            List<ItemInfo> artifactPossibilities = new List<ItemInfo>();
            List<ItemInfo> consumableAndGoldPossibilities = new List<ItemInfo>();

            foreach (ItemInfo item in Items.ItemCatalog.Where(x => x.SpawnDepthsAndChances.ContainsKey(spaceComponents.GameplayInfoComponent.FloorsReached)))
            {
                for (int i = 0; i < item.SpawnDepthsAndChances[spaceComponents.GameplayInfoComponent.FloorsReached]; i++)
                {
                    switch(item.DropType)
                    {
                        case ItemType.ARTIFACT:
                            artifactPossibilities.Add(item);
                            break;
                        case ItemType.CONSUMABLE:
                        case ItemType.GOLD:
                            consumableAndGoldPossibilities.Add(item);
                            break;
                    }
                }
            }

            //Spawn Artifacts
            if(artifactPossibilities.Count > 0)
            {
                for(int i = 0; i <= numberOfArtifacts; i++)
                {
                    artifactPossibilities[spaceComponents.random.Next(0, artifactPossibilities.Count)].SpawnFunction(spaceComponents, dungeonGrid, dungeonDimensions, freeTiles);
                }
            }

            //Spawn gold and consumables
            if(consumableAndGoldPossibilities.Count > 0)
            {
                for(int i = 0; i <= numberOfConsumablesAndGold; i++)
                {
                    consumableAndGoldPossibilities[spaceComponents.random.Next(0, consumableAndGoldPossibilities.Count)].SpawnFunction(spaceComponents, dungeonGrid, dungeonDimensions, freeTiles);
                }
            }

            foreach (ItemInfo item in Items.ItemCatalog.Where(x => x.IsRequiredSpawn))
            {
                item.SpawnFunction(spaceComponents, dungeonGrid, dungeonDimensions, freeTiles);
            }

        }
Ejemplo n.º 6
0
        public static bool TryToMove(StateSpaceComponents spaceComponents, DungeonTile[,] dungeonGrid, PositionComponent newPosition, Guid attemptingEntity)
        {
            bool canMove = true;
            foreach (Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Collidable) == ComponentMasks.Collidable).Select(x => x.Id))
            {
                if((int)spaceComponents.PositionComponents[id].Position.X == (int)newPosition.Position.X &&
                    (int)spaceComponents.PositionComponents[id].Position.Y == (int)newPosition.Position.Y &&
                    id != attemptingEntity)
                {
                    spaceComponents.CollisionComponents[attemptingEntity].CollidedObjects.Add(id);
                    spaceComponents.GlobalCollisionComponent.EntitiesThatCollided.Add(attemptingEntity);
                    if(spaceComponents.CollisionComponents[id].Solid && spaceComponents.CollisionComponents[attemptingEntity].Solid)
                    {
                        canMove = false;
                    }
                }
            }

            if(canMove)
            {
                spaceComponents.PositionComponents[attemptingEntity] = newPosition;
                if(dungeonGrid[(int)newPosition.Position.X, (int)newPosition.Position.Y].Type == TileType.TILE_TALLGRASS && 
                    (spaceComponents.Entities.Where(x => (x.Id == attemptingEntity)).First().ComponentFlags & ComponentMasks.Observer) != ComponentMasks.Observer)
                {
                    dungeonGrid[(int)newPosition.Position.X, (int)newPosition.Position.Y].Type = TileType.TILE_FLATTENEDGRASS;
                    dungeonGrid[(int)newPosition.Position.X, (int)newPosition.Position.Y].Symbol = Tiles.FlatGrassSymbol;
                    dungeonGrid[(int)newPosition.Position.X, (int)newPosition.Position.Y].SymbolColor = Tiles.FlatGrassSymbolColor;
                    dungeonGrid[(int)newPosition.Position.X, (int)newPosition.Position.Y].ChanceToIgnite = Tiles.FlatGrassIgniteChance;
                }
                if (dungeonGrid[(int)newPosition.Position.X, (int)newPosition.Position.Y].Type == TileType.TILE_FIRE &&
                    (spaceComponents.Entities.Where(x => (x.Id == attemptingEntity)).First().ComponentFlags & ComponentMasks.Observer) != ComponentMasks.Observer)
                {
                    spaceComponents.DelayedActions.Add(new Action(() =>
                    {
                        //Burn effect damage is hardcoded for now
                        StatusSystem.ApplyBurnEffect(spaceComponents, attemptingEntity, StatusEffects.Burning.Turns, StatusEffects.Burning.MinDamage, StatusEffects.Burning.MaxDamage);
                    }));
                }
            }

            return canMove;
        }
Ejemplo n.º 7
0
 public static void UseItem(StateSpaceComponents spaceComponents, DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions, Guid item, Guid user)
 {
     ItemFunctionsComponent itemInfo = spaceComponents.ItemFunctionsComponents[item];
     Vector2 target = spaceComponents.PositionComponents[user].Position;
     bool cancelledCast = false;
     if(itemInfo.Ranged)
     {
         //Call a function to get the target position.  If they cancel during this part, set cancelledCast to true.
     }
     //If the item use is successful, remove the item from inventory and delete the item
     Func<StateSpaceComponents, DungeonTile[,], Vector2, Guid, Guid, Vector2, bool> useFunction = ItemUseFunctionLookup.GetUseFunction(itemInfo.UseFunctionValue);
     if (!cancelledCast && useFunction!= null && useFunction(spaceComponents, dungeonGrid, dungeonDimensions, item, user, target))
     {
         NameComponent itemName = spaceComponents.NameComponents[item];
         itemInfo.Uses -= 1;
         //If the items' out of uses, remove it
         if(itemInfo.Uses <= 0)
         {
             InventoryComponent inventory = spaceComponents.InventoryComponents[user];
             inventory.Consumables.Remove(item);
             spaceComponents.InventoryComponents[user] = inventory;
             spaceComponents.EntitiesToDelete.Add(item);
             spaceComponents.GameMessageComponent.GameMessages.Add(new Tuple<Color, string>(Colors.Messages.Bad, string.Format("[TURN " + spaceComponents.GameplayInfoComponent.StepsTaken + "] " + "{0} has used the last of the {1}", spaceComponents.NameComponents[user].Name, spaceComponents.NameComponents[item].Name)));
         }
         //otherwise, just report how many uses it has left.
         else
         {
             ValueComponent itemValue = spaceComponents.ValueComponents[item];
             itemValue.Gold = (itemValue.Gold - itemInfo.CostToUse < 0) ? 0 : itemValue.Gold - itemInfo.CostToUse;
             spaceComponents.ValueComponents[item] = itemValue;
             spaceComponents.GameMessageComponent.GameMessages.Add(new Tuple<Color, string>(Colors.Messages.Bad, string.Format("[TURN " + spaceComponents.GameplayInfoComponent.StepsTaken + "] " + "{0} has {1} charge(s) left.", spaceComponents.NameComponents[item].Name, itemInfo.Uses)));
         }
         PlayerComponent player = spaceComponents.PlayerComponent;
         player.PlayerTookTurn = true;
         spaceComponents.PlayerComponent = player;
         spaceComponents.ItemFunctionsComponents[item] = itemInfo;
     }
 }
Ejemplo n.º 8
0
        public static void DrawDungeonEntities(StateSpaceComponents spaceComponents, Camera camera, SpriteBatch spriteBatch, Texture2D spriteSheet, int cellSize, DungeonTile[,] dungeonGrid, SpriteFont font, DungeonColorInfo colorInfo)
        {
            Matrix cameraMatrix = camera.GetMatrix();
            List<Entity> drawableEntities = spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Drawable) == ComponentMasks.Drawable).ToList();

            Entity player = spaceComponents.Entities.Where(c => (c.ComponentFlags & ComponentMasks.Player) == ComponentMasks.Player).FirstOrDefault();
            bool inWater = false;
            bool inFire = false;
            if (player != null)
            {
                Vector2 playerPos = spaceComponents.PositionComponents[spaceComponents.Entities.Where(c => (c.ComponentFlags & ComponentMasks.Player) == ComponentMasks.Player).First().Id].Position;
                inWater = dungeonGrid[(int)playerPos.X, (int)playerPos.Y].Type == TileType.TILE_WATER;
                inFire = dungeonGrid[(int)playerPos.X, (int)playerPos.Y].Type == TileType.TILE_FIRE;
            }
            //Draw items
            List<Guid> items = drawableEntities.Where(x => (x.ComponentFlags & ComponentMasks.PickupItem) == ComponentMasks.PickupItem).Select(x => x.Id).ToList();
            DisplaySystem.DrawEntities(items, spaceComponents, dungeonGrid, cameraMatrix, inWater, inFire, spriteBatch, spriteSheet, font, camera, colorInfo);

            //Draw everything else
            List<Guid> nonItems = drawableEntities.Where(x => (x.ComponentFlags & ComponentMasks.PickupItem) != ComponentMasks.PickupItem).Select(x => x.Id).ToList();
            DisplaySystem.DrawEntities(nonItems, spaceComponents, dungeonGrid, cameraMatrix, inWater, inFire, spriteBatch, spriteSheet, font, camera, colorInfo);

        }
Ejemplo n.º 9
0
        public static void RevealTiles(ref DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions, StateSpaceComponents spaceComponents)
        {
            bool inWater = false;
            Entity player = spaceComponents.Entities.Where(z => (z.ComponentFlags & Component.COMPONENT_PLAYER) == Component.COMPONENT_PLAYER).FirstOrDefault();
            if (player != null && (spaceComponents.PlayerComponent.PlayerTookTurn || spaceComponents.PlayerComponent.PlayerJustLoaded || spaceComponents.PlayerComponent.SightRadiusDeleted)) 
            {
                PlayerComponent events = spaceComponents.PlayerComponent;
                events.SightRadiusDeleted = false;
                spaceComponents.PlayerComponent = events;
                //Reset Range
                for (int i = 0; i < dungeonDimensions.X; i++)
                {
                    for (int j = 0; j < dungeonDimensions.Y; j++)
                    {
                        dungeonGrid[i, j].InRange = false;
                        dungeonGrid[i, j].FireIllumination = false;
                    }
                }
                //See if the player is in water
                inWater = dungeonGrid[(int)spaceComponents.PositionComponents[player.Id].Position.X, (int)spaceComponents.PositionComponents[player.Id].Position.Y].Type == TileType.TILE_WATER;

                foreach (Guid entity in spaceComponents.Entities.Where(c => (c.ComponentFlags & Component.COMPONENT_SIGHTRADIUS) == Component.COMPONENT_SIGHTRADIUS).Select(c => c.Id))
                {
                    bool isPlayer = player.Id == entity;
                    if(!spaceComponents.SightRadiusComponents[entity].DrawRadius || spaceComponents.SightRadiusComponents[entity].CurrentRadius == 0)
                    {
                        continue;
                    }
                    //Guid entity = player.Id;
                    Vector2 position = spaceComponents.PositionComponents[entity].Position;
                    int radius =  inWater && isPlayer ? spaceComponents.SightRadiusComponents[entity].CurrentRadius / 2 : spaceComponents.SightRadiusComponents[entity].CurrentRadius;
                    int initialX, x0, initialY, y0;
                    initialX = x0 = (int)position.X;
                    initialY = y0 = (int)position.Y;

                    List<Vector2> visionRange = new List<Vector2>();
                    /*
                                 Shared
                                 edge by
                      Shared     1 & 2      Shared
                      edge by\      |      /edge by
                      1 & 8   \     |     / 2 & 3
                               \1111|2222/
                               8\111|222/3
                               88\11|22/33
                               888\1|2/333
                      Shared   8888\|/3333  Shared
                      edge by-------@-------edge by
                      7 & 8    7777/|\4444  3 & 4
                               777/6|5\444
                               77/66|55\44
                               7/666|555\4
                               /6666|5555\
                      Shared  /     |     \ Shared
                      edge by/      |      \edge by
                      6 & 7      Shared     4 & 5
                                 edge by 
                                 5 & 6
                     */
                    int x = radius;
                    int y = 0;
                    int decisionOver2 = 1 - x;   // Decision criterion divided by 2 evaluated at x=r, y=0

                    while (y <= x)
                    {
                        if (-x + x0 >= 0 && -y + y0 >= 0)
                        {
                            // Octant 5
                            visionRange.Add(new Vector2(-x + x0, -y + y0));
                        }
                        else
                        {
                            int newX = -x + x0 >= 0 ? -x + x0 : 0;
                            int newY = -y + y0 >= 0 ? -y + y0 : 0;
                            visionRange.Add(new Vector2(newX, newY));
                        }
                        if (-y + x0 >= 0 && -x + y0 >= 0)
                        {
                            // Octant 6
                            visionRange.Add(new Vector2(-y + x0, -x + y0));
                        }
                        else
                        {
                            int newX = -y + x0 >= 0 ? -y + x0 : 0;
                            int newY = -x + y0 >= 0 ? -x + y0 : 0;
                            visionRange.Add(new Vector2(newX, newY));
                        }

                        if (x + x0 < dungeonDimensions.X && -y + y0 >= 0)
                        {
                            // Octant 8
                            visionRange.Add(new Vector2(x + x0, -y + y0));
                        }
                        else
                        {
                            int newX = x + x0 < dungeonDimensions.X ? x + x0 : (int)dungeonDimensions.X - 1;
                            int newY = -y + y0 >= 0 ? -y + y0 : 0;
                            visionRange.Add(new Vector2(newX, newY));
                        }
                        if (y + x0 < dungeonDimensions.X && -x + y0 >= 0)
                        {
                            // Octant 7
                            visionRange.Add(new Vector2(y + x0, -x + y0));
                        }
                        else
                        {
                            int newX = y + x0 < dungeonDimensions.X ? y + x0 : (int)dungeonDimensions.X - 1;
                            int newY = -x + y0 >= 0 ? -x + y0 : 0;
                            visionRange.Add(new Vector2(newX, newY));
                        }

                        if (x + x0 < dungeonDimensions.X && y + y0 < dungeonDimensions.Y)
                        {
                            // Octant 1
                            visionRange.Add(new Vector2(x + x0, y + y0));
                        }
                        else
                        {
                            int newX = x + x0 < dungeonDimensions.X ? x + x0 : (int)dungeonDimensions.X - 1;
                            int newY = y + y0 < dungeonDimensions.Y ? y + y0 : (int)dungeonDimensions.Y - 1;
                            visionRange.Add(new Vector2(newX, newY));
                        }
                        if (y + x0 < dungeonDimensions.X && x + y0 < dungeonDimensions.Y)
                        {
                            // Octant 2
                            visionRange.Add(new Vector2(y + x0, x + y0));
                        }
                        else
                        {
                            int newX = y + x0 < dungeonDimensions.X ? y + x0 : (int)dungeonDimensions.X - 1;
                            int newY = x + y0 < dungeonDimensions.Y ? x + y0 : (int)dungeonDimensions.Y - 1;
                            visionRange.Add(new Vector2(newX, newY));
                        }

                        if (-y + x0 >= 0 && x + y0 < dungeonDimensions.Y)
                        {
                            // Octant 3
                            visionRange.Add(new Vector2(-y + x0, x + y0));
                        }
                        else
                        {
                            int newX = -y + x0 >= 0 ? -y + x0 : 0;
                            int newY = x + y0 < dungeonDimensions.Y ? x + y0 : (int)dungeonDimensions.Y - 1;
                            visionRange.Add(new Vector2(newX, newY));
                        }
                        if (-x + x0 >= 0 && y + y0 < dungeonDimensions.Y)
                        {
                            // Octant 4
                            visionRange.Add(new Vector2(-x + x0, y + y0));
                        }
                        else
                        {
                            int newX = -x + x0 >= 0 ? -x + x0 : 0;
                            int newY = y + y0 < dungeonDimensions.Y ? y + y0 : (int)dungeonDimensions.Y - 1;
                            visionRange.Add(new Vector2(newX, newY));
                        }

                        y++;

                        if (decisionOver2 <= 0)
                        {
                            decisionOver2 += 2 * y + 1;   // Change in decision criterion for y -> y+1
                        }
                        else
                        {
                            x--;
                            decisionOver2 += 2 * (y - x) + 1;   // Change for y -> y+1, x -> x-1
                        }
                    }

                    //Fill the circle
                    foreach (var visionLine in visionRange.GroupBy(z => z.Y))
                    {
                        int smallestX = -1;
                        int largestX = -1;
                        foreach (var point in visionLine)
                        {
                            smallestX = smallestX == -1 ? (int)point.X : smallestX;
                            largestX = largestX == -1 ? (int)point.X : largestX;
                            if ((int)point.X < smallestX)
                            {
                                smallestX = (int)point.X;
                            }
                            if ((int)point.X > largestX)
                            {
                                largestX = (int)point.X;
                            }
                        }
                        //Build a line of points from smallest to largest x
                        for (int z = smallestX; z <= largestX; z++)
                        {
                            visionRange.Add(new Vector2(z, visionLine.Key));
                        }
                    }

                    foreach (Vector2 point in visionRange)
                    {
                        x0 = initialX;
                        y0 = initialY;
                        int dx = Math.Abs((int)point.X - x0), sx = x0 < (int)point.X ? 1 : -1;
                        int dy = -Math.Abs((int)point.Y - y0), sy = y0 < (int)point.Y ? 1 : -1;
                        int err = dx + dy, e2; /* error value e_xy */

                        for (;;)
                        {  /* loop */
                            
                            if (!dungeonGrid[x0, y0].Found)
                            {
                                dungeonGrid[x0, y0].NewlyFound = true;
                            }
                            dungeonGrid[x0, y0].FireIllumination = !isPlayer && dungeonGrid[(int)position.X, (int)position.Y].Type == TileType.TILE_FIRE;
                            dungeonGrid[x0, y0].Found = dungeonGrid[x0, y0].InRange = dungeonGrid[x0, y0].Occupiable = true;
                            if (dungeonGrid[x0, y0].Type == TileType.TILE_WALL || dungeonGrid[x0, y0].Type == TileType.TILE_ROCK)
                            {
                                dungeonGrid[x0, y0].Occupiable = false;
                                break;
                            }
                            if(dungeonGrid[x0, y0].Type == TileType.TILE_TALLGRASS && new Vector2(x0, y0) != position)
                            {
                                break;
                            }

                            if (x0 == (int)point.X && y0 == (int)point.Y) break;
                            e2 = 2 * err;
                            if (e2 >= dy) { err += dy; x0 += sx; } /* e_xy+e_x > 0 */
                            if (e2 <= dx) { err += dx; y0 += sy; } /* e_xy+e_y < 0 */
                        }


                    }
                }
                
            }
        }
Ejemplo n.º 10
0
 public static void IncreaseTileOpacity(ref DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions, GameTime gameTime, StateSpaceComponents spaceComponents)
 {
         for (int i = 0; i < dungeonDimensions.X; i++)
         {
             for (int j = 0; j < dungeonDimensions.Y; j++)
             {
                 if (dungeonGrid[i, j].NewlyFound)
                 {
                     if (dungeonGrid[i, j].Occupiable)
                     {
                         dungeonGrid[i, j].Opacity += (float)gameTime.ElapsedGameTime.TotalSeconds * 6;
                     }
                     else
                     {
                         dungeonGrid[i, j].Opacity += (float)gameTime.ElapsedGameTime.TotalSeconds * 4;
                     }
                 }
             }
         }
     if(spaceComponents.PlayerComponent.PlayerJustLoaded)
     {
         for (int i = 0; i < dungeonDimensions.X; i++)
         {
             for (int j = 0; j < dungeonDimensions.Y; j++)
             {
                 if (dungeonGrid[i, j].NewlyFound)
                 {
                     dungeonGrid[i, j].Opacity = 1;
                 }
             }
         }
     }
     
 }
Ejemplo n.º 11
0
        public static void HandleObserverFindings(StateSpaceComponents spaceComponents, KeyboardState key, KeyboardState prevKey, DungeonTile[,] dungeonGrid)
        {
            ObserverComponent observer = spaceComponents.ObserverComponent;
            Entity observerInfo = spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Observer) == ComponentMasks.Observer).FirstOrDefault();
            
            Vector2 playerPos = spaceComponents.PositionComponents[spaceComponents.Entities.Where(c => (c.ComponentFlags & ComponentMasks.Player) == ComponentMasks.Player).First().Id].Position;
            bool inWater = dungeonGrid[(int)playerPos.X, (int)playerPos.Y].Type == TileType.TILE_WATER;
            observer.SeeUnknown = false;

            if (observerInfo != null)
            {
                observer.Observed = new List<Guid>();
                int selectedItem = 0;
                PositionComponent observerPosition = spaceComponents.PositionComponents[observerInfo.Id];

                //gather a list of all observed items
                foreach (Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Observable) == ComponentMasks.Observable).Select(x => x.Id))
                {

                    PositionComponent enPos = spaceComponents.PositionComponents[id];
                    if (dungeonGrid[(int)observerPosition.Position.X, (int)observerPosition.Position.Y].InRange && enPos.Position == observerPosition.Position)
                    {
                        bool observedInWater = dungeonGrid[(int)enPos.Position.X, (int)enPos.Position.Y].Type == TileType.TILE_WATER;
                        if (observedInWater != inWater)
                        {
                            observer.SeeUnknown = true;
                            break;
                        }
                        observer.Observed.Add(id);
                    }
                }

                //set the current observed item to the first item if there isn't one yet
                if ((observer.SelectedItem == Guid.Empty && observer.Observed.Count > 0) || (observer.Observed.Count > 0 && !observer.Observed.Contains(observer.SelectedItem)))
                {
                    observer.SelectedItem = observer.Observed[selectedItem];
                }

                //set the index of the selected item
                if (observer.Observed.Count > 0)
                {
                    selectedItem = observer.Observed.IndexOf(observer.SelectedItem);
                }

                //Change the index if necessary
                if (key.IsKeyDown(Keys.Down) && prevKey.IsKeyUp(Keys.Down))
                {
                    selectedItem += 1;
                    if (selectedItem >= observer.Observed.Count)
                    {
                        selectedItem = 0;
                    }
                }
                else if (key.IsKeyDown(Keys.Up) && prevKey.IsKeyUp(Keys.Up))
                {
                    selectedItem -= 1;
                    if (selectedItem < 0)
                    {
                        selectedItem = observer.Observed.Count - 1;
                    }
                }

                //Update the component
                if (observer.Observed.Count > 0)
                {
                    observer.SelectedItem = observer.Observed[selectedItem];
                }

                spaceComponents.ObserverComponent = observer;
            }
        }
Ejemplo n.º 12
0
        public static void WriteMessages(StateSpaceComponents spaceComponents, SpriteBatch spriteBatch, Camera camera, SpriteFont font, DungeonTile[,] dungeonGrid)
        {
            float opacity = 1.15f;
            float decrement = .09f;
            int messageNumber = 0;
            int messageSpacing = (int)font.MeasureString("g").Y + 1; ;
            //Draw message log
            if(spaceComponents.GameMessageComponent.IndexBegin > 0)
            {
                float textHeight = font.MeasureString(Messages.ScrollingMessages).Y;
                spriteBatch.DrawString(font, Messages.ScrollingMessages, new Vector2(10, (int)camera.DungeonUIViewport.Bounds.Bottom -(int)textHeight - 10 - (messageNumber * messageSpacing)), Color.MediumVioletRed);
                messageNumber += 1;
            }
            foreach(Tuple<Color,string> message in spaceComponents.GameMessageComponent.GameMessages.Reverse<Tuple<Color,string>>().Skip(spaceComponents.GameMessageComponent.IndexBegin))
            {
                if(opacity < 0)
                {
                    break;
                }
                opacity -= decrement;
                string text = MessageDisplaySystem.WordWrap(font, message.Item2, camera.DungeonUIViewport.Width-20);

                float textHeight = font.MeasureString(text).Y;
                spriteBatch.DrawString(font,text, new Vector2(10, (int)camera.DungeonUIViewport.Bounds.Bottom - (int)textHeight - 10 - (messageNumber * messageSpacing)), message.Item1 * opacity);
                messageNumber += Regex.Matches(text, System.Environment.NewLine).Count;
                messageNumber += 1;
            }
            while (spaceComponents.GameMessageComponent.GameMessages.Count > spaceComponents.GameMessageComponent.MaxMessages)
            {
                spaceComponents.GameMessageComponent.GameMessages.RemoveAt(0);
            }
            spriteBatch.DrawString(font, spaceComponents.GameMessageComponent.GlobalMessage, new Vector2(10, camera.Bounds.Height - messageSpacing), spaceComponents.GameMessageComponent.GlobalColor);

            messageNumber = 0;
            //Draw statistics
                List<Tuple<Color,string>> statsToPrint = new List<Tuple<Color,string>>();
                GameplayInfoComponent gameplayInfo = spaceComponents.GameplayInfoComponent;

                statsToPrint.Add(new Tuple<Color, string>( Colors.Messages.Normal, string.Format("Floor {0}", gameplayInfo.FloorsReached)));
                statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Normal, string.Format("Steps: {0}", gameplayInfo.StepsTaken)));
                statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Normal, string.Format("Kills: {0}", gameplayInfo.Kills)));
            Entity player = spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Player) == ComponentMasks.Player).FirstOrDefault();
            if (player != null)
            {
                SkillLevelsComponent skills = InventorySystem.ApplyStatModifications(spaceComponents, player.Id, spaceComponents.SkillLevelsComponents[player.Id]);
                InventoryComponent inventory = spaceComponents.InventoryComponents[player.Id];
                statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Normal, string.Format("Health:  {0} / {1}", skills.CurrentHealth, skills.Health)));
                statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Normal, string.Format("Wealth: {0}", skills.Wealth)));
                statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Normal, string.Format("Damage: {0}-{1}", skills.MinimumDamage, skills.MaximumDamage)));
                statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Normal, string.Format("Accuracy: {0}", skills.Accuracy)));
                statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Normal, string.Format("Defense: {0}", skills.Defense)));
                statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                //Status Effects:
                Statuses statuses = StatusSystem.GetStatusEffectsOfEntity(spaceComponents, player.Id, dungeonGrid);
                if(statuses == Statuses.NONE)
                {
                    statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Normal, Messages.StatusMessages.Normal));
                    statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                }
                //If there are status effects on the player..
                else
                {
                    if((statuses & Statuses.BURNING) == Statuses.BURNING)
                    {
                        BurningComponent burning = spaceComponents.BurningComponents[player.Id];
                        statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Bad, string.Format(Messages.StatusMessages.Burning, burning.MinDamage, burning.MaxDamage, burning.TurnsLeft)));
                    }
                    if((statuses & Statuses.UNDERWATER) == Statuses.UNDERWATER)
                    {
                        statsToPrint.Add(new Tuple<Color, string>(Colors.Caves.WaterInRange, Messages.StatusMessages.Underwater));
                    }
                    if((statuses & Statuses.HEALTHREGEN) == Statuses.HEALTHREGEN)
                    {
                        HealthRegenerationComponent healthRegen = spaceComponents.HealthRegenerationComponents[player.Id];
                        statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Good, string.Format(Messages.StatusMessages.HealthRegen, healthRegen.HealthRegain, healthRegen.RegenerateTurnRate)));
                    }
                    statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                }

                statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Special, string.Format(Messages.InventoryArtifacts + " ({0}/{1})", inventory.Artifacts.Count, inventory.MaxArtifacts)));
                foreach (Guid id in inventory.Artifacts)
                {
                    NameComponent name = spaceComponents.NameComponents[id];
                    ArtifactStatsComponent artifactStats = spaceComponents.ArtifactStatsComponents[id];
                    statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.LootPickup, string.Format("{0} Lv{1}", name.Name, artifactStats.UpgradeLevel)));
                }

                statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Special, string.Format(Messages.InventoryConsumables + " ({0}/{1})", inventory.Consumables.Count, inventory.MaxConsumables)));
                if(inventory.Consumables.Count > 0)
                {
                    statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                    NameComponent name = spaceComponents.NameComponents[inventory.Consumables[0]];
                    ItemFunctionsComponent funcs = spaceComponents.ItemFunctionsComponents[inventory.Consumables[0]];
                    statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.LootPickup, string.Format("{0}({1})", name.Name, funcs.Uses)));
                    statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Normal, "Q - Use"));
                    statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Normal, "X - Throw"));
                    statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                    if (inventory.Consumables.Count > 1)
                    {
                        name = spaceComponents.NameComponents[inventory.Consumables[1]];
                        funcs = spaceComponents.ItemFunctionsComponents[inventory.Consumables[1]];
                        statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.LootPickup, string.Format("{0}({1})", name.Name, funcs.Uses)));
                        statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Normal, "E - Use"));
                        statsToPrint.Add(new Tuple<Color, string>(Colors.Messages.Normal, "C - Throw"));
                    }
                }
            }

            if (font != null)
                {
                    foreach (Tuple<Color,string> stat in statsToPrint)
                    {
                        string text = MessageDisplaySystem.WordWrap(font, stat.Item2, camera.DungeonUIViewportLeft.Width - messageSpacing);
                        Vector2 messageSize = font.MeasureString(stat.Item2);
                        spriteBatch.DrawString(font, text, new Vector2(camera.DungeonUIViewportLeft.X + 10, 10 + (messageSpacing * messageNumber)), stat.Item1);
                        messageNumber += 1;
                        messageNumber += Regex.Matches(text, System.Environment.NewLine).Count;
                    }
                }
        }
Ejemplo n.º 13
0
 public void DrawTiles(Camera camera, SpriteBatch spriteBatch, DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions)
 {
     for(int i = 0; i < (int)dungeonDimensions.X; i++)
     {
         for(int j = 0; j < (int)dungeonDimensions.Y; j++)
         {
             Rectangle tile = new Rectangle((int)i * cellSize, (int)j * cellSize, cellSize, cellSize);
             if (dungeonGrid[i, j].Found && !dungeonGrid[i,j].InRange)
             {
                 switch (dungeonGrid[i, j].Type)
                 {
                     case TileType.TILE_FLOOR:
                         spriteBatch.Draw(temporaryTile, tile, Color.DarkGreen);
                         break;
                     case TileType.TILE_WALL:
                         spriteBatch.Draw(temporaryTile, tile, Color.DarkViolet);
                         break;
                 }
             }
             else if(dungeonGrid[i,j].InRange && !dungeonGrid[i,j].NewlyFound)
             {
                 switch (dungeonGrid[i, j].Type)
                 {
                     case TileType.TILE_FLOOR:
                         spriteBatch.Draw(temporaryTile, tile, Color.Green);
                         break;
                     case TileType.TILE_WALL:
                         spriteBatch.Draw(temporaryTile, tile, Color.Violet);
                         break;
                 }
             }
             else if(dungeonGrid[i,j].NewlyFound)
             {
                 float opacity = dungeonGrid[i, j].Opacity;
                 switch (dungeonGrid[i, j].Type)
                 {
                     case TileType.TILE_FLOOR:
                         spriteBatch.Draw(temporaryTile, tile, Color.Green * opacity);
                         break;
                     case TileType.TILE_WALL:
                         spriteBatch.Draw(temporaryTile, tile, Color.Violet * opacity);
                         break;
                 }
                 dungeonGrid[i, j].Opacity += .21f;
                 if(dungeonGrid[i,j].Opacity > 1)
                 {
                     dungeonGrid[i, j].NewlyFound = false;
                     dungeonGrid[i, j].Found = true;
                 }
             }
         }
     }
 }
Ejemplo n.º 14
0
        public static void PrintObserver(StateSpaceComponents spaceComponents, SpriteFont font, SpriteBatch spriteBatch, DungeonTile[,] dungeonGrid, Camera camera, Texture2D UITexture)
        {
            ObserverComponent observer = spaceComponents.ObserverComponent;
            Entity observerInfo = spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Observer) == ComponentMasks.Observer).FirstOrDefault();
            if(observerInfo != null)
            {
                //Find out where the observer is
                PositionComponent observerPosition = spaceComponents.PositionComponents[observerInfo.Id];

                //Obtain the list of entities from the observer component
                List<Entity> observedItems = new List<Entity>();
                foreach (Guid id in observer.Observed)
                {
                    Entity entity = spaceComponents.Entities.Where(x => x.Id == id).FirstOrDefault();
                    if (entity != null)
                    {
                        observedItems.Add(entity);
                    }
                }

                //Set the initial variables
                int messageSpacing = (int)font.MeasureString("g").Y + 1;
                int messageLeft = 0;
                int messageRight = 0;
                int panelWidth = (int)((camera.DungeonViewport.Width / 2) - (DevConstants.Grid.CellSize * 2));
                List<Tuple<Color, string>> leftFindings = new List<Tuple<Color, string>>();
                List<Tuple<Color, string>> rightFindings = new List<Tuple<Color, string>>();

                //Gather information for the left side
                if (!dungeonGrid[(int)observerPosition.Position.X, (int)observerPosition.Position.Y].Found)
                {
                    leftFindings.Add(new Tuple<Color, string>(Colors.Messages.Bad, Messages.Observer.NotFound));
                }
                else
                {
                    if (dungeonGrid[(int)observerPosition.Position.X, (int)observerPosition.Position.Y].InRange)
                    {
                        leftFindings.Add(new Tuple<Color, string>(Colors.Messages.Good, Messages.Observer.InRange));
                    }
                    else
                    {
                        leftFindings.Add(new Tuple<Color, string>(Colors.Messages.Bad, Messages.Observer.OutOfRange));
                    }
                    leftFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                    switch (dungeonGrid[(int)observerPosition.Position.X, (int)observerPosition.Position.Y].Type)
                    {
                        case TileType.TILE_FLOOR:
                            leftFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, Messages.Observer.Floor));
                            break;
                        case TileType.TILE_WALL:
                            leftFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, Messages.Observer.Wall));
                            break;
                        case TileType.TILE_ROCK:
                            leftFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, Messages.Observer.Rock));
                            break;
                        case TileType.TILE_WATER:
                            leftFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, Messages.Observer.Water));
                            break;
                        case TileType.TILE_TALLGRASS:
                            leftFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, Messages.Observer.TallGrass));
                            break;
                        case TileType.TILE_FLATTENEDGRASS:
                            leftFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, Messages.Observer.FlatGrass));
                            break;
                        case TileType.TILE_FIRE:
                            leftFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, Messages.Observer.Fire));
                            break;
                        case TileType.TILE_ASH:
                            leftFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, Messages.Observer.Ash));
                            break;

                    }
                }

                if(observer.SeeUnknown)
                {
                    leftFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                    leftFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, Messages.Observer.Unknown));
                }

                if(observer.Observed.Count > 0)
                {
                    leftFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                    leftFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, "From here you can see the following: "));
                }
                //Gather observed names for the left side
                foreach(Entity en in observedItems)
                {
                    string prepend = (en.Id == observer.SelectedItem) ? "> " : string.Empty;
                    Color color = (en.Id == observer.SelectedItem) ? Colors.Messages.LootPickup : Colors.Messages.Normal;
                    leftFindings.Add(new Tuple<Color, string>(color, prepend + spaceComponents.NameComponents[en.Id].Name));
                }

                //Gather information for right side
                Entity selectedEntity = spaceComponents.Entities.Where(x => x.Id == observer.SelectedItem).FirstOrDefault();
                if(selectedEntity != null)
                {
                    if (spaceComponents.NameComponents[selectedEntity.Id].Name == "You")
                    {
                        rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, string.Format("You see yourself here.")));
                    }
                    else
                    {
                        rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, spaceComponents.NameComponents[selectedEntity.Id].Name));
                    }
                    rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, spaceComponents.NameComponents[selectedEntity.Id].Description));

                    //If the finding is an AI, gather the information for it
                    if((selectedEntity.ComponentFlags & ComponentMasks.ObservableAI) == ComponentMasks.ObservableAI)
                    {
                        AIState state = spaceComponents.AIStateComponents[selectedEntity.Id];
                        AIAlignment alignment = spaceComponents.AIAlignmentComponents[selectedEntity.Id];
                        SkillLevelsComponent skills = spaceComponents.SkillLevelsComponents[selectedEntity.Id];

                        switch (alignment.Alignment)
                        {
                            case AIAlignments.ALIGNMENT_NONE:
                                rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, "Neutral"));
                                break;
                            case AIAlignments.ALIGNMENT_HOSTILE:
                                rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Bad, "Hostile"));
                                break;
                            case AIAlignments.ALIGNMENT_FRIENDLY:
                                rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Good, "Friendly"));
                                break;
                        }
                        switch (state.State)
                        {
                            case AIStates.STATE_SLEEPING:
                                rightFindings.Add(new Tuple<Color, string>(Colors.Messages.StatusChange, "Sleeping"));
                                break;
                            case AIStates.STATE_ROAMING:
                                rightFindings.Add(new Tuple<Color, string>(Colors.Messages.StatusChange, "Roaming"));
                                break;
                            case AIStates.STATE_ATTACKING:
                                rightFindings.Add(new Tuple<Color, string>(Colors.Messages.StatusChange, "Attacking"));
                                break;
                            case AIStates.STATE_FLEEING:
                                rightFindings.Add(new Tuple<Color, string>(Colors.Messages.StatusChange, "Fleeing"));
                                break;
                        }
                        //Status Effects:
                        Statuses statuses = StatusSystem.GetStatusEffectsOfEntity(spaceComponents, selectedEntity.Id, dungeonGrid);
                        if (statuses == Statuses.NONE)
                        {
                            rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, Messages.StatusMessages.Normal));
                            rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                        }
                        //If there are status effects on the player..
                        else
                        {
                            if ((statuses & Statuses.BURNING) == Statuses.BURNING)
                            {
                                BurningComponent burning = spaceComponents.BurningComponents[selectedEntity.Id];
                                rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Bad, string.Format(Messages.StatusMessages.Burning, burning.MinDamage, burning.MaxDamage, burning.TurnsLeft)));
                            }
                            if ((statuses & Statuses.UNDERWATER) == Statuses.UNDERWATER)
                            {
                                rightFindings.Add(new Tuple<Color, string>(Colors.Caves.WaterInRange, Messages.StatusMessages.Underwater));
                            }
                            if ((statuses & Statuses.HEALTHREGEN) == Statuses.HEALTHREGEN)
                            {
                                HealthRegenerationComponent healthRegen = spaceComponents.HealthRegenerationComponents[selectedEntity.Id];
                                rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Good, string.Format(Messages.StatusMessages.HealthRegen, healthRegen.HealthRegain, healthRegen.RegenerateTurnRate)));
                            }
                            rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                        }


                        Entity player = spaceComponents.Entities.Where(x => (x.ComponentFlags & Component.COMPONENT_PLAYER) == Component.COMPONENT_PLAYER).First();
                        rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                        rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, string.Format("Health: {0} / {1}", skills.CurrentHealth, skills.Health)));
                        if (alignment.Alignment != AIAlignments.ALIGNMENT_FRIENDLY)
                        {
                            rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Good, string.Format("You have a {0}% chance to hit.", Math.Ceiling(CombatSystem.CalculateAccuracy(spaceComponents, spaceComponents.SkillLevelsComponents[player.Id], player.Id, skills, selectedEntity.Id)))));
                            rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Bad, string.Format("It has a {0}% chance of hitting you for a maximum of {1}.", Math.Ceiling(CombatSystem.CalculateAccuracy(spaceComponents, skills, selectedEntity.Id, spaceComponents.SkillLevelsComponents[player.Id], player.Id)), skills.MaximumDamage)));
                        }
                    }

                    //If the observed item is an item, gather that information instead
                    if ((selectedEntity.ComponentFlags & ComponentMasks.ObservableItem) == ComponentMasks.ObservableItem)
                    {
                        rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                        PickupComponent pickup = spaceComponents.PickupComponents[selectedEntity.Id];
                        switch (pickup.PickupType)
                        {
                            case ItemType.GOLD:
                                rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Special, "Gold"));
                                break;
                            case ItemType.CONSUMABLE:
                                rightFindings.Add(new Tuple<Color, string>(Colors.Messages.LootPickup, "Consumable"));
                                break;
                            case ItemType.ARTIFACT:
                                rightFindings.Add(new Tuple<Color, string>(Colors.Messages.LootPickup, "Artifact"));
                                break;
                        }

                        if((selectedEntity.ComponentFlags & ComponentMasks.ObservableValue) == ComponentMasks.ObservableValue && pickup.PickupType != ItemType.DOWNSTAIRS)
                        {
                            ValueComponent value = spaceComponents.ValueComponents[selectedEntity.Id];
                            rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Special, string.Format("This item is worth {0} gold.", value.Gold)));
                        }

                        if ((selectedEntity.ComponentFlags & ComponentMasks.ObservableSkillModifications) == ComponentMasks.ObservableSkillModifications)
                        {
                            StatModificationComponent stats = spaceComponents.StatModificationComponents[selectedEntity.Id];
                            rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                            rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, "This artifact affects the following stats: "));
                            if (stats.AccuracyChange != 0)
                            {
                                string sign = stats.AccuracyChange > 0 ? "+" : string.Empty;
                                Color color = stats.AccuracyChange > 0 ? Colors.Messages.Good : Colors.Messages.Bad;
                                rightFindings.Add(new Tuple<Color, string>(color, string.Format("Accuracy {0}{1}", sign, stats.AccuracyChange)));
                            }
                            if (stats.DefenseChange != 0)
                            {
                                string sign = stats.DefenseChange > 0 ? "+" : string.Empty;
                                Color color = stats.DefenseChange > 0 ? Colors.Messages.Good : Colors.Messages.Bad;
                                rightFindings.Add(new Tuple<Color, string>(color, string.Format("Defense {0}{1}", sign, stats.DefenseChange)));
                            }
                            if (stats.HealthChange != 0)
                            {
                                string sign = stats.HealthChange > 0 ? "+" : string.Empty;
                                Color color = stats.HealthChange > 0 ? Colors.Messages.Good : Colors.Messages.Bad;
                                rightFindings.Add(new Tuple<Color, string>(color, string.Format("Maximum Health {0}{1}", sign, stats.HealthChange)));
                            }
                            if (stats.DieNumberChange != 0)
                            {
                                string sign = stats.DieNumberChange > 0 ? "+" : string.Empty;
                                Color color = stats.DieNumberChange > 0 ? Colors.Messages.Good : Colors.Messages.Bad;
                                rightFindings.Add(new Tuple<Color, string>(color, string.Format("Dice Number on Attack {0}{1}", sign, stats.DieNumberChange)));
                            }
                            if (stats.MinimumDamageChange != 0)
                            {
                                string sign = stats.MinimumDamageChange > 0 ? "+" : string.Empty;
                                Color color = stats.MinimumDamageChange > 0 ? Colors.Messages.Good : Colors.Messages.Bad;
                                rightFindings.Add(new Tuple<Color, string>(color, string.Format("Minimum Damage {0}{1}", sign, stats.MinimumDamageChange)));
                            }
                            if (stats.MaximumDamageChange != 0)
                            {
                                string sign = stats.MaximumDamageChange > 0 ? "+" : string.Empty;
                                Color color = stats.MaximumDamageChange > 0 ? Colors.Messages.Good : Colors.Messages.Bad;
                                rightFindings.Add(new Tuple<Color, string>(color, string.Format("Maximum Damage {0}{1}", sign, stats.MaximumDamageChange)));
                            }
                        }

                        if((selectedEntity.ComponentFlags & ComponentMasks.ObservableUsage) == ComponentMasks.ObservableUsage)
                        {
                            ItemFunctionsComponent funcs = spaceComponents.ItemFunctionsComponents[selectedEntity.Id];
                            rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                            rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Good, string.Format("This item has {0} uses left.", funcs.Uses)));
                            rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Bad, string.Format("This item loses {0} value per use.", funcs.CostToUse)));
                            if(funcs.Ranged)
                            {
                                rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, "This item is cast at a range."));
                            }
                            else
                            {
                                rightFindings.Add(new Tuple<Color, string>(Colors.Messages.Normal, "This item is used where you stand."));
                            }
                        }

                    }

                }

                //Draw sections
                //Left section
                spriteBatch.Draw(UITexture, new Rectangle(0, 0, panelWidth, (int)camera.DungeonViewport.Height), Color.Black * .5f);
                foreach (Tuple<Color, string> message in leftFindings)
                {
                    if (string.IsNullOrEmpty(message.Item2))
                    {
                        continue;
                    }
                    string text = MessageDisplaySystem.WordWrap(font, message.Item2, panelWidth - messageSpacing);

                    float textHeight = font.MeasureString(message.Item2).Y;
                    spriteBatch.DrawString(font, text, new Vector2(messageSpacing, messageSpacing + (messageLeft * messageSpacing)), message.Item1);
                    messageLeft += Regex.Matches(text, System.Environment.NewLine).Count;
                    messageLeft += 1;
                }
                //Right section
                if (observer.Observed.Count > 0)
                {
                    spriteBatch.Draw(UITexture, new Rectangle((int)camera.DungeonViewport.Bounds.Right - panelWidth, 0, panelWidth, (int)camera.DungeonViewport.Height), Color.Black * .5f);
                    foreach (Tuple<Color, string> message in rightFindings)
                    {
                        if (string.IsNullOrEmpty(message.Item2))
                        {
                            continue;
                        }
                        string text = MessageDisplaySystem.WordWrap(font, message.Item2, panelWidth - messageSpacing);

                        float textHeight = font.MeasureString(message.Item2).Y;
                        spriteBatch.DrawString(font, text, new Vector2((int)camera.DungeonViewport.Bounds.Right - panelWidth + messageSpacing, messageSpacing + (messageRight * messageSpacing)), message.Item1);
                        messageRight += Regex.Matches(text, System.Environment.NewLine).Count;
                        messageRight += 1;
                    }
                }

            }
        }
Ejemplo n.º 15
0
        private static PositionComponent AIRoam(Guid entity, PositionComponent position, DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions, Random random)
        {
            List<Vector2> validSpots = new List<Vector2>();
            //Select a random traversible direction and move in that direction
            for(int i = (int)position.Position.X-1; i <= (int)position.Position.X+1; i++)
            {
                for(int j = (int)position.Position.Y-1; j <= (int)position.Position.Y+1; j++)
                {
                    if(i >=0 && j >= 0 && i < (int)dungeonDimensions.X && j < (int)dungeonDimensions.Y &&  dungeonGrid[i,j].Occupiable)
                    {
                        validSpots.Add(new Vector2(i, j));
                    }
                }
            }

            //Choose a new spot
            return new PositionComponent() { Position = validSpots[random.Next(0, validSpots.Count)] };

        }
Ejemplo n.º 16
0
 public static void ExtinguishFire(int x, int y, StateSpaceComponents spaceComponents, DungeonTile[,] dungeonGrid)
 {
     PlayerComponent player = spaceComponents.PlayerComponent;
     player.SightRadiusDeleted = true;
     spaceComponents.PlayerComponent = player;
     dungeonGrid[x, y].Type = TileType.TILE_ASH;
     dungeonGrid[x, y].Symbol = Tiles.AshSymbol;
     dungeonGrid[x, y].SymbolColor = Tiles.AshSymbolColor;
     dungeonGrid[x, y].TurnsToBurn = 0;
     dungeonGrid[x, y].ChanceToIgnite = Tiles.AshIgniteChance;
     spaceComponents.EntitiesToDelete.Add(dungeonGrid[x, y].AttachedEntity);
     dungeonGrid[x, y].AttachedEntity = Guid.Empty;
 }
Ejemplo n.º 17
0
        public Vector2 GenerateDungeon(ref DungeonTile[,] dungeonGrid, int worldMin, int worldMax, Random random, List <Vector2> freeTiles)
        {
            int worldI = random.Next(worldMin, worldMax);
            int worldJ = random.Next(worldMin, worldMax);

            dungeonGrid = new DungeonTile[worldI, worldJ];

            bool acceptable = false;

            while (!acceptable)
            {
                //Cellular Automata
                for (int i = 0; i < worldI; i++)
                {
                    for (int j = 0; j < worldJ; j++)
                    {
                        int choice = random.Next(0, 101);
                        dungeonGrid[i, j].Type = (choice <= 41) ? TileType.TILE_ROCK : TileType.TILE_FLOOR;
                    }
                }

                int iterations = 8;
                for (int z = 0; z <= iterations; z++)
                {
                    DungeonTile[,] newMap = new DungeonTile[worldI, worldJ];
                    for (int i = 0; i < worldI; i++)
                    {
                        for (int j = 0; j < worldJ; j++)
                        {
                            int numRocks = 0;
                            int farRocks = 0;
                            //Check 8 directions and self
                            //Self:
                            if (dungeonGrid[i, j].Type == TileType.TILE_ROCK)
                            {
                                numRocks += 1;
                            }
                            //Topleft
                            if (i - 1 < 0 || j - 1 < 0)
                            {
                                numRocks += 1;
                            }
                            else if (dungeonGrid[i - 1, j - 1].Type == TileType.TILE_ROCK)
                            {
                                numRocks += 1;
                            }
                            //Top
                            if (j - 1 < 0)
                            {
                                numRocks += 1;
                            }
                            else if (dungeonGrid[i, j - 1].Type == TileType.TILE_ROCK)
                            {
                                numRocks += 1;
                            }
                            //Topright
                            if (i + 1 > worldI - 1 || j - 1 < 0)
                            {
                                numRocks += 1;
                            }
                            else if (dungeonGrid[i + 1, j - 1].Type == TileType.TILE_ROCK)
                            {
                                numRocks += 1;
                            }
                            //Left
                            if (i - 1 < 0)
                            {
                                numRocks += 1;
                            }
                            else if (dungeonGrid[i - 1, j].Type == TileType.TILE_ROCK)
                            {
                                numRocks += 1;
                            }
                            //Right
                            if (i + 1 > worldI - 1)
                            {
                                numRocks += 1;
                            }
                            else if (dungeonGrid[i + 1, j].Type == TileType.TILE_ROCK)
                            {
                                numRocks += 1;
                            }
                            //Bottomleft
                            if (i - 1 < 0 || j + 1 > worldJ - 1)
                            {
                                numRocks += 1;
                            }
                            else if (dungeonGrid[i - 1, j + 1].Type == TileType.TILE_ROCK)
                            {
                                numRocks += 1;
                            }
                            //Bottom
                            if (j + 1 > worldJ - 1)
                            {
                                numRocks += 1;
                            }
                            else if (dungeonGrid[i, j + 1].Type == TileType.TILE_ROCK)
                            {
                                numRocks += 1;
                            }
                            //BottomRight
                            if (i + 1 > worldI - 1 || j + 1 > worldJ - 1)
                            {
                                numRocks += 1;
                            }
                            else if (dungeonGrid[i + 1, j + 1].Type == TileType.TILE_ROCK)
                            {
                                numRocks += 1;
                            }

                            //Check 8 directions for far rocks

                            //Topleft
                            if (i - 2 < 0 || j - 2 < 0)
                            {
                                farRocks += 1;
                            }
                            else if (dungeonGrid[i - 2, j - 2].Type == TileType.TILE_ROCK)
                            {
                                farRocks += 1;
                            }
                            //Top
                            if (j - 2 < 0)
                            {
                                farRocks += 1;
                            }
                            else if (dungeonGrid[i, j - 2].Type == TileType.TILE_ROCK)
                            {
                                farRocks += 1;
                            }
                            //Topright
                            if (i + 2 > worldI - 2 || j - 2 < 0)
                            {
                                farRocks += 1;
                            }
                            else if (dungeonGrid[i + 2, j - 2].Type == TileType.TILE_ROCK)
                            {
                                farRocks += 1;
                            }
                            //Left
                            if (i - 2 < 0)
                            {
                                farRocks += 1;
                            }
                            else if (dungeonGrid[i - 2, j].Type == TileType.TILE_ROCK)
                            {
                                farRocks += 1;
                            }
                            //Right
                            if (i + 2 > worldI - 2)
                            {
                                farRocks += 1;
                            }
                            else if (dungeonGrid[i + 2, j].Type == TileType.TILE_ROCK)
                            {
                                farRocks += 1;
                            }
                            //Bottomleft
                            if (i - 2 < 0 || j + 2 > worldJ - 2)
                            {
                                farRocks += 1;
                            }
                            else if (dungeonGrid[i - 2, j + 2].Type == TileType.TILE_ROCK)
                            {
                                farRocks += 1;
                            }
                            //Bottom
                            if (j + 2 > worldJ - 2)
                            {
                                farRocks += 1;
                            }
                            else if (dungeonGrid[i, j + 2].Type == TileType.TILE_ROCK)
                            {
                                farRocks += 1;
                            }
                            //BottomRight
                            if (i + 2 > worldI - 2 || j + 2 > worldJ - 2 || dungeonGrid[i + 2, j + 2].Type == TileType.TILE_ROCK)
                            {
                                farRocks += 1;
                            }
                            else if (dungeonGrid[i + 2, j + 2].Type == TileType.TILE_ROCK)
                            {
                                farRocks += 1;
                            }


                            if (numRocks >= 5 || i == 0 || j == 0 || i == worldI - 1 || j == worldJ - 1 || (z <= 3 && numRocks + farRocks <= 2))
                            {
                                newMap[i, j].Type = TileType.TILE_ROCK;
                            }
                            else
                            {
                                newMap[i, j].Type = TileType.TILE_FLOOR;
                            }
                        }
                    }
                    Array.Copy(newMap, dungeonGrid, worldJ * worldI);
                }

                int fillX = 0;
                int fillY = 0;
                do
                {
                    fillX = random.Next(0, worldI);
                    fillY = random.Next(0, worldJ);
                } while (dungeonGrid[fillX, fillY].Type != TileType.TILE_FLOOR);

                this.FloodFill(fillX, fillY, worldI, worldJ, ref dungeonGrid);

                double connectedTiles = 0.0;
                double totalTiles     = 0.0;
                for (int i = 0; i < worldI; i++)
                {
                    for (int j = 0; j < worldJ; j++)
                    {
                        if (dungeonGrid[fillX, fillY].Type == TileType.TILE_FLOOR)
                        {
                            totalTiles += 1.0;
                            if (dungeonGrid[i, j].Reached)
                            {
                                connectedTiles += 1.0;
                            }
                        }
                    }
                }

                if (connectedTiles / totalTiles >= .50)
                {
                    for (int i = 0; i < worldI; i++)
                    {
                        for (int j = 0; j < worldJ; j++)
                        {
                            if (!dungeonGrid[i, j].Reached)
                            {
                                dungeonGrid[i, j].Type = TileType.TILE_ROCK;
                            }
                        }
                    }
                    acceptable = true;
                }
            }

            //Mark Walls
            for (int i = 0; i < worldI; i++)
            {
                for (int j = 0; j < worldJ; j++)
                {
                    int numFloor = 0;
                    //Check 8 directions and self
                    //Self:
                    if (dungeonGrid[i, j].Type == TileType.TILE_ROCK)
                    {
                        //Topleft
                        if (!(i - 1 < 0 || j - 1 < 0) && dungeonGrid[i - 1, j - 1].Type == TileType.TILE_FLOOR)
                        {
                            numFloor += 1;
                        }
                        //Top
                        if (!(j - 1 < 0) && dungeonGrid[i, j - 1].Type == TileType.TILE_FLOOR)
                        {
                            numFloor += 1;
                        }
                        //Topright
                        if (!(i + 1 > worldI - 1 || j - 1 < 0) && dungeonGrid[i + 1, j - 1].Type == TileType.TILE_FLOOR)
                        {
                            numFloor += 1;
                        }
                        //Left
                        if (!(i - 1 < 0) && dungeonGrid[i - 1, j].Type == TileType.TILE_FLOOR)
                        {
                            numFloor += 1;
                        }
                        //Right
                        if (!(i + 1 > worldI - 1) && dungeonGrid[i + 1, j].Type == TileType.TILE_FLOOR)
                        {
                            numFloor += 1;
                        }
                        //Bottomleft
                        if (!(i - 1 < 0 || j + 1 > worldJ - 1) && dungeonGrid[i - 1, j + 1].Type == TileType.TILE_FLOOR)
                        {
                            numFloor += 1;
                        }
                        //Bottom
                        if (!(j + 1 > worldJ - 1) && dungeonGrid[i, j + 1].Type == TileType.TILE_FLOOR)
                        {
                            numFloor += 1;
                        }
                        //BottomRight
                        if (!(i + 1 > worldI - 1 || j + 1 > worldJ - 1) && dungeonGrid[i + 1, j + 1].Type == TileType.TILE_FLOOR)
                        {
                            numFloor += 1;
                        }

                        if (numFloor > 0)
                        {
                            dungeonGrid[i, j].Type = TileType.TILE_WALL;
                        }
                    }
                }
            }



            for (int i = 0; i < worldI; i++)
            {
                for (int j = 0; j < worldJ; j++)
                {
                    if (dungeonGrid[i, j].Type == TileType.TILE_FLOOR)
                    {
                        dungeonGrid[i, j].Occupiable     = true;
                        dungeonGrid[i, j].ChanceToIgnite = Tiles.FloorIgniteChance;
                        freeTiles.Add(new Vector2(i, j));
                    }
                }
            }

            return(new Vector2(worldI, worldJ));
        }
Ejemplo n.º 18
0
        public static Statuses GetStatusEffectsOfEntity(StateSpaceComponents spaceComponents, Guid entity, DungeonTile[,] dungeonGrid)
        {
            Statuses statuses = Statuses.NONE;

            //Check for UnderWater
            if((spaceComponents.Entities.Where(x => x.Id == entity).First().ComponentFlags & Component.COMPONENT_POSITION) == Component.COMPONENT_POSITION)
            {
                Vector2 entityPosition = spaceComponents.PositionComponents[entity].Position;
                if (dungeonGrid[(int)entityPosition.X, (int)entityPosition.Y].Type == TileType.TILE_WATER)
                {
                    statuses |= Statuses.UNDERWATER;
                }
            }

            //Check for Burning
            if ((spaceComponents.Entities.Where(x => x.Id == entity).First().ComponentFlags & ComponentMasks.BurningStatus) == ComponentMasks.BurningStatus)
            {
                statuses |= Statuses.BURNING;
            }

            //Check for HealthRegen
            if ((spaceComponents.Entities.Where(x => x.Id == entity).First().ComponentFlags & ComponentMasks.HealthRegen) == ComponentMasks.HealthRegen)
            {
                statuses |= Statuses.HEALTHREGEN;
            }

            return statuses;
        }
Ejemplo n.º 19
0
        private void FloodFill(int x, int y, int worldI, int worldJ, ref DungeonTile[,] dungeonGrid)
        {
            if (x < 0 || y < 0 || x >= worldI || y >= worldJ)
            {
                return;
            }

            Queue<Vector2> floodQueue = new Queue<Vector2>();
            floodQueue.Enqueue(new Vector2(x, y));

            while (floodQueue.Count > 0)
            {
                Vector2 pos = floodQueue.Dequeue();
                if (dungeonGrid[(int)pos.X, (int)pos.Y].Type == TileType.TILE_FLOOR && !dungeonGrid[(int)pos.X, (int)pos.Y].Reached)
                {
                    x = (int)pos.X;
                    y = (int)pos.Y;
                    dungeonGrid[(int)pos.X, (int)pos.Y].Reached = true;
                    HashSet<Vector2> toAdd = new HashSet<Vector2>();
                    toAdd.Add(new Vector2(x + 1, y + 1));
                    toAdd.Add(new Vector2(x, y + 1));
                    toAdd.Add(new Vector2(x + 1, y));
                    toAdd.Add(new Vector2(x - 1, y - 1));
                    toAdd.Add(new Vector2(x - 1, y));
                    toAdd.Add(new Vector2(x, y - 1));
                    toAdd.Add(new Vector2(x + 1, y - 1));
                    toAdd.Add(new Vector2(x - 1, y + 1));
                    foreach (var vector in toAdd)
                    {
                        if (!floodQueue.Contains(vector))
                        {
                            floodQueue.Enqueue(vector);
                        }
                    }
                    toAdd.Clear();
                }
            }

        }
Ejemplo n.º 20
0
        public Vector2 GenerateDungeon(ref DungeonTile[,] dungeonGrid, int worldMin, int worldMax, Random random, List<Vector2> freeTiles)
        {
            int worldI = random.Next(worldMin, worldMax);
            int worldJ = random.Next(worldMin, worldMax);

            dungeonGrid = new DungeonTile[worldI, worldJ];

            bool acceptable = false;

            while (!acceptable)
            {
                //Cellular Automata
                for (int i = 0; i < worldI; i++)
                {
                    for (int j = 0; j < worldJ; j++)
                    {
                        int choice = random.Next(0, 101);
                        dungeonGrid[i, j].Type = (choice <= 41) ? TileType.TILE_ROCK : TileType.TILE_FLOOR;
                    }
                }

                int iterations = 8;
                for (int z = 0; z <= iterations; z++)
                {
                    DungeonTile[,] newMap = new DungeonTile[worldI, worldJ];
                    for (int i = 0; i < worldI; i++)
                    {
                        for (int j = 0; j < worldJ; j++)
                        {
                            int numRocks = 0;
                            int farRocks = 0;
                            //Check 8 directions and self
                            //Self:
                            if (dungeonGrid[i, j].Type == TileType.TILE_ROCK)
                            {
                                numRocks += 1;
                            }
                            //Topleft
                            if (i - 1 < 0 || j - 1 < 0)
                            {
                                numRocks += 1;
                            }
                            else if (dungeonGrid[i - 1, j - 1].Type == TileType.TILE_ROCK)
                            {
                                numRocks += 1;
                            }
                            //Top
                            if (j - 1 < 0)
                            {
                                numRocks += 1;
                            }
                            else if (dungeonGrid[i, j - 1].Type == TileType.TILE_ROCK)
                            {
                                numRocks += 1;
                            }
                            //Topright
                            if (i + 1 > worldI - 1 || j - 1 < 0)
                            {
                                numRocks += 1;
                            }
                            else if (dungeonGrid[i + 1, j - 1].Type == TileType.TILE_ROCK)
                            {
                                numRocks += 1;
                            }
                            //Left
                            if (i - 1 < 0)
                            {
                                numRocks += 1;
                            }
                            else if (dungeonGrid[i - 1, j].Type == TileType.TILE_ROCK)
                            {
                                numRocks += 1;
                            }
                            //Right
                            if (i + 1 > worldI - 1)
                            {
                                numRocks += 1;
                            }
                            else if (dungeonGrid[i + 1, j].Type == TileType.TILE_ROCK)
                            {
                                numRocks += 1;
                            }
                            //Bottomleft
                            if (i - 1 < 0 || j + 1 > worldJ - 1)
                            {
                                numRocks += 1;
                            }
                            else if (dungeonGrid[i - 1, j + 1].Type == TileType.TILE_ROCK)
                            {
                                numRocks += 1;
                            }
                            //Bottom
                            if (j + 1 > worldJ - 1)
                            {
                                numRocks += 1;
                            }
                            else if (dungeonGrid[i, j + 1].Type == TileType.TILE_ROCK)
                            {
                                numRocks += 1;
                            }
                            //BottomRight
                            if (i + 1 > worldI - 1 || j + 1 > worldJ - 1)
                            {
                                numRocks += 1;
                            }
                            else if (dungeonGrid[i + 1, j + 1].Type == TileType.TILE_ROCK)
                            {
                                numRocks += 1;
                            }

                            //Check 8 directions for far rocks

                            //Topleft
                            if (i - 2 < 0 || j - 2 < 0)
                            {
                                farRocks += 1;
                            }
                            else if (dungeonGrid[i - 2, j - 2].Type == TileType.TILE_ROCK)
                            {
                                farRocks += 1;
                            }
                            //Top
                            if (j - 2 < 0)
                            {
                                farRocks += 1;
                            }
                            else if (dungeonGrid[i, j - 2].Type == TileType.TILE_ROCK)
                            {
                                farRocks += 1;
                            }
                            //Topright
                            if (i + 2 > worldI - 2 || j - 2 < 0)
                            {
                                farRocks += 1;
                            }
                            else if (dungeonGrid[i + 2, j - 2].Type == TileType.TILE_ROCK)
                            {
                                farRocks += 1;
                            }
                            //Left
                            if (i - 2 < 0)
                            {
                                farRocks += 1;
                            }
                            else if (dungeonGrid[i - 2, j].Type == TileType.TILE_ROCK)
                            {
                                farRocks += 1;
                            }
                            //Right
                            if (i + 2 > worldI - 2)
                            {
                                farRocks += 1;
                            }
                            else if (dungeonGrid[i + 2, j].Type == TileType.TILE_ROCK)
                            {
                                farRocks += 1;
                            }
                            //Bottomleft
                            if (i - 2 < 0 || j + 2 > worldJ - 2)
                            {
                                farRocks += 1;
                            }
                            else if (dungeonGrid[i - 2, j + 2].Type == TileType.TILE_ROCK)
                            {
                                farRocks += 1;
                            }
                            //Bottom
                            if (j + 2 > worldJ - 2)
                            {
                                farRocks += 1;
                            }
                            else if (dungeonGrid[i, j + 2].Type == TileType.TILE_ROCK)
                            {
                                farRocks += 1;
                            }
                            //BottomRight
                            if (i + 2 > worldI - 2 || j + 2 > worldJ - 2 || dungeonGrid[i + 2, j + 2].Type == TileType.TILE_ROCK)
                            {
                                farRocks += 1;
                            }
                            else if (dungeonGrid[i + 2, j + 2].Type == TileType.TILE_ROCK)
                            {
                                farRocks += 1;
                            }


                            if (numRocks >= 5 || i == 0 || j == 0 || i == worldI - 1 || j == worldJ - 1 || (z <= 3 && numRocks + farRocks <= 2))
                            {
                                newMap[i, j].Type = TileType.TILE_ROCK;
                            }
                            else
                            {
                                newMap[i, j].Type = TileType.TILE_FLOOR;
                            }
                        }
                    }
                    Array.Copy(newMap, dungeonGrid, worldJ * worldI);
                }

                int fillX = 0;
                int fillY = 0;
                do
                {
                    fillX = random.Next(0, worldI);
                    fillY = random.Next(0, worldJ);
                } while (dungeonGrid[fillX, fillY].Type != TileType.TILE_FLOOR);

                this.FloodFill(fillX, fillY, worldI, worldJ, ref dungeonGrid);

                double connectedTiles = 0.0;
                double totalTiles = 0.0;
                for (int i = 0; i < worldI; i++)
                {
                    for (int j = 0; j < worldJ; j++)
                    {
                        if (dungeonGrid[fillX, fillY].Type == TileType.TILE_FLOOR)
                        {
                            totalTiles += 1.0;
                            if (dungeonGrid[i, j].Reached)
                            {
                                connectedTiles += 1.0;
                            }
                        }
                    }
                }

                if (connectedTiles / totalTiles >= .50)
                {
                    for (int i = 0; i < worldI; i++)
                    {
                        for (int j = 0; j < worldJ; j++)
                        {
                            if (!dungeonGrid[i, j].Reached)
                            {
                                dungeonGrid[i, j].Type = TileType.TILE_ROCK;
                            }
                        }
                    }
                    acceptable = true;
                }

            }

            //Mark Walls
            for (int i = 0; i < worldI; i++)
            {
                for (int j = 0; j < worldJ; j++)
                {
                    int numFloor = 0;
                    //Check 8 directions and self
                    //Self:
                    if (dungeonGrid[i, j].Type == TileType.TILE_ROCK)
                    {
                        //Topleft
                        if (!(i - 1 < 0 || j - 1 < 0) && dungeonGrid[i - 1, j - 1].Type == TileType.TILE_FLOOR)
                        {
                            numFloor += 1;
                        }
                        //Top
                        if (!(j - 1 < 0) && dungeonGrid[i, j - 1].Type == TileType.TILE_FLOOR)
                        {
                            numFloor += 1;
                        }
                        //Topright
                        if (!(i + 1 > worldI - 1 || j - 1 < 0) && dungeonGrid[i + 1, j - 1].Type == TileType.TILE_FLOOR)
                        {
                            numFloor += 1;
                        }
                        //Left
                        if (!(i - 1 < 0) && dungeonGrid[i - 1, j].Type == TileType.TILE_FLOOR)
                        {
                            numFloor += 1;
                        }
                        //Right
                        if (!(i + 1 > worldI - 1) && dungeonGrid[i + 1, j].Type == TileType.TILE_FLOOR)
                        {
                            numFloor += 1;
                        }
                        //Bottomleft
                        if (!(i - 1 < 0 || j + 1 > worldJ - 1) && dungeonGrid[i - 1, j + 1].Type == TileType.TILE_FLOOR)
                        {
                            numFloor += 1;
                        }
                        //Bottom
                        if (!(j + 1 > worldJ - 1) && dungeonGrid[i, j + 1].Type == TileType.TILE_FLOOR)
                        {
                            numFloor += 1;
                        }
                        //BottomRight
                        if (!(i + 1 > worldI - 1 || j + 1 > worldJ - 1) && dungeonGrid[i + 1, j + 1].Type == TileType.TILE_FLOOR)
                        {
                            numFloor += 1;
                        }

                        if (numFloor > 0)
                        {
                            dungeonGrid[i, j].Type = TileType.TILE_WALL;
                        }
                    }

                }
            }



            for (int i = 0; i < worldI; i++)
            {
                for(int j = 0; j < worldJ; j++)
                {
                    if(dungeonGrid[i,j].Type == TileType.TILE_FLOOR)
                    {
                        dungeonGrid[i, j].Occupiable = true;
                        dungeonGrid[i, j].ChanceToIgnite = Tiles.FloorIgniteChance;
                        freeTiles.Add(new Vector2(i, j));
                    }
                }
            }

            return new Vector2(worldI, worldJ);
        }
Ejemplo n.º 21
0
        public static void HandleDungeonMovement(StateSpaceComponents spaceComponents, GraphicsDeviceManager graphics, GameTime gameTime,
            KeyboardState prevKeyboardState, MouseState prevMouseState, GamePadState prevGamepadState, Camera camera, DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions)
        {
            IEnumerable<Guid> movableEntities = spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.InputMoveable) == ComponentMasks.InputMoveable).Select(x => x.Id);
            foreach(Guid id in movableEntities)
            {
                bool hitWall = false;
                bool movement = false;
                KeyboardState keyState = Keyboard.GetState();
                PositionComponent pos = spaceComponents.PositionComponents[id];
                GameplayInfoComponent gameInfo = spaceComponents.GameplayInfoComponent;
                InputMovementComponent movementComponent = spaceComponents.InputMovementComponents[id];
                if (keyState.IsKeyDown(Keys.NumPad8))
                {
                    movement = InputMovementSystem.CalculateMovement(ref pos, 0, -1, ref movementComponent, gameTime, Keys.NumPad8);
                }
                else if (keyState.IsKeyDown(Keys.NumPad2))
                {
                    movement = InputMovementSystem.CalculateMovement(ref pos, 0, 1, ref movementComponent, gameTime, Keys.NumPad2);
                }
                else if (keyState.IsKeyDown(Keys.NumPad6))
                {
                    movement = InputMovementSystem.CalculateMovement(ref pos, 1, 0, ref movementComponent, gameTime, Keys.NumPad6);
                }
                else if (keyState.IsKeyDown(Keys.NumPad4))
                {
                    movement = InputMovementSystem.CalculateMovement(ref pos, -1, 0, ref movementComponent, gameTime, Keys.NumPad4);
                }
                else if (keyState.IsKeyDown(Keys.NumPad5))
                {
                    movement = InputMovementSystem.CalculateMovement(ref pos, 0, 0, ref movementComponent, gameTime, Keys.NumPad4);
                }
                else if (keyState.IsKeyDown(Keys.NumPad7))
                {
                    movement = InputMovementSystem.CalculateMovement(ref pos, -1, -1, ref movementComponent, gameTime, Keys.NumPad7);
                }
                else if (keyState.IsKeyDown(Keys.NumPad9))
                {
                    movement = InputMovementSystem.CalculateMovement(ref pos, 1, -1, ref movementComponent, gameTime, Keys.NumPad9);
                }
                else if (keyState.IsKeyDown(Keys.NumPad1))
                {
                    movement = InputMovementSystem.CalculateMovement(ref pos, -1, 1, ref movementComponent, gameTime, Keys.NumPad1);
                }
                else if (keyState.IsKeyDown(Keys.NumPad3))
                {
                    movement = InputMovementSystem.CalculateMovement(ref pos, 1, 1, ref movementComponent, gameTime, Keys.NumPad3);
                }
                #region Item
                else if (keyState.IsKeyDown(Keys.Q) && prevKeyboardState.IsKeyUp(Keys.Q))
                {
                    if(spaceComponents.InventoryComponents.ContainsKey(id))
                    { 
                        InventoryComponent invo = spaceComponents.InventoryComponents[id];
                        if (invo.Consumables.Count > 0)
                        {
                            ItemFunctionsComponent funcs = spaceComponents.ItemFunctionsComponents[invo.Consumables[0]];
                            InventorySystem.UseItem(spaceComponents, dungeonGrid, dungeonDimensions, invo.Consumables[0], id);
                        }
                    }
                }
                else if (keyState.IsKeyDown(Keys.E) && prevKeyboardState.IsKeyUp(Keys.E))
                {
                    if (spaceComponents.InventoryComponents.ContainsKey(id))
                    {
                        InventoryComponent invo = spaceComponents.InventoryComponents[id];
                        if(invo.Consumables.Count > 1)
                        {
                            ItemFunctionsComponent funcs = spaceComponents.ItemFunctionsComponents[invo.Consumables[1]];
                            InventorySystem.UseItem(spaceComponents, dungeonGrid, dungeonDimensions, invo.Consumables[1], id);
                        }
                    }
                }

                #endregion

                #region debug
                else if (keyState.IsKeyDown(Keys.OemPeriod) && prevKeyboardState.IsKeyUp(Keys.OemPeriod))
                {
                    TileSystem.CreateFire((int)pos.Position.X, (int)pos.Position.Y, spaceComponents, dungeonGrid);
                }

                #endregion


                //else if (keyState.IsKeyDown(Keys.Z) && prevKeyboardState.IsKeyUp(Keys.Z))
                //{
                //    SightRadiusComponent radius = spaceComponents.SightRadiusComponents[id];
                //    radius.CurrentRadius -= 1;
                //    spaceComponents.SightRadiusComponents[id] = (radius.CurrentRadius <= 0) ? spaceComponents.SightRadiusComponents[id] : radius;
                //    movement = true;
                //}
                //else if (keyState.IsKeyDown(Keys.X) && prevKeyboardState.IsKeyUp(Keys.X))
                //{
                //    SightRadiusComponent radius = spaceComponents.SightRadiusComponents[id];
                //    radius.CurrentRadius += 1;
                //    spaceComponents.SightRadiusComponents[id] = (radius.CurrentRadius > spaceComponents.SightRadiusComponents[id].MaxRadius) ? spaceComponents.SightRadiusComponents[id] : radius;
                //    movement = true;
                //}
                else
                {
                    movementComponent.IsButtonDown = false;
                    movementComponent.TotalTimeButtonDown = 0f;
                    movementComponent.LastKeyPressed = Keys.None;
                }
                bool outOfBounds = false;
                if(pos.Position.X < 0 || pos.Position.Y < 0 || pos.Position.X >= dungeonDimensions.X || pos.Position.Y >= dungeonDimensions.Y)
                {
                    outOfBounds = true;
                }
                if(!outOfBounds)
                {
                    hitWall = !dungeonGrid[(int)pos.Position.X, (int)pos.Position.Y].Occupiable && spaceComponents.CollisionComponents[id].Solid;
                    spaceComponents.InputMovementComponents[id] = movementComponent;
                    if (!hitWall && movement)
                    {
                        //Check collisions.  If no collisions, move into spot.
                        CollisionSystem.TryToMove(spaceComponents, dungeonGrid, pos, id);
                        if ((spaceComponents.Entities.Where(x => x.Id == id).First().ComponentFlags & Component.COMPONENT_PLAYER) == Component.COMPONENT_PLAYER)
                        {
                            gameInfo.StepsTaken += 1;
                            spaceComponents.GameplayInfoComponent = gameInfo;
                            PlayerComponent player = spaceComponents.PlayerComponent;
                            player.PlayerTookTurn = true;
                            spaceComponents.PlayerComponent = player;
                        }
                    }
                    if (hitWall)
                    {
                        MessageDisplaySystem.GenerateRandomGameMessage(spaceComponents, Messages.WallCollisionMessages, Colors.Messages.Normal);
                    }
                }

            }
        }
Ejemplo n.º 22
0
        public static void SpreadFire(ref DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions, StateSpaceComponents spaceComponents)
        {
            if(spaceComponents.PlayerComponent.PlayerTookTurn)
            {
                for (int i = 0; i < (int)dungeonDimensions.X; i++)
                {
                    for (int j = 0; j < (int)dungeonDimensions.Y; j++)
                    {
                        //If it's a fire tile, check its neighbors and attempt to spread the fire.  Decrease the fire burn time.  If the fire is dead, turn it to ash.
                        if(dungeonGrid[i,j].Type == TileType.TILE_FIRE)
                        {
                            for (int k = i - 1; k <= i + 1; k++)
                            {
                                for (int l = j - 1; l <= j + 1; l++)
                                {
                                    if(l >= 0 && k >= 0 && l < (int)dungeonDimensions.Y && k < (int)dungeonDimensions.X && spaceComponents.random.Next(0, 101) < dungeonGrid[k, l].ChanceToIgnite)
                                    {
                                        TileSystem.CreateFire(k, l, spaceComponents, dungeonGrid);
                                    }
                                }
                            }

                            dungeonGrid[i, j].TurnsToBurn -= 1;
                            if (dungeonGrid[i, j].TurnsToBurn <= 0)
                            {
                                TileSystem.ExtinguishFire(i, j, spaceComponents, dungeonGrid);
                            }

                        }
                    }
                }

                foreach (Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.BurningStatus) == ComponentMasks.BurningStatus).Select(x => x.Id))
                {
                    if((spaceComponents.Entities.Where(x => x.Id == id).First().ComponentFlags & Component.COMPONENT_POSITION) == Component.COMPONENT_POSITION)
                    {
                        Vector2 position = spaceComponents.PositionComponents[id].Position;
                        int i = (int)position.X;
                        int j = (int)position.Y;

                        for (int k = i - 1; k <= i + 1; k++)
                        {
                            for (int l = j - 1; l <= j + 1; l++)
                            {
                                if (l >= 0 && k >= 0 && l < (int)dungeonDimensions.Y && k < (int)dungeonDimensions.X && spaceComponents.random.Next(0, 101) < dungeonGrid[k, l].ChanceToIgnite)
                                {
                                    TileSystem.CreateFire(k, l, spaceComponents, dungeonGrid);
                                }
                            }
                        }
                    }
                }

            }

        }
Ejemplo n.º 23
0
 public static void TryPickupItems(StateSpaceComponents spaceComponents, DungeonTile[,] dungeongrid)
 {
     IEnumerable<Guid> entitiesThatCollided = spaceComponents.GlobalCollisionComponent.EntitiesThatCollided.Distinct();
     foreach(Guid collidingEntity in entitiesThatCollided)
     {
         Entity colliding = spaceComponents.Entities.Where(x => x.Id == collidingEntity).FirstOrDefault();
         //If the colliding entity has an inventory and messages, place the item inside the inventory.
         if(colliding != null && (colliding.ComponentFlags & ComponentMasks.InventoryPickup) == ComponentMasks.InventoryPickup)
         {
             CollisionComponent collidingEntityCollisions = spaceComponents.CollisionComponents[collidingEntity];
             InventoryComponent collidingEntityInventory = spaceComponents.InventoryComponents[collidingEntity];
             NameComponent collidingEntityName = spaceComponents.NameComponents[collidingEntity];
             PositionComponent collidingEntityPosition = spaceComponents.PositionComponents[collidingEntity];
             EntityMessageComponent collidingEntityMessages = spaceComponents.EntityMessageComponents[collidingEntity];
             foreach(Guid collidedEntity in collidingEntityCollisions.CollidedObjects)
             {
                 //Check to see if the collidedEntity is a pickup item, if it is, try to place it in the inventory if it fits.
                 Entity collided = spaceComponents.Entities.Where(x => x.Id == collidedEntity).FirstOrDefault();
                 //If the collideditem is a pickup item, handle it based on pickup type.
                 if(collided != null && (collided.ComponentFlags & ComponentMasks.PickupItem) == ComponentMasks.PickupItem)
                 {
                     PickupComponent itemPickup = spaceComponents.PickupComponents[collidedEntity];
                     ValueComponent itemValue = spaceComponents.ValueComponents[collidedEntity];
                     NameComponent itemName = spaceComponents.NameComponents[collidedEntity];
                     switch(itemPickup.PickupType)
                     {
                         case ItemType.GOLD:
                             if(spaceComponents.SkillLevelsComponents.ContainsKey(collidingEntity))
                             {
                                 SkillLevelsComponent skills = spaceComponents.SkillLevelsComponents[collidingEntity];
                                 skills.Wealth += itemValue.Gold;
                                 spaceComponents.SkillLevelsComponents[collidingEntity] = skills;
                                 if(dungeongrid[(int)collidingEntityPosition.Position.X, (int)collidingEntityPosition.Position.Y].InRange)
                                 {
                                     spaceComponents.GameMessageComponent.GameMessages.Add(new Tuple<Color, string>(Colors.Messages.Special, string.Format("[TURN " + spaceComponents.GameplayInfoComponent.StepsTaken + "] " + "{0} picked up {1} gold.", collidingEntityName.Name, itemValue.Gold)));
                                 }
                                 spaceComponents.EntitiesToDelete.Add(collidedEntity);
                             }
                             break;
                         case ItemType.CONSUMABLE:
                             //If the entity has room in their inventory, place the item in it
                             if(collidingEntityInventory.Consumables.Count < collidingEntityInventory.MaxConsumables)
                             {
                                 //Remove the position component flag and add the guid to the inventory of the entity
                                 collided.ComponentFlags &= ~Component.COMPONENT_POSITION;
                                 collidingEntityInventory.Consumables.Add(collided.Id);
                                 if(dungeongrid[(int)collidingEntityPosition.Position.X, (int)collidingEntityPosition.Position.Y].InRange && collidingEntityMessages.PickupItemMessages.Length > 0)
                                 {
                                     spaceComponents.GameMessageComponent.GameMessages.Add(new Tuple<Color, string>(Colors.Messages.LootPickup,
                                         string.Format("[TURN " + spaceComponents.GameplayInfoComponent.StepsTaken + "] " + collidingEntityMessages.PickupItemMessages[spaceComponents.random.Next(0, collidingEntityMessages.PickupItemMessages.Length)], collidingEntityName.Name, itemName.Name)));
                                 }
                             }
                             //If it can't fit in, and the entity has a message for the situation, display it.
                             else if(spaceComponents.EntityMessageComponents[collidingEntity].ConsumablesFullMessages != null && spaceComponents.EntityMessageComponents[collidingEntity].ConsumablesFullMessages.Length > 0)
                             {
                                 spaceComponents.GameMessageComponent.GameMessages.Add(new Tuple<Color, string>(Colors.Messages.Bad, "[TURN " + spaceComponents.GameplayInfoComponent.StepsTaken + "] " +  spaceComponents.EntityMessageComponents[collidingEntity].ConsumablesFullMessages[spaceComponents.random.Next(0, spaceComponents.EntityMessageComponents[collidingEntity].ConsumablesFullMessages.Length)]));
                             }
                             break;
                         case ItemType.ARTIFACT:
                             //If the entity has room in their inventory, place the item in it
                             if (collidingEntityInventory.Artifacts.Count < collidingEntityInventory.MaxArtifacts)
                             {
                                 //Remove the position component flag and add the guid to the inventory of the entity
                                 collided.ComponentFlags &= ~Component.COMPONENT_POSITION;
                                 collidingEntityInventory.Artifacts.Add(collided.Id);
                                 if (dungeongrid[(int)collidingEntityPosition.Position.X, (int)collidingEntityPosition.Position.Y].InRange && collidingEntityMessages.PickupItemMessages.Length > 0)
                                 {
                                     spaceComponents.GameMessageComponent.GameMessages.Add(new Tuple<Color, string>(Colors.Messages.LootPickup,
                                         string.Format("[TURN " + spaceComponents.GameplayInfoComponent.StepsTaken + "] " + collidingEntityMessages.PickupItemMessages[spaceComponents.random.Next(0, collidingEntityMessages.PickupItemMessages.Length)], collidingEntityName.Name, itemName.Name)));
                                 }
                             }
                             //If it can't fit in, and the entity has a message for the situation, display it.
                             else if (spaceComponents.EntityMessageComponents[collidingEntity].ArtifactsFullMessages != null && spaceComponents.EntityMessageComponents[collidingEntity].ArtifactsFullMessages.Length > 0)
                             {
                                 spaceComponents.GameMessageComponent.GameMessages.Add(new Tuple<Color, string>(Colors.Messages.Bad, "[TURN " + spaceComponents.GameplayInfoComponent.StepsTaken + "] " + spaceComponents.EntityMessageComponents[collidingEntity].ArtifactsFullMessages[spaceComponents.random.Next(0, spaceComponents.EntityMessageComponents[collidingEntity].ArtifactsFullMessages.Length)]));
                             }
                             break;
                         case ItemType.DOWNSTAIRS:
                             //Tell the game to go to the next level
                             if((spaceComponents.Entities.Where(x => x.Id == collidingEntity).FirstOrDefault().ComponentFlags & Component.COMPONENT_PLAYER) == Component.COMPONENT_PLAYER)
                             {
                                 PlayerComponent player = spaceComponents.PlayerComponent;
                                 player.GoToNextFloor = true;
                                 spaceComponents.PlayerComponent = player;
                             }
                             break;
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 24
0
 public static void CreateFire(int x, int y, StateSpaceComponents spaceComponents, DungeonTile[,] dungeonGrid)
 {
     dungeonGrid[x, y].ChanceToIgnite = 0;
     spaceComponents.DelayedActions.Add(new Action(() =>
     {
         dungeonGrid[x, y].Type = TileType.TILE_FIRE;
         dungeonGrid[x, y].Symbol = Tiles.FireSymbol;
         dungeonGrid[x, y].SymbolColor = Tiles.FireSymbolColor;
         dungeonGrid[x, y].TurnsToBurn = spaceComponents.random.Next(3, 10);
         dungeonGrid[x, y].ChanceToIgnite = Tiles.FireIgniteChance;
         if(dungeonGrid[x, y].AttachedEntity == Guid.Empty)
         {
             Guid idFire = spaceComponents.CreateEntity();
             spaceComponents.Entities.Where(c => c.Id == idFire).First().ComponentFlags = Component.COMPONENT_POSITION | Component.COMPONENT_SIGHTRADIUS;
             spaceComponents.PositionComponents[idFire] = new PositionComponent() { Position = new Vector2(x, y) };
             spaceComponents.SightRadiusComponents[idFire] = new SightRadiusComponent() { DrawRadius = true, CurrentRadius = 5, MaxRadius = 5 };
             dungeonGrid[x, y].AttachedEntity = idFire;
             foreach (Guid id in spaceComponents.PositionComponents.Where(z => z.Value.Position == new Vector2(x, y)).Select(z => z.Key))
             {
                 if (spaceComponents.SkillLevelsComponents.ContainsKey(id))
                 {
                     StatusSystem.ApplyBurnEffect(spaceComponents, id, StatusEffects.Burning.Turns, StatusEffects.Burning.MinDamage, StatusEffects.Burning.MaxDamage);
                 }
             }
         }
     }));
 }
Ejemplo n.º 25
0
        public static bool SpawnPlayer(StateSpaceComponents stateSpaceComponents, DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions, int cellSize, List<Vector2> freeTiles)
        {
            Entity player = stateSpaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Player) == ComponentMasks.Player).FirstOrDefault();
            if(player == null)
            {
                Guid id = stateSpaceComponents.CreateEntity();
                stateSpaceComponents.Entities.Where(x => x.Id == id).First().ComponentFlags = ComponentMasks.Player | Component.COMPONENT_INPUTMOVEMENT | ComponentMasks.InventoryPickup;
                //Set Position
                int tileIndex = stateSpaceComponents.random.Next(0, freeTiles.Count);
                stateSpaceComponents.PositionComponents[id] = new PositionComponent() { Position = freeTiles[tileIndex] };
                freeTiles.RemoveAt(tileIndex);
                dungeonGrid[(int)stateSpaceComponents.PositionComponents[id].Position.X, (int)stateSpaceComponents.PositionComponents[id].Position.Y].Occupiable = true;
                //Set Display
                stateSpaceComponents.DisplayComponents[id] = new DisplayComponent()
                {
                    Color = Color.White,
                    SpriteSource = new Rectangle(0 * cellSize, 0 * cellSize, cellSize, cellSize),
                    Origin = Vector2.Zero,
                    SpriteEffect = SpriteEffects.None,
                    Scale = 1f,
                    Rotation = 0f,
                    Opacity = 1f,
                    AlwaysDraw = true
                };
                //Set Sightradius
                stateSpaceComponents.SightRadiusComponents[id] = new SightRadiusComponent() { CurrentRadius = 15, MaxRadius = 15, DrawRadius = true };
                //Set first turn
                stateSpaceComponents.PlayerComponent = new PlayerComponent() { PlayerJustLoaded = true };
                //Collision information
                stateSpaceComponents.CollisionComponents[id] = new CollisionComponent() { CollidedObjects = new List<Guid>(), Solid = true };
                //Set name of player
                stateSpaceComponents.NameComponents[id] = new NameComponent() { Name = "You", Description = "This is me.  I came to these caves to find my fortune." };
                //Set Input of the player
                stateSpaceComponents.InputMovementComponents[id] = new InputMovementComponent() { TimeIntervalBetweenMovements = .09f, TimeSinceLastMovement = 0f, InitialWait = .5f, TotalTimeButtonDown = 0f, LastKeyPressed = Keys.None };
                //Set an alignment for AI to communicate with
                stateSpaceComponents.AIAlignmentComponents[id] = new AIAlignment() { Alignment = AIAlignments.ALIGNMENT_FRIENDLY };
                //Set combat messages
                stateSpaceComponents.EntityMessageComponents[id] = new EntityMessageComponent()
                {
                    NormalDodgeMessages = new string[]
                    {
                    " and the attack misses you!",
                    " but nothing happened.",
                    " ... but it failed!",
                    " and your defense protects you.",
                    " but it fails to connect."
                    },
                    StreakDodgeMessages = new string[]
                    {
                    " but you don't even notice.",
                    " and you laugh at the attempt.",
                    " but you easily dodge it again.",
                    " and misses you. Again!"
                    },
                    AttackNPCMessages = new string[]
                    {
                    "{0} attack the {1}",
                    "{0} take a swing at the {1}",
                    "{0} swipe at {1}",
                    "{0} try to damage the {1}",
                    "{0} slash viciously at the {1}"
                    },
                    NormalTakeDamageMessages = new string[]
                    {
                    " and you take {0} damage.",
                    " and it hurts! You take {0} damage.",
                    "! Ow. You lose {0} health.",
                    " and hits you for {0} damage."
                    },
                    BrokenDodgeStreakTakeDamageMessages = new string[]
                    {
                    " and you finally take {0} damage.",
                    " and this time you lose {0} health! Ow!",
                    " and hits you for {0} THIS time.",
                    "! {0} damage taken! Don't get cocky..."
                    },
                    PickupItemMessages = new string[]
                    {
                    "{0} pick up the {1}.",
                    "{0} find a {1}.",
                    "{0} got a {1}!"
                    },
                    ConsumablesFullMessages = new string[]
                    {
                    "You cannot carry any more consumables.",
                    "Your consumable slots are full!",
                    "You don't have any place to store this consumable."
                    },
                    ArtifactsFullMessages = new string[]
                    {
                    "Your artifact slots are too full for another.",
                    "Drop or scrap one of your artifacts to pick this up.",
                    "You can't pick up this artifact; you already have enough."
                    }
                };
                //Inventory
                stateSpaceComponents.InventoryComponents[id] = new InventoryComponent() { Artifacts = new List<Guid>(), Consumables = new List<Guid>(), MaxArtifacts = 3, MaxConsumables = 2 };
            }
            else
            {
                //If there's already a player, just make a new starting location on the floor
                //Set Position
                int tileIndex = stateSpaceComponents.random.Next(0, freeTiles.Count);
                stateSpaceComponents.PositionComponents[player.Id] = new PositionComponent() { Position = freeTiles[tileIndex] };
                freeTiles.RemoveAt(tileIndex);
                dungeonGrid[(int)stateSpaceComponents.PositionComponents[player.Id].Position.X, (int)stateSpaceComponents.PositionComponents[player.Id].Position.Y].Occupiable = true;
            }

            return true;
        }
Ejemplo n.º 26
0
        public static void AIUpdateVision(StateSpaceComponents spaceComponents, DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions)
        {
            foreach(Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.AIView) == ComponentMasks.AIView).Select(x => x.Id))
            {

                AIFieldOfView fieldOfViewInfo = spaceComponents.AIFieldOfViewComponents[id];

                //Reset seen tiles
                fieldOfViewInfo.SeenTiles = new List<Vector2>();

                if(fieldOfViewInfo.radius >= 0)
                {
                    Vector2 position = spaceComponents.PositionComponents[id].Position;
                    int radius = fieldOfViewInfo.radius;
                    int initialX, x0, initialY, y0;
                    initialX = x0 = (int)position.X;
                    initialY = y0 = (int)position.Y;

                    List<Vector2> visionRange = new List<Vector2>();
                    
                    int x = radius;
                    int y = 0;
                    int decisionOver2 = 1 - x;   // Decision criterion divided by 2 evaluated at x=r, y=0

                    while (y <= x)
                    {
                        if (-x + x0 >= 0 && -y + y0 >= 0)
                        {
                            // Octant 5
                            visionRange.Add(new Vector2(-x + x0, -y + y0));
                        }
                        else
                        {
                            int newX = -x + x0 >= 0 ? -x + x0 : 0;
                            int newY = -y + y0 >= 0 ? -y + y0 : 0;
                            visionRange.Add(new Vector2(newX, newY));
                        }
                        if (-y + x0 >= 0 && -x + y0 >= 0)
                        {
                            // Octant 6
                            visionRange.Add(new Vector2(-y + x0, -x + y0));
                        }
                        else
                        {
                            int newX = -y + x0 >= 0 ? -y + x0 : 0;
                            int newY = -x + y0 >= 0 ? -x + y0 : 0;
                            visionRange.Add(new Vector2(newX, newY));
                        }

                        if (x + x0 < dungeonDimensions.X && -y + y0 >= 0)
                        {
                            // Octant 8
                            visionRange.Add(new Vector2(x + x0, -y + y0));
                        }
                        else
                        {
                            int newX = x + x0 < dungeonDimensions.X ? x + x0 : (int)dungeonDimensions.X - 1;
                            int newY = -y + y0 >= 0 ? -y + y0 : 0;
                            visionRange.Add(new Vector2(newX, newY));
                        }
                        if (y + x0 < dungeonDimensions.X && -x + y0 >= 0)
                        {
                            // Octant 7
                            visionRange.Add(new Vector2(y + x0, -x + y0));
                        }
                        else
                        {
                            int newX = y + x0 < dungeonDimensions.X ? y + x0 : (int)dungeonDimensions.X - 1;
                            int newY = -x + y0 >= 0 ? -x + y0 : 0;
                            visionRange.Add(new Vector2(newX, newY));
                        }

                        if (x + x0 < dungeonDimensions.X && y + y0 < dungeonDimensions.Y)
                        {
                            // Octant 1
                            visionRange.Add(new Vector2(x + x0, y + y0));
                        }
                        else
                        {
                            int newX = x + x0 < dungeonDimensions.X ? x + x0 : (int)dungeonDimensions.X - 1;
                            int newY = y + y0 < dungeonDimensions.Y ? y + y0 : (int)dungeonDimensions.Y - 1;
                            visionRange.Add(new Vector2(newX, newY));
                        }
                        if (y + x0 < dungeonDimensions.X && x + y0 < dungeonDimensions.Y)
                        {
                            // Octant 2
                            visionRange.Add(new Vector2(y + x0, x + y0));
                        }
                        else
                        {
                            int newX = y + x0 < dungeonDimensions.X ? y + x0 : (int)dungeonDimensions.X - 1;
                            int newY = x + y0 < dungeonDimensions.Y ? x + y0 : (int)dungeonDimensions.Y - 1;
                            visionRange.Add(new Vector2(newX, newY));
                        }

                        if (-y + x0 >= 0 && x + y0 < dungeonDimensions.Y)
                        {
                            // Octant 3
                            visionRange.Add(new Vector2(-y + x0, x + y0));
                        }
                        else
                        {
                            int newX = -y + x0 >= 0 ? -y + x0 : 0;
                            int newY = x + y0 < dungeonDimensions.Y ? x + y0 : (int)dungeonDimensions.Y - 1;
                            visionRange.Add(new Vector2(newX, newY));
                        }
                        if (-x + x0 >= 0 && y + y0 < dungeonDimensions.Y)
                        {
                            // Octant 4
                            visionRange.Add(new Vector2(-x + x0, y + y0));
                        }
                        else
                        {
                            int newX = -x + x0 >= 0 ? -x + x0 : 0;
                            int newY = y + y0 < dungeonDimensions.Y ? y + y0 : (int)dungeonDimensions.Y - 1;
                            visionRange.Add(new Vector2(newX, newY));
                        }

                        y++;

                        if (decisionOver2 <= 0)
                        {
                            decisionOver2 += 2 * y + 1;   // Change in decision criterion for y -> y+1
                        }
                        else
                        {
                            x--;
                            decisionOver2 += 2 * (y - x) + 1;   // Change for y -> y+1, x -> x-1
                        }
                    }

                    //Fill the circle
                    foreach (var visionLine in visionRange.GroupBy(z => z.Y))
                    {
                        int smallestX = -1;
                        int largestX = -1;
                        foreach (var point in visionLine)
                        {
                            smallestX = smallestX == -1 ? (int)point.X : smallestX;
                            largestX = largestX == -1 ? (int)point.X : largestX;
                            if ((int)point.X < smallestX)
                            {
                                smallestX = (int)point.X;
                            }
                            if ((int)point.X > largestX)
                            {
                                largestX = (int)point.X;
                            }
                        }
                        //Build a line of points from smallest to largest x
                        for (int z = smallestX; z <= largestX; z++)
                        {
                            visionRange.Add(new Vector2(z, visionLine.Key));
                        }
                    }

                    foreach (Vector2 point in visionRange)
                    {
                        x0 = initialX;
                        y0 = initialY;

                        int dx = Math.Abs((int)point.X - x0), sx = x0 < (int)point.X ? 1 : -1;
                        int dy = -Math.Abs((int)point.Y - y0), sy = y0 < (int)point.Y ? 1 : -1;
                        int err = dx + dy, e2; /* error value e_xy */

                        for (;;)
                        {  /* loop */
                            if (dungeonGrid[x0, y0].Occupiable)
                            {

                                fieldOfViewInfo.SeenTiles.Add(new Vector2(x0, y0));
                            }
                            else
                            {
                                break;
                            }

                            if (x0 == (int)point.X && y0 == (int)point.Y) break;
                            e2 = 2 * err;
                            if (e2 >= dy) { err += dy; x0 += sx; } /* e_xy+e_x > 0 */
                            if (e2 <= dx) { err += dx; y0 += sy; } /* e_xy+e_y < 0 */
                        }


                    }
                    fieldOfViewInfo.SeenTiles = fieldOfViewInfo.SeenTiles.Distinct().ToList();
                    spaceComponents.AIFieldOfViewComponents[id] = fieldOfViewInfo;
                }
            }


        }
Ejemplo n.º 27
0
        public static void RevealTiles(DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions, StateSpaceComponents spaceComponents)
        {
            Guid entity = spaceComponents.Entities.Where(z => (z.ComponentFlags & ComponentMasks.Player) == ComponentMasks.Player).FirstOrDefault().Id;
            Vector2 position = spaceComponents.PositionComponents[entity].Position;
            int radius = spaceComponents.SightRadiusComponents[entity].Radius;
            int initialX, x0, initialY, y0;
            initialX = x0 = (int)position.X;
            initialY = y0 = (int)position.Y;

            //Reset Range
            for (int i = 0; i < dungeonDimensions.X; i++)
            {
                for (int j = 0; j < dungeonDimensions.Y; j++)
                {
                    dungeonGrid[i, j].InRange = false;
                }
            }
            List<Vector2> visionRange = new List<Vector2>();
            /*
                         Shared
                         edge by
              Shared     1 & 2      Shared
              edge by\      |      /edge by
              1 & 8   \     |     / 2 & 3
                       \1111|2222/
                       8\111|222/3
                       88\11|22/33
                       888\1|2/333
              Shared   8888\|/3333  Shared
              edge by-------@-------edge by
              7 & 8    7777/|\4444  3 & 4
                       777/6|5\444
                       77/66|55\44
                       7/666|555\4
                       /6666|5555\
              Shared  /     |     \ Shared
              edge by/      |      \edge by
              6 & 7      Shared     4 & 5
                         edge by 
                         5 & 6
             */
            int x = radius;
            int y = 0;
            int decisionOver2 = 1 - x;   // Decision criterion divided by 2 evaluated at x=r, y=0

            while (y <= x)
            {
                if (-x + x0 >= 0 && -y + y0 >= 0)
                {
                    // Octant 5
                    visionRange.Add(new Vector2(-x + x0, -y + y0));
                }
                else
                {
                    int newX = -x + x0 >= 0 ? -x + x0 : 0;
                    int newY = -y + y0 >= 0 ? -y + y0 : 0;
                    visionRange.Add(new Vector2(newX, newY));
                }
                if (-y + x0 >= 0 && -x + y0 >= 0)
                {
                    // Octant 6
                    visionRange.Add(new Vector2(-y + x0, -x + y0));
                }
                else
                {
                    int newX = -y + x0 >= 0 ? -y + x0 : 0;
                    int newY = -x + y0 >= 0 ? -x + y0 : 0;
                    visionRange.Add(new Vector2(newX, newY));
                }

                if (x + x0 < dungeonDimensions.X && -y + y0 >= 0)
                {
                    // Octant 8
                    visionRange.Add(new Vector2(x + x0, -y + y0));
                }
                else
                {
                    int newX = x + x0 < dungeonDimensions.X ? x + x0 : (int)dungeonDimensions.X - 1;
                    int newY = -y + y0 >= 0 ? -y + y0 : 0;
                    visionRange.Add(new Vector2(newX, newY));
                }
                if (y + x0 < dungeonDimensions.X && -x + y0 >= 0)
                {
                    // Octant 7
                    visionRange.Add(new Vector2(y + x0, -x + y0));
                }
                else
                {
                    int newX = y + x0 < dungeonDimensions.X ? y + x0 : (int)dungeonDimensions.X - 1;
                    int newY = -x + y0 >= 0 ? -x + y0 : 0;
                    visionRange.Add(new Vector2(newX, newY));
                }

                if (x + x0 < dungeonDimensions.X && y + y0 < dungeonDimensions.Y)
                {
                    // Octant 1
                    visionRange.Add(new Vector2(x + x0, y + y0));
                }
                else
                {
                    int newX = x + x0 < dungeonDimensions.X ? x + x0 : (int)dungeonDimensions.X - 1;
                    int newY = y + y0 < dungeonDimensions.Y ? y + y0 : (int)dungeonDimensions.Y - 1;
                    visionRange.Add(new Vector2(newX, newY));
                }
                if (y + x0 < dungeonDimensions.X && x + y0 < dungeonDimensions.Y)
                {
                    // Octant 2
                    visionRange.Add(new Vector2(y + x0, x + y0));
                }
                else
                {
                    int newX = y + x0 < dungeonDimensions.X ? y + x0 : (int)dungeonDimensions.X - 1;
                    int newY = x + y0 < dungeonDimensions.Y ? x + y0 : (int)dungeonDimensions.Y - 1;
                    visionRange.Add(new Vector2(newX, newY));
                }

                if (-y + x0 >= 0 && x + y0 < dungeonDimensions.Y)
                {
                    // Octant 3
                    visionRange.Add(new Vector2(-y + x0, x + y0));
                }
                else
                {
                    int newX = -y + x0 >= 0 ? -y + x0 : 0;
                    int newY = x + y0 < dungeonDimensions.Y ? x + y0 : (int)dungeonDimensions.Y - 1;
                    visionRange.Add(new Vector2(newX, newY));
                }
                if (-x + x0 >= 0 && y + y0 < dungeonDimensions.Y)
                {
                    // Octant 4
                    visionRange.Add(new Vector2(-x + x0, y + y0));
                }
                else
                {
                    int newX = -x + x0 >= 0 ? -x + x0 : 0;
                    int newY = y + y0 < dungeonDimensions.Y ? y + y0 : (int)dungeonDimensions.Y - 1;
                    visionRange.Add(new Vector2(newX, newY));
                }

                y++;

                if (decisionOver2 <= 0)
                {
                    decisionOver2 += 2 * y + 1;   // Change in decision criterion for y -> y+1
                }
                else
                {
                    x--;
                    decisionOver2 += 2 * (y - x) + 1;   // Change for y -> y+1, x -> x-1
                }
            }

            //Fill the circle
            foreach (var visionLine in visionRange.GroupBy(z => z.Y))
            {
                int smallestX = -1;
                int largestX = -1;
                foreach (var point in visionLine)
                {
                    smallestX = smallestX == -1 ? (int)point.X : smallestX;
                    largestX = largestX == -1 ? (int)point.X : largestX;
                    if ((int)point.X < smallestX)
                    {
                        smallestX = (int)point.X;
                    }
                    if ((int)point.X > largestX)
                    {
                        largestX = (int)point.X;
                    }
                }
                //Build a line of points from smallest to largest x
                for (int z = smallestX; z <= largestX; z++)
                {
                    visionRange.Add(new Vector2(z, visionLine.Key));
                }
            }

            foreach (Vector2 point in visionRange)
            {
                x0 = initialX;
                y0 = initialY;

                int dx = Math.Abs((int)point.X - x0), sx = x0 < (int)point.X ? 1 : -1;
                int dy = -Math.Abs((int)point.Y - y0), sy = y0 < (int)point.Y ? 1 : -1;
                int err = dx + dy, e2; /* error value e_xy */

                for (;;)
                {  /* loop */

                    if (!dungeonGrid[x0, y0].Found)
                    {
                        dungeonGrid[x0, y0].NewlyFound = true;
                    }
                    dungeonGrid[x0, y0].Found = dungeonGrid[x0, y0].InRange = true; 
                    if (dungeonGrid[x0, y0].Type == TileType.TILE_WALL || dungeonGrid[x0,y0].Type == TileType.TILE_ROCK)
                    {
                        break;
                    }

                    if (x0 == (int)point.X && y0 == (int)point.Y) break;
                    e2 = 2 * err;
                    if (e2 >= dy) { err += dy; x0 += sx; } /* e_xy+e_x > 0 */
                    if (e2 <= dx) { err += dx; y0 += sy; } /* e_xy+e_y < 0 */
                }


            }
        }
Ejemplo n.º 28
0
        public static bool SpawnTestEnemyNPC(StateSpaceComponents spaceComponents, DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions, int cellSize, List<Vector2> freeTiles)
        {
            Guid id = spaceComponents.CreateEntity();
            spaceComponents.Entities.Where(x => x.Id == id).First().ComponentFlags = ComponentMasks.Drawable | ComponentMasks.CombatReadyAI | ComponentMasks.AIView | ComponentMasks.InventoryPickup;

            int tileIndex = spaceComponents.random.Next(0, freeTiles.Count);
            spaceComponents.PositionComponents[id] = new PositionComponent() { Position = freeTiles[tileIndex] };
            freeTiles.RemoveAt(tileIndex);
            spaceComponents.DisplayComponents[id] = new DisplayComponent()
            {
                Color = Colors.Monsters.Red, //Color.DarkRed,
                Origin = Vector2.Zero,
                Rotation = 0f,
                Scale = 1f,
                SpriteEffect = SpriteEffects.None,
                SpriteSource = new Rectangle(0 * cellSize, 0 * cellSize, cellSize, cellSize),
                Symbol = "t",
                SymbolColor = Color.White,
                Opacity = 1f
            };
            spaceComponents.SkillLevelsComponents[id] = new SkillLevelsComponent() { CurrentHealth = 25, DieNumber = 1, Health = 25, Defense = 1, Accuracy = 100, Wealth = 25, MinimumDamage = 1, MaximumDamage = 2 };
            spaceComponents.CollisionComponents[id] = new CollisionComponent() { Solid = true, CollidedObjects = new List<Guid>() };
            spaceComponents.NameComponents[id] = new NameComponent() { Name = "TEST ENEMY NPC", Description = "It seems harmless enough.  How dangerous could a red square be?" };
            spaceComponents.AIAlignmentComponents[id] = new AIAlignment() { Alignment = AIAlignments.ALIGNMENT_HOSTILE };
            spaceComponents.AICombatComponents[id] = new AICombat() { AttackType = AIAttackTypes.ATTACK_TYPE_NORMAL, FleesWhenLowHealth = true };
            spaceComponents.AIStateComponents[id] = new AIState() { State = AIStates.STATE_SLEEPING };
            spaceComponents.AIFieldOfViewComponents[id] = new AIFieldOfView() { DrawField = false, Opacity = .3f, radius = 2, SeenTiles = new List<Vector2>(), Color = FOVColors.Sleeping };
            spaceComponents.AISleepComponents[id] = new AISleep() { ChanceToWake = 15, FOVRadiusChangeOnWake = 2 };
            spaceComponents.AIRoamComponents[id] = new AIRoam() { ChanceToDetect = 25 };
            spaceComponents.AIFleeComponents[id] = new AIFlee() { DoesFlee = true, FleeAtHealthPercent = 25, FleeUntilHealthPercent = 30 };
            spaceComponents.EntityMessageComponents[id] = new EntityMessageComponent()
            {
                AttackNPCMessages = new string[]
                {
                        "{0} swings at the {1}",
                        "{0} applies fury to the {1}'s face",
                        "{0} attempts brute force against {1}",
                        "{0} uses a walking attack fearlessly at {1}"
                },
                AttackPlayerMessages = new string[]
                {
                        "{0} tests a mighty attack on you",
                        "The {0} glitches out against you",
                        "Watch out! {0} tries to attack you"
                },
                NormalDodgeMessages = new string[]
                {
                        " but the attack missed!",
                        " and the creature dodges the attack.",
                        " but the creature's defense protects it.",
                        " and the defense test is a success.",
                        " but the combat system test makes the attack miss."
                },
                StreakDodgeMessages = new string[]
                {
                        " and, as always, the attack misses.",
                        " and it misses again!",
                        " and shows how advanced its AI is by dodging again.",
                        " and taunts at the attack. \"Give up!\""
                },
                NormalTakeDamageMessages = new string[]
                {
                        " and it takes {0} damage.",
                        " and it cries out, {0} health weaker.",
                        " and it glitches out, health dropping by {0}.",
                        " for {0} damage."
                },
                BrokenDodgeStreakTakeDamageMessages = new string[]
                {
                        " and against all odds deals {0} damage!",
                        " and the cocky creature allows {0} damage to go through!",
                        ", breaking impossible odds, landing {0} damage!!",
                        " and the test is broken! It takes {0} damage!"
                }
            };
            spaceComponents.InventoryComponents[id] = new InventoryComponent() { Artifacts = new List<Guid>(), Consumables = new List<Guid>(), MaxArtifacts = 0, MaxConsumables = 0 };

            return true;
        }
Ejemplo n.º 29
0
        public static bool CrazedMiner(StateSpaceComponents spaceComponents, DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions, int cellSize, List<Vector2> freeTiles)
        {
            Guid id = spaceComponents.CreateEntity();
            spaceComponents.Entities.Where(x => x.Id == id).First().ComponentFlags = ComponentMasks.Drawable | ComponentMasks.CombatReadyAI | ComponentMasks.AIView | ComponentMasks.InventoryPickup;

            int tileIndex = spaceComponents.random.Next(0, freeTiles.Count);
            spaceComponents.PositionComponents[id] = new PositionComponent() { Position = freeTiles[tileIndex] };
            freeTiles.RemoveAt(tileIndex);
            spaceComponents.DisplayComponents[id] = new DisplayComponent()
            {
                Color = Color.MediumPurple, // Color.DarkRed,
                Origin = Vector2.Zero,
                Rotation = 0f,
                Scale = 1f,
                SpriteEffect = SpriteEffects.None,
                SpriteSource = new Rectangle(0 * cellSize, 0 * cellSize, cellSize, cellSize),
                Symbol = "C",
                SymbolColor = Color.White,
                Opacity = 1f
            };
            spaceComponents.SkillLevelsComponents[id] = new SkillLevelsComponent() { CurrentHealth = 25, DieNumber = 1, Health = 25, Defense = 4, Accuracy = 80, Wealth = 100, MinimumDamage = 2, MaximumDamage = 7 };
            spaceComponents.CollisionComponents[id] = new CollisionComponent() { Solid = true, CollidedObjects = new List<Guid>() };
            spaceComponents.NameComponents[id] = new NameComponent() { Name = "CRAZED MINER", Description = "An injured, shambling husk of a man.  He clutches a pickaxe in his hands and precious gems are stuffed in his pockets.  It looks like greed got the better of his mind long ago." };
            spaceComponents.AIAlignmentComponents[id] = new AIAlignment() { Alignment = AIAlignments.ALIGNMENT_HOSTILE };
            spaceComponents.AICombatComponents[id] = new AICombat() { AttackType = AIAttackTypes.ATTACK_TYPE_NORMAL, FleesWhenLowHealth = true };
            spaceComponents.AIStateComponents[id] = new AIState() { State = AIStates.STATE_ROAMING };
            spaceComponents.AIFieldOfViewComponents[id] = new AIFieldOfView() { DrawField = false, Opacity = .3f, radius = 3, SeenTiles = new List<Vector2>(), Color = FOVColors.Roaming };
            spaceComponents.AISleepComponents[id] = new AISleep() { ChanceToWake = 10, FOVRadiusChangeOnWake = 1 };
            spaceComponents.AIRoamComponents[id] = new AIRoam() { ChanceToDetect = 25 };
            spaceComponents.AIFleeComponents[id] = new AIFlee() { DoesFlee = false, FleeAtHealthPercent = 25, FleeUntilHealthPercent = 30 };
            spaceComponents.EntityMessageComponents[id] = new EntityMessageComponent()
            {
                AttackNPCMessages = new string[]
                {
                        "{0} swings its pickaxe at {1}",
                        "{0} shambles toward {1}",
                        "{0} claws madly at {1}",
                },
                AttackPlayerMessages = new string[]
                {
                        "{0} swings its pickaxe at you",
                        "{0} shambles toward you",
                        "{0} claws madly at you",
                },
                NormalDodgeMessages = new string[]
                {
                        " but the attack missed!",
                        " and the creature dodges the attack.",
                        " but the creature's defense protects it.",
                },
                StreakDodgeMessages = new string[]
                {
                        " and, as always, the attack misses.",
                        " and it misses again!",
                        " and it laughs madly.",
                        " and taunts at the attack. \"Give up!\""
                },
                NormalTakeDamageMessages = new string[]
                {
                        " and it takes {0} damage.",
                        " and it cries out, {0} health weaker.",
                        " for {0} damage."
                },
                BrokenDodgeStreakTakeDamageMessages = new string[]
                {
                        " and against all odds deals {0} damage!",
                        " and the cocky creature allows {0} damage to go through!",
                        ", breaking impossible odds, landing {0} damage!!",
                }
            };
            spaceComponents.InventoryComponents[id] = new InventoryComponent() { Artifacts = new List<Guid>(), Consumables = new List<Guid>(), MaxArtifacts = 0, MaxConsumables = 0 };

            return true;
        }
Ejemplo n.º 30
0
        public static void ApplyBurnDamage(StateSpaceComponents spaceComponents, DungeonTile[,] dungeonGrid)
        {
            if (spaceComponents.PlayerComponent.PlayerTookTurn)
            {
                Entity player = spaceComponents.Entities.Where(z => (z.ComponentFlags & Component.COMPONENT_PLAYER) == Component.COMPONENT_PLAYER).FirstOrDefault();
                foreach (Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.BurningStatus) == ComponentMasks.BurningStatus).Select(x => x.Id))
                {
                    bool isPlayer = player.Id == id;
                    bool extinguished = false;
                    //If the entity is in water, extinguish the burning effect instead.
                    if(spaceComponents.PositionComponents.ContainsKey(id))
                    {
                        PositionComponent pos = spaceComponents.PositionComponents[id];
                        if(dungeonGrid[(int)pos.Position.X, (int)pos.Position.Y].Type == TileType.TILE_WATER)
                        {
                            spaceComponents.Entities.Where(x => x.Id == id).First().ComponentFlags &= ~Component.COMPONENT_BURNING;
                            spaceComponents.DelayedActions.Add(new Action(() =>
                            {
                                spaceComponents.BurningComponents.Remove(id);
                            }));
                            if(isPlayer)
                            {
                                spaceComponents.GameMessageComponent.GameMessages.Add(new Tuple<Microsoft.Xna.Framework.Color, string>(Colors.Messages.StatusChange, string.Format("[TURN " + spaceComponents.GameplayInfoComponent.StepsTaken + "] " + "You extinguish yourself in the water.")));
                            }
                            extinguished = true;
                        }
                    }
                    if (!extinguished && spaceComponents.BurningComponents.ContainsKey(id))
                    {
                        BurningComponent burning = spaceComponents.BurningComponents[id];
                        burning.TurnsLeft -= 1;
                        SkillLevelsComponent skills = spaceComponents.SkillLevelsComponents[id];
                        int damage = spaceComponents.random.Next(burning.MinDamage, burning.MaxDamage + 1);
                        skills.CurrentHealth -= damage;
                        spaceComponents.SkillLevelsComponents[id] = skills;
                        spaceComponents.BurningComponents[id] = burning;

                        //Handle Death
                        if (skills.CurrentHealth <= 0)
                        {
                            Entity deadEntity = spaceComponents.Entities.Where(x => x.Id == id).FirstOrDefault();
                            if(deadEntity != null)
                            {
                                InventorySystem.DropWholeInventory(spaceComponents, deadEntity.Id, spaceComponents.PositionComponents[deadEntity.Id].Position);
                                deadEntity.ComponentFlags &= ~Component.COMPONENT_POSITION;
                            }
                            spaceComponents.EntitiesToDelete.Add(id);
                            if (isPlayer)
                            {
                                //SCORE RECORD
                                spaceComponents.GameMessageComponent.GameMessages.Add(new Tuple<Microsoft.Xna.Framework.Color, string>(Colors.Messages.Special, string.Format("[TURN " + spaceComponents.GameplayInfoComponent.StepsTaken + "] " + Messages.Deaths.FirePlayer, spaceComponents.NameComponents[id].Name)));
                            }
                            else
                            {
                                spaceComponents.GameMessageComponent.GameMessages.Add(new Tuple<Microsoft.Xna.Framework.Color, string>(Colors.Messages.Special, string.Format("[TURN " + spaceComponents.GameplayInfoComponent.StepsTaken + "] " + Messages.Deaths.Fire, spaceComponents.NameComponents[id].Name)));
                                GameplayInfoComponent gameInfo = spaceComponents.GameplayInfoComponent;
                                gameInfo.Kills += 1;
                                spaceComponents.GameplayInfoComponent = gameInfo;
                            }
                        }

                        //Handle Burning running out
                        if (burning.TurnsLeft <= 0)
                        {
                            spaceComponents.Entities.Where(x => x.Id == id).First().ComponentFlags &= ~Component.COMPONENT_BURNING;
                            spaceComponents.DelayedActions.Add(new Action(() =>
                            {
                                spaceComponents.BurningComponents.Remove(id);
                            }));
                        }
                    }
                    

                }
            }
        }
Ejemplo n.º 31
0
        public static bool SpawnWildVines(StateSpaceComponents spaceComponents, DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions, int cellSize, List<Vector2> freeTiles)
        {
            Guid id = spaceComponents.CreateEntity();
            spaceComponents.Entities.Where(x => x.Id == id).First().ComponentFlags = ComponentMasks.Drawable | ComponentMasks.CombatReadyAI | ComponentMasks.AIView | ComponentMasks.InventoryPickup;

            int tileIndex = spaceComponents.random.Next(0, freeTiles.Count);
            spaceComponents.PositionComponents[id] = new PositionComponent() { Position = freeTiles[tileIndex] };
            freeTiles.RemoveAt(tileIndex);
            spaceComponents.DisplayComponents[id] = new DisplayComponent()
            {
                Color = Colors.Monsters.Red, // Color.DarkRed,
                Origin = Vector2.Zero,
                Rotation = 0f,
                Scale = 1f,
                SpriteEffect = SpriteEffects.None,
                SpriteSource = new Rectangle(0 * cellSize, 0 * cellSize, cellSize, cellSize),
                Symbol = "W",
                SymbolColor = Color.White,
                Opacity = 1f
            };
            spaceComponents.SkillLevelsComponents[id] = new SkillLevelsComponent() { CurrentHealth = 45, DieNumber = 2, Health = 45, Defense = 10, Accuracy = 135, Wealth = 25, MinimumDamage = 5, MaximumDamage = 14 };
            spaceComponents.CollisionComponents[id] = new CollisionComponent() { Solid = true, CollidedObjects = new List<Guid>() };
            spaceComponents.NameComponents[id] = new NameComponent() { Name = "WILD ROOTS", Description = "Imported fresh from Japan." };
            spaceComponents.AIAlignmentComponents[id] = new AIAlignment() { Alignment = AIAlignments.ALIGNMENT_HOSTILE };
            spaceComponents.AICombatComponents[id] = new AICombat() { AttackType = AIAttackTypes.ATTACK_TYPE_NORMAL, FleesWhenLowHealth = true };
            spaceComponents.AIStateComponents[id] = new AIState() { State = AIStates.STATE_ROAMING };
            spaceComponents.AIFieldOfViewComponents[id] = new AIFieldOfView() { DrawField = false, Opacity = .3f, radius = 5, SeenTiles = new List<Vector2>(), Color = FOVColors.Roaming };
            spaceComponents.AISleepComponents[id] = new AISleep() { ChanceToWake = 10, FOVRadiusChangeOnWake = 2 };
            spaceComponents.AIRoamComponents[id] = new AIRoam() { ChanceToDetect = 40 };
            spaceComponents.AIFleeComponents[id] = new AIFlee() { DoesFlee = false, FleeAtHealthPercent = 25, FleeUntilHealthPercent = 30 };
            spaceComponents.EntityMessageComponents[id] = new EntityMessageComponent()
            {
                AttackNPCMessages = new string[]
                {
                        "{0} swings its tentacles toward {1}",
                        "{0} applies fury to the {1}'s face",
                        "{0} attempts brute force against {1}",
                        "{0} uses a walking attack fearlessly at {1}"
                },
                AttackPlayerMessages = new string[]
                {
                        "{0} wiggles its tentacles at you",
                        "The {0} swipes at you multiple times",
                        "Gross.. the tentacles of {0} smear around you"
                },
                NormalDodgeMessages = new string[]
                {
                        " but the attack missed!",
                        " and the creature dodges the attack.",
                        " but the creature's defense protects it.",
                        " but it uses its tentacle vines to protect itself.",
                        " but the vines are too thick for the attack!"
                },
                StreakDodgeMessages = new string[]
                {
                        " and, as always, the attack misses.",
                        " and it misses again!",
                        " and it slithers around, cackling",
                        " and taunts at the attack. \"Give up!\""
                },
                NormalTakeDamageMessages = new string[]
                {
                        " and it takes {0} damage.",
                        " and it cries out, {0} health weaker.",
                        " and takes {0}, some of its vines dropping dead",
                        " for {0} damage."
                },
                BrokenDodgeStreakTakeDamageMessages = new string[]
                {
                        " and against all odds deals {0} damage!",
                        " and the cocky creature allows {0} damage to go through!",
                        ", breaking impossible odds, landing {0} damage!!",
                        " and the test is broken! It takes {0} damage!"
                }
            };
            spaceComponents.InventoryComponents[id] = new InventoryComponent() { Artifacts = new List<Guid>(), Consumables = new List<Guid>(), MaxArtifacts = 0, MaxConsumables = 0 };

            return true;
        }