Esempio n. 1
0
        public void CreaturesAdd(Creature _creature, Point _inBlockCoords)
        {
            if (Creatures.Any(_pair => _pair.Value == _inBlockCoords))
            {
                throw new ApplicationException();
            }
            //var busy = new List<Point>();
            //while (Creatures.Any(_pair => _pair.Value == _inBlockCoords))
            //{
            //    busy.Add(_inBlockCoords);
            //    var lt = _creature[0, 0].InBlockCoords;

            //    foreach (var point in new Point(Constants.MAP_BLOCK_SIZE / 2, Constants.MAP_BLOCK_SIZE / 2).GetSpiral(Constants.MAP_BLOCK_SIZE / 2 - 1))
            //    {

            //        if (_creature[point - lt].GetIsPassableBy(_creature) > 0 && !busy.Contains(point))
            //        {
            //            _inBlockCoords = point;
            //            break;
            //        }
            //    }
            //}

            Creatures.Add(_creature, _inBlockCoords);
            //if (_creature.GeoInfo != null)
            //{
            //    _creature.GeoInfo.WorldCoords = WorldCoords + _inBlockCoords;
            //}
        }
Esempio n. 2
0
 public void AddCreature(Creature creature)
 {
     if (Creatures == null)
     {
         Creatures = new List <Creature>();
     }
     Creatures.Add(creature);
 }
Esempio n. 3
0
        private void New()
        {
            var creature = _observableDataFactory.Create <CreatureDataObservable>();

            creature.Name = "Creature" + (Creatures.Count + 1);
            Creatures.Add(creature);

            _eventAggregator.GetEvent <CreatureCreatedEvent>().Publish(creature);
            RaiseValidityChangedEvent();
        }
Esempio n. 4
0
        public async void AddPlayers()
        {
            if (!pcsAdded)
            {
                // add players to encounter if they are not added yet
                List <PlayerCharacter> players = await App.Database.Players.Get <bool>((pc) => pc.CampaignID == this.CampaignId, null);

                foreach (var pc in players)
                {
                    Creatures.Add(new CreatureViewModel(pc));
                }

                pcsAdded = true;
            }
        }
Esempio n. 5
0
        private void LoadExistingData()
        {
            Creatures.Clear();
            Classes.Clear();

            foreach (var loaded in _moduleDataService.LoadAll <CreatureData>())
            {
                CreatureDataObservable creature = _observableDataFactory.CreateAndMap <CreatureDataObservable, CreatureData>(loaded);
                Creatures.Add(creature);
            }
            foreach (var loaded in _moduleDataService.LoadAll <ClassData>())
            {
                ClassDataObservable @class = _observableDataFactory.CreateAndMap <ClassDataObservable, ClassData>(loaded);
                Classes.Add(@class);
            }
        }
