forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL2Spawn.cs
More file actions
60 lines (52 loc) · 1.77 KB
/
Copy pathL2Spawn.cs
File metadata and controls
60 lines (52 loc) · 1.77 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
53
54
55
56
57
58
59
60
using System;
using L2dotNET.Models.Npcs;
using L2dotNET.Templates;
using NLog;
namespace L2dotNET.Tables
{
public class L2Spawn
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
public NpcTemplate Template { get; set; }
public SpawnLocation Location { get; set; }
public L2Npc Npc { get; set; }
private readonly IdFactory _idFactory;
private readonly SpawnTable _spawnTable;
public L2Spawn(NpcTemplate template, IdFactory idFactory, SpawnTable spawnTable)
{
Template = template ?? throw new ArgumentNullException(nameof(template));
_idFactory = idFactory;
_spawnTable = spawnTable;
}
public int GetNpcId()
{
return Template.NpcId;
}
public L2Npc Spawn(bool notifyOthers = true)
{
L2Npc npc;
if (Type.GetType("L2dotNET.Models.Npcs." + Template.Type) != null)
{
//TODO this is shit. Change it
npc = (L2Npc) Activator.CreateInstance(Type.GetType("L2dotNET.Models.Npcs." + Template.Type),
_spawnTable, _idFactory.NextId(), Template, this);
npc.X = Location.X;
npc.Y = Location.Y;
npc.Z = Location.Z;
npc.Heading = Location.Heading;
}
else
{
npc = new L2Npc(_spawnTable, _idFactory.NextId(), Template, this)
{
X = Location.X,
Y = Location.Y,
Z = Location.Z,
Heading = Location.Heading
};
}
npc.SpawnMeAsync(notifyOthers);
return npc;
}
}
}