1package com.osroyale.game.world.entity.combat;
3import com.osroyale.game.world.entity.combat.hit.Hit;
4import com.osroyale.game.world.entity.mob.Mob;
5import com.osroyale.game.world.entity.mob.npc.Npc;
6import com.osroyale.game.world.entity.mob.player.Player;
7import com.osroyale.game.world.entity.mob.player.PlayerRight;
8import com.osroyale.util.Stopwatch;
10import java.util.HashMap;
12import java.util.Optional;
13import java.util.concurrent.TimeUnit;
63 private final Map<Mob, DamageCounter> attackers =
new HashMap<>();
76 if (hit.getDamage() > 0) {
77 DamageCounter counter = attackers.putIfAbsent(character,
new DamageCounter(hit.getDamage()));
79 counter.incrementAmount(hit.getDamage());
94 for (Map.Entry<
Mob, DamageCounter> entry : attackers.entrySet()) {
95 DamageCounter counter = entry.getValue();
96 Mob entity = entry.getKey();
98 if (!entity.isNpc() || entity.isDead() || !entity.isValid() || counter.isTimeout())
100 if (counter.getAmount() > amount) {
101 amount = counter.getAmount();
102 killer = entity.getNpc();
105 return Optional.ofNullable(killer);
118 for (Map.Entry<
Mob, DamageCounter> entry : attackers.entrySet()) {
119 DamageCounter counter = entry.getValue();
120 Mob entity = entry.getKey();
122 if (!entity.isPlayer() || entity.isDead() || entity.isValid() || counter.isTimeout())
124 if (counter.getAmount() > amount) {
125 amount = counter.getAmount();
126 killer = entity.getPlayer();
129 return Optional.ofNullable(killer);
142 for (Map.Entry<
Mob, DamageCounter> entry : attackers.entrySet()) {
143 DamageCounter counter = entry.getValue();
144 Mob mob = entry.getKey();
146 if (mob.isDead() || !mob.isValid() || counter.isTimeout())
152 if (counter.getAmount() > amount) {
153 amount = counter.getAmount();
157 return Optional.ofNullable(killer);
173 private static final class DamageCounter {
190 public DamageCounter(
int amount) {
191 this.amount = amount;
199 public int getAmount() {
208 public void incrementAmount(
int amount) {
209 if (this.isTimeout()) {
212 this.amount += amount;
213 this.stopwatch.reset();
222 public boolean isTimeout() {
223 return stopwatch.elapsed(CombatConstants.DAMAGE_CACHE_TIMEOUT, TimeUnit.SECONDS);
Optional< Mob > calculateProperKiller()
Optional< Player > getPlayerKiller()
void add(Mob character, Hit hit)
Optional< Npc > getNpcKiller()
static boolean isIronman(Player player)