Esempio n. 6
0
        public async Task LoadData()
        {
            if (!dataLoaded)
            {
                var creatures = await App.Database.Creatures.Get <bool>((c) => c.EncounterID == Id, null);

                foreach (var c in creatures)
                {
                    var vm = new CreatureViewModel(c);
                    SetNumber(vm);
                    Creatures.Add(vm);
                }
            }

            dataLoaded = true;
        }
            public Battle(string input, int elfAttackPower = DefaultAttackPower)
            {
                var data   = input.SplitByNewline(shouldTrim: true);
                var width  = data.First().Length;
                var height = data.Length;

                Grid = new Position[width, height];

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        if (data[y][x] == '#')
                        {
                            continue;
                        }

                        Creature creature = null;
                        if (data[y][x] == 'G')
                        {
                            creature = Creature.CreateGoblin();
                        }
                        if (data[y][x] == 'E')
                        {
                            creature = Creature.CreateElf(elfAttackPower);
                        }
                        if (creature != null)
                        {
                            Creatures.Add(creature);
                        }

                        var value = (y * width) + x;

                        Grid[x, y] = new Position(x, y, value, creature);

                        if (y > 0 && Grid[x, y - 1] != null)
                        {
                            Grid[x, y].ConnectToPositionAbove(Grid[x, y - 1]);
                        }

                        if (x > 0 && Grid[x - 1, y] != null)
                        {
                            Grid[x, y].ConnectToPositionToTheLeft(Grid[x - 1, y]);
                        }
                    }
                }
            }
        public void NextTurn(ICreatureCommand playerCommand)
        {
            Random r = RandomNumberGenerator.GlobalRandom;

            if (!gameEnded())
            {
                if (playerCommand.isExecutable())
                {
                    //AbstractLogger.Current.Clear();
                    playerCommand.execute();

                    Creatures.RemoveAll(x => x.isDead || x.Field == null);

                    foreach (Creature creature in Creatures)
                    {
                        ICreatureCommand creatureCommand = creature.AI.GenerateNextCommand();
                        if (creatureCommand != null)
                        {
                            creatureCommand.execute();
                        }
                    }
                    ++turnCounter;
                    AbstractLogger.Current.Log("Tura " + turnCounter);

                    if (gameEnded())
                    {
                        if (Player.isDead == true)
                        {
                            AbstractLogger.Current.Log("Przegrałeś. Twój wynik to " + Player.Money + " punktów.");
                        }
                        else if (Player.PickedPointsCount == Generator.PointObjectsCount)
                        {
                            Player.Money += 10;
                            Player.Money += Player.Health / 2;
                            AbstractLogger.Current.Log("Dostajesz bonus " + Player.Health / 2 + " punktów za zachowane zdrowie.");
                            AbstractLogger.Current.Log("Dostajesz bonus " + (Generator.SizeX * Generator.SizeY) / 10 + " punktów za wielkość mapy.");
                            AbstractLogger.Current.Log("Wygrałeś!. Twój wynik to " + Player.Money + " punktów.");
                        }
                    }

                    if (turnCounter % 8 == 0)
                    {
                        Creatures.Add(Generator.GenerateRandomCreature(Map, Player));
                    }
                }
            }
        }
Esempio n. 9
0
        private void InitializePlayer()
        {
            Player = new Creature()
            {
                Type     = Creature.Types.PLAYER,
                Location = new Vector2(0, 0),
                Health   = 100,
                Attack   = 10,
                ID       = 9999,
                Range    = 32,
                Speed    = 7
            };
            Player.AddCard(Card.Types.Bomb);
            Player.AddCard(Card.Types.Heal);


            //Player.AIScript = Creature.CreateAttackIfInRange;
            Creatures.Add(Player);
        }
Esempio n. 10
0
 protected override void EnforceMinCreatures()
 {
     if (Creatures.Count < MIN_CREATURES)
     {
         Creatures.Sort();
         Creatures.Reverse();
         for (int i = 0; i < MIN_CREATURES - Creatures.Count; i++)
         {
             Creature PartnerA = Creatures[RandomInt(10)];
             Creature PartnerB = Creatures[RandomInt(10)];
             while (PartnerA == PartnerB)
             {
                 PartnerB = Creatures[RandomInt(10)];
             }
             Creature offspring = new Creature(PartnerA.agent.CrossOver(PartnerB.agent), new Position(RandomDouble(), RandomDouble()))
             {
                 lastMatedAtTick = ticksElapsed
             };
             Creatures.Add(offspring);
         }
     }
 }
