Пример #1
0
        private void ExecuteMoves(Dictionary <string, List <Tuple <int, int, int> > > playerMoves)
        {
            foreach (var player in playerMoves.Keys)
            {
                foreach (var move in playerMoves[player])
                {
                    var numGuysToMove = move.Item3;
                    if (numGuysToMove < 1)
                    {
                        continue;
                    }

                    var sourceFort = GetFortByID(move.Item1);
                    var destFort   = GetFortByID(move.Item2);
                    if (sourceFort == null || destFort == null || sourceFort.FortOwner != player || sourceFort.NumDefendingGuys < numGuysToMove)
                    {
                        continue;
                    }

                    sourceFort.NumDefendingGuys -= numGuysToMove;
                    var distanceBetweenForts = GetDistanceTo(sourceFort.Location, destFort.Location);
                    var gg = new GuyGroup {
                        DestinationFortID = destFort.ID, GroupOwner = player, NumGuys = numGuysToMove, TicksTillFinished = (int)distanceBetweenForts
                    };
                    TravelingGGs.Add(gg);
                }
            }
        }
Пример #2
0
        private void EnterFort(GuyGroup gg)
        {
            var destFort = GetFortByID(gg.DestinationFortID);

            if (gg.GroupOwner == destFort.FortOwner)
            {
                destFort.NumDefendingGuys += gg.NumGuys;
                gg.NumGuys = 0;
            }
            else
            {
                destFort.NumDefendingGuys -= gg.NumGuys;
                if (destFort.NumDefendingGuys < 0)
                {
                    destFort.FortOwner         = gg.GroupOwner;
                    destFort.NumDefendingGuys *= -1;
                    gg.NumGuys = 0;
                }
            }
        }
Пример #3
0
        private void ExecuteMoves(Dictionary <string, List <Move> > playerMoves)
        {
            foreach (var player in playerMoves.Keys)
            {
                foreach (var move in playerMoves[player])
                {
                    var numGuysToMove = move.NumGuys;
                    if (numGuysToMove < 1)
                    {
                        continue;
                    }

                    var sourceFort = GetFortByID(move.SourceFortID);
                    var destFort   = GetFortByID(move.DestinationFortID);
                    var toRemove   = sourceFort.DefendingGuys.Where(g => g.Type == move.GuyType).Take(numGuysToMove).ToList();

                    if (sourceFort == null || destFort == null || sourceFort.FortOwner != player || toRemove.Count < numGuysToMove)
                    {
                        continue;
                    }

                    // only remove the amount requested, not all
                    var toMove = new List <Guy>();
                    for (var i = 0; i < numGuysToMove; i++)
                    {
                        sourceFort.DefendingGuys.Remove(toRemove[i]);
                        toMove.Add(toRemove[i]);
                    }

                    var distanceBetweenForts = GetDistanceBetween(sourceFort.Location, destFort.Location);
                    var gg = new GuyGroup {
                        SourceFort = sourceFort, DestinationFort = destFort, GroupOwner = player, Guys = toMove, TicksTillFinished = (int)distanceBetweenForts / toMove[0].Speed
                    };
                    TravelingGGs.Add(gg);
                }
            }
        }
Пример #4
0
        private void EnterFort(GuyGroup gg)
        {
            var destFort = gg.DestinationFort;

            // if fort is empty
            if (destFort.FortOwner == null)
            {
                destFort.FortOwner     = gg.GroupOwner;
                destFort.DefendingGuys = gg.Guys;
                gg.Guys = new List <Guy>();
            }
            // if player is reinforcing
            else if (gg.GroupOwner == destFort.FortOwner)
            {
                destFort.DefendingGuys.Concat(gg.Guys);
                gg.Guys = new List <Guy>();
            }
            // if player is attacking
            else
            {
                // each team stabs each other at the same time, and then deaths are calculated
                while (gg.Guys.Count > 0 && destFort.DefendingGuys.Count > 0)
                {
                    var totalAttackerDmg = gg.Guys.Sum(g => g.Strength);
                    var totalDefenderDmg = destFort.DefendingGuys.Sum(g => g.Strength);

                    var numAttackers = gg.Guys.Count;
                    var numDefenders = destFort.DefendingGuys.Count;

                    // apply damage to defenders
                    for (var i = 0; i < totalAttackerDmg; i++)
                    {
                        var defender = destFort.DefendingGuys[i % numDefenders];
                        if (defender.Health > 0)
                        {
                            defender.Health--;
                        }
                    }

                    // apply damage to attackers
                    for (var i = 0; i < totalDefenderDmg; i++)
                    {
                        var attacker = gg.Guys[i % numAttackers];
                        if (attacker.Health > 0)
                        {
                            attacker.Health--;
                        }
                    }

                    // remove dead guys from lists
                    gg.Guys.RemoveAll(g => g.Health <= 0);
                    destFort.DefendingGuys.RemoveAll(g => g.Health <= 0);
                }

                // draw
                if (gg.Guys.Count == 0 && destFort.DefendingGuys.Count == 0)
                {
                    // do nothing
                }
                // defender wins
                else if (gg.Guys.Count == 0)
                {
                    // do nothing
                }
                // attacker wins
                else
                {
                    destFort.FortOwner     = gg.GroupOwner;
                    destFort.DefendingGuys = gg.Guys;
                    gg.Guys = new List <Guy>();
                }
            }
        }