コード例 #1
0
        public Monster(TypeMonster tm, int level, BattleParticipant bp) : base(tm, bp)
        {
            Debug.Assert(tm != null);
            Debug.Assert(level > 0);

            TypeMonster = tm;
        }
コード例 #2
0
        internal Battle(BattleParticipant player1, BattleParticipant player2, int turn, Random r, bool showForPlayer)
        {
            Debug.Assert(player1 != null);
            Debug.Assert(player2 != null);
            Debug.Assert(player1 != player2);
            //Debug.Assert(player1.BattleCalced == false);
            //Debug.Assert(player2.BattleCalced == false);
            Debug.Assert(player1.IsLive == true);
            Debug.Assert(player2.IsLive == true);

            //
            Player1 = player1;
            Player2 = player2;
            Turn    = turn;
            Rnd     = r;

            BattleCalced    = false;
            Step            = 0;
            SizeBattlefield = new Size((FormMain.Config.HeroRows * 2) + FormMain.Config.RowsBetweenSides, FormMain.Config.HeroInRow);
            Battlefield     = new Battlefield(SizeBattlefield.Width, SizeBattlefield.Height);

            // Запоминаем героев в одном списке для упрощения расчетов
            if (player2 is PlayerLair pl)
            {
                foreach (PlayerHero ph in pl.listAttackedHero)
                {
                    Debug.Assert(ph.IsLive);
                    AddHero(new HeroInBattle(this, ph, ph.CoordInPlayer, showForPlayer));
                }
            }
            else
            {
                foreach (Creature ph in player1.CombatHeroes)
                {
                    Debug.Assert(ph.IsLive);
                    AddHero(new HeroInBattle(this, ph, ph.CoordInPlayer, showForPlayer));
                }
            }

            foreach (Creature ph in player2.CombatHeroes)
            {
                Debug.Assert(ph.IsLive);
                AddHero(new HeroInBattle(this, ph, new Point(FormMain.Config.HeroInRow + FormMain.Config.RowsBetweenSides + (FormMain.Config.HeroInRow - ph.CoordInPlayer.X) - 1, ph.CoordInPlayer.Y), showForPlayer));
            }

            void AddHero(HeroInBattle hb)
            {
                Debug.Assert(hb.IsLive == true);
                //Debug.Assert(ph.ParametersInBattle.CurrentHealth > 0);
                //Debug.Assert(Battlefield.Tiles[hb.Coord.Y, hb.Coord.X].Unit == null);

                ActiveHeroes.Add(hb);
                AllHeroes.Add(hb);
                //Battlefield.Tiles[hb.Coord.Y, hb.Coord.X].Unit = hb;
            }
        }
コード例 #3
0
        private int CalcHealthPlayer(BattleParticipant p)
        {
            int health = 0;

            foreach (HeroInBattle h in battle.ActiveHeroes)
            {
                if (h.Player == p)
                {
                    health += h.CurrentHealth;
                }
            }

            return(health);
        }
コード例 #4
0
        private static int sequenceID = 0;// Генератор уникального кода героя

        public Creature(TypeCreature tc, BattleParticipant bp)
        {
            TypeCreature      = tc;
            BattleParticipant = bp;
            ID = ++sequenceID;

            StateCreature = TypeCreature.PersistentStateHeroAtMap;

            // Применяем дефолтные способности
            Abilities.AddRange(TypeCreature.Abilities);
            Specialization = FormMain.Config.FindSpecialization("SpeedMove");
            SecondarySkills.Add(FormMain.Config.FindSecondarySkill("Health"));

            // Берем оружие и доспехи
            MeleeWeapon = TypeCreature.WeaponMelee;
            RangeWeapon = TypeCreature.WeaponRange;
            Armour      = TypeCreature.Armour;

            if (TypeCreature.MaxLevel > 1)
            {
                Level = 0;

                ParametersBase = new HeroParameters(TypeCreature.ParametersByHire);

                // Переходим на 1 уровень
                LevelUp();
                ParametersWithAmmunition = new HeroParameters(ParametersBase);

                //
                UpdateBaseParameters();
            }
            else
            {
                Level = 1;
            }
        }
