forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdminSpawnNpc.cs
More file actions
52 lines (46 loc) · 1.65 KB
/
Copy pathAdminSpawnNpc.cs
File metadata and controls
52 lines (46 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Threading.Tasks;
using L2dotNET.Attributes;
using L2dotNET.Models.Npcs;
using L2dotNET.Models.Player;
using L2dotNET.Tables;
using L2dotNET.Templates;
using Microsoft.Extensions.DependencyInjection;
namespace L2dotNET.Commands.Admin
{
[Command(CommandName = "spawn")]
class AdminSpawnNpc : AAdminCommand
{
private readonly IdFactory _idFactory;
private readonly SpawnTable _spawnTable;
public AdminSpawnNpc(IServiceProvider serviceProvider) : base(serviceProvider)
{
_idFactory = serviceProvider.GetService<IdFactory>();
_spawnTable = serviceProvider.GetService<SpawnTable>();
}
protected internal override async Task UseAsync(L2Player admin, string alias)
{
await Task.Run(() =>
{
var processedVar = alias.Replace("spawn",string.Empty).Trim();
NpcTemplate npcTemp = null;
int potentialInt;
if (int.TryParse(processedVar, out potentialInt))
{
npcTemp = NpcTable.GetTemplate(potentialInt);
}
else
{
npcTemp = NpcTable.GetTemplateByName(processedVar);
}
if (npcTemp == null)
{
throw new NullReferenceException($"npcTemp is null for {processedVar}");
}
L2Spawn spawn = new L2Spawn(npcTemp, _idFactory, _spawnTable);
spawn.Location = new SpawnLocation(admin.X,admin.Y,admin.Z,admin.Heading, 0);
spawn.Spawn();
});
}
}
}