forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIdFactory.cs
More file actions
43 lines (35 loc) · 1.04 KB
/
Copy pathIdFactory.cs
File metadata and controls
43 lines (35 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.Threading;
using System.Threading.Tasks;
using L2dotNET.Services.Contracts;
using NLog;
namespace L2dotNET.Tables
{
public sealed class IdFactory : IInitialisable
{
private readonly IItemService _itemService;
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
public bool Initialised { get; private set; }
// TODO: Investigate the purpose of that
// public const int IdMin = 0x10000000;
// public const int IdMax = 0x7FFFFFFF;
private int _currentId = 1;
public IdFactory(IItemService itemService)
{
_itemService = itemService;
}
public int NextId()
{
return Interlocked.Increment(ref _currentId);
}
public async Task Initialise()
{
if (Initialised)
{
return;
}
_currentId = _itemService.GetMaxItemId();
Log.Info($"Used IDs {_currentId}.");
Initialised = true;
}
}
}