WutheringWaves/GameServer/Models/ModelManager.cs

40 lines
1.4 KiB
C#
Raw Permalink Normal View History

using Core.Config;
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;
private readonly ConfigManager _configManager;
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, ConfigManager configManager)
{
_playerStartingValues = playerStartingValues;
_configManager = configManager;
}
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 RoleModel Roles { get; } = new();
public FormationModel Formation { get; } = new();
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
}