// Init some more info now Random _rnd = new Random(); int dice = _rnd.nextInt(100); int crystalId = 0;+ int crystalObjectId = 0; int oldCrystalId = 0; int newCrystalId = 0; int crystalOffset = 0; int crystalsCount = 0; SystemMessage sm = new SystemMessage(614); success = false; // Now we got four choices: // 1- The Monster level is too low for the crystal. Nothing happens. // 2- Everything is correct, but it failed. Nothing happens. (57.5%) // 3- Everything is correct, but it failed. The crystal scatters. A sound event is played. (10%) // 4- Everything is correct, the crystal level up. A sound event is played. (32.5%) List<L2PcInstance> players = new FastList<L2PcInstance>(); if (levelPartyCrystals && killer.isInParty()) { players = killer.getParty().getPartyMembers(); } else { players.add(killer); } for (L2PcInstance player : players) { // Check how many soul crystals the player has in his inventory and which soul crystal he has canIncreaseCrystal = true; success = true; final L2ItemInstance[] inv = player.getInventory().getItems(); for (int index = 0; index < inv.length; index++) { final L2ItemInstance item = inv[index]; if ( (((item.getItemId() >= _REDCRYSTAL_OFFSET) || (item.getItemId() >= _GREENCRYSTAL_OFFSET) || (item.getItemId() >= _BLUECRYSTAL_OFFSET)) && ((item.getItemId() <= _REDCRYSTAL_OFFSET+10) || (item.getItemId() <= _GREENCRYSTAL_OFFSET+10) || (item.getItemId() <= _BLUECRYSTAL_OFFSET+10))) || (item.getItemId() == _REDCRYSTAL_LVL11) || (item.getItemId() == _BLUECRYSTAL_LVL11) || (item.getItemId() == _GREENCRYSTAL_LVL11) || (item.getItemId() == _REDCRYSTAL_LVL12) || (item.getItemId() == _BLUECRYSTAL_LVL12) || (item.getItemId() == _GREENCRYSTAL_LVL12) ) { crystalsCount++; if (crystalsCount > 1) { success = false; break; // break the "findCrystals" loop, as we already found more than one crystal. } crystalId = item.getItemId();+ crystalObjectId = item.getObjectId(); crystalOffset = 0; for (int crystalLevel = 0; crystalLevel <= _MAX_CRYSTALS_LEVEL; crystalLevel++) { // Get a crystal offset to calculate the new crystal ID if (crystalId == (_REDCRYSTAL_OFFSET + crystalLevel)) crystalOffset = _REDCRYSTAL_OFFSET; if (crystalId == (_GREENCRYSTAL_OFFSET + crystalLevel)) crystalOffset = _GREENCRYSTAL_OFFSET; if (crystalId == (_BLUECRYSTAL_OFFSET + crystalLevel)) crystalOffset = _BLUECRYSTAL_OFFSET; if (crystalLevel > 9) { if (crystalId == (_REDCRYSTAL_OFFSET+10)) crystalOffset = _REDCRYSTAL_LVL11 - (crystalLevel + 1); if (crystalId == (_GREENCRYSTAL_OFFSET+10)) crystalOffset = _GREENCRYSTAL_LVL11 - (crystalLevel + 1); if (crystalId == (_BLUECRYSTAL_OFFSET+10)) crystalOffset = _BLUECRYSTAL_LVL11 - (crystalLevel + 1); if (crystalId == (_REDCRYSTAL_LVL11)) crystalOffset = _REDCRYSTAL_LVL12 - (crystalLevel + 1); if (crystalId == (_GREENCRYSTAL_LVL11)) crystalOffset = _GREENCRYSTAL_LVL12 - (crystalLevel + 1); if (crystalId == (_BLUECRYSTAL_LVL11)) crystalOffset = _BLUECRYSTAL_LVL12 - (crystalLevel + 1); } // If the crystal level is way too high for this mob, say that we can't increase it if ((crystalLevel >= minCrystalLevel) && (crystalLevel < maxCrystalLevel)) { canIncreaseCrystal = true; } else { canIncreaseCrystal = false; } // Define crystals' IDs based on the crystalOffset found if (crystalOffset > 0) { oldCrystalId = crystalId; newCrystalId = (crystalOffset + crystalLevel) + 1; break; // Break the "findLevel" loop, as we already got the crystal Level. } } } } // The player has no crystals at all, reset our control vars and skip this player if (crystalsCount < 1) { oldCrystalId = 0; newCrystalId = 0; crystalOffset = 0; crystalsCount = 0; continue; // The player doesn't have any crystals with him. Get to the next player. } // The player has more than one soul crystal with him, the crystal resonates and we skip this player if (!success) { sm.addString("The soul crystal resonated."); player.sendPacket(new PlaySound("ItemSound2.broken_key")); player.sendPacket(sm); oldCrystalId = 0; newCrystalId = 0; crystalOffset = 0; crystalsCount = 0; continue; // The player failed to increase his crystal as he has more than one crystal. } // The soul crystal stage of the player is way too high, refuse to increase it if (!canIncreaseCrystal) { sm.addString("The soul crystal has refused to absorb the soul."); player.sendPacket(sm); oldCrystalId = 0; newCrystalId = 0; crystalOffset = 0; crystalsCount = 0; continue; // The player failed to increase his crystal cuz mob is wrong for his crystal level. } // If the killer succeeds or it is a boss mob, level up the crystal if ((dice < _LEVEL_CHANCE) || levelPartyCrystals) { // Remove old crystal from the killer's inventory- final L2ItemInstance oldCrystal = player.getInventory().destroyItem("Absorb", oldCrystalId, 1, player, this);+ final L2ItemInstance oldCrystal = player.getInventory().destroyItem("Absorb", crystalObjectId, 1, player, this); if (oldCrystal != null) { // Add new crystal to the killer's inventory player.getInventory().addItem("Absorb", newCrystalId, 1, player, this); final SystemMessage sms = new SystemMessage(SystemMessage.EARNED_ITEM); // Send a sound event and text message to the player player.sendPacket(new PlaySound("ItemSound.quest_itemget")); sms.addItemName(newCrystalId); player.sendPacket(sms); // Send Server->Client packets to notify the killer and update his Inventory } player.sendPacket(new ItemList(player, false)); } else if ((dice >= 100.0 - _BREAK_CHANCE) && !levelPartyCrystals) { // Remove old crystal from the killer's inventory- final L2ItemInstance oldCrystal = player.getInventory().destroyItem("Absorb", oldCrystalId, 1, player, this);+ final L2ItemInstance oldCrystal = player.getInventory().destroyItem("Absorb", crystalObjectId, 1, player, this); killer.sendPacket(new PlaySound("ItemSound3.sys_enchant_failed")); //sm.addString("The soul crystal scattered itself."); killer.sendPacket(sm); _absorbed = false; _absorbersList = null; return; } else { sm.addString("The soul crystal has failed to absorb the soul."); player.sendPacket(sm); } }