示例#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
        public async Task <bool> ReservePlayerColour(Guid sessionId, String sessionEtag, PlayerColour colour)
        {
            await StorageDelaySimulationTask;

            if (SessionMap.ContainsKey(sessionId))
            {
                DummySession session = SessionMap[sessionId];
                if (session.CurrentEtag == sessionEtag)
                {
                    var colourQuery = from player in session.Players
                                      where player.Colour == colour
                                      select player;
                    if (colourQuery.Count() == 0)
                    {
                        session.GenerateNewEtag();
                        return(true);
                    }
                    else
                    {
                        // Already taken
                        return(false);
                    }
                }
                else
                {
                    // Doesn't match!
                    throw new ConcurrencyException();
                }
            }
            else
            {
                throw new InvalidOperationException("Shouldn't call ReservePlayerColour with an invalid session GUID");
            }
        }
示例#3
0
        public Task SetSessionPhase(Guid sessionId, Guid currentPhaseId, SessionPhase newPhase)
        {
            DummySession foundSession = SessionMap[sessionId];

            if (foundSession != null)
            {
                if (foundSession.PhaseId == currentPhaseId)
                {
                    foundSession.SetupSessionPhase(newPhase);
                    if (newPhase == SessionPhase.Victory)
                    {
                        foundSession.Round += 1;
                    }
                    return(Task.FromResult(false));
                }
                else
                {
                    throw new ConcurrencyException();
                }
            }
            else
            {
                throw new InvalidOperationException("Called JoinSession with a non-existant GUID");
            }
        }
示例#4
0
        static public ControllerMockSetupContext SetupDummySession(this ControllerMock controller, Guid sessionId, String ownerId, PlayerColour colour)
        {
            DummySession session = controller.SessionRepository.SetupDummySession(sessionId, ownerId, colour);

            return(new ControllerMockSetupContext {
                ControllerMock = controller, DummySession = session
            });
        }
示例#5
0
        internal DummySession SetupDummySession(Guid sessionId, String ownerId, PlayerColour colour)
        {
            DummySession session = new DummySession {
                GameId = sessionId, OwnerId = ownerId
            };

            session.SetupAddPlayer(ownerId, colour);
            SessionMap[sessionId] = session;
            return(session);
        }
示例#6
0
        public async Task <Guid> CreateSession(String userId, PlayerColour colour)
        {
            Guid newId = Guid.NewGuid();

            SessionMap[newId] = new DummySession {
                GameId = newId, OwnerId = userId
            };
            await JoinSession(newId, userId, colour);

            return(newId);
        }
示例#7
0
        public Task <IEnumerable <INationData> > GetNations(Guid sessionId)
        {
            DummySession foundSession = SessionRepository.SessionMap[sessionId];

            if (foundSession != null)
            {
                IEnumerable <INationData> results = from player in foundSession.Players
                                                    select player;
                return(Task.FromResult(results));
            }
            else
            {
                throw new InvalidOperationException("Called GetNations with a non-existent GUID");
            }
        }
示例#8
0
        public Task <INationData> GetNation(Guid sessionId, string userId)
        {
            DummySession foundSession = SessionRepository.SessionMap[sessionId];

            if (foundSession != null)
            {
                var query = from player in foundSession.Players
                            where player.UserId == userId
                            select player;
                return(Task.FromResult <INationData>(query.FirstOrDefault()));
            }
            else
            {
                throw new InvalidOperationException("Called GetNation with a non-existent GUID");
            }
        }
示例#9
0
        public Task JoinSession(Guid sessionId, String userId, PlayerColour colour)
        {
            DummySession foundSession = SessionMap[sessionId];

            if (foundSession != null)
            {
                foundSession.Players.Add(new DummyNationData(userId)
                {
                    Colour = colour
                });
                foundSession.GenerateNewEtag();
                return(Task.FromResult(false));
            }
            else
            {
                throw new InvalidOperationException("Called JoinSession with a non-existant GUID");
            }
        }
示例#10
0
        public void SetCardOwner(IBatchOperationHandle batchOperationHandle, Guid sessionId, Guid regionId, String userId, String currentEtag)
        {
            DummySession foundSession = SessionRepository.SessionMap[sessionId];

            if (foundSession != null)
            {
                DummyNationData foundPlayer = foundSession.Players.Find(player => player.UserId == userId);
                if (foundPlayer != null)
                {
                    SetCardOwnerInternal(batchOperationHandle, sessionId, regionId, userId, currentEtag);
                }
                else
                {
                    throw new InvalidOperationException("Called SetCardOwner with a non-existent user id");
                }
            }
            else
            {
                throw new InvalidOperationException("Called SetCardOwner with a non-existent session id");
            }
        }
示例#11
0
        public Task MarkPlayerCompletedPhase(Guid sessionId, String userId, Guid phaseId)
        {
            DummySession foundSession = SessionRepository.SessionMap[sessionId];

            if (foundSession != null)
            {
                DummyNationData foundPlayer = foundSession.Players.Find(player => player.UserId == userId);
                if (foundPlayer != null)
                {
                    foundPlayer.CompletedPhase = phaseId;
                    return(Task.FromResult(false));
                }
                else
                {
                    throw new InvalidOperationException("Called MarkPlayerCompletedPhase with a non-existent user id");
                }
            }
            else
            {
                throw new InvalidOperationException("Called JoinSession with a non-existent GUID");
            }
        }
示例#12
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");
            }
        }