*
* @param lastAttacker The L2Character that has killed the L2Attackable
*/
public void doItemDrop(L2NpcTemplate npcTemplate, L2Character lastAttacker)
{
L2PcInstance player = null;
if (lastAttacker instanceof L2PcInstance) player = (L2PcInstance)lastAttacker;
else if (lastAttacker instanceof L2Summon) player = ((L2Summon)lastAttacker).getOwner();
if (player == null) return; // Don't drop anything if the last attacker or ownere isn't L2PcInstance
int levelModifier = calculateLevelModifierForDrop(player); // level modifier in %'s (will be subtracted from drop chance)
// Check the drop of a cursed weapon
if (levelModifier == 0 && player.getLevel() > 20) // Not deep blue mob
CursedWeaponsManager.getInstance().checkDrop(this, player);
// now throw all categorized drops and handle spoil.
for(L2DropCategory cat:npcTemplate.getDropData())
{
RewardItem item = null;
if (cat.isSweep())
{
// according to sh1ny, seeded mobs CAN be spoiled and swept.
if ( isSpoil()/* && !isSeeded() */)
{
FastList<RewardItem> sweepList = new FastList<RewardItem>();
for(L2DropData drop: cat.getAllDrops() )
{
item = calculateRewardItem(player, drop, levelModifier, true);
if (item == null) continue;
if (Config.DEBUG) _log.fine("Item id to spoil: " + item.getItemId() + " amount: " + item.getCount());
sweepList.add(item);
}
// Set the table _sweepItems of this L2Attackable
if (!sweepList.isEmpty())
_sweepItems = sweepList.toArray(new RewardItem[sweepList.size()]);
}
}
else
{
if (isSeeded())
{
L2DropData drop = cat.dropSeedAllowedDropsOnly();
if(drop == null)
continue;
item = calculateRewardItem(player, drop, levelModifier, false);
}
else
{
item = calculateCategorizedRewardItem(player, cat, levelModifier);
}
if (item != null)
{
if (Config.DEBUG) _log.fine("Item id to drop: " + item.getItemId() + " amount: " + item.getCount());
// Check if the autoLoot mode is active
if (Config.AUTO_LOOT) player.doAutoLoot(this, item); // Give this or these Item(s) to the L2PcInstance that has killed the L2Attackable
else DropItem(player, item); // drop the item on the ground
// Broadcast message if RaidBoss was defeated
if(this instanceof L2RaidBossInstance)
{
SystemMessage sm;
sm = new SystemMessage(SystemMessageId.S1_DIED_DROPPED_S3_S2);
sm.addString(getName());
sm.addItemName(item.getItemId());
sm.addNumber(item.getCount());
broadcastPacket(sm);
}
}
}
}
// Apply Special Item drop with rnd qty for champions
if (Config.L2JMOD_CHAMPION_ENABLE && isChampion() && (player.getLevel() <= getLevel()) && Config.L2JMOD_CHAMPION_REWARD > 0 && (Rnd.get(100) < Config.L2JMOD_CHAMPION_REWARD))
{
int champqty = Rnd.get(Config.L2JMOD_CHAMPION_REWARD_QTY);
champqty++; //quantity should actually vary between 1 and whatever admin specified as max, inclusive.
RewardItem item = new RewardItem(Config.L2JMOD_CHAMPION_REWARD_ID,champqty);
if (Config.AUTO_LOOT) player.addItem("ChampionLoot", item.getItemId(), item.getCount(), this, true); // Give this or these Item(s) to the L2PcInstance that has killed the L2Attackable
else DropItem(player, item);
}
//Instant Item Drop :>
double rateHp = getStat().calcStat(Stats.MAX_HP , 1, this, null);
if (rateHp <= 1 && String.valueOf(npcTemplate.type).contentEquals("L2Monster")) //only L2Monster with <= 1x HP can drop herbs
{
boolean _hp = false;
boolean _mp = false;
boolean _spec = false;
//ptk - patk type enhance
int random = Rnd.get(1000); // note *10
if ((random < Config.RATE_DROP_SPECIAL_HERBS) && !_spec) // && !_spec useless yet
{
RewardItem item = new RewardItem(8612, 1); // Herb of Warrior
if (Config.AUTO_LOOT && Config.AUTO_LOOT_HERBS) player.addItem("Loot", item.getItemId(), item.getCount(), this, true);
else DropItem(player, item);
_spec = true;
}
else for (int i = 0; i < 3; i++)
{
random = Rnd.get(100);
if (random < Config.RATE_DROP_COMMON_HERBS)
{
RewardItem item = null;
if (i == 0) item = new RewardItem(8606, 1); // Herb of Power
if (i == 1) item = new RewardItem(8608, 1); // Herb of Atk. Spd.
if (i == 2) item = new RewardItem(8610, 1); // Herb of Critical Attack
if (Config.AUTO_LOOT && Config.AUTO_LOOT_HERBS) player.addItem("Loot", item.getItemId(), item.getCount(), this, true);
else DropItem(player, item);
break;
}
}
//mtk - matk type enhance
random = Rnd.get(1000); // note *10
if ((random < Config.RATE_DROP_SPECIAL_HERBS) && !_spec)
{
RewardItem item = new RewardItem(8613, 1); // Herb of Mystic
if (Config.AUTO_LOOT && Config.AUTO_LOOT_HERBS) player.addItem("Loot", item.getItemId(), item.getCount(), this, true);
else DropItem(player, item);
_spec = true;
}
else for (int i = 0; i < 2; i++)
{
random = Rnd.get(100);
if (random < Config.RATE_DROP_COMMON_HERBS)
{
RewardItem item = null;
if (i == 0) item = new RewardItem(8607, 1); // Herb of Magic
if (i == 1) item = new RewardItem(8609, 1); // Herb of Casting Speed
if (Config.AUTO_LOOT && Config.AUTO_LOOT_HERBS) player.addItem("Loot", item.getItemId(), item.getCount(), this, true);
else DropItem(player, item);
break;
}
}
//hp+mp type
random = Rnd.get(1000); // note *10
if ((random < Config.RATE_DROP_SPECIAL_HERBS) && !_spec)
{
RewardItem item = new RewardItem(8614, 1); // Herb of Recovery
if (Config.AUTO_LOOT && Config.AUTO_LOOT_HERBS) player.addItem("Loot", item.getItemId(), item.getCount(), this, true);
else DropItem(player, item);
_mp = true;
_hp = true;
_spec = true;
}
//hp - restore hp type
if (!_hp)
{
random = Rnd.get(100);
if (random < Config.RATE_DROP_MP_HP_HERBS)
{
RewardItem item = new RewardItem(8600, 1); // Herb of Life
if (Config.AUTO_LOOT && Config.AUTO_LOOT_HERBS) player.addItem("Loot", item.getItemId(), item.getCount(), this, true);
else DropItem(player, item);
_hp = true;
}
}
if (!_hp)
{
random = Rnd.get(100);
if (random < Config.RATE_DROP_GREATER_HERBS)
{
RewardItem item = new RewardItem(8601, 1); // Greater Herb of Life
if (Config.AUTO_LOOT && Config.AUTO_LOOT_HERBS) player.addItem("Loot", item.getItemId(), item.getCount(), this, true);
else DropItem(player, item);
_hp = true;
}
}
if (!_hp)
{
random = Rnd.get(1000); // note *10
if (random < Config.RATE_DROP_SUPERIOR_HERBS)
{
RewardItem item = new RewardItem(8602, 1); // Superior Herb of Life
if (Config.AUTO_LOOT && Config.AUTO_LOOT_HERBS) player.addItem("Loot", item.getItemId(), item.getCount(), this, true);
else DropItem(player, item);
}
}
//mp - restore mp type
if (!_mp)
{
random = Rnd.get(100);
if (random < Config.RATE_DROP_MP_HP_HERBS)
{
RewardItem item = new RewardItem(8603, 1); // Herb of Manna
if (Config.AUTO_LOOT && Config.AUTO_LOOT_HERBS) player.addItem("Loot", item.getItemId(), item.getCount(), this, true);
else DropItem(player, item);
_mp = true;
}
}
if (!_mp)
{
random = Rnd.get(100);
if (random < Config.RATE_DROP_GREATER_HERBS)
{
RewardItem item = new RewardItem(8604, 1); // Greater Herb of Mana
if (Config.AUTO_LOOT && Config.AUTO_LOOT_HERBS) player.addItem("Loot", item.getItemId(), item.getCount(), this, true);
else DropItem(player, item);
_mp = true;
}
}
if (!_mp)
{
random = Rnd.get(1000); // note *10
if (random < Config.RATE_DROP_SUPERIOR_HERBS)
{
RewardItem item = new RewardItem(8605, 1); // Superior Herb of Mana
if (Config.AUTO_LOOT && Config.AUTO_LOOT_HERBS) player.addItem("Loot", item.getItemId(), item.getCount(), this, true);
else DropItem(player, item);
}
}
// speed enhance type
random = Rnd.get(100);
if (random < Config.RATE_DROP_COMMON_HERBS)
{
RewardItem item = new RewardItem(8611, 1); // Herb of Speed
if (Config.AUTO_LOOT && Config.AUTO_LOOT_HERBS) player.addItem("Loot", item.getItemId(), item.getCount(), this, true);
else DropItem(player, item);
}
}
}