forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL2Merchant.cs
More file actions
94 lines (77 loc) · 2.61 KB
/
Copy pathL2Merchant.cs
File metadata and controls
94 lines (77 loc) · 2.61 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System.Threading.Tasks;
using L2dotNET.Templates;
using L2dotNET.Network.serverpackets;
using L2dotNET.World;
using System.Timers;
using L2dotNET.Models.Player;
using L2dotNET.Network;
using L2dotNET.Tables;
using NLog;
namespace L2dotNET.Models.Npcs
{
class L2Merchant : L2Npc
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
private Timer CorpseTimer;
private readonly SpawnTable _spawnTable;
public L2Merchant(SpawnTable spawnTable, int objectId, NpcTemplate template, L2Spawn spawn) : base(spawnTable, objectId, template, spawn)
{
_spawnTable = spawnTable;
Template = template;
Name = template.Name;
InitializeCharacterStatus();
CharStatus.SetCurrentHp(MaxHp);
CharStatus.SetCurrentMp(MaxMp);
//Stats = new CharacterStat(this);
}
public override async Task SendPacketAsync(GameserverPacket pk)
{
foreach (L2Player pl in L2World.GetPlayers())
{
// TODO: Sends to all players on the server. It is not right
await pl.Gameclient.SendPacketAsync(pk);
}
}
public override async Task OnActionAsync(L2Player player)
{
if (player.Target != this)
{
player.SetTargetAsync(this);
return;
}
await player.CharMovement.MoveTo(X, Y, Z);
await player.SendPacketAsync(new MoveToPawn(player, this, 150));
}
public override async Task DoDieAsync(L2Character killer)
{
lock (this)
{
if (Dead)
return;
CharStatus.SetCurrentHp(0);
Dead = true;
}
Target = null;
await CharMovement.NotifyStopMove(true);
if (IsAttacking())
AbortAttack();
CharStatus.StopHpMpRegeneration();
await BroadcastPacketAsync(new Die(this));
_spawnTable.RegisterRespawn(spawn);
if (Template.CorpseTime <= 0)
{
return;
}
CorpseTimer = new Timer(Template.CorpseTime * 1000);
CorpseTimer.Elapsed += RemoveCorpse;
CorpseTimer.Start();
}
private async void RemoveCorpse(object sender, ElapsedEventArgs e)
{
CorpseTimer.Stop();
CorpseTimer.Enabled = false;
await BroadcastPacketAsync(new DeleteObject(ObjectId));
L2World.RemoveObject(this);
}
}
}