Skip to content

Commit 911b610

Browse files
authored
Merge pull request #1 from TorchAPI/master
Update from essentials master
2 parents 5308d5f + 2cd7b68 commit 911b610

10 files changed

Lines changed: 525 additions & 16 deletions

File tree

‎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: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,37 @@ public bool PCULessThan(MyCubeGrid grid, int pcu)
223223
return grid.BlocksPCU < pcu;
224224
}
225225

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+
226257
[Condition("blocksgreaterthan", helpText: "Finds grids with more than the given number of blocks.")]
227258
public bool BlocksGreaterThan(MyCubeGrid grid, int count)
228259
{
@@ -295,13 +326,20 @@ public bool OwnedBy(MyCubeGrid grid, string str)
295326
return grid.BigOwners.Count == 0;
296327
}
297328

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+
298336
if (string.Compare(str, "pirates", StringComparison.InvariantCultureIgnoreCase) == 0)
299337
{
300338
identityId = MyPirateAntennas.GetPiratesId();
301339
}
302340
else
303341
{
304-
var player = Utilities.GetPlayerByNameOrId(str);
342+
var player = Utilities.GetIdentityByNameOrIds(str);
305343
if (player == null)
306344
{
307345
if (long.TryParse(str, out long NPCId))
@@ -318,6 +356,7 @@ public bool OwnedBy(MyCubeGrid grid, string str)
318356

319357
return grid.BigOwners.Contains(identityId);
320358
}
359+
321360

322361
[Condition("hastype", "notype", "Finds grids containing blocks of the given type.")]
323362
public bool BlockType(MyCubeGrid grid, string str)
@@ -334,7 +373,7 @@ public bool BlockSubType(MyCubeGrid grid, string str)
334373
[Condition("haspilot", "Finds grids with pilots")]
335374
public bool Piloted(MyCubeGrid grid)
336375
{
337-
return grid.GetFatBlocks().OfType<MyCockpit>().Any(b => b.Pilot != null);
376+
return grid.GetFatBlocks().OfType<MyShipController>().Any(b => b.Pilot != null);
338377
}
339378

340379
/// <summary>

‎Essentials/Commands/EcoModule.cs‎

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Timers;
7+
using Sandbox;
8+
using Sandbox.Engine.Multiplayer;
9+
using Sandbox.Game.GameSystems.BankingAndCurrency;
10+
using Sandbox.Game.World;
11+
using Torch;
12+
using Torch.API.Managers;
13+
using Torch.Commands;
14+
using Torch.Commands.Permissions;
15+
using Torch.Managers.ChatManager;
16+
using Torch.Mod;
17+
using Torch.Mod.Messages;
18+
using VRage.Game.ModAPI;
19+
using VRageRender.Utils;
20+
21+
namespace Essentials.Commands
22+
{
23+
[Category("econ")]
24+
public class EcoModule : CommandModule {
25+
[Command("give", "Add a specified anount of credits into a users account. Use '*' to affect all players")]
26+
[Permission(MyPromoteLevel.Admin)]
27+
public void EcoGive(string Player, long amount) {
28+
if (Player != "*") {
29+
var p = Utilities.GetPlayerByNameOrId(Player);
30+
if (p == null) {
31+
Context.Respond("Player not found");
32+
return;
33+
}
34+
p.TryGetBalanceInfo(out long balance);
35+
Context.Respond($"new bal will be {balance + amount}");
36+
p.RequestChangeBalance(amount);
37+
ModCommunication.SendMessageTo(new NotificationMessage($"{amount} credits have been added to your virtual account", 10000, "Blue"), p.SteamUserId);
38+
39+
}
40+
else {
41+
foreach (var p in MySession.Static.Players.GetAllPlayers()) {
42+
long IdentityID = MySession.Static.Players.TryGetIdentityId(p.SteamId);
43+
MyBankingSystem.ChangeBalance(IdentityID, amount);
44+
ModCommunication.SendMessageTo(new NotificationMessage($"{amount} credits have been added to your virtual account", 10000, "Blue"), p.SteamId);
45+
}
46+
}
47+
Context.Respond($"{amount} credits given to account(s)");
48+
}
49+
50+
[Command("take", "Take a specified anount of credits from a users account. Use '*' to affect all players")]
51+
[Permission(MyPromoteLevel.Admin)]
52+
public void EcoTake(string Player, long amount) {
53+
if (Player != "*") {
54+
var p = Utilities.GetPlayerByNameOrId(Player);
55+
if (p == null) {
56+
Context.Respond("Player not found");
57+
return;
58+
}
59+
long changefactor = 0 - amount;
60+
p.RequestChangeBalance(changefactor);
61+
ModCommunication.SendMessageTo(new NotificationMessage($"{amount} credits have been taken to your virtual account", 10000, "Blue"), p.SteamUserId);
62+
}
63+
else {
64+
foreach (var p in MySession.Static.Players.GetAllPlayers()) {
65+
long IdentityID = MySession.Static.Players.TryGetIdentityId(p.SteamId);
66+
long balance = MyBankingSystem.GetBalance(IdentityID);
67+
MyBankingSystem.ChangeBalance(IdentityID, -amount);
68+
ModCommunication.SendMessageTo(new NotificationMessage($"{amount} credits have been taken to your virtual account", 10000, "Blue"), p.SteamId);
69+
}
70+
}
71+
Context.Respond($"{amount} credits taken from account(s)");
72+
}
73+
74+
[Command("set", "Set a users account to a specifed balance. Use '*' to affect all players")]
75+
[Permission(MyPromoteLevel.Admin)]
76+
public void EcoSet(string Player, long amount) {
77+
if (Player != "*") {
78+
var p = Utilities.GetPlayerByNameOrId(Player);
79+
if (p == null) {
80+
Context.Respond("Player not found");
81+
return;
82+
}
83+
p.TryGetBalanceInfo(out long balance);
84+
long difference = (balance - amount);
85+
p.RequestChangeBalance(-difference);
86+
ModCommunication.SendMessageTo(new NotificationMessage($"Your balance has been set to {amount} credits!", 10000, "Blue"), p.SteamUserId);
87+
}
88+
else {
89+
foreach (var p in MySession.Static.Players.GetAllPlayers()) {
90+
long IdentityID = MySession.Static.Players.TryGetIdentityId(p.SteamId);
91+
long balance = MyBankingSystem.GetBalance(IdentityID);
92+
long difference = (balance - amount);
93+
MyBankingSystem.ChangeBalance(IdentityID, -difference);
94+
ModCommunication.SendMessageTo(new NotificationMessage($"Your balance has been set to {amount} credits!", 10000, "Blue"), p.SteamId);
95+
}
96+
}
97+
Context.Respond($"Balance(s) set to {amount}");
98+
}
99+
100+
[Command("reset", "Reset the credits in a users account to 10,000. Use '*' to affect all players")]
101+
[Permission(MyPromoteLevel.Admin)]
102+
public void EcoReset(string Player) {
103+
if (Player != "*") {
104+
var p = Utilities.GetPlayerByNameOrId(Player);
105+
if (p == null) {
106+
Context.Respond("Player not found");
107+
return;
108+
}
109+
p.TryGetBalanceInfo(out long balance);
110+
long difference = (balance - 10000);
111+
p.RequestChangeBalance(-difference);
112+
ModCommunication.SendMessageTo(new NotificationMessage($"Your balance has been reset to 10,000 credits!", 10000, "Blue"), p.SteamUserId);
113+
}
114+
else {
115+
foreach (var p in MySession.Static.Players.GetAllPlayers()) {
116+
long IdentityID = MySession.Static.Players.TryGetIdentityId(p.SteamId);
117+
long balance = MyBankingSystem.GetBalance(IdentityID);
118+
long difference = (balance - 10000);
119+
MyBankingSystem.ChangeBalance(IdentityID, -difference);
120+
ModCommunication.SendMessageTo(new NotificationMessage($"Your balance has been reset to 10,000 credits!", 10000, "Blue"), p.SteamId);
121+
}
122+
}
123+
Context.Respond("Balance(s) reset to 10,000 credits");
124+
}
125+
126+
[Command("top", "Return a list of each players balance on the server sorted from highest to lowest")]
127+
[Permission(MyPromoteLevel.None)]
128+
public void EcoTop() {
129+
StringBuilder ecodata = new StringBuilder();
130+
ecodata.AppendLine("Summary of balanaces accross the server");
131+
Dictionary<ulong, long> balances = new Dictionary<ulong, long>();
132+
foreach (var p in MySession.Static.Players.GetAllPlayers()) {
133+
long IdentityID = MySession.Static.Players.TryGetIdentityId(p.SteamId);
134+
long balance = MyBankingSystem.GetBalance(IdentityID);
135+
balances.Add(p.SteamId, balance);
136+
}
137+
var sorted = balances.OrderByDescending(x => x.Value).ThenBy(x => x.Key);
138+
foreach (var value in sorted) {
139+
var test = MySession.Static.Players.TryGetIdentityNameFromSteamId(value.Key);
140+
ecodata.AppendLine($"Player: {MySession.Static.Players.TryGetIdentityNameFromSteamId(value.Key).ToString()} - Balance: {value.Value.ToString()}");
141+
}
142+
143+
if (Context.Player == null) {
144+
Context.Respond(ecodata.ToString());
145+
return;
146+
}
147+
ModCommunication.SendMessageTo(new DialogMessage("Public balance list", "List of players and their credit balances", ecodata.ToString()), Context.Player.SteamUserId);
148+
}
149+
150+
[Command("check", "Check the balance of a specific player")]
151+
[Permission(MyPromoteLevel.None)]
152+
public void EcoCheck(string Player) {
153+
var p = Utilities.GetPlayerByNameOrId(Player);
154+
if (p == null) {
155+
Context.Respond("Player is not online or cannot be found!");
156+
return;
157+
}
158+
long balance = MyBankingSystem.GetBalance(p.Identity.IdentityId);
159+
Context.Respond($"{p.DisplayName}'s balance is {balance} credits");
160+
}
161+
162+
[Command("pay")]
163+
[Permission(MyPromoteLevel.None)]
164+
public void EcoPay(string Player, long amount) {
165+
if (Context.Player == null) {
166+
Context.Respond("Console cannot execute this command");
167+
return;
168+
}
169+
var p = Utilities.GetPlayerByNameOrId(Player);
170+
if (p == null) {
171+
Context.Respond("Player is not online or cannot be found!");
172+
return;
173+
}
174+
MyBankingSystem.RequestTransfer(Context.Player.Identity.IdentityId, p.IdentityId, amount);
175+
ModCommunication.SendMessageTo(new NotificationMessage($"Your have recieved {amount} credits from {Context.Player}!", 10000, "Blue"),p.SteamUserId);
176+
ModCommunication.SendMessageTo(new NotificationMessage($"Your have sent {amount} credits to {p.DisplayName}!", 10000, "Blue"),Context.Player.SteamUserId);
177+
}
178+
179+
}
180+
}

0 commit comments

Comments
 (0)