Skip to content

Commit

Permalink
Add spawn command
Browse files Browse the repository at this point in the history
  • Loading branch information
sailro committed Apr 14, 2024
1 parent 8446497 commit 721b129
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Features/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Comfort.Common;
using EFT.CameraControl;
using EFT.Interactive;
using EFT.InventoryLogic;
using EFT.Trainer.Configuration;
Expand Down Expand Up @@ -447,6 +449,7 @@ private void RegisterCommands()
CreateCommand("load", () => LoadSettings());
CreateCommand("save", SaveSettings);

CreateCommand("spawn", $"(?<{ValueGroup}>.+)", SpawnItem);
CreateCommand("template", $"(?<{ValueGroup}>.+)", FindTemplates);

// Load default configuration
Expand Down Expand Up @@ -496,6 +499,59 @@ private void FindTemplates(Match match)
AddConsoleLog($"found {templates.Length.ToString().Cyan()} template(s)");
}

private void SpawnItem(Match match)
{
var matchGroup = match.Groups[ValueGroup];
if (matchGroup is not { Success: true })
return;

var player = GameState.Current?.LocalPlayer;
if (player == null)
return;

var search = matchGroup.Value;
var templates = FindTemplates(search).ToArray();

switch (templates.Length)
{
case 0:
AddConsoleLog("No template found!");
return;
case > 1:
{
foreach (var template in templates)
AddConsoleLog($"{template._id}: {template.ShortNameLocalizationKey.Localized().Green()} [{template.NameLocalizationKey.Localized()}]");

AddConsoleLog($"found {templates.Length.ToString().Cyan()} templates, be more specific");
return;
}
}

var tpl = templates[0];
var poolManager = Singleton<PoolManager>.Instance;

poolManager.LoadBundlesAndCreatePools(PoolManager.PoolsCategory.Raid, PoolManager.AssemblyType.Online, [..tpl.AllResources], JobPriority.Immediate).ContinueWith(delegate
{
var itemFactory = Singleton<ItemFactory>.Instance;
var item = itemFactory.CreateItem(MongoID.Generate(), tpl._id, null);
if (item == null)
{
AddConsoleLog("Failed to create item!");
return Task.CompletedTask;
}

_ = new TraderControllerClass(item, item.Id, item.ShortName);
var go = poolManager.CreateLootPrefab(item, ECameraType.Default);

go.SetActive(value: true);
var lootItem = Singleton<GameWorld>.Instance.CreateLootWithRigidbody(go, item, item.ShortName, Singleton<GameWorld>.Instance, randomRotation: false, null, out _);
lootItem.transform.SetPositionAndRotation(player.Transform.position + player.Transform.forward * 2f + player.Transform.up * 0.5f, player.Transform.rotation);
lootItem.LastOwner = player;

return Task.CompletedTask;
});
}

private void SetupWindowCoordinates()
{
bool needfix = false;
Expand Down
3 changes: 3 additions & 0 deletions NLog.EFT.Trainer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@
<Reference Include="ItemTemplate.Types">
<HintPath>$(EFTManagedPath)\ItemTemplate.Types.dll</HintPath>
</Reference>
<Reference Include="DissonanceVoip">
<HintPath>$(EFTManagedPath)\DissonanceVoip.dll</HintPath>
</Reference>
<Reference Include="0Harmony">
<HintPath>Installer\Resources\0Harmony.dll</HintPath>
</Reference>
Expand Down

0 comments on commit 721b129

Please sign in to comment.