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(); } }
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(); } }