Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.49 KB | None | 0 0
  1. /*
  2.  * Copyright (C) 2004-2013 L2J Server
  3.  *
  4.  * This file is part of L2J Server.
  5.  *
  6.  * L2J Server is free software: you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation, either version 3 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * L2J Server is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14.  * General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18.  */
  19. package com.l2jserver.gameserver.model.actor.knownlist;
  20.  
  21. import java.util.Collection;
  22. import java.util.List;
  23. import java.util.concurrent.ScheduledFuture;
  24.  
  25. import com.l2jserver.gameserver.ThreadPoolManager;
  26. import com.l2jserver.gameserver.ai.CtrlIntention;
  27. import com.l2jserver.gameserver.instancemanager.WalkingManager;
  28. import com.l2jserver.gameserver.model.L2Object;
  29. import com.l2jserver.gameserver.model.actor.L2Attackable;
  30. import com.l2jserver.gameserver.model.actor.L2Character;
  31. import com.l2jserver.gameserver.model.actor.L2Npc;
  32. import com.l2jserver.gameserver.model.actor.instance.L2FestivalGuideInstance;
  33. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  34. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  35. import com.l2jserver.gameserver.model.quest.Quest;
  36.  
  37. public class NpcKnownList extends CharKnownList
  38. {
  39.     private ScheduledFuture<?> _trackingTask = null;
  40.  
  41.     public NpcKnownList(L2Npc activeChar)
  42.     {
  43.         super(activeChar);
  44.     }
  45.  
  46.     @Override
  47.     public boolean addKnownObject(L2Object object)
  48.     {
  49.         if (!super.addKnownObject(object))
  50.         {
  51.             return false;
  52.         }
  53.  
  54.         if (getActiveObject().isNpc() && (object instanceof L2Character))
  55.         {
  56.             final L2Npc npc = (L2Npc) getActiveObject();
  57.             final List<Quest> quests = npc.getTemplate().getEventQuests(Quest.QuestEventType.ON_SEE_CREATURE);
  58.             if (quests != null)
  59.             {
  60.                 for (Quest quest : quests)
  61.                 {
  62.                     quest.notifySeeCreature(npc, (L2Character) object, object.isSummon());
  63.                 }
  64.             }
  65.         }
  66.         return true;
  67.     }
  68.  
  69.     @Override
  70.     public L2Npc getActiveChar()
  71.     {
  72.         return (L2Npc) super.getActiveChar();
  73.     }
  74.  
  75.     @Override
  76.     public int getDistanceToForgetObject(L2Object object)
  77.     {
  78.         return 2 * getDistanceToWatchObject(object);
  79.     }
  80.  
  81.     @Override
  82.     public int getDistanceToWatchObject(L2Object object)
  83.     {
  84.        
  85.         if (!(object instanceof L2Character))
  86.         {
  87.             return 0;
  88.         }
  89.  
  90.         if (object instanceof L2FestivalGuideInstance)
  91.         {
  92.             return 4000;
  93.         }
  94.  
  95.         if (object.isPlayable())
  96.         {
  97.             return 1500;
  98.         }
  99.  
  100.         if (object instanceof L2MonsterInstance)
  101.         {
  102.  
  103.             return 1500;
  104.  
  105.         }
  106.  
  107.         return 500;
  108.     }
  109.  
  110.     // Support for Walking monsters aggro
  111.     public void startTrackingTask()
  112.     {
  113.         if ((_trackingTask == null) && (getActiveChar().getAggroRange() > 0))
  114.         {
  115.             _trackingTask = ThreadPoolManager.getInstance().scheduleAiAtFixedRate(new TrackingTask(), 2000, 2000);
  116.         }
  117.     }
  118.  
  119.     // Support for Walking monsters aggro
  120.     public void stopTrackingTask()
  121.     {
  122.         if (_trackingTask != null)
  123.         {
  124.             _trackingTask.cancel(true);
  125.             _trackingTask = null;
  126.         }
  127.     }
  128.  
  129.     // Support for Walking monsters aggro
  130.     protected class TrackingTask implements Runnable
  131.     {
  132.         @Override
  133.         public void run()
  134.         {
  135.             if (getActiveChar() instanceof L2Attackable)
  136.             {
  137.                 final L2Attackable monster = (L2Attackable) getActiveChar();
  138.                 if (monster.getAI().getIntention() == CtrlIntention.AI_INTENTION_MOVE_TO)
  139.                 {
  140.                     final Collection<L2PcInstance> players = getKnownPlayers().values();
  141.                     if (players != null)
  142.                     {
  143.                         for (L2PcInstance pl : players)
  144.                         {
  145.                             if (!pl.isDead() && !pl.isInvul() && pl.isInsideRadius(monster, monster.getAggroRange(), true, false))
  146.                             {
  147.                                 if (pl.isTeam1() && monster.getClan().equals("Team2"))
  148.                                 {
  149.                                    
  150.                                     // Send aggroRangeEnter
  151.                                     if (monster.getHating(pl) == 0)
  152.                                     {
  153.                                         monster.addDamageHate(pl, 0, 0);
  154.                                     }
  155.  
  156.                                     // Skip attack for other targets, if one is already chosen for attack
  157.                                     if ((monster.getAI().getIntention() != CtrlIntention.AI_INTENTION_ATTACK) && !monster.isCoreAIDisabled())
  158.                                     {
  159.                                         WalkingManager.getInstance().stopMoving(getActiveChar(), false, true);
  160.                                         monster.addDamageHate(pl, 0, 100);
  161.                                         monster.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, pl, null);
  162.                                     }
  163.  
  164.                                 }
  165.                                 if (pl.isTeam2() && monster.getClan().equals("Team1"))
  166.                                 {
  167.                                    
  168.                                     // Send aggroRangeEnter
  169.                                     if (monster.getHating(pl) == 0)
  170.                                     {
  171.                                         monster.addDamageHate(pl, 0, 0);
  172.                                     }
  173.  
  174.                                     // Skip attack for other targets, if one is already chosen for attack
  175.                                     if ((monster.getAI().getIntention() != CtrlIntention.AI_INTENTION_ATTACK) && !monster.isCoreAIDisabled())
  176.                                     {
  177.                                         WalkingManager.getInstance().stopMoving(getActiveChar(), false, true);
  178.                                         monster.addDamageHate(pl, 0, 100);
  179.                                         monster.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, pl, null);
  180.                                     }
  181.  
  182.                                 }
  183.                             }
  184.                         }
  185.                     }
  186.                 }
  187.             }
  188.             if (getActiveChar() instanceof L2Attackable)
  189.             {
  190.                 final L2Attackable monster = (L2Attackable) getActiveChar();
  191.                 if (monster.getAI().getIntention() == CtrlIntention.AI_INTENTION_MOVE_TO)
  192.                 {
  193.                     final Collection<L2Object> players = getKnownObjects().values();
  194.                     if (players != null)
  195.                     {
  196.                         for (L2Object obj : players)
  197.                         {
  198.                             if (obj.isNpc())
  199.                             {
  200.                                 L2Npc npcMob = (L2Npc) obj;
  201.                                 if (!npcMob.isDead() && npcMob.isInsideRadius(monster, monster.getAggroRange(), true, false))
  202.                                 {
  203.                                     if (!npcMob.getClan().equals(monster.getClan()))
  204.                                     {
  205.                                        
  206.                                         if (monster.getHating(npcMob) == 0)
  207.                                         {
  208.                                             monster.addDamageHate(npcMob, 0, 0);
  209.                                         }
  210.  
  211.                                         // Skip attack for other targets, if one is already chosen for attack
  212.                                         if ((monster.getAI().getIntention() != CtrlIntention.AI_INTENTION_ATTACK))
  213.                                         {
  214.                                             WalkingManager.getInstance().stopMoving(getActiveChar(), false, true);
  215.                                             monster.addDamageHate(npcMob, 0, 100);
  216.                                             monster.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, npcMob, null);
  217.                                         }
  218.                                     }
  219.  
  220.                                     // Send aggroRangeEnter
  221.  
  222.                                 }
  223.  
  224.                             }
  225.                            
  226.                         }
  227.                     }
  228.                 }
  229.             }
  230.         }
  231.     }
  232. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement