Esempio n. 1
0
        private int GetCalibrationProgramFromPool(MissionInProgress missionInProgress)
        {
            var possibleRandomCPRGList = EntityDefault.All.GetByCategoryFlags(CategoryFlags.cf_random_calibration_programs).Select(d => d.Definition).ToList();

            Log("possible CPRG definitions:" + possibleRandomCPRGList.Count);

            var exceptCPRGDefinitions = missionInProgress.CollectCPRGDefinitionsFromItems();

            possibleRandomCPRGList = possibleRandomCPRGList.Except(missionInProgress.SelectedItemDefinitions).Except(exceptCPRGDefinitions).ToList();

            Log("except choosen:" + possibleRandomCPRGList.Count);

            if (possibleRandomCPRGList.Count == 0)
            {
                Log("no possible CPRG definitions to select from. " + this + " " + missionInProgress);
                throw new PerpetuumException(ErrorCodes.ConsistencyError);
            }

            //now we load the active cprg definitions from the character/gang
            var activeCPRGDefinitions = missionInProgress.CollectActiveCPRGDefinitions();

            Log("active CPRG definitions:" + activeCPRGDefinitions.Count);

            possibleRandomCPRGList = possibleRandomCPRGList.Except(activeCPRGDefinitions).ToList();

            Log("except active: " + possibleRandomCPRGList.Count);

            if (possibleRandomCPRGList.Count == 0)
            {
                Log("too many active cprgs running. mission resolve fails " + this + " " + missionInProgress);
                throw new PerpetuumException(ErrorCodes.TooManyActiveCPRG);
            }

            var choosenCPRG = possibleRandomCPRGList.RandomElement();

            //exclude
            missionInProgress.AddToSelectedItems(choosenCPRG);

            //and exclude this as well
            var resultingDefinition = ProductionDataAccess.GetResultingDefinitionFromCalibrationDefinition(choosenCPRG);

            missionInProgress.AddToSelectedItems(resultingDefinition);

            Log("selected CPRG: " + EntityDefault.Get(choosenCPRG).Name + " " + choosenCPRG);

            return(choosenCPRG);
        }