コード例 #5
0
        // Поиск пути
        public bool Pathfind(BattlefieldTile fromTile, BattlefieldTile toTile, BattleParticipant throughPlayer)
        {
            Debug.Assert(fromTile != null);
            Debug.Assert(toTile != null);
            Debug.Assert(fromTile != toTile);

            _path = new List <BattlefieldTile>();// Наиболее легкий найденный путь

            // Если это соседняя ячейка, то не надо искать путь
            if (fromTile.IsNeighbourTile(toTile))
            {
                // Если клетка зарезервирована или на ней есть юнит, идти на нее нельзя
                if ((toTile.ReservedForMove != null) || (toTile.Unit != null))
                {
                    return(false);
                }

                _path.Add(toTile);
                return(true);
            }

            // Если режим прохода сквозь юнита, то проверяем, есть ли вокруг ячейки для прохода
            // Если нет, выходиим
            if (throughPlayer != null)
            {
                bool foundedFree = false;
                foreach (BattlefieldTile t in fromTile.TilesAround)
                {
                    if ((t.Unit == null) && (t.ReservedForMove == null))
                    {
                        foundedFree = true;
                        break;
                    }
                }

                if (!foundedFree)
                {
                    return(false);
                }
            }

            // Очистка данных
            foreach (BattlefieldTile t in closedSet)
            {
                t.ClearPathData();
            }
            closedSet.Clear();

            foreach (BattlefieldTile t in openSet)
            {
                t.ClearPathData();
            }
            openSet.Clear();

            // Ищем путь
            FindPath(fromTile, toTile, throughPlayer);

            Debug.Assert((_path.Count() == 0) || fromTile.IsNeighbourTile(_path.First()));
            Debug.Assert((_path.Count() == 0) || (_path.Last() == toTile));

            return(_path.Count() > 0);
        }
コード例 #6
0
        public void FindPath(BattlefieldTile sourceTile, BattlefieldTile destTile, BattleParticipant throughPlayer)
        {
            Debug.Assert(sourceTile.Unit != null);

            BattlefieldTile currentNode;
            int             lengthFromStart;
            //List<BattlefieldTile> path = new List<BattlefieldTile>();
            BattlefieldTile bestTile = null;

            // Стартуем с начальной ячейки
            openSet.Add(sourceTile);
            sourceTile.State = StateTile.Opened;

            // Цикл, пока есть открытые (необработанные) клетки
            while (openSet.Count > 0)
            {
                // Текущая ячейка - с наименьшим числом отставшегося пути
                bestTile = openSet.First();

                foreach (BattlefieldTile t in openSet)
                {
                    if (t.EstimateFullPathLength < bestTile.EstimateFullPathLength)
                    {
                        currentNode = t;
                    }
                }
                Debug.Assert(bestTile != null);
                currentNode = bestTile;

                // Если пришли к конечной точке - строим путь и выходим
                if (currentNode == destTile)
                {
                    BuildPathForNode(currentNode);
                    return;
                }

                // Убираем ячейку из необработанных и добавляем в обработанные
                if (!openSet.Remove(currentNode))
                {
                    throw new Exception("Ячейка не удалена из списка.");
                }
                closedSet.Add(currentNode);// Только для того, чтобы по ней потом очистить данные для поиска пути
                currentNode.State = StateTile.Closed;

                foreach (BattlefieldTile neighbourNode in currentNode.TilesAround)
                {
                    // Если клетка недоступна, просто пропускаем ее
                    if (neighbourNode.State == StateTile.Unavailable)
                    {
                        continue;
                    }

                    // Если зарезервирована соседняя от начала пути ячейки, то обходим её
                    // Когда сделаем шаг, она может быть уже не зарезервирована, поэтому продолжим тот же путь
                    if ((neighbourNode.ReservedForMove != null) && neighbourNode.IsNeighbourTile(sourceTile))
                    {
                        neighbourNode.State = StateTile.Unavailable;
                        openSet.Remove(neighbourNode);
                        closedSet.Add(neighbourNode);

                        continue;
                    }

                    // Если на клетке есть юнит и это не клетка назначения, то пропускаем её
                    if ((neighbourNode.Unit != null) && (neighbourNode != destTile) && !((throughPlayer != null) && (neighbourNode.Unit.Player == throughPlayer)))
                    {
                        neighbourNode.State = StateTile.Unavailable;
                        openSet.Remove(neighbourNode);
                        closedSet.Add(neighbourNode);

                        continue;
                    }

                    //
                    lengthFromStart = currentNode.PathLengthFromStart + currentNode.GetDistanceToTile(neighbourNode);
                    if (((neighbourNode.PathLengthFromStart == 0) || (lengthFromStart < neighbourNode.PathLengthFromStart)) && (neighbourNode != sourceTile))
                    {
                        neighbourNode.PathLengthFromStart         = lengthFromStart;
                        neighbourNode.HeuristicEstimatePathLength = neighbourNode.GetHeuristicPathLength(destTile);
                        neighbourNode.EstimateFullPathLength      = neighbourNode.PathLengthFromStart + neighbourNode.HeuristicEstimatePathLength;
                        neighbourNode.PriorTile = currentNode;
                    }

                    if (neighbourNode.State == StateTile.Undefined)
                    {
                        openSet.Add(neighbourNode);
                        neighbourNode.State = StateTile.Opened;
                    }
                }
            }

            return;
        }
コード例 #7
0
 public PlayerHero(PlayerBuilding pb, BattleParticipant bp, TypeHero th) : base(th, bp)
 {
     Building  = pb;
     DayOfHire = Player.Lobby.Turn;
     TypeHero  = th;
 }
コード例 #8
0
 public PlayerHero(PlayerBuilding pb, BattleParticipant bp) : base(pb.Building.TrainedHero, bp)
 {
     Building  = pb;
     DayOfHire = Player.Lobby.Turn;
     TypeHero  = pb.Building.TrainedHero;
 }