Skip to content
Merged
Changes from all commits
Commits
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
Voting updated with reset for admins
  • Loading branch information
N1Ran committed Feb 2, 2019
commit 617f8a447122713f49036feb90a2495ef96e19b9
25 changes: 20 additions & 5 deletions Essentials/Commands/VotingModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sandbox.Engine.Multiplayer;
using Sandbox.Game.World;
using Torch.API.Managers;
using Torch.Commands;
using Torch.Commands.Permissions;
Expand Down Expand Up @@ -183,7 +183,7 @@ public void VoteCount()
StringBuilder sb = new StringBuilder();
sb.AppendLine($"Current vote: {voteInProgress}");
sb.AppendLine($"vote Status: {VoteStatus.ToString()}");
sb.AppendLine($"vote count: {_voteReg.Count} / player count: {MyMultiplayer.Static.MemberCount - 1}");
sb.AppendLine($"vote count: {_voteReg.Count} / player count: {MySession.Static.Players.GetOnlinePlayerCount()}");
sb.AppendLine($"vote percent: {votePercent}");
Context.Respond(sb.ToString());

Expand All @@ -202,7 +202,7 @@ private IEnumerable VoteCountdown(TimeSpan time)
{
Context.Torch.CurrentSession.Managers.GetManager<IChatManagerClient>()
.SendMessageAsSelf($"Vote for {voteInProgress} cancelled");
VoteReset();
VoteClear();
yield break;
}

Expand All @@ -222,7 +222,7 @@ private IEnumerable VoteCountdown(TimeSpan time)
}
else
{
votePercent = (int)Math.Round((double)100 * (_voteReg.Count / (MyMultiplayer.Static.MemberCount - 1)));
votePercent = (int)Math.Round((double)100 * (_voteReg.Count / (MySession.Static.Players.GetOnlinePlayerCount())));

if (votePercent >= command.Percentage)
{
Expand All @@ -235,13 +235,28 @@ private IEnumerable VoteCountdown(TimeSpan time)
Context.Torch.CurrentSession.Managers.GetManager<IChatManagerClient>()
.SendMessageAsSelf($"Vote for {voteInProgress} failed");
}
VoteReset();
VoteClear();
yield break;
}
}
}

[Command("vote reset", "Reset all vote logs")]
[Permission(MyPromoteLevel.Admin)]
public void VoteReset()
{
if (VoteStatus == Status.VoteInProgress)
{
VoteCancel();
}
else
VoteClear();
VoteClear();
votePercent = 0;
_votetimeout.Clear();
}

public void VoteClear()
{
Random rnd = new Random();
_cooldown = rnd.Next(5, 30);
Expand Down