Skip to content
39 changes: 32 additions & 7 deletions Essentials/AutoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ public class AutoCommand : ViewModel
private DateTime _nextRun = DateTime.MinValue;
private DayOfWeek _day = DayOfWeek.All;
private int _currentStep;
private int _votepercentage;
private TimeSpan _voteDuration = TimeSpan.Zero;
private string _name;
private bool _enabled;
private bool _votable;

[Display(Description = "Enables or disables this command. NOTE: !admin runauto does NOT respect this setting!")]
public bool Enabled
Expand All @@ -31,6 +34,7 @@ public bool Enabled
set => SetValue(ref _enabled, 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 @@ -72,6 +76,27 @@ public string Interval
}
}

[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, value);
}

[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 @@ -166,13 +191,13 @@ public override string ToString()
internal void RunNow()
{
Task.Run(() =>
{
foreach (var step in Steps)
{
step.RunStep();
Thread.Sleep(step.DelaySpan);
}
});
{
foreach (var step in Steps)
{
step.RunStep();
Thread.Sleep(step.DelaySpan);
}
});
}

public override string ToString()
Expand Down
2 changes: 1 addition & 1 deletion Essentials/Commands/AdminModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void PlayerCount(int count = -1)
{
if (count == -1)
{
Context.Respond($"Nax player count: {MyMultiplayer.Static.MemberLimit}. Current online players: {MyMultiplayer.Static.MemberCount - 1}");
Context.Respond($"Max player count: {MyMultiplayer.Static.MemberLimit}. Current online players: {MyMultiplayer.Static.MemberCount - 1}");
return;
}

Expand Down
174 changes: 174 additions & 0 deletions Essentials/Commands/BlocksModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sandbox.Common.ObjectBuilders;
using Sandbox.Game.Entities;
using VRage.Game.ModAPI;
using Sandbox.Game.Entities.Cube;
using Sandbox.ModAPI;
using Torch.Commands;
Expand Down Expand Up @@ -136,5 +138,177 @@ public void OffSubtype(string subtype)

Context.Respond($"Disabled {count} blocks of subtype {subtype}.");
}

[Command("on general", "Turn on all blocks of the specified general")]
public void OnGeneral(string category)
{
blockcategory result;
var count = 0;
if (Enum.TryParse(category, out result))
{
switch (result)
{
case blockcategory.power:
{
foreach (var entity in MyEntities.GetEntities().OfType<MyCubeGrid>())
{
IMyCubeGrid grid = entity as MyCubeGrid;
var blocks = new List<IMySlimBlock>();
grid.GetBlocks(blocks, f => f.FatBlock != null && f.FatBlock is IMyFunctionalBlock
&& (f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Reactor) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_BatteryBlock) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_SolarPanel)));
var list = blocks.Select(f => (IMyFunctionalBlock)f.FatBlock).Where(f => !f.Enabled).ToArray();
foreach (var item in list)
{
item.Enabled = true;
}
count++;
}
}
break;
case blockcategory.production:
{
foreach (var entity in MyEntities.GetEntities().OfType<MyCubeGrid>())
{
IMyCubeGrid grid = entity as MyCubeGrid;
var blocks = new List<IMySlimBlock>();
grid.GetBlocks(blocks, f => f.FatBlock != null && f.FatBlock is IMyFunctionalBlock
&& (f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Refinery) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Assembler) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_OxygenGenerator)));
var list = blocks.Select(f => (IMyFunctionalBlock)f.FatBlock).Where(f => !f.Enabled).ToArray();
foreach (var item in list)
{
item.Enabled = true;
}
count++;
}
}
break;
case blockcategory.weapons:
{
foreach (var entity in MyEntities.GetEntities().OfType<MyCubeGrid>())
{
IMyCubeGrid grid = entity as MyCubeGrid;
var blocks = new List<IMySlimBlock>();
grid.GetBlocks(blocks, f => f.FatBlock != null && f.FatBlock is IMyFunctionalBlock
&& (f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_InteriorTurret) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_TurretBase) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_LargeMissileTurret)));
var list = blocks.Select(f => (IMyFunctionalBlock)f.FatBlock).Where(f => !f.Enabled).ToArray();
foreach (var item in list)
{
item.Enabled = true;
}
count++;
}
}
break;

}
}
else
{
Context.Respond($"{category} is not part of the set. Use the following with this command: power, production, weapons ");
return;
}



Context.Respond($"Enabled {count} {category} blocks.");
}


[Command("off general", "Turn off all blocks of the specified general")]
public void OffGeneral(string category)
{
blockcategory result;
var count = 0;
if (Enum.TryParse(category, out result))
{
switch (result)
{
case blockcategory.power:
{
foreach (var entity in MyEntities.GetEntities().OfType<MyCubeGrid>())
{
IMyCubeGrid grid = entity as MyCubeGrid;
var blocks = new List<IMySlimBlock>();
grid.GetBlocks(blocks, f => f.FatBlock != null && f.FatBlock is IMyFunctionalBlock
&& (f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Reactor) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_BatteryBlock) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_SolarPanel)));
var list = blocks.Select(f => (IMyFunctionalBlock)f.FatBlock).Where(f => f.Enabled).ToArray();
foreach (var item in list)
{
item.Enabled = false;
}
count++;
}
}
break;
case blockcategory.production:
{
foreach (var entity in MyEntities.GetEntities().OfType<MyCubeGrid>())
{
IMyCubeGrid grid = entity as MyCubeGrid;
var blocks = new List<IMySlimBlock>();
grid.GetBlocks(blocks, f => f.FatBlock != null && f.FatBlock is IMyFunctionalBlock
&& (f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Refinery) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Assembler) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_OxygenGenerator)));
var list = blocks.Select(f => (IMyFunctionalBlock)f.FatBlock).Where(f => f.Enabled).ToArray();
foreach (var item in list)
{
item.Enabled = false;
}
count++;
}
}
break;
case blockcategory.weapons:
{
foreach (var entity in MyEntities.GetEntities().OfType<MyCubeGrid>())
{
IMyCubeGrid grid = entity as MyCubeGrid;
var blocks = new List<IMySlimBlock>();
grid.GetBlocks(blocks, f => f.FatBlock != null && f.FatBlock is IMyFunctionalBlock
&& (f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_InteriorTurret) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_TurretBase) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_LargeMissileTurret)));
var list = blocks.Select(f => (IMyFunctionalBlock)f.FatBlock).Where(f => f.Enabled).ToArray();
foreach (var item in list)
{
item.Enabled = false;
}
count++;
}
}
break;

}
}
else
{
Context.Respond($"{category} is not part of the set. Use the following with this command: power, production, weapons ");
return;
}



Context.Respond($"Disabled {count} {category} blocks.");
}



public enum blockcategory
{
power,
production,
weapons

}
}

}
15 changes: 15 additions & 0 deletions Essentials/Commands/CleanupModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ public void Delete()
Log.Info($"Cleanup deleted {count} grids matching conditions {string.Join(", ", Context.Args)}");
}

[Command("delete floatingobjects","deletes floating objects")]
public void FlObjDelete()
{
var count = 0;
foreach (var floater in MyEntities.GetEntities().OfType<MyFloatingObject>())
{
Log.Info($"Deleting floating object: {floater.DisplayName}");
floater.Close();
count++;
}
Context.Respond($"Deleted {count} floating objects.");
Log.Info($"Cleanup deleted {count} floating objects");

}

[Command("help", "Lists all cleanup conditions.")]
public void Help()
{
Expand Down
Loading