public void SetAvailableReinforcements(IBatchOperationHandle batchOperationHandle, Guid sessionId, string userId, string currentEtag, uint reinforcements)
        {
            DummySession foundSession = SessionRepository.SessionMap[sessionId];
            DummyBatchOperationHandle batchOperation = batchOperationHandle as DummyBatchOperationHandle;

            if (foundSession != null)
            {
                DummyNationData foundPlayer = foundSession.Players.Find(player => player.UserId == userId);
                if (foundPlayer != null)
                {
                    batchOperation.QueuedOperations.Add(() =>
                    {
                        foundPlayer.AvailableReinforcements = reinforcements;
                    });
                }
                else
                {
                    throw new InvalidOperationException("Called MarkPlayerCompletedPhase with a non-existent user id");
                }
            }
            else
            {
                throw new InvalidOperationException("Called JoinSession with a non-existent GUID");
            }
        }
 static public ControllerMockSetupContext SetupCardOwner(this ControllerMockSetupContext setupContext, String userId, Guid regionId)
 {
     using (DummyBatchOperationHandle batchOperation = new DummyBatchOperationHandle())
     {
         setupContext.ControllerMock.NationRepository.SetCardOwner(batchOperation, setupContext.DummySession.GameId, regionId, userId, String.Empty);
     }
     return(setupContext);
 }
 static public ControllerMockSetupContext SetupAvailableReinforcements(this ControllerMockSetupContext setupContext, String userId, UInt32 availableReinforcements)
 {
     using (DummyBatchOperationHandle batchOperation = new DummyBatchOperationHandle())
     {
         setupContext.ControllerMock.NationRepository.SetAvailableReinforcements(batchOperation, setupContext.DummySession.GameId, userId, String.Empty, availableReinforcements);
     }
     return(setupContext);
 }
Example #4
0
        public void RemoveCommand(IBatchOperationHandle batchOperationHandle, ICommandQueueMessage message)
        {
            DummyBatchOperationHandle dummyBatch = batchOperationHandle as DummyBatchOperationHandle;

            dummyBatch.QueuedOperations.Add(() =>
            {
                DummyDeployReinforcementsQueue.RemoveAll(queuedMessage => message.OperationId == queuedMessage.OperationId);
                DummyOrderAttackQueue.RemoveAll(queuedMessage => message.OperationId == queuedMessage.OperationId);
                DummyRedeployQueue.RemoveAll(queuedMessage => message.OperationId == queuedMessage.OperationId);
            });
        }
        public void CommitTroopsToPhase(IBatchOperationHandle batchOperationHandleInterface, IRegionData sourceRegion, UInt32 troopsToCommit)
        {
            DummyBatchOperationHandle batchOperationHandle = batchOperationHandleInterface as DummyBatchOperationHandle;
            DummyRegionData           region = sourceRegion as DummyRegionData;

            if (region != null && region.TroopCount > region.TroopsCommittedToPhase + troopsToCommit)
            {
                batchOperationHandle.QueuedOperations.Add(() =>
                {
                    region.TroopsCommittedToPhase += troopsToCommit;
                });
            }
            else
            {
                throw new InvalidOperationException("Invalid arguments passed");
            }
        }
        public void CreateRegion(IBatchOperationHandle batchOperationHandleInterface, Guid sessionId, Guid regionId, Guid continentId, String name, IEnumerable <Guid> connectedRegions, UInt32 cardValue)
        {
            DummyBatchOperationHandle batchOperationHandle = batchOperationHandleInterface as DummyBatchOperationHandle;

            batchOperationHandle.QueuedOperations.Add(() =>
            {
                RegionData[regionId] = new DummyRegionData(sessionId, regionId, continentId, String.Empty, cardValue);
                foreach (Guid connectedRegion in connectedRegions)
                {
                    RegionData[regionId].ConnectedRegionIds.Add(connectedRegion);
                }
            });
            batchOperationHandle.QueuedOperations.Add(() =>
            {
                CardData[regionId] = new DummyCardData(regionId, cardValue);
            });
        }
        public Task ResetDiscardedCards(IBatchOperationHandle batchOperationHandle, Guid sessionId)
        {
            DummyBatchOperationHandle batchOperation = batchOperationHandle as DummyBatchOperationHandle;
            List <ICardData>          results        = new List <ICardData>();

            foreach (DummyCardData card in RegionRepository.CardData.Values)
            {
                if (card.OwnerId == DummyCardData.UsedCard)
                {
                    batchOperation.QueuedOperations.Add(() =>
                    {
                        card.OwnerId = DummyCardData.UnownedCard;
                    });
                    results.Add(card);
                }
            }
            return(Task.FromResult(0));
        }
