}
public void calculateRewards(L2Character lastAttacker)
{
HashMap<L2Playable, AggroInfo> aggroList = getAggroMap();
L2Character topDamager = getTopDamager(aggroList.values());
if(lastAttacker == null && topDamager != null)
{
lastAttacker = topDamager;
}
if(lastAttacker == null || aggroList.isEmpty())
{
return;
}
L2Player killer = lastAttacker.getPlayer();
if(killer == null)
{
return;
}
if(topDamager == null)
{
topDamager = lastAttacker;
}
// Notify the Quest Engine of the L2NpcInstance death if necessary
try
{
if(Config.KILL_COUNTER)
{
killer.incrementKillsCounter(getNpcId());
}
getTemplate().killscount++;
if(getTemplate().hasQuestEvents())
{
GArray<L2Player> players = null; // массив с игроками, которые могут быть заинтересованы в квестах
if(isRaid() && Config.ALT_NO_LASTHIT) // Для альта на ластхит берем всех игроков вокруг
{
players = new GArray<L2Player>();
for(L2Playable pl : aggroList.keySet())
{
if(pl.isPlayer() && !pl.isDead() && pl.getReflectionId() == getReflectionId() && (pl.isInRange(this, Config.ALT_PARTY_DISTRIBUTION_RANGE) || pl.isInRange(killer, Config.ALT_PARTY_DISTRIBUTION_RANGE)) && Math.abs(pl.getZ() - getZ()) < 400)
{
players.add((L2Player) pl);
}
}
}
else if(killer.getParty() != null) // если пати то собираем всех кто подходит
{
players = new GArray<L2Player>(killer.getParty().getMemberCount());
for(L2Player pl : killer.getParty().getPartyMembers())
{
if(!pl.isDead() && pl.getReflectionId() == getReflectionId() && (pl.isInRange(this, Config.ALT_PARTY_DISTRIBUTION_RANGE) || pl.isInRange(killer, Config.ALT_PARTY_DISTRIBUTION_RANGE)) && Math.abs(pl.getZ() - getZ()) < 400)
{
players.add(pl);
}
}
}
if(getTemplate().getEventQuests(QuestEventType.MOBKILLED) != null)
{
for(Quest quest : getTemplate().getEventQuests(QuestEventType.MOBKILLED))
{
L2Player toReward = killer;
if(quest.getParty() != Quest.PARTY_NONE && players != null)
{
if(isRaid() || quest.getParty() == Quest.PARTY_ALL) // если цель рейд или квест для всей пати награждаем всех участников
{
for(L2Player pl : players)
{
QuestState qs = pl.getQuestState(quest.getName());
if(qs != null && !qs.isCompleted())
{
quest.notifyKill(this, qs);
}
}
toReward = null;
}
else
{ // иначе выбираем одного
GArray<L2Player> interested = new GArray<L2Player>(players.size());
for(L2Player pl : players)
{
QuestState qs = pl.getQuestState(quest.getName());
if(qs != null && !qs.isCompleted()) // из тех, у кого взят квест
{
interested.add(pl);
}
}
if(interested.isEmpty())
{
continue;
}
toReward = interested.get(Rnd.get(interested.size()));
if(toReward == null)
{
toReward = killer;
}
}
}
if(toReward != null)
{
QuestState qs = toReward.getQuestState(quest.getName());
if(qs != null && !qs.isCompleted())
{
quest.notifyKill(this, qs);
}
}
}
}
}
}
catch(final Exception e)
{
e.printStackTrace();
}
// Distribute Exp and SP rewards to L2Player (including Summon owner) that hit the L2NpcInstance and to their Party members
FastMap<L2Player, RewardInfo> rewards = new FastMap<L2Player, RewardInfo>().setShared(true);
for(AggroInfo info : aggroList.values())
{
if(info.damage <= 1)
{
continue;
}
L2Character attacker = info.attacker;
if(attacker == null || !attacker.isPlayer())
{
continue;
}
L2Player player = attacker.getPlayer();
if(player != null)
{
RewardInfo reward = rewards.get(player);
if(reward == null)
{
rewards.put(player, new RewardInfo(player, info.damage));
}
else
{
reward.addDamage(info.damage);
}
}
}
for(FastMap.Entry<L2Player, RewardInfo> e = rewards.head(), end = rewards.tail(); e != null && (e = e.getNext()) != end && e != null;)
{
L2Player attacker = e.getKey();
RewardInfo reward = e.getValue();
if(attacker == null || attacker.isDead() || reward == null)
{
continue;
}
L2Party party = attacker.getParty();
int maxHp = getMaxHp();
if(party == null)
{
int damage = Math.min(reward._dmg, maxHp);
if(damage > 0)
{
double[] xpsp = calculateExpAndSp(attacker, attacker.getLevel(), damage);
double neededExp = attacker.calcStat(Stats.SOULS_CONSUME_EXP, 0, this, null); // Начисление душ камаэлянам
if(neededExp > 0 && xpsp[0] > neededExp)
{
broadcastPacket(new SpawnEmitter(this, attacker));
ThreadPoolManager.getInstance().scheduleGeneral(new SoulConsumeTask(attacker), 1000);
}
xpsp[0] = applyOverhit(killer, xpsp[0]);
xpsp = attacker.applyVitality(this, xpsp[0], xpsp[1], 1.0);
attacker.addExpAndSp((long) xpsp[0], (long) xpsp[1], false, true);
}
rewards.remove(attacker);
}
else
{