コード例 #1
0
        /// <summary>
        /// Loads the SNACKS_RESOURCE_PROCESSOR config nodes and returns a list of processors.
        /// </summary>
        /// <returns>A list of resource processors.</returns>
        public static List <BaseResourceProcessor> LoadProcessors()
        {
            List <BaseResourceProcessor> resourceProcessors = new List <BaseResourceProcessor>();
            BaseResourceProcessor        resourceProcessor;

            ConfigNode[] nodes = GameDatabase.Instance.GetConfigNodes(ProcessorNode);
            ConfigNode   node;

            //Add the Stress processor if Stress is defined
            if (SnacksScenario.Instance.rosterResources.ContainsKey(StressProcessor.StressResourceName))
            {
                StressProcessor stressProcessor = new StressProcessor();
                stressProcessor.Initialize();
                resourceProcessors.Add(stressProcessor);
            }

            //Now go through all the config nodes and load them
            for (int index = 0; index < nodes.Length; index++)
            {
                node = nodes[index];
                if (!node.HasValue("name"))
                {
                    continue;
                }
                if (node.GetValue("name") == SnacksResourceProcessor.SnacksProcessorName)
                {
                    //Add the snacks processor
                    SnacksResourceProcessor snacksProcessor = new SnacksResourceProcessor();
                    snacksProcessor.Initialize();
                    resourceProcessors.Add(snacksProcessor);
                }
                else
                {
                    resourceProcessor = new BaseResourceProcessor(node);
                    resourceProcessor.Initialize();
                    resourceProcessors.Add(resourceProcessor);
                }
            }

            //Return all the processors
            return(resourceProcessors);
        }
コード例 #2
0
        public override bool IsValid(ProtoCrewMember astronaut)
        {
            if (!base.IsValid(astronaut))
            {
                return(false);
            }

            AstronautData astronautData = SnacksScenario.Instance.GetAstronautData(astronaut);

            if (astronautData == null)
            {
                return(false);
            }

            //Get the processor
            BaseResourceProcessor processor = null;
            int count = SnacksScenario.Instance.resourceProcessors.Count;

            for (int index = 0; index < count; index++)
            {
                processor = SnacksScenario.Instance.resourceProcessors[index];
                if (resultType == CheckResultTypes.resultConsumptionFailure || resultType == CheckResultTypes.resultConsumptionSuccess)
                {
                    if (processor.consumptionResults.ContainsKey(resourceName))
                    {
                        break;
                    }
                }
                else
                {
                    if (processor.productionResults.ContainsKey(resourceName))
                    {
                        break;
                    }
                }
                processor = null;
            }
            if (processor == null)
            {
                return(false);
            }

            switch (resultType)
            {
            case CheckResultTypes.resultConsumptionFailure:
                //Processor needs at least one failure
                if (processor.consumptionResults[resourceName].completedSuccessfully)
                {
                    return(false);
                }

                if (astronautData.processedResourceFailures.ContainsKey(resourceName))
                {
                    return(astronautData.processedResourceFailures[resourceName] >= cyclesRequired);
                }
                else
                {
                    return(true);
                }

            case CheckResultTypes.resultConsumptionSuccess:
                //Processor needs at least one success
                if (!processor.consumptionResults[resourceName].completedSuccessfully)
                {
                    return(false);
                }

                if (astronautData.processedResourceSuccesses.ContainsKey(resourceName))
                {
                    return(astronautData.processedResourceSuccesses[resourceName] >= cyclesRequired);
                }
                else
                {
                    return(true);
                }

            case CheckResultTypes.resultProductionFailure:
                //Processor needs at least one failure
                if (processor.consumptionResults[resourceName].completedSuccessfully)
                {
                    return(false);
                }

                if (astronautData.processedResourceFailures.ContainsKey(resourceName))
                {
                    return(astronautData.processedResourceFailures[resourceName] >= cyclesRequired);
                }
                else
                {
                    return(true);
                }

            case CheckResultTypes.resultProductionSuccess:
                //Processor needs at least one success
                if (!processor.consumptionResults[resourceName].completedSuccessfully)
                {
                    return(false);
                }

                if (astronautData.processedResourceSuccesses.ContainsKey(resourceName))
                {
                    return(astronautData.processedResourceSuccesses[resourceName] >= cyclesRequired);
                }
                else
                {
                    return(true);
                }
            }

            return(true);
        }