Skip to content

Commit fe8287b

Browse files
committed
Refact. Damage to monsters
1 parent 0d84f1b commit fe8287b

10 files changed

Lines changed: 121 additions & 101 deletions

File tree

src/L2dotNET/Commands/Admin/AdminHeal.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ protected internal override void Use(L2Player admin, string alias)
1919

2020
double hpval = target.MaxHp;
2121
double mpval = target.MaxMp;
22-
target.CharStatus.CurrentHp = target.MaxHp;
23-
target.CharStatus.CurrentMp = target.MaxMp;
22+
target.CharStatus.SetCurrentHp(target.MaxHp);
23+
target.CharStatus.SetCurrentMp(target.MaxMp);
2424

2525
StatusUpdate su = new StatusUpdate(target);
2626
su.Add(StatusUpdate.CurHp, (int)target.CharStatus.CurrentHp);

src/L2dotNET/Models/L2Character.cs

Lines changed: 62 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,33 @@ public class L2Character : L2Object
2828

2929
public byte IsRunning { get; set; } = 1;
3030

31-
public int AbnormalBitMask;
32-
public int AbnormalBitMaskEx;
33-
public int AbnormalBitMaskEvent;
34-
35-
public const int AbnormalMaskBleed = 0x000001;
36-
37-
public const int AbnormalMaskExInvincible = 0x000001;
38-
public const int AbnormalMaskExAirStun = 0x000002;
39-
public const int AbnormalMaskExAirRoot = 0x000004;
40-
public const int AbnormalMaskExBagSword = 0x000008;
41-
public const int AbnormalMaskExAfroYellow = 0x000010;
42-
public const int AbnormalMaskExAfroPink = 0x000020;
43-
public const int AbnormalMaskExAfroBlack = 0x000040;
44-
//unk x80
45-
public const int AbnormalMaskExStigmaShillien = 0x000100;
46-
public const int AbnormalMaskExStakatoRoot = 0x000200;
47-
public const int AbnormalMaskExFreezing = 0x000400;
48-
public const int AbnormalMaskExVesper = 0x000800;
49-
50-
public const int AbnormalMaskEventIceHand = 0x000008;
51-
public const int AbnormalMaskEventHeadphone = 0x000010;
52-
public const int AbnormalMaskEventCrown1 = 0x000020;
53-
public const int AbnormalMaskEventCrown2 = 0x000040;
54-
public const int AbnormalMaskEventCrown3 = 0x000080;
55-
31+
#region AbhornalMask
32+
public int AbnormalBitMask;
33+
public int AbnormalBitMaskEx;
34+
public int AbnormalBitMaskEvent;
35+
36+
public const int AbnormalMaskBleed = 0x000001;
37+
38+
public const int AbnormalMaskExInvincible = 0x000001;
39+
public const int AbnormalMaskExAirStun = 0x000002;
40+
public const int AbnormalMaskExAirRoot = 0x000004;
41+
public const int AbnormalMaskExBagSword = 0x000008;
42+
public const int AbnormalMaskExAfroYellow = 0x000010;
43+
public const int AbnormalMaskExAfroPink = 0x000020;
44+
public const int AbnormalMaskExAfroBlack = 0x000040;
45+
//unk x80
46+
public const int AbnormalMaskExStigmaShillien = 0x000100;
47+
public const int AbnormalMaskExStakatoRoot = 0x000200;
48+
public const int AbnormalMaskExFreezing = 0x000400;
49+
public const int AbnormalMaskExVesper = 0x000800;
50+
51+
public const int AbnormalMaskEventIceHand = 0x000008;
52+
public const int AbnormalMaskEventHeadphone = 0x000010;
53+
public const int AbnormalMaskEventCrown1 = 0x000020;
54+
public const int AbnormalMaskEventCrown2 = 0x000040;
55+
public const int AbnormalMaskEventCrown3 = 0x000080;
56+
#endregion
57+
5658
public int Int => CharacterStat.Int;
5759

5860
public int Str => CharacterStat.Str;
@@ -429,39 +431,38 @@ public void ReduceHpArea(int damage, int msgId)
429431
// SendPacket(new SystemMessage((SystemMessage.SystemMessageId)msgId).AddNumber(damage));
430432
}
431433

