Project update.

This commit is contained in:
MobiusDev
2015-12-31 23:53:41 +00:00
parent e0d681a17e
commit ad2bcd79be
4084 changed files with 83696 additions and 86998 deletions

View File

@ -0,0 +1,505 @@
/*
* This file is part of the L2J Mobius project.
*
* 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.l2jmobius.gameserver.model.olympiad;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.ai.CtrlIntention;
import com.l2jmobius.gameserver.instancemanager.AntiFeedManager;
import com.l2jmobius.gameserver.instancemanager.CastleManager;
import com.l2jmobius.gameserver.instancemanager.FortManager;
import com.l2jmobius.gameserver.model.L2Party;
import com.l2jmobius.gameserver.model.L2Party.messageType;
import com.l2jmobius.gameserver.model.Location;
import com.l2jmobius.gameserver.model.actor.L2Character;
import com.l2jmobius.gameserver.model.actor.L2Summon;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.entity.TvTEvent;
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
import com.l2jmobius.gameserver.model.skills.Skill;
import com.l2jmobius.gameserver.model.zone.type.L2OlympiadStadiumZone;
import com.l2jmobius.gameserver.network.SystemMessageId;
import com.l2jmobius.gameserver.network.serverpackets.ExOlympiadMode;
import com.l2jmobius.gameserver.network.serverpackets.InventoryUpdate;
import com.l2jmobius.gameserver.network.serverpackets.L2GameServerPacket;
import com.l2jmobius.gameserver.network.serverpackets.SkillCoolTime;
import com.l2jmobius.gameserver.network.serverpackets.SystemMessage;
/**
* @author godson, GodKratos, Pere, DS
*/
public abstract class AbstractOlympiadGame
{
protected static final Logger _log = Logger.getLogger(AbstractOlympiadGame.class.getName());
protected static final Logger _logResults = Logger.getLogger("olympiad");
protected static final String POINTS = "olympiad_points";
protected static final String COMP_DONE = "competitions_done";
protected static final String COMP_WON = "competitions_won";
protected static final String COMP_LOST = "competitions_lost";
protected static final String COMP_DRAWN = "competitions_drawn";
protected static final String COMP_DONE_WEEK = "competitions_done_week";
protected static final String COMP_DONE_WEEK_CLASSED = "competitions_done_week_classed";
protected static final String COMP_DONE_WEEK_NON_CLASSED = "competitions_done_week_non_classed";
protected static final String COMP_DONE_WEEK_TEAM = "competitions_done_week_team";
protected long _startTime = 0;
protected boolean _aborted = false;
protected final int _stadiumID;
protected AbstractOlympiadGame(int id)
{
_stadiumID = id;
}
public final boolean isAborted()
{
return _aborted;
}
public final int getStadiumId()
{
return _stadiumID;
}
protected boolean makeCompetitionStart()
{
_startTime = System.currentTimeMillis();
return !_aborted;
}
protected final void addPointsToParticipant(Participant par, int points)
{
par.updateStat(POINTS, points);
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_HAS_EARNED_S2_POINTS_IN_THE_OLYMPIAD_GAMES);
sm.addString(par.getName());
sm.addInt(points);
broadcastPacket(sm);
}
protected final void removePointsFromParticipant(Participant par, int points)
{
par.updateStat(POINTS, -points);
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_HAS_LOST_S2_POINTS_IN_THE_OLYMPIAD_GAMES);
sm.addString(par.getName());
sm.addInt(points);
broadcastPacket(sm);
}
/**
* Function return null if player passed all checks or SystemMessage with reason for broadcast to opponent(s).
* @param player
* @return
*/
protected static SystemMessage checkDefaulted(L2PcInstance player)
{
if ((player == null) || !player.isOnline())
{
return SystemMessage.getSystemMessage(SystemMessageId.YOUR_OPPONENT_MADE_HASTE_WITH_THEIR_TAIL_BETWEEN_THEIR_LEGS);
}
if ((player.getClient() == null) || player.getClient().isDetached())
{
return SystemMessage.getSystemMessage(SystemMessageId.YOUR_OPPONENT_MADE_HASTE_WITH_THEIR_TAIL_BETWEEN_THEIR_LEGS);
}
// safety precautions
if (player.inObserverMode() || TvTEvent.isPlayerParticipant(player.getObjectId()))
{
return SystemMessage.getSystemMessage(SystemMessageId.YOUR_OPPONENT_DOES_NOT_MEET_THE_REQUIREMENTS_TO_DO_BATTLE);
}
SystemMessage sm;
if (player.isDead())
{
sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_CURRENTLY_DEAD_AND_CANNOT_PARTICIPATE_IN_THE_OLYMPIAD);
sm.addPcName(player);
player.sendPacket(sm);
return SystemMessage.getSystemMessage(SystemMessageId.YOUR_OPPONENT_DOES_NOT_MEET_THE_REQUIREMENTS_TO_DO_BATTLE);
}
if (player.isSubClassActive())
{
sm = SystemMessage.getSystemMessage(SystemMessageId.C1_DOES_NOT_MEET_THE_PARTICIPATION_REQUIREMENTS_YOU_CANNOT_PARTICIPATE_IN_THE_OLYMPIAD_BECAUSE_YOU_HAVE_CHANGED_YOUR_CLASS_TO_SUBCLASS);
sm.addPcName(player);
player.sendPacket(sm);
return SystemMessage.getSystemMessage(SystemMessageId.YOUR_OPPONENT_DOES_NOT_MEET_THE_REQUIREMENTS_TO_DO_BATTLE);
}
if (player.isCursedWeaponEquipped())
{
sm = SystemMessage.getSystemMessage(SystemMessageId.C1_DOES_NOT_MEET_THE_PARTICIPATION_REQUIREMENTS_THE_OWNER_OF_S2_CANNOT_PARTICIPATE_IN_THE_OLYMPIAD);
sm.addPcName(player);
sm.addItemName(player.getCursedWeaponEquippedId());
player.sendPacket(sm);
return SystemMessage.getSystemMessage(SystemMessageId.YOUR_OPPONENT_DOES_NOT_MEET_THE_REQUIREMENTS_TO_DO_BATTLE);
}
if (!player.isInventoryUnder90(true))
{
sm = SystemMessage.getSystemMessage(SystemMessageId.C1_DOES_NOT_MEET_THE_PARTICIPATION_REQUIREMENTS_AS_THE_INVENTORY_WEIGHT_SLOT_IS_FILLED_BEYOND_80);
sm.addPcName(player);
player.sendPacket(sm);
return SystemMessage.getSystemMessage(SystemMessageId.YOUR_OPPONENT_DOES_NOT_MEET_THE_REQUIREMENTS_TO_DO_BATTLE);
}
return null;
}
protected static final boolean portPlayerToArena(Participant par, Location loc, int id)
{
final L2PcInstance player = par.getPlayer();
if ((player == null) || !player.isOnline())
{
return false;
}
try
{
player.setLastLocation();
if (player.isSitting())
{
player.standUp();
}
player.setTarget(null);
player.setOlympiadGameId(id);
player.setIsInOlympiadMode(true);
player.setIsOlympiadStart(false);
player.setOlympiadSide(par.getSide());
player.setOlympiadBuffCount(Config.ALT_OLY_MAX_BUFFS);
loc.setInstanceId(OlympiadGameManager.getInstance().getOlympiadTask(id).getZone().getInstanceId());
player.teleToLocation(loc, false);
player.sendPacket(new ExOlympiadMode(2));
}
catch (Exception e)
{
_log.log(Level.WARNING, e.getMessage(), e);
return false;
}
return true;
}
protected static final void removals(L2PcInstance player, boolean removeParty)
{
try
{
if (player == null)
{
return;
}
// Remove Buffs
player.stopAllEffectsExceptThoseThatLastThroughDeath();
// Remove Clan Skills
if (player.getClan() != null)
{
player.getClan().removeSkillEffects(player);
if (player.getClan().getCastleId() > 0)
{
CastleManager.getInstance().getCastleByOwner(player.getClan()).removeResidentialSkills(player);
}
if (player.getClan().getFortId() > 0)
{
FortManager.getInstance().getFortByOwner(player.getClan()).removeResidentialSkills(player);
}
}
// Abort casting if player casting
player.abortAttack();
player.abortCast();
// Force the character to be visible
player.setInvisible(false);
// Heal Player fully
player.setCurrentCp(player.getMaxCp());
player.setCurrentHp(player.getMaxHp());
player.setCurrentMp(player.getMaxMp());
// Remove Summon's Buffs
if (player.hasSummon())
{
final L2Summon pet = player.getPet();
if (pet != null)
{
pet.unSummon(player);
}
player.getServitors().values().forEach(s ->
{
s.stopAllEffectsExceptThoseThatLastThroughDeath();
s.abortAttack();
s.abortCast();
});
}
// stop any cubic that has been given by other player.
player.stopCubicsByOthers();
// Remove player from his party
if (removeParty)
{
final L2Party party = player.getParty();
if (party != null)
{
party.removePartyMember(player, messageType.Expelled);
}
}
// Remove Agathion
if (player.getAgathionId() > 0)
{
player.setAgathionId(0);
player.broadcastUserInfo();
}
player.checkItemRestriction();
// Remove shot automation
player.disableAutoShotsAll();
// Discharge any active shots
final L2ItemInstance item = player.getActiveWeaponInstance();
if (item != null)
{
item.unChargeAllShots();
}
// enable skills with cool time <= 15 minutes
for (Skill skill : player.getAllSkills())
{
if (skill.getReuseDelay() <= 900000)
{
player.enableSkill(skill);
}
}
player.sendSkillList();
player.sendPacket(new SkillCoolTime(player));
}
catch (Exception e)
{
_log.log(Level.WARNING, e.getMessage(), e);
}
}
protected static final void cleanEffects(L2PcInstance player)
{
try
{
// prevent players kill each other
player.setIsOlympiadStart(false);
player.setTarget(null);
player.abortAttack();
player.abortCast();
player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
if (player.isDead())
{
player.setIsDead(false);
}
player.stopAllEffectsExceptThoseThatLastThroughDeath();
player.clearSouls();
player.clearCharges();
if (player.getAgathionId() > 0)
{
player.setAgathionId(0);
}
final L2Summon pet = player.getPet();
if ((pet != null) && !pet.isDead())
{
pet.setTarget(null);
pet.abortAttack();
pet.abortCast();
pet.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
pet.stopAllEffectsExceptThoseThatLastThroughDeath();
}
player.getServitors().values().stream().filter(s -> !s.isDead()).forEach(s ->
{
s.setTarget(null);
s.abortAttack();
s.abortCast();
s.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
s.stopAllEffectsExceptThoseThatLastThroughDeath();
});
player.setCurrentCp(player.getMaxCp());
player.setCurrentHp(player.getMaxHp());
player.setCurrentMp(player.getMaxMp());
player.getStatus().startHpMpRegeneration();
}
catch (Exception e)
{
_log.log(Level.WARNING, e.getMessage(), e);
}
}
protected static final void playerStatusBack(L2PcInstance player)
{
try
{
if (player.isTransformed())
{
player.untransform();
}
if (player.isInOlympiadMode())
{
player.sendPacket(new ExOlympiadMode(0));
}
player.setIsInOlympiadMode(false);
player.setIsOlympiadStart(false);
player.setOlympiadSide(-1);
player.setOlympiadGameId(-1);
// Add Clan Skills
if (player.getClan() != null)
{
player.getClan().addSkillEffects(player);
if (player.getClan().getCastleId() > 0)
{
CastleManager.getInstance().getCastleByOwner(player.getClan()).giveResidentialSkills(player);
}
if (player.getClan().getFortId() > 0)
{
FortManager.getInstance().getFortByOwner(player.getClan()).giveResidentialSkills(player);
}
player.sendSkillList();
}
// heal again after adding clan skills
player.setCurrentCp(player.getMaxCp());
player.setCurrentHp(player.getMaxHp());
player.setCurrentMp(player.getMaxMp());
player.getStatus().startHpMpRegeneration();
if (Config.L2JMOD_DUALBOX_CHECK_MAX_OLYMPIAD_PARTICIPANTS_PER_IP > 0)
{
AntiFeedManager.getInstance().removePlayer(AntiFeedManager.OLYMPIAD_ID, player);
}
}
catch (Exception e)
{
_log.log(Level.WARNING, "portPlayersToArena()", e);
}
}
protected static final void portPlayerBack(L2PcInstance player)
{
if (player == null)
{
return;
}
final Location loc = player.getLastLocation();
if ((loc.getX() == 0) && (loc.getY() == 0))
{
return;
}
player.setIsPendingRevive(false);
player.setInstanceId(0);
player.teleToLocation(loc);
player.unsetLastLocation();
}
public static final void rewardParticipant(L2PcInstance player, int[][] reward)
{
if ((player == null) || !player.isOnline() || (reward == null))
{
return;
}
try
{
SystemMessage sm;
L2ItemInstance item;
final InventoryUpdate iu = new InventoryUpdate();
for (int[] it : reward)
{
if ((it == null) || (it.length != 2))
{
continue;
}
item = player.getInventory().addItem("Olympiad", it[0], it[1], player, null);
if (item == null)
{
continue;
}
iu.addModifiedItem(item);
sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_EARNED_S2_S1_S);
sm.addItemName(it[0]);
sm.addInt(it[1]);
player.sendPacket(sm);
}
player.sendPacket(iu);
}
catch (Exception e)
{
_log.log(Level.WARNING, e.getMessage(), e);
}
}
public abstract CompetitionType getType();
public abstract String[] getPlayerNames();
public abstract boolean containsParticipant(int playerId);
public abstract void sendOlympiadInfo(L2Character player);
public abstract void broadcastOlympiadInfo(L2OlympiadStadiumZone stadium);
protected abstract void broadcastPacket(L2GameServerPacket packet);
protected abstract boolean needBuffers();
protected abstract boolean checkDefaulted();
protected abstract void removals();
protected abstract boolean portPlayersToArena(List<Location> spawns);
protected abstract void cleanEffects();
protected abstract void portPlayersBack();
protected abstract void playersStatusBack();
protected abstract void clearPlayers();
protected abstract void handleDisconnect(L2PcInstance player);
protected abstract void resetDamage();
protected abstract void addDamage(L2PcInstance player, int damage);
protected abstract boolean checkBattleStatus();
protected abstract boolean haveWinner();
protected abstract void validateWinner(L2OlympiadStadiumZone stadium);
protected abstract int getDivider();
protected abstract int[][] getReward();
protected abstract String getWeeklyMatchType();
}

