public IDictionary <string, object> ResearchItem(ResearchLab researchLab, Character character, Container container, long itemEid, long researchKitEid, bool useCorporationWallet)
        {
            var maxSlotCount           = researchLab.RealMaxSlotsPerCharacter(character);
            var facilityEid            = researchLab.Eid;
            var runningProductionCount = RunningProductions.GetRunningProductionsByFacilityAndCharacter(character, facilityEid).Count();

            //check per character slots
            maxSlotCount.ThrowIfLess(runningProductionCount + 1, ErrorCodes.MaximumAmountOfProducionsReached);

            var sourceItem = container.GetItemOrThrow(itemEid, true);

            //robot cargo check
            sourceItem.GetOrLoadParentEntity().ThrowIfType <RobotInventory>(ErrorCodes.ResearchNotPossibleFromRobotCargo);

            var isPrototypeItem = _productionDataAccess.IsPrototypeDefinition(sourceItem.Definition);

            Logger.Info("item definition: " + sourceItem.ED.Name + " isPrototype:" + isPrototypeItem);

            sourceItem.HealthRatio.ThrowIfNotEqual(1.0, ErrorCodes.ItemHasToBeRepaired);

            sourceItem.Quantity.ThrowIfLess(sourceItem.ED.Quantity, ErrorCodes.MinimalQuantityNotReached);

            if (sourceItem.ED.AttributeFlags.Repackable)
            {
                sourceItem.IsRepackaged.ThrowIfFalse(ErrorCodes.ItemHasToBeRepackaged);
            }

            //CSAK csomagolt item mehet, nem kell a robotot ellenorizgetni

            var researchKit = (ResearchKit)container.GetItemOrThrow(researchKitEid, true);

            researchKit.GetOrLoadParentEntity().ThrowIfType <RobotInventory>(ErrorCodes.ResearchNotPossibleFromRobotCargo);

            //on gamma not even possible
            if (researchLab.GetDockingBase().IsOnGammaZone())
            {
                (researchKit.IsMissionRelated || sourceItem.IsCategory(CategoryFlags.cf_random_items)).ThrowIfTrue(ErrorCodes.OnlyMissionResearchKitAccepted);
            }

            //only single item
            if (researchKit.Quantity > 1)
            {
                researchKit = (ResearchKit)researchKit.Unstack(1);  //this is the working piece
            }

            /*
             * else
             * {
             *  container.RemoveItemOrThrow(researchKit);
             * }
             */

            if (sourceItem.Quantity > sourceItem.ED.Quantity)
            {
                sourceItem = sourceItem.Unstack(sourceItem.ED.Quantity);
            }

            /*
             * else
             * {
             *  container.RemoveItemOrThrow(sourceItem);
             * }
             */

            //check item
            _productionDataAccess.IsItemResearchable(sourceItem.Definition).ThrowIfFalse(ErrorCodes.ItemNotResearchable);

            //check item using the research kit
            researchKit.IsMatchingWithItem(sourceItem).ThrowIfError();

            //match research levels
            var itemLevel        = _productionDataAccess.GetResearchLevel(sourceItem.Definition);
            var researchKitLevel = researchKit.GetResearchLevel();

            _productionDataAccess.ResearchLevels.TryGetValue(sourceItem.Definition, out ItemResearchLevel itemResearchLevel).ThrowIfFalse(ErrorCodes.ItemNotResearchable);

            //calc time and bonus
            researchLab.CalculateFinalResearchTimeSeconds(character, itemLevel, researchKitLevel, isPrototypeItem, out int researchTimeSeconds, out int levelDifferenceBonusPoints);

            researchTimeSeconds = researchLab.GetShortenedProductionTime(researchTimeSeconds);

            if (researchKit.IsMissionRelated)
            {
                researchTimeSeconds = 10; //fix time for research in missions
            }

            ProductionInProgress newProduction;

            researchLab.StartResearch(character, researchTimeSeconds, sourceItem, researchKit, useCorporationWallet, out newProduction).ThrowIfError();

            //save to sql
            newProduction.InsertProductionInProgess();

            container.Save();

            //add to ram
            Transaction.Current.OnCommited(() => AddToRunningProductions(newProduction));

            newProduction.SendProductionEventToCorporationMembersOnCommitted(Commands.ProductionRemoteStart);

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

            //return info
            replyDict.Add(k.production, newProduction.ToDictionary());

            var containerInfo = container.ToDictionary();

            replyDict.Add(k.sourceContainer, containerInfo);

            //refresh the facility info
            var facilityInfo = researchLab.GetFacilityInfo(character);

            replyDict.Add(k.facility, facilityInfo);

            return(replyDict);
        }
예제 #2
0
 public override string ToString()
 {
     return($"R: {RoboticsFactory.ToString()} S: {Shipyard.ToString()} L: {ResearchLab.ToString()} M: {MissileSilo.ToString("")} N: {NaniteFactory.ToString("")}");
 }