Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Eclipse Workspace Patch 1.0
- #P L2J_Ephion
- Index: java/com/l2jserver/gameserver/network/clientpackets/RequestBypassToServer.java
- ===================================================================
- --- java/com/l2jserver/gameserver/network/clientpackets/RequestBypassToServer.java (revision 54)
- +++ java/com/l2jserver/gameserver/network/clientpackets/RequestBypassToServer.java (working copy)
- @@ -33,7 +34,9 @@
- import com.l2jserver.gameserver.model.actor.instance.L2MerchantSummonInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.model.entity.Hero;
- +import com.l2jserver.gameserver.model.entity.Kino;
- import com.l2jserver.gameserver.model.entity.L2Event;
- import com.l2jserver.gameserver.network.SystemMessageId;
- import com.l2jserver.gameserver.network.communityserver.CommunityServerThread;
- import com.l2jserver.gameserver.network.communityserver.writepackets.RequestShowCommunityBoard;
- @@ -147,6 +152,10 @@
- }
- catch (NumberFormatException nfe) {}
- }
- + else if (_command.startsWith("kino")){
- + Kino newKino = new Kino();
- + newKino.addNumbersByCommand(activeChar,_command.substring(5));
- + }
- else if (_command.startsWith("summon_"))
- {
- if(!activeChar.validateBypass(_command))
- Index: java/com/l2jserver/gameserver/GameServer.java
- ===================================================================
- --- java/com/l2jserver/gameserver/GameServer.java (revision 54)
- +++ java/com/l2jserver/gameserver/GameServer.java (working copy)
- @@ -120,6 +121,7 @@
- import com.l2jserver.gameserver.model.PartyMatchRoomList;
- import com.l2jserver.gameserver.model.PartyMatchWaitingList;
- import com.l2jserver.gameserver.model.entity.Hero;
- +import com.l2jserver.gameserver.model.entity.Kino;
- import com.l2jserver.gameserver.model.entity.TvTManager;
- import com.l2jserver.gameserver.model.olympiad.Olympiad;
- import com.l2jserver.gameserver.network.L2GameClient;
- @@ -379,7 +381,9 @@
- SkillHandler.getInstance();
- UserCommandHandler.getInstance();
- VoicedCommandHandler.getInstance();
- + Kino newKino = new Kino();
- + newKino.startKino();
- if (Config.L2JMOD_ALLOW_WEDDING)
- CoupleManager.getInstance();
- Index: java/com/l2jserver/Config.java
- ===================================================================
- --- java/com/l2jserver/Config.java (revision 54)
- +++ java/com/l2jserver/Config.java (working copy)
- @@ -34,6 +34,7 @@
- import java.net.UnknownHostException;
- import java.util.ArrayList;
- import java.util.Arrays;
- +import java.util.LinkedList;
- import java.util.List;
- import java.util.StringTokenizer;
- import java.util.logging.Level;
- @@ -720,6 +721,14 @@
- public static int L2JMOD_DUALBOX_CHECK_MAX_PLAYERS_PER_IP;
- public static int L2JMOD_DUALBOX_CHECK_MAX_OLYMPIAD_PARTICIPANTS_PER_IP;
- public static TIntIntHashMap L2JMOD_DUALBOX_CHECK_WHITELIST;
- + public static boolean KINO_ALLOWED;
- + public static int KINO_TIME;
- + public static int KINO_ITEM_ID;
- + public static long KINO_ITEM_AMMOUNT;
- + public static int KINO_MAX_NUMBER;
- + public static int KINO_NUMBERS_AMMOUNT;
- + public static List<Integer[]> KINO_PRICE;
- +
- //--------------------------------------------------
- // NPC Settings
- @@ -2475,6 +2484,35 @@
- }
- }
- }
- + KINO_ALLOWED = Boolean.parseBoolean(L2JModSettings.getProperty("KinoAllowed", "False"));
- + KINO_TIME = Integer.parseInt(L2JModSettings.getProperty("KinoTime", "30"));
- + KINO_ITEM_ID = Integer.parseInt(L2JModSettings.getProperty("KinoItemId", "57"));
- + KINO_ITEM_AMMOUNT = Long.parseLong(L2JModSettings.getProperty("KinoItemAmmount", "1000000"));
- + KINO_MAX_NUMBER = Integer.parseInt(L2JModSettings.getProperty("KinoMaxNumber", "80"));
- + KINO_NUMBERS_AMMOUNT = Integer.parseInt(L2JModSettings.getProperty("KinoNumbersAmmount", "4"));
- + if(KINO_ALLOWED){
- + String[] kinoPriceSplit = L2JModSettings.getProperty("KinoPrice", "").split(";");
- + KINO_PRICE = new LinkedList<Integer[]>();
- + for (String number : kinoPriceSplit)
- + {
- + String[] numbersSplit = number.split(",");
- + try
- + {
- + Integer[] numbersTable = new Integer[3];
- + numbersTable[0] = Integer.parseInt(numbersSplit[0]);
- + numbersTable[1] = Integer.parseInt(numbersSplit[1]);
- + numbersTable[2] = Integer.parseInt(numbersSplit[2]);
- + KINO_PRICE.add(numbersTable);
- + }
- + catch (NumberFormatException nfe)
- + {
- + if (!number.isEmpty())
- + {
- + _log.warning(StringUtil.concat("[KinoPriceList]: invalid config property -> Price List \"", numbersSplit[0], "\"", numbersSplit[1], "\"", numbersSplit[3]));
- + }
- + }
- + }
- + }
- }
- catch (Exception e)
- {
- Index: java/com/l2jserver/gameserver/model/entity/Kino.java
- ===================================================================
- --- java/com/l2jserver/gameserver/model/entity/Kino.java (revision 0)
- +++ java/com/l2jserver/gameserver/model/entity/Kino.java (revision 0)
- @@ -0,0 +1,271 @@
- +/*
- + * 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/>.
- + */
- +package com.l2jserver.gameserver.model.entity;
- +
- +import java.sql.Connection;
- +import java.sql.PreparedStatement;
- +import java.sql.ResultSet;
- +import java.util.LinkedList;
- +import java.util.List;
- +
- +import com.l2jserver.Config;
- +import com.l2jserver.L2DatabaseFactory;
- +import com.l2jserver.gameserver.Announcements;
- +import com.l2jserver.gameserver.ThreadPoolManager;
- +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
- +import com.l2jserver.util.StringUtil;
- +
- +/**
- + * @author Vampir
- + *
- + */
- +public class Kino
- +{
- + private static boolean canChoose = false;
- + private static List<Integer[]> choosenNumbers = new LinkedList<Integer[]>();
- + private static List<Integer[]> itemsAlreadyWon = new LinkedList<Integer[]>();
- +
- + private class mainCounter implements Runnable
- + {
- + @Override
- + public void run()
- + {
- + canChoose = false;
- + Integer randomNumbers[] = new Integer[Config.KINO_NUMBERS_AMMOUNT];
- + for(int i=0;i<Config.KINO_NUMBERS_AMMOUNT;i++){
- + boolean check = true;
- + while(check){
- + int liczba = (int) Math.round((Math.random()*(Config.KINO_MAX_NUMBER-1)+1));
- + for(int y = 0;y<i;y++)
- + if(liczba == randomNumbers[y])
- + check = false;;
- + if(check){
- + randomNumbers[i] = liczba;
- + check = false;
- + }else
- + check = true;
- + }
- + };
- + announceNumbers(randomNumbers);
- + try{Thread.sleep(Config.KINO_TIME*1000*2);}catch (InterruptedException e){}
- + getWinners(randomNumbers);
- + announceBestWinners(randomNumbers);
- + try{Thread.sleep(Config.KINO_TIME*1000*2);}catch (InterruptedException e){}
- + choosenNumbers.clear();
- + canChoose = true;
- + Announcements.getInstance().announceToAll("Next period of kino game just Started!");
- + ThreadPoolManager.getInstance().scheduleGeneral(new mainCounter(), (Config.KINO_TIME-2)*1000*60);
- + }
- + }
- +
- + public void goodHtml(L2PcInstance activeChar){
- + NpcHtmlMessage adminReply = new NpcHtmlMessage(10);
- + String qboxes = "";
- + String action = "";
- + for(int i = 0;i<Config.KINO_NUMBERS_AMMOUNT;i++){
- + qboxes += "Number "+ (i+1) +":<edit var=\"number"+ i +"\" width=120 height=15><br>";
- + action += "$number"+ i + " ";
- + }
- + giveItem(activeChar);
- + final StringBuilder replyMSG = StringUtil.startAppend(
- + 1000,
- + "<html><head><title>Kino</title></head><body>",
- + "<br><center>Choose your numbers:</center><br>",
- + qboxes,
- + "<button value=\"Buy Ticket\" action=\"bypass -h kino "+ action +"\" width=65 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">",
- + "<br>P.S. Remember that only numbers from 1 to "+ Config.KINO_MAX_NUMBER +" are allowed to be chosen.",
- + "<br>P.S.S One ticket Cost "+ Config.KINO_ITEM_AMMOUNT + " "+ activeChar.getInventory().getItemByItemId(Config.KINO_ITEM_ID).getName(),
- + "</html></body>"
- + );
- + adminReply.setHtml(replyMSG.toString());
- + activeChar.sendPacket(adminReply);
- + }
- +
- + public void otherHtmls(L2PcInstance activeChar, String msg){
- + giveItem(activeChar);
- + NpcHtmlMessage adminReply = new NpcHtmlMessage(10);
- + final StringBuilder replyMSG = StringUtil.startAppend(
- + 1000,
- + "<html><head><title>Kino</title></head><body>",
- + "<br><center>"+ msg +"</center><br>",
- + "</html></body>"
- + );
- + adminReply.setHtml(replyMSG.toString());
- + activeChar.sendPacket(adminReply);
- + }
- +
- + public boolean alreadyVoted(Integer objectId){
- + for(Integer[] numbers : choosenNumbers)
- + if(numbers[0].equals(objectId))
- + return true;
- + return false;
- + }
- +
- + public void addNumbersByCommand(L2PcInstance activeChar, String command)
- + {
- + Integer[] table = new Integer[Config.KINO_NUMBERS_AMMOUNT];
- + int spaces = 0;
- + int number = 0;
- + int max = 9;
- + if(Config.KINO_MAX_NUMBER<9)
- + max = Config.KINO_MAX_NUMBER;
- + boolean wrong = false;
- + for(int i = 0;i<command.length();i++){
- + try{
- + if(command.substring(i, i+1).equals(" ")){
- + if(command.length()-1 == i || command.substring(i+1, i+2).equals(" "))
- + wrong = true;
- + spaces ++;
- + }else{
- + if(command.length()-1 == i ||command.substring(i+1, i+2).equals(" ")){
- + for(int x = 1;x<=max;x++)
- + if(command.substring(i, i+1).equals(x+""))
- + table[number] = Integer.parseInt(command.substring(i, i+1));
- + }else{
- + for(int x = 10;x<=Config.KINO_MAX_NUMBER;x++){
- + if(command.length()-1 != i+1 && !command.substring(i+2, i+3).equals(" "))
- + wrong = true;
- + if(command.substring(i, i+2).equals(x+""))
- + table[number] = Integer.parseInt(command.substring(i, i+2));
- + }
- + i ++;
- + }
- + if(table[number] != null)
- + number ++;
- + else
- + wrong = true;
- + }
- + }catch(IndexOutOfBoundsException e){
- + wrong = true;
- + }
- + }
- + for(int i = 1;i<table.length;i++)
- + for(int x = 0;x<i;x++)
- + if(table[i] == table[x])
- + wrong = true;
- + if(spaces<=Config.KINO_NUMBERS_AMMOUNT-1 && !wrong){
- + activeChar.getInventory().destroyItem("For Ticket", Config.KINO_ITEM_ID, Config.KINO_ITEM_AMMOUNT, activeChar, this);
- + activeChar.sendMessage("You bought ticket.");
- + addNumbers(activeChar.getObjectId(),table);
- + }else
- + otherHtmls(activeChar, "You gave wrong Numbers!");
- + }
- +
- + private void giveItem(L2PcInstance activeChar){
- + List<Integer[]> tablesToDelete = new LinkedList<Integer[]>();
- + for(Integer[] table : itemsAlreadyWon)
- + if(table[0].equals(activeChar.getObjectId())){
- + activeChar.getInventory().addItem("Winning Item", table[1], table[2], activeChar, this);
- + activeChar.sendMessage("You won: "+ activeChar.getInventory().getItemByItemId(table[1]).getItemName());
- + tablesToDelete.add(table);
- + }
- + for(Integer[] table :tablesToDelete)
- + itemsAlreadyWon.remove(table);
- + }
- +
- + private void addNumbers(Integer objectId, Integer[] numbers){
- + Integer[] tableNumbers = new Integer[Config.KINO_NUMBERS_AMMOUNT+1];
- + tableNumbers[0] = objectId;
- + for(int i = 1;i<=Config.KINO_NUMBERS_AMMOUNT;i++)
- + tableNumbers[i] = numbers[(i-1)];
- + choosenNumbers.add(tableNumbers);
- + }
- +
- + private void announceBestWinners(Integer[] randomNumbers)
- + {
- + String winText = "Winners are: ";
- + int firstTextNumber = winText.length();
- + for(Integer[] numbers : choosenNumbers){
- + int goodNumbers = 0;
- + for(Integer number: numbers)
- + if(numbers[0] != number)
- + for(Integer randomNumber : randomNumbers)
- + if(number == randomNumber)
- + goodNumbers++;
- + if(goodNumbers == Config.KINO_MAX_NUMBER)
- + winText += getWinner(numbers[0]) + ", ";
- + }
- + if(winText.length() > firstTextNumber)
- + Announcements.getInstance().announceToAll(winText.substring(0, winText.length()-1));
- + else
- + Announcements.getInstance().announceToAll("There are no Winners!");
- + }
- +
- + private String getWinner(Integer charId)
- + {
- + String winText = "";
- + Connection con = null;
- + try
- + {
- + con = L2DatabaseFactory.getInstance().getConnection();
- + PreparedStatement statement = con.prepareStatement("SELECT char_name FROM characters WHERE charId="+charId);
- + ResultSet rset = statement.executeQuery();
- + if(rset.next())
- + {
- + winText = rset.getString("char_name");
- + }
- + rset.close();
- + statement.close();
- + }
- + catch (Exception e)
- + {
- + System.out.println("Error at getWinner in Kino.java " +e);
- + }
- + finally
- + {
- + L2DatabaseFactory.close(con);
- + }
- + return winText;
- + }
- +
- + private void announceNumbers(Integer[] randomNumbers)
- + {
- + String message = "Lucky Numbers are: ";
- + for(Integer number: randomNumbers)
- + message += number + ", ";
- + Announcements.getInstance().announceToAll(message);
- + }
- +
- + private void getWinners(Integer[] numbers){
- + for(Integer[] people : choosenNumbers){
- + int goodNumbers = 0;
- + for(int i = 1;i<people.length;i++)
- + for(int y = 0;y<numbers.length;y++)
- + if(people[i] == numbers[y])
- + goodNumbers ++;
- + for(Integer[] items : Config.KINO_PRICE)
- + if(goodNumbers == items[0]){
- + Integer[] table = new Integer[3];
- + table[0] = people[0];
- + table[1] = items[1];
- + table[2] = items[2];
- + itemsAlreadyWon.add(table);
- + }
- + }
- + }
- +
- + public void startKino()
- + {
- + if(Config.KINO_ALLOWED){
- + ThreadPoolManager.getInstance().scheduleGeneral(new mainCounter(), (Config.KINO_TIME-2)*1000*60);
- + canChoose = true;
- + }
- + }
- +
- + public boolean canChoose(){
- + return canChoose;
- + }
- +}
- Index: data/scripts/handlers/MasterHandler.java
- ===================================================================
- --- data/scripts/handlers/MasterHandler.java (revision 7978)
- +++ data/scripts/handlers/MasterHandler.java (working copy)
- @@ -246,12 +247,15 @@
- import handlers.voicedcommandhandlers.Debug;
- import handlers.voicedcommandhandlers.Lang;
- import handlers.voicedcommandhandlers.TvTVoicedInfo;
- +import handlers.voicedcommandhandlers.VoicedKino;
- import handlers.voicedcommandhandlers.Wedding;
- import handlers.voicedcommandhandlers.stats;
- @@ -540,6 +545,8 @@
- private static void loadVoicedHandlers()
- {
- VoicedCommandHandler.getInstance().registerVoicedCommandHandler(new stats());
- + VoicedCommandHandler.getInstance().registerVoicedCommandHandler(new VoicedKino());
- if (Config.L2JMOD_ALLOW_WEDDING)
- VoicedCommandHandler.getInstance().registerVoicedCommandHandler(new Wedding());
- if (Config.BANKING_SYSTEM_ENABLED)
- Index: data/scripts/handlers/voicedcommandhandlers/VoicedKino.java
- ===================================================================
- --- data/scripts/handlers/voicedcommandhandlers/VoicedKino.java (revision 0)
- +++ data/scripts/handlers/voicedcommandhandlers/VoicedKino.java (revision 0)
- @@ -0,0 +1,52 @@
- +/**
- + *
- + */
- +package handlers.voicedcommandhandlers;
- +
- +import com.l2jserver.Config;
- +import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
- +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jserver.gameserver.model.entity.Kino;
- +
- +/**
- + * @author Vampir
- + *
- + */
- +public class VoicedKino implements IVoicedCommandHandler
- +{
- + private final String[] _voicedCommands =
- + {
- + "kino"
- + };
- +
- + /**
- + *
- + * @see com.l2jserver.gameserver.handler.IVoicedCommandHandler#useVoicedCommand(java.lang.String, com.l2jserver.gameserver.model.actor.instance.L2PcInstance, java.lang.String)
- + */
- + public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params)
- + {
- + if (command.equalsIgnoreCase("kino")){
- + Kino x = new Kino();
- + if(x.canChoose())
- + if(!x.alreadyVoted(activeChar.getObjectId()))
- + if(activeChar.getInventory().getItemByItemId(Config.KINO_ITEM_ID) != null && activeChar.getInventory().getItemByItemId(Config.KINO_ITEM_ID).getCount()>= Config.KINO_ITEM_AMMOUNT)
- + x.goodHtml(activeChar);
- + else
- + x.otherHtmls(activeChar,"You do not have enough items to buy ticket.");
- + else
- + x.otherHtmls(activeChar,"You already bought a ticket!");
- + else
- + x.otherHtmls(activeChar,"You can not buy ticket right now!");
- + }
- + return true;
- + }
- +
- + /**
- + *
- + * @see com.l2jserver.gameserver.handler.IVoicedCommandHandler#getVoicedCommandList()
- + */
- + public String[] getVoicedCommandList()
- + {
- + return _voicedCommands;
- + }
- +}
- Index: java/config/l2jmods.properties
- ===================================================================
- --- java/config/l2jmods.properties (revision 54)
- +++ java/config/l2jmods.properties (working copy)
- @@ -426,3 +426,39 @@
- # will be 1+2=3. Use 0 or negative value for unlimited number of connections.
- # Default: 127.0.0.1,0 (no limits from localhost)
- DualboxCheckWhitelist = 127.0.0.1,0
- +
- +
- +# ---------------------------------------------------------------------------
- +# Kino
- +# ---------------------------------------------------------------------------
- +# Do you want to allow Kino games?
- +# Default: False
- +KinoAllowed = True
- +
- +# Time of each period in minutes.
- +# Default: 30
- +KinoTime = 30
- +
- +# Id of item that players need to pay for a ticket.
- +# Default: 57
- +KinoItemId = 57
- +
- +# How much of this items are needed to buy a ticket.
- +# Default: 1000000
- +KinoItemAmmount = 1000000
- +
- +# Whats the max number that players can choose.
- +# Default: 80
- +KinoMaxNumber = 80
- +
- +# How much numbers players have to choose.
- +# Default: 4
- +KinoNumbersAmmount = 4
- +
- +# Prices for each Number. First number mean how much good numbers player had
- +# Second number is Id of item, third is ammount of this item. write \ after
- +# making new line, dont write ; at the end
- +# Example:
- +KinoPrice = 2,57,2500;2,1467,5000;2,1468,200;\
- + 3,57,5000;3,1467,11;\
- + 4,57,33333333;4,1468,444
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement