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);
     }
 }
示例#2
0
        private static void CreateObserver(StateSpaceComponents spaceComponents, PositionComponent position)
        {
            Guid id = spaceComponents.CreateEntity();

            spaceComponents.Entities.Where(x => x.Id == id).First().ComponentFlags = ComponentMasks.Observer;
            spaceComponents.PositionComponents[id]  = position;
            spaceComponents.CollisionComponents[id] = new CollisionComponent()
            {
                Solid = false, CollidedObjects = new List <Guid>()
            };
            spaceComponents.InputMovementComponents[id] = new InputMovementComponent()
            {
                InitialWait = .3f, IsButtonDown = false, LastKeyPressed = Keys.None, TimeIntervalBetweenMovements = .1f, TimeSinceLastMovement = 0f, TotalTimeButtonDown = 0f
            };
            spaceComponents.DisplayComponents[id] = new DisplayComponent()
            {
                Color        = Colors.Messages.Special,
                Rotation     = 0f,
                Origin       = Vector2.Zero,
                Scale        = 1f,
                SpriteEffect = SpriteEffects.None,
                SpriteSource = new Rectangle(0 * DevConstants.Grid.CellSize, 0 * DevConstants.Grid.CellSize, DevConstants.Grid.CellSize, DevConstants.Grid.CellSize),
                AlwaysDraw   = true,
                Opacity      = .6f
            };
        }
        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);
            }
        }
示例#4
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);
     }
 }
 public void LoadLevel(ContentManager content, GraphicsDeviceManager graphics, Camera camera, StateComponents stateComponents, bool createEntities = true)
 {
     this.stateComponents = stateComponents;
     if (stateComponents.StateSpaceComponents != null)
     {
         this.stateSpaceComponents = stateComponents.StateSpaceComponents;
     }
     sprites                 = content.Load <Texture2D>(DevConstants.Graphics.SpriteSheet);
     dungeonSprites          = content.Load <Texture2D>(dungeonSpriteFile);
     messageFont             = content.Load <SpriteFont>(DevConstants.Graphics.MessageFont);
     asciiDisplay            = content.Load <SpriteFont>(DevConstants.Graphics.AsciiFont);
     optionFont              = content.Load <SpriteFont>(DevConstants.Graphics.OptionFont);
     UI                      = content.Load <Texture2D>(DevConstants.Graphics.UISheet);
     camera.AttachedToPlayer = true;
     if (createEntities)
     {
         LevelChangeSystem.CreateGameplayInfo(stateComponents, stateSpaceComponents);
         DungeonCreationSystem.TallGrassGeneration(ref dungeonGrid, dungeonDimensions, stateSpaceComponents.random, freeTiles, stateSpaceComponents);
         DungeonCreationSystem.WaterGeneration(ref dungeonGrid, dungeonDimensions, stateSpaceComponents.random, freeTiles, stateSpaceComponents, waterTiles);
         DungeonCreationSystem.CreateDungeonDrops(stateSpaceComponents, dungeonGrid, dungeonDimensions, freeTiles);
         DungeonCreationSystem.CreateDungeonMonsters(stateSpaceComponents, dungeonGrid, dungeonDimensions, DevConstants.Grid.CellSize, freeTiles);
         LevelChangeSystem.LoadPlayerSkillset(stateComponents, stateSpaceComponents);
         LevelChangeSystem.CreateMessageLog(stateSpaceComponents);
     }
     mapToPlayer = new DijkstraMapTile[(int)dungeonDimensions.X, (int)dungeonDimensions.Y];
 }
        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);
            }
        }
示例#7
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);
         }
     }
 }
示例#8
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);
                }
            }
        }
示例#9
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);
                        }
                    }
                }
            }
        }
示例#10
0
        public static void SetRandomGlobalMessage(StateSpaceComponents spaceComponents, string[] messageList)
        {
            GameMessageComponent newMessage = spaceComponents.GameMessageComponent;

            newMessage.GlobalMessage             = messageList[spaceComponents.random.Next(0, messageList.Count())];
            spaceComponents.GameMessageComponent = newMessage;
        }
示例#11
0
        public static bool CreateOrDestroyObserver(StateSpaceComponents spaceComponents)
        {
            //Get the first player's position
            PositionComponent pos = spaceComponents.PositionComponents[spaceComponents.Entities.Where(c => (c.ComponentFlags & ComponentMasks.Player) == ComponentMasks.Player).First().Id];

            IEnumerable<Guid> observers = spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Observer) == ComponentMasks.Observer).Select(c => c.Id);
            if (observers.Count() > 0)
            {
                foreach (Guid observer in observers)
                {
                    spaceComponents.EntitiesToDelete.Add(observer);
                }
                foreach (Entity player in spaceComponents.Entities.Where(x => (x.ComponentFlags & Component.COMPONENT_PLAYER) == Component.COMPONENT_PLAYER))
                {
                    player.ComponentFlags |= Component.COMPONENT_INPUTMOVEMENT;
                }
                return false; //Do not stop movement of other inputs
            }
            else
            {
                foreach (Entity player in spaceComponents.Entities.Where(x => (x.ComponentFlags & Component.COMPONENT_PLAYER) == Component.COMPONENT_PLAYER))
                {
                    player.ComponentFlags &= ~Component.COMPONENT_INPUTMOVEMENT;
                }
                spaceComponents.DelayedActions.Add(new Action(() =>
                {
                    CreateObserver(spaceComponents, pos);
                }));
                return true; //Do stop movement of other inputs
            }
        }
