source: binary-improvements/7dtd-server-fixes/src/CustomCommands/SetTimeReal.cs@ 154

Last change on this file since 154 was 130, checked in by alloc, 10 years ago

Fixes

File size: 1.7 KB
RevLine 
[84]1using System;
2
[130]3namespace AllocsFixes.CustomCommands
[84]4{
[130]5 public class SetTimeReal : ConsoleCommand
[84]6 {
[130]7 public SetTimeReal (ConsoleSdtd cons) : base(cons)
8 {
9 }
[84]10
[130]11 public override string Description ()
12 {
13 return "set current ingame time, params: <day> <hour> <min>";
14 }
[84]15
[130]16 public override string[] Names ()
17 {
18 return new string[] { "settimereal", "str" };
19 }
[84]20
[130]21 public override void Run (string[] _params)
22 {
23 try {
24 if (_params.Length != 3) {
25 m_Console.SendResult ("Usage: settimereal <day> <hour> <min>");
26 return;
27 }
[84]28
[130]29 int day, hour, min;
30 if (!int.TryParse (_params [0], out day)) {
31 m_Console.SendResult ("Could not parse day number \"" + _params [0] + "\"");
32 return;
33 }
34 if (day < 1) {
35 m_Console.SendResult ("Day must be >= 1");
36 return;
37 }
38 if (!int.TryParse (_params [1], out hour)) {
39 m_Console.SendResult ("Could not parse hour \"" + _params [1] + "\"");
40 return;
41 }
42 if (hour > 23) {
43 m_Console.SendResult ("Hour must be <= 23");
44 return;
45 }
46 if (!int.TryParse (_params [2], out min)) {
47 m_Console.SendResult ("Could not parse minute \"" + _params [2] + "\"");
48 return;
49 }
50 if (min > 59) {
51 m_Console.SendResult ("Minute must be <= 59");
52 return;
53 }
54 if ((day < 1) || (hour < 8 && day < 1)) {
55 m_Console.SendResult ("Time may not be prior to day 1, 8:00");
56 return;
57 }
58
59 ulong time = ((ulong)(day - 1) * 24000) + ((ulong)hour * 1000) + ((ulong)min * 1000 / 60) - 8000;
60 m_Console.gameManager.World.gameTime = time;
61 m_Console.SendResult (String.Format ("Set time to Day {0}, {1:00}:{2:00} = {3}", day, hour, min, time));
62 } catch (Exception e) {
63 Log.Out ("Error in SetTimeReal.Run: " + e);
[103]64 }
[84]65 }
66 }
67}
Note: See TracBrowser for help on using the repository browser.