2024-02-09 22:15:05 +00:00
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-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-10 22:28:35 +00:00
public ModelManager ( IOptions < PlayerStartingValues > playerStartingValues )
{
_playerStartingValues = playerStartingValues ;
}
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-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-09 09:20:14 +00:00
}