Esempio n. 11
0
        public void Spawn(Player player)
        {
            List <LevelObject> floors = Objects.FindAll(x => x.Name == "floor");

            // Spawn Player:
            while (true)
            {
                int p = rnd.Next(0, floors.Count);
                if (ItemContainers.Any(i => i.Position_x == floors[p].Position_x && i.Position_y == floors[p].Position_y))
                {
                    continue;
                }
                else
                {
                    player.Position_x = floors[p].Position_x;
                    player.Position_y = floors[p].Position_y;
                    Player            = player;
                    Objects.Add(Player);
                    Creatures.Add(Player);
                    break;
                }
            }

            // Spawn Skeletons:
            for (int i = 0; i < 20;)
            {
                int s = rnd.Next(0, floors.Count);
                if (Creatures.Any(obj => obj.Position_x == floors[s].Position_x && obj.Position_y == floors[s].Position_y) || ItemContainers.Any(c => c.Position_x == floors[s].Position_x && c.Position_y == floors[s].Position_y))
                {
                    continue;
                }
                else
                {
                    Skeleton skeleton = new Skeleton(ID);
                    skeleton.Position_x       = floors[s].Position_x;
                    skeleton.Position_y       = floors[s].Position_y;
                    skeleton.Spawn_Position_x = skeleton.Position_x;
                    skeleton.Spawn_Position_y = skeleton.Position_y;
                    skeleton.Habitat_x_max    = skeleton.Position_x + 2;
                    skeleton.Habitat_x_min    = skeleton.Position_x - 2;
                    skeleton.Habitat_y_max    = skeleton.Position_y + 2;
                    skeleton.Habitat_y_min    = skeleton.Position_y - 2;
                    skeleton.Follow_x_max     = skeleton.Position_x + 6;
                    skeleton.Follow_x_min     = skeleton.Position_x - 6;
                    skeleton.Follow_y_max     = skeleton.Position_y + 6;
                    skeleton.Follow_y_min     = skeleton.Position_y - 6;

                    Objects.Add(skeleton);
                    Creatures.Add(skeleton);
                    i++;
                }
            }
            // Spawn Skeleton Warriors:
            for (int i = 0; i < 10;)
            {
                int z = rnd.Next(0, floors.Count);
                if (Creatures.Any(obj => obj.Position_x == floors[z].Position_x && obj.Position_y == floors[z].Position_y) || ItemContainers.Any(c => c.Position_x == floors[z].Position_x && c.Position_y == floors[z].Position_y) || Math.Abs(floors[z].Position_x - Player.Position_x) < 30 || Math.Abs(floors[z].Position_y - Player.Position_y) < 30)
                {
                    continue;
                }
                else
                {
                    SkeletonWarrior skeleton = new SkeletonWarrior();
                    skeleton.Position_x       = floors[z].Position_x;
                    skeleton.Position_y       = floors[z].Position_y;
                    skeleton.Spawn_Position_x = skeleton.Position_x;
                    skeleton.Spawn_Position_y = skeleton.Position_y;
                    skeleton.Habitat_x_max    = skeleton.Position_x + 2;
                    skeleton.Habitat_x_min    = skeleton.Position_x - 2;
                    skeleton.Habitat_y_max    = skeleton.Position_y + 2;
                    skeleton.Habitat_y_min    = skeleton.Position_y - 2;
                    skeleton.Follow_x_max     = skeleton.Position_x + 4;
                    skeleton.Follow_x_min     = skeleton.Position_x - 4;
                    skeleton.Follow_y_max     = skeleton.Position_y + 4;
                    skeleton.Follow_y_min     = skeleton.Position_y - 4;
                    Objects.Add(skeleton);
                    Creatures.Add(skeleton);
                    i++;
                }
            }
            // Spawn Guards:
            for (int i = 0; i < 9; i++)
            {
                Guard guard = new Guard();
                guard.Position_x       = Rooms[i].Center_x - 1;
                guard.Position_y       = Rooms[i].Center_y - 1;
                guard.Spawn_Position_x = guard.Position_x;
                guard.Spawn_Position_y = guard.Position_y;
                guard.Habitat_x_max    = (guard.Spawn_Position_x + 1) + (Rooms[i].Length) / 2 - 1;
                guard.Habitat_x_min    = (guard.Spawn_Position_x + 1) - (Rooms[i].Length) / 2 + 1;
                guard.Habitat_y_max    = (guard.Spawn_Position_y + 1) + (Rooms[i].Width) / 2 - 1;
                guard.Habitat_y_min    = (guard.Spawn_Position_y + 1) - (Rooms[i].Width) / 2 + 1;
                guard.Follow_x_max     = guard.Habitat_x_max;
                guard.Follow_y_max     = guard.Habitat_y_max;
                guard.Follow_x_min     = guard.Habitat_x_min;
                guard.Follow_y_min     = guard.Habitat_y_min;
                Objects.Add(guard);
                Creatures.Add(guard);
            }
        }
