forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameTime.cs
More file actions
106 lines (89 loc) · 2.99 KB
/
Copy pathGameTime.cs
File metadata and controls
106 lines (89 loc) · 2.99 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using L2dotNET.Logging.Abstraction;
using L2dotNET.Models.Player;
using L2dotNET.Network;
using L2dotNET.Network.serverpackets;
using L2dotNET.World;
namespace L2dotNET.Controllers
{
public class GameTime
{
private static readonly ILog Log = LogProvider.GetCurrentClassLogger();
private static volatile GameTime _instance;
private static readonly object SyncRoot = new object();
public static GameTime Instance
{
get
{
if (_instance != null)
return _instance;
lock (SyncRoot)
{
if (_instance == null)
_instance = new GameTime();
}
return _instance;
}
}
public int Time;
private readonly GameserverPacket _dayPk = new SunRise();
private readonly GameserverPacket _nightPk = new SunSet();
private System.Timers.Timer _timeController;
public DateTime ServerStartUp;
public static bool Night;
private const int SecDay = 10800,
SecNight = 3600,
SecHour = 600,
SecDn = 14400;
private const int SecScale = 1800;
public void Initialize()
{
ServerStartUp = DateTime.Now;
Time = 5800 + 0; // 10800 18:00 вечер
_timeController = new System.Timers.Timer
{
Interval = 1000,
Enabled = true
};
_timeController.Elapsed += ActionTime;
Log.Info("Started 18:00 PM.");
}
private void ActionTime(object sender, System.Timers.ElapsedEventArgs e)
{
Time++;
switch (Time)
{
case SecDay + SecScale: // 21:00
NotifyStartNight();
break;
case SecScale: // 03:00
NotifyStartDay();
break;
}
if (Time == SecDn)
Time = 0;
}
private void NotifyStartDay()
{
Night = false;
L2World.Instance.GetPlayers().ForEach(p => p.NotifyDayChange(_dayPk));
}
private void NotifyStartNight()
{
Night = true;
L2World.Instance.GetPlayers().ForEach(p => p.NotifyDayChange(_nightPk));
}
public void EnterWorld(L2Player p)
{
p.NotifyDayChange(Night ? _nightPk : _dayPk);
}
public void ShowInfo(L2Player player)
{
DateTime dt = new DateTime(2000, 1, 1, 0, 0, 0).AddSeconds(Time * 6);
SystemMessage sm = new SystemMessage(Night ? SystemMessage.SystemMessageId.TimeS1S2InTheNight : SystemMessage.SystemMessageId.TimeS1S2InTheDay);
sm.AddString(dt.ToString("hh"));
sm.AddString(dt.ToString("mm:ss"));
player.SendPacket(sm);
}
}
}