From 6c8f41c93e82dba2b1da51b16c76243b48000575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Tue, 21 Dec 2021 22:43:29 +0100 Subject: [PATCH] feat: add skeleton of game type --- Core/NosSmooth.Game/Game.cs | 77 ++++++++++++++++++++++++++++++ Core/NosSmooth.Game/GameOptions.cs | 18 +++++++ 2 files changed, 95 insertions(+) create mode 100644 Core/NosSmooth.Game/Game.cs create mode 100644 Core/NosSmooth.Game/GameOptions.cs diff --git a/Core/NosSmooth.Game/Game.cs b/Core/NosSmooth.Game/Game.cs new file mode 100644 index 0000000000000000000000000000000000000000..a2ee239caae83fb60595249a72d831b6a7841bc5 --- /dev/null +++ b/Core/NosSmooth.Game/Game.cs @@ -0,0 +1,77 @@ +// +// Game.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.Extensions.Options; +using Microsoft.Extensions.Primitives; +using NosSmooth.Game.Data.Chat; +using NosSmooth.Game.Data.Inventory; +using NosSmooth.Game.Data.Raids; +using NosSmooth.Game.Entities; +using NosSmooth.Game.Maps; + +namespace NosSmooth.Game; + +/// +/// Represents base nostale game class with the character, current map, friends and current raid. +/// +public class Game +{ + private Map? _currentMap; + private readonly GameOptions _options; + + /// + /// Initializes a new instance of the class. + /// + /// The options for the game. + public Game(IOptions options) + { + _options = options.Value; + } + + /// + /// Gets the playing character of the client. + /// + public Character? Character { get; internal set; } + + /// + /// Gets the current map of the client. + /// + /// + /// Will be null until current map packet is received. + /// + public Map? CurrentMap + { + get => _currentMap; + internal set + { + _currentMap = value; + MapChanged?.CancelAfter(TimeSpan.FromSeconds(_options.EntityCacheDuration)); + } + } + + /// + /// Gets the friends list of the current client. + /// + public IReadOnlyList? Friends { get; internal set; } + + /// + /// Gets the active raid the client is currently on. + /// + /// + /// May be null if there is no raid in progress. + /// + public Raid? CurrentRaid { get; internal set; } + + /// + /// Gets the inventory of the client character. + /// + public Inventory Inventory { get; internal set; } + + /// + /// Cancellation token for changing the map to use in memory cache. + /// + internal CancellationTokenSource? MapChanged { get; private set; } +} \ No newline at end of file diff --git a/Core/NosSmooth.Game/GameOptions.cs b/Core/NosSmooth.Game/GameOptions.cs new file mode 100644 index 0000000000000000000000000000000000000000..8bdd8ca5ad53d5e56a47743ebfff1474508c86d4 --- /dev/null +++ b/Core/NosSmooth.Game/GameOptions.cs @@ -0,0 +1,18 @@ +// +// GameOptions.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace NosSmooth.Game; + +/// +/// Options for . +/// +public class GameOptions +{ + /// + /// Duration to cache entities for after changing maps in seconds. + /// + public ulong EntityCacheDuration { get; set; } +} \ No newline at end of file