View File

@ -0,0 +1,41 @@
/*
* This file is part of the L2J Mobius project.
*
* 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.l2jmobius.gameserver.model.olympiad;
/**
* @author DS
*/
public enum CompetitionType
{
CLASSED("classed"),
NON_CLASSED("non-classed"),
TEAMS("teams"),
OTHER("other");
private final String _name;
private CompetitionType(String name)
{
_name = name;
}
@Override
public final String toString()
{
return _name;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,97 @@
/*
* This file is part of the L2J Mobius project.
*
* 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.l2jmobius.gameserver.model.olympiad;
import java.util.Set;
import com.l2jmobius.gameserver.datatables.SpawnTable;
import com.l2jmobius.gameserver.enums.ChatType;
import com.l2jmobius.gameserver.model.L2Spawn;
import com.l2jmobius.gameserver.model.actor.L2Npc;
import com.l2jmobius.gameserver.network.NpcStringId;
import com.l2jmobius.gameserver.network.serverpackets.NpcSay;
/**
* @author DS
*/
public final class OlympiadAnnouncer implements Runnable
{
private static final int OLY_MANAGER = 31688;
private final Set<L2Spawn> _managers;
private int _currentStadium = 0;
public OlympiadAnnouncer()
{
_managers = SpawnTable.getInstance().getSpawns(OLY_MANAGER);
}
@Override
public void run()
{
OlympiadGameTask task;
for (int i = OlympiadGameManager.getInstance().getNumberOfStadiums(); --i >= 0; _currentStadium++)
{
if (_currentStadium >= OlympiadGameManager.getInstance().getNumberOfStadiums())
{
_currentStadium = 0;
}
task = OlympiadGameManager.getInstance().getOlympiadTask(_currentStadium);
if ((task != null) && (task.getGame() != null) && task.needAnnounce())
{
NpcStringId npcString;
final String arenaId = String.valueOf(task.getGame().getStadiumId() + 1);
switch (task.getGame().getType())
{
case NON_CLASSED:
{
npcString = NpcStringId.OLYMPIAD_CLASS_FREE_INDIVIDUAL_MATCH_IS_GOING_TO_BEGIN_IN_ARENA_S1_IN_A_MOMENT;
break;
}
case CLASSED:
{
npcString = NpcStringId.OLYMPIAD_CLASS_INDIVIDUAL_MATCH_IS_GOING_TO_BEGIN_IN_ARENA_S1_IN_A_MOMENT;
break;
}
case TEAMS:
{
npcString = NpcStringId.OLYMPIAD_ALL_CLASS_BATTLE_IS_GOING_TO_BEGIN_IN_ARENA_S1_IN_A_MOMENT;
break;
}
default:
{
continue;
}
}
L2Npc manager;
NpcSay packet;
for (L2Spawn spawn : _managers)
{
manager = spawn.getLastSpawn();
if (manager != null)
{
packet = new NpcSay(manager.getObjectId(), ChatType.NPC_SHOUT, manager.getId(), npcString);
packet.addStringParameter(arenaId);
manager.broadcastPacket(packet);
}
}
break;
}
}
}
}

View File

@ -0,0 +1,87 @@
/*
* This file is part of the L2J Mobius project.
*
* 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.l2jmobius.gameserver.model.olympiad;
import java.util.List;
import com.l2jmobius.Config;
import com.l2jmobius.util.Rnd;
/**
* @author DS
*/
public class OlympiadGameClassed extends OlympiadGameNormal
{
private OlympiadGameClassed(int id, Participant[] opponents)
{
super(id, opponents);
}
@Override
public final CompetitionType getType()
{
return CompetitionType.CLASSED;
}
@Override
protected final int getDivider()
{
return Config.ALT_OLY_DIVIDER_CLASSED;
}
@Override
protected final int[][] getReward()
{
return Config.ALT_OLY_CLASSED_REWARD;
}
@Override
protected final String getWeeklyMatchType()
{
return COMP_DONE_WEEK_CLASSED;
}
protected static final OlympiadGameClassed createGame(int id, List<List<Integer>> classList)
{
if ((classList == null) || classList.isEmpty())
{
return null;
}
List<Integer> list;
Participant[] opponents;
while (!classList.isEmpty())
{
list = classList.get(Rnd.nextInt(classList.size()));
if ((list == null) || (list.size() < 2))
{
classList.remove(list);
continue;
}
opponents = OlympiadGameNormal.createListOfParticipants(list);
if (opponents == null)
{
classList.remove(list);
continue;
}
return new OlympiadGameClassed(id, opponents);
}
return null;
}
}

View File

@ -0,0 +1,211 @@
/*
* This file is part of the L2J Mobius project.
*
* 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.l2jmobius.gameserver.model.olympiad;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.gameserver.instancemanager.ZoneManager;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.zone.type.L2OlympiadStadiumZone;
/**
* @author GodKratos, DS
*/
public class OlympiadGameManager implements Runnable
{
private static final Logger _log = Logger.getLogger(OlympiadGameManager.class.getName());
private volatile boolean _battleStarted = false;
private final OlympiadGameTask[] _tasks;
protected OlympiadGameManager()
{
final Collection<L2OlympiadStadiumZone> zones = ZoneManager.getInstance().getAllZones(L2OlympiadStadiumZone.class);
if ((zones == null) || zones.isEmpty())
{
throw new Error("No olympiad stadium zones defined !");
}
_tasks = new OlympiadGameTask[zones.size()];
int i = 0;
for (L2OlympiadStadiumZone zone : zones)
{
_tasks[i++] = new OlympiadGameTask(zone);
}
_log.log(Level.INFO, "Olympiad System: Loaded " + _tasks.length + " stadiums.");
}
public static final OlympiadGameManager getInstance()
{
return SingletonHolder._instance;
}
protected final boolean isBattleStarted()
{
return _battleStarted;
}
protected final void startBattle()
{
_battleStarted = true;
}
@Override
public final void run()
{
if (Olympiad.getInstance().isOlympiadEnd())
{
return;
}
if (Olympiad.getInstance().inCompPeriod())
{
OlympiadGameTask task;
AbstractOlympiadGame newGame;
List<List<Integer>> readyClassed = OlympiadManager.getInstance().hasEnoughRegisteredClassed();
boolean readyNonClassed = OlympiadManager.getInstance().hasEnoughRegisteredNonClassed();
boolean readyTeams = OlympiadManager.getInstance().hasEnoughRegisteredTeams();
if ((readyClassed != null) || readyNonClassed || readyTeams)
{
// set up the games queue
for (int i = 0; i < _tasks.length; i++)
{
task = _tasks[i];
synchronized (task)
{
if (!task.isRunning())
{
// Fair arena distribution
// 0,2,4,6,8.. arenas checked for classed or teams first
if (((readyClassed != null) || readyTeams) && ((i % 2) == 0))
{
// 0,4,8.. arenas checked for teams first
if (readyTeams && ((i % 4) == 0))
{
newGame = OlympiadGameTeams.createGame(i, OlympiadManager.getInstance().getRegisteredTeamsBased());
if (newGame != null)
{
task.attachGame(newGame);
continue;
}
readyTeams = false;
}
// if no ready teams found check for classed
if (readyClassed != null)
{
newGame = OlympiadGameClassed.createGame(i, readyClassed);
if (newGame != null)
{
task.attachGame(newGame);
continue;
}
readyClassed = null;
}
}
// 1,3,5,7,9.. arenas used for non-classed
// also other arenas will be used for non-classed if no classed or teams available
if (readyNonClassed)
{
newGame = OlympiadGameNonClassed.createGame(i, OlympiadManager.getInstance().getRegisteredNonClassBased());
if (newGame != null)
{
task.attachGame(newGame);
continue;
}
readyNonClassed = false;
}
}
}
// stop generating games if no more participants
if ((readyClassed == null) && !readyNonClassed && !readyTeams)
{
break;
}
}
}
}
else
{
// not in competition period
if (isAllTasksFinished())
{
OlympiadManager.getInstance().clearRegistered();
_battleStarted = false;
_log.log(Level.INFO, "Olympiad System: All current games finished.");
}
}
}
public final boolean isAllTasksFinished()
{
for (OlympiadGameTask task : _tasks)
{
if (task.isRunning())
{
return false;
}
}
return true;
}
public final OlympiadGameTask getOlympiadTask(int id)
{
if ((id < 0) || (id >= _tasks.length))
{
return null;
}
return _tasks[id];
}
public final int getNumberOfStadiums()
{
return _tasks.length;
}
public final void notifyCompetitorDamage(L2PcInstance player, int damage)
{
if (player == null)
{
return;
}
final int id = player.getOlympiadGameId();
if ((id < 0) || (id >= _tasks.length))
{
return;
}
final AbstractOlympiadGame game = _tasks[id].getGame();
if (game != null)
{
game.addDamage(player, damage);
}
}
private static class SingletonHolder
{
protected static final OlympiadGameManager _instance = new OlympiadGameManager();
}
}

View File

@ -0,0 +1,67 @@
/*
* This file is part of the L2J Mobius project.
*
* 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.l2jmobius.gameserver.model.olympiad;
import java.util.List;
import com.l2jmobius.Config;
/**
* @author DS
*/
public class OlympiadGameNonClassed extends OlympiadGameNormal
{
private OlympiadGameNonClassed(int id, Participant[] opponents)
{
super(id, opponents);
}
@Override
public final CompetitionType getType()
{
return CompetitionType.NON_CLASSED;
}
@Override
protected final int getDivider()
{
return Config.ALT_OLY_DIVIDER_NON_CLASSED;
}
@Override
protected final int[][] getReward()
{
return Config.ALT_OLY_NONCLASSED_REWARD;
}
@Override
protected final String getWeeklyMatchType()
{
return COMP_DONE_WEEK_NON_CLASSED;
}
protected static final OlympiadGameNonClassed createGame(int id, List<Integer> list)
{
final Participant[] opponents = OlympiadGameNormal.createListOfParticipants(list);
if (opponents == null)
{
return null;
}
return new OlympiadGameNonClassed(id, opponents);
}
}

View File

@ -0,0 +1,815 @@
/*
* This file is part of the L2J Mobius project.
*
* 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.l2jmobius.gameserver.model.olympiad;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import com.l2jmobius.Config;
import com.l2jmobius.commons.database.pool.impl.ConnectionFactory;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.Location;
import com.l2jmobius.gameserver.model.actor.L2Character;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.events.EventDispatcher;
import com.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
import com.l2jmobius.gameserver.model.zone.type.L2OlympiadStadiumZone;
import com.l2jmobius.gameserver.network.SystemMessageId;
import com.l2jmobius.gameserver.network.serverpackets.ExOlympiadMatchResult;
import com.l2jmobius.gameserver.network.serverpackets.ExOlympiadUserInfo;
import com.l2jmobius.gameserver.network.serverpackets.L2GameServerPacket;
import com.l2jmobius.gameserver.network.serverpackets.SystemMessage;
import com.l2jmobius.util.Rnd;
/**
* @author GodKratos, Pere, DS
*/
public abstract class OlympiadGameNormal extends AbstractOlympiadGame
{
protected int _damageP1 = 0;
protected int _damageP2 = 0;
protected Participant _playerOne;
protected Participant _playerTwo;
protected OlympiadGameNormal(int id, Participant[] opponents)
{
super(id);
_playerOne = opponents[0];
_playerTwo = opponents[1];
_playerOne.getPlayer().setOlympiadGameId(id);
_playerTwo.getPlayer().setOlympiadGameId(id);
}
protected static final Participant[] createListOfParticipants(List<Integer> list)
{
if ((list == null) || list.isEmpty() || (list.size() < 2))
{
return null;
}
int playerOneObjectId = 0;
L2PcInstance playerOne = null;
L2PcInstance playerTwo = null;
while (list.size() > 1)
{
playerOneObjectId = list.remove(Rnd.nextInt(list.size()));
playerOne = L2World.getInstance().getPlayer(playerOneObjectId);
if ((playerOne == null) || !playerOne.isOnline())
{
continue;
}
playerTwo = L2World.getInstance().getPlayer(list.remove(Rnd.nextInt(list.size())));
if ((playerTwo == null) || !playerTwo.isOnline())
{
list.add(playerOneObjectId);
continue;
}
final Participant[] result = new Participant[2];
result[0] = new Participant(playerOne, 1);
result[1] = new Participant(playerTwo, 2);
return result;
}
return null;
}
@Override
public final boolean containsParticipant(int playerId)
{
return ((_playerOne != null) && (_playerOne.getObjectId() == playerId)) || ((_playerTwo != null) && (_playerTwo.getObjectId() == playerId));
}
@Override
public final void sendOlympiadInfo(L2Character player)
{
player.sendPacket(new ExOlympiadUserInfo(_playerOne));
player.sendPacket(new ExOlympiadUserInfo(_playerTwo));
}
@Override
public final void broadcastOlympiadInfo(L2OlympiadStadiumZone stadium)
{
stadium.broadcastPacket(new ExOlympiadUserInfo(_playerOne));
stadium.broadcastPacket(new ExOlympiadUserInfo(_playerTwo));
}
@Override
protected final void broadcastPacket(L2GameServerPacket packet)
{
if (_playerOne.updatePlayer())
{
_playerOne.getPlayer().sendPacket(packet);
}
if (_playerTwo.updatePlayer())
{
_playerTwo.getPlayer().sendPacket(packet);
}
}
@Override
protected final boolean portPlayersToArena(List<Location> spawns)
{
boolean result = true;
try
{
result &= portPlayerToArena(_playerOne, spawns.get(0), _stadiumID);
result &= portPlayerToArena(_playerTwo, spawns.get(spawns.size() / 2), _stadiumID);
}
catch (Exception e)
{
_log.log(Level.WARNING, "", e);
return false;
}
return result;
}
@Override
protected boolean needBuffers()
{
return true;
}
@Override
protected final void removals()
{
if (_aborted)
{
return;
}
removals(_playerOne.getPlayer(), true);
removals(_playerTwo.getPlayer(), true);
}
@Override
protected final boolean makeCompetitionStart()
{
if (!super.makeCompetitionStart())
{
return false;
}
if ((_playerOne.getPlayer() == null) || (_playerTwo.getPlayer() == null))
{
return false;
}
_playerOne.getPlayer().setIsOlympiadStart(true);
_playerOne.getPlayer().updateEffectIcons();
_playerTwo.getPlayer().setIsOlympiadStart(true);
_playerTwo.getPlayer().updateEffectIcons();
return true;
}
@Override
protected final void cleanEffects()
{
if ((_playerOne.getPlayer() != null) && !_playerOne.isDefaulted() && !_playerOne.isDisconnected() && (_playerOne.getPlayer().getOlympiadGameId() == _stadiumID))
{
cleanEffects(_playerOne.getPlayer());
}
if ((_playerTwo.getPlayer() != null) && !_playerTwo.isDefaulted() && !_playerTwo.isDisconnected() && (_playerTwo.getPlayer().getOlympiadGameId() == _stadiumID))
{
cleanEffects(_playerTwo.getPlayer());
}
}
@Override
protected final void portPlayersBack()
{
if ((_playerOne.getPlayer() != null) && !_playerOne.isDefaulted() && !_playerOne.isDisconnected())
{
portPlayerBack(_playerOne.getPlayer());
}
if ((_playerTwo.getPlayer() != null) && !_playerTwo.isDefaulted() && !_playerTwo.isDisconnected())
{
portPlayerBack(_playerTwo.getPlayer());
}
}
@Override
protected final void playersStatusBack()
{
if ((_playerOne.getPlayer() != null) && !_playerOne.isDefaulted() && !_playerOne.isDisconnected() && (_playerOne.getPlayer().getOlympiadGameId() == _stadiumID))
{
playerStatusBack(_playerOne.getPlayer());
}
if ((_playerTwo.getPlayer() != null) && !_playerTwo.isDefaulted() && !_playerTwo.isDisconnected() && (_playerTwo.getPlayer().getOlympiadGameId() == _stadiumID))
{
playerStatusBack(_playerTwo.getPlayer());
}
}
@Override
protected final void clearPlayers()
{
_playerOne.setPlayer(null);
_playerOne = null;
_playerTwo.setPlayer(null);
_playerTwo = null;
}
@Override
protected final void handleDisconnect(L2PcInstance player)
{
if (player.getObjectId() == _playerOne.getObjectId())
{
_playerOne.setDisconnected(true);
}
else if (player.getObjectId() == _playerTwo.getObjectId())
{
_playerTwo.setDisconnected(true);
}
}
@Override
protected final boolean checkBattleStatus()
{
if (_aborted)
{
return false;
}
if ((_playerOne.getPlayer() == null) || _playerOne.isDisconnected())
{
return false;
}
if ((_playerTwo.getPlayer() == null) || _playerTwo.isDisconnected())
{
return false;
}
return true;
}
@Override
protected final boolean haveWinner()
{
if (!checkBattleStatus())
{
return true;
}
boolean playerOneLost = true;
try
{
if (_playerOne.getPlayer().getOlympiadGameId() == _stadiumID)
{
playerOneLost = _playerOne.getPlayer().isDead();
}
}
catch (Exception e)
{
playerOneLost = true;
}
boolean playerTwoLost = true;
try
{
if (_playerTwo.getPlayer().getOlympiadGameId() == _stadiumID)
{
playerTwoLost = _playerTwo.getPlayer().isDead();
}
}
catch (Exception e)
{
playerTwoLost = true;
}
return playerOneLost || playerTwoLost;
}
@Override
protected void validateWinner(L2OlympiadStadiumZone stadium)
{
if (_aborted)
{
return;
}
ExOlympiadMatchResult result = null;
boolean tie = false;
int winside = 0;
final List<OlympiadInfo> list1 = new ArrayList<>(1);
final List<OlympiadInfo> list2 = new ArrayList<>(1);
final boolean _pOneCrash = ((_playerOne.getPlayer() == null) || _playerOne.isDisconnected());
final boolean _pTwoCrash = ((_playerTwo.getPlayer() == null) || _playerTwo.isDisconnected());
final int playerOnePoints = _playerOne.getStats().getInt(POINTS);
final int playerTwoPoints = _playerTwo.getStats().getInt(POINTS);
int pointDiff = Math.min(playerOnePoints, playerTwoPoints) / getDivider();
if (pointDiff <= 0)
{
pointDiff = 1;
}
else if (pointDiff > Config.ALT_OLY_MAX_POINTS)
{
pointDiff = Config.ALT_OLY_MAX_POINTS;
}
int points;
SystemMessage sm;
// Check for if a player defaulted before battle started
if (_playerOne.isDefaulted() || _playerTwo.isDefaulted())
{
try
{
if (_playerOne.isDefaulted())
{
try
{
points = Math.min(playerOnePoints / 3, Config.ALT_OLY_MAX_POINTS);
removePointsFromParticipant(_playerOne, points);
list1.add(new OlympiadInfo(_playerOne.getName(), _playerOne.getClanName(), _playerOne.getClanId(), _playerOne.getBaseClass(), _damageP1, playerOnePoints - points, -points));
winside = 2;
if (Config.ALT_OLY_LOG_FIGHTS)
{
final LogRecord record = new LogRecord(Level.INFO, _playerOne.getName() + " default");
record.setParameters(new Object[]
{
_playerOne.getName(),
_playerTwo.getName(),
0,
0,
0,
0,
points,
getType().toString()
});
_logResults.log(record);
}
}
catch (Exception e)
{
_log.log(Level.WARNING, "Exception on validateWinner(): " + e.getMessage(), e);
}
}
if (_playerTwo.isDefaulted())
{
try
{
points = Math.min(playerTwoPoints / 3, Config.ALT_OLY_MAX_POINTS);
removePointsFromParticipant(_playerTwo, points);
list2.add(new OlympiadInfo(_playerTwo.getName(), _playerTwo.getClanName(), _playerTwo.getClanId(), _playerTwo.getBaseClass(), _damageP2, playerTwoPoints - points, -points));
if (winside == 2)
{
tie = true;
}
else
{
winside = 1;
}
if (Config.ALT_OLY_LOG_FIGHTS)
{
final LogRecord record = new LogRecord(Level.INFO, _playerTwo.getName() + " default");
record.setParameters(new Object[]
{
_playerOne.getName(),
_playerTwo.getName(),
0,
0,
0,
0,
points,
getType().toString()
});
_logResults.log(record);
}
}
catch (Exception e)
{
_log.log(Level.WARNING, "Exception on validateWinner(): " + e.getMessage(), e);
}
}
if (winside == 1)
{
result = new ExOlympiadMatchResult(tie, winside, list1, list2);
}
else
{
result = new ExOlympiadMatchResult(tie, winside, list2, list1);
}
stadium.broadcastPacket(result);
return;
}
catch (Exception e)
{
_log.log(Level.WARNING, "Exception on validateWinner(): " + e.getMessage(), e);
return;
}
}
// Create results for players if a player crashed
if (_pOneCrash || _pTwoCrash)
{
try
{
if (_pTwoCrash && !_pOneCrash)
{
sm = SystemMessage.getSystemMessage(SystemMessageId.CONGRATULATIONS_C1_YOU_WIN_THE_MATCH);
sm.addString(_playerOne.getName());
stadium.broadcastPacket(sm);
_playerOne.updateStat(COMP_WON, 1);
addPointsToParticipant(_playerOne, pointDiff);
list1.add(new OlympiadInfo(_playerOne.getName(), _playerOne.getClanName(), _playerOne.getClanId(), _playerOne.getBaseClass(), _damageP1, playerOnePoints + pointDiff, pointDiff));
_playerTwo.updateStat(COMP_LOST, 1);
removePointsFromParticipant(_playerTwo, pointDiff);
list2.add(new OlympiadInfo(_playerTwo.getName(), _playerTwo.getClanName(), _playerTwo.getClanId(), _playerTwo.getBaseClass(), _damageP2, playerTwoPoints - pointDiff, -pointDiff));
winside = 1;
rewardParticipant(_playerOne.getPlayer(), getReward());
if (Config.ALT_OLY_LOG_FIGHTS)
{
final LogRecord record = new LogRecord(Level.INFO, _playerTwo.getName() + " crash");
record.setParameters(new Object[]
{
_playerOne.getName(),
_playerTwo.getName(),
0,
0,
0,
0,
pointDiff,
getType().toString()
});
_logResults.log(record);
}
// Notify to scripts
EventDispatcher.getInstance().notifyEventAsync(new OnOlympiadMatchResult(_playerOne, _playerTwo, getType()), Olympiad.getInstance());
}
else if (_pOneCrash && !_pTwoCrash)
{
sm = SystemMessage.getSystemMessage(SystemMessageId.CONGRATULATIONS_C1_YOU_WIN_THE_MATCH);
sm.addString(_playerTwo.getName());
stadium.broadcastPacket(sm);
_playerTwo.updateStat(COMP_WON, 1);
addPointsToParticipant(_playerTwo, pointDiff);
list2.add(new OlympiadInfo(_playerTwo.getName(), _playerTwo.getClanName(), _playerTwo.getClanId(), _playerTwo.getBaseClass(), _damageP2, playerTwoPoints + pointDiff, pointDiff));
_playerOne.updateStat(COMP_LOST, 1);
removePointsFromParticipant(_playerOne, pointDiff);
list1.add(new OlympiadInfo(_playerOne.getName(), _playerOne.getClanName(), _playerOne.getClanId(), _playerOne.getBaseClass(), _damageP1, playerOnePoints - pointDiff, -pointDiff));
winside = 2;
rewardParticipant(_playerTwo.getPlayer(), getReward());
if (Config.ALT_OLY_LOG_FIGHTS)
{
final LogRecord record = new LogRecord(Level.INFO, _playerOne.getName() + " crash");
record.setParameters(new Object[]
{
_playerOne.getName(),
_playerTwo.getName(),
0,
0,
0,
0,
pointDiff,
getType().toString()
});
_logResults.log(record);
}
// Notify to scripts
EventDispatcher.getInstance().notifyEventAsync(new OnOlympiadMatchResult(_playerTwo, _playerOne, getType()), Olympiad.getInstance());
}
else if (_pOneCrash && _pTwoCrash)
{
stadium.broadcastPacket(SystemMessage.getSystemMessage(SystemMessageId.THERE_IS_NO_VICTOR));
_playerOne.updateStat(COMP_LOST, 1);
removePointsFromParticipant(_playerOne, pointDiff);
list1.add(new OlympiadInfo(_playerOne.getName(), _playerOne.getClanName(), _playerOne.getClanId(), _playerOne.getBaseClass(), _damageP1, playerOnePoints - pointDiff, -pointDiff));
_playerTwo.updateStat(COMP_LOST, 1);
removePointsFromParticipant(_playerTwo, pointDiff);
list2.add(new OlympiadInfo(_playerTwo.getName(), _playerTwo.getClanName(), _playerTwo.getClanId(), _playerTwo.getBaseClass(), _damageP2, playerTwoPoints - pointDiff, -pointDiff));
tie = true;
if (Config.ALT_OLY_LOG_FIGHTS)
{
final LogRecord record = new LogRecord(Level.INFO, "both crash");
record.setParameters(new Object[]
{
_playerOne.getName(),
_playerTwo.getName(),
0,
0,
0,
0,
pointDiff,
getType().toString()
});
_logResults.log(record);
}
}
_playerOne.updateStat(COMP_DONE, 1);
_playerTwo.updateStat(COMP_DONE, 1);
_playerOne.updateStat(COMP_DONE_WEEK, 1);
_playerTwo.updateStat(COMP_DONE_WEEK, 1);
_playerOne.updateStat(getWeeklyMatchType(), 1);
_playerTwo.updateStat(getWeeklyMatchType(), 1);
if (winside == 1)
{
result = new ExOlympiadMatchResult(tie, winside, list1, list2);
}
else
{
result = new ExOlympiadMatchResult(tie, winside, list2, list1);
}
stadium.broadcastPacket(result);
// Notify to scripts
EventDispatcher.getInstance().notifyEventAsync(new OnOlympiadMatchResult(null, _playerOne, getType()), Olympiad.getInstance());
EventDispatcher.getInstance().notifyEventAsync(new OnOlympiadMatchResult(null, _playerTwo, getType()), Olympiad.getInstance());
return;
}
catch (Exception e)
{
_log.log(Level.WARNING, "Exception on validateWinner(): " + e.getMessage(), e);
return;
}
}
try
{
String winner = "draw";
// Calculate Fight time
final long _fightTime = (System.currentTimeMillis() - _startTime);
double playerOneHp = 0;
if ((_playerOne.getPlayer() != null) && !_playerOne.getPlayer().isDead())
{
playerOneHp = _playerOne.getPlayer().getCurrentHp() + _playerOne.getPlayer().getCurrentCp();
if (playerOneHp < 0.5)
{
playerOneHp = 0;
}
}
double playerTwoHp = 0;
if ((_playerTwo.getPlayer() != null) && !_playerTwo.getPlayer().isDead())
{
playerTwoHp = _playerTwo.getPlayer().getCurrentHp() + _playerTwo.getPlayer().getCurrentCp();
if (playerTwoHp < 0.5)
{
playerTwoHp = 0;
}
}
// if players crashed, search if they've relogged
_playerOne.updatePlayer();
_playerTwo.updatePlayer();
if (((_playerOne.getPlayer() == null) || !_playerOne.getPlayer().isOnline()) && ((_playerTwo.getPlayer() == null) || !_playerTwo.getPlayer().isOnline()))
{
_playerOne.updateStat(COMP_DRAWN, 1);
_playerTwo.updateStat(COMP_DRAWN, 1);
sm = SystemMessage.getSystemMessage(SystemMessageId.THERE_IS_NO_VICTOR);
stadium.broadcastPacket(sm);
}
else if ((_playerTwo.getPlayer() == null) || !_playerTwo.getPlayer().isOnline() || ((playerTwoHp == 0) && (playerOneHp != 0)) || ((_damageP1 > _damageP2) && (playerTwoHp != 0) && (playerOneHp != 0)))
{
sm = SystemMessage.getSystemMessage(SystemMessageId.CONGRATULATIONS_C1_YOU_WIN_THE_MATCH);
sm.addString(_playerOne.getName());
stadium.broadcastPacket(sm);
_playerOne.updateStat(COMP_WON, 1);
_playerTwo.updateStat(COMP_LOST, 1);
addPointsToParticipant(_playerOne, pointDiff);
list1.add(new OlympiadInfo(_playerOne.getName(), _playerOne.getClanName(), _playerOne.getClanId(), _playerOne.getBaseClass(), _damageP1, playerOnePoints + pointDiff, pointDiff));
removePointsFromParticipant(_playerTwo, pointDiff);
list2.add(new OlympiadInfo(_playerTwo.getName(), _playerTwo.getClanName(), _playerTwo.getClanId(), _playerTwo.getBaseClass(), _damageP2, playerTwoPoints - pointDiff, -pointDiff));
winner = _playerOne.getName() + " won";
winside = 1;
// Save Fight Result
saveResults(_playerOne, _playerTwo, 1, _startTime, _fightTime, getType());
rewardParticipant(_playerOne.getPlayer(), getReward());
// Notify to scripts
EventDispatcher.getInstance().notifyEventAsync(new OnOlympiadMatchResult(_playerOne, _playerTwo, getType()), Olympiad.getInstance());
}
else if ((_playerOne.getPlayer() == null) || !_playerOne.getPlayer().isOnline() || ((playerOneHp == 0) && (playerTwoHp != 0)) || ((_damageP2 > _damageP1) && (playerOneHp != 0) && (playerTwoHp != 0)))
{
sm = SystemMessage.getSystemMessage(SystemMessageId.CONGRATULATIONS_C1_YOU_WIN_THE_MATCH);
sm.addString(_playerTwo.getName());
stadium.broadcastPacket(sm);
_playerTwo.updateStat(COMP_WON, 1);
_playerOne.updateStat(COMP_LOST, 1);
addPointsToParticipant(_playerTwo, pointDiff);
list2.add(new OlympiadInfo(_playerTwo.getName(), _playerTwo.getClanName(), _playerTwo.getClanId(), _playerTwo.getBaseClass(), _damageP2, playerTwoPoints + pointDiff, pointDiff));
removePointsFromParticipant(_playerOne, pointDiff);
list1.add(new OlympiadInfo(_playerOne.getName(), _playerOne.getClanName(), _playerOne.getClanId(), _playerOne.getBaseClass(), _damageP1, playerOnePoints - pointDiff, -pointDiff));
winner = _playerTwo.getName() + " won";
winside = 2;
// Save Fight Result
saveResults(_playerOne, _playerTwo, 2, _startTime, _fightTime, getType());
rewardParticipant(_playerTwo.getPlayer(), getReward());
// Notify to scripts
EventDispatcher.getInstance().notifyEventAsync(new OnOlympiadMatchResult(_playerTwo, _playerOne, getType()), Olympiad.getInstance());
}
else
{
// Save Fight Result
saveResults(_playerOne, _playerTwo, 0, _startTime, _fightTime, getType());
sm = SystemMessage.getSystemMessage(SystemMessageId.THERE_IS_NO_VICTOR);
stadium.broadcastPacket(sm);
int value = Math.min(playerOnePoints / getDivider(), Config.ALT_OLY_MAX_POINTS);
removePointsFromParticipant(_playerOne, value);
list1.add(new OlympiadInfo(_playerOne.getName(), _playerOne.getClanName(), _playerOne.getClanId(), _playerOne.getBaseClass(), _damageP1, playerOnePoints - value, -value));
value = Math.min(playerTwoPoints / getDivider(), Config.ALT_OLY_MAX_POINTS);
removePointsFromParticipant(_playerTwo, value);
list2.add(new OlympiadInfo(_playerTwo.getName(), _playerTwo.getClanName(), _playerTwo.getClanId(), _playerTwo.getBaseClass(), _damageP2, playerTwoPoints - value, -value));
tie = true;
}
_playerOne.updateStat(COMP_DONE, 1);
_playerTwo.updateStat(COMP_DONE, 1);
_playerOne.updateStat(COMP_DONE_WEEK, 1);
_playerTwo.updateStat(COMP_DONE_WEEK, 1);
_playerOne.updateStat(getWeeklyMatchType(), 1);
_playerTwo.updateStat(getWeeklyMatchType(), 1);
if (winside == 1)
{
result = new ExOlympiadMatchResult(tie, winside, list1, list2);
}
else
{
result = new ExOlympiadMatchResult(tie, winside, list2, list1);
}
stadium.broadcastPacket(result);
if (Config.ALT_OLY_LOG_FIGHTS)
{
final LogRecord record = new LogRecord(Level.INFO, winner);
record.setParameters(new Object[]
{
_playerOne.getName(),
_playerTwo.getName(),
playerOneHp,
playerTwoHp,
_damageP1,
_damageP2,
pointDiff,
getType().toString()
});
_logResults.log(record);
}
}
catch (Exception e)
{
_log.log(Level.WARNING, "Exception on validateWinner(): " + e.getMessage(), e);
}
}
@Override
protected final void addDamage(L2PcInstance player, int damage)
{
if ((_playerOne.getPlayer() == null) || (_playerTwo.getPlayer() == null))
{
return;
}
if (player == _playerOne.getPlayer())
{
_damageP1 += damage;
}
else if (player == _playerTwo.getPlayer())
{
_damageP2 += damage;
}
}
@Override
public final String[] getPlayerNames()
{
return new String[]
{
_playerOne.getName(),
_playerTwo.getName()
};
}
@Override
public boolean checkDefaulted()
{
SystemMessage reason;
_playerOne.updatePlayer();
_playerTwo.updatePlayer();
reason = checkDefaulted(_playerOne.getPlayer());
if (reason != null)
{
_playerOne.setDefaulted(true);
if (_playerTwo.getPlayer() != null)
{
_playerTwo.getPlayer().sendPacket(reason);
}
}
reason = checkDefaulted(_playerTwo.getPlayer());
if (reason != null)
{
_playerTwo.setDefaulted(true);
if (_playerOne.getPlayer() != null)
{
_playerOne.getPlayer().sendPacket(reason);
}
}
return _playerOne.isDefaulted() || _playerTwo.isDefaulted();
}
@Override
public final void resetDamage()
{
_damageP1 = 0;
_damageP2 = 0;
}
protected static final void saveResults(Participant one, Participant two, int winner, long startTime, long fightTime, CompetitionType type)
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("INSERT INTO olympiad_fights (charOneId, charTwoId, charOneClass, charTwoClass, winner, start, time, classed) values(?,?,?,?,?,?,?,?)"))
{
ps.setInt(1, one.getObjectId());
ps.setInt(2, two.getObjectId());
ps.setInt(3, one.getBaseClass());
ps.setInt(4, two.getBaseClass());
ps.setInt(5, winner);
ps.setLong(6, startTime);
ps.setLong(7, fightTime);
ps.setInt(8, (type == CompetitionType.CLASSED ? 1 : 0));
ps.execute();
}
catch (SQLException e)
{
if (_log.isLoggable(Level.SEVERE))
{
_log.log(Level.SEVERE, "SQL exception while saving olympiad fight.", e);
}
}
}
}

