Example #1
0
        /// <summary>
        /// Creates the role.
        /// </summary>
        /// <param name="option">The option.</param>
        /// <returns></returns>
        public async Task <IEntity> CreateRole(CreateRoleOption option)
        {
            IEntity role;

            switch (option.Race)
            {
            case Race.Human:
                role = await GrainFactory.GetGrain <IPrefabManager>(0).Clone(option.Name, "human.init");

                break;

            default:

                throw new ArgumentOutOfRangeException(nameof(option.Race));
            }

            var unit = GrainFactory.Get <IUnit>(role);
            var pos  = GrainFactory.Get <IPosition>(role);
            await unit.Fill(option);

            await pos.SetData(new Position(GameOptions.Value.SpawnPoint));

            await role.SetName(option.Name);

            State.Roles.Add(role);
            await WriteStateAsync();

            Logger.Info($"New role {option.Race}: {option.Name} ({this.GetPrimaryKeyString()}) has been added");

            return(role);
        }
Example #2
0
        public async Task <IEntity> GetNewRoleAsync(CreateRoleOption option = null)
        {
            IAccount account = await GetRegisteredAccountAsync();

            option = option ?? new Faker <CreateRoleOption>().RuleFor(o => o.Name, f => f.Name.FullName());
            IEntity entity = await account.CreateRole(option);

            await account.UseRole(entity);

            return(entity);
        }
Example #3
0
        public async Task <IEnumerable <IEntity> > GetNewRolesAsync(int num, CreateRoleOption option = null)
        {
            var tasks = new Task <IEntity> [num];

            for (var i = 0; i < tasks.Length; i++)
            {
                tasks[i] = GetNewRoleAsync(option);
            }

            return(await Task.WhenAll(tasks));
        }
Example #4
0
        /// <summary>
        /// Creates the role.
        /// </summary>
        /// <param name="option">The option.</param>
        /// <returns></returns>
        public async Task <bool> CreateRole(CreateRoleOption option)
        {
            if (option == null)
            {
                throw new ArgumentNullException(nameof(option));
            }

            option.Name = option.Name?.Trim() ?? throw new ArgumentNullException(nameof(option.Name));
            if (option.Name.Length < 3)
            {
                throw new ArgumentOutOfRangeException(nameof(option.Name));
            }

            await Session.Value.Get <IAccount>().CreateRole(option);

            return(true);
        }
Example #5
0
        public Task <bool> CreateRole([NotNull] CreateRoleOption option)
        {
            if (option == null)
            {
                throw new ArgumentNullException(nameof(option));
            }

            option.Name = option.Name?.Trim() ?? throw new ArgumentNullException(nameof(option.Name));
            if (option.Name.Length < 3)
            {
                throw new ArgumentOutOfRangeException(nameof(option.Name));
            }

            Entity role;

            switch (option.Race)
            {
            case Race.Human:
            {
                role = PrefabRepository.GetPrefab("human.init").Clone();
            }

            break;

            default:

                throw new ArgumentOutOfRangeException();
            }

            Mapper.Map(option, role.Get <UnitComponent>());
            role.Name = option.Name;
            role.Get <PositionComponent>().Pos = Config.Cfg.SpawnPoint;
            EntityRepository.SaveEntity(role);
            Roles.Add(role);

            Logger.Info($"New role {option.Name} has been added");

            return(Task.FromResult(true));
        }
Example #6
0
        public UnitState GenerateInitiateUnit(CreateRoleOption option)
        {
            var unit = new UnitState
            {
                Race   = option.Race,
                Gender = option.Gender,
            };

            for (var i = 0; i < (int)BodyPartIndex.BodyPartCount; i++)
            {
                unit.BodyParts[i] = BodyPart.Create(1, 10);
            }
            for (var i = 0; i < (int)AbilityIndex.AbilityCount; i++)
            {
                unit.Abilities[i] = new UnitProperty();
            }
            for (var i = 0; i < (int)EffectIndex.EffectCount; i++)
            {
                unit.Effects[i] = new UnitProperty();
            }

            return(unit);
        }
Example #7
0
 public Task Fill(CreateRoleOption option)
 {
     State.Gender = option.Gender;
     return(Task.CompletedTask);
 }
Example #8
0
 public IEntity CreateInitiateRole(CreateRoleOption option)
 {
     throw new NotImplementedException();
 }