/** * That method drops current alliance and retrograde badge.<br> * If any Varka quest is in progress, it stops the quest (and drop all related qItems) : * * @param player The player to check. */ private static void testKetraDemote(L2PcInstance player) { if (player.isAlliedWithKetra()) { // Drop the alliance (old friends become aggro). player.setAllianceWithVarkaKetra(0); final PcInventory inventory = player.getInventory(); // Drop by 1 the level of that alliance (symbolized by a quest item). for (int i = 7215; i >= 7211; i--) { L2ItemInstance item = inventory.getItemByItemId(i); if (item != null) { // Destroy the badge. player.destroyItemByItemId("Quest", i, item.getCount(), player, true); // Badge lvl 1 ; no addition of badge of lower level. if (i != 7211) player.addItem("Quest", i - 1, 1, player, true); break; } } for (String mission : ketraMissions) { QuestState pst = player.getQuestState(mission); if (pst != null) pst.exitQuest(true); } } }
/** * This method is used to destroy a CW.<br> * It manages following states : * * <ul> * <li><u>item on a online player</u> : drops the CW from inventory, and set back ancient * pk/karma values. * <li><u>item on a offline player</u> : make SQL operations in order to drop item from * inventory. * <li><u>item on ground</u> : destroys the item directly. * </ul> * * For all cases, a message is broadcasted, and the different states are reinitialized. */ public void endOfLife() { if (_isActivated) { // Player is online ; unequip weapon && destroy it. if (_player != null && _player.isOnline()) { _log.info(_name + " being removed online."); _player.abortAttack(); _player.setKarma(_playerKarma); _player.setPkKills(_playerPkKills); _player.setCursedWeaponEquippedId(0); removeDemonicSkills(); // Unequip && remove. _player.useEquippableItem(_item, true); _player.destroyItemByItemId("CW", _itemId, 1, _player, false); _player.broadcastUserInfo(); _player.store(); } // Player is offline ; make only SQL operations. else { _log.info(_name + " being removed offline."); try (Connection con = L2DatabaseFactory.getInstance().getConnection()) { // Delete the item PreparedStatement statement = con.prepareStatement("DELETE FROM items WHERE owner_id=? AND item_id=?"); statement.setInt(1, _playerId); statement.setInt(2, _itemId); if (statement.executeUpdate() != 1) _log.warning("Error while deleting itemId " + _itemId + " from userId " + _playerId); statement.close(); // Restore the karma and PK kills. statement = con.prepareStatement("UPDATE characters SET karma=?, pkkills=? WHERE obj_id=?"); statement.setInt(1, _playerKarma); statement.setInt(2, _playerPkKills); statement.setInt(3, _playerId); if (statement.executeUpdate() != 1) _log.warning("Error while updating karma & pkkills for userId " + _playerId); statement.close(); } catch (Exception e) { _log.log(Level.WARNING, "Could not delete : " + e.getMessage(), e); } } } else { // This CW is in the inventory of someone who has another cursed weapon equipped. if (_player != null && _player.getInventory().getItemByItemId(_itemId) != null) { _player.destroyItemByItemId("CW", _itemId, 1, _player, false); _log.info(_name + " item has been assimilated."); } // This CW is on the ground. else if (_item != null) { _item.decayMe(); _log.info(_name + " item has been removed from world."); } } // Drop tasks. cancelDailyTimerTask(); cancelOverallTimerTask(); cancelDropTimerTask(); // Delete infos from table, if any. removeFromDb(); // Inform all ppl. Broadcast.toAllOnlinePlayers( SystemMessage.getSystemMessage(SystemMessageId.S1_HAS_DISAPPEARED).addItemName(_itemId)); // Reset state. _player = null; _item = null; _isActivated = false; _isDropped = false; _nbKills = 0; _currentStage = 1; _numberBeforeNextStage = 0; _hungryTime = 0; _endTime = 0; _playerId = 0; _playerKarma = 0; _playerPkKills = 0; }