Ejemplo n.º 1
0
        public static Result VisitMedicBay(string userId)
        {
            var result = new Result();

            try
            {
                using (var heroContext = new HeroContext())
                {
                    var hero = heroContext.Heroes.Single(p => p.UserId == userId);

                    string validationMessage;
                    if (!ValidationService.Validate(hero, 1, out validationMessage))
                    {
                        throw new Exception(validationMessage);
                    }

                    var dice           = new DiceService();
                    var healthRestored = restoreHealth(hero, dice);
                    heroContext.SaveChanges();

                    var successMessage = string.Format("The Medic Bay restored {0} health!", healthRestored);
                    result.Message = successMessage;
                    result.Hero    = hero;

                    ActivityService.QueueActivity(userId, EventType.Medic, successMessage);
                }
            }
            catch (Exception exception)
            {
                Trace.TraceError(exception.Message);
                throw;
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static Result PurchaseArmor(string userId)
        {
            var result = new Result();

            try
            {
                using (var heroContext = new HeroContext())
                {
                    var hero = heroContext.Heroes.Single(p => p.UserId == userId);

                    string validationMessage;
                    if (!ValidationService.Validate(hero, 10, out validationMessage))
                    {
                        throw new Exception(validationMessage);
                    }
                    var dice             = new DiceService();
                    var armorImprovement = improveArmor(hero, dice);

                    heroContext.SaveChanges();

                    var successMessage = string.Format(
                        "Armor upgrade was successful giving you an improvement of {0}!",
                        armorImprovement);

                    result.Message = successMessage;
                    result.Hero    = hero;

                    ActivityService.QueueActivity(userId, EventType.Armor, successMessage);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.Message);
                throw new Exception(ex.Message);
            }
            return(result);
        }
Ejemplo n.º 3
0
        public static Result Train(string userId)
        {
            var result = new Result();

            try
            {
                using (var heroContext = new HeroContext())
                {
                    var hero = heroContext.Heroes.Single(p => p.UserId == userId);

                    string validationMessage;
                    if (!ValidationService.Validate(hero, 1, out validationMessage))
                    {
                        throw new Exception(validationMessage);
                    }

                    var dice             = new DiceService();
                    var trainingIncrease = performTraining(hero, dice);
                    heroContext.SaveChanges();

                    var successMessage =
                        string.Format("Training was successful earning you a {0} point training advantage!",
                                      trainingIncrease);

                    result.Message = successMessage;
                    result.Hero    = hero;

                    ActivityService.QueueActivity(userId, EventType.Weapon, successMessage);
                }
            }
            catch (Exception exception)
            {
                Trace.TraceError(exception.Message);
                throw;
            }
            return(result);
        }
Ejemplo n.º 4
0
 internal static void RecordBattle(string userId, string resultMessage)
 {
     ActivityService.QueueActivity(userId, EventType.Battle, resultMessage);
 }