View File

@ -0,0 +1,536 @@
/*
* This file is part of the L2J Mobius project.
*
* 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.l2jmobius.gameserver.model.olympiad;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.ThreadPoolManager;
import com.l2jmobius.gameserver.model.zone.type.L2OlympiadStadiumZone;
import com.l2jmobius.gameserver.network.SystemMessageId;
import com.l2jmobius.gameserver.network.serverpackets.SystemMessage;
/**
* @author DS
*/
public final class OlympiadGameTask implements Runnable
{
protected static final Logger _log = Logger.getLogger(OlympiadGameTask.class.getName());
protected static final long BATTLE_PERIOD = Config.ALT_OLY_BATTLE; // 6 mins
private static final int[] TELEPORT_TO_ARENA_TIMES =
{
120,
60,
30,
15,
10,
5,
4,
3,
2,
1,
0
};
private static final int[] BATTLE_START_TIME_FIRST =
{
60,
50,
40,
30,
20,
10,
0
};
private static final int[] BATTLE_START_TIME_SECOND =
{
10,
5,
4,
3,
2,
1,
0
};
private static final int[] TELEPORT_TO_TOWN_TIMES =
{
40,
30,
20,
10,
5,
4,
3,
2,
1,
0
};
private final L2OlympiadStadiumZone _zone;
private AbstractOlympiadGame _game;
private GameState _state = GameState.IDLE;
private boolean _needAnnounce = false;
private int _countDown = 0;
private static enum GameState
{
BEGIN,
TELEPORT_TO_ARENA,
GAME_STARTED,
BATTLE_COUNTDOWN_FIRST,
BATTLE_COUNTDOWN_SECOND,
BATTLE_STARTED,
BATTLE_IN_PROGRESS,
GAME_CANCELLED,
GAME_STOPPED,
TELEPORT_TO_TOWN,
CLEANUP,
IDLE
}
public OlympiadGameTask(L2OlympiadStadiumZone zone)
{
_zone = zone;
zone.registerTask(this);
}
public final boolean isRunning()
{
return _state != GameState.IDLE;
}
public final boolean isGameStarted()
{
return (_state.ordinal() >= GameState.GAME_STARTED.ordinal()) && (_state.ordinal() <= GameState.CLEANUP.ordinal());
}
public final boolean isBattleStarted()
{
return _state == GameState.BATTLE_IN_PROGRESS;
}
public final boolean isBattleFinished()
{
return _state == GameState.TELEPORT_TO_TOWN;
}
public final boolean needAnnounce()
{
if (_needAnnounce)
{
_needAnnounce = false;
return true;
}
return false;
}
public final L2OlympiadStadiumZone getZone()
{
return _zone;
}
public final AbstractOlympiadGame getGame()
{
return _game;
}
public final void attachGame(AbstractOlympiadGame game)
{
if ((game != null) && (_state != GameState.IDLE))
{
_log.log(Level.WARNING, "Attempt to overwrite non-finished game in state " + _state);
return;
}
_game = game;
_state = GameState.BEGIN;
_needAnnounce = false;
ThreadPoolManager.getInstance().executeGeneral(this);
}
@Override
public final void run()
{
try
{
int delay = 1; // schedule next call after 1s
switch (_state)
{
// Game created
case BEGIN:
{
_state = GameState.TELEPORT_TO_ARENA;
_countDown = Config.ALT_OLY_WAIT_TIME;
break;
}
// Teleport to arena countdown
case TELEPORT_TO_ARENA:
{
if (_countDown > 0)
{
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_WILL_BE_MOVED_TO_THE_OLYMPIAD_STADIUM_IN_S1_SECOND_S);
sm.addInt(_countDown);
_game.broadcastPacket(sm);
}
delay = getDelay(TELEPORT_TO_ARENA_TIMES);
if (_countDown <= 0)
{
_state = GameState.GAME_STARTED;
}
break;
}
// Game start, port players to arena
case GAME_STARTED:
{
if (!startGame())
{
_state = GameState.GAME_CANCELLED;
break;
}
_state = GameState.BATTLE_COUNTDOWN_FIRST;
_countDown = BATTLE_START_TIME_FIRST[0];
delay = 5;
break;
}
// Battle start countdown, first part (60-10)
case BATTLE_COUNTDOWN_FIRST:
{
if (_countDown > 0)
{
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.THE_MATCH_WILL_START_IN_S1_SECOND_S);
sm.addInt(_countDown);
_zone.broadcastPacket(sm);
}
delay = getDelay(BATTLE_START_TIME_FIRST);
if (_countDown <= 0)
{
openDoors();
_state = GameState.BATTLE_COUNTDOWN_SECOND;
_countDown = BATTLE_START_TIME_SECOND[0];
delay = getDelay(BATTLE_START_TIME_SECOND);
}
break;
}
// Battle start countdown, second part (10-0)
case BATTLE_COUNTDOWN_SECOND:
{
if (_countDown > 0)
{
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.THE_MATCH_WILL_START_IN_S1_SECOND_S);
sm.addInt(_countDown);
_zone.broadcastPacket(sm);
}
delay = getDelay(BATTLE_START_TIME_SECOND);
if (_countDown <= 0)
{
_state = GameState.BATTLE_STARTED;
}
break;
}
// Beginning of the battle
case BATTLE_STARTED:
{
_countDown = 0;
_state = GameState.BATTLE_IN_PROGRESS; // set state first, used in zone update
if (!startBattle())
{
_state = GameState.GAME_STOPPED;
}
break;
}
// Checks during battle
case BATTLE_IN_PROGRESS:
{
_countDown += 1000;
if (checkBattle() || (_countDown > Config.ALT_OLY_BATTLE))
{
_state = GameState.GAME_STOPPED;
}
break;
}
// Battle cancelled before teleport participants to the stadium
case GAME_CANCELLED:
{
stopGame();
_state = GameState.CLEANUP;
break;
}
// End of the battle
case GAME_STOPPED:
{
_state = GameState.TELEPORT_TO_TOWN;
_countDown = TELEPORT_TO_TOWN_TIMES[0];
stopGame();
delay = getDelay(TELEPORT_TO_TOWN_TIMES);
break;
}
// Teleport to town countdown
case TELEPORT_TO_TOWN:
{
if (_countDown > 0)
{
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_WILL_BE_MOVED_BACK_TO_TOWN_IN_S1_SECOND_S);
sm.addInt(_countDown);
_game.broadcastPacket(sm);
}
delay = getDelay(TELEPORT_TO_TOWN_TIMES);
if (_countDown <= 0)
{
_state = GameState.CLEANUP;
}
break;
}
// Removals
case CLEANUP:
{
cleanupGame();
_state = GameState.IDLE;
_game = null;
return;
}
}
ThreadPoolManager.getInstance().scheduleGeneral(this, delay * 1000);
}
catch (Exception e)
{
switch (_state)
{
case GAME_STOPPED:
case TELEPORT_TO_TOWN:
case CLEANUP:
case IDLE:
{
_log.log(Level.WARNING, "Unable to return players back in town, exception: " + e.getMessage());
_state = GameState.IDLE;
_game = null;
return;
}
}
_log.log(Level.WARNING, "Exception in " + _state + ", trying to port players back: " + e.getMessage(), e);
_state = GameState.GAME_STOPPED;
ThreadPoolManager.getInstance().scheduleGeneral(this, 1000);
}
}
private final int getDelay(int[] times)
{
int time;
for (int i = 0; i < (times.length - 1); i++)
{
time = times[i];
if (time >= _countDown)
{
continue;
}
final int delay = _countDown - time;
_countDown = time;
return delay;
}
// should not happens
_countDown = -1;
return 1;
}
/**
* Second stage: check for defaulted, port players to arena, announce game.
* @return true if no participants defaulted.
*/
private final boolean startGame()
{
try
{
// Checking for opponents and teleporting to arena
if (_game.checkDefaulted())
{
return false;
}
_zone.closeDoors();
if (_game.needBuffers())
{
_zone.spawnBuffers();
}
if (!_game.portPlayersToArena(_zone.getSpawns()))
{
return false;
}
_game.removals();
_needAnnounce = true;
OlympiadGameManager.getInstance().startBattle(); // inform manager
return true;
}
catch (Exception e)
{
_log.log(Level.WARNING, e.getMessage(), e);
}
return false;
}
/**
* Third stage: open doors.
*/
private final void openDoors()
{
try
{
_game.resetDamage();
_zone.openDoors();
}
catch (Exception e)
{
_log.log(Level.WARNING, e.getMessage(), e);
}
}
/**
* Fourth stage: last checks, remove buffers, start competition itself.
* @return true if all participants online and ready on the stadium.
*/
private final boolean startBattle()
{
try
{
if (_game.needBuffers())
{
_zone.deleteBuffers();
}
if (_game.checkBattleStatus() && _game.makeCompetitionStart())
{
// game successfully started
_game.broadcastOlympiadInfo(_zone);
_zone.broadcastPacket(SystemMessage.getSystemMessage(SystemMessageId.THE_MATCH_HAS_STARTED_FIGHT));
_zone.updateZoneStatusForCharactersInside();
return true;
}
}
catch (Exception e)
{
_log.log(Level.WARNING, e.getMessage(), e);
}
return false;
}
/**
* Fifth stage: battle is running, returns true if winner found.
* @return
*/
private final boolean checkBattle()
{
try
{
return _game.haveWinner();
}
catch (Exception e)
{
_log.log(Level.WARNING, e.getMessage(), e);
}
return true;
}
/**
* Sixth stage: winner's validations
*/
private final void stopGame()
{
try
{
_game.validateWinner(_zone);
}
catch (Exception e)
{
_log.log(Level.WARNING, e.getMessage(), e);
}
try
{
_zone.updateZoneStatusForCharactersInside();
}
catch (Exception e)
{
_log.log(Level.WARNING, e.getMessage(), e);
}
try
{
_game.cleanEffects();
}
catch (Exception e)
{
_log.log(Level.WARNING, e.getMessage(), e);
}
}
/**
* Seventh stage: game cleanup (port players back, closing doors, etc)
*/
private final void cleanupGame()
{
try
{
_game.playersStatusBack();
}
catch (Exception e)
{
_log.log(Level.WARNING, e.getMessage(), e);
}
try
{
_game.portPlayersBack();
}
catch (Exception e)
{
_log.log(Level.WARNING, e.getMessage(), e);
}
try
{
_game.clearPlayers();
}
catch (Exception e)
{
_log.log(Level.WARNING, e.getMessage(), e);
}
try
{
_zone.closeDoors();
}
catch (Exception e)
{
_log.log(Level.WARNING, e.getMessage(), e);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,98 @@
/*
* This file is part of the L2J Mobius project.
*
* 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.l2jmobius.gameserver.model.olympiad;
/**
* @author JIV
*/
public class OlympiadInfo
{
private final String _name;
private final String _clan;
private final int _clanId;
private final int _classId;
private final int _dmg;
private final int _curPoints;
private final int _diffPoints;
public OlympiadInfo(String name, String clan, int clanId, int classId, int dmg, int curPoints, int diffPoints)
{
_name = name;
_clan = clan;
_clanId = clanId;
_classId = classId;
_dmg = dmg;
_curPoints = curPoints;
_diffPoints = diffPoints;
}
/**
* @return the name the player's name.
*/
public String getName()
{
return _name;
}
/**
* @return the name the player's clan name.
*/
public String getClanName()
{
return _clan;
}
/**
* @return the name the player's clan id.
*/
public int getClanId()
{
return _clanId;
}
/**
* @return the name the player's class id.
*/
public int getClassId()
{
return _classId;
}
/**
* @return the name the player's damage.
*/
public int getDamage()
{
return _dmg;
}
/**
* @return the name the player's current points.
*/
public int getCurrentPoints()
{
return _curPoints;
}
/**
* @return the name the player's points difference since this match.
*/
public int getDiffPoints()
{
return _diffPoints;
}
}

View File

@ -0,0 +1,583 @@
/*
* This file is part of the L2J Mobius project.
*
* 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.l2jmobius.gameserver.model.olympiad;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.ThreadPoolManager;
import com.l2jmobius.gameserver.instancemanager.AntiFeedManager;
import com.l2jmobius.gameserver.model.L2Party;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.StatsSet;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.network.SystemMessageId;
import com.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jmobius.gameserver.network.serverpackets.SystemMessage;
/**
* @author DS
*/
public class OlympiadManager
{
private final List<Integer> _nonClassBasedRegisters;
private final Map<Integer, List<Integer>> _classBasedRegisters;
private final List<List<Integer>> _teamsBasedRegisters;
protected OlympiadManager()
{
_nonClassBasedRegisters = new CopyOnWriteArrayList<>();
_classBasedRegisters = new ConcurrentHashMap<>();
_teamsBasedRegisters = new CopyOnWriteArrayList<>();
}
public static final OlympiadManager getInstance()
{
return SingletonHolder._instance;
}
public final List<Integer> getRegisteredNonClassBased()
{
return _nonClassBasedRegisters;
}
public final Map<Integer, List<Integer>> getRegisteredClassBased()
{
return _classBasedRegisters;
}
public final List<List<Integer>> getRegisteredTeamsBased()
{
return _teamsBasedRegisters;
}
protected final List<List<Integer>> hasEnoughRegisteredClassed()
{
List<List<Integer>> result = null;
for (Map.Entry<Integer, List<Integer>> classList : _classBasedRegisters.entrySet())
{
if ((classList.getValue() != null) && (classList.getValue().size() >= Config.ALT_OLY_CLASSED))
{
if (result == null)
{
result = new CopyOnWriteArrayList<>();
}
result.add(classList.getValue());
}
}
return result;
}
protected final boolean hasEnoughRegisteredNonClassed()
{
return _nonClassBasedRegisters.size() >= Config.ALT_OLY_NONCLASSED;
}
protected final boolean hasEnoughRegisteredTeams()
{
return _teamsBasedRegisters.size() >= Config.ALT_OLY_TEAMS;
}
protected final void clearRegistered()
{
_nonClassBasedRegisters.clear();
_classBasedRegisters.clear();
_teamsBasedRegisters.clear();
AntiFeedManager.getInstance().clear(AntiFeedManager.OLYMPIAD_ID);
}
public final boolean isRegistered(L2PcInstance noble)
{
return isRegistered(noble, noble, false);
}
private final boolean isRegistered(L2PcInstance noble, L2PcInstance player, boolean showMessage)
{
final Integer objId = Integer.valueOf(noble.getObjectId());
// party may be already dispersed
for (List<Integer> team : _teamsBasedRegisters)
{
if ((team != null) && team.contains(objId))
{
if (showMessage)
{
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_ALREADY_REGISTERED_ON_THE_WAITING_LIST_FOR_THE_3_VS_3_CLASS_IRRELEVANT_TEAM_MATCH);
sm.addPcName(noble);
player.sendPacket(sm);
}
return true;
}
}
if (_nonClassBasedRegisters.contains(objId))
{
if (showMessage)
{
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_ALREADY_REGISTERED_ON_THE_WAITING_LIST_FOR_THE_ALL_CLASS_BATTLE);
sm.addPcName(noble);
player.sendPacket(sm);
}
return true;
}
final List<Integer> classed = _classBasedRegisters.get(noble.getBaseClassId());
if ((classed != null) && classed.contains(objId))
{
if (showMessage)
{
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_ALREADY_REGISTERED_ON_THE_CLASS_MATCH_WAITING_LIST);
sm.addPcName(noble);
player.sendPacket(sm);
}
return true;
}
return false;
}
public final boolean isRegisteredInComp(L2PcInstance noble)
{
return isRegistered(noble, noble, false) || isInCompetition(noble, noble, false);
}
private final boolean isInCompetition(L2PcInstance noble, L2PcInstance player, boolean showMessage)
{
if (!Olympiad._inCompPeriod)
{
return false;
}
AbstractOlympiadGame game;
for (int i = OlympiadGameManager.getInstance().getNumberOfStadiums(); --i >= 0;)
{
game = OlympiadGameManager.getInstance().getOlympiadTask(i).getGame();
if (game == null)
{
continue;
}
if (game.containsParticipant(noble.getObjectId()))
{
if (!showMessage)
{
return true;
}
switch (game.getType())
{
case CLASSED:
{
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_ALREADY_REGISTERED_ON_THE_CLASS_MATCH_WAITING_LIST);
sm.addPcName(noble);
player.sendPacket(sm);
break;
}
case NON_CLASSED:
{
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_ALREADY_REGISTERED_ON_THE_WAITING_LIST_FOR_THE_ALL_CLASS_BATTLE);
sm.addPcName(noble);
player.sendPacket(sm);
break;
}
case TEAMS:
{
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_ALREADY_REGISTERED_ON_THE_WAITING_LIST_FOR_THE_3_VS_3_CLASS_IRRELEVANT_TEAM_MATCH);
sm.addPcName(noble);
player.sendPacket(sm);
break;
}
}
return true;
}
}
return false;
}
public final boolean registerNoble(L2PcInstance player, CompetitionType type)
{
if (!Olympiad._inCompPeriod)
{
player.sendPacket(SystemMessageId.THE_OLYMPIAD_GAMES_ARE_NOT_CURRENTLY_IN_PROGRESS);
return false;
}
if (Olympiad.getInstance().getMillisToCompEnd() < 600000)
{
player.sendPacket(SystemMessageId.PARTICIPATION_REQUESTS_ARE_NO_LONGER_BEING_ACCEPTED);
return false;
}
final int charId = player.getObjectId();
if (Olympiad.getInstance().getRemainingWeeklyMatches(charId) < 1)
{
player.sendPacket(SystemMessageId.THE_MAXIMUM_MATCHES_YOU_CAN_PARTICIPATE_IN_1_WEEK_IS_30);
return false;
}
switch (type)
{
case CLASSED:
{
if (!checkNoble(player, player))
{
return false;
}
if (Olympiad.getInstance().getRemainingWeeklyMatchesClassed(charId) < 1)
{
player.sendPacket(SystemMessageId.YOU_CAN_ENTER_UP_TO_50_FREE_FOR_ALL_BATTLES_AND_50_CLASS_SPECIFIC_BATTLES_PER_WEEK);
return false;
}
List<Integer> classed = _classBasedRegisters.get(player.getBaseClassId());
if (classed != null)
{
classed.add(charId);
}
else
{
classed = new CopyOnWriteArrayList<>();
classed.add(charId);
_classBasedRegisters.put(player.getBaseClassId(), classed);
}
player.sendPacket(SystemMessageId.YOU_HAVE_BEEN_REGISTERED_FOR_THE_OLYMPIAD_WAITING_LIST_FOR_A_CLASS_BATTLE);
break;
}
case NON_CLASSED:
{
if (!checkNoble(player, player))
{
return false;
}
if (Olympiad.getInstance().getRemainingWeeklyMatchesNonClassed(charId) < 1)
{
player.sendPacket(SystemMessageId.YOU_CAN_ENTER_UP_TO_50_FREE_FOR_ALL_BATTLES_AND_50_CLASS_SPECIFIC_BATTLES_PER_WEEK);
return false;
}
_nonClassBasedRegisters.add(charId);
player.sendPacket(SystemMessageId.YOU_ARE_CURRENTLY_REGISTERED_FOR_A_1V1_CLASS_IRRELEVANT_MATCH);
break;
}
case TEAMS:
{
final L2Party party = player.getParty();
if ((party == null) || (party.getMemberCount() != 3))
{
player.sendPacket(SystemMessageId.THE_REQUEST_CANNOT_BE_MADE_BECAUSE_THE_REQUIREMENTS_HAVE_NOT_BEEN_MET_TO_PARTICIPATE_IN_A_TEAM_MATCH_YOU_MUST_FIRST_FORM_A_3_MEMBER_PARTY);
return false;
}
if (!party.isLeader(player))
{
player.sendPacket(SystemMessageId.ONLY_A_PARTY_LEADER_CAN_REQUEST_A_TEAM_MATCH);
return false;
}
int teamPoints = 0;
final List<Integer> team = new ArrayList<>(party.getMemberCount());
for (L2PcInstance noble : party.getMembers())
{
if (!checkNoble(noble, player))
{
// remove previously registered party members
if (Config.L2JMOD_DUALBOX_CHECK_MAX_OLYMPIAD_PARTICIPANTS_PER_IP > 0)
{
for (L2PcInstance unreg : party.getMembers())
{
if (unreg == noble)
{
break;
}
AntiFeedManager.getInstance().removePlayer(AntiFeedManager.OLYMPIAD_ID, unreg);
}
}
return false;
}
if (Olympiad.getInstance().getRemainingWeeklyMatchesTeam(noble.getObjectId()) < 1)
{
player.sendPacket(SystemMessageId.YOU_CAN_ENTER_UP_TO_50_FREE_FOR_ALL_BATTLES_AND_50_CLASS_SPECIFIC_BATTLES_PER_WEEK);
return false;
}
team.add(noble.getObjectId());
teamPoints += Olympiad.getInstance().getNoblePoints(noble.getObjectId());
}
if (teamPoints < 10)
{
// TODO: replace with retail message
player.sendMessage("Your team must have at least 10 points in total.");
// remove previously registered party members
if (Config.L2JMOD_DUALBOX_CHECK_MAX_OLYMPIAD_PARTICIPANTS_PER_IP > 0)
{
for (L2PcInstance unreg : party.getMembers())
{
AntiFeedManager.getInstance().removePlayer(AntiFeedManager.OLYMPIAD_ID, unreg);
}
}
return false;
}
party.broadcastPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_ARE_CURRENTLY_REGISTERED_FOR_A_3_VS_3_CLASS_IRRELEVANT_TEAM_MATCH));
_teamsBasedRegisters.add(team);
break;
}
}
return true;
}
public final boolean unRegisterNoble(L2PcInstance noble)
{
if (!Olympiad._inCompPeriod)
{
noble.sendPacket(SystemMessageId.THE_OLYMPIAD_GAMES_ARE_NOT_CURRENTLY_IN_PROGRESS);
return false;
}
if (!noble.isNoble())
{
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_DOES_NOT_MEET_THE_PARTICIPATION_REQUIREMENTS_ONLY_NOBLESSE_EXALTED_CHARACTERS_CAN_PARTICIPATE_IN_THE_OLYMPIAD);
sm.addString(noble.getName());
noble.sendPacket(sm);
return false;
}
if (!isRegistered(noble, noble, false))
{
noble.sendPacket(SystemMessageId.YOU_ARE_NOT_CURRENTLY_REGISTERED_FOR_THE_OLYMPIAD);
return false;
}
if (isInCompetition(noble, noble, false))
{
return false;
}
final Integer objId = Integer.valueOf(noble.getObjectId());
if (_nonClassBasedRegisters.remove(objId))
{
if (Config.L2JMOD_DUALBOX_CHECK_MAX_OLYMPIAD_PARTICIPANTS_PER_IP > 0)
{
AntiFeedManager.getInstance().removePlayer(AntiFeedManager.OLYMPIAD_ID, noble);
}
noble.sendPacket(SystemMessageId.YOU_HAVE_BEEN_REMOVED_FROM_THE_OLYMPIAD_WAITING_LIST);
return true;
}
final List<Integer> classed = _classBasedRegisters.get(noble.getBaseClassId());
if ((classed != null) && classed.remove(objId))
{
_classBasedRegisters.put(noble.getBaseClassId(), classed);
if (Config.L2JMOD_DUALBOX_CHECK_MAX_OLYMPIAD_PARTICIPANTS_PER_IP > 0)
{
AntiFeedManager.getInstance().removePlayer(AntiFeedManager.OLYMPIAD_ID, noble);
}
noble.sendPacket(SystemMessageId.YOU_HAVE_BEEN_REMOVED_FROM_THE_OLYMPIAD_WAITING_LIST);
return true;
}
for (List<Integer> team : _teamsBasedRegisters)
{
if ((team != null) && team.contains(objId))
{
_teamsBasedRegisters.remove(team);
ThreadPoolManager.getInstance().executeGeneral(new AnnounceUnregToTeam(team));
return true;
}
}
return false;
}
public final void removeDisconnectedCompetitor(L2PcInstance player)
{
final OlympiadGameTask task = OlympiadGameManager.getInstance().getOlympiadTask(player.getOlympiadGameId());
if ((task != null) && task.isGameStarted())
{
task.getGame().handleDisconnect(player);
}
final Integer objId = Integer.valueOf(player.getObjectId());
if (_nonClassBasedRegisters.remove(objId))
{
return;
}
final List<Integer> classed = _classBasedRegisters.get(player.getBaseClassId());
if ((classed != null) && classed.remove(objId))
{
return;
}
for (List<Integer> team : _teamsBasedRegisters)
{
if ((team != null) && team.contains(objId))
{
_teamsBasedRegisters.remove(team);
ThreadPoolManager.getInstance().executeGeneral(new AnnounceUnregToTeam(team));
return;
}
}
}
/**
* @param noble - checked noble
* @param player - messages will be sent to this L2PcInstance
* @return true if all requirements are met
*/
// TODO: move to the bypass handler after reworking points system
private final boolean checkNoble(L2PcInstance noble, L2PcInstance player)
{
SystemMessage sm;
if (!noble.isNoble())
{
sm = SystemMessage.getSystemMessage(SystemMessageId.C1_DOES_NOT_MEET_THE_PARTICIPATION_REQUIREMENTS_ONLY_NOBLESSE_EXALTED_CHARACTERS_CAN_PARTICIPATE_IN_THE_OLYMPIAD);
sm.addPcName(noble);
player.sendPacket(sm);
return false;
}
if (noble.isSubClassActive())
{
sm = SystemMessage.getSystemMessage(SystemMessageId.C1_DOES_NOT_MEET_THE_PARTICIPATION_REQUIREMENTS_SUBCLASSES_AND_DUEL_CLASSES_CANNOT_PARTICIPATE_IN_THE_OLYMPIAD);
sm.addPcName(noble);
player.sendPacket(sm);
return false;
}
if (noble.isCursedWeaponEquipped())
{
sm = SystemMessage.getSystemMessage(SystemMessageId.C1_DOES_NOT_MEET_THE_PARTICIPATION_REQUIREMENTS_THE_OWNER_OF_S2_CANNOT_PARTICIPATE_IN_THE_OLYMPIAD);
sm.addPcName(noble);
sm.addItemName(noble.getCursedWeaponEquippedId());
player.sendPacket(sm);
return false;
}
if (!noble.isInventoryUnder90(true))
{
sm = SystemMessage.getSystemMessage(SystemMessageId.C1_DOES_NOT_MEET_THE_PARTICIPATION_REQUIREMENTS_AS_THE_INVENTORY_WEIGHT_SLOT_IS_FILLED_BEYOND_80);
sm.addPcName(noble);
player.sendPacket(sm);
return false;
}
final int charId = noble.getObjectId();
if (noble.isOnEvent())
{
player.sendMessage("You can't join olympiad while participating on TvT Event.");
return false;
}
if (isRegistered(noble, player, true))
{
return false;
}
if (isInCompetition(noble, player, true))
{
return false;
}
StatsSet statDat = Olympiad.getNobleStats(charId);
if (statDat == null)
{
statDat = new StatsSet();
statDat.set(Olympiad.CLASS_ID, noble.getBaseClassId());
statDat.set(Olympiad.CHAR_NAME, noble.getName());
statDat.set(Olympiad.POINTS, Olympiad.DEFAULT_POINTS);
statDat.set(Olympiad.COMP_DONE, 0);
statDat.set(Olympiad.COMP_WON, 0);
statDat.set(Olympiad.COMP_LOST, 0);
statDat.set(Olympiad.COMP_DRAWN, 0);
statDat.set(Olympiad.COMP_DONE_WEEK, 0);
statDat.set(Olympiad.COMP_DONE_WEEK_CLASSED, 0);
statDat.set(Olympiad.COMP_DONE_WEEK_NON_CLASSED, 0);
statDat.set(Olympiad.COMP_DONE_WEEK_TEAM, 0);
statDat.set("to_save", true);
Olympiad.addNobleStats(charId, statDat);
}
final int points = Olympiad.getInstance().getNoblePoints(charId);
if (points <= 0)
{
final NpcHtmlMessage message = new NpcHtmlMessage(player.getLastHtmlActionOriginId());
message.setFile(player.getHtmlPrefix(), "html/olympiad/noble_nopoints1.htm");
message.replace("%objectId%", String.valueOf(noble.getLastHtmlActionOriginId()));
player.sendPacket(message);
return false;
}
if ((Config.L2JMOD_DUALBOX_CHECK_MAX_OLYMPIAD_PARTICIPANTS_PER_IP > 0) && !AntiFeedManager.getInstance().tryAddPlayer(AntiFeedManager.OLYMPIAD_ID, noble, Config.L2JMOD_DUALBOX_CHECK_MAX_OLYMPIAD_PARTICIPANTS_PER_IP))
{
final NpcHtmlMessage message = new NpcHtmlMessage(player.getLastHtmlActionOriginId());
message.setFile(player.getHtmlPrefix(), "html/mods/OlympiadIPRestriction.htm");
message.replace("%max%", String.valueOf(AntiFeedManager.getInstance().getLimit(player, Config.L2JMOD_DUALBOX_CHECK_MAX_OLYMPIAD_PARTICIPANTS_PER_IP)));
player.sendPacket(message);
return false;
}
return true;
}
private static final class AnnounceUnregToTeam implements Runnable
{
private final List<Integer> _team;
public AnnounceUnregToTeam(List<Integer> t)
{
_team = t;
}
@Override
public final void run()
{
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_BEEN_REMOVED_FROM_THE_OLYMPIAD_WAITING_LIST);
for (int objectId : _team)
{
final L2PcInstance teamMember = L2World.getInstance().getPlayer(objectId);
if (teamMember != null)
{
teamMember.sendPacket(sm);
if (Config.L2JMOD_DUALBOX_CHECK_MAX_OLYMPIAD_PARTICIPANTS_PER_IP > 0)
{
AntiFeedManager.getInstance().removePlayer(AntiFeedManager.OLYMPIAD_ID, teamMember);
}
}
}
}
}
public int getCountOpponents()
{
return _nonClassBasedRegisters.size() + _classBasedRegisters.size() + _teamsBasedRegisters.size();
}
private static class SingletonHolder
{
protected static final OlympiadManager _instance = new OlympiadManager();
}
}

