Exemplo n.º 1
0
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var character    = request.Session.Character;
                var robotEid     = request.Data.GetOrDefault <long>(k.robotEID);
                var containerEid = request.Data.GetOrDefault <long>(k.containerEID);

                character.IsDocked.ThrowIfFalse(ErrorCodes.CharacterHasToBeDocked);
                character.IsRobotSelectedForOtherCharacter(robotEid).ThrowIfTrue(ErrorCodes.UnknownError);

                var container = Container.GetOrThrow(containerEid);
                //not possible from corp hangar, robot inventory, and system container
                container.ThrowIfType <CorporateHangar>(ErrorCodes.AccessDenied);
                container.ThrowIfType <CorporateHangarFolder>(ErrorCodes.AccessDenied);
                container.ThrowIfType <RobotInventory>(ErrorCodes.AccessDenied);
                container.ThrowIfType <DefaultSystemContainer>(ErrorCodes.AccessDenied);
                container.CheckAccessAndThrowIfFailed(character, ContainerAccess.List);

                var robot = _robotHelper.LoadRobotForCharacter(robotEid, character, true);
                robot.Parent.ThrowIfNotEqual(containerEid, ErrorCodes.ParentError);
                robot.IsRepackaged.ThrowIfTrue(ErrorCodes.ItemHasToBeUnpacked);

                robot.CheckEnablerExtensionsAndThrowIfFailed(character);
                character.SetActiveRobot(robot);
                robot.Save();

                Message.Builder.FromRequest(request).WithOk().Send();
                scope.Complete();
            }
        }
Exemplo n.º 2
0
        public override void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var id             = request.Data.GetOrDefault <int>(k.ID);
                var robotEid       = request.Data.GetOrDefault <long>(k.robotEID);
                var containerEid   = request.Data.GetOrDefault <long>(k.containerEID);
                var forCorporation = request.Data.GetOrDefault <int>(k.forCorporation).ToBool();

                var character = request.Session.Character;
                var repo      = GetFittingPresetRepository(character, forCorporation);
                var preset    = repo.Get(id);
                var robot     = _robotHelper.LoadRobotForCharacter(robotEid, character);
                robot.ED.ThrowIfNotEqual(preset.Robot, ErrorCodes.WTFErrorMedicalAttentionSuggested);

                var container = Container.GetWithItems(containerEid, character);
                robot.EmptyRobot(character, container, false);

                foreach (var moduleInfos in preset.Modules.GroupBy(i => i.Component))
                {
                    var component = robot.GetRobotComponent((RobotComponentType)moduleInfos.Key).ThrowIfNull(ErrorCodes.ItemNotFound);

                    foreach (var moduleInfo in moduleInfos)
                    {
                        var module = container.GetItems().OfType <Module>().FirstOrDefault(m => m.ED == moduleInfo.Module);
                        if (module == null)
                        {
                            continue;
                        }

                        module = (Module)module.Unstack(1);

                        if (module is ActiveModule activeModule && moduleInfo.Ammo != EntityDefault.None)
                        {
                            var ammo = (Ammo)container.GetAndRemoveItemByDefinition(moduleInfo.Ammo.Definition, activeModule.AmmoCapacity);
                            if (ammo != null)
                            {
                                activeModule.SetAmmo(ammo);
                            }
                        }

                        component.EquipModuleOrThrow(module, moduleInfo.Slot);
                    }
                }

                robot.Initialize(character);

                robot.Save();
                container.Save();

                var result = new Dictionary <string, object>
                {
                    { k.robot, robot.ToDictionary() },
                    { k.container, container.ToDictionary() }
                };
                Message.Builder.FromRequest(request).WithData(result).Send();

                scope.Complete();
            }
        }
Exemplo n.º 3
0
        public void HandleRequest(IRequest request)
        {
            // make sure the transaction scope is disposed of properly.
            using (TransactionScope scope = Db.CreateTransaction())
            {
                try
                {
                    if (TryGetRobotFromZone(request, out Robot robot))
                    {
                        robot.EnlistTransaction();
                    }
                    else
                    {
                        var robotEid = request.Data.GetOrDefault <long>(k.robotEID);
                        robot = _robotHelper.LoadRobotForCharacter(robotEid, request.Session.Character);
                    }

                    if (robot == null)
                    {
                        throw new PerpetuumException(ErrorCodes.RobotNotFound);
                    }

                    if (!robot.IsSingleAndUnpacked)
                    {
                        throw new PerpetuumException(ErrorCodes.RobotMustbeSingleAndNonRepacked);
                    }

                    if (ForFitting)
                    {
                        robot.CheckOwnerOnlyCharacterAndThrowIfFailed(request.Session.Character);
                    }
                    else
                    {
                        robot.CheckOwnerCharacterAndCorporationAndThrowIfFailed(request.Session.Character);
                    }

                    switch (robot.GetOrLoadParentEntity())
                    {
                    case DefaultSystemContainer _:
                    case RobotInventory _ when ForFitting:
                    case CorporateHangar _ when ForFitting:
                    {
                        throw new PerpetuumException(ErrorCodes.AccessDenied);
                    }
                    }

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

                    Message.Builder.FromRequest(request).WithData(result).WrapToResult().WithEmpty().Send();
                }
                finally
                {
                    scope?.Complete();
                }
            }
        }
Exemplo n.º 4
0
        public void Activate(RobotInventory targetContainer, Character character)
        {
            var robot = _robotHelper.LoadRobotForCharacter(targetContainer.GetOrLoadParentEntity().Eid, character, true);

            robot.ThrowIfNull(ErrorCodes.NoRobotFound);
            robot.DynamicProperties.Update(k.tint, this.ED.Config.Tint); //Apply color
            robot.DynamicProperties.Update(k.decay, 255);                //Reset Decay
            robot.Save();
        }
Exemplo n.º 5
0
        public override void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var robotEid       = request.Data.GetOrDefault <long>(k.robotEID);
                var name           = request.Data.GetOrDefault <string>(k.name);
                var forCorporation = request.Data.GetOrDefault <int>(k.forCorporation).ToBool();

                var character = request.Session.Character;
                var robot     = _robotHelper.LoadRobotForCharacter(robotEid, character);
                var preset    = Robots.Fitting.FittingPreset.CreateFrom(robot);
                preset.Name = name;

                var repo = GetFittingPresetRepository(character, forCorporation);
                repo.Insert(preset);

                SendAllPresetsToCharacter(request, repo);
                scope.Complete();
            }
        }