forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL2Player.cs
More file actions
1456 lines (1205 loc) · 44.3 KB
/
Copy pathL2Player.cs
File metadata and controls
1456 lines (1205 loc) · 44.3 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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Timers;
using L2dotNET.DataContracts;
using L2dotNET.DataContracts.Shared.Enums;
using L2dotNET.Enums;
using L2dotNET.Models.Inventory;
using L2dotNET.Models.Items;
using L2dotNET.Models.Npcs;
using L2dotNET.Models.Npcs.Decor;
using L2dotNET.Models.Player.General;
using L2dotNET.Models.Stats;
using L2dotNET.Models.Stats.Funcs;
using L2dotNET.Models.Status;
using L2dotNET.Models.Vehicles;
using L2dotNET.Network;
using L2dotNET.Network.serverpackets;
using L2dotNET.Services.Contracts;
using L2dotNET.Templates;
using L2dotNET.Tools;
using L2dotNET.Utility;
using L2dotNET.World;
using Microsoft.Extensions.DependencyInjection;
using NLog;
namespace L2dotNET.Models.Player
{
public class L2Player : L2Character
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
public readonly ICharacterService _characterService;
public new PlayerStatus CharStatus => (PlayerStatus) base.CharStatus;
public AccountContract Account { get; set; }
public GameClient Gameclient { get; private set; }
public ClassId ClassId { get; set; }
public L2PartyRoom PartyRoom { get; set; }
public L2Party Party { get; set; }
public Gender Sex { get; set; }
public HairStyleId HairStyleId { get; set; }
public HairColor HairColor { get; set; }
public Face Face { get; set; }
public bool WhisperBlock { get; set; }
public long Experience { get; set; }
public long ExpOnDeath { get; set; }
public long ExpAfterLogin { get; set; }
public int Sp { get; set; }
public double CurrentCp
{
get => CharStatus.CurrentCp;
set => CharStatus.SetCurrentCp(value);
}
public int Karma { get; set; }
public int PvpKills { get; set; }
public DateTime? DeleteTime { get; set; }
public int CanCraft { get; set; }
public int PkKills { get; set; }
public int RecomendationsLeft { get; set; }
public int RecomandationsHave { get; set; }
public int AccessLevel { get; set; }
public int Online { get; private set; }
public int OnlineTime { get; set; }
public int CharacterSlot { get; set; }
public int CurrentWeight { get; set; }
public double CollisionRadius { get; set; }
public double CollisionHeight { get; set; }
public int CursedWeaponLevel { get; set; }
public DateTime? LastAccess { get; set; }
public int IsIn7SDungeon { get; set; }
public int? PunishLevel { get; set; }
public DateTime? PunishTime { get; set; }
public int PowerGrade { get; set; }
public bool Nobless { get; set; }
public bool Hero { get; set; }
public DateTime? LastRecomendationDate { get; set; }
public PcInventory Inventory { get; set; }
public dynamic SessionData { get; set; }
public new PcTemplate Template { get; set; }
public byte Builder = 1;
public byte Noblesse = 0;
public byte Heroic = 0;
public bool Diet = false;
public int PenaltyWeight;
public int PenaltyGrade = 0;
public int CurrentFocusEnergy = 0;
public int ItemLimitInventory = 80,
ItemLimitSelling = 5,
ItemLimitBuying = 5,
ItemLimitRecipeDwarven = 50,
ItemLimitRecipeCommon = 50,
ItemLimitWarehouse = 120,
ItemLimitClanWarehouse = 150,
ItemLimitExtra = 0,
ItemLimitQuest = 20;
public L2Npc FolkNpc;
public int LastX1 = -4;
public int LastY1;
private Timer _timerTooFar;
public string Locale = "en";
public int PCreateCommonItem = 0;
public int PCreateItem = 0;
public List<L2Shortcut> Shortcuts = new List<L2Shortcut>();
public int ZoneId = -1;
public int Obsx = -1;
public int Obsy;
public int Obsz;
// arrow, bolt
public L2Item SecondaryWeaponSupport;
public override L2Item ActiveWeapon => null;
public List<int> AutoSoulshots = new List<int>();
public List<int> SetKeyItems;
public int SetKeyId;
public int MountType;
public NpcTemplate MountedTemplate;
public int TradeState;
public SortedList<int, int> CurrentTrade;
public int Sstt;
private DateTime _pingTimeout;
private int _lastPingId;
public int Ping = -1;
public int AttackingId;
private L2Chair _chair;
public L2Boat Boat;
public int BoatX;
public int BoatY;
public int BoatZ;
public PcTemplate BaseClass;
public PcTemplate ActiveClass;
private ActionFailed _af;
public int ViewingAdminPage;
public int ViewingAdminTeleportGroup = -1;
public int TeleportPayId;
public int LastMinigameScore;
public short ClanType;
public int Fame;
private Timer _sitTime;
private bool _isSitting;
private Timer _petSummonTime,
_nonpetSummonTime;
private int _petId = -1;
private L2Item _petControlItem;
public bool IsInOlympiad = false;
public L2Item EnchantScroll,
EnchantItem,
EnchantStone;
public byte EnchantState = 0;
// 0 cls, 1 violet, 2 blink
public byte PvPStatus;
public bool IsCursed = false;
public string PenaltyClanCreate = "0";
public string PenaltyClanJoin = "0";
public byte PartyState;
public L2Player Requester;
public int ItemDistribution;
public int VehicleId => Boat?.ObjectId ?? 0;
public L2Player(PcTemplate template, int objectId) : base(objectId, template)
{
Template = template;
_characterService = GameServer.ServiceProvider.GetService<ICharacterService>();
CharacterStat = new CharacterStat(this);
AddFuncsToNewCharacter();
InitializeCharacterStatus();
Inventory = new PcInventory(this);
Title = string.Empty;
Experience = 0;
Level = 1;
ClassId = template.ClassId;
BaseClass = template;
ActiveClass = template;
CharStatus.CurrentCp = MaxCp;
CharStatus.SetCurrentHp(MaxHp, false);
CharStatus.SetCurrentMp(MaxMp, false);
X = template.SpawnX;
Y = template.SpawnY;
Z = template.SpawnZ;
LastAccess = DateTime.UtcNow;
if (template.DefaultInventory != null)
{
//foreach (PC_item i in template._items)
//{
// if (!i.item.isStackable())
// {
// for (long s = 0; s < i.count; s++)
// {
// L2Item item = new L2Item(i.item);
// item.Enchant = i.enchant;
// if (i.lifetime != -1)
// item.AddLimitedHour(i.lifetime);
// item.Location = L2Item.L2ItemLocation.inventory;
// player.Inventory.addItem(item, false, false);
// if (i.equip)
// {
// int pdollId = player.Inventory.getPaperdollId(item.Template);
// player.setPaperdoll(pdollId, item, false);
// }
// }
// }
// else
// player.addItem(i.item.ItemID, i.count);
//}
}
}
public L2Player(ICharacterService characterService) :base(0, null)
{
_characterService = characterService;
}
public override void InitializeCharacterStatus()
{
base.CharStatus = new PlayerStatus(this);
}
public byte PrivateStoreType = 0;
public byte GetPrivateStoreType()
{
return PrivateStoreType;
}
public int GetTitleColor()
{
return 0xFFFF77;
}
public int GetNameColor()
{
return 0xFFFFFF;
}
internal uint GetFishz()
{
return 0;
}
internal uint GetFishy()
{
return 0;
}
internal uint GetFishx()
{
return 0;
}
internal bool IsFishing()
{
return false;
}
public override async Task SendPacketAsync(GameserverPacket gameserverPacket)
{
await Gameclient.SendPacketAsync(gameserverPacket);
}
public override async Task SendActionFailedAsync()
{
if (_af == null)
_af = new ActionFailed();
await SendPacketAsync(_af);
}
public override async Task SendSystemMessage(SystemMessageId msgId)
{
await SendPacketAsync(new SystemMessage(msgId));
}
public override async Task SendMessageAsync(string p)
{
await SendPacketAsync(new SystemMessage(SystemMessageId.S1).AddString(p));
}
public int GetForceIncreased()
{
return CurrentFocusEnergy;
}
public void UpdateReuse()
{
SendPacketAsync(new SkillCoolTime(this));
}
public override void AddFuncsToNewCharacter()
{
base.AddFuncsToNewCharacter();
CharacterStat.AddStatFunction(FuncMaxCpMul.Instance);
//Henna stuff go here
}
public void OnGameInit()
{
//CStatsInit();
//CharacterStat.SetTemplate(ActiveClass);
ExpAfterLogin = 0;
}
public void ShowHtm(string file, L2Object o)
{
if (file.EndsWithIgnoreCase(".htm"))
{
SendPacketAsync(new NpcHtmlMessage(this, $"./html/{file}", o.ObjectId, 0));
if (o is L2Npc npc)
FolkNpc = npc;
}
else
ShowHtmPlain(file, o);
}
public void ShowHtm(string file, L2Npc npc, int questId)
{
if (file.EndsWithIgnoreCase(".htm"))
{
NpcHtmlMessage htm = new NpcHtmlMessage(this, file, npc.ObjectId, 0);
htm.Replace("<?quest_id?>", questId);
SendPacketAsync(htm);
FolkNpc = npc;
}
else
ShowHtmPlain(file, npc);
}
public void UpdateAndBroadcastStatus(int broadcastType)
{
if (broadcastType == 1)
SendPacketAsync(new UserInfo(this));
else if (broadcastType == 2)
{
BroadcastUserInfoAsync();
}
}
public void ShowHtmPlain(string plain, L2Object o)
{
SendPacketAsync(new NpcHtmlMessage(this, plain, o?.ObjectId ?? -1, true));
if (o is L2Npc)
FolkNpc = (L2Npc)o;
}
public void SendQuestList()
{
SendPacketAsync(new QuestList(this));
}
public void AddExpSp(int exp, int sp, bool msg)
{
SystemMessage sm = new SystemMessage(SystemMessageId.YouEarnedS1ExpAndS2Sp);
sm.AddNumber(exp);
sm.AddNumber(sp);
SendPacketAsync(sm);
Experience += exp;
Sp += sp;
//Need to Level up ?
if(Level != Player.Experience.GetLevel(Experience))
{
Level = Player.Experience.GetLevel(Experience);
this.BroadcastPacketAsync(new SocialAction(ObjectId, 15));
this.SendPacketAsync(new SystemMessage(SystemMessageId.YouIncreasedYourLevel));
}
StatusUpdate su = new StatusUpdate(this);
su.Add(StatusUpdate.Exp, (int)Experience);
su.Add(StatusUpdate.Sp, Sp);
su.Add(StatusUpdate.Level, Level);
SendPacketAsync(su);
}
public void Timer()
{
_timerTooFar = new Timer(30 * 1000);
_timerTooFar.Elapsed += _timeToFarTimerTask;
_timerTooFar.Interval = 10000;
_timerTooFar.Enabled = true;
}
public void _timeToFarTimerTask(object sender, ElapsedEventArgs e)
{
ValidateVisibleObjects(X, Y, true);
}
public bool IsAlikeDead()
{
return false;
}
public void RegisterShortcut(int slot, int page, int type, int id, int level, int characterType)
{
lock (Shortcuts)
{
L2Shortcut shortcut = Shortcuts.FirstOrDefault(sc => (sc.Slot == slot) && (sc.Page == page));
if (shortcut != null)
{
Shortcuts.Remove(shortcut);
//SQL_Block sqb = new SQL_Block("user_shortcuts");
//sqb.where("ownerId", ObjID);
//sqb.where("classId", ActiveClass.id);
//sqb.where("slot", _slot);
//sqb.where("page", _page);
//sqb.sql_delete(false);
}
}
{
L2Shortcut sc = new L2Shortcut(slot, page, type, id, level, characterType);
lock (Shortcuts)
Shortcuts.Add(sc);
SendPacketAsync(new ShortCutRegister(sc));
//SQL_Block sqb = new SQL_Block("user_shortcuts");
//sqb.param("ownerId", ObjID);
//sqb.param("classId", ActiveClass.id);
//sqb.param("slot", _slot);
//sqb.param("page", _page);
//sqb.param("type", _type);
//sqb.param("id", _id);
//sqb.param("lvl", _level);
//sqb.param("cha", _characterType);
//sqb.sql_insert(false);
}
}
public bool SubActive()
{
return ActiveClass != BaseClass;
}
public override void OnPickUp(L2Item item)
{
//item.Location = L2Item.L2ItemLocation.inventory;
//Inventory.addItem(item, true, true);
}
public void AddItem(int itemId, int count)
{
Inventory.AddItem(itemId, count, this);
}
public void DestroyItem(L2Item item, int count)
{
Inventory.DestroyItem(item, count, this);
}
public void DestroyItemById(int itemId, int count)
{
Inventory.DestroyItemById(itemId, count, this);
}
public bool ReduceAdena(int count)
{
return Inventory.ReduceAdena(count, this);
}
public L2Item GetItemByObjId(int objId)
{
return Inventory.GetItemByObjectId(objId);
}
public List<L2Item> GetAllItems()
{
return Inventory.Items;
}
public int GetAdena()
{
return Inventory.AdenaCount();
}
public void AddAdena(int count, bool sendMessage)
{
if (sendMessage)
SendPacketAsync(new SystemMessage(SystemMessageId.EarnedS1Adena).AddNumber(count));
if (count <= 0)
return;
InventoryUpdate iu = new InventoryUpdate();
iu.AddNewItem(Inventory.AddItem(57, count, this));
SendPacketAsync(iu);
}
public override string AsString()
{
return $"L2Player:{Name}";
}
public override void OnRemObject(L2Object obj)
{
SendPacketAsync(new DeleteObject(obj.ObjectId));
}
public override void OnAddObject(L2Object obj, GameserverPacket pk, string msg = null)
{
if (obj is L2Npc)
SendPacketAsync(new NpcInfo((L2Npc)obj));
else
{
if (obj is L2Player)
{
SendPacketAsync(new CharInfo((L2Player)obj));
if (msg != null)
((L2Player)obj).SendMessageAsync(msg);
}
else
{
if (obj is L2Item)
SendPacketAsync(pk ?? new SpawnItem((L2Item)obj));
else
{
{
if (obj is L2Chair)
SendPacketAsync(new StaticObject((L2Chair)obj));
else
{
if (obj is L2StaticObject)
SendPacketAsync(new StaticObject((L2StaticObject)obj));
else
{
if (obj is L2Boat)
SendPacketAsync(new VehicleInfo((L2Boat)obj));
}
}
}
}
}
}
}
public override async Task BroadcastStatusUpdateAsync()
{
StatusUpdate statusUpdate = new StatusUpdate(this);
statusUpdate.Add(StatusUpdate.CurHp, (int)CharStatus.CurrentHp);
statusUpdate.Add(StatusUpdate.CurMp, (int)CharStatus.CurrentMp);
statusUpdate.Add(StatusUpdate.CurCp, (int)CurrentCp);
statusUpdate.Add(StatusUpdate.MaxCp, MaxCp);
await SendPacketAsync(statusUpdate);
}
public override async Task BroadcastUserInfoAsync()
{
await SendPacketAsync(new UserInfo(this));
//if (getPolyType() == PolyType.NPC)
// Broadcast.toKnownPlayers(this, new AbstractNpcInfo.PcMorphInfo(this, getPolyTemplate()));
//else
await Task.WhenAll(L2World.GetPlayers().Where(player => player != this)
.Select(player => player.SendPacketAsync(new CharInfo(this))));
}
public override void AddKnownObject(L2Object obj)
{
SendInfoFrom(obj);
}
private void SendInfoFrom(L2Object obj)
{
//if (obj.getPolyType() == PolyType.ITEM)
// sendPacket(new SpawnItem(obj));
//else
//{
// send object info to player
obj.SendInfoAsync(this);
// if (obj is L2Character)
//{
// // Update the state of the L2Character object client side by sending Server->Client packet MoveToPawn/MoveToLocation and AutoAttackStart to the L2PcInstance
// L2Character obj2 = (L2Character)obj;
// if (obj2. hasAI())
// obj2.getAI().describeStateToPlayer(this);
// }
// }
}
public void SetOnline(GameClient client)
{
Online = 1;
client.CurrentPlayer = this;
Gameclient = client;
L2World.AddPlayer(this);
}
public async Task SetOffline()
{
Online = 0;
Party?.Leave(this);
if (CharMovement.IsMoving)
{
CharMovement.UpdatePosition();
CharMovement.NotifyStopMove();
}
await _characterService.UpdatePlayer(this);
L2World.RemovePlayer(this);
DecayMe();
}
public bool HasItem(int itemId, int count)
{
return Inventory.Items.Where(item => item.Template.ItemId == itemId).Any(item => item.Count >= count);
}
public override async Task SendInfoAsync(L2Player player)
{
//if (this.Boa isInBoat())
// getPosition().set(getBoat().getPosition());
//if (getPolyType() == PolyType.NPC)
// activeChar.sendPacket(new AbstractNpcInfo.PcMorphInfo(this, getPolyTemplate()));
//else
//{
await player.SendPacketAsync(new CharInfo(this));
if (_isSitting)
{
// L2Object obj = World.getInstance().getObject(_throneId);
// if (obj is L2StaticObject)
//activeChar.sendPacket(new ChairSit(getObjectId(), ((L2StaticObjectInstance)object).getStaticObjectId()));
}
//}
//int relation = getRelation(activeChar);
//boolean isAutoAttackable = isAutoAttackable(activeChar);
//activeChar.sendPacket(new RelationChanged(this, relation, isAutoAttackable));
//if (getPet() != null)
// activeChar.sendPacket(new RelationChanged(getPet(), relation, isAutoAttackable));
//relation = activeChar.getRelation(this);
//isAutoAttackable = activeChar.isAutoAttackable(this);
//sendPacket(new RelationChanged(activeChar, relation, isAutoAttackable));
//if (activeChar.getPet() != null)
// sendPacket(new RelationChanged(activeChar.getPet(), relation, isAutoAttackable));
//if (isInBoat())
// activeChar.sendPacket(new GetOnVehicle(getObjectId(), getBoat().getObjectId(), getVehiclePosition()));
//switch (getStoreType())
//{
// case SELL:
// case PACKAGE_SELL:
// activeChar.sendPacket(new PrivateStoreMsgSell(this));
// break;
// case BUY:
// activeChar.sendPacket(new PrivateStoreMsgBuy(this));
// break;
// case MANUFACTURE:
// activeChar.sendPacket(new RecipeShopMsg(this));
// break;
//}
}
public override async Task SetTargetAsync(L2Character newTarget)
{
if (newTarget != null)
{
if (!newTarget.Visible)
newTarget = null;
}
L2Character oldTarget = Target;
if (oldTarget != null)
{
if (oldTarget.Equals(newTarget))
return;
oldTarget?.CharStatus.RemoveStatusListener(this);
}
if (newTarget is L2StaticObject)
{
await SendPacketAsync(new MyTargetSelected(newTarget.ObjectId, 0));
await SendPacketAsync(new StaticObject((L2StaticObject) newTarget));
}
else
{
if (newTarget != null)
{
if (newTarget.ObjectId != ObjectId)
await SendPacketAsync(new ValidateLocation(newTarget));
await SendPacketAsync(new MyTargetSelected(newTarget.ObjectId, Level - newTarget.Level));
newTarget.CharStatus.AddStatusListener(this);
StatusUpdate su = new StatusUpdate(newTarget);
su.Add(StatusUpdate.MaxHp, newTarget.MaxHp);
su.Add(StatusUpdate.CurHp, (int)newTarget.CharStatus.CurrentHp);
await SendPacketAsync(su);
await BroadcastPacketAsync(su, false);
}
}
if (newTarget == null && Target != null)
{
await BroadcastPacketAsync(new TargetUnselected(this));
}
base.SetTargetAsync(newTarget);
}
public override async Task OnActionAsync(L2Player player)
{
if (player.Target != this)
await player.SetTargetAsync(this);
else
{
await player.SendActionFailedAsync();
//follow
}
}
public async Task ShowHtmAdminAsync(string val, bool plain)
{
await SendPacketAsync(new NpcHtmlMessage(this, val, this.ObjectId));
ViewingAdminPage = 1;
}
public void ShowHtmBbs(string val)
{
ShowBoard.SeparateAndSendAsync(val, this);
}
public void SendItemList(bool open = false)
{
SendPacketAsync(new ItemList(this, open));
// SendPacket(new ExQuestItemList(this));
}
public void UpdateWeight()
{
int oldweight = CurrentWeight;
int total = 0;
//if (!_diet)
// foreach (L2Item it in Inventory.Items.Values.Where(it => it.Template.Weight != 0))
//{
// if (it.Template.isStackable())
// total += it.Template.Weight * it.Count;
// else
// total += it.Template.Weight;
//}
CurrentWeight = total >= int.MaxValue ? int.MaxValue : total;
if (oldweight == total)
return;
StatusUpdate su = new StatusUpdate(this);
su.Add(StatusUpdate.CurLoad, CurrentWeight);
SendPacketAsync(su);
int weightproc = (total * 1000) / 100; //max weight
int newWeightPenalty;
if (weightproc < 500)
newWeightPenalty = 0;
else
{
if (weightproc < 666)
newWeightPenalty = 1;
else
{
if (weightproc < 800)
newWeightPenalty = 2;
else
{
if (weightproc < 1000)
newWeightPenalty = 3;
else
newWeightPenalty = 4;
}
}
}
if (PenaltyWeight == newWeightPenalty)
return;
//if (newWeightPenalty > 0)
// AddSkill(4270, newWeightPenalty, false, true);
//else
// RemoveSkill(4270, false, true);
PenaltyWeight = newWeightPenalty;
SendPacketAsync(new EtcStatusUpdate(this));
}
public bool CheckFreeWeight(int weight)
{
// if ((CurrentWeight + weight) >= CharacterStat.GetStat(EffectType.BMaxWeight))
// return false;
return true;
}
public bool CheckFreeWeight80(int weight)
{
//if ((CurrentWeight + weight) >= (CharacterStat.GetStat(EffectType.BMaxWeight) * .8))
// return false;
return true;
}
public override void UpdateAbnormalEventEffect()
{
BroadcastPacketAsync(new ExBrExtraUserInfo(ObjectId, AbnormalBitMaskEvent));
}
public override void UpdateAbnormalExEffect()
{
BroadcastUserInfoAsync();
}
public bool IsRestored;
public void TotalRestore()
{
if (IsRestored)
return;
OnGameInit();
//RestoreSkills();
//db_restoreQuests();
//db_restoreRecipes();
// db_restoreShortcuts(); elfo to be added
IsRestored = true;
}
public void DB_RestoreShortcuts()
{
//MySqlConnection connection = SQLjec.getInstance().conn();
//MySqlCommand cmd = connection.CreateCommand();
//connection.Open();
//cmd.CommandText = $"SELECT * FROM user_shortcuts WHERE ownerId={ObjID} and classId={ActiveClass.id}";
//cmd.CommandType = CommandType.Text;
//MySqlDataReader reader = cmd.ExecuteReader();
//while (reader.Read())
//{
// L2Shortcut sc = new L2Shortcut();
// sc._slot = reader.GetInt32("slot");
// sc._page = reader.GetInt32("page");
// sc._type = reader.GetInt32("type");
// sc._id = reader.GetInt32("id");
// sc._level = reader.GetInt32("lvl");
// sc._characterType = reader.GetInt32("cha");
// _shortcuts.Add(sc);
//}
//reader.Close();
//connection.Close();
}
public void PendToJoinParty(L2Player asker, int askerItemDistribution)
{
PartyState = 1;
Requester = asker;
Requester.ItemDistribution = askerItemDistribution;
SendPacketAsync(new AskJoinParty(asker.Name, askerItemDistribution));
}
public void ClearPend()
{
PartyState = 0;
Requester = null;
}
public byte GetEnchantValue()
{
int val = Inventory.Paperdoll?[Models.Inventory.Inventory.PaperdollRhand]?.Enchant ?? 0;
if (MountType > 0)
return 0;
if (val > 127)
val = 127;
return (byte)val;
}
public override void OnNewTargetSelection(L2Object target)
{
int color = 0;
SendPacketAsync(new MyTargetSelected(target.ObjectId, color));
}
public override void OnOldTargetSelection(L2Object target)
{
double dis = Calcs.CalculateDistance(this, target, true);
if (dis < 151)
target.NotifyActionAsync(this);
else
CharMovement.MoveTo(target.X, target.Y, target.Z);
SendActionFailedAsync();
}
public void PetSummon(L2Item item, int npcId, bool isPet = true)
{
if (isPet)
{
if (_petSummonTime == null)
{
_petSummonTime = new Timer
{
Interval = 5000
};
_petSummonTime.Elapsed += PetSummonEnd;
}
_petSummonTime.Enabled = true;
SendSystemMessage(SystemMessageId.SummonAPet);
}
else
{
if (_nonpetSummonTime == null)
{
_nonpetSummonTime = new Timer
{
Interval = 5000
};
_nonpetSummonTime.Elapsed += NonpetSummonEnd;
}
_nonpetSummonTime.Enabled = true;
}
_petId = npcId;
_petControlItem = item;
BroadcastPacketAsync(new MagicSkillUse(this, this, 1111, 1, 5000));
SendPacketAsync(new SetupGauge(ObjectId, SetupGauge.SgColor.Blue, 4900));
}
private void PetSummonEnd(object sender, ElapsedEventArgs e)
{
//L2Pet pet = new L2Pet();
////pet.setTemplate(NpcTable.Instance.GetNpcTemplate(PetID));
//pet.SetOwner(this);
//pet.ControlItem = _petControlItem;
//// pet.sql_restore();
//pet.SpawmMe();
//_petSummonTime.Enabled = false;