/// <summary> /// Initializes a new instance of the <see cref="ApplicationContext"/> class. /// </summary> /// <param name="options">A reference to the application configuration.</param> /// <param name="rsaDecryptor">A reference to the RSA decryptor in use.</param> /// <param name="scriptsLoader">A reference to the scripts loader in use.</param> /// <param name="itemTypeLoader">A reference to the item type loader in use.</param> /// <param name="monsterTypeLoader">A reference to the monster type loader in use.</param> /// <param name="telemetryClient">A reference to the telemetry client.</param> /// <param name="cancellationTokenSource">A reference to the master cancellation token source.</param> /// <param name="dbContextGenerationFunc">A reference to a function to generate the database context.</param> public ApplicationContext( IOptions <ApplicationContextOptions> options, IRsaDecryptor rsaDecryptor, IScriptLoader scriptsLoader, IItemTypeLoader itemTypeLoader, IMonsterTypeLoader monsterTypeLoader, TelemetryClient telemetryClient, CancellationTokenSource cancellationTokenSource, Func <IFibulaDbContext> dbContextGenerationFunc) { options.ThrowIfNull(nameof(options)); rsaDecryptor.ThrowIfNull(nameof(rsaDecryptor)); scriptsLoader.ThrowIfNull(nameof(scriptsLoader)); itemTypeLoader.ThrowIfNull(nameof(itemTypeLoader)); monsterTypeLoader.ThrowIfNull(nameof(monsterTypeLoader)); cancellationTokenSource.ThrowIfNull(nameof(cancellationTokenSource)); dbContextGenerationFunc.ThrowIfNull(nameof(dbContextGenerationFunc)); DataAnnotationsValidator.ValidateObjectRecursive(options.Value); this.Options = options.Value; this.RsaDecryptor = rsaDecryptor; this.ScriptLoader = scriptsLoader; this.CancellationTokenSource = cancellationTokenSource; this.TelemetryClient = telemetryClient; this.itemTypeLoader = itemTypeLoader; this.monsterTypeLoader = monsterTypeLoader; this.contextGenerationFunction = dbContextGenerationFunc; }
/// <summary> /// Initializes a new instance of the <see cref="Player"/> class. /// </summary> /// <param name="client">The client to associate this player to.</param> /// <param name="characterEntity">The player's corresponding character entity lodaded from storage.</param> /// <param name="scriptsLoader">A reference to the scripts loader in use.</param> public Player( IClient client, ICharacterEntity characterEntity, IScriptLoader scriptsLoader) : base(characterEntity) { scriptsLoader.ThrowIfNull(nameof(scriptsLoader)); client.ThrowIfNull(nameof(client)); characterEntity.ThrowIfNull(nameof(characterEntity)); this.Client = client; this.Client.PlayerId = this.Id; this.CharacterId = characterEntity.Id; this.Outfit = characterEntity.Outfit; this.InitializeSkills(scriptsLoader); var expLevel = this.Skills.TryGetValue(SkillType.Experience, out ISkill expSkill) ? expSkill.CurrentLevel : 1; this.Stats[CreatureStat.BaseSpeed].Set(220 + (2 * (expLevel - 1))); this.Stats[CreatureStat.CarryStrength].Set(150); this.Stats.Add(CreatureStat.ManaPoints, new Stat(CreatureStat.ManaPoints, characterEntity.CurrentManapoints == default ? characterEntity.MaxHitpoints : characterEntity.CurrentManapoints, characterEntity.MaxManapoints)); this.Stats[CreatureStat.ManaPoints].Changed += this.RaiseStatChange; this.Stats.Add(CreatureStat.SoulPoints, new Stat(CreatureStat.SoulPoints, 0, 0)); this.Stats[CreatureStat.SoulPoints].Changed += this.RaiseStatChange; this.Inventory = new PlayerInventory(this); // Hard-coded stuff. this.EmittedLightLevel = (byte)LightLevels.Torch; this.EmittedLightColor = (byte)LightColors.Orange; }