Ejemplo n.º 1
0
        protected static void SendInfoToCorporation(ITechTreeService techTreeService, long corporationEid)
        {
            var info = new Dictionary <string, object>();

            techTreeService.AddInfoToDictionary(corporationEid, info);
            var points = new TechTreePointsHandler(corporationEid);

            points.AddAvailablePointsToDictionary(info);

            Message.Builder.SetCommand(Commands.TechTreeCorporationInfo)
            .WithData(info)
            .ToCorporation(corporationEid, PresetCorporationRoles.CAN_LIST_TECHTREE)
            .Send();
        }
Ejemplo n.º 2
0
        public override void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var containerEid = request.Data.GetOrDefault <long>(k.container);
                var items        = request.Data.GetOrDefault <long[]>(k.items);

                var character = request.Session.Character;
                var container = Container.GetWithItems(containerEid, character, ContainerAccess.Remove);
                var kernels   = container.GetItems(items).OfType <Kernel>();
                var points    = new TechTreePointsHandler(character.Eid);

                foreach (var kernelGroup in kernels.GroupBy(kernel => kernel.PointType))
                {
                    var pointType = kernelGroup.Key;
                    var sumQty    = kernelGroup.Sum(kernel => kernel.Quantity);

                    points.UpdatePoints(pointType, current => current + sumQty);

                    foreach (var kernel in kernelGroup)
                    {
                        Entity.Repository.Delete(kernel);
                    }

                    var logEvent = new LogEvent(LogType.Research, character)
                    {
                        Definition = kernelGroup.First().Definition,
                        Quantity   = sumQty,
                        Points     = new Points(pointType, sumQty)
                    };

                    TechTreeLogger.WriteLog(logEvent);
                }

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

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

                scope.Complete();
            }
        }
        public override void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var points = request.Data.GetOrDefault <IDictionary <string, object> >(k.points).Select(kvp => new Points((TechTreePointType)int.Parse(kvp.Key), (int)kvp.Value)).ToArray();

                var character         = request.Session.Character;
                var characterPoints   = new TechTreePointsHandler(character.Eid);
                var corporationEid    = character.CorporationEid;
                var corporationPoints = new TechTreePointsHandler(corporationEid);

                foreach (var point in points)
                {
                    characterPoints.UpdatePoints(point.type, current =>
                    {
                        current.ThrowIfLess(point.amount, ErrorCodes.TechTreeNotEnoughPoints, gex => gex.SetData("pointType", (int)point.type).SetData("points", point.amount));
                        corporationPoints.UpdatePoints(point.type, c => c + point.amount);

                        var logEvent = new LogEvent(LogType.Donate, character)
                        {
                            CorporationEid = corporationEid,
                            Points         = point
                        };

                        TechTreeLogger.WriteLog(logEvent);
                        return(current - point.amount);
                    });
                }

                var result = new Dictionary <string, object>();
                characterPoints.AddAvailablePointsToDictionary(result, "characterPoints");

                if (Corporation.GetRoleFromSql(character).HasRole(PresetCorporationRoles.CAN_LIST_TECHTREE))
                {
                    corporationPoints.AddAvailablePointsToDictionary(result, "corporationPoints");
                }

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

                Transaction.Current.OnCommited(() => SendInfoToCorporation(_techTreeService, corporationEid));

                scope.Complete();
            }
        }
        public override void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var definition     = request.Data.GetOrDefault <int>(k.definition);
                var forCorporation = request.Data.GetOrDefault <int>(k.forCorporation) == 1;

                var character = request.Session.Character;
                var ownerEid  = character.Eid;
                var logEvent  = new LogEvent(LogType.Unlock, character)
                {
                    Definition = definition
                };

                if (forCorporation)
                {
                    Corporation.GetRoleFromSql(character).HasRole(PresetCorporationRoles.CAN_UNLOCK_TECHTREE).ThrowIfFalse(ErrorCodes.TechTreeAccessDenied);
                    var corporationEid = character.CorporationEid;
                    logEvent.CorporationEid = corporationEid;
                    ownerEid = corporationEid;

                    Transaction.Current.OnCommited(() => SendInfoToCorporation(_techTreeService, corporationEid));
                }

                var points        = new TechTreePointsHandler(ownerEid);
                var techTreeNodes = _infoService.GetNodes();
                var node          = techTreeNodes.GetOrDefault(definition);
                if (node == null)
                {
                    throw PerpetuumException.Create(ErrorCodes.TechTreeNodeNotFound).SetData("definition", definition);
                }

                var unlockedNodes = _techTreeService.GetUnlockedNodes(ownerEid).ToArray();

                // tudja-e mar
                var any = unlockedNodes.Any(n => n == node);
                if (any)
                {
                    throw PerpetuumException.Create(ErrorCodes.TechTreeAlreadyUnlocked).SetData("definition", definition);
                }

                // parent megvan-e
                var allUnlocked = node.Traverse(techTreeNodes).All(unlockedNodes.Contains);
                if (!allUnlocked)
                {
                    throw new PerpetuumException(ErrorCodes.TechTreeUnlockParentMissing);
                }

                var enablerExtension = node.GetEnablerExtension(_infoService.GetGroupInfos());
                character.CheckLearnedExtension(enablerExtension).ThrowIfFalse(ErrorCodes.TechTreeEnablerExtensionMissing);

                foreach (var price in node.Prices)
                {
                    var amount = forCorporation ? price.amount * _infoService.CorporationPriceMultiplier : price.amount;

                    points.UpdatePoints(price.type, current =>
                    {
                        if (current < amount)
                        {
                            throw PerpetuumException.Create(ErrorCodes.TechTreeNotEnoughPoints).SetData("pointType", (int)price.type).SetData("points", amount);
                        }

                        logEvent.Points = price;
                        TechTreeLogger.WriteLog(logEvent);
                        return(current - amount);
                    });
                }

                var r = Db.Query().CommandText("insert into techtreeunlockednodes (owner,definition) values (@owner,@definition)")
                        .SetParameter("@owner", ownerEid)
                        .SetParameter("@definition", node.Definition)
                        .ExecuteNonQuery();

                if (r == 0)
                {
                    throw new PerpetuumException(ErrorCodes.SQLInsertError);
                }

                Transaction.Current.OnCommited(() => _techTreeService.NodeUnlocked(ownerEid, node));

                var result = new Dictionary <string, object>
                {
                    { k.definition, definition },
                    { k.forCorporation, forCorporation }
                };

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

                scope.Complete();
            }
        }