Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spawnqi command. #557

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ConsoleCommands/BaseTemplateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal abstract class BaseTemplateCommand : ConsoleCommandWithArgument
{
public override string Pattern => RequiredArgumentPattern;

protected static IEnumerable<ItemTemplate> FindTemplates(string searchShortNameOrTemplateId)
protected static ItemTemplate[] FindTemplates(string searchShortNameOrTemplateId)
{
if (!Singleton<ItemFactory>.Instantiated)
return [];
Expand All @@ -29,6 +29,7 @@ protected static IEnumerable<ItemTemplate> FindTemplates(string searchShortNameO
return templates
.Values
.Where(t => t.ShortNameLocalizationKey.Localized().IndexOf(searchShortNameOrTemplateId, StringComparison.OrdinalIgnoreCase) >= 0
|| t.NameLocalizationKey.Localized().IndexOf(searchShortNameOrTemplateId, StringComparison.OrdinalIgnoreCase) >= 0);
|| t.NameLocalizationKey.Localized().IndexOf(searchShortNameOrTemplateId, StringComparison.OrdinalIgnoreCase) >= 0)
.ToArray();
}
}
41 changes: 34 additions & 7 deletions ConsoleCommands/Spawn.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
using System.Linq;
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Comfort.Common;
using Diz.Utils;
using EFT.CameraControl;
using EFT.InventoryLogic;
using EFT.Trainer.Extensions;
using EFT.Trainer.Features;
using EFT.Trainer.Properties;
using JetBrains.Annotations;
using UnityEngine;
using Random = UnityEngine.Random;

#nullable enable

Expand All @@ -29,7 +33,7 @@ public override void Execute(Match match)
return;

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

switch (templates.Length)
{
Expand All @@ -45,25 +49,41 @@ public override void Execute(Match match)
}

var tpl = templates[0];
SpawnTemplate(tpl, player, this);
}

internal static void SpawnTemplate(string template, Player player, ConsoleCommand command, Func<ItemTemplate, bool> filter)
{
var result = FindTemplates(template)
.FirstOrDefault(filter);

if (result == null)
return;

SpawnTemplate(result, player, command);
}

