Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.l2jfrozen.gameserver.handler.voicedcommandhandlers;
- /*
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see <http://www.gnu.org/licenses/>.
- */
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.logging.Logger;
- import java.util.Random;
- import com.l2jfrozen.Config;
- import com.l2jfrozen.gameserver.cache.HtmCache;
- import com.l2jfrozen.gameserver.handler.ICustomByPassHandler;
- import com.l2jfrozen.gameserver.handler.IVoicedCommandHandler;
- import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
- import com.l2jfrozen.util.CloseUtil;
- import com.l2jfrozen.util.database.L2DatabaseFactory;
- /**
- * <B><U>User Character .luck voicecommand - SL2 L2JEmu</U></B><BR><BR>
- *
- *
- * <U>NOTICE:</U> Voice command .luck that when used, allows player to
- * choose an ammount between 1kk, 10kk and 50kk Adenas. He has 50% chance to double the ammount
- * and 50% chance to lose it. It's gamble.<BR><BR>
- *
- *
- * (solving client crashes on character entering world)<BR><BR>
- *
- *
- * @author szponiasty
- * @version $Revision: 0.17.2.95.2.9 $ $Date: 2010/03/03 9:07:11 $
- */
- public class Luck implements IVoicedCommandHandler, ICustomByPassHandler
- {
- static final Logger _log = Logger.getLogger(Repair.class.getName());
- private static final String[] _voicedCommands =
- {
- "luck",
- };
- @Override
- public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
- {
- if (!activeChar.getClient().getFloodProtectors().getTransaction().tryPerformAction("bank"))
- {
- activeChar.sendMessage("You Cannot Test Your Luck So Fast!");
- return true;
- }
- if (activeChar==null)
- return false;
- // Send activeChar HTML page
- if (command.startsWith("luck"))
- {
- String htmContent = HtmCache.getInstance().getHtm("data/html/mods/luck.htm");
- NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(5);
- npcHtmlMessage.setHtml(htmContent);
- activeChar.sendPacket(npcHtmlMessage);
- return true;
- }
- //_log.warning("Luck Attempt: Failed. ");
- return false;
- }
- @Override
- public String[] getVoicedCommandList()
- {
- return _voicedCommands;
- }
- private static final String [] _BYPASSCMD = {"luck","luck_close_win"};
- private enum CommandEnum
- {
- luck,
- luck_close_win
- }
- @Override
- public String[] getByPassCommands()
- {
- return _BYPASSCMD;
- }
- /* (non-Javadoc)
- * @see com.l2jfrozen.gameserver.handler.ICustomByPassHandler#handleCommand(java.lang.String, com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance, java.lang.String)
- */
- @Override
- public void handleCommand(String command, final L2PcInstance activeChar,
- String tryLuck)
- {
- CommandEnum comm = CommandEnum.valueOf(command);
- if(comm == null)
- return;
- switch(comm)
- {
- case luck:{
- int adenaLuck = 0;
- if(tryLuck.contains("1"))
- adenaLuck = 1000000;
- else if(tryLuck.contains("2"))
- adenaLuck = 10000000;
- else if(tryLuck.contains("3"))
- adenaLuck = 50000000;
- if (activeChar.getInventory().getInventoryItemCount(57, 0) >= adenaLuck){
- // 50% chance to succeed
- Random r = new Random();
- int choice = r.nextInt(2);
- if(choice==0) {
- activeChar.getInventory().addAdena("Adena", adenaLuck, activeChar, null);
- activeChar.sendMessage("Congratulations! You have won" + adenaLuck + "adenas!");
- }
- else
- {
- activeChar.getInventory().reduceAdena("Adena", adenaLuck, activeChar, null);
- activeChar.sendMessage("Too bad... You just lost" + adenaLuck + "adenas...");
- }
- }
- else
- activeChar.sendMessage("You do not have "+adenaLuck+" Adenas to test your luck with.");
- }
- case luck_close_win:{
- return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment