Skip to content

Commit

Permalink
[Game] Fixed selection of spawnerId for the current templateId: (#964)
Browse files Browse the repository at this point in the history
* [Game] Fixed selection of spawnerId for the current templateId:
- For each spawnerId, the templateId we need is usually specified in template.Name;

* [Game] Changes made:
- moved the declaration of the pattern & regexp variable to the outer area outside the loop;
  • Loading branch information
NL0bP committed Jun 5, 2024
1 parent 3f1fef0 commit 519a072
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions AAEmu.Game/Core/Managers/World/SpawnManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -57,17 +58,32 @@ public void AddNpcSpawner(NpcSpawner npcSpawner)
var npcSpawnerIds = NpcGameData.Instance.GetSpawnerIds(npcSpawner.UnitId);
// TODO добавил список спавнеров // added a list of spawners
var spawners = new List<NpcSpawner>();
var pattern = $@"\b{Regex.Escape(npcSpawner.UnitId.ToString())}\b";
var regex = new Regex(pattern);
foreach (var id in npcSpawnerIds)
{
npcSpawner.NpcSpawnerIds.Add(id);
// в template.Name обычно должно присутствовать templateId для нашего Npc, по нему будем брать нужный spawnerId
// in template.Name there should usually be a templateId for our Npc, we will use it to take the required spawnerId
var template = NpcGameData.Instance.GetNpcSpawnerTemplate(id);
if (template.NpcSpawnerCategoryId == NpcSpawnerCategory.Normal && npcSpawnerIds.Count > 1)
var containsId = regex.IsMatch(template.Name);
if (containsId)
{
continue;
npcSpawner.NpcSpawnerIds.Add(id);
npcSpawner.Id = id;
npcSpawner.Template = template;
foreach (var n in npcSpawner.Template.Npcs)
{
n.Position = npcSpawner.Position;
}
}
// сохраняем npcSpawner.Id для NpcSpawnerCategory.Autocreated
}

if (npcSpawner.Id == 0 && npcSpawnerIds.Count == 1)
{
var id = npcSpawnerIds[0];
npcSpawner.NpcSpawnerIds.Add(id);
npcSpawner.Id = id;
npcSpawner.Template = template;
npcSpawner.Template = NpcGameData.Instance.GetNpcSpawnerTemplate(id);
foreach (var n in npcSpawner.Template.Npcs)
{
n.Position = npcSpawner.Position;
Expand Down

0 comments on commit 519a072

Please sign in to comment.