Skip to content

Commit caa20d2

Browse files
committed
Merge branch 'master' of https://github.com/TorchSE/Essentials into master
2 parents 2b2d732 + e1d9406 commit caa20d2

21 files changed

Lines changed: 1852 additions & 162 deletions

‎Essentials.Tests/Essentials.Tests.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@
9090
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
9191
</ItemGroup>
9292
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
93-
</Project>
93+
</Project>

‎Essentials/Commands/AdminModule.cs‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,5 +298,36 @@ public void ListMute()
298298
var ms = new DialogMessage("Muted Users", content: sb.ToString());
299299
ModCommunication.SendMessageTo(ms, Context.Player.SteamUserId);
300300
}
301+
302+
[Command("give", "Insert an item with a specific quanity into a players inventory")]
303+
[Permission(MyPromoteLevel.Admin)]
304+
public void give(string playerName, string itemType, string item, int quantity) {
305+
string type = "MyObjectBuilder_" + itemType;
306+
VRage.Game.MyDefinitionId.TryParse(type, item, out VRage.Game.MyDefinitionId defID);
307+
308+
if (defID.ToString().Contains("null")) {
309+
Context.Respond("Invalid item type");
310+
return;
311+
}
312+
313+
if (playerName != "*") {
314+
var p = Utilities.GetPlayerByNameOrId(playerName);
315+
if (p == null) {
316+
Context.Respond("Player not found");
317+
return;
318+
}
319+
Sandbox.Game.MyVisualScriptLogicProvider.AddToPlayersInventory(p.IdentityId, defID, quantity);
320+
ModCommunication.SendMessageTo(new NotificationMessage($"You have been given {quantity} {item} {itemType}", 5000, "Blue"), p.SteamUserId);
321+
}
322+
323+
else {
324+
foreach (var p in MySession.Static.Players.GetOnlinePlayers()) {
325+
var player = Utilities.GetPlayerByNameOrId(p.DisplayName);
326+
Sandbox.Game.MyVisualScriptLogicProvider.AddToPlayersInventory(p.Identity.IdentityId, defID, quantity);
327+
ModCommunication.SendMessageTo(new NotificationMessage($"You have been given {quantity} {item} {itemType}", 5000, "Blue"), player.SteamUserId);
328+
}
329+
}
330+
Context.Respond("Item(s) given!");
331+
}
301332
}
302333
}

