コード例 #1
0
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var id        = request.Data.GetOrDefault <int>(k.ID);
                var character = request.Session.Character;

                character.IsDocked.ThrowIfFalse(ErrorCodes.CharacterHasToBeDocked);
                character.CheckNextAvailableUndockTimeAndThrowIfFailed();
                CheckExtensionLevelAndThrowIfFailed(character);

                var sparkTeleport      = _sparkTeleportHelper.Get(id);
                var currentDockingBase = character.GetCurrentDockingBase();

                character.SubtractFromWallet(TransactionType.SparkTeleportUse, SparkTeleport.SPARK_TELEPORT_USE_FEE);

                if (sparkTeleport.DockingBase == currentDockingBase)
                {
                    throw new PerpetuumException(ErrorCodes.YouAreHereAlready);
                }

                sparkTeleport.DockingBase.IsDockingAllowed(character).ThrowIfError();
                sparkTeleport.DockingBase.DockIn(character, Player.NormalUndockDelay);

                var robot = sparkTeleport.DockingBase.GetPublicContainerWithItems(character)
                            .GetFullTree()
                            .OfType <Robot>()
                            .FirstOrDefault(r => !r.IsRepackaged && ItemExtensions.HaveAllEnablerExtensions(r, character));

                character.SetActiveRobot(robot);

                Transaction.Current.OnCommited(() =>
                {
                    currentDockingBase.LeaveChannel(character);

                    Message.Builder.FromRequest(request)
                    .WithData(sparkTeleport.ToDictionary())
                    .Send();
                });

                scope.Complete();
            }
        }