/** * This method is used to drop the CW from a monster.<br> * It drops the item on ground, and broadcast earthquake && red sky animations. * * @param attackable : The monster who dropped CW. * @param player : The player who killed the monster. */ private void dropFromMob(L2Attackable attackable, L2PcInstance player) { _isActivated = false; // get position int x = attackable.getX() + Rnd.get(-70, 70); int y = attackable.getY() + Rnd.get(-70, 70); int z = GeoData.getInstance().getHeight(x, y, attackable.getZ()); // create item and drop it _item = ItemTable.getInstance().createItem("CursedWeapon", _itemId, 1, player, attackable); _item.setDestroyProtected(true); _item.dropMe(attackable, x, y, z); // RedSky and Earthquake Broadcast.toAllOnlinePlayers(new ExRedSky(10)); Broadcast.toAllOnlinePlayers(new Earthquake(x, y, z, 14, 3)); _isDropped = true; SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S2_WAS_DROPPED_IN_THE_S1_REGION); sm.addZoneName(player.getX(), player.getY(), player.getZ()); sm.addItemName(_itemId); Broadcast.toAllOnlinePlayers(sm); }
/** * This method is used to drop the CW from player.<br> * It drops the item on ground, and reset player stats. * * @param killer : The player who killed CW owner. */ private void dropFromPlayer(L2Character killer) { _player.abortAttack(); // Prevent item from being removed by ItemsAutoDestroy _item.setDestroyProtected(true); _player.dropItem("DieDrop", _item, killer, true); _isActivated = false; _isDropped = true; _player.setKarma(_playerKarma); _player.setPkKills(_playerPkKills); _player.setCursedWeaponEquippedId(0); removeDemonicSkills(); // Cancel the daily timer. It will be reactivated when someone will pickup the weapon. cancelDailyTimerTask(); // Activate the "1h dropped CW" timer. _dropTimerTask = ThreadPoolManager.getInstance().scheduleGeneral(new DropTimerTask(), 3600000L); // Reset current stage to 1. _currentStage = 1; // Drop infos from database. removeFromDb(); SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S2_WAS_DROPPED_IN_THE_S1_REGION); sm.addZoneName(_player.getX(), _player.getY(), _player.getZ()); sm.addItemName(_itemId); Broadcast.toAllOnlinePlayers(sm); }
@Override public void useItem(L2Playable playable, ItemInstance item, boolean forceUse) { if (!(playable instanceof L2PcInstance)) return; final L2PcInstance activeChar = (L2PcInstance) playable; final ItemInstance weaponInst = activeChar.getActiveWeaponInstance(); final Weapon weaponItem = activeChar.getActiveWeaponItem(); final int itemId = item.getItemId(); // Check if bss can be used if (weaponInst == null || weaponItem == null || weaponItem.getSpiritShotCount() == 0) { if (!activeChar.getAutoSoulShot().contains(itemId)) activeChar.sendPacket(SystemMessageId.CANNOT_USE_SPIRITSHOTS); return; } // Check if bss is already active (it can be charged over SpiritShot) if (activeChar.isChargedShot(ShotType.BLESSED_SPIRITSHOT)) return; // Check for correct grade. if (weaponItem.getCrystalType() != item.getItem().getCrystalType()) { if (!activeChar.getAutoSoulShot().contains(itemId)) activeChar.sendPacket(SystemMessageId.SPIRITSHOTS_GRADE_MISMATCH); return; } // Consume bss if player has enough of them if (!activeChar.destroyItemWithoutTrace( "Consume", item.getObjectId(), weaponItem.getSpiritShotCount(), null, false)) { if (!activeChar.disableAutoShot(itemId)) activeChar.sendPacket(SystemMessageId.NOT_ENOUGH_SPIRITSHOTS); return; } final IntIntHolder[] skills = item.getItem().getSkills(); activeChar.sendPacket(SystemMessageId.ENABLED_SPIRITSHOT); activeChar.setChargedShot(ShotType.BLESSED_SPIRITSHOT, true); Broadcast.toSelfAndKnownPlayersInRadiusSq( activeChar, new MagicSkillUse(activeChar, activeChar, skills[0].getId(), 1, 0, 0), 360000); }
/** * Method used to send messages.<br> * * <ul> * <li>one is broadcasted to warn ppl CW is online. * <li>the other shows left timer for for CW owner (either in hours or minutes). * </ul> */ public void cursedOnLogin() { SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.S2_OWNER_HAS_LOGGED_INTO_THE_S1_REGION); msg.addZoneName(_player.getX(), _player.getY(), _player.getZ()); msg.addItemName(_player.getCursedWeaponEquippedId()); Broadcast.toAllOnlinePlayers(msg); int timeLeft = (int) (getTimeLeft() / 60000); if (timeLeft > 60) { msg = SystemMessage.getSystemMessage(SystemMessageId.S2_HOUR_OF_USAGE_TIME_ARE_LEFT_FOR_S1); msg.addItemName(_player.getCursedWeaponEquippedId()); msg.addNumber(Math.round(timeLeft / 60)); } else { msg = SystemMessage.getSystemMessage(SystemMessageId.S2_MINUTE_OF_USAGE_TIME_ARE_LEFT_FOR_S1); msg.addItemName(_player.getCursedWeaponEquippedId()); msg.addNumber(timeLeft); } _player.sendPacket(msg); }
public void activate(L2PcInstance player, ItemInstance item) { // if the player is mounted, attempt to unmount first and pick it if successful. if (player.isMounted() && !player.dismount()) { player.sendPacket( SystemMessage.getSystemMessage(SystemMessageId.FAILED_TO_PICKUP_S1) .addItemName(item.getItemId())); item.setDestroyProtected(true); player.dropItem("InvDrop", item, null, true); return; } _isActivated = true; // Hold player data. _player = player; _playerId = _player.getObjectId(); _playerKarma = _player.getKarma(); _playerPkKills = _player.getPkKills(); _item = item; // Generate a random number for next stage. _numberBeforeNextStage = Rnd.get((int) Math.round(_stageKills * 0.5), (int) Math.round(_stageKills * 1.5)); // Renew hungry time. _hungryTime = _durationLost * 60; // Activate the daily timer. _dailyTimerTask = ThreadPoolManager.getInstance() .scheduleGeneralAtFixedRate(new DailyTimerTask(), 60000L, 60000L); // Cancel the "1h dropped CW" timer. cancelDropTimerTask(); insertData(); // Change player stats _player.setCursedWeaponEquippedId(_itemId); _player.setKarma(9999999); _player.setPkKills(0); if (_player.isInParty()) _player.getParty().removePartyMember(_player, MessageType.Expelled); // Disable active toggles for (L2Effect effect : _player.getAllEffects()) { if (effect.getSkill().isToggle()) effect.exit(); } // Add CW skills giveDemonicSkills(); // Equip the weapon _player.useEquippableItem(_item, true); // Fully heal player _player.setCurrentHpMp(_player.getMaxHp(), _player.getMaxMp()); _player.setCurrentCp(_player.getMaxCp()); // Refresh player stats _player.broadcastUserInfo(); // _player.broadcastPacket(new SocialAction(_player, 17)); Broadcast.toAllOnlinePlayers( SystemMessage.getSystemMessage( SystemMessageId.THE_OWNER_OF_S2_HAS_APPEARED_IN_THE_S1_REGION) .addZoneName(_player.getX(), _player.getY(), _player.getZ()) .addItemName(_item.getItemId())); }
/** * 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; }