summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/Buff/XBuffLifeSteal.cs
blob: a2250c2e7cb1e6e304dbaf80d62b824bfa70b46e (plain)
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
using System;
using XUtliPoolLib;

namespace XMainClient
{
	internal class XBuffLifeSteal : BuffEffect
	{
		private float m_Ratio;

		private float m_UpperBoundRatio;

		private double m_StealUpperBound = 0.0;

		private XBuff m_Buff;

		private XEntity m_Entity;

		public static bool TryCreate(BuffTable.RowData rowData, XBuff buff)
		{
			bool flag = rowData.LifeSteal[0] == 0f;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				buff.AddEffect(new XBuffLifeSteal(ref rowData.LifeSteal, buff));
				result = true;
			}
			return result;
		}

		public XBuffLifeSteal(ref SeqRef<float> data, XBuff _Buff)
		{
			this.m_Ratio = data[0];
			this.m_Buff = _Buff;
			this.m_UpperBoundRatio = data[1];
		}

		public override void OnAdd(XEntity entity, CombatEffectHelper pEffectHelper)
		{
			this.m_Entity = entity;
			bool flag = this.m_UpperBoundRatio > 0f && entity != null && entity.Attributes != null;
			if (flag)
			{
				this.m_StealUpperBound = entity.Attributes.GetAttr(XAttributeDefine.XAttr_MaxHP_Total) * (double)this.m_UpperBoundRatio;
			}
		}

		public override void OnRemove(XEntity entity, bool IsReplaced)
		{
		}

		public override void OnCastDamage(HurtInfo rawInput, ProjectDamageResult result)
		{
			bool flag = rawInput.SkillID == 0u;
			if (!flag)
			{
				bool flag2 = this.m_Buff.RelevantSkills != null && this.m_Buff.RelevantSkills.Count != 0;
				if (flag2)
				{
					bool flag3 = !this.m_Buff.RelevantSkills.Contains(rawInput.SkillID);
					if (flag3)
					{
						return;
					}
				}
				bool accept = result.Accept;
				if (accept)
				{
					double num = result.Value * (double)this.m_Ratio;
					bool flag4 = this.m_UpperBoundRatio > 0f;
					if (flag4)
					{
						num = Math.Min(num, this.m_StealUpperBound);
						this.m_StealUpperBound -= num;
					}
					bool flag5 = num > 0.0;
					if (flag5)
					{
						XAttrChangeEventArgs @event = XEventPool<XAttrChangeEventArgs>.GetEvent();
						@event.AttrKey = XAttributeDefine.XAttr_CurrentHP_Basic;
						@event.DeltaValue = num;
						@event.Firer = this.m_Entity;
						@event.bShowHUD = !this.m_Buff.BuffInfo.DontShowText;
						XSingleton<XEventMgr>.singleton.FireEvent(@event);
					}
				}
			}
		}
	}
}