Advertisement
Guest User

Error

a guest
May 4th, 2014
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.17 KB | None | 0 0
  1. /*
  2.  * This program is free software: you can redistribute it and/or modify it under
  3.  * the terms of the GNU General Public License as published by the Free Software
  4.  * Foundation, either version 3 of the License, or (at your option) any later
  5.  * version.
  6.  *
  7.  * This program is distributed in the hope that it will be useful, but WITHOUT
  8.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9.  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10.  * details.
  11.  *
  12.  * You should have received a copy of the GNU General Public License along with
  13.  * this program. If not, see <http://www.gnu.org/licenses/>.
  14.  */
  15. /*
  16.  * This program is free software: you can redistribute it and/or modify it under
  17.  * the terms of the GNU General Public License as published by the Free Software
  18.  * Foundation, either version 3 of the License, or (at your option) any later
  19.  * version.
  20.  *
  21.  * This program is distributed in the hope that it will be useful, but WITHOUT
  22.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  23.  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  24.  * details.
  25.  *
  26.  * You should have received a copy of the GNU General Public License along with
  27.  * this program. If not, see <http://www.gnu.org/licenses/>.
  28.  */
  29. package com.l2jserver.gameserver.model.zone.type;
  30.  
  31. import java.io.File;
  32. import java.io.FileInputStream;
  33. import java.util.ArrayList;
  34. import java.util.List;
  35. import java.util.Properties;
  36.  
  37. import javolution.util.FastList;
  38.  
  39. import com.l2jserver.gameserver.ThreadPoolManager;
  40. import com.l2jserver.gameserver.datatables.SkillData;
  41. import com.l2jserver.gameserver.model.actor.L2Character;
  42. import com.l2jserver.gameserver.model.actor.L2Summon;
  43. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  44. import com.l2jserver.gameserver.model.itemcontainer.PcInventory;
  45. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  46. import com.l2jserver.gameserver.model.skills.Skill;
  47. import com.l2jserver.gameserver.model.zone.ZoneId;
  48. import com.l2jserver.util.Rnd;
  49.  
  50. /**
  51.  * @author Wyatt
  52.  * @version 1.3
  53.  */
  54.  
  55. public class L2MultiFunctionZone extends L2RespawnZone
  56. {
  57.    
  58.     public L2MultiFunctionZone(int id)
  59.     {
  60.         super(id);
  61.         loadConfigs();
  62.     }
  63.    
  64.     public static boolean pvp_enabled, restart_zone, store_zone, logout_zone, revive_noblesse, revive_heal, revive, remove_buffs, remove_pets, give_noblesse;
  65.     static int radius, enchant, revive_delay;
  66.     static int[][] spawn_loc;
  67.     Skill noblesse = SkillData.getInstance().getSkill(1323, 1);
  68.     private static List<String> items = new FastList<>();
  69.     private static List<String> grades = new FastList<>(), classes = new FastList<>();
  70.     public static List<int[]> rewards;
  71.     static String[] gradeNames =
  72.     {
  73.         "",
  74.         "D",
  75.         "C",
  76.         "B",
  77.         "A",
  78.         "S",
  79.         "S80",
  80.         "S84"
  81.     };
  82.    
  83.     @Override
  84.     protected void onEnter(L2Character character)
  85.     {
  86.         character.setInsideZone(ZoneId.NO_SUMMON_FRIEND, true);
  87.         character.setInsideZone(ZoneId.MULTI_FUNCTION, true);
  88.         if (!store_zone)
  89.         {
  90.             character.setInsideZone(ZoneId.NO_STORE, true);
  91.         }
  92.        
  93.         if (character instanceof L2PcInstance)
  94.         {
  95.             L2PcInstance activeChar = ((L2PcInstance) character);
  96.             if ((classes != null) && classes.contains("" + activeChar.getClassId().getId()))
  97.             {
  98.                 activeChar.teleToLocation(83597, 147888, -3405);
  99.                 activeChar.sendMessage("Your class is not allowed in the MultiFunction zone.");
  100.                 return;
  101.             }
  102.            
  103.             for (L2ItemInstance o : activeChar.getInventory()._items)
  104.             {
  105.                 if (o.isEquipable() && o.isEquipped() && !checkItem(o))
  106.                 {
  107.                     int slot = activeChar.getInventory().getSlotFromItem(o);
  108.                     activeChar.getInventory().unEquipItemInBodySlot(slot);
  109.                     activeChar.sendMessage(o.getName() + " unequiped because is not allowed inside this zone.");
  110.                 }
  111.             }
  112.             activeChar.sendMessage("You entered in a MultiFunction zone.");
  113.             clear(activeChar);
  114.             if (give_noblesse)
  115.             {
  116.                 noblesse.applyEffects(activeChar, activeChar);
  117.             }
  118.             if (pvp_enabled)
  119.             {
  120.                 activeChar.updatePvPFlag(1);
  121.             }
  122.         }
  123.     }
  124.    
  125.     @Override
  126.     protected void onExit(L2Character character)
  127.     {
  128.         character.setInsideZone(ZoneId.NO_SUMMON_FRIEND, false);
  129.         character.setInsideZone(ZoneId.MULTI_FUNCTION, false);
  130.         if (!store_zone)
  131.         {
  132.             character.setInsideZone(ZoneId.NO_STORE, false);
  133.         }
  134.        
  135.         if (character instanceof L2PcInstance)
  136.         {
  137.             L2PcInstance activeChar = ((L2PcInstance) character);
  138.             activeChar.sendMessage("You left from a MultiFunction zone.");
  139.            
  140.             if (pvp_enabled)
  141.             {
  142.                 activeChar.stopPvPFlag();
  143.             }
  144.         }
  145.     }
  146.    
  147.     @Override
  148.     public void onDieInside(final L2Character character)
  149.     {
  150.         if (character instanceof L2PcInstance)
  151.         {
  152.             final L2PcInstance activeChar = ((L2PcInstance) character);
  153.             if (revive)
  154.             {
  155.                 ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  156.                 {
  157.                     @Override
  158.                     public void run()
  159.                     {
  160.                         activeChar.doRevive();
  161.                         heal(activeChar);
  162.                         int[] loc = spawn_loc[Rnd.get(spawn_loc.length)];
  163.                         activeChar.teleToLocation(loc[0] + Rnd.get(-radius, radius), loc[1] + Rnd.get(-radius, radius), loc[2]);
  164.                     }
  165.                 }, revive_delay * 1000);
  166.             }
  167.         }
  168.     }
  169.    
  170.     @Override
  171.     public void onReviveInside(L2Character character)
  172.     {
  173.         if (character instanceof L2PcInstance)
  174.         {
  175.             L2PcInstance activeChar = ((L2PcInstance) character);
  176.             if (revive_noblesse)
  177.             {
  178.                 noblesse.applyEffects(activeChar, activeChar);
  179.             }
  180.             if (revive_heal)
  181.             {
  182.                 heal(activeChar);
  183.             }
  184.         }
  185.     }
  186.    
  187.     private void clear(L2PcInstance player)
  188.     {
  189.         if (remove_buffs)
  190.         {
  191.             player.stopAllEffectsExceptThoseThatLastThroughDeath();
  192.             if (remove_pets)
  193.             {
  194.                 L2Summon pet = player.getSummon();
  195.                 if (pet != null)
  196.                 {
  197.                     pet.stopAllEffectsExceptThoseThatLastThroughDeath();
  198.                     pet.unSummon(player);
  199.                 }
  200.             }
  201.         }
  202.         else
  203.         {
  204.             if (remove_pets)
  205.             {
  206.                 L2Summon pet = player.getSummon();
  207.                 if (pet != null)
  208.                 {
  209.                     pet.unSummon(player);
  210.                 }
  211.             }
  212.         }
  213.     }
  214.    
  215.     static void heal(L2PcInstance activeChar)
  216.     {
  217.         activeChar.setCurrentHp(activeChar.getMaxHp());
  218.         activeChar.setCurrentCp(activeChar.getMaxCp());
  219.         activeChar.setCurrentMp(activeChar.getMaxMp());
  220.     }
  221.    
  222.     public static void givereward(L2PcInstance player)
  223.     {
  224.         if (player.isInsideZone(ZoneId.MULTI_FUNCTION))
  225.         {
  226.             for (int[] reward : rewards)
  227.             {
  228.                 PcInventory inv = player.getInventory();
  229.                 inv.addItem("Custom Reward", reward[0], reward[1], player, player);
  230.             }
  231.         }
  232.     }
  233.    
  234.     public static boolean checkItem(L2ItemInstance item)
  235.     {
  236.         int o = item.getItem().getCrystalType();
  237.         int e = item.getEnchantLevel();
  238.        
  239.         if ((enchant != 0) && (e >= enchant))
  240.         {
  241.             return false;
  242.         }
  243.        
  244.         if (grades.contains(gradeNames[o]))
  245.         {
  246.             return false;
  247.         }
  248.        
  249.         if ((items != null) && items.contains("" + item.getId()))
  250.         {
  251.             return false;
  252.         }
  253.         return true;
  254.     }
  255.    
  256.     private static void loadConfigs()
  257.     {
  258.         try
  259.         {
  260.             Properties prop = new Properties();
  261.             prop.load(new FileInputStream(new File("./config/MultiFunctionZone.properties")));
  262.             pvp_enabled = Boolean.parseBoolean(prop.getProperty("EnablePvP", "False"));
  263.             spawn_loc = parseItemsList(prop.getProperty("SpawnLoc", "150111,144740,-12248"));
  264.             revive_delay = Integer.parseInt(prop.getProperty("ReviveDelay", "10"));
  265.             if (revive_delay != 0)
  266.             {
  267.                 revive = true;
  268.             }
  269.             give_noblesse = Boolean.parseBoolean(prop.getProperty("GiveNoblesse", "False"));
  270.             String[] propertySplit = prop.getProperty("Items", "").split(",");
  271.             if (propertySplit.length != 0)
  272.             {
  273.                 for (String i : propertySplit)
  274.                 {
  275.                     items.add(i);
  276.                 }
  277.             }
  278.             propertySplit = prop.getProperty("Grades", "").split(",");
  279.             if (propertySplit.length != 0)
  280.             {
  281.                 for (String i : propertySplit)
  282.                 {
  283.                     if (i.equals("D") || i.equals("C") || i.equals("B") || i.equals("A") || i.equals("S") || i.equals("S80") || i.equals("S84"))
  284.                     {
  285.                         grades.add(i);
  286.                     }
  287.                 }
  288.             }
  289.             propertySplit = prop.getProperty("Classes", "").split(",");
  290.             if (propertySplit.length != 0)
  291.             {
  292.                 for (String i : propertySplit)
  293.                 {
  294.                     classes.add(i);
  295.                 }
  296.             }
  297.             radius = Integer.parseInt(prop.getProperty("RespawnRadius", "500"));
  298.             enchant = Integer.parseInt(prop.getProperty("Enchant", "0"));
  299.             remove_buffs = Boolean.parseBoolean(prop.getProperty("RemoveBuffs", "False"));
  300.             remove_pets = Boolean.parseBoolean(prop.getProperty("RemovePets", "False"));
  301.             restart_zone = Boolean.parseBoolean(prop.getProperty("NoRestartZone", "False"));
  302.             store_zone = Boolean.parseBoolean(prop.getProperty("NoStoreZone", "False"));
  303.             logout_zone = Boolean.parseBoolean(prop.getProperty("NoLogoutZone", "False"));
  304.             revive_noblesse = Boolean.parseBoolean(prop.getProperty("ReviveNoblesse", "False"));
  305.             revive_heal = Boolean.parseBoolean(prop.getProperty("ReviveHeal", "False"));
  306.             rewards = new ArrayList<>();
  307.             propertySplit = prop.getProperty("Rewards", "57,100000").split(";");
  308.             for (String reward : propertySplit)
  309.             {
  310.                 String[] rewardSplit = reward.split(",");
  311.                 if (rewardSplit.length == 2)
  312.                 {
  313.                     try
  314.                     {
  315.                         rewards.add(new int[]
  316.                         {
  317.                             Integer.parseInt(rewardSplit[0]),
  318.                             Integer.parseInt(rewardSplit[1])
  319.                         });
  320.                     }
  321.                     catch (NumberFormatException nfe)
  322.                     {
  323.                     }
  324.                 }
  325.             }
  326.         }
  327.         catch (Exception e)
  328.         {
  329.             e.printStackTrace();
  330.         }
  331.     }
  332.    
  333.     private static int[][] parseItemsList(String line)
  334.     {
  335.         final String[] propertySplit = line.split(";");
  336.         if (propertySplit.length == 0)
  337.         {
  338.             return null;
  339.         }
  340.        
  341.         int i = 0;
  342.         String[] valueSplit;
  343.         final int[][] result = new int[propertySplit.length][];
  344.         for (String value : propertySplit)
  345.         {
  346.             valueSplit = value.split(",");
  347.             if (valueSplit.length != 3)
  348.             {
  349.                 return null;
  350.             }
  351.            
  352.             result[i] = new int[3];
  353.             try
  354.             {
  355.                 result[i][0] = Integer.parseInt(valueSplit[0]);
  356.             }
  357.             catch (NumberFormatException e)
  358.             {
  359.                 return null;
  360.             }
  361.             try
  362.             {
  363.                 result[i][1] = Integer.parseInt(valueSplit[1]);
  364.             }
  365.             catch (NumberFormatException e)
  366.             {
  367.                 return null;
  368.             }
  369.             try
  370.             {
  371.                 result[i][2] = Integer.parseInt(valueSplit[2]);
  372.             }
  373.             catch (NumberFormatException e)
  374.             {
  375.                 return null;
  376.             }
  377.             i++;
  378.         }
  379.         return result;
  380.     }
  381. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement