/** * 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; }
@Override protected final void writeImpl() { writeC(0x92); writeD(_activeChar.getObjectId()); writeD(_idTemplate + 1000000); writeS(_name); // name writeD(_isAttackable ? 1 : 0); writeD(_x); writeD(_y); writeD(_z); writeD(_heading); writeF(1.0); // movement multiplier writeF(1.0); // attack speed multiplier writeF(_collisionRadius); writeF(_collisionHeight); writeD((int) (_isAttackable ? _activeChar.getCurrentHp() : 0)); writeD(_isAttackable ? _activeChar.getMaxHp() : 0); writeD(0x01); // object type writeD(0x00); // special effects }
@Override public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon) { final QuestState qs = getQuestState(attacker, false); if ((qs != null) && qs.isCond(2)) { if (isSummon) { final NpcData data = NPC_DATA.get(npc.getId()); if ((qs.getMemoState() % data.memoStateMod) < data.memoStateValue) { final L2Summon pet = attacker.getPet(); if ((pet != null) && (pet.getControlObjectId() == qs.getInt("fluteObjectId"))) { final int hits = qs.getInt("hits") + 1; qs.set("hits", hits); if (hits < data.minHits) { if ((npc.getId() == TREE_OF_ABYSS) && (getRandom(100) < 2)) { npc.setTarget(attacker); npc.doCast(DRYAD_ROOT.getSkill()); } } else if (getRandom(100) < 2) { if (hasQuestItems(attacker, FAIRY_LEAF)) { npc.broadcastPacket( new NpcSay(npc, ChatType.NPC_GENERAL, NpcStringId.GIVE_ME_A_FAIRY_LEAF)); takeItems(attacker, FAIRY_LEAF, 1); qs.setMemoState(qs.getMemoState() + data.memoStateValue); qs.unset("hits"); playSound(attacker, QuestSound.ITEMSOUND_QUEST_MIDDLE); if (qs.getMemoState() == 15) { qs.setCond(3); } } } } } else { switch (getRandom(3)) { case 0: npc.broadcastPacket( new NpcSay(npc, ChatType.NPC_GENERAL, NpcStringId.WHY_DO_YOU_BOTHER_ME_AGAIN)); break; case 1: npc.broadcastPacket(new NpcSay(npc, ChatType.NPC_GENERAL, data.message)); break; case 2: npc.broadcastPacket( new NpcSay( npc, ChatType.NPC_GENERAL, NpcStringId.LEAVE_NOW_BEFORE_YOU_INCUR_THE_WRATH_OF_THE_GUARDIAN_GHOST)); break; } } } else if (getRandom(100) < 30) { npc.setTarget(attacker); npc.doCast(VICIOUS_POISON.getSkill()); } } else if ((npc.getCurrentHp() < (npc.getMaxHp() * 0.67)) && (getRandom(100) < 30)) { npc.setTarget(attacker); npc.doCast(VICIOUS_POISON.getSkill()); } return super.onAttack(npc, attacker, damage, isSummon); }
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); }