示例#12
0
        public static void DrawAIFieldOfViews(StateSpaceComponents spaceComponents, Camera camera, SpriteBatch spriteBatch, Texture2D rectangleTexture, int cellSize, DungeonTile[,] dungeonGrid)
        {
            Matrix cameraMatrix = camera.GetMatrix();

            foreach (Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.AIView) == ComponentMasks.AIView).Select(x => x.Id))
            {
                AIFieldOfView fovInfo = spaceComponents.AIFieldOfViewComponents[id];
                if (fovInfo.DrawField)
                {
                    foreach (Vector2 tilePosition in fovInfo.SeenTiles)
                    {
                        Vector2 tile = new Vector2((int)tilePosition.X * cellSize, (int)tilePosition.Y * cellSize);

                        Vector2   bottomRight  = Vector2.Transform(new Vector2((tile.X + cellSize), (tile.Y + cellSize)), cameraMatrix);
                        Vector2   topLeft      = Vector2.Transform(tile, cameraMatrix);
                        Rectangle cameraBounds = new Rectangle((int)topLeft.X, (int)topLeft.Y, (int)bottomRight.X - (int)topLeft.X, (int)bottomRight.Y - (int)topLeft.Y);

                        if (dungeonGrid[(int)tilePosition.X, (int)tilePosition.Y].InRange && camera.IsInView(cameraMatrix, cameraBounds))
                        {
                            if (spaceComponents.AlternateFOVColorChangeComponents.ContainsKey(id))
                            {
                                AlternateFOVColorChangeComponent altColorInfo = spaceComponents.AlternateFOVColorChangeComponents[id];
                                spriteBatch.Draw(rectangleTexture, position: tile, color: Color.Lerp(fovInfo.Color, altColorInfo.AlternateColor, altColorInfo.Seconds / altColorInfo.SwitchAtSeconds) * fovInfo.Opacity, origin: new Vector2(DevConstants.Grid.TileBorderSize, DevConstants.Grid.TileBorderSize));
                            }
                            else
                            {
                                //origin is 4,4 because the tile texture is 40x40 and the grid is 32x32.  If size of grid changes, change this -- and then don't hardcode it anymore!!!
                                spriteBatch.Draw(rectangleTexture, position: tile, color: fovInfo.Color * fovInfo.Opacity, origin: new Vector2(DevConstants.Grid.TileBorderSize, DevConstants.Grid.TileBorderSize));
                            }
                        }
                    }
                }
            }
        }
示例#13
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);
                        }
                    }
                }
            }
        }
示例#14
0
        public static SkillLevelsComponent ApplyStatModifications(StateSpaceComponents spaceComponents, Guid entity, SkillLevelsComponent originalStats)
        {
            SkillLevelsComponent newStats = originalStats;

            //See if the entity has an inventory to check for artifact modifications
            if (spaceComponents.InventoryComponents.ContainsKey(entity))
            {
                InventoryComponent entityInventory = spaceComponents.InventoryComponents[entity];
                //For each artifact in the entity' inventory, look for the statmodificationcomponent, and modify stats accordingly.
                foreach (Guid id in  entityInventory.Artifacts)
                {
                    Entity inventoryItem = spaceComponents.Entities.Where(x => x.Id == id).FirstOrDefault();
                    if (inventoryItem != null && (inventoryItem.ComponentFlags & ComponentMasks.Artifact) == ComponentMasks.Artifact)
                    {
                        StatModificationComponent statsMods = spaceComponents.StatModificationComponents[id];
                        newStats.Accuracy      = (newStats.Accuracy + statsMods.AccuracyChange < 0) ? 0 : newStats.Accuracy + statsMods.AccuracyChange;
                        newStats.Defense       = (newStats.Defense + statsMods.DefenseChange < 0) ? 0 : newStats.Defense + statsMods.DefenseChange;
                        newStats.DieNumber     = (newStats.DieNumber + statsMods.DieNumberChange < 1) ? 1 : newStats.DieNumber + statsMods.DieNumberChange;
                        newStats.Health        = (newStats.Health + statsMods.HealthChange < 0) ? 0 : newStats.Health + statsMods.HealthChange;
                        newStats.MaximumDamage = (newStats.MaximumDamage + statsMods.MaximumDamageChange < 1) ? 1 : newStats.MaximumDamage + statsMods.MaximumDamageChange;
                        newStats.MinimumDamage = (newStats.MinimumDamage + statsMods.MinimumDamageChange < 1) ? 1 : newStats.MinimumDamage + statsMods.MinimumDamageChange;
                    }
                }
            }

            return(newStats);
        }
示例#15
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);
        }
示例#16
0
        public static bool CreateOrDestroyObserver(StateSpaceComponents spaceComponents)
        {
            //Get the first player's position
            PositionComponent pos = spaceComponents.PositionComponents[spaceComponents.Entities.Where(c => (c.ComponentFlags & ComponentMasks.Player) == ComponentMasks.Player).First().Id];

            IEnumerable <Guid> observers = spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Observer) == ComponentMasks.Observer).Select(c => c.Id);

            if (observers.Count() > 0)
            {
                foreach (Guid observer in observers)
                {
                    spaceComponents.EntitiesToDelete.Add(observer);
                }
                foreach (Entity player in spaceComponents.Entities.Where(x => (x.ComponentFlags & Component.COMPONENT_PLAYER) == Component.COMPONENT_PLAYER))
                {
                    player.ComponentFlags |= Component.COMPONENT_INPUTMOVEMENT;
                }
                return(false); //Do not stop movement of other inputs
            }
            else
            {
                foreach (Entity player in spaceComponents.Entities.Where(x => (x.ComponentFlags & Component.COMPONENT_PLAYER) == Component.COMPONENT_PLAYER))
                {
                    player.ComponentFlags &= ~Component.COMPONENT_INPUTMOVEMENT;
                }
                spaceComponents.DelayedActions.Add(new Action(() =>
                {
                    CreateObserver(spaceComponents, pos);
                }));
                return(true); //Do stop movement of other inputs
            }
        }
示例#17
0
 public static void RetainNecessaryComponents(StateComponents stateComponents, StateSpaceComponents spaceComponents)
 {
     //Transfer components, then delete all AI-related components and all item related components that aren't in the players' inventories.
     stateComponents.StateSpaceComponents = spaceComponents;
     List<Guid> itemsToKeep = new List<Guid>();
     foreach(Guid id in stateComponents.StateSpaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.CombatReadyAI) == ComponentMasks.CombatReadyAI).Select(x => x.Id))
     {
         //Change this to only hostile AI when allies need to be implemented.
         stateComponents.StateSpaceComponents.EntitiesToDelete.Add(id);
     }
     foreach (Guid id in stateComponents.StateSpaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.PickupItem) == ComponentMasks.PickupItem).Select(x => x.Id))
     {
         foreach(Guid player in spaceComponents.Entities.Where(x => (x.ComponentFlags & Component.COMPONENT_PLAYER) == Component.COMPONENT_PLAYER).Select(x => x.Id))
         {
             InventoryComponent inventory = stateComponents.StateSpaceComponents.InventoryComponents[player];
             if(!inventory.Artifacts.Contains(id) && !inventory.Consumables.Contains(id))
             {
                 stateComponents.StateSpaceComponents.EntitiesToDelete.Add(id);
                 break;
             }
             else
             {
                 itemsToKeep.Add(id);
             }
         }
     }
     foreach(Guid id in stateComponents.StateSpaceComponents.Entities.Where(x => (x.ComponentFlags & Component.COMPONENT_PLAYER) != Component.COMPONENT_PLAYER).Select(x => x.Id))
     {
         if(!itemsToKeep.Contains(id))
         {
             stateComponents.StateSpaceComponents.EntitiesToDelete.Add(id);
         }
     }
 }
