Guest User

Luck.java

a guest
Jan 1st, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.46 KB | None | 0 0
  1. package com.l2jfrozen.gameserver.handler.voicedcommandhandlers;
  2.  
  3. /*
  4.  * This program is free software: you can redistribute it and/or modify it under
  5.  * the terms of the GNU General Public License as published by the Free Software
  6.  * Foundation, either version 3 of the License, or (at your option) any later
  7.  * version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful, but WITHOUT
  10.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11.  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  12.  * details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License along with
  15.  * this program. If not, see <http://www.gnu.org/licenses/>.
  16.  */
  17.  
  18. import java.sql.Connection;
  19. import java.sql.PreparedStatement;
  20. import java.sql.ResultSet;
  21. import java.sql.SQLException;
  22. import java.util.logging.Logger;
  23. import java.util.Random;
  24.  
  25. import com.l2jfrozen.Config;
  26. import com.l2jfrozen.gameserver.cache.HtmCache;
  27. import com.l2jfrozen.gameserver.handler.ICustomByPassHandler;
  28. import com.l2jfrozen.gameserver.handler.IVoicedCommandHandler;
  29. import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  30. import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
  31. import com.l2jfrozen.util.CloseUtil;
  32. import com.l2jfrozen.util.database.L2DatabaseFactory;
  33.  
  34.  
  35.  
  36. /**
  37.  * <B><U>User Character .luck voicecommand - SL2 L2JEmu</U></B><BR><BR>
  38.  *
  39.  *
  40.  * <U>NOTICE:</U> Voice command .luck that when used, allows player to
  41.  * choose an ammount between 1kk, 10kk and 50kk Adenas. He has 50% chance to double the ammount
  42.  * and 50% chance to lose it. It's gamble.<BR><BR>
  43.  *
  44.  *
  45.  * (solving client crashes on character entering world)<BR><BR>
  46.  *
  47.  *
  48.  * @author szponiasty
  49.  * @version $Revision: 0.17.2.95.2.9 $ $Date: 2010/03/03 9:07:11 $
  50.  */
  51. public class Luck implements IVoicedCommandHandler, ICustomByPassHandler
  52. {
  53.     static final Logger _log = Logger.getLogger(Repair.class.getName());
  54.    
  55.     private static final String[]   _voicedCommands =
  56.         {
  57.         "luck",
  58.         };
  59.    
  60.     @Override
  61.     public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
  62.     {      
  63.         if (!activeChar.getClient().getFloodProtectors().getTransaction().tryPerformAction("bank"))
  64.         {
  65.             activeChar.sendMessage("You Cannot Test Your Luck So Fast!");
  66.             return true;
  67.         }
  68.         if (activeChar==null)
  69.             return false;
  70.        
  71.         // Send activeChar HTML page
  72.         if (command.startsWith("luck"))              
  73.         {            
  74.             String htmContent = HtmCache.getInstance().getHtm("data/html/mods/luck.htm");
  75.             NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(5);
  76.             npcHtmlMessage.setHtml(htmContent);    
  77.             activeChar.sendPacket(npcHtmlMessage); 
  78.             return true;
  79.         }
  80.        
  81.         //_log.warning("Luck Attempt: Failed. ");
  82.         return false;
  83.     }
  84.    
  85.    
  86.  
  87.     @Override
  88.     public String[] getVoicedCommandList()
  89.     {
  90.         return _voicedCommands;
  91.     }
  92.  
  93.    
  94.     private static final String [] _BYPASSCMD = {"luck","luck_close_win"};
  95.    
  96.     private enum CommandEnum
  97.     {
  98.         luck,
  99.         luck_close_win
  100.     }
  101.    
  102.     @Override
  103.     public String[] getByPassCommands()
  104.     {
  105.         return _BYPASSCMD;
  106.     }
  107.  
  108.     /* (non-Javadoc)
  109.      * @see com.l2jfrozen.gameserver.handler.ICustomByPassHandler#handleCommand(java.lang.String, com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance, java.lang.String)
  110.      */
  111.     @Override
  112.     public void handleCommand(String command, final L2PcInstance activeChar,
  113.         String tryLuck)
  114.     {
  115.        
  116.         CommandEnum comm = CommandEnum.valueOf(command);
  117.        
  118.         if(comm == null)
  119.             return;
  120.        
  121.         switch(comm)
  122.         {
  123.             case luck:{
  124.                 int adenaLuck = 0;
  125.                 if(tryLuck.contains("1"))
  126.                     adenaLuck = 1000000;
  127.                 else if(tryLuck.contains("2"))
  128.                     adenaLuck = 10000000;
  129.                 else if(tryLuck.contains("3"))
  130.                     adenaLuck = 50000000;
  131.                 if (activeChar.getInventory().getInventoryItemCount(57, 0) >= adenaLuck){
  132.                     // 50% chance to succeed
  133.                     Random r = new Random();
  134.                     int choice = r.nextInt(2);
  135.                     if(choice==0) {
  136.                         activeChar.getInventory().addAdena("Adena", adenaLuck, activeChar, null);
  137.                         activeChar.sendMessage("Congratulations! You have won" + adenaLuck + "adenas!");
  138.                     }
  139.                     else
  140.                     {
  141.                         activeChar.getInventory().reduceAdena("Adena", adenaLuck, activeChar, null);
  142.                         activeChar.sendMessage("Too bad... You just lost" + adenaLuck + "adenas...");
  143.                     }
  144.                 }
  145.                 else
  146.                     activeChar.sendMessage("You do not have "+adenaLuck+" Adenas to test your luck with.");
  147.  
  148.             }
  149.             case luck_close_win:{
  150.                 return;
  151.             }
  152.         }
  153.  
  154.     }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment