/// <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); }
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); }
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)); }
/// <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); }
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)); }
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); }
public Task Fill(CreateRoleOption option) { State.Gender = option.Gender; return(Task.CompletedTask); }
public IEntity CreateInitiateRole(CreateRoleOption option) { throw new NotImplementedException(); }