public void HandleRequest(IRequest request)
        {
            var result         = new Dictionary <string, object>();
            var charactersDict = new Dictionary <string, object>();

            var count = 0;

            var records = Db.Query().CommandText(@"select
c.characterid as characterid,
c.rootEID as rooteid,
c.moodMessage as moodmessage,
c.lastUsed as lastused,
c.creation as creation,
c.credit as credit,
c.nick as nick,
c.inUse as inuse,
c.avatar as avatar,
c.docked as docked,
c.activechassis as activechassis,
c.zoneID as zoneid,
c.baseEID as baseeid,
c.homebaseEID as homebaseeid,
c.offensivenick as offensivenick,
e.ename as currentbasename,
h.ename as homebasename
from characters c JOIN entities e on e.eid=c.baseEID 
LEFT JOIN entities h ON c.homebaseEID=h.eid 
where accountID = @accountID and active = 1").SetParameter("@accountID", request.Session.AccountId)
                          .Execute();

            foreach (var record in records)
            {
                var characterID     = record.GetValue <int>("characterid");
                var isDocked        = record.GetValue <bool>("docked");
                var zoneId          = record.GetValue <int?>("zoneid");
                var currentBaseEID  = record.GetValue <long>("baseeid");
                var homeBaseEID     = record.GetValue <long?>("homebaseeid") ?? 0L;
                var offensiveNick   = record.GetValue <bool>("offensivenick");
                var currentBaseName = record.GetValue <string>("currentbasename");
                var homeBaseName    = record.GetValue <string>("homebasename");
                var moodMessage     = record.GetValue <string>("moodmessage");
                var lastUsed        = record.GetValue <DateTime?>("lastused");
                var creation        = record.GetValue <DateTime>("creation");
                var credit          = record.GetValue <double>("credit");
                var nick            = record.GetValue <string>("nick");
                var inUse           = record.GetValue <bool>("inuse");
                var avatar          = record.GetValue <string>("avatar");
                var rootEid         = record.GetValue <long>("rooteid");

                var currentDockingBase = _dockingBaseHelper.GetDockingBase(currentBaseEID);
                var homeDockingBase    = _dockingBaseHelper.GetDockingBase(homeBaseEID);

                var dict = new Dictionary <string, object>
                {
                    { k.characterID, characterID },
                    { k.rootEID, rootEid },
                    { k.moodMessage, moodMessage },
                    { k.lastUsed, lastUsed },
                    { k.creation, creation },
                    { k.credit, (long)credit },
                    { k.nick, nick },
                    { k.inUse, inUse ? 1 : 0 },
                    { k.avatar, (GenxyString)avatar },
                    { k.docked, isDocked },
                    { k.zoneID, zoneId },
                    { k.baseEID, currentBaseEID },
                    { k.homeBaseEID, homeBaseEID },
                    { k.baseName, currentBaseName },
                    { k.homeBaseName, homeBaseName },
                    { k.offensiveNick, offensiveNick },
                    { k.currentBaseZone, currentDockingBase?.Zone.Id },
                    { k.homeBaseZone, homeDockingBase?.Zone.Id },
                    { k.baseDefinition, currentDockingBase?.Definition },
                    { k.homeBaseDefinition, homeDockingBase?.Definition },
                    { k.dockingBaseInfo, currentDockingBase?.GetDockingBaseDetails() }
                };

                charactersDict.Add("c" + count++, dict);
            }

            result.Add("characters", charactersDict);

            var account = _accountManager.Repository.Get(request.Session.AccountId);
            var ep      = _accountManager.CalculateCurrentEp(account);

            result.Add("extensionPoints", ep);

            Message.Builder.FromRequest(request).WithData(result).WrapToResult().WithEmpty().Send();
        }
Example #2
0
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var account = _accountManager.Repository.Get(request.Session.AccountId).ThrowIfNull(ErrorCodes.AccountNotFound);

                var character   = request.Session.Character;
                var extensionId = request.Data.GetOrDefault <int>(k.extensionID);
                var isAdmin     = request.Session.AccessLevel.IsAdminOrGm();

                character.IsDocked.ThrowIfFalse(ErrorCodes.CharacterHasToBeDocked);

                var extensionInfo = _extensionReader.GetExtensionByID(extensionId).ThrowIfNull(ErrorCodes.ExtensionNotFound);

                // req extension check
                if (!extensionInfo.RequiredExtensions.All(pr => character.CheckLearnedExtension(pr)))
                {
                    isAdmin.ThrowIfFalse(ErrorCodes.PrerequireExtensionError);
                }

                //the level he/she wants to learn
                var extensionLevel = character.GetExtensionLevel(extensionId) + 1;
                extensionLevel.ThrowIfGreater(10, ErrorCodes.ExtensionFullyLearnt);

                var extensionRank      = extensionInfo.rank;
                var extensionPointCost = _extensionPoints.GetNominalExtensionPoints(extensionLevel, extensionRank);

                //extension price
                if (extensionLevel == 1)
                {
                    // ha lvl 1 akkor leszedjuk penzzel a komat
                    character.SubtractFromWallet(TransactionType.extensionLearn, extensionInfo.price);
                }

                //training character -> no EP pool usage
                //                   -> free extension start
                if (!character.IsInTraining())
                {
                    //points check
                    var availablePoints = _accountManager.CalculateCurrentEp(account);
                    if (availablePoints < extensionPointCost)
                    {
                        isAdmin.ThrowIfFalse(ErrorCodes.NotEnoughExtensionPoints);
                    }

                    //spent extension
                    _accountManager.AddExtensionPointsSpent(account, character, extensionPointCost, extensionId, extensionLevel);
                }

                //write to sql
                character.IncreaseExtensionLevel(extensionId, extensionLevel);

                var result = _accountManager.GetEPData(account, character);
                result.Add(k.extensionID, extensionId);
                result.Add(k.extensionLevel, extensionLevel);

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

                scope.Complete();
            }
        }