Пример #1
0
        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");
            }
        }
Пример #2
0
 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);
 }
Пример #3
0
 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);
 }
Пример #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);
            });
        }
Пример #5
0
        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");
            }
        }
Пример #6
0
        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);
            });
        }
Пример #7
0
        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));
        }
Пример #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));
        }
Пример #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;
                    }
                });
            }
        }
Пример #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");
                }
            }
        }
Пример #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");
            }
        }