Randon eventas

    
  1. Atsijungęs

    teampages

    Pranešimai: 0

    Sveiki, turiu toki event isidejas, ir proble yra, kartais zmoniu neiteleportuoja i ta zona, ir tas eventas tesesi amzinai, vaiksto su tom aurom paskiau ir eventas toliau nevyksta.

    Evento kodas:
    /*
    * 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 .
    */
    package com.l2jfrozen.gameserver.model.entity.event;

    import java.util.concurrent.CopyOnWriteArrayList;

    import com.l2jfrozen.Config;
    import com.l2jfrozen.gameserver.datatables.sql.ItemTable;
    import com.l2jfrozen.gameserver.model.L2World;
    import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
    import com.l2jfrozen.gameserver.model.entity.Announcements;
    import com.l2jfrozen.gameserver.model.entity.olympiad.Olympiad;
    import com.l2jfrozen.gameserver.network.serverpackets.ExShowScreenMessage;
    import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
    import com.l2jfrozen.util.random.Rnd;

    /**
    * @author RnP PC
    *
    */
    /*
    * 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 .
    */


    /**
    * @author lioy
    *
    */
    public class RandomFight
    {
    public static enum State{INACTIVE,REGISTER,LOADING,FIGHT}
    public static State state = State.INACTIVE;

    public static CopyOnWriteArrayList players = new CopyOnWriteArrayList<>();

    protected void openRegistrations()
    {
    state = State.REGISTER;
    Announcements.getInstance().announceToAll("Winner reward: " + ItemTable.getInstance().getTemplate(Config.RANDOM_FIGHT_REWARD_ID).getName() + "!");
    Announcements.getInstance().announceToAll("Random Fight Event will start in 10 minute.");
    Announcements.getInstance().announceToAll("To register write ?register");
    Announcements.getInstance().announceToAll("If you wanna unregister write ?unregister");
    ThreadPoolManager.getInstance().scheduleGeneral(new checkRegist(), 60000 );
    }

    protected void checkRegistrations()
    {
    state=State.LOADING;

    if(players.size() < 2)
    {
    // Announcements.getInstance().announceToAll("Random Fight Event will not start cause of no many partitipations, we are sorry.");
    // clean();
    // return;
    for(L2PcInstance player : L2World.getInstance().getAllPlayers())
    {
    if(!players.contains(player) && !player.isInOlympiadMode() && !Olympiad.getInstance().isRegistered(player) && !player.isDead()
    && player.getPrivateStoreType() == L2PcInstance.STORE_PRIVATE_NONE && !player.isProcessingTransaction() && !player.inObserverMode())
    players.add(player);
    }
    if(players.size() < 2)
    {
    Announcements.getInstance().announceToAll("Random Fight Event will not start cause of no many partitipations, we are sorry.");
    clean();
    return;
    }
    }
    Announcements.getInstance().announceToAll("Amount of players Registed: "+players.size());
    Announcements.getInstance().announceToAll("2 Random players will be choosen in 30 seconds!");
    Announcements.getInstance().announceToAll("If you wanna unregister write ?unregister");
    ThreadPoolManager.getInstance().scheduleGeneral(new pickPlayers(), 30000 );
    }


    protected void pickPlayers()
    {
    if(players.size() < 2)
    {
    Announcements.getInstance().announceToAll("Random Fight Event aborted because no many partitipations, we are sorry.");
    clean();
    return;
    }

    for(L2PcInstance p : players)
    if(p.isInOlympiadMode() || Olympiad.getInstance().isRegistered(p))
    {
    players.remove(p);
    p.sendMessage("You automatically left from event because of your olympiad obligations.");
    }


    L2PcInstance p1 = players.get(Rnd.get(players.size()));
    L2PcInstance p2 = players.get(Rnd.get(players.size()));

    while(p1==p2)
    p2=players.get(Rnd.get(players.size()));

    players.clear();
    players.add(p1);
    players.add(p2);

    Announcements.getInstance().announceToAll("Players selected: "+players.get(0).getName()+" || "+players.get(1).getName());
    Announcements.getInstance().announceToAll("Players will be teleported in 15 seconds");
    ThreadPoolManager.getInstance().scheduleGeneral(new teleportPlayers(), 15000);
    }


    protected void teleport()
    {
    if(players.size() < 2)
    {
    Announcements.getInstance().announceToAll("Random Fight Event aborted because no many partitipations, we are sorry.");
    clean();
    return;
    }
    Announcements.getInstance().announceToAll("Players teleported!");

    players.get(0).teleToLocation(113474,15552,3968);
    players.get(1).teleToLocation(112990,15489,3968);
    players.get(0).setTeam(1);
    players.get(1).setTeam(2);

    //para,etc

    players.get(0).sendMessage("Fight will begin in 15 seconds!");
    players.get(1).sendMessage("Fight will begin in 15 seconds!");

    ThreadPoolManager.getInstance().scheduleGeneral(new fight(), 15000);
    }

    protected void startFight()
    {

    if(players.isEmpty() || players.size() < 2)
    {
    Announcements.getInstance().announceToAll("One of the players isn't online, event aborted we are sorry!");
    clean();
    return;
    }

    state = State.FIGHT;

    Announcements.getInstance().announceToAll("FIGHT STARTED!");
    try{
    for(L2PcInstance p : players){
    p.updatePvPFlag(1);
    p.sendPacket(new ExShowScreenMessage("Start Fight!",750));
    Thread.sleep(750);
    p.sendPacket(new ExShowScreenMessage("Kill your enemy!",750));
    Thread.sleep(750);
    p.sendPacket(new ExShowScreenMessage("Reveiwe reward Top-Grade Life Stone: level 76 ",750));
    }
    }catch(Exception e){}
    ThreadPoolManager.getInstance().scheduleGeneral(new checkLast(), 120000 );
    }

    protected void lastCheck()
    {
    if(state == State.FIGHT)
    {
    if(players.size() 0)
    p.setKarma(0);
    p.updatePvPFlag(0);
    p.broadcastUserInfo();
    p.teleToLocation(82698,148638,-3473);

    }
    }

    public static void clean()
    {

    if(state == State.FIGHT)
    for(L2PcInstance p : players)
    p.setTeam(0);


    players.clear();
    state = State.INACTIVE;

    }

    protected RandomFight()
    {
    ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new Event(), 60000 * Config.EVERY_MINUTES , 60000 * Config.EVERY_MINUTES);
    }

    public static RandomFight getInstance()
    {
    return SingletonHolder._instance;
    }

    private static class SingletonHolder
    {
    protected static final RandomFight _instance = new RandomFight();
    }

    protected class Event implements Runnable
    {
    @Override
    public void run()
    {
    if(state == State.INACTIVE)
    openRegistrations();
    }

    }

    protected class checkRegist implements Runnable
    {

    @Override
    public void run()
    {
    checkRegistrations();
    }

    }

    protected class pickPlayers implements Runnable
    {
    @Override
    public void run()
    {
    pickPlayers();
    }

    }

    protected class teleportPlayers implements Runnable
    {
    @Override
    public void run()
    {
    teleport();
    }

    }

    protected class fight implements Runnable
    {

    @Override
    public void run()
    {
    startFight();
    }

    }

    protected class checkLast implements Runnable
    {
    @Override
    public void run()
    {
    lastCheck();
    }

    }
    }



    Gal zinot kur problema?
    Paskutinį kartą redagavo: teampages 4 Lapkričio 2015 - 03:55
    4 Lapkričio 2015 - 03:55 / #1
  2. 
  3. Atsijungęs

    wewewe

    Pavadinimas: L2 žaidėjas

    Narys

    Pranešimai: 727

    Vartotojo apdovanojimai: 16

    panasu, kad kodas rasytas protine negalia turincio penkiamecio. Tikriausiai del to ir grybauja...
    4 Lapkričio 2015 - 11:01 / #2
  4. 
  5. Atsijungęs

    teampages

    Pranešimai: 0

    Pasakyk kaip sutvarkyti nrml tada
    5 Lapkričio 2015 - 07:11 / #3
  6. 
  7. Atsijungęs

    wewewe

    Pavadinimas: L2 žaidėjas

    Narys

    Pranešimai: 727

    Vartotojo apdovanojimai: 16

    Evento steitas static, playeriu listas static, kodas multithreaded ir singleton patternas neteisingai padarytas... nu va del to greiciausiai ir kyla bedos. Padaryk pati evento koda normaliai be jokiu static nesamoniu, prilipdyk jam singleton patterna ir padaryk atskira sito evento manageri, kuris tik perjungines evento steitus. Pats eventas turi zinot kas atsitinka pasikeitus jo steitui is vieno i kita.
    5 Lapkričio 2015 - 14:30 / #4
  8. 
  9. Atsijungęs

    teampages

    Pranešimai: 0

    Prijimk skype: teampages. :) sumokesiu banko prvedimu :
    6 Lapkričio 2015 - 04:29 / #5