Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 50.59 KB | None | 0 0
  1. package l2f.gameserver.model.Phantoms;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileReader;
  6. import java.io.IOException;
  7. import java.io.LineNumberReader;
  8. import java.sql.Connection;
  9. import java.sql.PreparedStatement;
  10. import java.sql.ResultSet;
  11. import java.util.Map;
  12. import java.util.concurrent.ConcurrentHashMap;
  13. import java.util.concurrent.ConcurrentLinkedQueue;
  14.  
  15. import javolution.text.TextBuilder;
  16. import javolution.util.FastList;
  17. import javolution.util.FastMap;
  18.  
  19. import org.apache.log4j.Logger;
  20.  
  21. import l2f.commons.util.Rnd;
  22. import l2f.gameserver.model.actor.instances.player.ShortCut;
  23. import l2f.gameserver.model.base.InvisibleType;
  24. import l2f.gameserver.model.base.Race;
  25. import l2f.gameserver.Config;
  26. import l2f.gameserver.ThreadPoolManager;
  27. import l2f.gameserver.database.DatabaseFactory;
  28. import l2f.gameserver.ai.CtrlIntention;
  29. import l2f.gameserver.ai.PlayableAI.nextAction;
  30. import l2f.gameserver.skills.AbnormalEffect;
  31. import l2f.gameserver.skills.effects.EffectTemplate;
  32. import l2f.gameserver.stats.Env;
  33. import l2f.gameserver.tables.ClanTable;
  34. import l2f.gameserver.tables.SkillTable;
  35. import l2f.gameserver.geodata.GeoEngine;
  36. import l2f.gameserver.model.instances.NpcInstance;
  37. import l2f.gameserver.model.items.ItemInstance;
  38. import l2f.gameserver.utils.ItemFunctions;
  39. import l2f.gameserver.model.Effect;
  40. import l2f.gameserver.model.GameObject;
  41. import l2f.gameserver.model.GameObjectsStorage;
  42. import l2f.gameserver.model.Skill;
  43. import l2f.gameserver.model.World;
  44. import l2f.gameserver.utils.Location;
  45. import l2f.gameserver.model.Player;
  46. import l2f.gameserver.network.serverpackets.MagicSkillUse;
  47. import l2f.gameserver.network.serverpackets.Say2;
  48. import l2f.gameserver.network.serverpackets.components.ChatType;
  49. import l2f.gameserver.templates.PlayerTemplate;
  50. import l2f.gameserver.templates.item.CreateItem;
  51. import l2f.gameserver.templates.item.ItemTemplate;
  52.  
  53. public class PhantomPlayers
  54. {
  55.    private static final Logger _log= Logger.getLogger(PhantomPlayers.class.getName());
  56.    private static String _phantomAcc = Config.PHANTOM_PLAYERS_AKK;
  57.    private static int _PhantomsLimit = 0;
  58.    private static int _setsCount = 0;
  59.    private static int _setsCountClan = 0;
  60.    private volatile int _PhantomsTownTotal = 0;
  61.    private static int _nameColCount = 0;
  62.    private static int _titleColCount = 0;
  63.    private static FastList<Integer> _nameColors = new FastList<Integer>();
  64.    private static FastList<Integer> _titleColors = new FastList<Integer>();
  65.    private static FastList<L2Set> _sets = new FastList<L2Set>();
  66.    private static int _setsArcherCount = 0;
  67.    private static FastList<L2Set> _setsArcher = new FastList<L2Set>();
  68.    private static PhantomPlayers _instance;
  69.    private static int _setsOlyCount = 0;
  70.    private static FastList<L2Set> _setsOly = new FastList<L2Set>();
  71.    private static int _locsCount = 0;
  72.    private static FastList<Location> _PhantomsTownLoc = new FastList<Location>();
  73.    private static FastMap<Integer, L2Fantome> _phantoms = new FastMap<Integer, L2Fantome>();
  74.    private static int _PhantomssayPhantomsCount = 0;
  75.    private static FastList<String> _PhantomssayPhantoms = new FastList<String>();
  76.    private static int _PhantomsdeadtalkCount = 0;
  77.    private static FastList<String> _Phantomsdeadtalk = new FastList<String>();
  78.    private static Map<Integer, ConcurrentLinkedQueue<Player>> _PhantomsTown = new ConcurrentHashMap<Integer, ConcurrentLinkedQueue<Player>>();
  79.    private static Map<Integer, ConcurrentLinkedQueue<Player>> _PhantomsTownClan = new ConcurrentHashMap<Integer, ConcurrentLinkedQueue<Player>>();
  80.    private static Map<Integer, ConcurrentLinkedQueue<Integer>> _PhantomsTownClanList = new ConcurrentHashMap<Integer, ConcurrentLinkedQueue<Integer>>();
  81.    
  82.    private static int buffs[][] = { // id, lvl, group
  83.       { 306, 1, 2 },
  84.       { 308, 1, 2 },
  85.       { 307, 1, 2 },
  86.       { 309, 1, 2 },
  87.       { 266, 1, 2 },
  88.       { 529, 1, 2 },
  89.       { 530, 1, 2 },
  90.       { 1303, 2, 2 },
  91.       { 1085, 3, 2 },
  92.       { 1040, 3, 2 },
  93.       { 1062, 2, 2 },
  94.       { 4703, 3, 2 },
  95.       { 1389, 3, 2 },
  96.       { 1461, 1, 2 },
  97.       { 1413, 1, 2 },
  98.       { 1191, 3, 2 },
  99.       { 1182, 3, 2 },
  100.       { 1189, 3, 2 },
  101.       { 1392, 3, 2 },
  102.       { 1035, 4, 2 },
  103.       { 1259, 4, 2 },
  104.       { 1460, 1, 2 },
  105.       { 1044, 3, 2 },
  106.       { 1078, 6, 2 },
  107.       { 1259, 4, 2 },
  108.       { 264, 1, 2 },
  109.       { 265, 1, 2 },
  110.       { 267, 1, 2 },
  111.       { 268, 1, 2 },
  112.       { 304, 1, 2 },
  113.       { 349, 1, 2 },
  114.       { 363, 1, 2 },
  115.       { 273, 1, 2 },
  116.       { 276, 1, 2 },
  117.       { 365, 1, 2 },
  118.       { 270, 1, 2 },
  119.       { 830, 1, 2 },
  120.       { 1500, 1, 2 },
  121.       { 1503, 1, 2 },
  122.       { 1501, 1, 2 },
  123.       { 1504, 1, 2 },
  124.       { 1323, 1, 1 },
  125.       { 1240, 3, 1 },
  126.       { 1501, 1, 1 },
  127.       { 1036, 2, 1 },
  128.       { 1062, 2, 1 },
  129.       { 4699, 3, 1 },
  130.       { 1388, 3, 1 },
  131.       { 1461, 1, 1 },
  132.       { 1191, 3, 1 },
  133.       { 1182, 3, 1 },
  134.       { 1189, 3, 1 },
  135.       { 1392, 3, 1 },
  136.       { 1352, 1, 1 },
  137.       { 1035, 4, 1 },
  138.       { 264, 1, 1 },
  139.       { 265, 1, 1 },
  140.       { 267, 1, 1 },
  141.       { 268, 1, 1 },
  142.       { 269, 1, 1 },
  143.       { 304, 1, 1 },
  144.       { 349, 1, 1 },
  145.       { 363, 1, 1 },
  146.       { 364, 1, 1 },
  147.       { 271, 1, 1 },
  148.       { 274, 1, 1 },
  149.       { 275, 1, 1 },
  150.       { 270, 1, 1 },
  151.       { 269, 1, 1 },
  152.       { 306, 1, 1 },
  153.       { 308, 1, 1 },
  154.       { 272, 1, 1 },
  155.       { 307, 1, 1 },
  156.       { 309, 1, 1 },
  157.       { 310, 1, 1 },
  158.       { 266, 1, 1 },
  159.       { 529, 1, 1 },
  160.       { 530, 1, 1 },
  161.       { 1502, 1, 1 },
  162.       { 1503, 1, 1 },
  163.       { 1517, 1, 1 },
  164.       { 1259, 4, 1 },
  165.       { 1519, 1, 1 },
  166.       { 1323, 1, 1 },
  167.       { 1363, 1, 1 }, // Chant of Victory
  168.       { 1504, 1, 1 }
  169.       };
  170.  
  171.    public static PhantomPlayers getInstance()
  172.    {
  173.       return _instance;
  174.    }
  175.  
  176.    public static void init()
  177.    {
  178.       _instance = new PhantomPlayers();
  179.       _instance.load();
  180.    }
  181.  
  182.    private void load()
  183.    {
  184.       parceArmors();
  185.       parceArcherArmors();
  186.       parceOlyArmors();
  187.       parceColors();
  188.       cachedeadtalk();
  189.       if(Config.ALLOW_PHANTOM_PLAYERS)
  190.       {
  191.          parceTownLocs();
  192.          parceTownClans();
  193.          //parceTownRecs();
  194.          cacheFantoms();
  195.          cachesayPhantoms();
  196.          _PhantomsLimit = Config.PHANTOM_PLAYERS_COUNT_FIRST + Config.PHANTOM_PLAYERS_COUNT_NEXT + 10;
  197.          _PhantomsTown.put(1, new ConcurrentLinkedQueue<Player>());
  198.          _PhantomsTown.put(2, new ConcurrentLinkedQueue<Player>());
  199.       }
  200.    }
  201.  
  202.    private void cacheFantoms()
  203.    {
  204.       new Thread(new Runnable()
  205.     {
  206.       @SuppressWarnings("unused")
  207.       public void run()
  208.       {
  209.          String name = "";
  210.          String new_name = "";
  211.          Connection con = null;
  212.          Player fantom = null;
  213.          try
  214.          {
  215.             con = DatabaseFactory.getInstance().getConnection();
  216.             con.setTransactionIsolation(1);
  217.             PreparedStatement st = con.prepareStatement("SELECT obj_Id,char_name,title,x,y,z,clanid FROM characters WHERE account_name = ?");
  218.             st.setString(1, _phantomAcc);
  219.             ResultSet rs = st.executeQuery();
  220.             rs.setFetchSize(250);
  221.             while(rs.next())
  222.             {
  223.                name = rs.getString("char_name");
  224.                _phantoms.put(Integer.valueOf(rs.getInt("obj_Id")), new L2Fantome(name, rs.getString("title"), rs.getInt("x"), rs.getInt("y"), rs.getInt("z"), rs.getInt("clanid")));
  225.             }
  226.             st.close();
  227.             rs.close();
  228.             con.close();
  229.             _log.info("PhantomPlayers: Cached " + _phantoms.size() + " players.");
  230.          }
  231.          catch (Exception e)
  232.          {
  233.             _log.warn("PhantomPlayers: could not load chars from DB: " + e);
  234.          }
  235.          finally
  236.          {
  237.             if(con != null)
  238.                con = null;
  239.          }
  240.          if (!_phantoms.isEmpty())
  241.          {
  242.             ThreadPoolManager.getInstance().schedule(new FantomTask(1), Config.PHANTOM_PLAYERS_DELAY_FIRST * 1000);
  243.          }
  244.       }
  245.       }).start();
  246.    }
  247.  
  248.    private void parceArmors()
  249.    {
  250.       if (!_sets.isEmpty())
  251.          _sets.clear();
  252.  
  253.       LineNumberReader lnr = null;
  254.       BufferedReader br = null;
  255.       FileReader fr = null;
  256.       try
  257.       {
  258.          File Data = new File("./config/mod/Phantom/town_sets.properties");
  259.          if (!Data.exists())
  260.             return;
  261.          fr = new FileReader(Data);
  262.          br = new BufferedReader(fr);
  263.          lnr = new LineNumberReader(br);
  264.          String line;
  265.          while ((line = lnr.readLine()) != null)
  266.          {
  267.             if(line.trim().length() == 0 || line.startsWith("#"))
  268.                continue;
  269.             String[] items = line.split(",");
  270.             int custom = 0;
  271.             try
  272.             {
  273.                custom = Integer.parseInt(items[6]);
  274.             }
  275.             catch (Exception e)
  276.             {
  277.                custom = 0;
  278.             }
  279.             _sets.add(new L2Set(Integer.parseInt(items[0]), Integer.parseInt(items[1]), Integer.parseInt(items[2]), Integer.parseInt(items[3]), Integer.parseInt(items[4]), Integer.parseInt(items[5]), Integer.parseInt(items[6]), Integer.parseInt(items[7]),  custom));
  280.          }
  281.          _setsCount = _sets.size() - 1;
  282.          _log.info("Load " + _setsCount + " phantom armor sets");
  283.       }
  284.       catch(Exception e)
  285.       {
  286.          e.printStackTrace();
  287.       }
  288.       finally
  289.       {
  290.          try
  291.          {
  292.             if (fr != null)
  293.                fr.close();
  294.             if (br != null)
  295.                br.close();
  296.             if (lnr != null)
  297.                lnr.close();
  298.          }
  299.          catch(Exception e)
  300.          {
  301.          }
  302.       }
  303.    }
  304.  
  305.    private void parceArcherArmors()
  306.    {
  307.       if (!_setsArcher.isEmpty())
  308.          _setsArcher.clear();
  309.  
  310.       LineNumberReader lnr = null;
  311.       BufferedReader br = null;
  312.       FileReader fr = null;
  313.       try
  314.       {
  315.          File Data = new File("./config/mod/Phantom/archer_sets.properties");
  316.          if (!Data.exists())
  317.             return;
  318.          fr = new FileReader(Data);
  319.          br = new BufferedReader(fr);
  320.          lnr = new LineNumberReader(br);
  321.          String line;
  322.          while ((line = lnr.readLine()) != null)
  323.          {
  324.             if(line.trim().length() == 0 || line.startsWith("#"))
  325.                continue;
  326.             String[] items = line.split(",");
  327.             int custom = 0;
  328.             try
  329.             {
  330.                custom = Integer.parseInt(items[5]);
  331.             }
  332.             catch (Exception e)
  333.             {
  334.                custom = 0;
  335.             }
  336.             _setsArcher.add(new L2Set(Integer.parseInt(items[0]), Integer.parseInt(items[1]), Integer.parseInt(items[2]), Integer.parseInt(items[3]), Integer.parseInt(items[4]), Integer.parseInt(items[5]), Integer.parseInt(items[6]), Integer.parseInt(items[7]), custom));
  337.          }
  338.          _setsArcherCount = _setsArcher.size() - 1;
  339.          _log.info("Load " + _setsArcherCount + " Aecher phantom armor sets");
  340.       }
  341.       catch(IOException | NumberFormatException e)
  342.       {
  343.       }
  344.       finally
  345.       {
  346.          try
  347.          {
  348.             if (fr != null)
  349.                fr.close();
  350.             if (br != null)
  351.                br.close();
  352.             if (lnr != null)
  353.                lnr.close();
  354.          }
  355.          catch(Exception e)
  356.          {
  357.          }
  358.       }
  359.    }
  360.  
  361.    private void parceOlyArmors()
  362.    {
  363.       if (!_setsOly.isEmpty())
  364.          _setsOly.clear();
  365.  
  366.       LineNumberReader lnr = null;
  367.       BufferedReader br = null;
  368.       FileReader fr = null;
  369.       try
  370.       {
  371.          File Data = new File("./config/mod/Phantom/oly_sets.properties");
  372.          if (!Data.exists())
  373.             return;
  374.          fr = new FileReader(Data);
  375.          br = new BufferedReader(fr);
  376.          lnr = new LineNumberReader(br);
  377.          String line;
  378.          while ((line = lnr.readLine()) != null)
  379.          {
  380.             if(line.trim().length() == 0 || line.startsWith("#"))
  381.                continue;
  382.             String[] items = line.split(",");
  383.             int custom = 0;
  384.             try
  385.             {
  386.                custom = Integer.parseInt(items[6]);
  387.             }
  388.             catch (Exception e)
  389.             {
  390.                custom = 0;
  391.             }
  392.             _setsOly.add(new L2Set(Integer.parseInt(items[0]), Integer.parseInt(items[1]), Integer.parseInt(items[2]), Integer.parseInt(items[3]), Integer.parseInt(items[4]), Integer.parseInt(items[5]), Integer.parseInt(items[6]), Integer.parseInt(items[7]), custom));
  393.          }
  394.          _setsOlyCount = _setsOly.size() - 1;
  395.          _log.info("Load " + _setsOlyCount + " phantom Only armor sets");
  396.       }
  397.       catch(Exception e)
  398.       {
  399.          e.printStackTrace();
  400.       }
  401.       finally
  402.       {
  403.          try
  404.          {
  405.             if (fr != null)
  406.                fr.close();
  407.             if (br != null)
  408.                br.close();
  409.             if (lnr != null)
  410.                lnr.close();
  411.          }
  412.          catch(Exception e)
  413.          {
  414.          }
  415.       }
  416.    }
  417.  
  418.    @SuppressWarnings({ "unchecked", "rawtypes" })
  419.    private void parceTownClans()
  420.    {
  421.       LineNumberReader lnr = null;
  422.       BufferedReader br = null;
  423.       FileReader fr = null;
  424.       try
  425.       {
  426.          File Data = new File("./config/mod/Phantom/town_clans.properties");
  427.             if (!Data.exists())
  428.                return;
  429.          fr = new FileReader(Data);
  430.          br = new BufferedReader(fr);
  431.          lnr = new LineNumberReader(br);
  432.          int clanId = 0;
  433.          String line;
  434.          while((line = lnr.readLine()) != null)
  435.          {
  436.             if (line.trim().length() == 0 || line.startsWith("#"))
  437.                continue;
  438.             String[] items = line.split(":");
  439.             clanId = Integer.parseInt(items[0]);
  440.             String[] pls = items[1].split(",");
  441.             ConcurrentLinkedQueue players = new ConcurrentLinkedQueue();
  442.             for (String plid : pls)
  443.                players.add(Integer.valueOf(Integer.parseInt(plid)));
  444.             _PhantomsTownClanList.put(Integer.valueOf(clanId), players);
  445.          }
  446.          _setsCountClan = _PhantomsTownClanList.size() - 1;
  447.          _log.info("Load " + _setsCountClan + " phantom Clans");
  448.       }
  449.       catch (Exception e)
  450.       {
  451.          e.printStackTrace();
  452.       }
  453.       finally
  454.       {
  455.          try
  456.          {
  457.             if (fr != null)
  458.                fr.close();
  459.             if (br != null)
  460.                br.close();
  461.             if (lnr != null)
  462.                lnr.close();
  463.          }
  464.          catch (Exception e1)
  465.          {
  466.          }
  467.       }
  468.    }
  469.  
  470.    private void parceTownLocs()
  471.    {
  472.       _PhantomsTownLoc.clear();
  473.       LineNumberReader lnr = null;
  474.       BufferedReader br = null;
  475.       FileReader fr = null;
  476.       try
  477.       {
  478.          File Data = new File("./config/mod/Phantom/town_locs.properties");
  479.          if (!Data.exists())
  480.             return;
  481.          fr = new FileReader(Data);
  482.          br = new BufferedReader(fr);
  483.          lnr = new LineNumberReader(br);
  484.          String line;
  485.          while ((line = lnr.readLine()) != null)
  486.          {
  487.             if (line.trim().length() == 0 || line.startsWith("#"))
  488.                continue;
  489.             String[] items = line.split(",");
  490.             _PhantomsTownLoc.add(new Location(Integer.parseInt(items[0]), Integer.parseInt(items[1]), Integer.parseInt(items[2])));
  491.          }
  492.          _locsCount = _PhantomsTownLoc.size() - 1;
  493.          _log.info("Load " + _locsCount + " phantom Town Locations");
  494.       }
  495.       catch (Exception e)
  496.       {
  497.          e.printStackTrace();
  498.       }
  499.       finally
  500.       {
  501.          try
  502.          {
  503.             if (fr != null)
  504.                fr.close();
  505.             if (br != null)
  506.                br.close();
  507.             if (lnr != null)
  508.                lnr.close();
  509.          }
  510.          catch (Exception e1)
  511.          {
  512.          }
  513.       }
  514.    }
  515.  
  516.    public void startWalk(Player phantom)
  517.    {
  518.       ThreadPoolManager.getInstance().schedule(new PhantomWalk(phantom), 10000);
  519.    }
  520.  
  521.    private class PhantomWalk implements Runnable
  522.    {
  523.       Player _phantom;
  524.       public PhantomWalk(Player phantom)
  525.       {
  526.          _phantom = phantom;
  527.       }
  528.  
  529.       public void run()
  530.       {
  531.          if (_phantom.isDead())
  532.          {    if (Config.ALLOW_PHANTOM_CHAT)
  533.             {
  534.             if(Rnd.get(100) < 90)
  535.             {  
  536.             switch (Rnd.get(1, 5))
  537.             {
  538.             case 1:
  539.                Say2 cs = new Say2(_phantom.getObjectId(), ChatType.SHOUT, _phantom.getName(), getRandomdeadtalk());
  540.                for(Player player : World.getAroundPlayers(_phantom, 10000, 3000))
  541.                   if(player != null)
  542.                      if(!player.isBlockAll())
  543.                         player.sendPacket(cs);
  544.                _phantom.kick();
  545.                break;
  546.             case 2:
  547.                _phantom.kick();
  548.                break;
  549.             case 3:
  550.                Say2 cs3 = new Say2(_phantom.getObjectId(), ChatType.ALL, _phantom.getName(), getRandomdeadtalk());
  551.                for(Player player : World.getAroundPlayers(_phantom, 1200, 1000))
  552.                   if(player != null)
  553.                      if(!player.isBlockAll())
  554.                         player.sendPacket(cs3);
  555.                _phantom.kick();
  556.                break;
  557.             }
  558.             }
  559.             }
  560.          }
  561.            
  562.          if (_phantom.isInWater())
  563.             _phantom.teleToClosestTown();
  564.          if(Rnd.get(100) < 10)
  565.             if(Rnd.get(100) < 20)
  566.                if (_phantom.isSitting())
  567.                   _phantom.standUp();
  568.          // баф фантомов
  569.          Skill skill;
  570.          if(Rnd.get(100) < 50)
  571.          {
  572.             // баф воинов
  573.             if (!_phantom.getClassId().isMage() || _phantom.getClassId().getRace() == Race.orc)
  574.             {
  575.             for(int buff[] : buffs)
  576.                if(buff[2] == 1)
  577.                {
  578.                      skill = SkillTable.getInstance().getInfo(buff[0], buff[1]);
  579.                      for(EffectTemplate et : skill.getEffectTemplates())
  580.                      {
  581.                         Env env = new Env(_phantom, _phantom, skill);
  582.                         Effect effect = et.getEffect(env);
  583.                         effect.setPeriod(36000);
  584.                         _phantom.getEffectList().addEffect(effect);
  585.                      }
  586.                }
  587.             }
  588.             //баф магов
  589.             if (_phantom.getClassId().isMage() && _phantom.getClassId().getRace() != Race.orc)
  590.             {
  591.                for(int buff[] : buffs)
  592.                   if(buff[2] == 2)
  593.                   {
  594.                         skill = SkillTable.getInstance().getInfo(buff[0], buff[1]);
  595.                         for(EffectTemplate et : skill.getEffectTemplates())
  596.                         {
  597.                            Env env = new Env(_phantom, _phantom, skill);
  598.                            Effect effect = et.getEffect(env);
  599.                            effect.setPeriod(36000);
  600.                            _phantom.getEffectList().addEffect(effect);
  601.                         }
  602.                   }
  603.                
  604.             }
  605.            
  606.          }
  607.          
  608.            
  609.            
  610.             /*
  611.             for(NpcInstance npc : World.getAroundNpc(_phantom, 100, 100))
  612.                for(int buffers_id : _buffers)
  613.                if(npc.getNpcId() == buffers_id && !_phantom.isSitting())
  614.                {
  615.                   if (!_phantom.getClassId().isMage() || _phantom.getClassId().getRace() == Race.orc)
  616.                      for(int[] buff : _warrBuff)
  617.                         npc.broadcastPacket(new MagicSkillUse(npc, _phantom, buff[2], buff[3], 0, 0));
  618.                   if (_phantom.getClassId().isMage() && _phantom.getClassId().getRace() != Race.orc)
  619.                      for(int[] buff : _mageBuff)
  620.                         npc.broadcastPacket(new MagicSkillUse(npc, _phantom, buff[2], buff[3], 0, 0));              
  621.                }*/
  622.  
  623.          // писдеж в чат
  624.          if (Config.ALLOW_PHANTOM_CHAT)
  625.          {
  626.             if(Rnd.get(100) < Config.PHANTOM_CHAT_CHANSE)
  627.             {  
  628.                switch (Rnd.get(1, 3))
  629.                {
  630.                case 1:
  631.                   Say2 cs = new Say2(_phantom.getObjectId(), ChatType.SHOUT, _phantom.getName(), getRandomSayPhantoms());
  632.                   for(Player player : World.getAroundPlayers(_phantom, 10000, 3000))
  633.                      if(player != null)
  634.                         if(!player.isBlockAll())
  635.                            player.sendPacket(cs);
  636.                   break;
  637.                case 2:
  638.                   Say2 cs2 = new Say2(_phantom.getObjectId(), ChatType.TRADE, _phantom.getName(), getRandomSayPhantoms());
  639.                   for(Player player : World.getAroundPlayers(_phantom, 5000, 2000))
  640.                      if(player != null)
  641.                         if(!player.isBlockAll())
  642.                            player.sendPacket(cs2);
  643.                   break;
  644.                case 3:
  645.                   Say2 cs3 = new Say2(_phantom.getObjectId(), ChatType.ALL, _phantom.getName(), getRandomSayPhantoms());
  646.                   for(Player player : World.getAroundPlayers(_phantom, 1200, 1000))
  647.                      if(player != null)
  648.                         if(!player.isBlockAll())
  649.                            player.sendPacket(cs3);
  650.                   break;
  651.                }
  652.             }
  653.          }
  654.          // использование анимации сосок Ы грейда
  655.          if(Rnd.get(100) < 10)
  656.          {
  657.             if (!_phantom.getClassId().isMage() || _phantom.getClassId().getRace() == Race.orc)
  658.                _phantom.broadcastPacket(new MagicSkillUse(_phantom, _phantom, 2154, 1, 0, 0));
  659.             if (_phantom.getClassId().isMage() && _phantom.getClassId().getRace() != Race.orc)
  660.                _phantom.broadcastPacket(new MagicSkillUse(_phantom, _phantom, 2159, 1, 0, 0));
  661.          }
  662.          
  663.          // примитивная атака скилами
  664.          if(Rnd.get(100) < 70)
  665.          {
  666.             if (!_phantom.getClassId().isMage() || _phantom.getClassId().getRace() == Race.orc)
  667.                for(Player player : World.getAroundPlayers(_phantom, 100, 100))
  668.                   if (GeoEngine.canSeeTarget(_phantom, player, false) && !player.isDead() && !player.isInZonePeace() && !_phantom.isInZonePeace() && (player.getKarma() != 0 || player.getPvpFlag() > 0))
  669.                   {
  670.                      if(_phantom.getRealDistance3D(player) <= _phantom.getPhysicalAttackRange() + 40)
  671.                      {
  672.                         _phantom.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, player);
  673.                         try {
  674.                            Thread.sleep(500L);
  675.                         } catch (InterruptedException e) {
  676.                            // TODO Auto-generated catch block
  677.                            e.printStackTrace();
  678.                         }
  679.                         if (_phantom.getClassId().getRace() == Race.human)
  680.                            _phantom.doCast(SkillTable.getInstance().getInfo(3, 2), player, true);
  681.                         if (_phantom.getClassId().getRace() == Race.elf)
  682.                            _phantom.doCast(SkillTable.getInstance().getInfo(3, 2), player, true);
  683.                         if (_phantom.getClassId().getRace() == Race.darkelf)
  684.                            _phantom.doCast(SkillTable.getInstance().getInfo(3, 2), player, true);
  685.                         if (_phantom.getClassId().getRace() == Race.orc)
  686.                            _phantom.doCast(SkillTable.getInstance().getInfo(29, 2), player, true);
  687.                         if (_phantom.getClassId().getRace() == Race.dwarf)
  688.                            _phantom.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, player);
  689.                         if (_phantom.getClassId().getRace() == Race.kamael)
  690.                            _phantom.doCast(SkillTable.getInstance().getInfo(468, 2), player, true);
  691.                         try {
  692.                            Thread.sleep(2000L);
  693.                         } catch (InterruptedException e)
  694.                         {
  695.                            e.printStackTrace();
  696.                         }
  697.                         _phantom.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, player);
  698.                      }
  699.                      else
  700.                         try {
  701.                            Thread.sleep(500L);
  702.                         } catch (InterruptedException e)
  703.                          {
  704.                            e.printStackTrace();
  705.                         }
  706.                         _phantom.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, player);
  707.                   }
  708.             if (_phantom.getClassId().isMage() && _phantom.getClassId().getRace() != Race.orc)
  709.                for(Player player : World.getAroundPlayers(_phantom, 100, 100))
  710.                   if (GeoEngine.canSeeTarget(_phantom, player, false) && !player.isDead() && !player.isInZonePeace() && !_phantom.isInZonePeace() && (player.getKarma() != 0 || player.getPvpFlag() > 0))
  711.                   {
  712.                      _phantom.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, player);
  713.                      _phantom.doCast(SkillTable.getInstance().getInfo(1177, 2), player, true);
  714.                   }
  715.          }
  716.          // атака мобов ?? Оо=)
  717.          if(Rnd.get(100) < 40)
  718.          {
  719.             if (!_phantom.getClassId().isMage() || _phantom.getClassId().getRace() == Race.orc)
  720.                for(NpcInstance npc : World.getAroundNpc(_phantom, 800, 200))
  721.                   if (GeoEngine.canSeeTarget(_phantom, npc, false) && npc.isMonster() && !npc.isDead())
  722.                      _phantom.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, npc);
  723.                         _phantom.broadcastPacket(new MagicSkillUse(_phantom, _phantom, 2154, 1, 0, 0));
  724.             if (_phantom.getClassId().isMage() && _phantom.getClassId().getRace() != Race.orc)
  725.                for(NpcInstance npc : World.getAroundNpc(_phantom, 800, 200))
  726.                   if (GeoEngine.canSeeTarget(_phantom, npc, false) && npc.isMonster() && !npc.isDead())
  727.                   {
  728.                      _phantom.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, npc);
  729.                      _phantom.broadcastPacket(new MagicSkillUse(_phantom, _phantom, 2159, 1, 0, 0));
  730.                      _phantom.doCast(SkillTable.getInstance().getInfo(1177, 2), npc, true);
  731.                   }
  732.          }
  733.          
  734.          // атака игроков??
  735.          if(Rnd.get(100) < 10)
  736.          {
  737.             if (!_phantom.getClassId().isMage() || _phantom.getClassId().getRace() == Race.orc)
  738.                for(Player player : World.getAroundPlayers(_phantom, 600, 200))
  739.                   if (GeoEngine.canSeeTarget(_phantom, player, false) && !player.isDead() && !player.isInZonePeace() && !_phantom.isInZonePeace())
  740.                      _phantom.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, player);
  741.            
  742.             if (_phantom.getClassId().isMage() && _phantom.getClassId().getRace() != Race.orc)
  743.                for(Player player : World.getAroundPlayers(_phantom, 600, 200))
  744.                   if (GeoEngine.canSeeTarget(_phantom, player, false) && !player.isDead() && !player.isInZonePeace() && !_phantom.isInZonePeace())
  745.                   {
  746.                      _phantom.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, player);
  747.                      _phantom.doCast(SkillTable.getInstance().getInfo(1177, 2), player, true);
  748.                   }
  749.          }
  750.          
  751.          // подбор предметов
  752.          if(Rnd.get(100) < 10)
  753.             if(_phantom.getAI().getIntention() != CtrlIntention.AI_INTENTION_ATTACK || _phantom.getAI().getIntention() != CtrlIntention.AI_INTENTION_CAST)
  754.                for(GameObject obj : World.getAroundObjects(_phantom, 800, 200))
  755.                   if (obj.isItem())
  756.                   _phantom.getAI().setIntention(CtrlIntention.AI_INTENTION_PICK_UP, obj);
  757.          
  758.          // движение
  759.          if(Rnd.get(1000) < 1)
  760.          {
  761.             if(_phantom.getAI().getIntention() != CtrlIntention.AI_INTENTION_ATTACK || _phantom.getAI().getIntention() != CtrlIntention.AI_INTENTION_CAST)
  762.                _phantom.rndWalk();  
  763.          }
  764.          startWalk(_phantom);
  765.       }
  766.    }
  767.  
  768.    // кеш фраз фантомов
  769.    private void cachesayPhantoms()
  770.    {
  771.       _PhantomssayPhantoms.clear();
  772.       LineNumberReader lnr = null;
  773.       BufferedReader br = null;
  774.       FileReader fr = null;
  775.       try
  776.       {
  777.          File Data = new File("./config/mod/Phantom/sayPhantoms.talk");
  778.          if (!Data.exists())
  779.             return;
  780.          fr = new FileReader(Data);
  781.          br = new BufferedReader(fr);
  782.          lnr = new LineNumberReader(br);
  783.          String line;
  784.          while ((line = lnr.readLine()) != null)
  785.          {
  786.             if (line.trim().length() == 0 || line.startsWith("#"))
  787.                continue;
  788.             _PhantomssayPhantoms.add(line);
  789.          }
  790.          _PhantomssayPhantomsCount = _PhantomssayPhantoms.size() - 1;
  791.          _log.info("Load " + _PhantomssayPhantomsCount + " phantom say");
  792.       }
  793.       catch (Exception e)
  794.       {
  795.          e.printStackTrace();
  796.       }
  797.       finally
  798.       {
  799.          try
  800.          {
  801.             if (fr != null)
  802.                fr.close();
  803.             if (br != null)
  804.                br.close();
  805.             if (lnr != null)
  806.                lnr.close();
  807.          }
  808.          catch (Exception e1)
  809.          {
  810.          }
  811.       }
  812.    }
  813.  
  814.    private void cachedeadtalk()
  815.    {
  816.       _Phantomsdeadtalk.clear();
  817.       LineNumberReader lnr = null;
  818.       BufferedReader br = null;
  819.       FileReader fr = null;
  820.       try
  821.       {
  822.          File Data = new File("./config/mod/Phantom/dead.talk");
  823.          if (!Data.exists())
  824.             return;
  825.          fr = new FileReader(Data);
  826.          br = new BufferedReader(fr);
  827.          lnr = new LineNumberReader(br);
  828.          String line;
  829.          while ((line = lnr.readLine()) != null)
  830.          {
  831.             if (line.trim().length() == 0 || line.startsWith("#"))
  832.                continue;
  833.             _Phantomsdeadtalk.add(line);
  834.          }
  835.          _PhantomsdeadtalkCount = _Phantomsdeadtalk.size() - 1;
  836.          _log.info("Load " + _PhantomsdeadtalkCount + " phantom Last");
  837.       }
  838.       catch (Exception e)
  839.       {
  840.          e.printStackTrace();
  841.       }
  842.       finally
  843.       {
  844.          try
  845.          {
  846.             if (fr != null)
  847.                fr.close();
  848.             if (br != null)
  849.                br.close();
  850.             if (lnr != null)
  851.                lnr.close();
  852.          }
  853.          catch (Exception e1)
  854.          {
  855.          }
  856.       }
  857.    }
  858.  
  859.    private void parceColors()
  860.    {
  861.       _nameColors = Config.PHANTOM_PLAYERS_NAME_CLOLORS;
  862.       _titleColors = Config.PHANTOM_PLAYERS_TITLE_CLOLORS;
  863.       _nameColCount = _nameColors.size() - 1;
  864.       _titleColCount = _titleColors.size() - 1;
  865.    }
  866.  
  867.    private L2Set getRandomSet()
  868.    {
  869.       return _sets.get(Rnd.get(_setsCount));
  870.    }
  871.  
  872.    @SuppressWarnings("unused")
  873.    private L2Set getRandomArcherSet()
  874.    {
  875.       return _setsArcher.get(Rnd.get(_setsArcherCount));
  876.    }
  877.  
  878.    @SuppressWarnings("unused")
  879.    private int getRandomPhantom()
  880.    {
  881.       return Rnd.get(600000000, 600006081);
  882.    }
  883.  
  884.    private int getRandomPhantomNext()
  885.    {
  886.       int obj = 0;
  887.       for (int i = 6; i > 0; i--)
  888.       {
  889.          obj = Rnd.get(600000000, 600006081);
  890.          if (!_PhantomsTown.get(1).contains(obj) && !_PhantomsTown.get(2).contains(obj))
  891.             return obj;
  892.       }
  893.       return getRandomPhantomNext();
  894.    }
  895.    @SuppressWarnings("unused")
  896.    private int getRandomClan()
  897.    {
  898.       return Rnd.get(600000000, 600006081);
  899.    }
  900.  
  901.    private Location getRandomLoc()
  902.    {
  903.       Location loc = null;
  904.       if(loc == null)
  905.          loc = _PhantomsTownLoc.get(Rnd.get(0, _locsCount));
  906.       return loc;
  907.    }
  908.  
  909.    static class L2Set
  910.    {
  911.       public int _body;
  912.       public int _gaiters;
  913.       public int _gloves;
  914.       public int _boots;
  915.       public int _weapon;
  916.       public int _custom;
  917.       public int _shield;
  918.       public int _cloak;
  919.       public int _grade;
  920.       L2Set(int bod, int gaiter, int glove, int boot, int weapon, int shield, int cloak, int grade, int custom)
  921.       {
  922.          _body = bod;
  923.          _gaiters = gaiter;
  924.          _gloves = glove;
  925.          _boots = boot;
  926.          _weapon = weapon;
  927.          _shield = shield;
  928.          _cloak = cloak;
  929.          _grade = grade;
  930.          _custom = custom;
  931.       }
  932.    }
  933.  
  934.    static class L2Fantome
  935.    {
  936.       public String name;
  937.       public String title;
  938.       public int x;
  939.       public int y;
  940.       public int z;
  941.       public int clanId;
  942.       L2Fantome(String name, String title, int x, int y, int z, int clanId)
  943.       {
  944.          this.name = name;
  945.          this.title = title;
  946.          this.x = x;
  947.          this.y = y;
  948.          this.z = z;
  949.          this.clanId = clanId;
  950.       }
  951.    }
  952.  
  953.    public class FantomTask implements Runnable
  954.    {
  955.       public int _task;
  956.       public FantomTask(int task)
  957.       {
  958.          _task = task;
  959.       }
  960.       public void run()
  961.       {
  962.          int count = 0;
  963.          int count2 = 0;
  964.          int PhantomObjId = 0;
  965.          int PhantomObjId2 = 0;
  966.          switch (_task)
  967.          {
  968.             case 1:
  969.             {
  970.                _log.info("PhantomPlayers: 1st wave, spawn started.");
  971.                while(count < Config.PHANTOM_PLAYERS_COUNT_FIRST)
  972.                {
  973.                   Player fantom = null;
  974.                   PhantomObjId = getRandomPhantomNext();
  975.                   if(!(_PhantomsTown.get(1).contains(PhantomObjId)))
  976.                   {
  977.                      fantom = loadPhantom(PhantomObjId);
  978.                      if(fantom == null)
  979.                         continue;
  980.                      _PhantomsTown.get(1).add(fantom);
  981.                      if(Config.PHANTOM_PLAYERS_SOULSHOT_ANIM && Rnd.get(100) < 45)
  982.                      {
  983.                         try
  984.                         {
  985.                            Thread.sleep(900);
  986.                         }
  987.                         catch (InterruptedException e)
  988.                         {}
  989.                         fantom.broadcastPacket(new MagicSkillUse(fantom, fantom, 2154, 1, 0, 0));
  990.                         if (Rnd.get(100) < 5)
  991.                            fantom.sitDown(null);
  992.                         if (Rnd.get(100) < 30)
  993.                            fantom.startAbnormalEffect(AbnormalEffect.S_NAVIT);
  994.                         try
  995.                         {
  996.                            Thread.sleep(300);
  997.                         }
  998.                         catch(InterruptedException e)
  999.                         {
  1000.                         }
  1001.                         fantom.broadcastPacket(new MagicSkillUse(fantom, fantom, 2164, 1, 0, 0));
  1002.                      }
  1003.                      try
  1004.                      {
  1005.                         Thread.sleep(Config.PHANTOM_PLAYERS_DELAY_SPAWN_FIRST);
  1006.                      }
  1007.                      catch (InterruptedException e)
  1008.                      {
  1009.                      }
  1010.                      count++;
  1011.                   }
  1012.                }
  1013.                _log.info("FPhantomPlayers: 1st wave, spawned " + count + " players.");
  1014.                //Online.getInstance().checkMaxOnline();
  1015.                ThreadPoolManager.getInstance().schedule(new FantomTaskDespawn(1), Config.PHANTOM_PLAYERS_DESPAWN_FIRST);
  1016.                ThreadPoolManager.getInstance().schedule(new FantomTask(2), Config.PHANTOM_PLAYERS_DELAY_NEXT);
  1017.                ThreadPoolManager.getInstance().schedule(new Social(), 12000L);
  1018.                ThreadPoolManager.getInstance().schedule(new CheckCount(), 300000L);
  1019.                break;
  1020.             }
  1021.             case 2:
  1022.             {
  1023.                _log.info("PhantomPlayers: 2nd wave, spawn started.");
  1024.                while (count2 < Config.PHANTOM_PLAYERS_COUNT_NEXT)
  1025.                {
  1026.                   Player fantom2 = null;
  1027.                   PhantomObjId2 = getRandomPhantomNext();
  1028.                   if(!(_PhantomsTown.get(1).contains(PhantomObjId2)) || !(_PhantomsTown.get(2).contains(PhantomObjId2)))
  1029.                   {
  1030.                      fantom2 = loadPhantom(PhantomObjId2);
  1031.                      if(fantom2 == null)
  1032.                         continue;
  1033.                      _PhantomsTown.get(2).add(fantom2);
  1034.                      if(Config.PHANTOM_PLAYERS_SOULSHOT_ANIM && Rnd.get(100) < 45)
  1035.                      {
  1036.                         try
  1037.                         {
  1038.                            Thread.sleep(900L);
  1039.                         }
  1040.                         catch (InterruptedException e) {
  1041.                         }
  1042.                         if (Rnd.get(100) < 3)
  1043.                            fantom2.sitDown(null);
  1044.                         fantom2.broadcastPacket(new MagicSkillUse(fantom2, fantom2, 2154, 1, 0, 0));
  1045.                         try
  1046.                         {
  1047.                            Thread.sleep(300L);
  1048.                         }
  1049.                         catch (InterruptedException e) {
  1050.                         }
  1051.                         fantom2.broadcastPacket(new MagicSkillUse(fantom2, fantom2, 2164, 1, 0, 0));
  1052.                      }
  1053.                      try
  1054.                      {
  1055.                         Thread.sleep(Config.PHANTOM_PLAYERS_DELAY_SPAWN_NEXT);
  1056.                      }
  1057.                      catch (InterruptedException e) {
  1058.                      }
  1059.                      count2++;
  1060.                   }
  1061.                }
  1062.                _log.info("PhantomPlayers: 2nd wave, spawned " + count2 + " players.");
  1063.                //Online.getInstance().checkMaxOnline();
  1064.                ThreadPoolManager.getInstance().schedule(new FantomTaskDespawn(2), Config.PHANTOM_PLAYERS_DESPAWN_NEXT);
  1065.             }
  1066.          }
  1067.       }
  1068.    }
  1069.  
  1070.    public class FantomTaskDespawn implements Runnable
  1071.    {
  1072.       public int _task;
  1073.       public FantomTaskDespawn(int task)
  1074.       {
  1075.          _task = task;
  1076.       }
  1077.       @SuppressWarnings("unused")
  1078.       public void run()
  1079.       {
  1080.          Location loc = null;
  1081.          Player next = null;
  1082.          ConcurrentLinkedQueue<Player> players = _PhantomsTown.get(_task);
  1083.          for (Player fantom : players)
  1084.          {
  1085.             if (fantom == null)
  1086.                continue;
  1087.             loc = fantom.getPhantomLoc();
  1088.             //new Disconnection(fantom).defaultSequence(false);
  1089.             fantom.setOnlineStatus(false);
  1090.             _PhantomsTown.get(_task).remove(fantom);
  1091.             try
  1092.             {
  1093.                Thread.sleep(_task == 1 ? Config.PHANTOM_PLAYERS_DELAY_DESPAWN_FIRST : Config.PHANTOM_PLAYERS_DELAY_DESPAWN_NEXT);
  1094.             }
  1095.             catch(InterruptedException e){
  1096.             }
  1097.             if(_PhantomsTownTotal > _PhantomsLimit)
  1098.                continue;
  1099.             int nextObjId = getRandomPhantomNext();
  1100.             if(!(_PhantomsTown.get(_task).contains(nextObjId)))
  1101.             {
  1102.                next = loadPhantom(nextObjId);
  1103.                if(next == null)
  1104.                   continue;
  1105.                _PhantomsTown.get(_task).add(next);
  1106.                if(Config.PHANTOM_PLAYERS_SOULSHOT_ANIM && Rnd.get(100) < 45)
  1107.                {
  1108.                   try
  1109.                   {
  1110.                      Thread.sleep(900L);
  1111.                   }
  1112.                   catch (InterruptedException e) {
  1113.                   }
  1114.                   if (Rnd.get(100) < 3)
  1115.                      next.sitDown(null);
  1116.                   next.broadcastPacket(new MagicSkillUse(next, next, 2154, 1, 0, 0));
  1117.                   try
  1118.                   {
  1119.                      Thread.sleep(300L);
  1120.                   }
  1121.                   catch (InterruptedException e) {
  1122.                   }
  1123.                   next.broadcastPacket(new MagicSkillUse(next, next, 2164, 1, 0, 0));
  1124.                }
  1125.                try
  1126.                {
  1127.                   Thread.sleep(100L);
  1128.                }
  1129.                catch (InterruptedException e)
  1130.                {}
  1131.             }
  1132.          }
  1133.          loc = null;
  1134.          next = null;
  1135.          ThreadPoolManager.getInstance().schedule(new FantomTaskDespawn(1), _task == 1 ? Config.PHANTOM_PLAYERS_DESPAWN_FIRST : Config.PHANTOM_PLAYERS_DESPAWN_NEXT);
  1136.       }
  1137.    }
  1138.  
  1139.    public class CheckCount implements Runnable
  1140.    {
  1141.       public CheckCount()
  1142.       {
  1143.       }
  1144.         @Override
  1145.       public void run()
  1146.       {
  1147.          for (Map.Entry<Integer, ConcurrentLinkedQueue<Player>> entry : _PhantomsTown.entrySet())
  1148.          {
  1149.             Integer wave = entry.getKey();
  1150.             ConcurrentLinkedQueue<Player> players = entry.getValue();
  1151.             if (wave == null || players == null || players.isEmpty())
  1152.                continue;
  1153.             int limit = wave.intValue() == 1 ? Config.PHANTOM_PLAYERS_COUNT_FIRST : Config.PHANTOM_PLAYERS_COUNT_NEXT;
  1154.             int overflow = players.size() - limit;
  1155.             if (overflow < 1)
  1156.                continue;
  1157.             for (Player fantom : players)
  1158.             {
  1159.                //new Disconnection(fantom).defaultSequence(false);
  1160.                fantom.setOnlineStatus(false);
  1161.                _PhantomsTown.get(wave).remove(fantom);
  1162.                overflow--;
  1163.                if (overflow == 0)
  1164.                   break;
  1165.             }
  1166.          }
  1167.          ThreadPoolManager.getInstance().schedule(new CheckCount(), 300000L);
  1168.       }
  1169.    }
  1170.  
  1171.    public class Social implements Runnable
  1172.    {
  1173.       public Social()
  1174.       {
  1175.       }
  1176.  
  1177.         @Override
  1178.       public void run()
  1179.       {
  1180.          TextBuilder tb = new TextBuilder();
  1181.          for(Map.Entry<Integer, ConcurrentLinkedQueue<Player>> entry : _PhantomsTown.entrySet())
  1182.          {
  1183.             Integer wave = entry.getKey();
  1184.             ConcurrentLinkedQueue<Player> players = entry.getValue();
  1185.             if (wave == null || players == null || players.isEmpty())
  1186.                continue;
  1187.             int count = 0;
  1188.             for (Player player : players)
  1189.             {
  1190.                if (Rnd.get(100) < 65)
  1191.                {
  1192.                   switch (Rnd.get(2))
  1193.                   {
  1194.                      case 0:
  1195.                      case 1:
  1196.                         ItemInstance wpn = player.getActiveWeaponInstance();
  1197.                         int enhchant = wpn.getEnchantLevel();
  1198.                         int nextench = enhchant + 1;
  1199.                         if(Rnd.get(100) < 65 && enhchant <= Config.PHANTOM_PLAYERS_ENCHANT_MAX)
  1200.                            wpn.setEnchantLevel(nextench);
  1201.                         else if(Rnd.get(100) < 70)
  1202.                         {
  1203.                            wpn.setEnchantLevel(5);
  1204.                            if(nextench > 13 && Rnd.get(100) < 2)
  1205.                            {
  1206.                               tb.append("!");
  1207.                               for(int i = Rnd.get(2, 13); i > 0; i--)
  1208.                                  tb.append("!");
  1209.                               //player.sayString(getRandomEnchantPhrase() + tb.toString(), 1);
  1210.                               tb.clear();
  1211.                            }
  1212.                         }
  1213.                         //player.sendItems(true);
  1214.                         player.broadcastUserInfo(true);
  1215.                         break;
  1216.                      case 2:
  1217.                         if (Rnd.get(100) >= 5)
  1218.                            break;
  1219.                         player.moveToLocation(player.getX() + Rnd.get(30), player.getY() + Rnd.get(30), player.getZ(), 40, true);
  1220.                         player.getAI().setNextAction(nextAction.INTERACT, null, null, false, false);
  1221.                   }
  1222.                   try
  1223.                   {
  1224.                      Thread.sleep(Rnd.get(500, 1500));
  1225.                   }
  1226.                   catch (InterruptedException e)
  1227.                   {
  1228.                   }
  1229.                   count++;
  1230.                }
  1231.                if (count > 55)
  1232.                   break;
  1233.             }
  1234.          }
  1235.          tb.clear();
  1236.          tb = null;
  1237.          ThreadPoolManager.getInstance().schedule(new Social(), 12000L);
  1238.       }
  1239.    }
  1240.    @SuppressWarnings("unused")
  1241.    private Player loadPhantom(int objId)
  1242.    {
  1243.       int nbPlayerIG = GameObjectsStorage.getAllPlayersCount();
  1244.       if(nbPlayerIG < Config.MAXIMUM_ONLINE_USERS)
  1245.       {
  1246.          L2Fantome phantom = _phantoms.get(objId);
  1247.          if(phantom == null)
  1248.             return null;
  1249.          //Collection<Player> allPlayers = GameObjectsStorage.getAllPlayers();
  1250.          //Player[] players = allPlayers.toArray(new Player[allPlayers.size()]);      
  1251.          //for (int i = 0; i < players.length; i++)
  1252.          //{
  1253.          //   if(objId == players[i].getObjectId())
  1254.          //      return null;
  1255.          //}
  1256.          L2Set set = getRandomSet();
  1257.          ItemInstance body = null;
  1258.          ItemInstance gaiters = null;
  1259.          ItemInstance gloves = null;
  1260.          ItemInstance boots = null;
  1261.          ItemInstance weapon = null;
  1262.          ItemInstance shield = null;
  1263.          ItemInstance cloak = null;
  1264.          ItemInstance custom = null;
  1265.          int grade = set._grade;
  1266.          int setLevel = 1;
  1267.          if(grade == 0)
  1268.             setLevel = Rnd.get(1, 19);
  1269.          if(grade == 1)
  1270.             setLevel = Rnd.get(20, 39);
  1271.          if(grade == 2)
  1272.             setLevel = Rnd.get(40, 51);
  1273.          if(grade == 3)
  1274.             setLevel = Rnd.get(52, 60);
  1275.          if(grade == 4)
  1276.             setLevel = Rnd.get(61, 75);
  1277.          if(grade == 5)
  1278.             setLevel = Rnd.get(76, 83);
  1279.          if(grade == 6)
  1280.             setLevel = Rnd.get(84, 85);
  1281.          
  1282.          Player fantom = Player.restorePhantom(objId, setLevel, false);
  1283.      
  1284.          fantom.setOfflineMode(false);
  1285.          fantom.setIsOnline(true);
  1286.          fantom.updateOnlineStatus();
  1287.          //fantom.setNameColor(getNameColor());
  1288.          //fantom.setTitleColor(getTitleColor());
  1289.          //fantom.setOfflineMode(false);
  1290.          Location loc = getRandomLoc();
  1291.          fantom.setPhantomLoc(loc.getX(), loc.getY(), loc.getZ());
  1292.          fantom.setXYZ(loc.getX()+ Rnd.get(60), loc.getY() + Rnd.get(60), loc.getZ());
  1293.          Location loc1 = new Location(loc.getX()+ Rnd.get(150), loc.getY() + Rnd.get(150), loc.getZ());
  1294.          fantom.setOnlineStatus(true);
  1295.          fantom.setInvisibleType(InvisibleType.NONE);
  1296.  
  1297.          fantom.setNonAggroTime(Long.MAX_VALUE);
  1298.          fantom.spawnMe(loc1);
  1299.          fantom.setCurrentHpMp(fantom.getMaxHp(), fantom.getMaxMp());
  1300.          fantom.setCurrentCp(fantom.getMaxCp());
  1301.          if (Rnd.get(100) < 90)
  1302.             fantom.setClan(ClanTable.getInstance().getClan(getRandomClan()));
  1303.  
  1304.          if(Config.ALLOW_PHANTOM_SETS && fantom.getClassId().getRace() != Race.kamael)
  1305.          {
  1306.             if(set._body != 0)
  1307.                body = ItemFunctions.createItem(set._body);
  1308.             if(body != null)
  1309.             {
  1310.                fantom.getInventory().addItem(body, "fantom Item");
  1311.                fantom.getInventory().equipItem(body);
  1312.             }
  1313.             if(set._gaiters != 0)
  1314.                gaiters = ItemFunctions.createItem(set._gaiters);
  1315.             if(gaiters != null)
  1316.             {
  1317.                fantom.getInventory().addItem(gaiters, "fantom Item");
  1318.                fantom.getInventory().equipItem(gaiters);
  1319.             }
  1320.             if(set._gloves != 0)
  1321.                gloves = ItemFunctions.createItem(set._gloves);
  1322.             if(gloves != null)
  1323.             {
  1324.                fantom.getInventory().addItem(gloves, "fantom Item");
  1325.                fantom.getInventory().equipItem(gloves);
  1326.             }
  1327.             if(set._boots != 0)
  1328.                boots = ItemFunctions.createItem(set._boots);
  1329.             if(boots != null)
  1330.             {
  1331.                fantom.getInventory().addItem(boots, "fantom Item");
  1332.                fantom.getInventory().equipItem(boots);
  1333.             }
  1334.             if(set._weapon != 0)
  1335.                weapon = ItemFunctions.createItem(set._weapon);
  1336.             if(weapon != null)
  1337.             {
  1338.                fantom.getInventory().addItem(weapon, "fantom Item");
  1339.                fantom.getInventory().equipItem(weapon);
  1340.             }  
  1341.             if(set._shield != 0)
  1342.                shield = ItemFunctions.createItem(set._shield);
  1343.             if(shield != null)
  1344.             {
  1345.                fantom.getInventory().addItem(shield, "fantom Item");
  1346.                fantom.getInventory().equipItem(shield);
  1347.             }
  1348.             if(set._cloak != 0)
  1349.                cloak = ItemFunctions.createItem(set._cloak);
  1350.             if(cloak != null)
  1351.             {
  1352.                fantom.getInventory().addItem(cloak, "fantom Item");
  1353.                fantom.getInventory().equipItem(cloak);
  1354.             }
  1355.            
  1356.             //int[] classIdArcher = {92, 102, 109};
  1357.  
  1358.             //if (set._custom > 0)
  1359.             //{
  1360.             //   custom = ItemFunctions.createItem(set._custom);
  1361.             //   fantom.getInventory().addItem(custom);
  1362.             //   fantom.getInventory().equipItem(custom);
  1363.             //}
  1364.  
  1365.             //if(weapon != null)
  1366.             //   weapon.setEnchantLevel(Rnd.get(Config.PHANTOM_PLAYERS_ENCHANT_MIN, Config.PHANTOM_PLAYERS_ENCHANT_MAX));
  1367.             //if(Rnd.get(100) < 30)
  1368.             //   weapon.setAugmentation(new L2Augmentation(1067847165, 3250, 1));
  1369.             //if(weapon.getItemType() == WeaponType.BOW && (fantom.getClassId().getId() != 92 || fantom.getClassId().getId() != 102 || fantom.getClassId().getId() != 109))
  1370.             //{
  1371.             //   fantom.setClassId(classIdArcher[Rnd.get(classIdArcher.length)], true, false);
  1372.                //fantom.initAggro(true, true);
  1373.             //}
  1374.          }
  1375.          if(!Config.ALLOW_PHANTOM_SETS || fantom.getClassId().getRace() == Race.kamael)
  1376.          {
  1377.             PlayerTemplate template = fantom.getTemplate();
  1378.             for (CreateItem i : template.getItems())
  1379.             {
  1380.                ItemInstance item = ItemFunctions.createItem(i.getItemId());
  1381.                fantom.getInventory().addItem(item, "fantom Char Item");
  1382.  
  1383.                if (i.isEquipable() && item.isEquipable() && (fantom.getActiveWeaponItem() == null || item.getTemplate().getType2() != ItemTemplate.TYPE2_WEAPON))
  1384.                   fantom.getInventory().equipItem(item);
  1385.             }
  1386.          }
  1387.          //fantom.broadcastUserInfo(true);
  1388.          fantom.broadcastCharInfo();
  1389.          fantom.rndWalk();
  1390.          //fantom.setOnlineStatusPhantom(true);
  1391.          //RegionBBSManager.getInstance().changeCommunityBoard();
  1392.          startWalk(fantom);
  1393.          return fantom;
  1394.       }
  1395.       return null;
  1396.    }
  1397.  
  1398.    private String getRandomSayPhantoms()
  1399.    {
  1400.       return _PhantomssayPhantoms.get(Rnd.get(_PhantomssayPhantomsCount));
  1401.    }
  1402.  
  1403.    public String getRandomdeadtalk()
  1404.    {
  1405.       return _Phantomsdeadtalk.get(Rnd.get(_PhantomsdeadtalkCount));
  1406.    }
  1407.  
  1408. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement