Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f1e6262
Auto Commands Update Try again (#129)
N1Ran Sep 10, 2019
47bf34f
Revert "Auto Commands Update Try again (#129)"
rexxar-tc Sep 10, 2019
8864a16
Promised nothing is forgotten this time (#130)
N1Ran Sep 10, 2019
8ac340f
Stop fixing shit that ain't broke N1
N1Ran Sep 11, 2019
3818e63
Merge pull request #131 from N1Ran/master
Jimmacle Sep 12, 2019
c94132c
Ignore projected grids
Jimmacle Sep 20, 2019
4b70415
Added a few more convenience commands (#139)
LordTylus Nov 26, 2019
70fdb93
Clean up voxel reset code; fix an edge case bug
rexxar-tc Feb 12, 2020
1f82b65
Fix !sandbox clean breaking factions when removing founder (#147)
LordTylus Apr 22, 2020
5308d5f
Added PCU conditions for the Cleanup command. (#148)
SKO85 Apr 22, 2020
96b4154
add '!admin give' command (#154)
Bishbash777 May 11, 2020
0ba711d
Add a visible notification for the player to indicate when they have …
Bishbash777 May 12, 2020
e2a99d9
Add a visible notification for the player to indicate when they have …
Bishbash777 May 12, 2020
2ebeb92
Some requested commands (#152)
N1Ran May 12, 2020
8a18411
Update GridModule.cs (#153)
dylloop May 12, 2020
1ffb255
Added HasOwnerType condition for Cleanup command (#151)
SKO85 May 12, 2020
1361914
Revert "Update GridModule.cs (#153)"
rexxar-tc May 12, 2020
5f87e89
Merge branch 'master' of https://github.com/Bishbash777/Essentials
Bishbash777 May 13, 2020
e8085f7
Add new economy interaction commands for both players and admins
Bishbash777 May 14, 2020
17edcf6
Add a client popup message to signal if they have send/recieved credits
Bishbash777 May 14, 2020
d1a5f60
Fix voxel reset counting
rexxar-tc May 15, 2020
470fc4d
Merge branch 'master' of https://github.com/Bishbash777/Essentials
Bishbash777 May 15, 2020
4f04344
Updated incorrect grammar
Bishbash777 May 15, 2020
90cebb6
Add new economy interaction commands for both players and admins (#158)
Bishbash777 May 15, 2020
e77f39d
fix sandbox clean removing faction reputations (#159)
N1Ran May 15, 2020
188fc31
Add "!identity clear" command to clear an identity of a specific play…
Bishbash777 Jun 9, 2020
c62a602
Merge branch 'master' of https://github.com/Bishbash777/Essentials
Bishbash777 Jun 9, 2020
8fd659c
Merge pull request #162 from Bishbash777/master
Bishbash777 Jun 9, 2020
2ac4390
Only turn off blocks which are enabled
Bishbash777 Jun 18, 2020
ad8734e
Merge pull request #163 from Bishbash777/master
Bishbash777 Jun 18, 2020
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Promised nothing is forgotten this time (#130)
* AutoCommand update 1/2

* AutoCommands Update 2/2

* Few forgotten things
  • Loading branch information
N1Ran authored and rexxar-tc committed Sep 10, 2019
commit 8864a16e9bf4b6a430466ed55f181f6436cd8f2e
47 changes: 30 additions & 17 deletions Essentials/AutoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,28 @@ public class AutoCommand : ViewModel
private DateTime _nextRun = DateTime.MinValue;
private DayOfWeek _day = DayOfWeek.All;
private Trigger _trigger = Trigger.Disabled;
private Gtl _comparer = Gtl.LessThan;
private int _currentStep;
private string _name;
private float _triggerRatio;
private double _triggerCount;

/*
[Display(Description = "Enables or disables this command. NOTE: !admin runauto does NOT respect this setting!")]
public bool Enabled
{
get => _enabled;
set => SetValue(ref _enabled, value);
}
*/

[Display(Name = "Trigger", Description ="Choose a trigger for the command")]
public Trigger CommandTrigger
{
get => _trigger;
set => SetValue(ref _trigger, value);
}

[Display(Name = "Trigger Operator", Description ="Choose a Ratio Comparer for the command")]
public Gtl Compare
{
get => _comparer;
set => SetValue(ref _comparer, value);
}


[Display(Description = "Sets the name of this command. Use this name in conjunction with !admin runauto to trigger the command from ingame or from other auto commands.")]
public string Name
{
Expand Down Expand Up @@ -120,13 +122,19 @@ public void Update()
if (DateTime.Now < _nextRun)
return;

if(CommandTrigger == Trigger.Scheduled && Interval == TimeSpan.Zero.ToString())
if (DayOfWeek != DayOfWeek.All && DateTime.Now.DayOfWeek != (System.DayOfWeek)(int)DayOfWeek)
{
switch (CommandTrigger)
{
case Trigger.GridCount:
case Trigger.SimSpeed:
case Trigger.PlayerCount:
RunNow();
_nextRun = DateTime.Now + _interval;
return;
case Trigger.Scheduled when Interval == TimeSpan.Zero.ToString() && DayOfWeek != DayOfWeek.All && DateTime.Now.DayOfWeek != (System.DayOfWeek)(int)DayOfWeek:
//adding one day because I can't be bothered to calculate exact interval
_nextRun += TimeSpan.FromDays(1);
return;
}
}


if (Steps.Count <= 0)
Expand All @@ -140,11 +148,9 @@ public void Update()

if (_currentStep < Steps.Count) return;
_currentStep = 0;
if(CommandTrigger == Trigger.Scheduled && Interval == TimeSpan.Zero.ToString())
_nextRun = DateTime.Now.Date + _scheduledTime + TimeSpan.FromDays(1);
else if((CommandTrigger != Trigger.Disabled || CommandTrigger != Trigger.Vote) && Interval != TimeSpan.Zero.ToString())

_nextRun = DateTime.Now + _interval;
_nextRun = _scheduledTime != TimeSpan.Zero
? DateTime.Now.Date + _scheduledTime + TimeSpan.FromDays(1)
: _nextRun = DateTime.Now + _interval;
}


Expand Down Expand Up @@ -210,6 +216,13 @@ public override string ToString()
return $"{Name} : {_trigger.ToString()} : {Steps.Count}";
}
}

public enum Gtl
{
LessThan,
GreaterThan,
Equal
}

public enum Trigger
{
Expand Down
77 changes: 69 additions & 8 deletions Essentials/AutoCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
using Sandbox.Game.World;
using Sandbox.Game.Multiplayer;
using Sandbox.Game.Entities;
using Sandbox.ModAPI;
using VRage.Game.ModAPI;
using static Essentials.Gtl;


namespace Essentials
Expand All @@ -23,6 +25,8 @@ public class AutoCommands : IDisposable
public static AutoCommands Instance => _instance ?? (_instance = new AutoCommands());
private static readonly Logger Log = LogManager.GetLogger("Essentials");
private Timer _timer;
private readonly Dictionary<AutoCommand,DateTime> _simSpeedCheck = new Dictionary<AutoCommand, DateTime>();


public void Start()
{
Expand All @@ -39,24 +43,81 @@ private bool CanRun(AutoCommand command)
case Trigger.Disabled:
return false;
case Trigger.OnStart:
var a = Math.Max(TimeSpan.Parse(command.Interval).TotalSeconds, 60);
var b = ((ITorchServer)TorchBase.Instance).ElapsedPlayTime;
if ((a - b.TotalSeconds) <= 1 && (a - b.TotalSeconds > 0))
command.RunNow();
break;
return Math.Abs((MyAPIGateway.Session.ElapsedPlayTime - TimeSpan.Parse(command.Interval))
.TotalSeconds) < 1;
case Trigger.Vote:
break;
case Trigger.Timed:
return true;
case Trigger.Scheduled:
return true;
case Trigger.GridCount:
return Tree.Grids.Count >= command.TriggerCount;
var gridCount = MyEntities.GetEntities().OfType<IMyCubeGrid>().Count();
switch (command.Compare)
{
case GreaterThan:
return gridCount > command.TriggerCount;
case LessThan:
return gridCount < command.TriggerCount;
case Equal:
return Math.Abs(gridCount-command.TriggerCount)<1;
default:
throw new Exception("meh");
}
case Trigger.PlayerCount:
return MySession.Static.Players.GetOnlinePlayerCount() >= command.TriggerCount;
switch (command.Compare)
{
case GreaterThan:
return MySession.Static.Players.GetOnlinePlayerCount() >= command.TriggerCount;
case LessThan:
return MySession.Static.Players.GetOnlinePlayerCount() <= command.TriggerCount;
default:
throw new Exception("meh");
}

case Trigger.SimSpeed:
return Math.Min(Sync.ServerSimulationRatio, 1) <= command.TriggerRatio;
var commandActive = _simSpeedCheck.TryGetValue(command, out var time);
switch (command.Compare)
{
case GreaterThan:
if (commandActive)
{
if ((DateTime.Now - time).TotalSeconds < command.TriggerCount) break;
_simSpeedCheck.Remove(command);
return Math.Min(Sync.ServerSimulationRatio, 1) > command.TriggerRatio;
}

if (Math.Min(Sync.ServerSimulationRatio, 1) < command.TriggerRatio) break;
_simSpeedCheck.Add(command, DateTime.Now);
break;

case LessThan:
if (commandActive)
{
if ((DateTime.Now - time).TotalSeconds < command.TriggerCount) break;
_simSpeedCheck.Remove(command);
return Math.Min(Sync.ServerSimulationRatio, 1) < command.TriggerRatio;
}

if (Math.Min(Sync.ServerSimulationRatio, 1) > command.TriggerRatio) break;
_simSpeedCheck.Add(command, DateTime.Now);
break;

case Equal:
if (commandActive)
{
if ((DateTime.Now - time).TotalSeconds < command.TriggerCount) break;
_simSpeedCheck.Remove(command);
return (Math.Abs(Sync.ServerSimulationRatio - command.TriggerRatio) <= 0);
}

if (Math.Abs(Sync.ServerSimulationRatio - command.TriggerRatio)>0)
break;
_simSpeedCheck.Add(command, DateTime.Now);
break;
}
break;

default:
throw new Exception("fuck it");
}
Expand Down