Пример #1
0
        public Task <Guid> OrderAttack(IBatchOperationHandle batchOperationHandleInterface, Guid sessionId, Guid phaseId, Guid sourceRegion, String sourceRegionEtag, Guid targetRegion, UInt32 numberOfTroops)
        {
            BatchOperationHandle batchOperationHandle = batchOperationHandleInterface as BatchOperationHandle;
            CloudTable           commandQueueTable    = GetCommandQueueTableForSession(sessionId);
            Guid operationId = Guid.NewGuid();

            TableOperation operation       = TableOperation.Retrieve <CommandQueueTableEntry>(sessionId.ToString(), "Command_" + sourceRegion.ToString() + "_" + targetRegion.ToString());
            var            orderAttackTask = commandQueueTable.ExecuteAsync(operation)
                                             .ContinueWith(getExistingTask =>
            {
                TableResult getExistingResult = getExistingTask.Result;
                if (getExistingResult.Result != null)
                {
                    // Update existing entry
                    CommandQueueTableEntry existingCommand = getExistingResult.Result as CommandQueueTableEntry;
                    existingCommand.OperationId            = operationId;
                    existingCommand.RawNumberOfTroops     += (int)numberOfTroops;

                    // Kick off update operation
                    batchOperationHandle.BatchOperation.Replace(existingCommand);
                }
                else
                {
                    // Create a new table entry
                    CommandQueueTableEntry newCommand = CommandQueueTableEntry.CreateAttackMessage(operationId, sessionId, phaseId, sourceRegion, sourceRegionEtag, targetRegion, numberOfTroops);

                    // Kick off the insert operation
                    batchOperationHandle.BatchOperation.Insert(newCommand);
                }
            });

            batchOperationHandle.AddPrerequisite(orderAttackTask, 1);

            return(Task.FromResult(operationId));
        }
Пример #2
0
        public void AssignRegionOwnership(IBatchOperationHandle batchOperationHandleInterface, Guid sessionId, Dictionary <Guid, OwnershipChange> ownershipChanges)
        {
            BatchOperationHandle batchOperationHandle = batchOperationHandleInterface as BatchOperationHandle;

            // Get the session data table
            CloudTable sessionDataTable = SessionRepository.GetTableForSessionData(TableClient, sessionId);

            // Fetch all regions (quicker than fetching only what we need, one by one)
            var updateRegionOwnershipTask = GetRegions(sessionId)
                                            .ContinueWith(regionTask => { AssignRegionOwnership(batchOperationHandleInterface, regionTask.Result, ownershipChanges); });

            batchOperationHandle.AddPrerequisite(updateRegionOwnershipTask, ownershipChanges.Count);
        }
Пример #3
0
        public void SetAvailableReinforcements(IBatchOperationHandle batchOperationHandleInterface, Guid sessionId, String userId, String currentEtag, UInt32 reinforcements)
        {
            BatchOperationHandle batchOperationHandle = batchOperationHandleInterface as BatchOperationHandle;

            // Get the session data table
            CloudTable sessionDataTable = SessionRepository.GetTableForSessionData(TableClient, sessionId);

            // Create a DynamicTableEntity so that we can do a partial update of this table (a merge)
            DynamicTableEntity nationEntry = NationTableEntry.CreateDynamicTableEntity(sessionId, userId, currentEtag);

            NationTableEntry.SetAvailableReinforcements(nationEntry, reinforcements);
            batchOperationHandle.BatchOperation.Merge(nationEntry);
        }
Пример #4
0
        private void SetCardInternal(IBatchOperationHandle batchOperationHandleInterface, Guid sessionId, Guid regionId, CardTableEntry.State newState, String newOwnerId, String currentEtag)
        {
            BatchOperationHandle batchOperationHandle = batchOperationHandleInterface as BatchOperationHandle;

            // Get the session data table
            CloudTable sessionDataTable = SessionRepository.GetTableForSessionData(TableClient, sessionId);

            // Create a DynamicTableEntity so that we can do a partial update of this table (a merge)
            DynamicTableEntity cardEntry = CardTableEntry.CreateDynamicTableEntity(sessionId, regionId, currentEtag);

            CardTableEntry.SetOwner(cardEntry, newState, newOwnerId);
            batchOperationHandle.BatchOperation.Merge(cardEntry);
        }