示例#18
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);
                 }
             }
         }
     }));
 }
示例#19
0
 public static bool TestUse(StateSpaceComponents spaceComponents, DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions, Guid item, Guid user, Vector2 targetPosition)
 {
     spaceComponents.GameMessageComponent.GameMessages.Add(new Tuple <Color, string>(Colors.Messages.StatusChange, "You use this item and something happens."));
     spaceComponents.DelayedActions.Add(new Action(() =>
     {
         Guid id = spaceComponents.CreateEntity();
         spaceComponents.Entities.Where(c => c.Id == id).First().ComponentFlags = ComponentMasks.DrawableOutline | Component.COMPONENT_TIME_TO_LIVE | ComponentMasks.GlowingOutline;
         spaceComponents.PositionComponents[id] = new PositionComponent()
         {
             Position = targetPosition
         };
         spaceComponents.OutlineComponents[id] = new OutlineComponent()
         {
             Color = Color.CornflowerBlue, Opacity = .8f
         };
         spaceComponents.TimeToLiveComponents[id] = new TimeToLiveComponent()
         {
             CurrentSecondsAlive = 0f, SecondsToLive = 4f
         };
         spaceComponents.SecondaryOutlineComponents[id] = new SecondaryOutlineComponent()
         {
             AlternateColor = Color.Red, Seconds = 0f, SwitchAtSeconds = .6f
         };
     }));
     return(true);
 }
示例#20
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);
        }
示例#21
0
        private static void AITryToWake(Guid entity, StateSpaceComponents spaceComponents)
        {
            AIFieldOfView entityFOV       = spaceComponents.AIFieldOfViewComponents[entity];
            AIAlignment   entityAlignment = spaceComponents.AIAlignmentComponents[entity];
            AISleep       entitySleep     = spaceComponents.AISleepComponents[entity];
            AIState       entityState     = spaceComponents.AIStateComponents[entity];

            foreach (Guid id in spaceComponents.Entities.Where(x => ((x.ComponentFlags & Component.COMPONENT_PLAYER) == Component.COMPONENT_PLAYER) ||
                                                               ((x.ComponentFlags & ComponentMasks.CombatReadyAI) == ComponentMasks.CombatReadyAI)).Select(x => x.Id))
            {
                PositionComponent position  = spaceComponents.PositionComponents[id];
                AIAlignment       alignment = spaceComponents.AIAlignmentComponents[id];
                if (entityFOV.SeenTiles.Contains(position.Position) && entityAlignment.Alignment != alignment.Alignment && spaceComponents.random.Next(1, 101) <= entitySleep.ChanceToWake)
                {
                    entityState.State = AIStates.STATE_ROAMING;
                    entityFOV.radius += entitySleep.FOVRadiusChangeOnWake;
                    entityFOV.Color   = FOVColors.Roaming;
                    spaceComponents.AIStateComponents[entity]       = entityState;
                    spaceComponents.AIFieldOfViewComponents[entity] = entityFOV;
                    spaceComponents.GameMessageComponent.GameMessages.Add(new Tuple <Color, string>(Colors.Messages.StatusChange,
                                                                                                    string.Format("[TURN " + spaceComponents.GameplayInfoComponent.StepsTaken + "] " + Messages.AwokenBySight[spaceComponents.random.Next(0, Messages.AwokenBySight.Count())], spaceComponents.NameComponents[entity].Name)));
                    return;
                }
            }
        }
示例#22
0
 public static void RetainPlayerStatistics(StateComponents stateComponents, StateSpaceComponents spaceComponents)
 {
     Guid id = spaceComponents.Entities.Where(x => (x.ComponentFlags & Component.COMPONENT_PLAYER) == Component.COMPONENT_PLAYER).Select(x => x.Id).First();
     SkillLevelsComponent skills = spaceComponents.SkillLevelsComponents[id];
     GameplayInfoComponent gameInfo = spaceComponents.GameplayInfoComponent;
     stateComponents.GameplayInfo = gameInfo;
     stateComponents.PlayerSkillLevels = skills;
 }
示例#23
0
 public static void ResetCollision(StateSpaceComponents spaceComponents)
 {
     foreach (Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Collidable) == ComponentMasks.Collidable).Select(x => x.Id))
     {
         spaceComponents.CollisionComponents[id].CollidedObjects.Clear();
     }
     spaceComponents.GlobalCollisionComponent = new GlobalCollisionComponent() { EntitiesThatCollided = new List<Guid>() };
 }
示例#24
0
 public static void DrawDungeonEntities(StateSpaceComponents spaceComponents, Camera camera, SpriteBatch spriteBatch, int cellSize)
 {
     IEnumerable<Guid> drawableEntities = spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Drawable) == ComponentMasks.Drawable).Select(x => x.Id);
     foreach(Guid id in drawableEntities)
     {
         spriteBatch.Draw(spaceComponents.DisplayComponents[id].Texture, new Vector2(spaceComponents.PositionComponents[id].Position.X * cellSize, spaceComponents.PositionComponents[id].Position.Y * cellSize), spaceComponents.DisplayComponents[id].Color);
     }
 }