Esempio n. 12
0
 public void Enter(Creature creature, Direction direction)
 {
     Creatures.Add(creature);
     this.CreatureEntered?.Invoke(this, creature, direction);
 }
Esempio n. 13
0
 public void AddCreature(Creature creature) // Used to add creatures from outside the class, such as summoning minions.
 {
     Creatures.Add(creature);
 }
Esempio n. 14
0
        public void LoadMap(string mapname)
        {
            this.Loading = true;
            map          = Squared.Tiled.Map.Load(String.Format("Content\\{0}", mapname), content);
            MapWidth     = map.Width * map.TileWidth;
            MapHeight    = map.Height * map.TileHeight;
            MapWidth     = (MapWidth > screenw) ? MapWidth : screenw;
            MapHeight    = (MapHeight > screenh) ? MapWidth : screenh;
            renderTarget = new RenderTarget2D(
                device,
                MapWidth,
                MapHeight,
                //1024,
                //1024,
                false,
                device.PresentationParameters.BackBufferFormat,
                DepthFormat.Depth24);


            Random random = new Random();

            foreach (var grp in map.ObjectGroups)
            {
                //ObjectGroup grp = kvpair.Value;
                foreach (var tiledobj in grp.Objects)
                {
                    if (tiledobj.Name.Equals("Start"))
                    {
                        Console.WriteLine("object: {0}, x {1} y {2} width {3} height {4}", tiledobj.Name, tiledobj.X, tiledobj.Y, tiledobj.Width, tiledobj.Height);
                        Player.Location = new Vector2(tiledobj.X + tiledobj.Width / 2, tiledobj.Y + tiledobj.Width / 2);
                    }
                    else if (tiledobj.Name.Equals("SpawnPortal"))
                    {
                        Portals.Add(new SpawnPortal()
                        {
                            CreatureTypes = new Creature.Types[] { Creature.Types.SMALL, Creature.Types.MEDIUM },
                            Location      = new Vector2(tiledobj.X + tiledobj.Width / 2, tiledobj.Y + tiledobj.Height / 2),
                            Size          = random.Next(1, 6),
                            isOpen        = false
                        });
                    }
                    else if (tiledobj.Name.Equals("BossSpawn"))
                    {
                        var bosstype = tiledobj.Properties["BossType"];
                        switch (bosstype)
                        {
                        case "FirstBoss":
                            Creatures.Add(new Creature()
                            {
                                Attack   = 10,
                                Health   = 500,
                                Range    = 128,
                                Location = new Vector2(tiledobj.X + tiledobj.Width / 2, tiledobj.Y + tiledobj.Height / 2),
                                ID       = Creatures.Count,
                                Type     = Creature.Types.BOSS,
                                Speed    = 4,
                                AIScript = Creature.ChargePlayerIfInRange
                            });
                            break;

                        default:
                            throw new NotImplementedException();
                        }
                    }
                    else if (tiledobj.Name.Equals("Location"))
                    {
                        if (tiledobj.Properties.ContainsKey("LocationType"))
                        {
                            Locations.Add(new Location()
                            {
                                X      = tiledobj.X + tiledobj.Width / 2,
                                Y      = tiledobj.Y + tiledobj.Height / 2,
                                Type   = tiledobj.Properties["LocationType"],
                                Width  = tiledobj.Width,
                                Height = tiledobj.Height,
                            });
                        }
                    }
                }
                MapChanged = true;
            }

            //this.Viewport = new Vector2(-(map.Width*map.TileWidth / 2f), - (map.Height*map.TileHeight / 2f));
            this.Viewport = new Vector2(0, 0);
            //X = this.MapWidth / 2;
            //Y = this.MapHeight / 2;
            X            = this.Viewport.X / 2;
            Y            = this.Viewport.Y / 2;
            this.Loading = false;
        }
