Exemplo n.º 1
0
        public IDictionary <string, object> CalibrateLine(Character character, long calibrationEid, Container container)
        {
            var lineCount = ProductionLine.CountLinesForCharacter(character, Eid);
            var maxSlots  = RealMaxSlotsPerCharacter(character);

            lineCount.ThrowIfGreaterOrEqual(maxSlots, ErrorCodes.MaximumAmountOfProducionsReached);

            var calibrationItem = (CalibrationProgram)container.GetItemOrThrow(calibrationEid);

            calibrationItem.Quantity.ThrowIfNotEqual(1, ErrorCodes.ServerError);

            var targetDefinition = calibrationItem.TargetDefinition;

            targetDefinition.ThrowIfEqual(0, ErrorCodes.CPRGNotProducible);
            var targetDefault = EntityDefault.Get(targetDefinition);

            calibrationItem.HasComponents.ThrowIfFalse(ErrorCodes.CPRGNotProducible);


            //no mission stuff here
            if (calibrationItem.IsMissionRelated || targetDefault.CategoryFlags.IsCategory(CategoryFlags.cf_random_items))
            {
                if (this.GetDockingBase().IsOnGammaZone())
                {
                    throw new PerpetuumException(ErrorCodes.MissionItemCantBeProducedOnGamma);
                }
            }


            ProductionLine.CreateCalibratedLine(character, Eid, calibrationItem);

            //remove from container
            container.RemoveItemOrThrow(calibrationItem);

            //parent the cprg to the facility
            this.GetStorage().AddChild(calibrationItem);

            calibrationItem.Save();

            container.Save();

            ProductionHelper.ProductionLogInsert(character, targetDefinition, 1, ProductionInProgressType.inserCT, 0, 0, false);

            var informDict   = container.ToDictionary();
            var linesList    = GetLinesList(character);
            var facilityInfo = GetFacilityInfo(character);

            var replyDict = new Dictionary <string, object>
            {
                { k.lines, linesList },
                { k.lineCount, linesList.Count },
                { k.sourceContainer, informDict },
                { k.facility, facilityInfo }
            };

            return(replyDict);
        }
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var lineId      = request.Data.GetOrDefault <int>(k.ID);
                var character   = request.Session.Character;
                var facilityEid = request.Data.GetOrDefault <long>(k.facility);

                _productionManager.PrepareProductionForPublicContainer(facilityEid, character, out Mill mill, out PublicContainer publicContainer);

                var productionLine = ProductionLine.LoadByIdAndCharacterAndFacility(character, lineId, facilityEid);

                productionLine.IsActive().ThrowIfTrue(ErrorCodes.ProductionIsRunningOnThisLine);

                var calibrationProgram = productionLine.ExtractCalibrationProgram(mill);

                //add to public container
                publicContainer.AddItem(calibrationProgram, character.Eid, false);

                //save container
                publicContainer.Save();

                //delete line
                ProductionLine.DeleteById(productionLine.Id);

                ProductionHelper.ProductionLogInsert(character, productionLine.TargetDefinition, 1, ProductionInProgressType.removeCT, 0, 0, false);

                var linesList     = mill.GetLinesList(character);
                var containerList = publicContainer.ToDictionary();

                var result = new Dictionary <string, object>
                {
                    { k.lineCount, linesList.Count },
                    { k.lines, linesList },
                    { k.container, containerList }
                };


                Message.Builder.FromRequest(request).WithData(result).Send();

                scope.Complete();
            }
        }