Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
dad1a19
Now we're cooking
N1Ran Jan 27, 2019
617f8a4
Voting updated with reset for admins
N1Ran Feb 2, 2019
93e01e5
This is the percentage limiter for voting system...derp
N1Ran Feb 2, 2019
c2cd494
funsies
N1Ran Feb 3, 2019
b21be2d
?
N1Ran Feb 3, 2019
fedea70
voting module updated
N1Ran Feb 6, 2019
1591f95
voting module updated
N1Ran Feb 7, 2019
8347c1f
voting module updated.
N1Ran Feb 7, 2019
77dc054
Merge branch 'Patron' into ToPatron
N1Ran Feb 9, 2019
aeb591a
GPS Marker for grids list command
N1Ran Feb 9, 2019
b9239dc
some faction functions
N1Ran Feb 9, 2019
514ea6e
List players online
N1Ran Feb 9, 2019
1ba4878
Faction functions
N1Ran Feb 10, 2019
a33e369
New method to calculate vote
N1Ran Feb 10, 2019
6592cbe
new method to calculate votes
N1Ran Feb 10, 2019
86af0de
twe
N1Ran Feb 10, 2019
72d72e0
tweak
N1Ran Feb 10, 2019
b44e4df
Booyah
N1Ran Feb 11, 2019
0160488
Added command to list players online with admin command (useful for d…
N1Ran Feb 11, 2019
e8a59a6
Added GPS marker option to Grids list command
N1Ran Feb 11, 2019
5cb7f03
added faction list and faction remove option to faction command
N1Ran Feb 11, 2019
a528dc1
Resolving conflict before uploading
N1Ran Feb 11, 2019
7271434
Rex's faction removal merged
N1Ran Feb 11, 2019
cb3d6c7
updated with patrol Torch
N1Ran Feb 11, 2019
3c4d312
comma makes a major difference
N1Ran Feb 13, 2019
e602ea5
Resolve
N1Ran Feb 14, 2019
57f4262
Merger
N1Ran Feb 14, 2019
cecb2de
New Faction feation
N1Ran Feb 15, 2019
3115e8d
AutoCommands revamp in progress
N1Ran Feb 16, 2019
9722ca0
Yet another fix for the damned voting module
N1Ran Feb 17, 2019
3a71685
AutoCommands major tweaks and another go at fixing the damned voting …
N1Ran Feb 17, 2019
0e8019e
Let's get those new goodies loaded and decrease conflicts
N1Ran Feb 17, 2019
3a6acc4
meh
N1Ran Feb 17, 2019
7c7442b
Remove Old method and added OnStart Trigger to AutoCommands
N1Ran Feb 18, 2019
2958523
Run on Start trigger added
N1Ran Feb 18, 2019
ffc03e6
updated
N1Ran Feb 18, 2019
326820a
Here are the commit addressing the review.
N1Ran Feb 20, 2019
cf60893
Lets clear things up and look professional 🕴
N1Ran Feb 20, 2019
bb6e249
Merge branch 'Patron' into ToPatron
rexxar-tc Feb 21, 2019
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
Remove Old method and added OnStart Trigger to AutoCommands
  • Loading branch information
N1Ran committed Feb 18, 2019
commit 7c7442b5b350df3b13caee41b57bac02eaccd73d
34 changes: 6 additions & 28 deletions Essentials/AutoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public class AutoCommand : ViewModel
private Trigger _trigger = Trigger.Disabled;
private int _currentStep;
private string _name;
private bool _enabled;
private float _ratio;
private float _triggerRatio;
private double _triggerCount;

/*
Expand Down Expand Up @@ -88,10 +87,10 @@ public string Interval
}

[Display(Name = "Trigger Ratio", Description = "Ratio for Sim Speed and Vote Triggers. 0.5 is equivalent to 50%")]
public float Ratio
public float TriggerRatio
{
get => _ratio;
set => SetValue(ref _ratio, Math.Min(Math.Max(value, 0), 1));
get => _triggerRatio;
set => SetValue(ref _triggerRatio, Math.Min(Math.Max(value, 0), 1));

}
[Display(Name = "Trigger Count", Description = "Only use with")]
Expand All @@ -101,28 +100,6 @@ public double TriggerCount
set => SetValue(ref _triggerCount, Math.Max(0, value));

}
/*
[Display(Description = "Adds voting option to this command. NOTE: A successful vote will activate this command")]
public bool Votable
{
get => _votable;
set => SetValue(ref _votable, value);
}

[Display(Name = "Vote Duration", Description = "Sets the duration for the vote. NOTE: Make sure to check the votable box to activate. Format is HH:MM:SS.")]
public string VoteDuration
{
get => _voteDuration.ToString();
set => SetValue(ref _voteDuration, TimeSpan.Parse(value));
}

[Display(Name = "Vote Percentage", Description = "Sets the percentage Yes vote needed for the command to activate. NOTE: This only works if the votable box is checked")]
public int Percentage
{
get => _votepercentage;
set => SetValue(ref _votepercentage, Math.Min(Math.Max(value, 0), 100));
}
*/

[Display(Name = "Day of week", GroupName = "Schedule", Description = "Combined with Scheduled Time, will run the command on the given day of the week at the set time.")]
public DayOfWeek DayOfWeek
Expand Down Expand Up @@ -243,7 +220,8 @@ public enum Trigger
Vote,
PlayerCount,
GridCount,
SimSpeed
SimSpeed,
OnStart
}