Esempio n. 15
0
        /// <summary> Populates a dungeon-like map. </summary>
        private void GenerateDungeon()
        {
            GenerateRooms();
            GenerateMaze();
            foreach (List <int> pointSet in RoomPoints)
            {
                MakeDoor(pointSet);
            }
            // Retract the maze starting at the dead ends
            for (int i = 0; i < 500; i++)
            {
                List <List <int> > mazeEnds = GetMazeEndPoints();
                foreach (List <int> endPoints in mazeEnds)
                {
                    Data[endPoints[0], endPoints[1]] = null;
                }
            }
            // Ensure that all regions are connected (i.e. only one region)
            List <List <int> > regionLocations = GetRegionLocations();

            while (regionLocations.Count > 1)
            {
                ConnectRegions(regionLocations);
                FloodFill(regionLocations[0][0], regionLocations[0][1]);
                regionLocations = GetRegionLocations();
            }
            // Place the stairs to get out of the dungeon
            int entryRoom = Engine.rand.Next(0, RoomPoints.Count);
            int exitRoom  = Engine.rand.Next(0, RoomPoints.Count);

            if (entryRoom == exitRoom && RoomPoints.Count > 1)
            {
                exitRoom = (exitRoom + 1) % RoomPoints.Count;
            }
            int entryY = Engine.rand.Next(RoomPoints[entryRoom][0], RoomPoints[entryRoom][2]);
            int entryX = Engine.rand.Next(RoomPoints[entryRoom][1], RoomPoints[entryRoom][3]);
            int exitY  = Engine.rand.Next(RoomPoints[exitRoom][0], RoomPoints[exitRoom][2]);
            int exitX  = Engine.rand.Next(RoomPoints[exitRoom][1], RoomPoints[exitRoom][3]);

            Data[entryY, entryX] = new Stair(entryY, entryX, StairType.Up);
            Data[exitY, exitX]   = new Stair(exitY, exitX, StairType.Down);
            foreach (List <int> points in RoomPoints)
            {
                for (int y = points[0] - 1; y < points[2] + 1; ++y)
                {
                    for (int x = points[1] - 1; x < points[3] + 1; ++x)
                    {
                        if (Data[y, x] == null)
                        {
                            Data[y, x] = new Wall(y, x);
                        }
                    }
                }
            }

            Program.player.CoordX = entryX;
            Program.player.CoordY = entryY;
            foreach (List <int> room in RoomPoints)
            {
                int cY = Engine.rand.Next(room[0], room[2]);
                int cX = Engine.rand.Next(room[1], room[3]);
                // randomly select index
                // get type of that index
                // make new object of that type with cast of that type
                Creature c = new Creature(Engine.MasterCreatures[0]);
                c.CoordY = cY;
                c.CoordX = cX;
                Creatures.Add(c);
            }
            foreach (List <int> room in RoomPoints)
            {
                if (Engine.rand.Next(0, 10) < 3)
                {
                    int index = Engine.rand.Next(0, Engine.MasterOrbs.Count);
                    int y     = Engine.rand.Next(room[0], room[2]);
                    int x     = Engine.rand.Next(room[1], room[3]);
                    Data[y, x].Inventory.AddItem(new Orb(Engine.MasterOrbs[index]));
                }
            }
        }