Пример #5
0
        public void CommitTroopsToPhase(IBatchOperationHandle batchOperationHandleInterface, IRegionData sourceRegion, UInt32 troopsToCommit)
        {
            BatchOperationHandle batchOperationHandle = batchOperationHandleInterface as BatchOperationHandle;
            RegionTableEntry     region = sourceRegion as RegionTableEntry;

            if (region != null && region.TroopCount > region.TroopsCommittedToPhase + troopsToCommit)
            {
                region.StoredTroopsCommittedToPhase += (int)troopsToCommit;
                batchOperationHandle.BatchOperation.Replace(region);
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
Пример #6
0
        public void AddCombat(IBatchOperationHandle batchOperationHandleInterface, Guid sessionId, UInt32 round, IEnumerable <Tuple <CombatType, IEnumerable <ICombatArmy> > > armies)
        {
            BatchOperationHandle batchOperationHandle = batchOperationHandleInterface as BatchOperationHandle;

            // Insert armies
            List <Guid> createdCombatIds = new List <Guid>();

            foreach (var armyEntry in armies)
            {
                Guid             combatId = Guid.NewGuid();
                CombatTableEntry entry    = new CombatTableEntry(sessionId, round, combatId, armyEntry.Item1);
                entry.SetCombatArmy(armyEntry.Item2);
                batchOperationHandle.BatchOperation.Insert(entry);
                createdCombatIds.Add(combatId);
            }
        }
Пример #7
0
        public void AddArmyToCombat(IBatchOperationHandle batchOperationHandleInterface, ICombat combat, IEnumerable <ICombatArmy> armies)
        {
            BatchOperationHandle batchOperationHandle = batchOperationHandleInterface as BatchOperationHandle;
            CombatTableEntry     combatEntry          = combat as CombatTableEntry;

            combatEntry.IsValid();

            List <ICombatArmy> existingArmies = combat.InvolvedArmies.ToList();

            foreach (var army in armies)
            {
                existingArmies.Add(new CombatArmy(army.OriginRegionId, army.OwnerUserId, army.ArmyMode, army.NumberOfTroops));
            }
            combatEntry.SetCombatArmy(existingArmies);

            batchOperationHandle.BatchOperation.Replace(combatEntry);
        }
Пример #8
0
        public void CreateRegion(IBatchOperationHandle batchOperationHandleInterface, Guid sessionId, Guid regionId, Guid continentId, String name, IEnumerable <Guid> connectedRegions, UInt32 cardValue)
        {
            BatchOperationHandle batchOperationHandle = batchOperationHandleInterface as BatchOperationHandle;

            // Create a new table entry
            RegionTableEntry newRegion = new RegionTableEntry(sessionId, regionId, continentId, name, cardValue);

            newRegion.IsValid();
            newRegion.SetConnectedRegions(connectedRegions);
            batchOperationHandle.BatchOperation.Insert(newRegion);

            // Create a new card for this region
            CardTableEntry newCard = new CardTableEntry(sessionId, regionId);

            newCard.IsValid();
            newCard.ValueRaw = (Int32)cardValue;
            batchOperationHandle.BatchOperation.Insert(newCard);
        }
Пример #9
0
        public void AssignRegionOwnership(IBatchOperationHandle batchOperationHandleInterface, IEnumerable <IRegionData> regions, Dictionary <Guid, OwnershipChange> ownershipChanges)
        {
            BatchOperationHandle batchOperationHandle = batchOperationHandleInterface as BatchOperationHandle;

            // Get NationTableEntry for every player that needs updating
            var updateOperations = from ownershipChange in ownershipChanges
                                   join region in regions.Cast <RegionTableEntry>() on ownershipChange.Key equals region.RegionId
                                   select new { Region = region, NewOwner = ownershipChange.Value.UserId, NewTroopCount = (Int32)ownershipChange.Value.TroopCount };

            // Modify entries as required
            foreach (var operation in updateOperations)
            {
                RegionTableEntry regionEntry = operation.Region;
                regionEntry.IsValid();
                regionEntry.OwnerId                      = operation.NewOwner;
                regionEntry.StoredTroopCount             = operation.NewTroopCount;
                regionEntry.StoredTroopsCommittedToPhase = 0;
                batchOperationHandle.BatchOperation.Replace(regionEntry);
            }
        }