View File

@ -0,0 +1,188 @@
/*
* This file is part of the L2J Mobius project.
*
* 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.l2jmobius.gameserver.model.olympiad;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.StatsSet;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
/**
* @author DS, Zoey76
*/
public final class Participant
{
private final int objectId;
private L2PcInstance player;
private final String name;
private final int side;
private final int baseClass;
private boolean disconnected = false;
private boolean defaulted = false;
private final StatsSet stats;
public String clanName;
public int clanId;
public Participant(L2PcInstance plr, int olympiadSide)
{
objectId = plr.getObjectId();
player = plr;
name = plr.getName();
side = olympiadSide;
baseClass = plr.getBaseClassId();
stats = Olympiad.getNobleStats(getObjectId());
clanName = plr.getClan() != null ? plr.getClan().getName() : "";
clanId = plr.getClanId();
}
public Participant(int objId, int olympiadSide)
{
objectId = objId;
player = null;
name = "-";
side = olympiadSide;
baseClass = 0;
stats = null;
clanName = "";
clanId = 0;
}
/**
* Updates the reference to {@link #player}, if it's null or appears off-line.
* @return {@code true} if after the update the player isn't null, {@code false} otherwise.
*/
public final boolean updatePlayer()
{
if ((player == null) || !player.isOnline())
{
player = L2World.getInstance().getPlayer(getObjectId());
}
return (player != null);
}
/**
* @param statName
* @param increment
*/
public final void updateStat(String statName, int increment)
{
stats.set(statName, Math.max(stats.getInt(statName) + increment, 0));
}
/**
* @return the name the player's name.
*/
public String getName()
{
return name;
}
/**
* @return the name the player's clan name.
*/
public String getClanName()
{
return clanName;
}
/**
* @return the name the player's id.
*/
public int getClanId()
{
return clanId;
}
/**
* @return the player
*/
public L2PcInstance getPlayer()
{
return player;
}
/**
* @return the objectId
*/
public int getObjectId()
{
return objectId;
}
/**
* @return the stats
*/
public StatsSet getStats()
{
return stats;
}
/**
* @param noble the player to set
*/
public void setPlayer(L2PcInstance noble)
{
player = noble;
}
/**
* @return the side
*/
public int getSide()
{
return side;
}
/**
* @return the baseClass
*/
public int getBaseClass()
{
return baseClass;
}
/**
* @return the disconnected
*/
public boolean isDisconnected()
{
return disconnected;
}
/**
* @param val the disconnected to set
*/
public void setDisconnected(boolean val)
{
disconnected = val;
}
/**
* @return the defaulted
*/
public boolean isDefaulted()
{
return defaulted;
}
/**
* @param val the value to set.
*/
public void setDefaulted(boolean val)
{
defaulted = val;
}
}