示例#25
0
        public static void DrawDungeonEntities(StateSpaceComponents spaceComponents, Camera camera, SpriteBatch spriteBatch, int cellSize)
        {
            IEnumerable <Guid> drawableEntities = spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Drawable) == ComponentMasks.Drawable).Select(x => x.Id);

            foreach (Guid id in drawableEntities)
            {
                spriteBatch.Draw(spaceComponents.DisplayComponents[id].Texture, new Vector2(spaceComponents.PositionComponents[id].Position.X * cellSize, spaceComponents.PositionComponents[id].Position.Y * cellSize), spaceComponents.DisplayComponents[id].Color);
            }
        }
 public RandomlyGeneratedStateSpace(IGenerationAlgorithm dungeonGeneration, int worldMin, int worldMax)
 {
     stateSpaceComponents = new StateSpaceComponents();
     freeTiles            = new List <Vector2>();
     waterTiles           = new List <Vector2>();
     dungeonDimensions    = dungeonGeneration.GenerateDungeon(ref dungeonGrid, worldMin, worldMax, stateSpaceComponents.random, freeTiles);
     dungeonSpriteFile    = dungeonGeneration.GetDungeonSpritesheetFileName();
     dungeonColorInfo     = dungeonGeneration.GetColorInfo();
 }
示例#27
0
 public static void UpdateIndefinitelyMovingEntities(StateSpaceComponents spaceComponents, GameTime gameTime)
 {
     foreach (Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.IndefiniteMovingEntity) == ComponentMasks.IndefiniteMovingEntity).Select(x => x.Id))
     {
         PositionComponent position = spaceComponents.PositionComponents[id];
         position.Position += spaceComponents.DirectionComponents[id].Direction * spaceComponents.VelocityComponents[id].Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
         spaceComponents.PositionComponents[id] = position;
     }
 }
示例#28
0
        public static void RetainPlayerStatistics(StateComponents stateComponents, StateSpaceComponents spaceComponents)
        {
            Guid id = spaceComponents.Entities.Where(x => (x.ComponentFlags & Component.COMPONENT_PLAYER) == Component.COMPONENT_PLAYER).Select(x => x.Id).First();
            SkillLevelsComponent  skills   = spaceComponents.SkillLevelsComponents[id];
            GameplayInfoComponent gameInfo = spaceComponents.GameplayInfoComponent;

            stateComponents.GameplayInfo      = gameInfo;
            stateComponents.PlayerSkillLevels = skills;
        }
示例#29
0
 public static void UpdateIndefinitelyMovingEntities(StateSpaceComponents spaceComponents, GameTime gameTime)
 {
     foreach (Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.IndefiniteMovingEntity) == ComponentMasks.IndefiniteMovingEntity).Select(x => x.Id))
     {
         PositionComponent position = spaceComponents.PositionComponents[id];
         position.Position += spaceComponents.DirectionComponents[id].Direction * spaceComponents.VelocityComponents[id].Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
         spaceComponents.PositionComponents[id] = position;
     }
 }
示例#30
0
 public static void ApplyBurnEffect(StateSpaceComponents spaceComponents, Guid entity, int turns, int minDamage, int maxDamage)
 {
     Entity burnedEntity = spaceComponents.Entities.Where(x => x.Id == entity).FirstOrDefault();
     if (burnedEntity != null)
     {
         burnedEntity.ComponentFlags |= Component.COMPONENT_BURNING;
         spaceComponents.BurningComponents[entity] = new BurningComponent() { MaxDamage = maxDamage, MinDamage = minDamage, TurnsLeft = turns };
     }
 }
示例#31
0
        public static bool SpawnTestConsumable(StateSpaceComponents spaceComponents, DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions, List <Vector2> freeTiles)
        {
            Guid id = spaceComponents.CreateEntity();

            spaceComponents.Entities.Where(x => x.Id == id).First().ComponentFlags = ComponentMasks.Drawable | ComponentMasks.GlowingOutline | ComponentMasks.PickupItem | ComponentMasks.Consumable;
            spaceComponents.DisplayComponents[id] = new DisplayComponent()
            {
                AlwaysDraw   = false,
                Color        = Colors.Messages.LootPickup,
                Opacity      = 1f,
                Origin       = Vector2.Zero,
                Rotation     = 0f,
                Scale        = 1f,
                SpriteEffect = SpriteEffects.None,
                SpriteSource = new Rectangle(0 * DevConstants.Grid.CellSize, 0 * DevConstants.Grid.CellSize, DevConstants.Grid.CellSize, DevConstants.Grid.CellSize),
                Symbol       = "!",
                SymbolColor  = Color.White
            };
            Vector2 position = freeTiles[spaceComponents.random.Next(0, freeTiles.Count)];

            freeTiles.Remove(position);
            spaceComponents.PositionComponents[id] = new PositionComponent()
            {
                Position = position
            };
            spaceComponents.OutlineComponents[id] = new OutlineComponent()
            {
                Color = Color.Purple, Opacity = 1f
            };
            spaceComponents.SecondaryOutlineComponents[id] = new SecondaryOutlineComponent()
            {
                AlternateColor = Color.LightBlue, Seconds = 0f, SwitchAtSeconds = .75f
            };
            spaceComponents.PickupComponents[id] = new PickupComponent()
            {
                PickupType = ItemType.CONSUMABLE
            };
            spaceComponents.ValueComponents[id] = new ValueComponent()
            {
                Gold = spaceComponents.random.Next(0, 231)
            };
            spaceComponents.NameComponents[id] = new NameComponent()
            {
                Name        = "Test Potion",
                Description = "It is... green."
            };
            spaceComponents.ItemFunctionsComponents[id] = new ItemFunctionsComponent()
            {
                Ranged = false, UseFunctionValue = ItemUseFunctions.TESTUSE, Uses = 3, CostToUse = 20
            };
            spaceComponents.CollisionComponents[id] = new CollisionComponent()
            {
                CollidedObjects = new List <Guid>(), Solid = false
            };
            return(true);
        }
示例#32
0
 public static void ResetCollision(StateSpaceComponents spaceComponents)
 {
     foreach (Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Collidable) == ComponentMasks.Collidable).Select(x => x.Id))
     {
         spaceComponents.CollisionComponents[id].CollidedObjects.Clear();
     }
     spaceComponents.GlobalCollisionComponent = new GlobalCollisionComponent()
     {
         EntitiesThatCollided = new List <Guid>()
     };
 }
