Ejemplo n.º 1
0
        internal static async Task <bool> RandomlyAttack(GameController game, WorldController world, RegionController regions, Guid sessionId, String ownerId, UInt32 troopCount)
        {
            ISession session = await game.GetSession(sessionId);

            // Get owned regions
            IEnumerable <Guid> ownedRegions = await GetCurrentlyOwnedRegions(world, sessionId, ownerId);

            bool hasAttacked = false;

            foreach (Guid ownedRegionId in ownedRegions)
            {
                IRegion details = await regions.GetDetails(sessionId, ownedRegionId);

                if (details.TroopCount > 1)
                {
                    foreach (Guid adjacentRegionId in details.ConnectedRegions)
                    {
                        IRegion targetDetails = await regions.GetDetails(sessionId, adjacentRegionId);

                        if (targetDetails.OwnerId != ownerId)
                        {
                            UInt32 troopsToAttackWith = Math.Min(details.TroopCount - 1, troopCount);
                            await regions.PostAttack(sessionId, ownedRegionId, troopsToAttackWith, adjacentRegionId);

                            hasAttacked = true;
                            break;
                        }
                    }
                }

                if (hasAttacked)
                {
                    break;
                }
            }

            // End attack phase
            await game.PostEndPhase(session.GameId, session.PhaseId);

            return(hasAttacked);
        }
Ejemplo n.º 2
0
        internal static async Task RandomlyRedeployTroops(GameController game, WorldController world, RegionController regions, Guid sessionId, String ownerId)
        {
            ISession session = await game.GetSession(sessionId);

            // Get owned regions
            IEnumerable <Guid> ownedRegions = await GetCurrentlyOwnedRegions(world, sessionId, ownerId);

            bool hasRedeployed = false;

            foreach (Guid ownedRegionId in ownedRegions)
            {
                IRegion details = await regions.GetDetails(sessionId, ownedRegionId);

                if (details.TroopCount > 1)
                {
                    foreach (Guid adjacentRegionId in details.ConnectedRegions)
                    {
                        if (ownedRegions.Contains(adjacentRegionId))
                        {
                            await regions.PostRedeployTroops(sessionId, ownedRegionId, details.TroopCount - 1, adjacentRegionId);

                            hasRedeployed = true;
                            break;
                        }
                    }
                }

                if (hasRedeployed)
                {
                    break;
                }
            }

            // End redeployment
            await game.PostEndPhase(session.GameId, session.PhaseId);
        }