1
1
using System ;
2
+ using System . Diagnostics ;
2
3
using System . Timers ;
3
4
using NitroxModel . Logger ;
4
5
using NitroxModel . Packets ;
6
+ using NitroxServer . GameLogic . Bases ;
5
7
6
8
namespace NitroxServer . GameLogic
7
9
{
8
10
public class EventTriggerer
9
11
{
10
- PlayerManager playerManager ;
11
- public EventTriggerer ( PlayerManager playerManager )
12
+ private PlayerManager playerManager ;
13
+ private Stopwatch stopWatch ;
14
+ public double ElapsedTime ;
15
+ public double AuroraExplosionTime ;
16
+ public EventTriggerer ( PlayerManager playerManager , double elapsedTime , double ? auroraExplosionTime )
12
17
{
13
18
this . playerManager = playerManager ;
14
- SetupEventTimers ( ) ;
19
+ SetupEventTimers ( elapsedTime , auroraExplosionTime ) ;
15
20
}
16
21
17
- public void SetupEventTimers ( )
22
+ private void SetupEventTimers ( double elapsedTime , double ? auroraExplosionTime )
18
23
{
19
24
// eventually this should be on a better timer so it can be saved, paused, etc
20
25
Log . Debug ( "Event Triggerer started!" ) ;
21
- double auroraTimer = RandomNumber ( 2.3d , 4d ) * 1200d * 1000d ; //Time.deltaTime returns seconds so we need to multiply 1000
22
- CreateTimer ( auroraTimer * 0.2d , StoryEventType . PDA , "Story_AuroraWarning1" ) ;
23
- CreateTimer ( auroraTimer * 0.5d , StoryEventType . PDA , "Story_AuroraWarning2" ) ;
24
- CreateTimer ( auroraTimer * 0.8d , StoryEventType . PDA , "Story_AuroraWarning3" ) ;
25
- CreateTimer ( auroraTimer , StoryEventType . PDA , "Story_AuroraWarning4" ) ;
26
- CreateTimer ( auroraTimer + 24000 , StoryEventType . EXTRA , "Story_AuroraExplosion" ) ;
26
+
27
+ ElapsedTime = elapsedTime ;
28
+ if ( auroraExplosionTime . HasValue )
29
+ {
30
+ AuroraExplosionTime = auroraExplosionTime . Value ;
31
+ }
32
+ else
33
+ {
34
+ AuroraExplosionTime = RandomNumber ( 2.3d , 4d ) * 1200d * 1000d ; //Time.deltaTime returns seconds so we need to multiply 1000
35
+ }
36
+
37
+ CreateTimer ( AuroraExplosionTime * 0.2d - ElapsedTime , StoryEventType . PDA , "Story_AuroraWarning1" ) ;
38
+ CreateTimer ( AuroraExplosionTime * 0.5d - ElapsedTime , StoryEventType . PDA , "Story_AuroraWarning2" ) ;
39
+ CreateTimer ( AuroraExplosionTime * 0.8d - ElapsedTime , StoryEventType . PDA , "Story_AuroraWarning3" ) ;
40
+ CreateTimer ( AuroraExplosionTime - ElapsedTime , StoryEventType . PDA , "Story_AuroraWarning4" ) ;
41
+ CreateTimer ( AuroraExplosionTime + 24000 - ElapsedTime , StoryEventType . EXTRA , "Story_AuroraExplosion" ) ;
42
+ //like the timers, except we can see how much time has passed
43
+ stopWatch = new Stopwatch ( ) ;
44
+ stopWatch . Start ( ) ;
27
45
}
28
46
29
- public Timer CreateTimer ( double time , StoryEventType eventType , string key )
47
+ private Timer CreateTimer ( double time , StoryEventType eventType , string key )
30
48
{
49
+ //if timeOffset goes past the time
50
+ if ( time <= 0 )
51
+ {
52
+ return null ;
53
+ }
54
+
31
55
Timer timer = new Timer ( ) ;
32
56
timer . Elapsed += delegate
33
57
{
@@ -40,10 +64,19 @@ public Timer CreateTimer(double time, StoryEventType eventType, string key)
40
64
return timer ;
41
65
}
42
66
43
- public double RandomNumber ( double min , double max )
67
+ private double RandomNumber ( double min , double max )
44
68
{
45
69
Random random = new Random ( ) ;
46
70
return random . NextDouble ( ) * ( max - min ) + min ;
47
71
}
72
+
73
+ public double GetRealElapsedTime ( )
74
+ {
75
+ if ( stopWatch == null )
76
+ {
77
+ return ElapsedTime ;
78
+ }
79
+ return stopWatch . ElapsedMilliseconds + ElapsedTime ;
80
+ }
48
81
}
49
82
}
0 commit comments