Exemple #1
0
        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);

                if (spark.changePrice > 0)
                {
                    character.SubtractFromWallet(TransactionType.SparkActivation, spark.changePrice);
                }

                var unlockedSparks = _sparkHelper.GetUnlockedSparkData(character).ToArray();

                if (!spark.defaultSpark)
                {
                    //is spark unlocked?
                    unlockedSparks.Any(uls => uls.sparkId == sparkId).ThrowIfFalse(ErrorCodes.SparkLocked);
                }

                var currentSpark = unlockedSparks.FirstOrDefault(uls => uls.active);

                if (currentSpark != null)
                {
                    (currentSpark.sparkId == sparkId).ThrowIfTrue(ErrorCodes.SparkAlreadyActive);

                    if (currentSpark.activationTime != null)
                    {
                        (DateTime.Now.Subtract((DateTime)currentSpark.activationTime).TotalMinutes < SparkHelper.SPARK_CHANGE_MINUTES).ThrowIfTrue(ErrorCodes.SparkCooldownNotOver);
                    }

                    if (currentSpark.sparkId > 0)
                    {
                        _sparkHelper.DeactivateSpark(character, currentSpark.sparkId);
                    }
                }

                _sparkHelper.ActivateSpark(character, sparkId);

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

                scope.Complete();
            }
        }
Exemple #2
0
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var nick     = request.Data.GetOrDefault <string>(k.nick).Trim();
                var avatar   = request.Data.GetOrDefault <Dictionary <string, object> >(k.avatar);
                var raceID   = request.Data.GetOrDefault <int>(k.raceID);
                var majorID  = request.Data.GetOrDefault <int>(k.majorID);
                var schoolID = request.Data.GetOrDefault <int>(k.schoolID);
                var sparkID  = request.Data.GetOrDefault <int>(k.sparkID);

                var account = _accountManager.Repository.Get(request.Session.AccountId);
                if (account == null)
                {
                    throw new PerpetuumException(ErrorCodes.AccountNotFound);
                }

                Character.CheckNickAndThrowIfFailed(nick, request.Session.AccessLevel, account);

                //only 3 characters per account is allowed
                var activeCharactersCount = _accountManager.GetActiveCharactersCount(account);
                if (activeCharactersCount >= 3)
                {
                    throw new PerpetuumException(ErrorCodes.MaximumAmountOfCharactersReached);
                }

                if (account.FirstCharacterDate == null)
                {
                    account.FirstCharacterDate = DateTime.Now;
                    _accountManager.Repository.Update(account);
                }

                var character = CreateNewCharacter();
                character.AccountId = account.Id;
                character.Nick      = nick;
                character.Avatar    = GenxyString.FromDictionary(avatar);
                character.IsDocked  = true;

                DockingBase        dockingBase;
                DefaultCorporation corporation;

                if (schoolID > 0)
                {
                    if (majorID == 0 || raceID == 0 || sparkID == 0)
                    {
                        throw new PerpetuumException(ErrorCodes.WTFErrorMedicalAttentionSuggested);
                    }

                    corporation = DefaultCorporation.GetBySchool(raceID, schoolID) ?? throw new PerpetuumException(ErrorCodes.CorporationNotExists);
                    dockingBase = corporation.GetDockingBase();
                    dockingBase.CreateStarterRobotForCharacter(character, true);

                    character.MajorId  = majorID;
                    character.RaceId   = raceID;
                    character.SchoolId = schoolID;
                    character.SparkId  = sparkID;
                    character.AddToWallet(TransactionType.CharacterCreate, 20000);

                    var extensions = character.GetDefaultExtensions();
                    character.SetExtensions(extensions);

                    var sparkToActivate = _sparkHelper.ConvertCharacterWizardSparkIdToSpark(sparkID);
                    _sparkHelper.ActivateSpark(character, sparkToActivate);
                }
                else
                {
                    // training
                    dockingBase = _dockingBaseHelper.GetTrainingDockingBase();
                    corporation = ((TrainingDockingBase)dockingBase).GetTrainingCorporation();
                    character.SetAllExtensionLevel(5);
                    dockingBase.CreateStarterRobotForCharacter(character);
                    character.AddToWallet(TransactionType.CharacterCreate, 10000000);
                }

                character.CurrentDockingBaseEid = dockingBase.Eid;
                character.DefaultCorporationEid = corporation.Eid;

                //add to default corp, only in sql
                corporation.AddNewCharacter(character);

                _accountManager.PackageGenerateAll(account);

                Transaction.Current.OnCommited(() =>
                {
                    _channelManager.JoinChannel(corporation.ChannelName, character);
                    Message.Builder.FromRequest(request).SetData(k.characterID, character.Id).Send();
                });

                scope.Complete();
            }
        }