Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Eclipse Workspace Patch 1.0
- #P TEST_GAMESERVER
- Index: java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (revision 4699)
- +++ java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (working copy)
- @@ -452,6 +452,11 @@
- private boolean _noble = false;
- private boolean _hero = false;
- + private boolean _dice = false;
- +
- +
- +
- + private int nums;
- /** The L2FolkInstance corresponding to the last Folk wich one the player talked. */
- private L2FolkInstance _lastFolkNpc = null;
- @@ -8215,6 +8220,22 @@
- return true;
- }
- + public boolean isDice()
- + {
- + return _dice;
- + }
- +
- + public void setDice(boolean y){
- + _dice = y;
- + }
- +
- + public int getNum(){
- + return nums;
- + }
- +
- + public void setNum(int n){
- + nums = n;
- + }
- public boolean isNoble()
- {
- return _noble;
- Index: java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/Random.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/Random.java (revision 0)
- +++ java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/Random.java (revision 0)
- @@ -0,0 +1,59 @@
- +/* 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 2, 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, write to the Free Software
- + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- + * 02111-1307, USA.
- + *
- + * http://www.gnu.org/copyleft/gpl.html
- + */
- +package net.sf.l2j.gameserver.handler.voicedcommandhandlers;
- +
- +import java.util.StringTokenizer;
- +
- +import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
- +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- +
- +/**
- + *
- + * @author Codex
- + */
- +public class Random implements IVoicedCommandHandler
- +{
- + private static final String[] VOICED_COMMANDS = { "dice"};
- +
- + public boolean useVoicedCommand(String command, L2PcInstance activeChar,String target){
- + if(command.startsWith("dice")){
- + String val = command.substring(4);
- + StringTokenizer st = new StringTokenizer(val);
- + int num = Integer.parseInt(st.nextToken());
- +
- + if(!activeChar.isDice())
- + {
- + activeChar.sendMessage("You can't press this command now,you are out of the event");
- + return false;
- + }
- +
- + if(num >= 1 && num <= 8)
- + {
- + activeChar.sendMessage("You successfully voted for this round!");
- + activeChar.setNum(num);
- + }
- + }
- + return true;
- + }
- +
- +
- + public String[] getVoicedCommandList(){
- + return VOICED_COMMANDS;
- + }
- +
- +}
- Index: java/net/sf/l2j/gameserver/model/entity/RandomEvent.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/model/entity/RandomEvent.java (revision 0)
- +++ java/net/sf/l2j/gameserver/model/entity/RandomEvent.java (revision 0)
- @@ -0,0 +1,229 @@
- +/* 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 2, 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, write to the Free Software
- + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- + * 02111-1307, USA.
- + *
- + * http://www.gnu.org/copyleft/gpl.html
- + */
- +package net.sf.l2j.gameserver.model.entity;
- +
- +import java.util.Random;
- +
- +import net.sf.l2j.gameserver.Announcements;
- +import net.sf.l2j.gameserver.ThreadPoolManager;
- +import net.sf.l2j.gameserver.model.L2World;
- +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- +
- +import javolution.util.FastList;
- +
- +/**
- + *
- + * @author Codex
- + */
- +public class RandomEvent
- +{
- + Random dice = new Random();
- + FastList <Integer> _numbers = new FastList <Integer>();
- + static FastList <L2PcInstance> _players = new FastList <L2PcInstance>();
- + public static boolean canRegist = false;
- + int number;
- + boolean running = false;
- +
- + class ReTask implements Runnable {
- + public void run()
- + {
- + if(running) return;
- +
- + handle();
- + }
- +
- + }
- +
- + void handle(){
- + running = true;
- + setCanRegist(true);
- + globalMessage("Random Event Registering Started, you have 15 minutes go register..");
- + waitMinutes(10);
- + globalMessage("Random Event Registering Finishing in 5 minutes...go and register fast");
- + waitMinutes(5);
- + globalMessage("Registrations Finished, event starts in 30 seconds");
- + setCanRegist(false);
- + generateNums();
- + waitSeconds(30);
- + takeStatusVote();
- + while(_players.size() > 1){
- + globalMessage("You can now press .dice 1/2/3/4/5/6/7/8 , you have 20 seconds,Hurry up!");
- + waitSeconds(20);
- + checkAfkers();
- + announceNumber();
- + globalMessage("The Global Random Number is: "+announceNumber());
- + checkNumbers();
- + }
- + rewarding();
- + running = false;
- +
- + }
- +
- + void generateNums() {
- + int counter = 1;
- + while( counter < 9){
- + number = 1 + dice.nextInt(8);
- + _numbers.add(number);
- + counter ++ ;
- + }
- + }
- +
- + void clear(){
- + _numbers.clear();
- + _players.clear();
- + for(L2PcInstance x: L2World.getInstance().getAllPlayers())
- + x.setNum(0);
- + }
- + public static void register(L2PcInstance p){
- + setCanRegist(true);
- +
- + if(!canRegist){
- + p.sendMessage("Event is closed now.");
- + return;
- + }
- + if(_players.contains(p)){
- + p.sendMessage("You can't register because you are already in the list");
- + return;
- + }
- +
- + if(p.isOlympiadStart() || p.isInOlympiadMode()){
- + p.sendMessage("You can't register during olympiad match");
- + return;
- + }
- +
- + _players.add(p);
- + p.sendMessage("You have successfully registed in the random event");
- + }
- +
- + public static void unRegister(L2PcInstance p){
- + if(!_players.contains(p)){
- + p.sendMessage("You can't unregister because you are not in the list");
- + return;
- + }
- +
- + if(!canRegist){
- + p.sendMessage("Event is closed now.");
- + return;
- + }
- +
- + _players.remove(p);
- + p.sendMessage("You have successfully unregisted from the random event");
- + }
- +
- + public void checkEmpty(){
- + if(_players.isEmpty() || _players.size() == 1){
- + globalMessage("Event Canceled during of no participations.");
- + }
- + }
- +
- + public void waitSeconds(int i){
- + try{
- + Thread.sleep(i * 1000);
- + }
- + catch (Exception e ){
- + e.printStackTrace();
- + }
- + }
- +
- + public void waitMinutes(int i){
- + try{
- + Thread.sleep(i * 60000);
- + }
- + catch (Exception e ){
- + e.printStackTrace();
- + }
- + }
- +
- + public void takeStatusVote(){
- + for(L2PcInstance p : _players){
- + p.sendMessage("You can now press .dice 1/2/3/4/5/6/7/8!");
- + p.setDice(true);
- + }
- + }
- +
- + public void checkAfkers(){
- + for(L2PcInstance p: _players){
- + if(p.getNum() == 0){
- + _players.remove(p);
- + }
- + }
- + }
- +
- + public void globalMessage(String s ){
- + Announcements.getInstance().announceToAll(s);
- + }
- +
- + public int announceNumber() {
- + return _numbers.get(1+dice.nextInt(8));
- + }
- +
- + public void checkNumbers(){
- + for(L2PcInstance p : _players){
- + if(p.getNum() != announceNumber()){
- + p.sendMessage("We are sorry, you lost...you are out of the event now");
- + _players.remove(p);
- + }
- + else {
- + p.sendMessage("wOw!!You continue the event now...");
- + }
- + if(_players.size() == 0){
- + globalMessage("No-one answered correctly, round redo");
- + for(L2PcInstance pl : L2World.getInstance().getAllPlayers()){
- + if(pl.getNum() > 0){
- + _players.add(pl);
- + }
- + }
- +
- + }
- + }
- + }
- +
- + public void rewarding(){
- + for(L2PcInstance p: _players){
- + if(_players.contains(p) && _players.size() == 1){
- + p.sendMessage("You won the event!!!!!!Now you are rewarding!!");
- + globalMessage(p.getName()+" won the Random Event");
- + p.getInventory().addItem("Winner", 3481, 25, p, null);
- + p.broadcastUserInfo();
- + }
- + }
- + }
- +
- +
- +
- + public static void setCanRegist(boolean x)
- + {
- + canRegist = x;
- + }
- +
- + private RandomEvent()
- + {
- + ThreadPoolManager.getInstance().scheduleGeneral(new ReTask(), 10800000);
- + }
- +
- + public static RandomEvent getInstance()
- + {
- + return SingletonHolder._instance;
- + }
- +
- + private static class SingletonHolder
- + {
- + @SuppressWarnings("synthetic-access")
- + protected static final RandomEvent _instance = new RandomEvent();
- + }
- +}
- Index: java/net/sf/l2j/gameserver/model/actor/instance/L2RandomInstance.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/model/actor/instance/L2RandomInstance.java (revision 0)
- +++ java/net/sf/l2j/gameserver/model/actor/instance/L2RandomInstance.java (revision 0)
- @@ -0,0 +1,44 @@
- +/* 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 2, 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, write to the Free Software
- + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- + * 02111-1307, USA.
- + *
- + * http://www.gnu.org/copyleft/gpl.html
- + */
- +package net.sf.l2j.gameserver.model.actor.instance;
- +
- +import net.sf.l2j.gameserver.model.entity.RandomEvent;
- +import net.sf.l2j.gameserver.templates.L2NpcTemplate;
- +
- +/**
- + *
- + * @author Codex
- + */
- +public class L2RandomInstance extends L2NpcInstance
- +{
- +
- + public L2RandomInstance(int objectId, L2NpcTemplate template)
- + {
- + super(objectId, template);
- + }
- +
- + public void onBypassFeedback(L2PcInstance player , String command ){
- + if(command.startsWith("unregister")){
- + RandomEvent.unRegister(player);
- + }
- + else if(command.startsWith("register")){
- + RandomEvent.register(player);
- + }
- + }
- +
- +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement