Ejemplo n.º 1
0
        public override void HandleVisibility()
        {
            localCreatures = new List <Creature>();

            RayCaster.SetAllInvis(Position, SightDist + 5);

            int localDangerCount = 0;

            foreach (Point point in VisiblePoints)
            {
                Program.WorldMap.LocalTile[point.X, point.Y].Visible  = true;
                Program.WorldMap.LocalTile[point.X, point.Y].Explored = true;
                if (Program.WorldMap.LocalTile[point.X, point.Y].Opaque == false)
                {
                    Program.WorldMap.LocalTile.Floor[point.X * Program.WorldMap.LocalTile.Width + point.Y].Explored = true;
                    Program.WorldMap.LocalTile.Floor[point.X * Program.WorldMap.LocalTile.Width + point.Y].Visible  = true;
                }

                // add items to memory map, remove them if there is a mismatch between memory map and local map
                if (Program.WorldMap.LocalTile[point.X, point.Y] is Item)
                {
                    Program.WorldMap.LocalTile.MemoryMap[point.X * Program.WorldMap.LocalTile.Width + point.Y] = Program.WorldMap.LocalTile[point.X, point.Y];
                }
                else if (Program.WorldMap.LocalTile.MemoryMap[point.X * Program.WorldMap.LocalTile.Width + point.Y] != null)
                {
                    Program.WorldMap.LocalTile.MemoryMap[point.X * Program.WorldMap.LocalTile.Width + point.Y] = null;
                }

                if (Program.WorldMap.LocalTile[point.X, point.Y] is Monster && ((Creature)Program.WorldMap.LocalTile[point.X, point.Y]).Friendly == false && ((Creature)Program.WorldMap.LocalTile[point.X, point.Y]).Alive)
                {
                    localDangerCount++;
                }

                if (Program.WorldMap.LocalTile[point.X, point.Y] is Creature creature)
                {
                    localCreatures.Add(creature);
                }
            }

            if (localDangerCount > 0)
            {
                if (dangerCount < localDangerCount)
                {
                    Program.Player.Path = null;
                }
                dangerCount = localDangerCount;
            }
            else
            {
                dangerCount = localDangerCount;
            }
        }
Ejemplo n.º 2
0
        public override void HandleVisibility()
        {
            localCreatures = new List <Creature>();

            RayCaster.SetAllInvis(Position, SightDist + 5, WorldIndex, CurrentFloor);

            Block[] blocks           = CurrentFloor >= 0 ? Program.WorldMap[WorldIndex.X, WorldIndex.Y].Dungeon.Floors[CurrentFloor].Blocks : Program.WorldMap[WorldIndex.X, WorldIndex.Y].Blocks;
            Tile[]  tiles            = CurrentFloor >= 0 ? Program.WorldMap[WorldIndex.X, WorldIndex.Y].Dungeon.Floors[CurrentFloor].Floor : Program.WorldMap[WorldIndex.X, WorldIndex.Y].Floor;
            int     width            = Program.WorldMap[WorldIndex.X, WorldIndex.Y].Width;
            int     localDangerCount = 0;

            foreach (Point point in VisiblePoints)
            {
                blocks[point.X * width + point.Y].Visible  = true;
                blocks[point.X * width + point.Y].Explored = true;
                if (blocks[point.X * width + point.Y].Opaque == false)
                {
                    tiles[point.X * width + point.Y].Visible  = true;
                    tiles[point.X * width + point.Y].Explored = true;
                }

                //// add items to memory map, remove them if there is a mismatch between memory map and local map
                //if (blocks[point.X * width + point.Y] is Item)
                //    Program.WorldMap[WorldIndex.X, WorldIndex.Y].MemoryMap[point.X * width + point.Y] = blocks[point.X * width + point.Y];
                //else if (Program.WorldMap[WorldIndex.X, WorldIndex.Y].MemoryMap[point.X * width + point.Y] != null)
                //    Program.WorldMap[WorldIndex.X, WorldIndex.Y].MemoryMap[point.X * width + point.Y] = null;


                if (blocks[point.X * width + point.Y] is Creature creature)
                {
                    localCreatures.Add(creature);
                    if (creature is Monster monster && (monster.Faction.Equals(Faction) == false && monster.Alive))
                    {
                        localDangerCount++;
                    }
                }
            }

            if (localDangerCount > 0)
            {
                if (dangerCount < localDangerCount)
                {
                    Program.Player.Path = null;
                }
                dangerCount = localDangerCount;
            }
            else
            {
                dangerCount = localDangerCount;
            }
        }
        public static bool HandleMapSwitching(Creature creature)
        {
            // set all visibile cells to invisible so before switching maps
            RayCaster.SetAllInvis(creature.Position, creature.SightDist + 5);

            bool success = false;

            if (creature.Position.X == 0 && Program.WorldMap.WorldIndex.X != 0)
            {
                success = creature.MoveMaps(new Point(Program.WorldMap.LocalTile.Width - 1, creature.Position.Y),
                                            Program.WorldMap.LocalTile, Program.WorldMap[Program.WorldMap.WorldIndex.X - 1, Program.WorldMap.WorldIndex.Y]);
                if (success)
                {
                    Program.WorldMap.WorldIndex.X -= 1;
                }
            }
            else if (creature.Position.Y == Program.WorldMap.LocalTile.Height - 1 && Program.WorldMap.WorldIndex.Y != 4)
            {
                success = creature.MoveMaps(new Point(creature.Position.X, 0), Program.WorldMap.LocalTile,
                                            Program.WorldMap[Program.WorldMap.WorldIndex.X, Program.WorldMap.WorldIndex.Y + 1]);
                if (success)
                {
                    Program.WorldMap.WorldIndex.Y += 1;
                }
            }
            else if (creature.Position.X == Program.WorldMap.LocalTile.Width - 1 && Program.WorldMap.WorldIndex.X != 4)
            {
                success = creature.MoveMaps(new Point(0, creature.Position.Y), Program.WorldMap.LocalTile,
                                            Program.WorldMap[Program.WorldMap.WorldIndex.X + 1, Program.WorldMap.WorldIndex.Y]);
                if (success)
                {
                    Program.WorldMap.WorldIndex.X += 1;
                }
            }
            else if (creature.Position.Y == 0 && Program.WorldMap.WorldIndex.Y != 0)
            {
                success = creature.MoveMaps(new Point(creature.Position.X, Program.WorldMap[0, 0].Height - 1),
                                            Program.WorldMap.LocalTile, Program.WorldMap[Program.WorldMap.WorldIndex.X, Program.WorldMap.WorldIndex.Y - 1]);
                if (success)
                {
                    Program.WorldMap.WorldIndex.Y -= 1;
                }
            }

            return(success);
        }
Ejemplo n.º 4
0
 // behaviors //
 public void UpdateFOV()
 {
     visiblePoints = RayCaster.CalculateFOV(sightDist, this).ToList();
 }