示例#33
0
        public static int CalculateMeleeDamage(StateSpaceComponents spaceComponents, SkillLevelsComponent attackingStats, Guid attacker)
        {
            attackingStats = InventorySystem.ApplyStatModifications(spaceComponents, attacker, attackingStats);

            int damage = 0;

            for (int i = 0; i < attackingStats.DieNumber; i++)
            {
                damage += spaceComponents.random.Next((int)(attackingStats.MinimumDamage / attackingStats.DieNumber), (int)(attackingStats.MaximumDamage / attackingStats.DieNumber) + 1);
            }
            return(damage);
        }
示例#34
0
        public static bool SpawnGold(StateSpaceComponents spaceComponents, DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions, List <Vector2> freeTiles)
        {
            Guid id = spaceComponents.CreateEntity();

            spaceComponents.Entities.Where(x => x.Id == id).First().ComponentFlags = ComponentMasks.Drawable | ComponentMasks.GlowingOutline | ComponentMasks.PickupItem;
            spaceComponents.DisplayComponents[id] = new DisplayComponent()
            {
                AlwaysDraw   = false,
                Color        = Colors.Messages.Special,
                Opacity      = 1f,
                Origin       = Vector2.Zero,
                Rotation     = 0f,
                Scale        = 1f,
                SpriteEffect = SpriteEffects.None,
                SpriteSource = new Rectangle(0 * DevConstants.Grid.CellSize, 0 * DevConstants.Grid.CellSize, DevConstants.Grid.CellSize, DevConstants.Grid.CellSize),
                Symbol       = "$",
                SymbolColor  = Color.White
            };
            Vector2 position = freeTiles[spaceComponents.random.Next(0, freeTiles.Count)];

            freeTiles.Remove(position);
            spaceComponents.PositionComponents[id] = new PositionComponent()
            {
                Position = position
            };
            spaceComponents.OutlineComponents[id] = new OutlineComponent()
            {
                Color = Color.Purple, Opacity = 1f
            };
            spaceComponents.SecondaryOutlineComponents[id] = new SecondaryOutlineComponent()
            {
                AlternateColor = Color.LightBlue, Seconds = 0f, SwitchAtSeconds = .75f
            };
            spaceComponents.PickupComponents[id] = new PickupComponent()
            {
                PickupType = ItemType.GOLD
            };
            spaceComponents.ValueComponents[id] = new ValueComponent()
            {
                Gold = spaceComponents.random.Next(0, 231)
            };
            spaceComponents.NameComponents[id] = new NameComponent()
            {
                Name        = "Gold",
                Description = "Some people try and use fancy names for this mass of wealth. Credits, Stardust, Gil... it buys shelter and women all the same."
            };
            spaceComponents.CollisionComponents[id] = new CollisionComponent()
            {
                CollidedObjects = new List <Guid>(), Solid = false
            };
            return(true);
        }
示例#35
0
        public static bool SpawnDownStairway(StateSpaceComponents spaceComponents, DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions, List <Vector2> freeTiles)
        {
            Guid id = spaceComponents.CreateEntity();

            spaceComponents.Entities.Where(x => x.Id == id).First().ComponentFlags = ComponentMasks.Drawable | ComponentMasks.GlowingOutline | ComponentMasks.PickupItem;
            spaceComponents.DisplayComponents[id] = new DisplayComponent()
            {
                AlwaysDraw   = false,
                Color        = Color.Black,
                Opacity      = 1f,
                Origin       = Vector2.Zero,
                Rotation     = 0f,
                Scale        = 1f,
                SpriteEffect = SpriteEffects.None,
                SpriteSource = new Rectangle(0 * DevConstants.Grid.CellSize, 0 * DevConstants.Grid.CellSize, DevConstants.Grid.CellSize, DevConstants.Grid.CellSize),
                Symbol       = "<",
                SymbolColor  = Color.White
            };
            Vector2 position = freeTiles[spaceComponents.random.Next(0, freeTiles.Count)];

            freeTiles.Remove(position);
            spaceComponents.PositionComponents[id] = new PositionComponent()
            {
                Position = position
            };
            spaceComponents.OutlineComponents[id] = new OutlineComponent()
            {
                Color = Color.Goldenrod, Opacity = 1f
            };
            spaceComponents.SecondaryOutlineComponents[id] = new SecondaryOutlineComponent()
            {
                AlternateColor = Color.White, Seconds = 0f, SwitchAtSeconds = 2f
            };
            spaceComponents.PickupComponents[id] = new PickupComponent()
            {
                PickupType = ItemType.DOWNSTAIRS
            };
            spaceComponents.ValueComponents[id] = new ValueComponent()
            {
                Gold = spaceComponents.random.Next(0, 231)
            };
            spaceComponents.NameComponents[id] = new NameComponent()
            {
                Name        = "A Path Downward",
                Description = "A small passageway leading deeper into this cave system.  There's no telling what waits at the other end, but you have a feeling there's no going back once you descend."
            };
            spaceComponents.CollisionComponents[id] = new CollisionComponent()
            {
                CollidedObjects = new List <Guid>(), Solid = true
            };
            return(true);
        }
示例#36
0
        public static void ApplyBurnEffect(StateSpaceComponents spaceComponents, Guid entity, int turns, int minDamage, int maxDamage)
        {
            Entity burnedEntity = spaceComponents.Entities.Where(x => x.Id == entity).FirstOrDefault();

            if (burnedEntity != null)
            {
                burnedEntity.ComponentFlags |= Component.COMPONENT_BURNING;
                spaceComponents.BurningComponents[entity] = new BurningComponent()
                {
                    MaxDamage = maxDamage, MinDamage = minDamage, TurnsLeft = turns
                };
            }
        }
示例#37
0
 public static void UpdateMaxCombo(StateSpaceComponents spaceComponents, Guid entityWithInventory, int hitCombo)
 {
     if (spaceComponents.InventoryComponents.ContainsKey(entityWithInventory))
     {
         InventoryComponent inventory = spaceComponents.InventoryComponents[entityWithInventory];
         foreach (Guid id in inventory.Artifacts)
         {
             ArtifactStatsComponent stats = spaceComponents.ArtifactStatsComponents[id];
             stats.MaximumComboWith = (stats.MaximumComboWith >= hitCombo) ? stats.MaximumComboWith : hitCombo;
             spaceComponents.ArtifactStatsComponents[id] = stats;
         }
     }
 }
示例#38
0
 public static void IncrementTimesMissesWithArtifact(StateSpaceComponents spaceComponents, Guid entityWithInventory)
 {
     if (spaceComponents.InventoryComponents.ContainsKey(entityWithInventory))
     {
         InventoryComponent inventory = spaceComponents.InventoryComponents[entityWithInventory];
         foreach (Guid id in inventory.Artifacts)
         {
             ArtifactStatsComponent stats = spaceComponents.ArtifactStatsComponents[id];
             stats.MissesWith += 1;
             spaceComponents.ArtifactStatsComponents[id] = stats;
         }
     }
 }
示例#39
0
 public static void IncrementDamageTakenWithArtifact(StateSpaceComponents spaceComponents, Guid entityWithInventory, int damage)
 {
     if (spaceComponents.InventoryComponents.ContainsKey(entityWithInventory))
     {
         InventoryComponent inventory = spaceComponents.InventoryComponents[entityWithInventory];
         foreach (Guid id in inventory.Artifacts)
         {
             ArtifactStatsComponent stats = spaceComponents.ArtifactStatsComponents[id];
             stats.DamageTakenWith += damage;
             spaceComponents.ArtifactStatsComponents[id] = stats;
         }
     }
 }
        public RandomlyGeneratedStateSpace(DungeonInfo data)
        {
            stateSpaceComponents = data.stateSpaceComponents;
            dungeonSpriteFile    = data.dungeonSpriteFile;
            dungeonGrid          = data.dungeonGrid;
            dungeonColorInfo     = data.dungeonColorInfo;
            dungeonDimensions    = data.dungeonDimensions;
            freeTiles            = data.freeTiles;
            PlayerComponent player = stateSpaceComponents.PlayerComponent;

            player.PlayerJustLoaded = true;
            stateSpaceComponents.PlayerComponent = player;
        }
示例#41
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;
        }
示例#42
0
 public static void CreateGameplayInfo(StateComponents stateComponents, StateSpaceComponents spaceComponents)
 {
     if (stateComponents != null)
     {
         GameplayInfoComponent info = stateComponents.GameplayInfo;
         info.FloorsReached += 1;
         spaceComponents.GameplayInfoComponent = info;
     }
     else
     {
         //Set GameplayInfo
         spaceComponents.GameplayInfoComponent = new GameplayInfoComponent() { Kills = 0, StepsTaken = 0, FloorsReached = 1, Madness = 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);
            }

        }
示例#44
0
 public static void AICheckFleeing(StateSpaceComponents spaceComponents)
 {
     if (spaceComponents.PlayerComponent.PlayerTookTurn)
     {
         foreach (Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.CombatReadyAI) == ComponentMasks.CombatReadyAI).Select(x => x.Id))
         {
             AIState state = spaceComponents.AIStateComponents[id];
             if (state.State == AIStates.STATE_ATTACKING)
             {
                 AIFlee flee = spaceComponents.AIFleeComponents[id];
                 if (flee.DoesFlee)
                 {
                     AIFieldOfView FOV = spaceComponents.AIFieldOfViewComponents[id];
                     SkillLevelsComponent skills = spaceComponents.SkillLevelsComponents[id];
                     AIAlignment alignment = spaceComponents.AIAlignmentComponents[id];
                     double healthPercent = ((double)skills.CurrentHealth / (double)skills.Health) * 100;
                     if (healthPercent <= flee.FleeAtHealthPercent)
                     {
                         state.State = AIStates.STATE_FLEEING;
                         FOV.Color = FOVColors.Fleeing;
                         spaceComponents.AIStateComponents[id] = state;
                         spaceComponents.AIFieldOfViewComponents[id] = FOV;
                         spaceComponents.GameMessageComponent.GameMessages.Add(new Tuple<Color, string>(Colors.Messages.StatusChange,
                             string.Format("[TURN " + spaceComponents.GameplayInfoComponent.StepsTaken + "] " + Messages.Flee[spaceComponents.random.Next(0, Messages.Flee.Count())], spaceComponents.NameComponents[id].Name)));
                     }
                 }
             }
             else if (state.State == AIStates.STATE_FLEEING)
             {
                 AIFlee flee = spaceComponents.AIFleeComponents[id];
                 AIFieldOfView FOV = spaceComponents.AIFieldOfViewComponents[id];
                 SkillLevelsComponent skills = spaceComponents.SkillLevelsComponents[id];
                 double healthPercent = ((double)skills.CurrentHealth / (double)skills.Health) * 100;
                 AIAlignment alignment = spaceComponents.AIAlignmentComponents[id];
                 if (healthPercent >= flee.FleeUntilHealthPercent)
                 {
                     state.State = AIStates.STATE_ATTACKING;
                     spaceComponents.AIStateComponents[id] = state;
                     FOV.Color = FOVColors.Fleeing;
                     spaceComponents.AIStateComponents[id] = state;
                     spaceComponents.AIFieldOfViewComponents[id] = FOV;
                     spaceComponents.GameMessageComponent.GameMessages.Add(new Tuple<Color, string>(Colors.Messages.StatusChange,
                         string.Format("[TURN " + spaceComponents.GameplayInfoComponent.StepsTaken + "] " + Messages.Flee[spaceComponents.random.Next(0, Messages.Flee.Count())], spaceComponents.NameComponents[id].Name)));
                 }
             }
         }
     }
 }
示例#45
0
 public static void UpdateDestructionTimes(StateSpaceComponents spaceComponents, GameTime gameTime)
 {
     foreach(Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & Component.COMPONENT_TIME_TO_LIVE) == Component.COMPONENT_TIME_TO_LIVE).Select(x => x.Id))
     {
         TimeToLiveComponent timeToLive = spaceComponents.TimeToLiveComponents[id];
         timeToLive.CurrentSecondsAlive += (float)gameTime.ElapsedGameTime.TotalSeconds;
         if(timeToLive.SecondsToLive < timeToLive.CurrentSecondsAlive)
         {
             spaceComponents.EntitiesToDelete.Add(id);
         }
         else
         {
             spaceComponents.TimeToLiveComponents[id] = timeToLive;
         }
     }
 }
