Addition of getMainDamageDealer method.

This commit is contained in:
MobiusDevelopment
2021-10-27 21:26:39 +00:00
parent ebddd951ed
commit 6b069bb28a
46 changed files with 562 additions and 59 deletions

View File

@@ -921,6 +921,27 @@ public class Attackable extends NpcInstance
}
}
public Creature getMainDamageDealer()
{
if (_aggroList.isEmpty())
{
return null;
}
int damage = 0;
Creature damageDealer = null;
for (AggroInfo info : _aggroList.values())
{
if ((info != null) && (info._damage > damage) && Util.checkIfInRange(Config.ALT_PARTY_RANGE, this, info._attacker, true))
{
damage = info._damage;
damageDealer = info._attacker;
}
}
return damageDealer;
}
/**
* Add damage and hate to the attacker AggroInfo of the Attackable _aggroList.
* @param attacker The Creature that gave damages to this Attackable

View File

@@ -1817,6 +1817,11 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
setKilledAlready(true);
}
// Calculate rewards for main damage dealer.
final Creature mainDamageDealer = isMonster() ? ((MonsterInstance) this).getMainDamageDealer() : null;
calculateRewards(mainDamageDealer != null ? mainDamageDealer : killer);
// Set target to null and cancel Attack or Cast
setTarget(null);
@@ -1885,28 +1890,11 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
stopAllEffects();
}
}
else
// this means all other characters, including Summons
else // this means all other characters, including Summons
{
stopAllEffects();
}
// if killer is the same then the most damager/hated
Creature mostHated = null;
if (this instanceof Attackable)
{
mostHated = ((Attackable) this)._mostHated;
}
if ((mostHated != null) && isInsideRadius2D(mostHated, 200))
{
calculateRewards(mostHated);
}
else
{
calculateRewards(killer);
}
// Send the Server->Client packet StatusUpdate with current HP and MP to all other PlayerInstance to inform
broadcastStatusUpdate();