Advertisement
Guest User

SuperMonster for aCis

a guest
May 11th, 2014
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.48 KB | None | 0 0
  1. package custom.SuperMonster;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.SQLException;
  6. import java.util.concurrent.TimeUnit;
  7.  
  8. import net.sf.l2j.L2DatabaseFactory;
  9. import net.sf.l2j.gameserver.Announcements;
  10. import net.sf.l2j.gameserver.datatables.SkillTable;
  11. import net.sf.l2j.gameserver.model.L2Skill;
  12. import net.sf.l2j.gameserver.model.actor.L2Npc;
  13. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  14. import net.sf.l2j.gameserver.model.quest.Quest;
  15.  
  16. /**
  17.  * @author SoFace
  18.  */
  19. public class SuperMonster extends Quest
  20. {
  21.     // Monsters's ID.
  22.     private static final int MONSTERS[] =
  23.     {
  24.         12564
  25.     };
  26.    
  27.     private static final boolean REWARD_PARTY = false; // Reward party ?
  28.    
  29.     private final static boolean REWARD_NOBLE = true; // Give Noblesse  ?
  30.    
  31.     private final static boolean REWARD_HERO = false; // Give Hero ?
  32.     private final static int REWARD_HERO_DAYS = -1; // How many days to give the status of Hero ?
  33.                                                     // 0 - Until relogin. -1 - Forever.
  34.    
  35.     private final static boolean REWARD_SKILL = true; // Give Skill ?
  36.     private final static int REWARD_SKILL_ID = 0; // Skill's ID.
  37.     private final static int REWARD_SKILL_LVL = 0; // Skill's LvL.
  38.    
  39.     private final static boolean REWARD_ITEMS = true; // Give Items ?
  40.     private final static int REWARD_ITEM_ID = 4037; // Item's ID.
  41.     private final static int REWARD_ITEM_COUNT = 5; // Count.
  42.    
  43.     public SuperMonster()
  44.     {
  45.         super(-1, "SuperMonster", "custom");
  46.        
  47.         for (int mobs : MONSTERS)
  48.             addKillId(mobs);
  49.     }
  50.    
  51.     @Override
  52.     public String onKill(L2Npc npc, L2PcInstance player, boolean isPet)
  53.     {
  54.         L2Skill skill = SkillTable.getInstance().getInfo(REWARD_SKILL_ID, REWARD_SKILL_LVL);
  55.        
  56.         Announcements.announceToAll("SuperMonster was killed.");
  57.        
  58.         if (REWARD_PARTY)
  59.         {
  60.             if (player.getParty() != null)
  61.             {
  62.                 for (L2PcInstance members : player.getParty().getPartyMembers())
  63.                 {
  64.                     members.sendMessage("Congratulations ! You killed The SuperMonster !");
  65.                    
  66.                     if (REWARD_ITEMS)
  67.                         members.addItem("Add", REWARD_ITEM_ID, REWARD_ITEM_COUNT, members, true);
  68.                     if (REWARD_SKILL)
  69.                         members.addSkill(skill, true);
  70.                     if (REWARD_HERO)
  71.                     {
  72.                         if (!player.isHero())
  73.                             addHero(player, REWARD_HERO_DAYS);
  74.                         else
  75.                             player.sendMessage("You already Hero.");
  76.                     }
  77.                     if (REWARD_NOBLE)
  78.                     {
  79.                         if (!members.isNoble())
  80.                             members.setNoble(true, true);
  81.                         else
  82.                             members.sendMessage("You already Noblesse.");
  83.                     }
  84.                    
  85.                     members.broadcastUserInfo();
  86.                 }
  87.             }
  88.             else
  89.             {
  90.                 player.sendMessage("Congratulations ! You killed The SuperMonster !");
  91.                
  92.                 if (REWARD_ITEMS)
  93.                     player.addItem("Add", REWARD_ITEM_ID, REWARD_ITEM_COUNT, player, true);
  94.                 if (REWARD_SKILL)
  95.                     player.addSkill(skill, true);
  96.                 if (REWARD_HERO)
  97.                 {
  98.                     if (!player.isHero())
  99.                         addHero(player, REWARD_HERO_DAYS);
  100.                     else
  101.                         player.sendMessage("You already Hero.");
  102.                 }
  103.                 if (REWARD_NOBLE)
  104.                 {
  105.                     if (!player.isNoble())
  106.                         player.setNoble(true, true);
  107.                     else
  108.                         player.sendMessage("You already Noblesse.");
  109.                 }
  110.                
  111.                 player.broadcastUserInfo();
  112.             }
  113.         }
  114.         else
  115.         {
  116.             player.sendMessage("Congratulations ! You killed The SuperMonster !");
  117.            
  118.             if (REWARD_ITEMS)
  119.                 player.addItem("Add", REWARD_ITEM_ID, REWARD_ITEM_COUNT, player, true);
  120.             if (REWARD_SKILL)
  121.                 player.addSkill(skill, true);
  122.             if (REWARD_HERO)
  123.             {
  124.                 if (!player.isHero())
  125.                     addHero(player, REWARD_HERO_DAYS);
  126.                 else
  127.                     player.sendMessage("You already Hero.");
  128.             }
  129.             if (REWARD_NOBLE)
  130.             {
  131.                 if (!player.isNoble())
  132.                     player.setNoble(true, true);
  133.                 else
  134.                     player.sendMessage("You already Noblesse.");
  135.             }
  136.            
  137.             player.broadcastUserInfo();
  138.         }
  139.        
  140.         return null;
  141.     }
  142.    
  143.     private void addHero(L2PcInstance player, int days)
  144.     {
  145.         long _heroExpire = 0L;
  146.        
  147.         player.setHero(true);
  148.         player.broadcastUserInfo();
  149.        
  150.         if (days == 0)
  151.         {
  152.             _heroExpire = 3L;
  153.             return;
  154.         }
  155.         _heroExpire = (days == -1 ? 1L : System.currentTimeMillis() + TimeUnit.DAYS.toMillis(days));
  156.        
  157.         try (Connection con = L2DatabaseFactory.getConnection())
  158.         {
  159.             PreparedStatement stm = con.prepareStatement("UPDATE `characters` SET `hero`=? WHERE `obj_Id`=?");
  160.             stm.setLong(1, _heroExpire);
  161.             stm.setInt(2, player.getObjectId());
  162.             stm.execute();
  163.         }
  164.         catch (SQLException e)
  165.         {
  166.             e.printStackTrace();
  167.         }
  168.     }
  169.    
  170.     public static void main(String args[])
  171.     {
  172.         new SuperMonster();
  173.     }
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement