Noticias:

Debes de estar registrado para poder ver el contenido indicado. Registrate o Conectate

Menú Principal

Evento Recompensa PvP Zone por tiempo

Iniciado por Swarlog, Ago 06, 2022, 02:14 AM

Tema anterior - Siguiente tema

Swarlog


Cada 1 hora se reinicia el evento y se inicia una nueva ronda.
Al final del periodo el tipo que tiene la mayoría de pvp dentro de la zona que ha configurado obtiene una recompensa que es totalmente su negocio va a establecer.

Aquí está el núcleo de la función:
Código (javascript) [Seleccionar]
/*

* 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 net.sf.l2j.gameserver.model.events;



import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.util.Calendar;

import java.util.Date;



import net.sf.l2j.L2DatabaseFactory;

import net.sf.l2j.gameserver.Announcements;

import net.sf.l2j.gameserver.ThreadPoolManager;

import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;

import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;



/**

* @author Elfocrash

*

*/

public class PlayerOfTheHour

{



public static long getTimeToOclock()

{

Date d = new Date();

  Calendar c = Calendar.getInstance();

    c.setTime(d);



   

        c.add(Calendar.HOUR, 1);



    c.set(Calendar.MINUTE, 0);

    c.set(Calendar.SECOND, 0);

  // System.out.print(c.getTime());

    long howMany = (c.getTimeInMillis()-d.getTime());

        return howMany;

}



public static String getNextHourToDate()

{

Date d = new Date();

  Calendar c = Calendar.getInstance();

    c.setTime(d);

    c.add(Calendar.HOUR, 1);

   

   

      return c.getTime().toString();

}

public static String getTimeToDate()

{

Date d = new Date();

  Calendar c = Calendar.getInstance();

    c.setTime(d);



   

        c.add(Calendar.HOUR, 1);



    c.set(Calendar.MINUTE, 0);

    c.set(Calendar.SECOND, 0);

   

   

        return c.getTime().toString();

}

public static int getZonePvp(L2PcInstance activeChar)

{

int id=0;

try (Connection con = L2DatabaseFactory.getInstance().getConnection())

{

PreparedStatement statement = con.prepareStatement("SELECT zone_pvp FROM characters WHERE obj_Id=?");

statement.setInt(1, activeChar.getObjectId());

ResultSet rset = statement.executeQuery();



while (rset.next())

{

id = rset.getInt("zone_pvp");

}

rset.close();

statement.close();

}

catch (Exception e)

{

}

return id;

}



public static void addZonePvp(L2PcInstance activeChar)

{

try(Connection con = L2DatabaseFactory.getInstance().getConnection())

{

PreparedStatement statement = con.prepareStatement("UPDATE characters SET zone_pvp=? WHERE obj_Id=?");

statement.setInt(1, getZonePvp(activeChar) +1);

statement.setInt(2, activeChar.getObjectId());

statement.executeUpdate();

statement.close();

}

catch(Exception e)

{



}

}



public static void resetZonePvp()

{

try(Connection con = L2DatabaseFactory.getInstance().getConnection())

{

PreparedStatement statement = con.prepareStatement("UPDATE characters SET zone_pvp=0");

statement.executeUpdate();

statement.close();

}

catch(Exception e)

{



}

}



static int getTopZonePvpCount()

{

int id=0;

try (Connection con = L2DatabaseFactory.getInstance().getConnection())

{

PreparedStatement statement = con.prepareStatement("SELECT zone_pvp FROM characters ORDER BY zone_pvp DESC LIMIT 1");

ResultSet rset = statement.executeQuery();



while (rset.next())

{

id = rset.getInt("zone_pvp");

}

rset.close();

statement.close();

}

catch (Exception e)

{

}

return id;

}



static String getTopZonePvpName()

{

String name = null;

try (Connection con = L2DatabaseFactory.getInstance().getConnection())

{

PreparedStatement statement = con.prepareStatement("SELECT char_name FROM characters ORDER BY zone_pvp DESC LIMIT 1");

ResultSet rset = statement.executeQuery();



while (rset.next())

{

name = rset.getString("char_name");

}

rset.close();

statement.close();

}

catch (Exception e)

{

}

return name;

}



private PlayerOfTheHour()

{



}

public static void getTopHtml(L2PcInstance activeChar)

{

  NpcHtmlMessage htm = new NpcHtmlMessage(0);

    StringBuilder sb = new StringBuilder("<html><body>");

    sb.append("<center><br>Top 10 PvP:<br><br1>");

    Connection con = null;

            try

            {

              con = L2DatabaseFactory.getInstance().getConnection();

              PreparedStatement stm = con.prepareStatement("SELECT char_name,zone_pvp,accesslevel,online FROM characters ORDER BY zone_pvp DESC LIMIT 10");

              ResultSet rSet = stm.executeQuery();

              while (rSet.next())

              {

              int accessLevel = rSet.getInt("accesslevel");

              if (accessLevel > 0)

              {

                continue;

              }

              int pvpKills = rSet.getInt("zone_pvp");

              if (pvpKills == 0)

              {

                continue;

              }

              String pl = rSet.getString("char_name");

              sb.append("Player: <font color=\"LEVEL\">"+pl+"</font> PvPs: <font color=\"LEVEL\">"+pvpKills+"</font><br1>");

              }

            }

            catch (Exception e)

            {

              System.out.println("Error while selecting top 15 pvp from database.");

            }

            finally

            {

              try

              {

              if (con != null)

                con.close();

              }

              catch (Exception e)

              {}

            }

            sb.append("Next round: " + getTimeToDate() +"</body></html>");

            htm.setHtml(sb.toString());

            activeChar.sendPacket(htm);

  }



