/** * Starts the participation of the TvTEvent<br> * 1. Get L2NpcTemplate by Config.TVT_EVENT_PARTICIPATION_NPC_ID<br> * 2. Try to spawn a new npc of it<br> * <br> * * @return boolean: true if success, otherwise false<br> */ public static boolean startParticipation() { try { _npcSpawn = new L2Spawn(Config.TVT_EVENT_PARTICIPATION_NPC_ID); _npcSpawn.setX(Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES[0]); _npcSpawn.setY(Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES[1]); _npcSpawn.setZ(Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES[2]); _npcSpawn.setAmount(1); _npcSpawn.setHeading(Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES[3]); _npcSpawn.setRespawnDelay(1); // later no need to delete spawn from db, we don't store it (false) SpawnTable.getInstance().addNewSpawn(_npcSpawn, false); _npcSpawn.init(); _lastNpcSpawn = _npcSpawn.getLastSpawn(); _lastNpcSpawn.setCurrentHp(_lastNpcSpawn.getMaxHp()); _lastNpcSpawn.setTitle("TvT Event Participation"); _lastNpcSpawn.isAggressive(); _lastNpcSpawn.decayMe(); _lastNpcSpawn.spawnMe( _npcSpawn.getLastSpawn().getX(), _npcSpawn.getLastSpawn().getY(), _npcSpawn.getLastSpawn().getZ()); _lastNpcSpawn.broadcastPacket(new MagicSkillUse(_lastNpcSpawn, _lastNpcSpawn, 1034, 1, 1, 1)); } catch (Exception e) { _log.log( Level.WARNING, "TvTEventEngine[TvTEvent.startParticipation()]: exception: " + e.getMessage(), e); return false; } setState(EventState.PARTICIPATING); EventDispatcher.getInstance().notifyEventAsync(new OnTvTEventRegistrationStart()); return true; }
/** UnSpawns the TvTEvent npc */ private static void unSpawnNpc() { // Delete the npc _lastNpcSpawn.deleteMe(); SpawnTable.getInstance().deleteSpawn(_lastNpcSpawn.getSpawn(), false); // Stop respawning of the npc _npcSpawn.stopRespawn(); _npcSpawn = null; _lastNpcSpawn = null; }
@Override public boolean doDie(L2Character killer) { if (getCastle().getSiege().isInProgress()) { getCastle().getSiege().killedCT(this); if ((_guards != null) && !_guards.isEmpty()) { for (L2Spawn spawn : _guards) { try { spawn.stopRespawn(); // spawn.getLastSpawn().doDie(spawn.getLastSpawn()); } catch (Exception e) { _log.log(Level.WARNING, "Error at L2ControlTowerInstance", e); } } _guards.clear(); } } return super.doDie(killer); }
public static void sendNpcView(L2PcInstance activeChar, L2Npc npc) { final NpcHtmlMessage html = new NpcHtmlMessage(); html.setFile(activeChar.getHtmlPrefix(), "html/mods/NpcView/Info.htm"); html.replace("%name%", npc.getName()); html.replace( "%hpGauge%", HtmlUtil.getHpGauge(250, (long) npc.getCurrentHp(), npc.getMaxHp(), false)); html.replace( "%mpGauge%", HtmlUtil.getMpGauge(250, (long) npc.getCurrentMp(), npc.getMaxMp(), false)); final L2Spawn npcSpawn = npc.getSpawn(); if ((npcSpawn == null) || (npcSpawn.getRespawnMinDelay() == 0)) { html.replace("%respawn%", "None"); } else { TimeUnit timeUnit = TimeUnit.MILLISECONDS; long min = Long.MAX_VALUE; for (TimeUnit tu : TimeUnit.values()) { final long minTimeFromMillis = tu.convert(npcSpawn.getRespawnMinDelay(), TimeUnit.MILLISECONDS); final long maxTimeFromMillis = tu.convert(npcSpawn.getRespawnMaxDelay(), TimeUnit.MILLISECONDS); if ((TimeUnit.MILLISECONDS.convert(minTimeFromMillis, tu) == npcSpawn.getRespawnMinDelay()) && (TimeUnit.MILLISECONDS.convert(maxTimeFromMillis, tu) == npcSpawn.getRespawnMaxDelay())) { if (min > minTimeFromMillis) { min = minTimeFromMillis; timeUnit = tu; } } } final long minRespawnDelay = timeUnit.convert(npcSpawn.getRespawnMinDelay(), TimeUnit.MILLISECONDS); final long maxRespawnDelay = timeUnit.convert(npcSpawn.getRespawnMaxDelay(), TimeUnit.MILLISECONDS); final String timeUnitName = timeUnit.name().charAt(0) + timeUnit.name().toLowerCase().substring(1); if (npcSpawn.hasRespawnRandom()) { html.replace("%respawn%", minRespawnDelay + "-" + maxRespawnDelay + " " + timeUnitName); } else { html.replace("%respawn%", minRespawnDelay + " " + timeUnitName); } } html.replace("%atktype%", Util.capitalizeFirst(npc.getAttackType().name().toLowerCase())); html.replace("%atkrange%", npc.getStat().getPhysicalAttackRange()); html.replace("%patk%", (int) npc.getPAtk(activeChar)); html.replace("%pdef%", (int) npc.getPDef(activeChar)); html.replace("%matk%", (int) npc.getMAtk(activeChar, null)); html.replace("%mdef%", (int) npc.getMDef(activeChar, null)); html.replace("%atkspd%", npc.getPAtkSpd()); html.replace("%castspd%", npc.getMAtkSpd()); html.replace("%critrate%", npc.getStat().getCriticalHit(activeChar, null)); html.replace("%evasion%", npc.getEvasionRate(activeChar)); html.replace("%accuracy%", npc.getStat().getAccuracy()); html.replace("%speed%", (int) npc.getStat().getMoveSpeed()); html.replace("%attributeatktype%", Elementals.getElementName(npc.getStat().getAttackElement())); html.replace( "%attributeatkvalue%", npc.getStat().getAttackElementValue(npc.getStat().getAttackElement())); html.replace("%attributefire%", npc.getStat().getDefenseElementValue(Elementals.FIRE)); html.replace("%attributewater%", npc.getStat().getDefenseElementValue(Elementals.WATER)); html.replace("%attributewind%", npc.getStat().getDefenseElementValue(Elementals.WIND)); html.replace("%attributeearth%", npc.getStat().getDefenseElementValue(Elementals.EARTH)); html.replace("%attributedark%", npc.getStat().getDefenseElementValue(Elementals.DARK)); html.replace("%attributeholy%", npc.getStat().getDefenseElementValue(Elementals.HOLY)); html.replace("%dropListButtons%", getDropListButtons(npc)); activeChar.sendPacket(html); }