forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL2Npc.cs
More file actions
396 lines (344 loc) · 15.5 KB
/
Copy pathL2Npc.cs
File metadata and controls
396 lines (344 loc) · 15.5 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
using System.Threading.Tasks;
using System.Timers;
using L2dotNET.Models.Player;
using L2dotNET.Network.serverpackets;
using L2dotNET.Templates;
using L2dotNET.Tools;
using L2dotNET.World;
using L2dotNET.Tables;
using NLog;
namespace L2dotNET.Models.Npcs
{
public class L2Npc : L2Character
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
public new NpcTemplate Template;
public bool Summoned;
public bool StructureControlled = false;
public L2Npc(SpawnTable spawnTable, int objectId, NpcTemplate template, L2Spawn spawn) : base(objectId, template)
{
Template = template;
Name = Template.Name;
InitializeCharacterStatus();
CharStatus.SetCurrentHp(MaxHp);
CharStatus.SetCurrentMp(MaxMp);
this.spawn = spawn;
//CStatsInit();
}
protected L2Spawn spawn;
//public virtual void setTemplate(NpcTemplate template)
//{
// Template = template;
// ObjID = IdFactory.Instance.nextId();
// CStatsInit();
// CharacterStat.setTemplate(template);
// CurHP = CharacterStat.getStat(skills2.TEffectType.b_max_hp);
// Name = template.Name;
// AIProcessor = new citizen();
// AIProcessor.dialog = new Dictionary<string, string>();
// AIProcessor.diaLog.Add("fnHi", "lector001.htm");
// AIProcessor.diaLog.Add("fnFeudInfo", "gludio_feud_manager001.htm");
// AIProcessor.diaLog.Add("fnNoFeudInfo", "farm_messenger002.htm");
// AIProcessor.myself = this;
//}
public override async Task NotifyActionAsync(L2Player player)
{
double dis = Calcs.CalculateDistance(player, this, true);
await CharMovement.MoveTo(X, Y, Z);
}
public int NpcId => Template.NpcId;
public int NpcHashId => Template.NpcId + 1000000;
public new byte IsRunning()
{
return 1;
}
public byte IsAlikeDead()
{
return 0;
}
public override async Task OnActionAsync(L2Player player)
{
if (player.Target != this)
player.SetTargetAsync(this);
else
{
await player.CharMovement.MoveTo(X, Y, Z);
await player.SendPacketAsync(new MoveToPawn(player, this, 150));
if (Template.Type == "L2Monster")
{
Log.Debug("Attack Monester By L2NPC");
await player.DoAttackAsync(this);
}
await player.SendActionFailedAsync();
}
}
public override async Task OnActionShiftAsync(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));
await ShowNPCInfoAsync(player);
}
public virtual void OnTeleportRequest(L2Player player)
{
}
public void UseTeleporter(L2Player player, int type, int entryId)
{
}
public virtual void OnDialog(L2Player player, int ask, int reply)
{
player.FolkNpc = this;
//if (ask > 0 && ask < 1000)
//{
// QuestManager.Instance.OnQuestTalk(player, this, ask, reply);
// return;
//}
//AITemplate t = AIManager.Instance.CheckDialogResult(Template.NpcId);
//if (t != null)
//{
// t.onDialog(player, ask, reply, this);
// return;
//}
//switch (ask)
//{
// case -1:
// switch (reply)
// {
// case 8:
// player.sendPacket(new ExBuySellList_Buy(player.getAdena()));
// player.sendPacket(new ExBuySellList_Sell(player));
// break;
// default:
// NpcData.Instance.Buylist(player, this, (short)reply);
// break;
// }
// break;
// case -3:
// grandmaster_total.onReply(player, reply, this);
// break;
// case -19: //нобл запрос
// switch (reply)
// {
// case 0:
// case 1:
// player.ShowHtm(player.Noblesse == 1 ? "fornobless.htm" : "fornonobless.htm", this);
// break;
// }
// break;
// case -20: //нобл запрос
// switch (reply)
// {
// case 2:
// NpcData.Instance.RequestTeleportList(this, player, 2);
// break;
// }
// break;
// case -21: //нобл запрос
// switch (reply)
// {
// case 2:
// NpcData.Instance.RequestTeleportList(this, player, 3);
// break;
// }
// break;
// case -22: //нобл запрос
// switch (reply)
// {
// case 2:
// NpcData.Instance.RequestTeleportList(this, player, 1);
// break;
// }
// break;
// case -303:
// MultiSell.Instance.ShowList(player, this, reply);
// break;
// case -305:
// switch (reply)
// {
// case 1:
// // NpcData.getInstance().multisell(player, this, reply); //TEST
// break;
// }
// break;
// case -1000:
// {
// switch (reply)
// {
// case 1:
// //See the lord and get the tax rate information
// break;
// }
// }
// break;
//}
}
public override async Task OnForcedAttackAsync(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 async Task ShowSkillLearnAsync(L2Player player, bool backward)
{
await player.SendMessageAsync("I cannot teach you anything.");
}
public override async Task BroadcastUserInfoAsync()
{
// TODO: Sends to all players on the server. It is not right
foreach (L2Player pl in L2World.GetPlayers())
{
await pl.SendPacketAsync(new NpcInfo(this));
}
}
public override async Task BroadcastUserInfoToObjectAsync(L2Object l2Object)
{
await l2Object.SendPacketAsync(new NpcInfo(this));
}
public override async Task OnSpawnAsync(bool notifyOthers = true)
{
if (notifyOthers)
await BroadcastUserInfoAsync();
StartAi();
}
private Timer _corpseTimer;
public int ResidenceId;
public override async Task DoDieAsync(L2Character killer)
{
await base.DoDieAsync(killer);
if (Template.CorpseTime <= 0)
{
return;
}
_corpseTimer = new Timer(Template.CorpseTime * 1000);
_corpseTimer.Elapsed += RemoveCorpse;
_corpseTimer.Enabled = true;
}
private async void RemoveCorpse(object sender, ElapsedEventArgs e)
{
_corpseTimer.Enabled = false;
_corpseTimer.Stop();
await BroadcastPacketAsync(new DeleteObject(ObjectId));
L2World.RemoveObject(this);
}
public override async Task DeleteByForceAsync()
{
if ((_corpseTimer != null) && _corpseTimer.Enabled)
_corpseTimer.Enabled = false;
await base.DeleteByForceAsync();
}
public bool IsBoss()
{
return false; //Template.AiT == templates.TObjectCategory.boss;
}
public void ConsumeBody()
{
if (_corpseTimer != null)
_corpseTimer.Enabled = false;
_corpseTimer = null;
RemoveCorpse(null, null);
}
public bool IsFlying()
{
return false;
}
public async Task ShowNPCInfoAsync(L2Player player)
{
NpcHtmlMessage html = new NpcHtmlMessage(player, "./html/admin/npcinfo.htm", ObjectId);
html.Replace("%objid%", ObjectId);
html.Replace("%class%", "null");
html.Replace("%id%", NpcId);
html.Replace("%lvl%", Level);
html.Replace("%name%", Name);
html.Replace("%tmplid%", Template.IdTemplate);
html.Replace("%aggro%", Attackable > 0 ? Template.AggroRange : 0);
html.Replace("%corpse%", Template.CorpseTime);
html.Replace("%enchant%", Template.EnchantEffect);
html.Replace("%hp%", CharStatus.CurrentHp);
html.Replace("%hpmax%", MaxHp);
html.Replace("%mp%", CharStatus.CurrentMp);
html.Replace("%mpmax%", MaxMp);
html.Replace("%patk%", Template.BasePAtk);
html.Replace("%matk%", Template.BaseMAtk);
html.Replace("%mdef%", Template.BaseMDef);
html.Replace("%pdef%", Template.BasePDef);
html.Replace("%accu%", CharacterStat.Accuracy);
html.Replace("%evas%", CharacterStat.EvasionRate(this));
html.Replace("%crit%", Template.BaseCritRate);
html.Replace("%aspd%", Template.BasePAtkSpd);
html.Replace("%cspd%", CharacterStat.MAttackSpeed);
html.Replace("%rspd%", Template.BaseRunSpd);
html.Replace("%str%", Str);
html.Replace("%con%", Con);
html.Replace("%dex%", Dex);
html.Replace("%int%", Int);
html.Replace("%wit%", Wit);
html.Replace("%men%", Men);
html.Replace("%loc%", $"{X} {Y} {Z}");
html.Replace("%dist%", player.CharMovement.DistanceToSquared(X,Y));
// // byte attackAttribute = ((L2Character)this).getAttackElement();
// html.replace("%ele_atk_value%", "%todo%" /* String.valueOf(((L2Character)this).getAttackElementValue(attackAttribute)) */);
// html.replace("%ele_dfire%", String.valueOf(((L2Character)this).getDefenseElementValue((byte)2)));
// html.replace("%ele_dwater%", String.valueOf(((L2Character)this).getDefenseElementValue((byte)3)));
// html.replace("%ele_dwind%", String.valueOf(((L2Character)this).getDefenseElementValue((byte)1)));
// html.replace("%ele_dearth%", String.valueOf(((L2Character)this).getDefenseElementValue((byte)4)));
// html.replace("%ele_dholy%", String.valueOf(((L2Character)this).getDefenseElementValue((byte)5)));
// html.replace("%ele_ddark%", String.valueOf(((L2Character)this).getDefenseElementValue((byte)6)));
if (spawn != null)
{
html.Replace("%spawn%", $"{spawn.Location.X} {spawn.Location.Y} {spawn.Location.Z}");
html.Replace("%loc2d%", player.CharMovement.DistanceToSquared(spawn.Location.Y,spawn.Location.X));
html.Replace("%loc3d%", "<font color=FF0000>--</font>");
//html.Replace("%loc3d%", player.getDistanceSq(spawn.Location.X,spawn.Location.Y,spawn.Location.Z); -Not implemented
html.Replace("%resp%", spawn.Location.RespawnDelay / 1000);
}
else
{
html.Replace("%spawn%", "<font color=FF0000>null</font>");
html.Replace("%loc2d%", "<font color=FF0000>--</font>");
html.Replace("%loc3d%", "<font color=FF0000>--</font>");
html.Replace("%resp%", "<font color=FF0000>--</font>");
}
// if (hasAI())
// {
// html.replace("%ai_intention%", "<tr><td><table width=270 border=0><tr><td width=100><font color=FFAA00>Intention:</font></td><td align=right width=170>" + String.valueOf(getAI().getIntention().name()) + "</td></tr></table></td></tr>");
// html.replace("%ai%", "<tr><td><table width=270 border=0><tr><td width=100><font color=FFAA00>AI</font></td><td align=right width=170>" + getAI().getClass().getSimpleName() + "</td></tr></table></td></tr>");
// html.replace("%ai_type%", "<tr><td><table width=270 border=0><tr><td width=100><font color=FFAA00>AIType</font></td><td align=right width=170>" + String.valueOf(getAiType()) + "</td></tr></table></td></tr>");
// html.replace("%ai_clan%", "<tr><td><table width=270 border=0><tr><td width=100><font color=FFAA00>Clan & Range:</font></td><td align=right width=170>" + String.valueOf(getClan()) + " " + String.valueOf(getClanRange()) + "</td></tr></table></td></tr>");
// html.replace("%ai_enemy_clan%", "<tr><td><table width=270 border=0><tr><td width=100><font color=FFAA00>Enemy & Range:</font></td><td align=right width=170>" + String.valueOf(getEnemyClan()) + " " + String.valueOf(getEnemyRange()) + "</td></tr></table></td></tr>");
// }
// else
// {
// html.replace("%ai_intention%", "");
// html.replace("%ai%", "");
// html.replace("%ai_type%", "");
// html.replace("%ai_clan%", "");
// html.replace("%ai_enemy_clan%", "");
// }
if (Template.GetType().ToString() == "L2dotNET.Models.Npcs.L2Merchant")
html.Replace("%butt%", "<button value=\"Shop\" action=\"bypass -h admin_showShop " + NpcId + "\" width=65 height=19 back=\"L2UI_ch3.smallbutton2_over\" fore=\"L2UI_ch3.smallbutton2\">");
else
html.Replace("%butt%", "");
await player.SendPacketAsync(html);
}
public virtual int Attackable => 0;
public override double Radius => Template.CollisionRadius == 0 ? 12 : Template.CollisionRadius;
public override double Height => Template.CollisionHeight == 0 ? 22 : Template.CollisionHeight;
public override string AsString()
{
return $"L2Npc:{Template.NpcId}; id {ObjectId}";
}
public void CreateOnePrivateEx(int npcId, string aiType, int x, int y, int z) { }
public async Task CastBuffForQuestRewardAsync(L2Character cha, int skillId)
{
await cha.SendMessageAsync($"L2Npc.CastBuffForQuestReward {skillId}");
}
}
}