Example #1
0
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var character   = request.Session.Character;
                var lineId      = request.Data.GetOrDefault <int>(k.ID);
                var rounds      = request.Data.GetOrDefault <int>(k.rounds);
                var facilityEid = request.Data.GetOrDefault <long>(k.facility);

                _productionManager.GetFacilityAndCheckDocking(facilityEid, character, out Mill mill);

                ProductionLine.LoadById(lineId, out ProductionLine productionLine).ThrowIfError();

                productionLine.CharacterId.ThrowIfNotEqual(character.Id, ErrorCodes.OwnerMismatch);

                var maxRounds = Mill.GetMaxRounds(character);

                if (rounds > maxRounds)
                {
                    rounds = maxRounds;
                }

                ProductionLine.SetRounds(rounds, productionLine.Id).ThrowIfError();

                var linesList    = mill.GetLinesList(character);
                var facilityInfo = mill.GetFacilityInfo(character);

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

                Message.Builder.SetCommand(Commands.ProductionLineList).WithData(reply).ToClient(request.Session).Send();

                scope.Complete();
            }
        }
        public IDictionary <string, object> LineStartInMill(Character character, Container sourceContainer, int lineId, int cycles, bool useCorporationWallet, bool searchInRobots, Mill mill, int rounds)
        {
            const int maxCycles = 1;

            cycles.ThrowIfGreater(maxCycles, ErrorCodes.ProductionMaxCyclesExceeded);

            var maxRounds = Mill.GetMaxRounds(character);

            if (rounds > maxRounds)
            {
                rounds = maxRounds;
            }

            ProductionLine productionLine;

            ProductionLine.LoadById(lineId, out productionLine).ThrowIfError();

            productionLine.CharacterId.ThrowIfNotEqual(character.Id, ErrorCodes.OwnerMismatch);
            productionLine.IsActive().ThrowIfTrue(ErrorCodes.ProductionIsRunningOnThisLine);
            productionLine.IsAtZero().ThrowIfTrue(ErrorCodes.ProductionLineIsAtZero);

            if (productionLine.Rounds != rounds)
            {
                ProductionLine.SetRounds(rounds, productionLine.Id).ThrowIfError();
                productionLine.Rounds = rounds;
            }

            bool hasBonus;
            var  newProduction = mill.LineStart(character, productionLine, sourceContainer, cycles, useCorporationWallet, out hasBonus);

            if (newProduction == null)
            {
                if (useCorporationWallet)
                {
                    throw new PerpetuumException(ErrorCodes.CorporationNotEnoughMoney);
                }

                throw new PerpetuumException(ErrorCodes.CharacterNotEnoughMoney);
            }

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

            var linesList = mill.GetLinesList(character);

            replyDict.Add(k.lines, linesList);
            replyDict.Add(k.lineCount, linesList.Count);

            var productionDict = newProduction.ToDictionary();

            replyDict.Add(k.production, productionDict);

            var informDict = sourceContainer.ToDictionary();

            replyDict.Add(k.sourceContainer, informDict);

            var facilityInfo = mill.GetFacilityInfo(character);

            replyDict.Add(k.facility, facilityInfo);

            replyDict.Add(k.hasBonus, hasBonus);

            return(replyDict);
        }