Gladicek

Untitled

Aug 21st, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.99 KB | None | 0 0
  1.     private class WatcherTask implements Runnable
  2.     {
  3.         L2Npc npc = null;
  4.        
  5.         protected WatcherTask()
  6.         {
  7.             npc = L2Npc.this;
  8.         }
  9.        
  10.         public void run()
  11.         {
  12.             if (npc == null)
  13.                 return;
  14.             if (npc.isDead())
  15.                 npc.stopWatcherTask();
  16.            
  17.             // Get all characters in range 900 (should be enough)
  18.             Collection<L2PcInstance> knowList = npc.getKnownList().getKnownPlayersInRadius(900);
  19.             // Get list of known and triggered already players
  20.             FastList<L2PcInstance> watcherList = npc.getWatcherList();
  21.            
  22.             // Check if all is ok with our knowlist
  23.             if (knowList == null)
  24.                 return;
  25.            
  26.             // If knowlist is empty we can clear watchlist also if its not empty
  27.             if (knowList.isEmpty())
  28.             {
  29.                 if (!watcherList.isEmpty())
  30.                     watcherList.clear();
  31.                
  32.                 return;
  33.             }
  34.            
  35.             // First verify if player on our list is still in range
  36.             for (L2PcInstance player : watcherList)
  37.             {
  38.                 if (player == null)
  39.                     continue;
  40.                 if (!knowList.contains(player))
  41.                     watcherList.remove(player);
  42.             }
  43.            
  44.             // Now check know list for new objects
  45.             for (L2Character character : knowList)
  46.             {
  47.                 if (character == null || character.isDead())
  48.                     continue;
  49.                
  50.                 final L2PcInstance player = character.getActingPlayer();
  51.                 if (player != null)
  52.                 {
  53.                     // Player can be invisible
  54.                     if (player.inObserverMode() || player.getAppearance().getInvisible())
  55.                         continue;
  56.                     // Check if player is on our list (was triggered already)
  57.                     if (!watcherList.contains(player))
  58.                     {
  59.                         // Check if we really 'see' our target
  60.                         if (GeoData.getInstance().canSeeTarget(npc, player))
  61.                         {
  62.                             // Add player to list - we need trigger quests only once
  63.                             watcherList.add(player);
  64.                            
  65.                             // Notify quests
  66.                             if (getTemplate().getEventQuests(Quest.QuestEventType.ON_PLAYER_SEE) != null)
  67.                                 for (Quest quest : getTemplate().getEventQuests(Quest.QuestEventType.ON_PLAYER_SEE))
  68.                                     quest.notifyPlayerSee(npc, player);
  69.                         }
  70.                     }
  71.                 }
  72.             }
Advertisement
Add Comment
Please, Sign In to add comment