using Client.Domain.Factories;
using Client.Infrastructure.Factories;
using Client.Domain.Parsers;
using Client.Infrastructure.Parsers;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Windows;
using Client.Domain.Transports;
using Client.Infrastructure.Transports;
using Client.Domain.Entities;
using Client.Domain.Service;
using Client.Domain.ValueObjects;
using Microsoft.Extensions.Configuration;
using System.Reflection;
using Client.Application.Views;
using Client.Application.ViewModels;
using Client.Domain.Helpers;
using Client.Infrastructure.Helpers;
using Client.Domain.Events;
using Client.Infrastructure.Events;
using System;
using Client.Infrastructure.Service;
using System.Collections.Generic;
using System.Linq;
using Client.Domain.AI;
using Client.Infrastructure.AI.IO;
using Client.Domain.AI.IO;
namespace Client
{
///
/// Interaction logic for App.xaml
///
public partial class App : System.Windows.Application
{
public static IHost? AppHost { get; private set; }
public App()
{
AppHost = Host.CreateDefaultBuilder()
.ConfigureServices(
(hostContext, services) => ConfigureServices(services)
)
.Build();
}
protected override async void OnStartup(StartupEventArgs e)
{
await AppHost!.StartAsync();
var startupForm = AppHost.Services.GetRequiredService();
startupForm.Show();
base.OnStartup(e);
var application = AppHost.Services.GetRequiredService();
await application.StartAsync();
}
protected override async void OnExit(ExitEventArgs e)
{
await AppHost!.StopAsync();
base.OnExit(e);
}
private void ConfigureServices(IServiceCollection services)
{
IConfiguration config = new ConfigurationBuilder()
.AddJsonFile("config.json", optional: false, reloadOnChange: true)
.AddJsonFile("Assets/data/experience.json", optional: false, reloadOnChange: true)
.AddJsonFile("Assets/data/npcInfo.json", optional: false, reloadOnChange: true)
.AddJsonFile("Assets/data/itemInfo.json", optional: false, reloadOnChange: true)
.AddJsonFile("Assets/data/skillInfo.json", optional: false, reloadOnChange: true)
.Build();
services
.AddSingleton(typeof(IConfiguration), config)
.AddSingleton()
.AddSingleton(
typeof(Bot),
x => new Bot(
x.GetRequiredService(),
config.GetValue("DLLName") ?? ""
)
)
.AddSingleton(typeof(EntityHandlerFactoryInterface), typeof(EntityHandlerFactory))
.AddSingleton(typeof(MessageParserInterface), typeof(JsonMessageParser))
.AddSingleton(typeof(OutgoingMessageBuilderInterface), typeof(JsonOutgoingMessageBuilder))
.AddSingleton(
typeof(TransportInterface),
x => new NamedPipeTransport(
config.GetValue("ConnectionPipeName") ?? ""
)
)
.AddSingleton(typeof(ExperienceHelperInterface), typeof(ConfigurationExperienceHelper))
.AddSingleton(typeof(NpcInfoHelperInterface), typeof(ConfigurationNpcInfoHelper))
.AddSingleton(typeof(ItemInfoHelperInterface), typeof(ConfigurationItemInfoHelper))
.AddSingleton(typeof(SkillInfoHelperInterface), typeof(ConfigurationSkillInfoHelper))
.AddSingleton(typeof(EventBusInterface), typeof(InMemoryEventBus))
.AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory))
.AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory))
.AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory))
.AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory))
.AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory))
.AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory))
.AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory))
.AddTransient(typeof(EntityFactoryInterface), typeof(ItemFactory))
.AddSingleton()
.AddSingleton()
.AddSingleton()
.AddSingleton()
.AddSingleton()
.AddSingleton()
.AddSingleton()
.AddSingleton()
.AddSingleton(
typeof(PathfinderInterface),
x => new L2jGeoDataPathfinder(
config.GetValue("GeoDataDirectory") ?? "",
config.GetValue("MaxPassableHeight")
)
)
.AddSingleton(
typeof(AsyncPathMoverInterface),
x => new AsyncPathMover(
x.GetRequiredService(),
x.GetRequiredService(),
config.GetValue("PathNumberOfAttempts"),
config.GetValue("NodeWaitingTime"),
config.GetValue("NodeDistanceTolerance"),
config.GetValue("NextNodeDistanceTolerance")
)
)
.AddSingleton()
.AddSingleton()
.AddSingleton(
typeof(AIInterface),
x => new AI(
x.GetRequiredService(),
x.GetRequiredService(),
x.GetRequiredService(),
x.GetRequiredService()
)
)
.AddTransient(typeof(ConfigSerializerInterface), typeof(JsonConfigSerializer))
.AddTransient(typeof(ConfigDeserializerInterface), typeof(JsonConfigDeserializer))
.AddSingleton()
.AddSingleton();
}
}
}