コード例 #1
0
 private static void SetLocation(ExternalThreatInfo nextThreatInfo, string location, int currentThreatIndex)
 {
     if (nextThreatInfo == null || nextThreatInfo.ZoneLocation.HasValue)
     {
         throw new InvalidOperationException("Error on external threat #" + currentThreatIndex);
     }
     nextThreatInfo.ZoneLocation = TryParseEnum <ZoneLocation>(location);
     if (!nextThreatInfo.ZoneLocation.HasValue)
     {
         throw new InvalidOperationException("Error on external threat #" + currentThreatIndex);
     }
 }
コード例 #2
0
        private static ParseThreatsResult <ExternalThreat> ParseExternalThreats(IEnumerable <string> chunk)
        {
            var externalThreats = new List <ExternalThreat>();
            var bonusThreats    = new List <Threat>();
            var threatTokens    = new Queue <string>(chunk.Skip(1));
            ExternalThreatInfo nextThreatInfo = null;

            while (threatTokens.Any())
            {
                var nextToken = ParseToken(threatTokens.Dequeue());
                if (nextToken == null)
                {
                    throw new InvalidOperationException("Error on external threat #" + (externalThreats.Count + 1));
                }
                switch (nextToken.Item1)
                {
                case "id":
                    if (nextThreatInfo != null)
                    {
                        throw new InvalidOperationException("Error on external threat #" + (externalThreats.Count + 1));
                    }
                    nextThreatInfo = new ExternalThreatInfo {
                        Threat = ExternalThreatFactory.CreateThreat <ExternalThreat>(nextToken.Item2)
                    };
                    if (nextThreatInfo.Threat == null)
                    {
                        throw new InvalidOperationException("Error on external threat #" + (externalThreats.Count + 1));
                    }
                    break;

                case "time":
                    SetTimeAppears(nextThreatInfo, nextToken.Item2, externalThreats.Count + 1);
                    break;

                case "location":
                    SetLocation(nextThreatInfo, nextToken.Item2, externalThreats.Count + 1);
                    break;

                case "extra-internal-threat-id":
                    bonusThreats.Add(SetExtraInternalThreat(nextToken.Item2, nextThreatInfo, externalThreats.Count + 1));
                    break;

                case "extra-external-threat-id":
                    bonusThreats.Add(SetExtraExternalThreat(nextToken.Item2, nextThreatInfo, externalThreats.Count + 1));
                    break;

                default:
                    throw new InvalidOperationException("Error on external threat #" + (externalThreats.Count + 1));
                }
                if (nextThreatInfo != null && nextThreatInfo.IsValid())
                {
                    var threat = nextThreatInfo.Threat;
                    threat.SetInitialPlacement(
                        nextThreatInfo.TimeAppears.GetValueOrDefault(),
                        nextThreatInfo.ZoneLocation.GetValueOrDefault());
                    InitializeBonusThreats(nextThreatInfo);
                    externalThreats.Add(threat);
                    nextThreatInfo = null;
                }
            }
            if (nextThreatInfo != null)
            {
                throw new InvalidOperationException("Error on external threat #" + (externalThreats.Count + 1));
            }
            return(new ParseThreatsResult <ExternalThreat>
            {
                Threats = externalThreats,
                BonusThreats = bonusThreats
            });
        }