432-
public override void ReduceHp(L2Character attacker, double damage)
433-
{
434-
if (Dead)
435-
return;
436-
437-
//if ((this is L2Player && attacker is L2Player))
438-
//{
439-
// if (CurCp > 0)
440-
// {
441-
// CurCp -= damage;
442-
443-
// if (CurCp < 0)
444-
// {
445-
// damage = CurCp * -1;
446-
// CurCp = 0;
447-
// }
448-
// }
449-
//}
450-
451-
CharStatus.CurrentHp -= damage;
452-
453-
StatusUpdate statusUpdate = new StatusUpdate(this);
454-
statusUpdate.Add(StatusUpdate.CurHp, (int)CharStatus.CurrentHp);
455-
// statusUpdate.Add(StatusUpdate.CurCp, (int)CurCp);
456-
BroadcastPacket(statusUpdate);
457-
458-
if (CharStatus.CurrentHp <= 0)
459-
{
460-
CharStatus.CurrentHp = 0;
461-
DoDie(attacker);
462-
return;
463-
}
464-
}
434+
//public override void ReduceHp(L2Character attacker, double damage)
435+
//{
436+
// if (Dead)
437+
// return;
438+
439+
// //if ((this is L2Player && attacker is L2Player))
440+
// //{
441+
// // if (CurCp > 0)
442+
// // {
443+
// // CurCp -= damage;
444+
445+
// // if (CurCp < 0)
446+
// // {
447+
// // damage = CurCp * -1;
448+
// // CurCp = 0;
449+
// // }
450+
// // }
451+
// //}
452+
453+
// CharStatus.ReduceHp(damage,attacker);
454+
455+
// StatusUpdate statusUpdate = new StatusUpdate(this);
456+
// statusUpdate.Add(StatusUpdate.CurHp, (int)CharStatus.CurrentHp);
457+
// // statusUpdate.Add(StatusUpdate.CurCp, (int)CurCp);
458+
// BroadcastPacket(statusUpdate);
459+
460+
// if (CharStatus.CurrentHp <= 0)
461+
// {
462+
// DoDie(attacker);
463+
// return;
464+
// }
465+
//}
465466

466467
public virtual void DoDie(L2Character killer)
467468
{
@@ -470,7 +471,7 @@ public virtual void DoDie(L2Character killer)
470471
if (Dead)
471472
return;
472473

473-
CharStatus.CurrentHp = 0;
474+
CharStatus.SetCurrentHp(0);
474475

475476
Dead = true;
476477
}
@@ -637,7 +638,7 @@ public virtual void AttackDoHit(object sender, ElapsedEventArgs e)
637638
{
638639
if (!Hit1.Miss)
639640
{
640-
Target.ReduceHp(this, Hit1.Damage);
641+
Target.CharStatus.ReduceHp(Hit1.Damage, this);
641642

642643
if (Target is L2Player)
643644
Target.SendPacket(new SystemMessage(SystemMessage.SystemMessageId.C1HasReceivedS3DamageFromC2).AddName(Target).AddName(this).AddNumber(Hit1.Damage));
@@ -660,7 +661,7 @@ public virtual void AttackDoHit2Nd(object sender, ElapsedEventArgs e)
660661
{
661662
if (!Hit2.Miss)
662663
{
663-
Target.ReduceHp(this, Hit2.Damage);
664+
Target.CharStatus.ReduceHp(Hit2.Damage, this);
664665
if (Target is L2Player)
665666
Target.SendPacket(new SystemMessage(SystemMessage.SystemMessageId.C1HasReceivedS3DamageFromC2).AddName(Target).AddName(this).AddNumber(Hit2.Damage));
666667
}

src/L2dotNET/Models/L2Object.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public virtual void BroadcastPacket(GameserverPacket pk)
8585
BroadcastPacket(pk, false);
8686
}
8787

88-
public virtual void ReduceHp(L2Character attacker, double damage) { }
88+
//public virtual void ReduceHp(L2Character attacker, double damage) { }
8989

9090
public virtual void DecayMe()
9191
{

src/L2dotNET/Models/Status/CharStatus.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public class CharStatus
1515
protected static readonly byte RegenFlagCp = 4;
1616
private static readonly byte RegenFlagHp = 1;
1717
private static readonly byte RegenFlagMp = 2;
18-
public double CurrentHp { get => _currentHp; set => SetCurrentHp(value); }
19-
public double CurrentMp { get => _currentMp; set => SetCurrentMp(value); }
18+
public double CurrentHp { get => _currentHp; }
19+
public double CurrentMp { get => _currentMp; }
2020
private Timer _regTask;
2121
protected byte _flagsRegenActive = 0;
2222
private double _currentHp = 0;
@@ -46,9 +46,11 @@ public void ReduceHp(double value, L2Character attacker /*, bool awake, bool isD
4646
return;
4747

4848
if (value > 0)
49-
SetCurrentHp(Math.Max(CurrentHp - value, 0));
49+
{
50+
SetCurrentHp(Math.Max(_currentHp - value, 0), true);
51+
}
5052

51-
if (CurrentHp < 0.5)
53+
if (_currentHp < 0.5)
5254
{
5355
Character.AbortAttack();
5456
Character.DoDie(attacker);
@@ -57,7 +59,7 @@ public void ReduceHp(double value, L2Character attacker /*, bool awake, bool isD
5759

5860
public void ReduceMp(double value)
5961
{
60-
CurrentMp = Math.Max(CurrentMp - value, 0);
62+
_currentMp = Math.Max(_currentMp - value, 0);
6163
}
6264

6365
public void SetCurrentMp(double newMp)
@@ -151,13 +153,13 @@ public void StopHpMpRegeneration()
151153

152154
private void RegenTask(object sender, ElapsedEventArgs e)
153155
{
154-
if (CurrentHp < Character.MaxHp)
155-
SetCurrentHp(CurrentHp + (Character.MaxHp * 1.0 / 100), false); // we will calculate the actual modified when we do formulas
156+
if (_currentHp < Character.MaxHp)
157+
SetCurrentHp(_currentHp + (Character.MaxHp * 1.0 / 100), false); // we will calculate the actual modified when we do formulas
156158

157-
if (CurrentMp < Character.MaxMp)
158-
SetCurrentMp(CurrentMp + (Character.MaxMp * 1.0 / 100), false); // we will calculate the actual modified when we do formulas
159+
if (_currentMp < Character.MaxMp)
160+
SetCurrentMp(_currentMp + (Character.MaxMp * 1.0 / 100), false); // we will calculate the actual modified when we do formulas
159161

160-
//Character.BroadcastStatusUpdate();
162+
Character.BroadcastStatusUpdate();
161163
}
162164
}
163165
}

src/L2dotNET/Models/Status/PlayerStatus.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ public PlayerStatus(L2Player player) : base(player)
1212
Character = player;
1313
}
1414

15-
public void SetCurrentCp(double newHp)
15+
public void SetCurrentCp(double newCp)
1616
{
17-
SetCurrentHp(newHp, true);
17+
//SetCurrentHp(newCp, true);
1818
}
1919

2020
[MethodImpl(MethodImplOptions.Synchronized)]

src/L2dotNET/Models/npcs/L2Monster.cs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace L2dotNET.Models.npcs
99
{
1010
class L2Monster : L2Npc
1111
{
12-
1312
private readonly ILog Log = LogManager.GetLogger(typeof(L2Monster));
1413

1514
private Timer CorpseTimer;
@@ -20,14 +19,15 @@ public L2Monster(int objectId, NpcTemplate template) : base(objectId, template)
2019
Name = template.Name;
2120
InitializeCharacterStatus();
2221

23-
CharStatus.CurrentHp = Template.BaseHpMax(0);
24-
CharStatus.CurrentMp = Template.BaseMpMax(0);
22+
CharStatus.SetCurrentHp(Template.BaseHpMax(0));
23+
CharStatus.SetCurrentMp(Template.BaseMpMax(0));
2524
//Stats = new CharacterStat(this);
2625
}
2726

2827
public override void OnAction(L2Player player)
2928
{
30-
if (player.Target != this) {
29+
if (player.Target != this)
30+
{
3131
player.SetTarget(this);
3232
player.SendPacket(new MyTargetSelected(ObjId, 0));
3333
return;
@@ -39,14 +39,35 @@ public override void OnAction(L2Player player)
3939
}
4040

4141
public override void DoDie(L2Character killer)
42-
{
42+
{
43+
lock (this)
44+
{
45+
if (Dead)
46+
return;
47+
48+
CharStatus.SetCurrentHp(0);
49+
50+
Dead = true;
51+
}
4352
//Check For Exp
44-
if(killer is L2Player)
53+
if (killer is L2Player)
4554
{
4655
((L2Player)killer).AddExpSp(this.Template.Exp, this.Template.Sp, true);
4756
}
57+
58+
Target = null;
59+
NotifyStopMove(true, true);
60+
61+
if (IsAttacking())
62+
AbortAttack();
63+
64+
CharStatus.StopHpMpRegeneration();
65+
66+
//BroadcastPacket(new Die(this));
4867
if (Template.CorpseTime <= 0)
49-
{ return; }
68+
{
69+
return;
70+
}
5071
CorpseTimer = new Timer(Template.CorpseTime * 1000);
5172
CorpseTimer.Elapsed += new ElapsedEventHandler(RemoveCorpse);
5273
CorpseTimer.Start();

src/L2dotNET/Models/npcs/L2Npc.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ namespace L2dotNET.Models.npcs
1313
{
1414
public class L2Npc : L2Character
1515
{
16+
private readonly ILog Log = LogManager.GetLogger(typeof(L2Npc));
17+
1618
public new NpcTemplate Template;
1719
public bool Summoned;
1820
public bool StructureControlled = false;
1921

20-
21-
private readonly ILog Log = LogManager.GetLogger(typeof(L2Npc)) ;
22-
2322
public L2Npc(int objectId, NpcTemplate template) : base(objectId, template)
2423
{
2524
Template = template;
@@ -54,7 +53,7 @@ public L2Npc(int objectId, NpcTemplate template) : base(objectId, template)
5453
public override void NotifyAction(L2Player player)
5554
{
5655
double dis = Calcs.CalculateDistance(player, this, true);
57-
TryMoveTo(X, Y, Z);
56+
TryMoveTo(X, Y, Z);
5857
}
5958

6059
public int NpcId => Template.NpcId;
@@ -78,8 +77,8 @@ public override void OnAction(L2Player player)
7877
else
7978
{
8079
player.MoveTo(X, Y, Z);
81-
player.SendPacket(new MoveToPawn(player, this,150));
82-
if(Template.Type == "L2Monster")
80+
player.SendPacket(new MoveToPawn(player, this, 150));
81+
if (Template.Type == "L2Monster")
8382
{
8483
Log.Debug("Attack Monester By L2NPC");
8584
player.DoAttack(this);
@@ -90,7 +89,7 @@ public override void OnAction(L2Player player)
9089

9190
public virtual void OnTeleportRequest(L2Player player)
9291
{
93-
92+
9493
}
9594

9695
public void UseTeleporter(L2Player player, int type, int entryId)
@@ -289,7 +288,7 @@ public void ShowSkillLearn(L2Player player, bool backward)
289288

290289
public override void BroadcastUserInfo()
291290
{
292-
foreach (var character in L2World.Instance.GetObjects().Where(x=>x.GetType() == typeof(L2Character)))
291+
foreach (var character in L2World.Instance.GetObjects().Where(x => x.GetType() == typeof(L2Character)))
293292
character.SendPacket(new NpcInfo(this));
294293
}
295294

@@ -300,11 +299,11 @@ public override void BroadcastUserInfoToObject(L2Object l2Object)
300299

301300
public override void OnSpawn(bool notifyOthers = true)
302301
{
303-
if(notifyOthers)
302+
if (notifyOthers)
304303
BroadcastUserInfo();
305304
StartAi();
306305
}
307-
306+
308307
private Timer _corpseTimer;
309308
public int ResidenceId;
310309

@@ -316,8 +315,6 @@ public override void DoDie(L2Character killer)
316315
{
317316
return;
318317
}
319-
320-
321318
_corpseTimer = new Timer(Template.CorpseTime * 1000);
322319
_corpseTimer.Elapsed += new ElapsedEventHandler(RemoveCorpse);
323320
_corpseTimer.Enabled = true;

src/L2dotNET/Models/npcs/decor/L2Chair.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public L2Chair(int objectId, CharTemplate template) : base(objectId, template)
1010
{
1111
Closed = 0;
1212
//MaxHp = 0;
13-
CharStatus.CurrentHp = 0;
13+
CharStatus.SetCurrentHp(0);
1414
}
1515

1616
public override string AsString()

0 commit comments

Comments
 (0)