예제 #1
0
        private static InternalThreat SetExtraInternalThreat <T>(
            string extraInternalThreatId,
            StandardThreatInfo <T> nextThreatInfo,
            int currentThreatIndex) where T : Threat
        {
            var bonusInternalThreat = InternalThreatFactory.CreateThreat <InternalThreat>(extraInternalThreatId);

            if (nextThreatInfo == null || bonusInternalThreat == null)
            {
                throw new InvalidOperationException("Error on external threat #" + currentThreatIndex);
            }
            AddBonusThreatInfo(nextThreatInfo, bonusInternalThreat);
            return(bonusInternalThreat);
        }
예제 #2
0
 private static IList <ExternalThreat> CreateExternalThreats(IEnumerable <ExternalThreatModel> threatModels, ZoneLocation zone)
 {
     return(threatModels
            .Select(threatModel =>
     {
         var threat = ExternalThreatFactory.CreateThreat <ExternalThreat>(threatModel.Id);
         threat.SetInitialPlacement(threatModel.TimeAppears, zone);
         if (threat.NeedsBonusInternalThreat)
         {
             ((IThreatWithBonusThreat <InternalThreat>)threat).BonusThreat = InternalThreatFactory.CreateThreat <InternalThreat>(threatModel.BonusInternalThreat.Id);
         }
         if (threat.NeedsBonusExternalThreat)
         {
             ((IThreatWithBonusThreat <ExternalThreat>)threat).BonusThreat = ExternalThreatFactory.CreateThreat <ExternalThreat>(threatModel.BonusExternalThreat.Id);
         }
         return threat;
     })
            .ToList());
 }
예제 #3
0
        private static ParseThreatsResult <InternalThreat> ParseInternalThreats(IEnumerable <string> chunk)
        {
            var internalThreats = new List <InternalThreat>();
            var bonusThreats    = new List <Threat>();
            var threatTokens    = new Queue <string>(chunk.Skip(1));
            InternalThreatInfo nextThreatInfo = null;

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

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

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

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

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