示例#46
0
 public static void UpdateOutlineColors(StateSpaceComponents spaceComponents, GameTime gameTime)
 {
     foreach (Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.GlowingOutline) == ComponentMasks.GlowingOutline).Select(x => x.Id))
     {
         SecondaryOutlineComponent altColorInfo = spaceComponents.SecondaryOutlineComponents[id];
         altColorInfo.Seconds += (float)gameTime.ElapsedGameTime.TotalSeconds;
         if (altColorInfo.Seconds >= altColorInfo.SwitchAtSeconds)
         {
             OutlineComponent outline = spaceComponents.OutlineComponents[id];
             Color temp = outline.Color;
             outline.Color = altColorInfo.AlternateColor;
             altColorInfo.AlternateColor = temp;
             altColorInfo.Seconds = 0f;
             spaceComponents.OutlineComponents[id] = outline;
         }
         spaceComponents.SecondaryOutlineComponents[id] = altColorInfo;
     }
 }
示例#47
0
 public static void UpdateFovColors(StateSpaceComponents spaceComponents, GameTime gameTime)
 {
     foreach(Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.FOVColorChange) == ComponentMasks.FOVColorChange).Select(x => x.Id))
     {
         AlternateFOVColorChangeComponent altColorInfo = spaceComponents.AlternateFOVColorChangeComponents[id];
         altColorInfo.Seconds += (float)gameTime.ElapsedGameTime.TotalSeconds;
         if(altColorInfo.Seconds >= altColorInfo.SwitchAtSeconds)
         {
             AIFieldOfView fovInfo = spaceComponents.AIFieldOfViewComponents[id];
             Color temp = fovInfo.Color;
             fovInfo.Color = altColorInfo.AlternateColor;
             altColorInfo.AlternateColor = temp;
             altColorInfo.Seconds = 0f;
             spaceComponents.AIFieldOfViewComponents[id] = fovInfo;
         }
         spaceComponents.AlternateFOVColorChangeComponents[id] = altColorInfo;
     }
 }
示例#48
0
 public static void RegenerateHealth(StateSpaceComponents spaceComponents)
 {
     if (spaceComponents.PlayerComponent.PlayerTookTurn)
     {
         foreach (Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.HealthRegen) == ComponentMasks.HealthRegen).Select(x => x.Id))
         {
             HealthRegenerationComponent healthRegen = spaceComponents.HealthRegenerationComponents[id];
             healthRegen.TurnsSinceLastHeal += 1;
             if (healthRegen.TurnsSinceLastHeal >= healthRegen.RegenerateTurnRate)
             {
                 SkillLevelsComponent skills = spaceComponents.SkillLevelsComponents[id];
                 skills.CurrentHealth += healthRegen.HealthRegain;
                 skills.CurrentHealth = (skills.CurrentHealth >= skills.Health) ? skills.Health : skills.CurrentHealth;
                 spaceComponents.SkillLevelsComponents[id] = skills;
             }
             spaceComponents.HealthRegenerationComponents[id] = healthRegen;
         }
     }
 }
示例#49
0
 public static void AICheckDetection(StateSpaceComponents spaceComponents)
 {
     if(spaceComponents.PlayerComponent.PlayerTookTurn)
     {
         foreach (Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.CombatReadyAI) == ComponentMasks.CombatReadyAI).Select(x => x.Id))
         {
             AIState state = spaceComponents.AIStateComponents[id];
             switch (state.State)
             {
                 case AIStates.STATE_SLEEPING:
                     AISystem.AITryToWake(id, spaceComponents);
                     break;
                 case AIStates.STATE_ROAMING:
                     AISystem.AITryToFind(id, spaceComponents);
                     break;
             }
         }
     }
 }
示例#50
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;
        }
示例#51
0
        public static void DrawString(SpriteBatch spriteBatch, StateSpaceComponents spaceComponents, SpriteFont font, Camera camera)
        {
            Matrix cameraMatrix = camera.GetMatrix();
            foreach (Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.DrawableLabel) == ComponentMasks.DrawableLabel).Select(x => x.Id))
            {
                LabelComponent label = spaceComponents.LabelComponents[id];
                Vector2 position = new Vector2(spaceComponents.PositionComponents[id].Position.X, spaceComponents.PositionComponents[id].Position.Y);
                Vector2 stringSize = font.MeasureString(label.Text);
                Vector2 bottomRight = Vector2.Transform(new Vector2(position.X + stringSize.X, position.Y + stringSize.Y), 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))
                {
                    spriteBatch.DrawString(font, label.Text, position,
                        label.Color, label.Rotation, label.Origin, label.Scale, label.SpriteEffect, 0f);
                }
            }
        }
示例#52
0
        public static void UpdateMovingEntities(StateSpaceComponents spaceComponents, GameTime gameTime)
        {
            foreach (Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.MovingEntity) == ComponentMasks.MovingEntity).Select(x => x.Id))
            {
                PositionComponent position = spaceComponents.PositionComponents[id];
                TargetPositionComponent target = spaceComponents.TargetPositionComponents[id];

                Vector2 Direction = Vector2.Normalize(target.TargetPosition - position.Position);
                float distance = Math.Abs(Vector2.Distance(position.Position, target.TargetPosition));
                if (distance > 10)
                {
                    position.Position += Direction * spaceComponents.VelocityComponents[id].Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    spaceComponents.PositionComponents[id] = position;
                }
                else if (spaceComponents.TargetPositionComponents[id].DestroyWhenReached)
                {
                    spaceComponents.EntitiesToDelete.Add(id);
                }
            }
        }
示例#53
0
 public static void LoadPlayerSkillset(StateComponents stateComponents, StateSpaceComponents spaceComponents)
 {
     foreach(Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & Component.COMPONENT_PLAYER) == Component.COMPONENT_PLAYER).Select(x => x.Id))
     {
         if (stateComponents != null)
         {
             spaceComponents.SkillLevelsComponents[id] = stateComponents.PlayerSkillLevels;
         }
         else
         {
             spaceComponents.SkillLevelsComponents[id] = new SkillLevelsComponent()
             {
                 CurrentHealth = 100,
                 Health = 100,
                 Defense = 50,
                 Accuracy = 100,
                 Wealth = 0
             };
         }
     }
 }
示例#54
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);

        }
示例#55
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;
 }
示例#56
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);
                            }));
                        }
                    }
                    

                }
            }
        }
示例#57
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;
        }
