Exemple #1
0
        public IDictionary <string, object> ResearchQuery(Character character, int researchKitDefinition, int targetDefinition)
        {
            var replyDict = new Dictionary <string, object>
            {
                { k.researchKitDefinition, researchKitDefinition },
                { k.itemDefinition, targetDefinition }
            };

            var researchKitDefault = EntityDefault.Get(researchKitDefinition);
            var itemDefault        = EntityDefault.Get(targetDefinition);

            var missionRelated = false;

            //match item vs research kit vs mission
            if (researchKitDefault.CategoryFlags.IsCategory(CategoryFlags.cf_random_research_kits))
            {
                itemDefault.CategoryFlags.IsCategory(CategoryFlags.cf_generic_random_items).ThrowIfFalse(ErrorCodes.OnlyMissionItemAccepted);
                missionRelated = true;
            }

            if (itemDefault.CategoryFlags.IsCategory(CategoryFlags.cf_generic_random_items))
            {
                researchKitDefault.CategoryFlags.IsCategory(CategoryFlags.cf_random_research_kits).ThrowIfFalse(ErrorCodes.OnlyMissionResearchKitAccepted);
                missionRelated = true;
            }

            //on gamma not even possible
            if (GetDockingBase().IsOnGammaZone())
            {
                missionRelated.ThrowIfTrue(ErrorCodes.MissionItemCantBeResearchedOnGamma);
            }

            var researchKitLevel = ResearchKit.GetResearchLevelByDefinition(researchKitDefinition);

            replyDict.Add(k.researchKitLevel, researchKitLevel);

            var isPrototypeItem = ProductionDataAccess.IsPrototypeDefinition(targetDefinition);

            Logger.Info("item definition: " + EntityDefault.Get(targetDefinition).Name + " isPrototype:" + isPrototypeItem);

            var nominalDict = new Dictionary <string, object>();
            var realDict    = new Dictionary <string, object>();

            //match research levels
            var itemLevel = ProductionDataAccess.GetResearchLevel(targetDefinition);

            itemLevel.ThrowIfEqual(0, ErrorCodes.ItemNotResearchable);
            itemLevel.ThrowIfGreater(researchKitLevel, ErrorCodes.ResearchLevelMismatch);

            var itemResearchLevel = ProductionDataAccess.ResearchLevels.GetOrDefault(targetDefinition).ThrowIfNull(ErrorCodes.ItemNotResearchable);

            var outputDefinition = (int)itemResearchLevel.calibrationProgramDefinition.ThrowIfNull(ErrorCodes.ServerError);

            //calculate
            CalculateFinalResearchTimeSeconds(character, itemLevel, researchKitLevel, isPrototypeItem, out int researchTimeSeconds, out int levelDifferenceBonusPoints);

            researchTimeSeconds = GetShortenedProductionTime(researchTimeSeconds);

            var price = missionRelated ? 0.0 : researchTimeSeconds *GetPricePerSecond(targetDefinition);

            ProductionDataAccess.GetCalibrationDefault(outputDefinition, out int materialEfficiency, out int timeEfficiency);

            var rawMaterialEfficiency = materialEfficiency;

            CalculateMaterialAndTimeEfficiency(character, itemResearchLevel, levelDifferenceBonusPoints, ref materialEfficiency, ref timeEfficiency);

            if (missionRelated)
            {
                //the material efficiency must be default 1.0
                materialEfficiency = rawMaterialEfficiency;
            }


            //calculate nominal
            var nominalResearchTimeSeconds = CalculateNominalResearchTimeSeconds(character, itemResearchLevel.researchLevel);

            var nominalPrice = missionRelated ? 0.0 : nominalResearchTimeSeconds *GetPricePerSecond(targetDefinition);

            ProductionDataAccess.GetCalibrationDefault(outputDefinition, out int nominalMaterialEfficiency, out int nominalTimeEfficiency);

            var rawNominalMatEff = nominalMaterialEfficiency;

            CalculateMaterialAndTimeEfficiency(character, itemResearchLevel, 0, ref nominalMaterialEfficiency, ref nominalTimeEfficiency);

            if (missionRelated)
            {
                nominalMaterialEfficiency  = rawNominalMatEff;
                researchTimeSeconds        = 10;
                nominalResearchTimeSeconds = 10;
            }

            //collect definition related
            replyDict.Add(k.calibrationProgram, itemResearchLevel.calibrationProgramDefinition);

            //collect real
            realDict.Add(k.price, (long)price);
            realDict.Add(k.researchTime, researchTimeSeconds);
            realDict.Add(k.materialEfficiency, materialEfficiency);
            realDict.Add(k.timeEfficiency, timeEfficiency);

            //collect nominal
            nominalDict.Add(k.price, (long)nominalPrice);
            nominalDict.Add(k.researchTime, nominalResearchTimeSeconds);
            nominalDict.Add(k.materialEfficiency, nominalMaterialEfficiency);
            nominalDict.Add(k.timeEfficiency, nominalTimeEfficiency);

            replyDict.Add(k.real, realDict);
            replyDict.Add(k.nominal, nominalDict);
            replyDict.Add(k.facility, Eid);

            return(replyDict);
        }
