/// <summary> /// Creates a new character. /// </summary> public async Task <Character> CreateCharacterAsync(ulong discordId, string name) { if (!StringHelper.IsOnlyLetters(name)) { throw new Exception(Exceptions.CHAR_NAMES_NOT_LETTERS); } if (name.Length > 24 || name.Length < 2) { throw new Exception(Exceptions.CHAR_NAMES_LENGTH); } var characters = await GetAllCharactersAsync(discordId); if (characters.Count > 0) { if (HasDuplicateName(characters, name)) { throw new Exception(Exceptions.CHAR_NAMES_NOT_UNIQUE); } if (characters.Count >= MAX_CHARACTERS) { throw new Exception(Exceptions.CHAR_TOO_MANY); } } name = StringHelper.ToTitleCase(name); var character = new Character() { DiscordId = discordId, Active = false, Name = name, Description = "", Story = "", Experience = 0, ExperiencePoints = 0, SpecialPoints = SpecialService.STARTING_SPECIAL_POINTS, TagPoints = _chargenOptions.SkillPoints, Money = 1000, Statistics = new List <StatisticValue>(), EffectCharacters = new List <EffectCharacter>() }; _statsService.InitializeStatistics(character.Statistics); if (characters.Count == 0) { character.Active = true; } await _charRepository.AddAsync(character); return(character); }
public async Task <bool> CreateNpcPresetAsync(string name) { // NPC preset with name exists if (await GetNpcPreset(name) != null) { throw new Exception(Exceptions.NPC_PRESET_EXISTS); } NpcPreset preset = new NpcPreset { Name = name, Statistics = new List <StatisticValue>() }; _statsService.InitializeStatistics(preset.Statistics); await _presetRepository.AddAsync(preset); return(true); }
public Character CreateNpc(string name, NpcPreset preset) { if (FindNpc(name) != null) { throw new Exception(Exceptions.NPC_CHAR_EXISTS); } if (preset == null) { throw new Exception(Exceptions.NPC_INVALID_PRESET); } if (preset.Enabled == false) { throw new Exception(Exceptions.NPC_INVALID_PRESET_DISABLED); } Character newNpc = new Character { Name = name, Statistics = preset.Statistics }; // Trying to keep this OOP as possible... _statService.InitializeStatistics(newNpc.Statistics); var timer = new Timer(); timer.Elapsed += (sender, e) => OnDurationElasped(sender, e, newNpc); timer.Interval = NPC_ACTIVE_DURATION.TotalMilliseconds; timer.Enabled = true; NpcTimers.Add(newNpc, timer); Npcs.Add(newNpc); return(newNpc); }