RuneHive-Game
Loading...
Searching...
No Matches
Hit.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.hit;
2
3import java.util.function.Function;
4
5/**
6 * A {@code Hit} object holds the damage amount and hitsplat data.
7 *
8 * @author Michael | Chex
9 */
10public class Hit {
11
12 /** The damage amount. */
13 private int damage;
14
15 /** The hitsplat type. */
17
18 /** The hit icon. */
20
21 /** Whether or not this hit is accurate. */
22 private boolean accurate;
23
24 private Hit[] multipleHits = null;
25
26 /**
27 * Constructs a new {@link Hit} object.
28 *
29 * @param multipleHits A array of multiple hits
30 */
31 public Hit(Hit[] multipleHits) {
32 this.multipleHits = multipleHits;
33 int totalDamage = 0;
34 for(Hit hit : multipleHits) totalDamage += hit.damage;
35 this.damage = totalDamage;
36 }
37
38 /**
39 * Constructs a new {@link Hit} object.
40 *
41 * @param damage the damage amount
42 * @param hitsplat the hitsplat type
43 * @param hitIcon the hit icon
44 * @param accurate whether or not this hit is accurate
45 */
47 this.damage = damage;
48 this.hitsplat = hitsplat;
49 this.hitIcon = hitIcon;
50 this.accurate = accurate;
51 }
52
53 /**
54 * Constructs a new {@link Hit} object.
55 *
56 * @param damage the damage amount
57 * @param hitsplat the hitsplat type
58 * @param hitIcon the hit icon
59 */
61 this(damage, hitsplat, hitIcon, damage > 0);
62 }
63
64 /**
65 * Constructs a new {@link Hit} object.
66 *
67 * @param damage the damage amount
68 * @param hitIcon the hit icon
69 */
70 public Hit(int damage, HitIcon hitIcon) {
71 this(damage, Hitsplat.NORMAL, hitIcon, damage > 0);
72 }
73
74 /**
75 * Constructs a new {@link Hit} object.
76 *
77 * @param damage the damage amount
78 * @param hitsplat the hitsplat type
79 */
80 public Hit(int damage, Hitsplat hitsplat) {
81 this(damage, hitsplat, HitIcon.NONE, damage > 0);
82 }
83
84 /**
85 * Constructs a new {@link Hit} object.
86 *
87 * @param damage the damage amount
88 */
89 public Hit(int damage) {
91 }
92
93 /**
94 * Sets the hit damage.
95 *
96 * @param damage the damage to set
97 */
98 public void setDamage(int damage) {
99 this.damage = damage;
100 }
101
102 /**
103 * Sets the hit damage with a function. If the damage is less than one, the
104 * damage is set to zero and hitsplat setVenom to block.
105 *
106 * @param modifier the modifier to damage
107 */
108 public void modifyDamage(Function<Integer, Integer> modifier) {
109 damage = modifier.apply(damage);
110
111 if (damage <= 0) {
112 damage = 0;
113 }
114 }
115
116 /**
117 * Gets the damage amount.
118 *
119 * @return the damage amount
120 */
121 public int getDamage() {
122 return damage;
123 }
124
125 /**
126 * Gets the damage type.
127 *
128 * @return the damage type
129 */
131 return hitsplat;
132 }
133
134 /**
135 * Gets the hit icon.
136 *
137 * @return the hit icon
138 */
140 return hitIcon;
141 }
142
143 /**
144 * Checks if the hit is accurate.
145 *
146 * @return {@code true} if the hit is accurate
147 */
148 public boolean isAccurate() {
149 return accurate;
150 }
151
152 public Hit[] getMultipleHits() { return multipleHits; }
153
154 /**
155 * Sets the hit icon.
156 *
157 * @param hitIcon the hit icon to set
158 */
159 public void setIcon(HitIcon hitIcon) {
160 this.hitIcon = hitIcon;
161 }
162
164 this.hitsplat = hitsplat;
165 }
166
167 public void setAs(Hit other) {
168 this.damage = other.damage;
169 this.hitIcon = other.hitIcon;
170 this.hitsplat = other.hitsplat;
171 this.accurate = other.accurate;
172 }
173
174 public void setAccurate(boolean accurate) {
175 this.accurate = accurate;
176 }
177}
Hitsplat hitsplat
The hitsplat type.
Definition Hit.java:16
int getDamage()
Gets the damage amount.
Definition Hit.java:121
Hit(int damage, HitIcon hitIcon)
Constructs a new Hit object.
Definition Hit.java:70
Hit(int damage, Hitsplat hitsplat, HitIcon hitIcon, boolean accurate)
Constructs a new Hit object.
Definition Hit.java:46
void setIcon(HitIcon hitIcon)
Sets the hit icon.
Definition Hit.java:159
Hit(int damage)
Constructs a new Hit object.
Definition Hit.java:89
Hit(int damage, Hitsplat hitsplat, HitIcon hitIcon)
Constructs a new Hit object.
Definition Hit.java:60
Hit(Hit[] multipleHits)
Constructs a new Hit object.
Definition Hit.java:31
Hitsplat getHitsplat()
Gets the damage type.
Definition Hit.java:130
boolean accurate
Whether or not this hit is accurate.
Definition Hit.java:22
HitIcon getHitIcon()
Gets the hit icon.
Definition Hit.java:139
void setDamage(int damage)
Sets the hit damage.
Definition Hit.java:98
Hit(int damage, Hitsplat hitsplat)
Constructs a new Hit object.
Definition Hit.java:80
void modifyDamage(Function< Integer, Integer > modifier)
Sets the hit damage with a function.
Definition Hit.java:108
void setHitsplat(Hitsplat hitsplat)
Definition Hit.java:163
boolean isAccurate()
Checks if the hit is accurate.
Definition Hit.java:148
The enumerated type whose elements represent the hit icon of a Hit.
Definition HitIcon.java:8