‎Essentials/Commands/BlocksModule.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ public void OffType(string type)
6565
foreach (var block in grid.GetFatBlocks().OfType<MyFunctionalBlock>())
6666
{
6767
var blockType = block.BlockDefinition.Id.TypeId.ToString().Substring(16);
68-
if (block != null && string.Compare(type, blockType, StringComparison.InvariantCultureIgnoreCase) ==
69-
0)
68+
if (block != null && string.Compare(type, blockType, StringComparison.InvariantCultureIgnoreCase) == 0 && block.Enabled == true)
7069
{
7170
block.Enabled = false;
7271
count++;

‎Essentials/Commands/CleanupModule.cs‎

Lines changed: 74 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
using System;
1+
using NLog;
2+
using Sandbox.Game.Entities;
3+
using Sandbox.Game.EntityComponents;
4+
using Sandbox.Game.World;
5+
using System;
26
using System.Collections.Generic;
37
using System.Linq;
48
using System.Reflection;
59
using System.Text;
610
using System.Text.RegularExpressions;
7-
using System.Threading.Tasks;
8-
using System.Windows.Media.Media3D;
9-
using Sandbox.Game.Entities;
10-
using Sandbox.Game.World;
1111
using Torch.Commands;
12-
using NLog;
13-
using Sandbox.Game.EntityComponents;
14-
using Sandbox.Game.Multiplayer;
15-
using SpaceEngineers.Game.Entities.Blocks;
1612
using Torch.Mod;
1713
using Torch.Mod.Messages;
18-
using VRage.Game.Entity;
19-
using VRage.Game.ModAPI;
2014
using Vector3D = VRageMath.Vector3D;
2115

2216
namespace Essentials.Commands
@@ -25,6 +19,7 @@ namespace Essentials.Commands
2519
public class CleanupModule : CommandModule
2620
{
2721
private static readonly Logger Log = LogManager.GetLogger("Essentials");
22+
2823
[Command("scan", "Find grids matching the given conditions")]
2924
public void Scan()
3025
{
@@ -64,7 +59,7 @@ public void Delete()
6459
Log.Info($"Cleanup deleted {count} grids matching conditions {string.Join(", ", Context.Args)}");
6560
}
6661

67-
[Command("delete floatingobjects","deletes floating objects")]
62+
[Command("delete floatingobjects", "deletes floating objects")]
6863
public void FlObjDelete()
6964
{
7065
var count = 0;
@@ -76,7 +71,6 @@ public void FlObjDelete()
7671
}
7772
Context.Respond($"Deleted {count} floating objects.");
7873
Log.Info($"Cleanup deleted {count} floating objects");
79-
8074
}
8175

8276
[Command("help", "Lists all cleanup conditions.")]
@@ -89,8 +83,8 @@ public void Help()
8983
sb.AppendLine($" {c.HelpText}");
9084
}
9185

92-
if(!Context.SentBySelf)
93-
ModCommunication.SendMessageTo(new DialogMessage("Cleanup help", null, sb.ToString()), Context.Player.SteamUserId);
86+
if (!Context.SentBySelf)
87+
ModCommunication.SendMessageTo(new DialogMessage("Cleanup help", null, sb.ToString()), Context.Player.SteamUserId);
9488
else
9589
Context.Respond(sb.ToString());
9690
}
@@ -116,8 +110,8 @@ public CleanupModule()
116110
private IEnumerable<MyCubeGrid> ScanConditions(IReadOnlyList<string> args)
117111
{
118112
var conditions = new List<Func<MyCubeGrid, bool?>>();
119-
120-
for (var i = 0; i < args.Count; i ++)
113+
114+
for (var i = 0; i < args.Count; i++)
121115
{
122116
string parameter;
123117
if (i + 1 >= args.Count)
@@ -130,7 +124,6 @@ private IEnumerable<MyCubeGrid> ScanConditions(IReadOnlyList<string> args)
130124
}
131125

132126
var arg = args[i];
133-
134127

135128
if (parameter != null)
136129
{
@@ -169,7 +162,7 @@ private IEnumerable<MyCubeGrid> ScanConditions(IReadOnlyList<string> args)
169162
}
170163

171164
//default scan to find grids without pilots
172-
if(!args.Contains("haspilot", StringComparer.CurrentCultureIgnoreCase))
165+
if (!args.Contains("haspilot", StringComparer.CurrentCultureIgnoreCase))
173166
conditions.Add(g => !Piloted(g));
174167

175168
foreach (var group in MyCubeGridGroups.Static.Logical.Groups)
@@ -180,7 +173,7 @@ private IEnumerable<MyCubeGrid> ScanConditions(IReadOnlyList<string> args)
180173
{
181174
if (node.NodeData.Projector != null)
182175
continue;
183-
176+
184177
foreach (var c in conditions)
185178
{
186179
bool? r = c.Invoke(node.NodeData);
@@ -196,7 +189,7 @@ private IEnumerable<MyCubeGrid> ScanConditions(IReadOnlyList<string> args)
196189
break;
197190
}
198191

199-
if(res)
192+
if (res)
200193
foreach (var grid in group.Nodes.Where(x => x.NodeData.Projector == null))
201194
yield return grid.NodeData;
202195
}
@@ -218,6 +211,49 @@ public bool BlocksLessThan(MyCubeGrid grid, int count)
218211
return grid.BlocksCount < count;
219212
}
220213

214+
[Condition("pcugreaterthan", helpText: "Finds grids with more than the given number of PCU.")]
215+
public bool PCUGreaterThan(MyCubeGrid grid, int pcu)
216+
{
217+
return grid.BlocksPCU > pcu;
218+
}
219+
220+
[Condition("pculessthan", helpText: "Finds grids with less than the given number of PCU.")]
221+
public bool PCULessThan(MyCubeGrid grid, int pcu)
222+
{
223+
return grid.BlocksPCU < pcu;
224+
}
225+
226+
[Condition("hasownertype", helpText: "Finds grids with the specified owner type (npc | player | nobody).")]
227+
public bool HasOwnerType(MyCubeGrid grid, string ownerType)
228+
{
229+
if (string.IsNullOrEmpty(ownerType))
230+
return false;
231+
232+
// Get the owner type of the grid.
233+
var gridOwnerType = Utils.Ownership.GetOwnerType(grid);
234+
235+
// Check provided input string.
236+
switch (ownerType.ToLower().Trim())
237+
{
238+
// Check if grid is owner by an NPC.
239+
case "npc":
240+
case "npcs":
241+
return gridOwnerType == Utils.Ownership.OwnerType.NPC;
242+
243+
// Check if the grid is owned by a Player.
244+
case "player":
245+
case "players":
246+
return gridOwnerType == Utils.Ownership.OwnerType.Player;
247+
248+
// Check if the grid is owned by Nobody.
249+
case "nobody":
250+
return gridOwnerType == Utils.Ownership.OwnerType.Nobody;
251+
}
252+
253+
// In all other cases, just return false.
254+
return false;
255+
}
256+
221257
[Condition("blocksgreaterthan", helpText: "Finds grids with more than the given number of blocks.")]
222258
public bool BlocksGreaterThan(MyCubeGrid grid, int count)
223259
{
@@ -290,18 +326,25 @@ public bool OwnedBy(MyCubeGrid grid, string str)
290326
return grid.BigOwners.Count == 0;
291327
}
292328

329+
if (string.Compare(str, "npc", StringComparison.Ordinal) == 0)
330+
{
331+
return grid.BigOwners.Count > 0 &&
332+
MySession.Static.Factions.IsNpcFaction(grid.BigOwners.FirstOrDefault());
333+
}
334+
335+
293336
if (string.Compare(str, "pirates", StringComparison.InvariantCultureIgnoreCase) == 0)
294337
{
295338
identityId = MyPirateAntennas.GetPiratesId();
296339
}
297340
else
298341
{
299-
var player = Utilities.GetPlayerByNameOrId(str);
342+
var player = Utilities.GetIdentityByNameOrIds(str);
300343
if (player == null)
301344
{
302-
if(long.TryParse(str, out long NPCId))
345+
if (long.TryParse(str, out long NPCId))
303346
{
304-
if(MySession.Static.Players.IdentityIsNpc(NPCId))
347+
if (MySession.Static.Players.IdentityIsNpc(NPCId))
305348
{
306349
return grid.BigOwners.Contains(NPCId);
307350
}
@@ -313,6 +356,7 @@ public bool OwnedBy(MyCubeGrid grid, string str)
313356

314357
return grid.BigOwners.Contains(identityId);
315358
}
359+
316360

317361
[Condition("hastype", "notype", "Finds grids containing blocks of the given type.")]
318362
public bool BlockType(MyCubeGrid grid, string str)
@@ -329,11 +373,11 @@ public bool BlockSubType(MyCubeGrid grid, string str)
329373
[Condition("haspilot", "Finds grids with pilots")]
330374
public bool Piloted(MyCubeGrid grid)
331375
{
332-
return grid.GetFatBlocks().OfType<MyCockpit>().Any(b => b.Pilot != null);
376+
return grid.GetFatBlocks().OfType<MyShipController>().Any(b => b.Pilot != null);
333377
}
334378

335379
/// <summary>
336-
/// Removes pilots from grid before deleting,
380+
/// Removes pilots from grid before deleting,
337381
/// so the character doesn't also get deleted and break everything
338382
/// </summary>
339383
/// <param name="grid"></param>
@@ -360,7 +404,7 @@ public Condition(MethodInfo evalMethod, ConditionAttribute attribute)
360404
InvertCommand = attribute.InvertCommand;
361405
HelpText = attribute.HelpText;
362406
_method = evalMethod;
363-
if(_method.ReturnType!= typeof(bool))
407+
if (_method.ReturnType != typeof(bool))
364408
throw new TypeLoadException("Condition does not return a bool!");
365409
var p = _method.GetParameters();
366410
if (p.Length < 1 || p[0].ParameterType != typeof(MyCubeGrid))
@@ -371,7 +415,6 @@ public Condition(MethodInfo evalMethod, ConditionAttribute attribute)
371415
Parameter = null;
372416
else
373417
Parameter = p[1];
374-
375418
}
376419

377420
public bool? Evaluate(MyCubeGrid grid, string arg, bool invert, CleanupModule module)
@@ -396,13 +439,13 @@ public Condition(MethodInfo evalMethod, ConditionAttribute attribute)
396439
return null;
397440
}
398441

399-
result = (bool)_method.Invoke(module, new[] {grid, val});
442+
result = (bool)_method.Invoke(module, new[] { grid, val });
400443
}
401444
else
402445
{
403-
result = (bool)_method.Invoke(module, new object[] {grid});
446+
result = (bool)_method.Invoke(module, new object[] { grid });
404447
}
405-
448+
406449
return result != invert;
407450
}
408451
}

0 commit comments

Comments
 (0)