2024-02-21 14:47:37 +00:00
using Core.Config ;
using GameServer.Controllers.Attributes ;
2024-02-10 22:28:35 +00:00
using GameServer.Settings ;
2024-02-10 16:04:03 +00:00
using GameServer.Systems.Event ;
2024-02-10 22:28:35 +00:00
using Microsoft.Extensions.Options ;
2024-02-09 22:15:05 +00:00
namespace GameServer.Models ;
2024-02-09 09:20:14 +00:00
internal class ModelManager
{
2024-02-10 22:28:35 +00:00
private readonly IOptions < PlayerStartingValues > _playerStartingValues ;
2024-02-21 14:47:37 +00:00
private readonly ConfigManager _configManager ;
2024-02-10 22:28:35 +00:00
2024-02-09 09:20:14 +00:00
private PlayerModel ? _playerModel ;
2024-02-10 16:04:03 +00:00
private CreatureModel ? _creatureModel ;
2024-02-09 09:20:14 +00:00
2024-02-21 14:47:37 +00:00
public ModelManager ( IOptions < PlayerStartingValues > playerStartingValues , ConfigManager configManager )
2024-02-10 22:28:35 +00:00
{
_playerStartingValues = playerStartingValues ;
2024-02-21 14:47:37 +00:00
_configManager = configManager ;
2024-02-10 22:28:35 +00:00
}
2024-02-09 22:15:05 +00:00
[GameEvent(GameEventType.Login)]
2024-02-09 09:20:14 +00:00
public void OnLogin ( )
{
2024-02-10 22:28:35 +00:00
_playerModel = PlayerModel . CreateDefaultPlayer ( _playerStartingValues . Value ) ;
2024-02-10 16:04:03 +00:00
_creatureModel = new CreatureModel ( _playerModel . Id ) ;
2024-02-11 22:23:13 +00:00
Formation . Set ( _playerStartingValues . Value . Characters ) ;
2024-02-09 09:20:14 +00:00
}
public PlayerModel Player = > _playerModel ? ? throw new InvalidOperationException ( $"Trying to access {nameof(PlayerModel)} instance before initialization!" ) ;
2024-02-10 16:04:03 +00:00
public CreatureModel Creature = > _creatureModel ? ? throw new InvalidOperationException ( $"Trying to access {nameof(CreatureModel)} instance before initialization!" ) ;
2024-02-11 22:23:13 +00:00
2024-02-21 14:47:37 +00:00
public RoleModel Roles { get ; } = new ( ) ;
2024-02-11 22:23:13 +00:00
public FormationModel Formation { get ; } = new ( ) ;
2024-02-21 14:47:37 +00:00
public InventoryModel Inventory { get ; } = new ( ) ;
2024-02-14 21:22:21 +00:00
public ChatModel Chat { get ; } = new ( ) ;
2024-02-09 09:20:14 +00:00
}