Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HitPointsController"/> class.
 /// </summary>
 /// <param name="logger">Logger for the class.</param>
 /// <param name="hitPointsService">Service to perform hit points logic.</param>
 public HitPointsController(ILogger <HitPointsController> logger, IHitPointsService hitPointsService)
 {
     _logger           = logger;
     _hitPointsService = hitPointsService;
 }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CharactersService"/> class.
 /// </summary>
 /// <param name="repo">The character repository to use.</param>
 /// <param name="hpService">An implementation of hit points service.</param>
 public CharactersService(CharactersRepository repo, IHitPointsService hpService)
 {
     _repo      = repo;
     _hpService = hpService;
 }
Esempio n. 3
0
        public DnDBeyondMutation(ICharactersService charactersService, IHitPointsService hitPointsService)
        {
            Name = "Mutation";

            // Create new character
            Field <CharacterType>(
                "createCharacter",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <Inputs.CharacterInput> > {
                Name = "character"
            }),
                resolve: context =>
            {
                var character = context.GetArgument <Character>("character");
                return(charactersService.CreateCharacter(character));
            });

            // Update character's temporary hit points
            Field <CharacterType>(
                "updateTemporaryHitPoints",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType> {
                Name = "id"
            },
                    new QueryArgument <IntGraphType> {
                Name = "temporaryHitPoints"
            }),
                resolve: context =>
            {
                var id = context.GetArgument <long>("id");
                var temporaryHitPoints = context.GetArgument <int>("temporaryHitPoints");
                return(hitPointsService.UpdateTemporaryHitPoints(id, temporaryHitPoints));
            });

            // Damage a character
            Field <CharacterType>(
                "damageCharacter",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType> {
                Name = "id"
            },
                    new QueryArgument <IntGraphType> {
                Name = "damage"
            },
                    new QueryArgument <StringGraphType> {
                Name = "damageType"
            }),
                resolve: context =>
            {
                var id         = context.GetArgument <long>("id");
                var damage     = context.GetArgument <int>("damage");
                var damageType = context.GetArgument <string>("damageType");
                return(hitPointsService.DamageCharacter(id, damage, damageType));
            });

            // Heal a character
            Field <CharacterType>(
                "healCharacter",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType> {
                Name = "id"
            },
                    new QueryArgument <IntGraphType> {
                Name = "heal"
            }),
                resolve: context =>
            {
                var id   = context.GetArgument <long>("id");
                var heal = context.GetArgument <int>("heal");
                return(hitPointsService.HealCharacter(id, heal));
            });
        }