    public static void getInstance()

    {

   

        ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new Runnable()

        {

            @Override

           

            public void run()

            {

           

            Announcements.announceToAll("The Player of the Hour is " + getTopZonePvpName() + " with "+getTopZonePvpCount()+ " pvps");

            //TODO Your reward should go here.

            resetZonePvp();

            Announcements.announceToAll("New Player of the Hour just started. Go to Primeval Isle and show us what you got.");

Announcements.announceToAll("This round will end at: " + getNextHourToDate() + ".");

            }

        }, getTimeToOclock() ,  3600000);

    }

   

   

}

Usted también necesitará este VoicedCommand con el fin de comprobar el ranking de esta hora. El comando es .zonepvp.
Código (javascript) [Seleccionar]
/*

* 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 net.sf.l2j.gameserver.handler.voicedcommandhandlers;



import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;

import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;

import net.sf.l2j.gameserver.model.events.PlayerOfTheHour;





public class ZonePvp implements IVoicedCommandHandler

{

private static final String[] _voicedCommands = { "zonepvp"};





@Override

public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)

{



if(command.equals(_voicedCommands[0]))

{

PlayerOfTheHour.getTopHtml(activeChar);



}

return true;

}



@Override

public String[] getVoicedCommandList()

{

return _voicedCommands;

}

}

También es necesario para hacer sus increasePvpKills () método siguiente aspecto:
Código (javascript) [Seleccionar]
public void increasePvpKills()

{

// Add karma to attacker and increase its PK counter

setPvpKills(getPvpKills() + 1);



if(isInsideZone(ZoneId.ZONE_PVP))

PlayerOfTheHour.addZonePvp(this);



// Send a Server->Client UserInfo packet to attacker with its Karma and PK Counter

sendPacket(new UserInfo(this));

}

Por fin lo que necesita esta zona. No te olvides de registrarlo en idDeZona:
Código (javascript) [Seleccionar]
/*

* 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 net.sf.l2j.gameserver.model.zone.type;



import net.sf.l2j.gameserver.model.actor.L2Character;

import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;

import net.sf.l2j.gameserver.model.zone.L2SpawnZone;

import net.sf.l2j.gameserver.model.zone.ZoneId;

import net.sf.l2j.gameserver.network.SystemMessageId;



/**

* An arena

* @author durgus

*/

public class L2ZonePvpZone extends L2SpawnZone

{

public L2ZonePvpZone(int id)

{

super(id);

}



@Override

protected void onEnter(L2Character character)

{

if (character instanceof L2PcInstance)

{

((L2PcInstance) character).sendMessage("You are now inside the Player of the Hour Zone.");

}



character.setInsideZone(ZoneId.ZONE_PVP, true);

character.setInsideZone(ZoneId.NO_SUMMON_FRIEND, true);

}



@Override

protected void onExit(L2Character character)

{

character.setInsideZone(ZoneId.ZONE_PVP, false);

character.setInsideZone(ZoneId.NO_SUMMON_FRIEND, false);



if (character instanceof L2PcInstance)

{

((L2PcInstance) character).sendMessage("You are no longer inside the Player of the Hour Zone.");

}

}



@Override

public void onDieInside(L2Character character)

{

}



@Override

public void onReviveInside(L2Character character)

{

}

}

Por último es necesario agregar esto en gameserver:
Código (javascript) [Seleccionar]
PlayerOfTheHour.getInstance();
Credito: Elfocrash