forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL2Character.cs
More file actions
1088 lines (868 loc) · 31.7 KB
/
Copy pathL2Character.cs
File metadata and controls
1088 lines (868 loc) · 31.7 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.Timers;
using L2dotNET.Enums;
using L2dotNET.Models.Items;
using L2dotNET.Models.Player;
using L2dotNET.Models.Stats;
using L2dotNET.Models.Stats.Funcs;
using L2dotNET.Models.Status;
using L2dotNET.Network.serverpackets;
using L2dotNET.Templates;
using L2dotNET.Tools;
using L2dotNET.World;
using Calculator = L2dotNET.Models.Stats.Calculator;
namespace L2dotNET.Models
{
public class L2Character : L2Object
{
public virtual CharTemplate Template { get; set; }
public virtual string Name { get; set; }
public virtual string Title { get; set; }
public int SpawnX { get; set; }
public int SpawnY { get; set; }
public int SpawnZ { get; set; }
private readonly byte[] _zones = new byte[ZoneId.GetZoneCount()];
public byte IsRunning { get; set; } = 1;
#region AbhornalMask
public int AbnormalBitMask;
public int AbnormalBitMaskEx;
public int AbnormalBitMaskEvent;
public const int AbnormalMaskBleed = 0x000001;
public const int AbnormalMaskExInvincible = 0x000001;
public const int AbnormalMaskExAirStun = 0x000002;
public const int AbnormalMaskExAirRoot = 0x000004;
public const int AbnormalMaskExBagSword = 0x000008;
public const int AbnormalMaskExAfroYellow = 0x000010;
public const int AbnormalMaskExAfroPink = 0x000020;
public const int AbnormalMaskExAfroBlack = 0x000040;
//unk x80
public const int AbnormalMaskExStigmaShillien = 0x000100;
public const int AbnormalMaskExStakatoRoot = 0x000200;
public const int AbnormalMaskExFreezing = 0x000400;
public const int AbnormalMaskExVesper = 0x000800;
public const int AbnormalMaskEventIceHand = 0x000008;
public const int AbnormalMaskEventHeadphone = 0x000010;
public const int AbnormalMaskEventCrown1 = 0x000020;
public const int AbnormalMaskEventCrown2 = 0x000040;
public const int AbnormalMaskEventCrown3 = 0x000080;
#endregion
public int Int => CharacterStat.Int;
public int Str => CharacterStat.Str;
public int Con => CharacterStat.Con;
public int Men => CharacterStat.Men;
public int Dex => CharacterStat.Dex;
public int Wit => CharacterStat.Wit;
public int MaxHp => CharacterStat.MaxHp;
public int MaxMp => CharacterStat.MaxMp;
public int MaxCp => CharacterStat.MaxCp;
protected byte zoneValidateCounter = 4;
public CharStatus CharStatus { get; set; }
public virtual void UpdateAbnormalEffect() { }
public virtual void UpdateAbnormalExEffect() { }
public virtual void UpdateAbnormalEventEffect() { }
private Timer _updatePositionTime = new Timer(90);
public Calculator[] Calculators { get; set; }
public CharacterStat CharacterStat { get; set; }
public L2Character(int objectId, CharTemplate template) : base(objectId)
{
Template = template;
CharacterStat = new CharacterStat(this);
InitializeCharacterStatus();
Calculators = new Calculator[Models.Stats.Stats.Values.Count()];
AddFuncsToNewCharacter();
_updatePositionTime.Elapsed += UpdatePositionTask;
}
public virtual CharStatus GetStatus()
{
return CharStatus;
}
public virtual void InitializeCharacterStatus()
{
CharStatus = new CharStatus(this);
}
public virtual void SetTarget(L2Character obj)
{
if (obj != null && !obj.Visible)
obj = null;
Target = obj;
}
public void AddStatFunc(Func func)
{
if (func == null)
return;
var statId = Array.IndexOf(Models.Stats.Stats.Values.ToArray(), func.Stat);
lock (Calculators)
{
if (Calculators[statId] == null)
Calculators[statId] = new Calculator();
Calculators[statId].AddFunc(func);
}
}
public void AddStatFuncs(IEnumerable<Func> funcs)
{
List<Stat> modifiedStats = new List<Stat>();
foreach (var func in funcs)
{
modifiedStats.Add(func.Stat);
AddStatFunc(func);
}
BroadcastModifiedStats(modifiedStats);
}
public void RemoveStatsByOwner(object owner)
{
throw new NotImplementedException();
}
public virtual void AddFuncsToNewCharacter()
{
AddStatFunc(new FuncPAtkMod());
AddStatFunc(new FuncMAtkMod());
AddStatFunc(new FuncPDefMod());
AddStatFunc(new FuncMDefMod());
AddStatFunc(new FuncMaxHpMul());
AddStatFunc(new FuncMaxMpMul());
AddStatFunc(new FuncAtkAccuracy());
AddStatFunc(new FuncAtkEvasion());
AddStatFunc(new FuncPAtkSpeed());
AddStatFunc(new FuncMAtkSpeed());
AddStatFunc(new FuncMoveSpeed());
AddStatFunc(new FuncAtkCritical());
AddStatFunc(new FuncMAtkCritical());
}
public double GetLevelMod()
{
return (100.0 - 11 + Level) / 100.0;
}
public void BroadcastModifiedStats(List<Stat> stats)
{
if (stats == null || !stats.Any())
return;
bool broadcastFull = false;
StatusUpdate statusUpdate = null;
foreach (var stat in stats)
{
if (stat == Models.Stats.Stats.PowerAttackSpeed)
{
if(statusUpdate == null)
statusUpdate = new StatusUpdate(this);
statusUpdate.Add(StatusUpdate.AtkSpd, CharacterStat.PAttackSpeed);
}
else if (stat == Models.Stats.Stats.MagicAttackSpeed)
{
if (statusUpdate == null)
statusUpdate = new StatusUpdate(this);
statusUpdate.Add(StatusUpdate.CastSpd, CharacterStat.MAttackSpeed);
}
else if (stat == Models.Stats.Stats.MaxHp)
{
if (statusUpdate == null)
statusUpdate = new StatusUpdate(this);
statusUpdate.Add(StatusUpdate.MaxHp, CharacterStat.MaxHp);
}else if (stat == Models.Stats.Stats.RunSpeed)
broadcastFull = true;
}
if (this is L2Player player)
{
if (broadcastFull)
player.UpdateAndBroadcastStatus(2);
else
{
player.UpdateAndBroadcastStatus(1);
if(statusUpdate != null)
BroadcastPacket(statusUpdate);
}
}
else if(statusUpdate != null)
BroadcastPacket(statusUpdate);
}
public override void OnForcedAttack(L2Player player)
{
player.SendActionFailed();
}
public override void OnSpawn(bool notifyOthers = true)
{
base.OnSpawn(notifyOthers);
RevalidateZone(true);
}
public virtual void DeleteMe()
{
//foreach (L2Player o in KnownObjects.Values.OfType<L2Player>())
// o.SendPacket(new DeleteObject(ObjId));
}
public void RevalidateZone(bool force)
{
if (Region == null)
return;
if (force)
zoneValidateCounter = 4;
else
{
zoneValidateCounter--;
if (zoneValidateCounter < 0)
zoneValidateCounter = 4;
else
return;
}
Region.RevalidateZones(this);
}
public override void SetRegion(L2WorldRegion newRegion)
{
// confirm revalidation of old region's zones
if (Region != null)
{
if (newRegion != null)
Region.RevalidateZones(this);
else
Region.RemoveFromZones(this);
}
base.SetRegion(newRegion);
}
public void SetInsisdeZone(ZoneId zone, bool state)
{
if (state)
_zones[(int)zone.Id]++;
else
_zones[(int)zone.Id]--;
}
public virtual void SendMessage(string p) { }
public virtual void SendActionFailed() { }
public virtual void SendSystemMessage(SystemMessage.SystemMessageId msgId) { }
public virtual void OnPickUp(L2Item item) { }
public int ClientPosX,
ClientPosY,
ClientPosZ,
ClientHeading;
public virtual void Teleport(int x, int y, int z)
{
SetTarget(null);
//clearKnowns(true);
X = x;
Y = y;
Z = z;
if (!(this is L2Player))
return;
BroadcastPacket(new TeleportToLocation(ObjId, x, y, z, Heading));
}
private Timer _waterTimer;
private DateTime _waterTimeDamage;
public void WaterTimer()
{
if (IsInWater())
{
bool next = false;
if ((_waterTimer == null) || !_waterTimer.Enabled)
{
_waterTimer = new Timer();
_waterTimer.Elapsed += WaterActionTime;
_waterTimer.Interval = 3000;
next = true;
}
if (!next)
return;
int breath = 100;
_waterTimeDamage = DateTime.Now.AddSeconds(breath);
_waterTimer.Enabled = true;
if (this is L2Player)
SendPacket(new SetupGauge(ObjId, SetupGauge.SgColor.Cyan, breath * 1000));
}
else
{
if ((_waterTimer == null) || !_waterTimer.Enabled)
return;
_waterTimer.Enabled = false;
if (this is L2Player)
SendPacket(new SetupGauge(ObjId, SetupGauge.SgColor.Cyan, 1));
}
//if (!isInWater())
//{
// if (_waterTimer == null)
// return;
// if (_waterTimer.Enabled)
// {
// _waterTimer.Stop();
// _waterTimer.Enabled = false;
// _waterTimer = null;
// if (this is L2Player)
// {
// sendPacket(new SetupGauge(ObjID, SetupGauge.SG_color.cyan, 1));
// }
// }
// return;
//}
//else
//{
// if (_waterTimer == null)
// {
// int breath = (int)CharacterStat.getStat(TEffectType.b_breath);
// _waterTimeDamage = DateTime.Now.AddSeconds(breath);
// _waterTimer = new System.Timers.Timer(breath * 1000);
// _waterTimer.Elapsed += new ElapsedEventHandler(waterActionTime);
// _waterTimer.Enabled = true;
// _waterTimer.Interval = 3000;
// return;
// }
//}
}
private void WaterActionTime(object sender, ElapsedEventArgs e)
{
TimeSpan ts = _waterTimeDamage - DateTime.Now;
if (!(ts.TotalMilliseconds < 0))
return;
if (this is L2Player)
ReduceHpArea(200, 297);
}
public void ReduceHpArea(int damage, int msgId)
{
//if (Dead)
// return;
//CurHp -= damage;
//StatusUpdate su = new StatusUpdate(ObjId);
//su.Add(StatusUpdate.CurHp, (int)CurHp);
//su.Add(StatusUpdate.MaxHp, (int)CharacterStat.GetStat(EffectType.BMaxHp));
//BroadcastPacket(su);
//if (CurHp <= 0)
//{
// Dead = true;
// CurHp = 0;
// DoDie(null, true);
// return;
//}
//if (this is L2Player)
// SendPacket(new SystemMessage((SystemMessage.SystemMessageId)msgId).AddNumber(damage));
}
//public override void ReduceHp(L2Character attacker, double damage)
//{
// if (Dead)
// return;
// //if ((this is L2Player && attacker is L2Player))
// //{
// // if (CurCp > 0)
// // {
// // CurCp -= damage;
// // if (CurCp < 0)
// // {
// // damage = CurCp * -1;
// // CurCp = 0;
// // }
// // }
// //}
// CharStatus.ReduceHp(damage,attacker);
// StatusUpdate statusUpdate = new StatusUpdate(this);
// statusUpdate.Add(StatusUpdate.CurHp, (int)CharStatus.CurrentHp);
// // statusUpdate.Add(StatusUpdate.CurCp, (int)CurCp);
// BroadcastPacket(statusUpdate);
// if (CharStatus.CurrentHp <= 0)
// {
// DoDie(attacker);
// return;
// }
//}
public virtual void DoDie(L2Character killer)
{
lock (this)
{
if (Dead)
return;
CharStatus.SetCurrentHp(0);
Dead = true;
}
Target = null;
NotifyStopMove(true,true);
if (IsAttacking())
AbortAttack();
CharStatus.StopHpMpRegeneration();
BroadcastStatusUpdate();
BroadcastPacket(new Die(this));
}
public virtual void DeleteByForce()
{
BroadcastPacket(new DeleteObject(ObjId));
L2World.Instance.RemoveObject(this);
}
public virtual L2Item ActiveWeapon => null;
public virtual L2Item SecondaryWeapon => null;
public virtual L2Item ActiveArmor => null;
public L2Character TargetToHit { get; set; }
public L2Character Target { get; set; }
public virtual void DoAttack(L2Character target)
{
if (target == null)
{
return;
}
if (target.Dead)
{
return;
}
if ((AttackToHit != null) && AttackToHit.Enabled)
return;
if ((AttackToEnd != null) && AttackToEnd.Enabled)
return;
double dist = 60,
reqMp = 0;
L2Item weapon = ActiveWeapon;
double timeAtk = 100;//attackspeed
bool dual = false,
ranged = false,
ss = false;
if (weapon != null) { }
else
timeAtk = (1362 * 345) / timeAtk;
if (!Calcs.CheckIfInRange((int)dist, this, target, true))
{
TryMoveTo(target.X, target.Y, target.Z);
return;
}
if ((reqMp > 0) && (reqMp > CharStatus.CurrentMp))
{
SendMessage($"no mp {CharStatus.CurrentMp} {reqMp}");
return;
}
Attack atk = new Attack(this, target, ss, 5);
if (dual)
{
Hit1 = GenHitSimple(true, ss);
atk.AddHit(target.ObjId, (int)Hit1.Damage, Hit1.Miss, Hit1.Crit, Hit1.ShieldDef > 0);
Hit2 = GenHitSimple(true, ss);
atk.AddHit(target.ObjId, (int)Hit2.Damage, Hit2.Miss, Hit2.Crit, Hit2.ShieldDef > 0);
}
else
{
Hit1 = GenHitSimple(false, ss);
atk.AddHit(target.ObjId, (int)Hit1.Damage, Hit1.Miss, Hit1.Crit, Hit1.ShieldDef > 0);
}
Target = target;
if (AttackToHit == null)
{
AttackToHit = new Timer();
AttackToHit.Elapsed += AttackDoHit;
}
double timeToHit = ranged ? timeAtk * 0.5 : timeAtk * 0.6;
AttackToHit.Interval = timeToHit;
AttackToHit.Enabled = true;
if (dual)
{
if (AttackToHitBonus == null)
{
AttackToHitBonus = new Timer();
AttackToHitBonus.Elapsed += AttackDoHit2Nd;
}
AttackToHitBonus.Interval = timeAtk * 0.78;
AttackToHitBonus.Enabled = true;
}
if (AttackToEnd == null)
{
AttackToEnd = new Timer();
AttackToEnd.Elapsed += AttackDoEnd;
}
AttackToEnd.Interval = timeAtk;
AttackToEnd.Enabled = true;
BroadcastPacket(atk);
}
public class Hit
{
public bool Miss;
public double ShieldDef;
public bool Crit;
public double Damage;
}
public Hit Hit1,
Hit2;
public Hit GenHitSimple(bool dual, bool ss)
{
Hit h = new Hit
{
Miss = false
};
if (h.Miss)
return h;
h.ShieldDef = 0;
h.Crit = false;
h.Damage = 100;
if (dual)
h.Damage *= .5;
if (ss)
h.Damage *= 2;
if (h.Crit)
h.Damage *= 2;
return h;
}
public virtual void AttackDoHit(object sender, ElapsedEventArgs e)
{
if (Target != null)
{
if (!Hit1.Miss)
{
Target.CharStatus.ReduceHp(Hit1.Damage, this);
if (Target is L2Player)
Target.SendPacket(new SystemMessage(SystemMessage.SystemMessageId.C1HasReceivedS3DamageFromC2).AddName(Target).AddName(this).AddNumber(Hit1.Damage));
}
else
{
if (Target is L2Player)
{
Target.SendPacket(new SystemMessage(SystemMessage.SystemMessageId.C1HasEvadedC2Attack).AddName(Target).AddName(this));
}
}
}
AttackToHit.Enabled = false;
}
public virtual void AttackDoHit2Nd(object sender, ElapsedEventArgs e)
{
if (Target != null)
{
if (!Hit2.Miss)
{
Target.CharStatus.ReduceHp(Hit2.Damage, this);
if (Target is L2Player)
Target.SendPacket(new SystemMessage(SystemMessage.SystemMessageId.C1HasReceivedS3DamageFromC2).AddName(Target).AddName(this).AddNumber(Hit2.Damage));
}
else
{
if (Target is L2Player)
{
Target.SendPacket(new SystemMessage(SystemMessage.SystemMessageId.C1HasEvadedC2Attack).AddName(Target).AddName(this));
}
}
}
AttackToHitBonus.Enabled = false;
}
public virtual void AttackDoEnd(object sender, ElapsedEventArgs e)
{
AttackToEnd.Enabled = false;
//L2Item weapon = Inventory.getWeapon();
//if (weapon != null)
//{
// if (weapon.Soulshot)
// weapon.Soulshot = false;
// foreach (int sid in weapon.Template.getSoulshots())
// if (autoSoulshots.Contains(sid))
// {
// if (Inventory.getItemCount(sid) < weapon.Template.SoulshotCount)
// {
// sendPacket(new SystemMessage(1435).addItemName(sid));//Due to insufficient $s1, the automatic use function has been deactivated.
// lock (autoSoulshots)
// {
// autoSoulshots.Remove(sid);
// sendPacket(new ExAutoSoulShot(sid, 0));
// }
// }
// else
// {
// Inventory.destroyItem(sid, weapon.Template.SoulshotCount, false, true);
// weapon.Soulshot = true;
// broadcastSoulshotUse(sid);
// }
// break;
// }
//}
// if (Target != null)
// doAttack((L2Character)Target);
}
public void BroadcastSoulshotUse(int itemId)
{
int skillId = 0;
switch (itemId)
{
case 1835:
case 5789:
skillId = 2039;
break;
case 1463:
skillId = 2150;
break;
case 1464:
skillId = 2151;
break;
case 1465:
skillId = 2152;
break;
case 1466:
skillId = 2153;
break;
case 1467:
skillId = 2154;
break;
case 22082:
skillId = 26060;
break;
case 22083:
skillId = 26061;
break;
case 22084:
skillId = 26062;
break;
case 22085:
skillId = 26063;
break;
case 22086:
skillId = 26064;
break;
}
if (skillId <= 0)
return;
BroadcastPacket(new MagicSkillUse(this, this, skillId, 1, 0));
SendSystemMessage(SystemMessage.SystemMessageId.EnabledSoulshot);
}
public virtual void AbortAttack()
{
if ((AttackToHit != null) && AttackToHit.Enabled)
AttackToHit.Enabled = false;
if ((AttackToHitBonus != null) && AttackToHitBonus.Enabled)
AttackToHitBonus.Enabled = false;
if ((AttackToEnd != null) && AttackToEnd.Enabled)
AttackToEnd.Enabled = false;
// hit1 = null;
// hit2 = null;
}
public Timer AttackToHit,
AttackToHitBonus,
AttackToEnd;
public int PBlockSpell = 0,
PBlockSkill = 0;
public int PBlockAct = 0;
public virtual bool CantMove()
{
if (PBlockAct == 1)
return true;
if ((AbnormalBitMaskEx & AbnormalMaskExFreezing) == AbnormalMaskExFreezing)
return true;
return false;
}
public void TryMoveTo(int x, int y, int z)
{
TargetToHit = null;
if (CantMove())
{
SendActionFailed();
return;
}
DestX = x;
DestY = y;
DestZ = z;
MoveTo(x, y, z);
}
public void TryMoveToAndHit(int x, int y, int z,L2Character target)
{
TargetToHit = target;
if (CantMove())
{
SendActionFailed();
return;
}
DestX = x;
DestY = y;
DestZ = z;
MoveToAndHit(x, y, z);
}
public void Status_FreezeMe(bool status, bool update)
{
if (status)
AbnormalBitMaskEx |= AbnormalMaskExFreezing;
else
AbnormalBitMaskEx &= ~AbnormalMaskExFreezing;
if (update)
UpdateAbnormalExEffect();
}
public virtual void OnOldTargetSelection(L2Object target) { }
public virtual void OnNewTargetSelection(L2Object target) { }
public virtual void BroadcastStatusUpdate()
{
if (!CharStatus.StatusListener.Any())
return;
//will look into this later
//if (!needHpUpdate(352))
// return;
StatusUpdate su = new StatusUpdate(this);
su.Add(StatusUpdate.CurHp, (int)CharStatus.CurrentHp);
foreach (var temp in CharStatus.StatusListener)
{
if(temp.ObjId != ObjId)
temp?.SendPacket(su);
}
}
public virtual L2Character[] GetPartyCharacters()
{
return new[] { this };
}
public bool IsMoving()
{
return (_updatePositionTime != null) && _updatePositionTime.Enabled;
}
public void MoveTo(int x, int y, int z)
{
TargetToHit = null;
if (IsAttacking())
AbortAttack();
if (_updatePositionTime.Enabled) // новый маршрут, но старый не закончен
NotifyStopMove(false);
DestX = x;
DestY = y;
DestZ = z;
double dx = x - X,
dy = y - Y;
//dz = (z - Z);
double distance = GetPlanDistanceSq(x, y);
double spy = dy / distance,
spx = dx / distance;
double speed = 130; //TODO: Human Figher Speed Based, need get characters run speed
//TODO: check possible divisions by zero
_ticksToMove = (int)Math.Ceiling((10 * distance) / speed); //Client Response time = 1000ms, XYZ server check = 100ms (distance * 10 to get better precision)
_ticksToMoveCompleted = 0;
_xSpeedTicks = (DestX - X) / (float)_ticksToMove;
_ySpeedTicks = (DestY - Y) / (float)_ticksToMove;
Heading = (int)((Math.Atan2(-spx, -spy) * 10430.378) + short.MaxValue);
BroadcastPacket(new CharMoveToLocation(this));
_updatePositionTime.Enabled = true;
}
public void MoveToAndHit(int x, int y, int z)
{
if (IsAttacking())
AbortAttack();
if (_updatePositionTime.Enabled) // новый маршрут, но старый не закончен
NotifyStopMove(false);
DestX = x;
DestY = y;
DestZ = z;
double dx = x - X,
dy = y - Y;
//dz = (z - Z);
double distance = GetPlanDistanceSq(x, y);
double spy = dy / distance,
spx = dx / distance;
double speed = 130; //TODO: Human Figher Speed Based, need get characters run speed
//TODO: check possible divisions by zero
_ticksToMove = (int)Math.Ceiling((10 * distance) / speed); //Client Response time = 1000ms, XYZ server check = 100ms (distance * 10 to get better precision)
_ticksToMoveCompleted = 0;
_xSpeedTicks = (DestX - X) / (float)_ticksToMove;
_ySpeedTicks = (DestY - Y) / (float)_ticksToMove;
Heading = (int)((Math.Atan2(-spx, -spy) * 10430.378) + short.MaxValue);
BroadcastPacket(new CharMoveToLocation(this));
_updatePositionTime.Enabled = true;
}
private void UpdatePositionTask(object sender, ElapsedEventArgs e)
{
ValidateWaterZones();
if ((DestX == X) && (DestY == Y) && (DestZ == Z))
{
NotifyArrived();
return;
}
if (_ticksToMove > _ticksToMoveCompleted)
{
_ticksToMoveCompleted++;
X += (int)_xSpeedTicks;
Y += (int)_ySpeedTicks;
}
else
{
X = DestX;
Y = DestY;
Z = DestZ;
NotifyArrived();
}
}
public virtual void NotifyStopMove(bool broadcast, bool update = false)
{
if (_updatePositionTime.Enabled)
_updatePositionTime.Enabled = false;
if (update)
BroadcastPacket(new StopMove(this));
DestX = 0;
DestY = 0;
DestZ = 0;
_xSpeedTicks = 0;
_ySpeedTicks = 0;
_ticksToMove = 0;
_ticksToMoveCompleted = 0;
}
public virtual void NotifyArrived()
{
if (TargetToHit != null)
this.DoAttack(TargetToHit);
if (_updatePositionTime.Enabled)
_updatePositionTime.Enabled = false;
DestX = 0;
DestY = 0;
DestZ = 0;
_xSpeedTicks = 0;
_ySpeedTicks = 0;
_ticksToMove = 0;
}
private int _ticksToMove,
_ticksToMoveCompleted;
private float _xSpeedTicks;
private float _ySpeedTicks;