/// <summary> /// Creates the character. /// </summary> /// <param name="name">The name.</param> /// <param name="characterClass">The character class.</param> /// <param name="level">The level.</param> /// <param name="slot">The slot.</param> /// <returns>The created character.</returns> protected virtual Character CreateCharacter(string name, CharacterClassNumber characterClass, int level, byte slot) { var character = this.Context.CreateNew <Character>(); character.CharacterClass = this.GameConfiguration.CharacterClasses.First(c => c.Number == (byte)characterClass); character.Name = name; character.CharacterSlot = slot; character.CreateDate = DateTime.Now; character.KeyConfiguration = new byte[30]; foreach ( var attribute in character.CharacterClass.StatAttributes.Select( a => this.Context.CreateNew <StatAttribute>(a.Attribute, a.BaseValue))) { character.Attributes.Add(attribute); } character.CurrentMap = character.CharacterClass.HomeMap; var spawnGate = character.CurrentMap !.ExitGates.Where(m => m.IsSpawnGate).SelectRandom(); character.PositionX = (byte)Rand.NextInt(spawnGate.X1, spawnGate.X2); character.PositionY = (byte)Rand.NextInt(spawnGate.Y1, spawnGate.Y2); character.Attributes.First(a => a.Definition == Stats.Level).Value = level; character.Experience = GameConfigurationInitializer.CalculateNeededExperience(level); character.LevelUpPoints = (int)((character.Attributes.First(a => a.Definition == Stats.Level).Value - 1) * character.CharacterClass.StatAttributes.First(a => a.Attribute == Stats.PointsPerLevelUp).BaseValue); character.Inventory = this.Context.CreateNew <ItemStorage>(); character.Inventory.Money = 10000000; return(character); }
private Character?CreateCharacter(Player player, string name, CharacterClass charclass) { var account = player.Account; if (account is null) { player.Logger.LogWarning("Account Object is null."); throw new ArgumentNullException(nameof(player), "Account Object is null."); } player.Logger.LogDebug("Enter CreateCharacter: {0} {1} {2}", account.LoginName, name, charclass); var isValidName = string.IsNullOrWhiteSpace(player.GameContext.Configuration.CharacterNameRegex) || Regex.IsMatch(name, player.GameContext.Configuration.CharacterNameRegex); player.Logger.LogDebug("CreateCharacter: Character Name matches = {0}", isValidName); if (!isValidName) { return(null); } var freeSlot = this.GetFreeSlot(player); if (freeSlot is null) { return(null); } if (!charclass.CanGetCreated || charclass.HomeMap is null) { return(null); } var character = player.PersistenceContext.CreateNew <Character>(); character.CharacterClass = charclass; character.Name = name; character.CharacterSlot = freeSlot.Value; character.CreateDate = DateTime.Now; character.KeyConfiguration = new byte[30]; var attributes = character.CharacterClass.StatAttributes.Select(a => player.PersistenceContext.CreateNew <StatAttribute>(a.Attribute, a.BaseValue)).ToList(); attributes.ForEach(character.Attributes.Add); character.CurrentMap = charclass.HomeMap; var randomSpawnGate = character.CurrentMap !.ExitGates.Where(g => g.IsSpawnGate).SelectRandom(); character.PositionX = (byte)Rand.NextInt(randomSpawnGate.X1, randomSpawnGate.X2); character.PositionY = (byte)Rand.NextInt(randomSpawnGate.Y1, randomSpawnGate.Y2); character.Inventory = player.PersistenceContext.CreateNew <ItemStorage>(); account.Characters.Add(character); player.GameContext.PlugInManager.GetPlugInPoint <ICharacterCreatedPlugIn>()?.CharacterCreated(player, character); player.PersistenceContext.SaveChanges(); player.Logger.LogDebug("Creating Character Complete."); return(character); }