Exemple #2
0
        private IDictionary <string, object> EndResearch(ProductionInProgress productionInProgress)
        {
            Logger.Info("research finished: " + productionInProgress);

            Item        item;
            ResearchKit researchKit;

            LoadItemAndResearchKit(productionInProgress, out researchKit, out item).ThrowIfError();

            var isPrototypeItem = ProductionDataAccess.IsPrototypeDefinition(item.Definition);

            var itemLevel        = ProductionDataAccess.GetResearchLevel(item.Definition);
            var researchKitLevel = researchKit.GetResearchLevel();

            int researchTime;
            int levelDifferenceBonusPoints;

            CalculateFinalResearchTimeSeconds(productionInProgress.character, itemLevel, researchKitLevel, isPrototypeItem, out researchTime, out levelDifferenceBonusPoints);

            var outputDefinition = productionInProgress.resultDefinition;

            //load public container
            var targetContainer = (PublicContainer)Container.GetOrThrow(PublicContainerEid);

            targetContainer.ReloadItems(productionInProgress.character);

            var outputDefault = EntityDefault.Get(outputDefinition).ThrowIfEqual(EntityDefault.None, ErrorCodes.DefinitionNotSupported);

            (outputDefault.CategoryFlags.IsCategory(CategoryFlags.cf_calibration_programs) || outputDefault.CategoryFlags.IsCategory(CategoryFlags.cf_random_calibration_programs)).ThrowIfFalse(ErrorCodes.WTFErrorMedicalAttentionSuggested);


            //create item
            var resultItem = targetContainer.CreateAndAddItem(outputDefinition, false, item1 =>
            {
                item1.Owner    = productionInProgress.character.Eid;
                item1.Quantity = 1;
            });

            var calibrationProgram = resultItem as CalibrationProgram;

            calibrationProgram.ThrowIfNull(ErrorCodes.ConsistencyError);

            var itemResearchLevel = ProductionDataAccess.GetItemReserchLevelByCalibrationProgram(calibrationProgram);

            int materialEfficiency;
            int timeEfficiency;

            researchKit.GetCalibrationDefaults(outputDefault, out materialEfficiency, out timeEfficiency);

            var rawMatEff = materialEfficiency;

            //modify the results even further
            CalculateMaterialAndTimeEfficiency(productionInProgress.character, itemResearchLevel, levelDifferenceBonusPoints, ref materialEfficiency, ref timeEfficiency);

            if (calibrationProgram.IsMissionRelated)
            {
                materialEfficiency = rawMatEff;
                calibrationProgram.MaterialEfficiencyPoints = rawMatEff;
                calibrationProgram.TimeEfficiencyPoints     = timeEfficiency;
            }
            else
            {
                calibrationProgram.MaterialEfficiencyPoints = materialEfficiency;
                calibrationProgram.TimeEfficiencyPoints     = timeEfficiency;
            }



            var randomCalibrationProgram = calibrationProgram as RandomCalibrationProgram;

            //for random missions look up for targets, gang and stuff
            randomCalibrationProgram?.SetComponentsFromRunningTargets(productionInProgress.character);

            calibrationProgram.Save();

            productionInProgress.character.WriteItemTransactionLog(TransactionType.ResearchCreated, calibrationProgram);

            //delete the used items

            Repository.Delete(item);

            Repository.Delete(researchKit);

            productionInProgress.character.WriteItemTransactionLog(TransactionType.ResearchDeleted, item);
            productionInProgress.character.WriteItemTransactionLog(TransactionType.ResearchDeleted, researchKit);

            targetContainer.Save();

            Logger.Info("endResearch created an item: " + calibrationProgram + " production:" + productionInProgress);

            var replyDict = new Dictionary <string, object>
            {
                { k.result, calibrationProgram.ToDictionary() }
            };


            ProductionProcessor.EnqueueProductionMissionTarget(MissionTargetType.research, productionInProgress.character, MyMissionLocationId(), calibrationProgram.Definition);
            return(replyDict);
        }