Example #8
0
        public Task <Guid> OrderAttack(IBatchOperationHandle batchOperationHandle, Guid sessionId, Guid phaseId, Guid sourceRegion, String sourceRegionEtag, Guid targetRegion, UInt32 numberOfTroops)
        {
            DummyBatchOperationHandle batchOperation = batchOperationHandle as DummyBatchOperationHandle;
            Guid operationId = Guid.NewGuid();

            batchOperation.QueuedOperations.Add(() =>
            {
                DummyOrderAttackQueue.Add(new DummyOrderAttack
                {
                    OperationId      = operationId,
                    PhaseId          = phaseId,
                    SourceRegion     = sourceRegion,
                    SourceRegionEtag = sourceRegionEtag,
                    TargetRegion     = targetRegion,
                    NumberOfTroops   = numberOfTroops
                });
            });
            return(Task.FromResult(operationId));
        }
Example #9
0
        public void AddCombat(IBatchOperationHandle batchOperationHandleInterface, Guid sessionId, UInt32 round, IEnumerable <Tuple <CombatType, IEnumerable <ICombatArmy> > > armies)
        {
            List <Guid> createdCombatIds = new List <Guid>();

            foreach (var combatData in armies)
            {
                Guid        combatId = Guid.NewGuid();
                DummyCombat combat   = new DummyCombat(combatId, combatData.Item1);
                createdCombatIds.Add(combatId);

                foreach (ICombatArmy army in combatData.Item2)
                {
                    combat.SetupAddArmy(army.OriginRegionId, army.OwnerUserId, army.ArmyMode, army.NumberOfTroops);
                }

                DummyBatchOperationHandle batchOperationHandle = batchOperationHandleInterface as DummyBatchOperationHandle;
                batchOperationHandle.QueuedOperations.Add(() =>
                {
                    // Add to lookup
                    AddToCombatLookup(combat);

                    // Add to typed storage
                    switch (combat.ResolutionType)
                    {
                    case CombatType.BorderClash:
                        BorderClashes[combatId] = combat;
                        break;

                    case CombatType.MassInvasion:
                        MassInvasions[combatId] = combat;
                        break;

                    case CombatType.Invasion:
                        Invasions[combatId] = combat;
                        break;

                    case CombatType.SpoilsOfWar:
                        SpoilsOfWar[combatId] = combat;
                        break;
                    }
                });
            }
        }
Example #10
0
        public void AssignRegionOwnership(IBatchOperationHandle batchOperationHandleInterface, IEnumerable <IRegionData> regions, Dictionary <Guid, OwnershipChange> ownershipChanges)
        {
            DummyBatchOperationHandle batchOperationHandle = batchOperationHandleInterface as DummyBatchOperationHandle;

            foreach (var change in ownershipChanges)
            {
                if (RegionData.ContainsKey(change.Key))
                {
                    DummyRegionData regionData = RegionData[change.Key];
                    batchOperationHandle.QueuedOperations.Add(() =>
                    {
                        regionData.OwnerId                = change.Value.UserId;
                        regionData.TroopCount             = change.Value.TroopCount;
                        regionData.TroopsCommittedToPhase = 0;
                        regionData.GenerateNewEtag();
                    });
                }
                else
                {
                    throw new InvalidOperationException("Invalid region id specified");
                }
            }
        }
Example #11
0
        public void SetCardOwnerInternal(IBatchOperationHandle batchOperationHandle, Guid sessionId, Guid regionId, String userId, String currentEtag)
        {
            DummySession foundSession = SessionRepository.SessionMap[sessionId];

            if (foundSession != null)
            {
                if (RegionRepository.CardData.ContainsKey(regionId))
                {
                    DummyBatchOperationHandle batchOperation = batchOperationHandle as DummyBatchOperationHandle;
                    batchOperation.QueuedOperations.Add(() =>
                    {
                        RegionRepository.CardData[regionId].OwnerId = userId;
                    });
                }
                else
                {
                    throw new InvalidOperationException("Called SetCardOwner with a non-existent region id");
                }
            }
            else
            {
                throw new InvalidOperationException("Called SetCardOwner with a non-existent session id");
            }
        }