public enum DayOfWeek
Expand Down
76 changes: 18 additions & 58 deletions Essentials/AutoCommands.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
using NLog;
using Torch.ViewModels;
using Torch.API;
using Torch.Server;
using Sandbox.Game.World;
using Sandbox.Game.Multiplayer;
using Sandbox.Game.Entities;
using VRage.Game.ModAPI;

Expand All @@ -17,77 +20,32 @@ public class AutoCommands : IDisposable
private static AutoCommands _instance;
public static AutoCommands Instance => _instance ?? (_instance = new AutoCommands());
private static readonly Logger Log = LogManager.GetLogger("Essentials");

private Stopwatch _uptime;
private Timer _timer;

public void Start()
{
_uptime = Stopwatch.StartNew();
_timer = new Timer(1000);
_timer.Elapsed += TimerElapsed;
_timer.AutoReset = true;
_timer.Start();
}

/* public void RunChecks()
public void RunOnStart()
{
foreach (var command in EssentialsPlugin.Instance.Config.AutoCommands)
{
switch (command.CommandTrigger)
if (command.CommandTrigger != Trigger.OnStart)
return;
else if(command.CommandTrigger == Trigger.OnStart)
{
case Trigger.SimSpeed:
{
if (MySession.Static.SessionSimSpeedServer <= command.Ratio)
try
{
command.Update();
}
catch (Exception ex)
{
Log.Error(ex, "Error encountered during autocommand update!");
}
}
break;
case Trigger.PlayerCount:
{
if (MySession.Static.Players.GetOnlinePlayerCount() >= command.TriggerCount)
try
{
command.Update();
}
catch (Exception ex)
{
Log.Error(ex, "Error encountered during autocommand update!");
}
break;
}
case Trigger.GridCount:
{
int gridCount = 0;
foreach (var e in MyEntities.GetEntities())
{
if(e is IMyCubeGrid)
gridCount++;
}
if (gridCount >= command.TriggerCount)
{
try
{
command.Update();
}
catch (Exception ex)
{
Log.Error(ex, "Error encountered during autocommand update!");
}
}
break;
}
default:
break;
var elapsed = TimeSpan.FromSeconds(Math.Floor(_uptime.Elapsed.TotalSeconds));
if(TimeSpan.Parse(command.Interval) == elapsed)
command.RunNow();
}
}

}*/

}
private bool CanRun(AutoCommand command)
{
switch (command.CommandTrigger)
Expand All @@ -113,16 +71,18 @@ private bool CanRun(AutoCommand command)
return true;
else return false;
case Trigger.SimSpeed:
if (MySession.Static.SessionSimSpeedServer <= command.Ratio)
if (Math.Min(Sync.ServerSimulationRatio, 1) <= command.TriggerRatio)
return true;
else
return false;

}
}

private void TimerElapsed(object sender, ElapsedEventArgs e)

private void TimerElapsed(object sender, ElapsedEventArgs e)
{
RunOnStart();
foreach (var command in EssentialsPlugin.Instance.Config.AutoCommands)
{
if(!CanRun(command))
Expand Down
4 changes: 2 additions & 2 deletions Essentials/Commands/VotingModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ private IEnumerable VoteCountdown(TimeSpan time)
double vr = ((_voteReg.Count / MySession.Static.Players.GetOnlinePlayerCount()) * 100);
Task.Delay(5000).ContinueWith(_ =>
{
if (vr >= command.Ratio)
if (vr >= command.TriggerRatio)
{
Context.Torch.CurrentSession.Managers.GetManager<IChatManagerClient>()
.SendMessageAsSelf($"Vote for {voteInProgress} is successful");
voteResult = Status.voteSuccess;
command.RunNow();
}
else if (vr < command.Ratio)
else if (vr < command.TriggerRatio)
{
Context.Torch.CurrentSession.Managers.GetManager<IChatManagerClient>()
.SendMessageAsSelf($"Vote for {voteInProgress} failed");
Expand Down
3 changes: 1 addition & 2 deletions Essentials/EssentialsPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ private void SessionChanged(ITorchSession session, TorchSessionState state)
_control.IsEnabled = true;
_control.DataContext = Config;
});
Task.Delay(10000).ContinueWith(_ =>
AutoCommands.Instance.Start());
AutoCommands.Instance.Start();
InfoModule.Init();
break;
case TorchSessionState.Unloading:
Expand Down