WutheringWaves/GameServer/Models/ModelManager.cs

35 lines
1.2 KiB
C#
Raw Normal View History

2024-02-09 22:15:05 +00:00
using GameServer.Controllers.Attributes;
using GameServer.Settings;
2024-02-10 16:04:03 +00:00
using GameServer.Systems.Event;
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
{
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
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()
{
_playerModel = PlayerModel.CreateDefaultPlayer(_playerStartingValues.Value);
2024-02-10 16:04:03 +00:00
_creatureModel = new CreatureModel(_playerModel.Id);
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!");
public FormationModel Formation { get; } = new();
2024-02-14 21:22:21 +00:00
public ChatModel Chat { get; } = new();
2024-02-09 09:20:14 +00:00
}