示例#1
0
        public override void Activate(Account account, Character character)
        {
            if (_sparkHelper.IsSparkUnlocked(character, ED.Options.SparkID))
            {
                throw new PerpetuumException(ErrorCodes.SparkAlreadyUnlocked);
            }

            _sparkHelper.UnlockSpark(character, ED.Options.SparkID);

            var e = new AccountTransactionLogEvent(account, AccountTransactionType.SparkRedeem)
            {
                Eid = Eid
            };

            AccountManager.LogTransaction(e);

            Transaction.Current.OnCommited(() =>
            {
                _sparkHelper.CreateSparksListMessage(character).ToCharacter(character).Send();
            });
        }
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var sparkId   = request.Data.GetOrDefault <int>(k.sparkID);
                var character = request.Session.Character;

                character.IsDocked.ThrowIfFalse(ErrorCodes.CharacterHasToBeDocked);

                var spark = _sparkHelper.GetSpark(sparkId).ThrowIfNull(ErrorCodes.ItemNotFound);
                spark.defaultSpark.ThrowIfTrue(ErrorCodes.SparkAlreadyUnlocked);
                spark.unlockable.ThrowIfFalse(ErrorCodes.WTFErrorMedicalAttentionSuggested);

                _sparkHelper.GetUnlockedSparkData(character).Any(uls => uls.sparkId == sparkId).ThrowIfTrue(ErrorCodes.SparkAlreadyUnlocked);

                if (spark.unlockPrice != null)
                {
                    character.SubtractFromWallet(TransactionType.SparkUnlock, (double)spark.unlockPrice);
                }

                if (spark.definition != null)
                {
                    var publicContainer = character.GetPublicContainerWithItems();

                    //keress meg itemet
                    var foundItems = publicContainer.GetItems().Where(i => i.Definition == spark.definition);

                    var needed = (int)spark.quantity;

                    foreach (var item in foundItems)
                    {
                        if (item.Quantity > needed)
                        {
                            item.Quantity = item.Quantity - needed;
                            needed        = 0;
                            break; //found more
                        }

                        if (item.Quantity <= needed)
                        {
                            needed = needed - item.Quantity;

                            Entity.Repository.Delete(item);

                            if (needed <= 0)
                            {
                                break; //found enough
                            }
                        }
                    }

                    needed.ThrowIfGreater(0, ErrorCodes.SparkNotEnoughItems);
                    publicContainer.Save();
                }

                if (spark.energyCredit != null)
                {
                    //%%% itt a cucc
                }

                if (spark.allianceEid != null)
                {
                    var standing = _standingHandler.GetStanding((long)spark.allianceEid, character.Eid);
                    standing.ThrowIfLess((double)spark.standingLimit, ErrorCodes.StandingTooLow);
                }

                _sparkHelper.UnlockSpark(character, sparkId);

                //return list
                Transaction.Current.OnCommited(() => _sparkHelper.SendSparksList(request));

                scope.Complete();
            }
        }