Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Eclipse Workspace Patch 1.0
- #P CodingTime
- Index: gameserver/head-src/com/l2jfrozen/gameserver/network/clientpackets/RequestBypassToServer.java
- ===================================================================
- --- gameserver/head-src/com/l2jfrozen/gameserver/network/clientpackets/RequestBypassToServer.java (revision 931)
- +++ gameserver/head-src/com/l2jfrozen/gameserver/network/clientpackets/RequestBypassToServer.java (working copy)
- @@ -37,6 +37,7 @@
- import com.l2jfrozen.gameserver.model.actor.position.L2CharPosition;
- import com.l2jfrozen.gameserver.model.entity.event.CTF;
- import com.l2jfrozen.gameserver.model.entity.event.DM;
- +import com.l2jfrozen.gameserver.model.entity.event.Kino;
- import com.l2jfrozen.gameserver.model.entity.event.L2Event;
- import com.l2jfrozen.gameserver.model.entity.event.TvT;
- import com.l2jfrozen.gameserver.model.entity.event.VIP;
- @@ -127,6 +128,11 @@
- {
- playerHelp(activeChar, _command.substring(12));
- }
- + else if (_command.startsWith("kino"))
- + {
- + Kino newKino = new Kino();
- + newKino.addNumbersByCommand(activeChar,_command.substring(5));
- + }
- else if(_command.startsWith("npc_"))
- {
- if(!activeChar.validateBypass(_command))
- Index: gameserver/config/functions/l2jfrozen.properties
- ===================================================================
- --- gameserver/config/functions/l2jfrozen.properties (revision 931)
- +++ gameserver/config/functions/l2jfrozen.properties (working copy)
- @@ -280,4 +280,38 @@
- ProtectorSkillLevel = 13
- ProtectorSkillTime = 600
- # Npc Protector Message
- -ProtectorMessage = Hey You!, Never Kill On This Area, Go Read The Rules!
- \ No newline at end of file
- +ProtectorMessage = Hey You!, Never Kill On This Area, Go Read The Rules!
- +
- +# ---------------------------------------------------------------------------
- +# Kino
- +# ---------------------------------------------------------------------------
- +# Do you want to allow Kino games?
- +# Default: False
- +KinoAllowed = True
- +
- +# Time of each period in minutes.
- +# Default: 30
- +KinoTime = 5
- +
- +# 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
- \ No newline at end of file
- Index: gameserver/head-src/com/l2jfrozen/Config.java
- ===================================================================
- --- gameserver/head-src/com/l2jfrozen/Config.java (revision 931)
- +++ gameserver/head-src/com/l2jfrozen/Config.java (working copy)
- @@ -33,6 +33,7 @@
- import java.net.UnknownHostException;
- import java.util.ArrayList;
- import java.util.HashMap;
- +import java.util.LinkedList;
- import java.util.List;
- import java.util.Map;
- import java.util.Properties;
- @@ -2378,6 +2379,14 @@
- public static String FARM2_CUSTOM_MESSAGE;
- public static String PVP1_CUSTOM_MESSAGE;
- public static String PVP2_CUSTOM_MESSAGE;
- +
- + public static boolean KINO_ALLOWED;
- + public static int KINO_TIME;
- + public static int KINO_ITEM_ID;
- + public static int KINO_ITEM_AMMOUNT;
- + public static int KINO_MAX_NUMBER;
- + public static int KINO_NUMBERS_AMMOUNT;
- + public static List<Integer[]> KINO_PRICE;
- //============================================================
- public static void loadL2JFrozenConfig()
- @@ -2497,6 +2506,36 @@
- FARM2_CUSTOM_MESSAGE = L2JFrozenSettings.getProperty("Farm2CustomMeesage", "You have been teleported to Farm Zone 2!");
- PVP1_CUSTOM_MESSAGE = L2JFrozenSettings.getProperty("PvP1CustomMeesage", "You have been teleported to PvP Zone 1!");
- PVP2_CUSTOM_MESSAGE = L2JFrozenSettings.getProperty("PvP2CustomMeesage", "You have been teleported to PvP Zone 2!");
- +
- + KINO_ALLOWED = Boolean.parseBoolean(L2JFrozenSettings.getProperty("KinoAllowed", "True"));
- + KINO_TIME = Integer.parseInt(L2JFrozenSettings.getProperty("KinoTime", "30"));
- + KINO_ITEM_ID = Integer.parseInt(L2JFrozenSettings.getProperty("KinoItemId", "57"));
- + KINO_ITEM_AMMOUNT = Integer.parseInt(L2JFrozenSettings.getProperty("KinoItemAmmount", "1000000"));
- + KINO_MAX_NUMBER = Integer.parseInt(L2JFrozenSettings.getProperty("KinoMaxNumber", "80"));
- + KINO_NUMBERS_AMMOUNT = Integer.parseInt(L2JFrozenSettings.getProperty("KinoNumbersAmmount", "4"));
- + if(KINO_ALLOWED){
- + String[] kinoPriceSplit = L2JFrozenSettings.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: gameserver/head-src/com/l2jfrozen/gameserver/model/entity/event/Kino.java
- ===================================================================
- --- gameserver/head-src/com/l2jfrozen/gameserver/model/entity/event/Kino.java (revision 0)
- +++ gameserver/head-src/com/l2jfrozen/gameserver/model/entity/event/Kino.java (revision 0)
- @@ -0,0 +1,274 @@
- +/*
- + * 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.l2jfrozen.gameserver.model.entity.event;
- +
- +import java.sql.Connection;
- +import java.sql.PreparedStatement;
- +import java.sql.ResultSet;
- +import java.util.LinkedList;
- +import java.util.List;
- +
- +import com.l2jfrozen.Config;
- +import com.l2jfrozen.util.database.L2DatabaseFactory;
- +import com.l2jfrozen.gameserver.model.entity.Announcements;
- +import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
- +import com.l2jfrozen.gameserver.model.PcInventory;
- +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
- +import com.l2jfrozen.util.StringUtil;
- +
- +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("Ticket",Config.KINO_ITEM_ID, Config.KINO_ITEM_AMMOUNT, activeChar, null);
- + 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, null);
- + 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;
- + }
- +}
- \ No newline at end of file
- Index: gameserver/head-src/com/l2jfrozen/gameserver/GameServer.java
- ===================================================================
- --- gameserver/head-src/com/l2jfrozen/gameserver/GameServer.java (revision 931)
- +++ gameserver/head-src/com/l2jfrozen/gameserver/GameServer.java (working copy)
- @@ -117,6 +117,7 @@
- import com.l2jfrozen.gameserver.model.PartyMatchWaitingList;
- import com.l2jfrozen.gameserver.model.entity.Announcements;
- import com.l2jfrozen.gameserver.model.entity.Hero;
- +import com.l2jfrozen.gameserver.model.entity.event.Kino;
- import com.l2jfrozen.gameserver.model.entity.MonsterRace;
- import com.l2jfrozen.gameserver.model.entity.event.manager.EventManager;
- import com.l2jfrozen.gameserver.model.entity.olympiad.Olympiad;
- @@ -534,6 +535,10 @@
- Util.printSection("EventManager");
- EventManager.getInstance().startEventRegistration();
- + Kino newKino = new Kino();
- + newKino.startKino();
- + _log.info("Kino event is currently running");
- +
- if(EventManager.TVT_EVENT_ENABLED || EventManager.CTF_EVENT_ENABLED || EventManager.DM_EVENT_ENABLED)
- {
- if(EventManager.TVT_EVENT_ENABLED)
- Index: gameserver/head-src/com/l2jfrozen/gameserver/handler/voicedcommandhandlers/VoicedKino.java
- ===================================================================
- --- gameserver/head-src/com/l2jfrozen/gameserver/handler/voicedcommandhandlers/VoicedKino.java (revision 0)
- +++ gameserver/head-src/com/l2jfrozen/gameserver/handler/voicedcommandhandlers/VoicedKino.java (revision 0)
- @@ -0,0 +1,52 @@
- +/**
- + *
- + */
- +package com.l2jfrozen.gameserver.handler.voicedcommandhandlers;
- +
- +import com.l2jfrozen.Config;
- +import com.l2jfrozen.gameserver.handler.IVoicedCommandHandler;
- +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jfrozen.gameserver.model.entity.event.Kino;
- +
- +
- +
- +public class VoicedKino implements IVoicedCommandHandler
- +{
- + private final String[] _voicedCommands =
- + {
- + "kino"
- + };
- +
- + /**
- + *
- + * @see com.l2jfrozen.gameserver.handler.IVoicedCommandHandler#useVoicedCommand(java.lang.String, com.l2jfrozen.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.l2jfrozen.gameserver.handler.IVoicedCommandHandler#getVoicedCommandList()
- + */
- + public String[] getVoicedCommandList()
- + {
- + return _voicedCommands;
- + }
- +}
- \ No newline at end of file
- Index: gameserver/head-src/com/l2jfrozen/gameserver/handler/VoicedCommandHandler.java
- ===================================================================
- --- gameserver/head-src/com/l2jfrozen/gameserver/handler/VoicedCommandHandler.java (revision 931)
- +++ gameserver/head-src/com/l2jfrozen/gameserver/handler/VoicedCommandHandler.java (working copy)
- @@ -34,6 +34,7 @@
- import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.StatsCmd;
- import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.TvTCmd;
- import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.VersionCmd;
- +import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.VoicedKino;
- import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.Voting;
- import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.Wedding;
- @@ -65,6 +66,7 @@
- _datatable = new FastMap<String, IVoicedCommandHandler>();
- registerVoicedCommandHandler( new Voting());
- + registerVoicedCommandHandler( new VoicedKino());
- if(Config.BANKING_SYSTEM_ENABLED)
- {
Advertisement
Add Comment
Please, Sign In to add comment