1
|
|
|
/* |
2
|
|
|
* This file is part of Araknemu. |
3
|
|
|
* |
4
|
|
|
* Araknemu is free software: you can redistribute it and/or modify |
5
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
7
|
|
|
* (at your option) any later version. |
8
|
|
|
* |
9
|
|
|
* Araknemu is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU Lesser General Public License for more details. |
13
|
|
|
* |
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
15
|
|
|
* along with Araknemu. If not, see <https://www.gnu.org/licenses/>. |
16
|
|
|
* |
17
|
|
|
* Copyright (c) 2017-2019 Vincent Quatrevieux |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
package fr.quatrevieux.araknemu.game.fight.castable.effect.handler.damage; |
21
|
|
|
|
22
|
|
|
import fr.quatrevieux.araknemu.game.fight.castable.effect.Element; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Compute suffered damage |
26
|
|
|
* |
27
|
|
|
* Formula : |
28
|
|
|
* (value * percent / 100 - fixed - reduce) * multiply |
29
|
|
|
*/ |
30
|
|
|
public final class Damage implements MultipliableDamage { |
31
|
|
|
private final int value; |
32
|
|
|
private final Element element; |
33
|
|
|
|
34
|
1 |
|
private int multiply = 1; |
35
|
1 |
|
private int fixed = 0; |
36
|
1 |
|
private int percent = 100; |
37
|
1 |
|
private int reduce = 0; |
38
|
1 |
|
private int returned = 0; |
39
|
|
|
|
40
|
1 |
|
public Damage(int value, Element element) { |
41
|
1 |
|
this.value = value; |
42
|
1 |
|
this.element = element; |
43
|
1 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get the damage element |
47
|
|
|
*/ |
48
|
|
|
public Element element() { |
49
|
1 |
|
return element; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
@Override |
53
|
|
|
public int value() { |
54
|
1 |
|
final int base = (value * percent / 100 - fixed - reduce); |
55
|
|
|
|
56
|
1 |
|
if (base <= 0) { |
57
|
1 |
|
return 0; |
58
|
|
|
} |
59
|
|
|
|
60
|
1 |
|
return base * multiply; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Reduce damage in percent |
65
|
|
|
*/ |
66
|
|
|
public Damage percent(int percent) { |
67
|
1 |
|
if (percent > this.percent) { |
68
|
1 |
|
this.percent = 0; |
69
|
|
|
} else { |
70
|
1 |
|
this.percent -= percent; |
71
|
|
|
} |
72
|
|
|
|
73
|
1 |
|
return this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Reduce fixed damage |
78
|
|
|
*/ |
79
|
|
|
public Damage fixed(int fixed) { |
80
|
1 |
|
this.fixed += fixed; |
81
|
|
|
|
82
|
1 |
|
return this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
@Override |
86
|
|
|
public Damage multiply(int factor) { |
87
|
1 |
|
this.multiply *= factor; |
88
|
|
|
|
89
|
1 |
|
return this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Reduce fixed damage with buff effect |
94
|
|
|
*/ |
95
|
|
|
public Damage reduce(int value) { |
96
|
1 |
|
this.reduce += value; |
97
|
|
|
|
98
|
1 |
|
return this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Add reflected damage |
103
|
|
|
*/ |
104
|
|
|
public Damage reflect(int value) { |
105
|
1 |
|
this.returned += value; |
106
|
|
|
|
107
|
1 |
|
return this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Get the damage reduction value from armor buff effects |
112
|
|
|
*/ |
113
|
|
|
public int reducedDamage() { |
114
|
1 |
|
return reduce; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* How much damage has been reflected by the target ? |
119
|
|
|
*/ |
120
|
|
|
public int reflectedDamage() { |
121
|
1 |
|
return returned; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|