Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private class WatcherTask implements Runnable
- {
- L2Npc npc = null;
- protected WatcherTask()
- {
- npc = L2Npc.this;
- }
- public void run()
- {
- if (npc == null)
- return;
- if (npc.isDead())
- npc.stopWatcherTask();
- // Get all characters in range 900 (should be enough)
- Collection<L2PcInstance> knowList = npc.getKnownList().getKnownPlayersInRadius(900);
- // Get list of known and triggered already players
- FastList<L2PcInstance> watcherList = npc.getWatcherList();
- // Check if all is ok with our knowlist
- if (knowList == null)
- return;
- // If knowlist is empty we can clear watchlist also if its not empty
- if (knowList.isEmpty())
- {
- if (!watcherList.isEmpty())
- watcherList.clear();
- return;
- }
- // First verify if player on our list is still in range
- for (L2PcInstance player : watcherList)
- {
- if (player == null)
- continue;
- if (!knowList.contains(player))
- watcherList.remove(player);
- }
- // Now check know list for new objects
- for (L2Character character : knowList)
- {
- if (character == null || character.isDead())
- continue;
- final L2PcInstance player = character.getActingPlayer();
- if (player != null)
- {
- // Player can be invisible
- if (player.inObserverMode() || player.getAppearance().getInvisible())
- continue;
- // Check if player is on our list (was triggered already)
- if (!watcherList.contains(player))
- {
- // Check if we really 'see' our target
- if (GeoData.getInstance().canSeeTarget(npc, player))
- {
- // Add player to list - we need trigger quests only once
- watcherList.add(player);
- // Notify quests
- if (getTemplate().getEventQuests(Quest.QuestEventType.ON_PLAYER_SEE) != null)
- for (Quest quest : getTemplate().getEventQuests(Quest.QuestEventType.ON_PLAYER_SEE))
- quest.notifyPlayerSee(npc, player);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment