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);
        }
Esempio n. 2
0
        /// <summary>
        /// Sets the definition as one of the source items of a research - the item to researh
        /// </summary>
        /// <param name="missionInProgress"></param>
        /// <param name="usePrimaryLink"></param>
        protected bool TryGetResearchableItemFromResearchTarget(MissionInProgress missionInProgress, bool usePrimaryLink = true)
        {
            MissionTargetInProgress linkedTarget;

            if (usePrimaryLink)
            {
                if (!ValidPrimaryLinkSet)
                {
                    return(false);
                }

                linkedTarget = GetSourceTargetForPrimaryAndSolve(missionInProgress);
            }
            else
            {
                if (!ValidSecondaryLinkSet)
                {
                    return(false);
                }

                linkedTarget = GetSourceTargetForSecondaryAndSolve(missionInProgress);
            }

            if (linkedTarget?.TargetType == MissionTargetType.research)
            {
                if (!linkedTarget.myTarget.ValidDefinitionSet)
                {
                    Logger.Error("no valid cprg definition is set for " + linkedTarget.myTarget);
                    throw new PerpetuumException(ErrorCodes.ConsistencyError);
                }

                //this target is created to aid the research. It must spawn an original item
                //and there must be a way to get the decoder as well along the mission

                //cannot use selected definition exceptions
                var itemDefinition = ProductionDataAccess.GetResultingDefinitionFromCalibrationDefinition(linkedTarget.myTarget.Definition);

                missionInProgress.AddToSelectedItems(itemDefinition);

                //as a side effect it may happen that previous targets choose this definition. dont be surprised!

                //possible workaround
                // position the spawn targets as the last/first items, so they will find the item amongst the choosen ones
                // according to research targets in mission

                definition = itemDefinition;
                quantity   = 1;

                Log("researchable item resolved:" + PrimaryEntityDefault.Name + " from " + linkedTarget.myTarget);

                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        private int GetDefinitionFromMissionItemsPool(MissionInProgress missionInProgress, CategoryFlags categoryFlags)
        {
            var possibleDefinitions = EntityDefault.All.GetByCategoryFlags(categoryFlags).Select(d => d.Definition).ToList();

            Log("possible mission item definitions:" + categoryFlags + " " + possibleDefinitions.Count);

            possibleDefinitions = possibleDefinitions.Except(missionInProgress.SelectedItemDefinitions).ToList();

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

            if (possibleDefinitions.Count == 0)
            {
                Logger.Error("no mission item definition to select from. " + this + " " + missionInProgress);
                throw new PerpetuumException(ErrorCodes.ConsistencyError);
            }

            var choosenDefinition = possibleDefinitions.RandomElement();

            missionInProgress.AddToSelectedItems(choosenDefinition);

            Log("selected item definition " + choosenDefinition);

            return(choosenDefinition);
        }