Exemplo n.º 1
0
        private void DealWithCPRGGenerators(MissionInProgress missionInProgress)
        {
            var source = GetSourceTargetForPrimaryAndSolve(missionInProgress);

            if (source != null)
            {
                //linked to a target which creates a CPRG artificially.
                //item supply or spawn item currently
                if (!source.myTarget.ValidDefinitionSet)
                {
                    Logger.Error("no cprg definition is set in: " + source);
                    throw new PerpetuumException(ErrorCodes.ConsistencyError);
                }

                if (source.myTarget.PrimaryEntityDefault.CategoryFlags.IsCategory(CategoryFlags.cf_random_calibration_programs))
                {
                    Log("linked to a CPRG generator. " + source);

                    //this is the item the CPRG will aid to massproduce
                    var targetDefinition = ProductionDataAccess.GetResultingDefinitionFromCalibrationDefinition(source.myTarget.Definition);

                    definition = targetDefinition;

                    if (!ValidQuantitySet)
                    {
                        quantity = 1; //start scaling :)
                    }

                    Log("definition is set to CPRG result: " + source.myTarget.Definition + " -> " + targetDefinition);
                }
            }
        }
Exemplo 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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
 /// <summary>
 ///     Generate the item's definition the ct will create
 /// </summary>
 private void GenerateResearchResultAsSecondaryDefinition(MissionInProgress missionInProgress)
 {
     //the default item related to the CT
     secondaryDefinition = ProductionDataAccess.GetResultingDefinitionFromCalibrationDefinition(Definition);
     Log("Default definition is used for the CPRG");
 }