示例#58
0
        public static void UpdateCamera(Camera camera, GameTime gameTime, StateSpaceComponents stateSpaceComponents, int cellSize, KeyboardState prevKey)
        {
            if (Mouse.GetState().RightButton == ButtonState.Pressed)
            {
                MessageDisplaySystem.SetRandomGlobalMessage(stateSpaceComponents, Messages.CameraDetatchedMessage);
                camera.Target = Vector2.Transform(Mouse.GetState().Position.ToVector2(), camera.GetInverseMatrix());
                camera.AttachedToPlayer = false;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.W))
            {
                camera.AttachedToPlayer = false;
                camera.Position.Y -= camera.Velocity.Y * (float)gameTime.ElapsedGameTime.TotalSeconds;
                camera.Target = camera.Position;
                MessageDisplaySystem.SetRandomGlobalMessage(stateSpaceComponents, Messages.CameraDetatchedMessage);
            }
            if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                camera.AttachedToPlayer = false;
                camera.Position.X -= camera.Velocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds;
                camera.Target = camera.Position;
                MessageDisplaySystem.SetRandomGlobalMessage(stateSpaceComponents, Messages.CameraDetatchedMessage);
            }
            if (Keyboard.GetState().IsKeyDown(Keys.S))
            {
                camera.AttachedToPlayer = false;
                camera.Position.Y += camera.Velocity.Y * (float)gameTime.ElapsedGameTime.TotalSeconds;
                camera.Target = camera.Position;
                MessageDisplaySystem.SetRandomGlobalMessage(stateSpaceComponents, Messages.CameraDetatchedMessage);
            }
            if (Keyboard.GetState().IsKeyDown(Keys.D))
            {
                camera.AttachedToPlayer = false;
                camera.Position.X += camera.Velocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds;
                camera.Target = camera.Position;
                MessageDisplaySystem.SetRandomGlobalMessage(stateSpaceComponents, Messages.CameraDetatchedMessage);
            }
            if(Keyboard.GetState().IsKeyDown(Keys.OemPlus) && prevKey.IsKeyUp(Keys.OemPlus))
            {
                if(camera.Scale + .25f < 4.25f)
                {
                    camera.Scale += .25f;
                }
            }
            if (Keyboard.GetState().IsKeyDown(Keys.OemMinus) && prevKey.IsKeyUp(Keys.OemMinus))
            {
                if (camera.Scale - .25f > 0f)
                {
                    camera.Scale -= .25f;
                }
            }

            if (Keyboard.GetState().IsKeyDown(Keys.R))
            {
                camera.AttachedToPlayer = true;
                MessageDisplaySystem.SetRandomGlobalMessage(stateSpaceComponents, new string[] { string.Empty });
            }

            if (camera.AttachedToPlayer)
            {
                Entity playerId = stateSpaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Player) == ComponentMasks.Player).FirstOrDefault();
                if(stateSpaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Observer) == ComponentMasks.Observer).FirstOrDefault() != null)
                {
                    playerId = stateSpaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Observer) == ComponentMasks.Observer).FirstOrDefault();
                }
                if (playerId != null)
                {
                    camera.Target = new Vector2((int)stateSpaceComponents.PositionComponents[playerId.Id].Position.X * cellSize + stateSpaceComponents.DisplayComponents[playerId.Id].SpriteSource.Width / 2,
                    (int)stateSpaceComponents.PositionComponents[playerId.Id].Position.Y * cellSize + stateSpaceComponents.DisplayComponents[playerId.Id].SpriteSource.Height / 2);
                }
                if (stateSpaceComponents.PlayerComponent.PlayerJustLoaded)
                {
                    camera.Position = new Vector2((int)stateSpaceComponents.PositionComponents[playerId.Id].Position.X * cellSize + stateSpaceComponents.DisplayComponents[playerId.Id].SpriteSource.Width / 2,
                    (int)stateSpaceComponents.PositionComponents[playerId.Id].Position.Y * cellSize + stateSpaceComponents.DisplayComponents[playerId.Id].SpriteSource.Height / 2);
                }
            }
            if (Vector2.Distance(camera.Position, camera.Target) > 0)
            {
                float distance = Vector2.Distance(camera.Position, camera.Target);
                Vector2 direction = Vector2.Normalize(camera.Target - camera.Position);
                float velocity = distance * 2.5f;
                if (distance > 10f)
                {
                    camera.Position += direction * velocity * (camera.Scale >= 1 ? camera.Scale : 1) * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
            }
        }
示例#59
0
 public static void AITryToFind(Guid entity, StateSpaceComponents spaceComponents)
 {
     AIFieldOfView entityFOV = spaceComponents.AIFieldOfViewComponents[entity];
     AIAlignment entityAlignment = spaceComponents.AIAlignmentComponents[entity];
     AIRoam entityRoam = spaceComponents.AIRoamComponents[entity];
     AIState entityState = spaceComponents.AIStateComponents[entity];
     foreach (Guid id in spaceComponents.Entities.Where(x => ((x.ComponentFlags & Component.COMPONENT_PLAYER) == Component.COMPONENT_PLAYER) ||
         ((x.ComponentFlags & ComponentMasks.CombatReadyAI) == ComponentMasks.CombatReadyAI)).Select(x => x.Id))
     {
         PositionComponent position = spaceComponents.PositionComponents[id];
         AIAlignment alignment = spaceComponents.AIAlignmentComponents[id];
         if (entityFOV.SeenTiles.Contains(position.Position) && entityAlignment.Alignment != alignment.Alignment && spaceComponents.random.Next(1, 101) <= entityRoam.ChanceToDetect)
         {
             entityState.State = AIStates.STATE_ATTACKING;
             entityFOV.Color = FOVColors.Attacking;
             spaceComponents.AIStateComponents[entity] = entityState;
             spaceComponents.AIFieldOfViewComponents[entity] = entityFOV;
             spaceComponents.GameMessageComponent.GameMessages.Add(new Tuple<Color, string>(Colors.Messages.StatusChange,
                 string.Format("[TURN " + spaceComponents.GameplayInfoComponent.StepsTaken + "] " + Messages.FoundBySight[spaceComponents.random.Next(0, Messages.FoundBySight.Count())], spaceComponents.NameComponents[entity].Name)));
             return;
         }
     }
 }
示例#60
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;
                }
            }


        }