コード例 #1
0
        public StoredCounterBase Map(CounterBase source, StoredCounterBase destination)
        {
            StoredCounterBase destinationCounter = null;
            var genericCounter = source as GenericCounter;

            if (genericCounter != null)
            {
                var genericDestination = new StoredGenericCounter
                {
                    BonusPercent = genericCounter.BonusPercentage,
                    CurrentSteps = genericCounter.CurrentSteps,
                    Inflation    = genericCounter.Inflation
                };
                destinationCounter = genericDestination;
            }

            var singleCounter = source as SingleCounter;

            if (singleCounter != null)
            {
                destinationCounter = new StoredSingleCounter {
                    Value = singleCounter.Value
                };
            }
            if (destinationCounter != null)
            {
                MapCommon(source, destinationCounter);
            }

            var delayedCounter = source as DelayedCounter;

            if (delayedCounter != null)
            {
                destinationCounter = new StoredDelayedCounter
                {
                    SecondsRemaining = delayedCounter.SecondsRemaining,
                    DelayedValue     = delayedCounter.SubValue
                };
            }
            if (destinationCounter != null)
            {
                MapCommon(source, destinationCounter);
            }

            return(destinationCounter);
        }
コード例 #2
0
        private StoredCounterBase[] PrepareCountersToPersist(IGame game)
        {
            var counters = new StoredCounterBase[game.GameCash.Counters.Length];

            foreach (var sourceCounter in game.GameCash.Counters)
            {
                StoredCounterBase destinationCouner = null;
                var sourcenGenericCounter           = sourceCounter as GenericCounter;
                if (sourcenGenericCounter != null)
                {
                    var destinationGenericCounter = new StoredGenericCounter
                    {
                        BonusPercent = sourcenGenericCounter.BonusPercentage,
                        Inflation    = sourcenGenericCounter.Inflation,
                        CurrentSteps = sourcenGenericCounter.CurrentSteps
                    };
                    destinationCouner = destinationGenericCounter;
                }
                var sourceSingleCounter = sourceCounter as SingleCounter;
                if (sourceSingleCounter != null)
                {
                    destinationCouner = new StoredSingleCounter();
                }
                var sourceDelayedCounter = sourceCounter as DelayedCounter;
                if (sourceDelayedCounter != null)
                {
                    var destinationDelayedCounter = new StoredDelayedCounter
                    {
                        SecondsRemaining = sourceDelayedCounter.SecondsRemaining,
                        DelayedValue     = sourceDelayedCounter.SubValue
                    };
                    destinationCouner = destinationDelayedCounter;
                }
                if (destinationCouner != null)
                {
                    destinationCouner.Id    = sourceCounter.Id;
                    destinationCouner.Value = sourceCounter.Value;
                }
                if (destinationCouner != null)
                {
                    counters[destinationCouner.Id] = destinationCouner;
                }
            }
            return(counters);
        }