private static void SpawnTemplate(ItemTemplate template, Player player, ConsoleCommand command)
{
var poolManager = Singleton<PoolManager>.Instance;

poolManager
.LoadBundlesAndCreatePools(PoolManager.PoolsCategory.Raid, PoolManager.AssemblyType.Online, [.. tpl.AllResources], JobPriority.Immediate)
.LoadBundlesAndCreatePools(PoolManager.PoolsCategory.Raid, PoolManager.AssemblyType.Online, [.. template.AllResources], JobPriority.Immediate)
.ContinueWith(task =>
{
AsyncWorker.RunInMainTread(delegate
{
if (task.IsFaulted)
{
AddConsoleLog(Strings.ErrorFailedToLoadItemBundle.Red());
command.AddConsoleLog(Strings.ErrorFailedToLoadItemBundle.Red());
}
else
{
var itemFactory = Singleton<ItemFactory>.Instance;
var item = itemFactory.CreateItem(MongoID.Generate(), tpl._id, null);
var item = itemFactory.CreateItem(MongoID.Generate(), template._id, null);
if (item == null)
{
AddConsoleLog(Strings.ErrorFailedToCreateItem.Red());
command.AddConsoleLog(Strings.ErrorFailedToCreateItem.Red());
}
else
{
Expand All @@ -74,7 +94,14 @@ public override void Execute(Match match)

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);

var transform = player.Transform;
var position = transform.position
+ transform.right * Random.Range(-1f, 1f)
+ transform.forward * 2f
+ transform.up * 0.5f;

lootItem.transform.SetPositionAndRotation(position, transform.rotation);
lootItem.LastOwner = player;
}
}
Expand Down
3 changes: 2 additions & 1 deletion ConsoleCommands/SpawnBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
namespace EFT.Trainer.ConsoleCommands;

[UsedImplicitly]
internal class SpawnBot : BaseTemplateCommand
internal class SpawnBot : ConsoleCommandWithArgument
{
public const string MatchAll = "*";

public override string Pattern => RequiredArgumentPattern;
public override string Name => Strings.CommandSpawnBot;

public override void Execute(Match match)
Expand Down
57 changes: 57 additions & 0 deletions ConsoleCommands/SpawnQuestItems.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Collections.Generic;
using System.Linq;
using EFT.Quests;
using EFT.Trainer.Extensions;
using EFT.Trainer.Features;
using EFT.Trainer.Properties;
using JetBrains.Annotations;
using UnityEngine;

#nullable enable

namespace EFT.Trainer.ConsoleCommands;

[UsedImplicitly]
internal class SpawnQuestItems : ConsoleCommandWithoutArgument
{
public override string Name => Strings.CommandSpawnQuestItems;

public override void Execute()
{
var player = GameState.Current?.LocalPlayer;
if (!player.IsValid())
return;

var profile = player.Profile;

var startedQuests = profile.QuestsData
.Where(q => q.Status is EQuestStatus.Started && q.Template != null)
.ToArray();

if (!startedQuests.Any())
return;

foreach (var quest in startedQuests)
{
foreach (var condition in GetConditions(quest))
{
var count = Mathf.RoundToInt(condition.value);
if (count is <= 0 or > 20)
continue;

foreach (var target in condition.target)
{
for (var i = 0; i < count; i++)
Spawn.SpawnTemplate(target, player, this, t => !t.QuestItem); // for now we are only able to spawn non location-specific items like batteries, meds, keys, etc.
}
}
}
}

private static IEnumerable<ConditionMultipleTargets> GetConditions(QuestDataClass quest)
{
// do we need to add ConditionMultipleTargets / ConditionItem / ConditionPlaceItem
var conditions = quest.Template!.Conditions[EQuestStatus.AvailableForFinish];
return conditions.OfType<ConditionFindItem>();
}
}
1 change: 1 addition & 0 deletions NLog.EFT.Trainer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<Compile Include="ConsoleCommands\ListSuperRare.cs" />
<Compile Include="ConsoleCommands\LoadTrackList.cs" />
<Compile Include="ConsoleCommands\SaveTrackList.cs" />
<Compile Include="ConsoleCommands\SpawnQuestItems.cs" />
<Compile Include="ConsoleCommands\SpawnBot.cs" />
<Compile Include="ConsoleCommands\Spawn.cs" />
<Compile Include="ConsoleCommands\Status.cs" />
Expand Down
9 changes: 9 additions & 0 deletions Properties/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Properties/Strings.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -934,4 +934,7 @@ Les couleurs sont stockées sous la forme d'un tableau de valeurs flottantes 'RG
<data name="CommandSpawnBotEnumerateFormat" xml:space="preserve">
<value>{0}</value>
</data>
<data name="CommandSpawnQuestItems" xml:space="preserve">
<value>spawnqi</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Properties/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -934,4 +934,7 @@ Colors are stored as an array of 'RGBA' floats</value>
<data name="CommandSpawnBotEnumerateFormat" xml:space="preserve">
<value>{0}</value>
</data>
<data name="CommandSpawnQuestItems" xml:space="preserve">
<value>spawnqi</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Properties/Strings.zh-cn.resx
Original file line number Diff line number Diff line change
Expand Up @@ -935,4 +935,7 @@
<data name="CommandSpawnBotEnumerateFormat" xml:space="preserve">
<value>{0}</value>
</data>
<data name="CommandSpawnQuestItems" xml:space="preserve">
<value>spawnqi</value>
</data>
</root>
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ This trainer hooks into the command system, so you can easily setup features usi
| savetl | `[filename]` | | Save current tracklist to file |
| spawn | `[name]` | | Spawn object in front of player |
| spawnbot | `[name]` or `*` | | Spawn a bot, ex `spawnbot bossKilla` |
| spawnqi | | | Spawn items-to-find in active quests |
| stamina | `on` or `off` | `off` | Enable/Disable unlimited stamina |
| stash | `on` or `off` | `off` | Show/Hide stashes |
| status | | | Show status of all features |
Expand Down