(https://www.united-extreme.com/u3games/comunidades/l2/index.php?action=dlattach;topic=410.0;attach=276)
Consiste en un evento que se activa de forma automática cada hora, en donde el jugador con más combates ganados en una zona pvp es anunciado y ganador del evento.
Se puede configurar, así que puedes modificar la zona pvp, tiempo, etc.. el código es algo antiguo, pero merece la pena este evento.
CitarPlayerOfTheHour.java
/*
* 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);
}
}
CitarZonePvp.java
/*
* 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;
}
}
A tener en cuenta estos parámetros:
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));
}
CitarL2ZonePvpZone.java
Para la creación de la zona pvp:
/*
* 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)
{
}
}
Citargameserver.java
Añadir la siguiente línea para la activación del evento:
PlayerOfTheHour.getInstance();
y Listo! Creditos: Elfocrash