actual freya branch
This commit is contained in:
@@ -0,0 +1,499 @@
|
||||
/*
|
||||
* 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.l2jserver.gameserver.model.olympiad;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jserver.Config;
|
||||
import com.l2jserver.gameserver.ai.CtrlIntention;
|
||||
import com.l2jserver.gameserver.datatables.HeroSkillTable;
|
||||
import com.l2jserver.gameserver.instancemanager.AntiFeedManager;
|
||||
import com.l2jserver.gameserver.instancemanager.CastleManager;
|
||||
import com.l2jserver.gameserver.instancemanager.FortManager;
|
||||
import com.l2jserver.gameserver.model.L2ItemInstance;
|
||||
import com.l2jserver.gameserver.model.L2Party;
|
||||
import com.l2jserver.gameserver.model.L2Skill;
|
||||
import com.l2jserver.gameserver.model.Location;
|
||||
import com.l2jserver.gameserver.model.actor.L2Character;
|
||||
import com.l2jserver.gameserver.model.actor.L2Summon;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
|
||||
import com.l2jserver.gameserver.model.entity.TvTEvent;
|
||||
import com.l2jserver.gameserver.model.zone.type.L2OlympiadStadiumZone;
|
||||
import com.l2jserver.gameserver.network.SystemMessageId;
|
||||
import com.l2jserver.gameserver.network.serverpackets.ExOlympiadMode;
|
||||
import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
|
||||
import com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket;
|
||||
import com.l2jserver.gameserver.network.serverpackets.SkillCoolTime;
|
||||
import com.l2jserver.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 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_GAINED_S2_OLYMPIAD_POINTS);
|
||||
sm.addString(par.name);
|
||||
sm.addNumber(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_OLYMPIAD_POINTS);
|
||||
sm.addString(par.name);
|
||||
sm.addNumber(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.THE_GAME_HAS_BEEN_CANCELLED_BECAUSE_THE_OTHER_PARTY_ENDS_THE_GAME);
|
||||
}
|
||||
|
||||
if ((player.getClient() == null) || player.getClient().isDetached())
|
||||
{
|
||||
return SystemMessage.getSystemMessage(SystemMessageId.THE_GAME_HAS_BEEN_CANCELLED_BECAUSE_THE_OTHER_PARTY_ENDS_THE_GAME);
|
||||
}
|
||||
|
||||
// safety precautions
|
||||
if (player.inObserverMode() || TvTEvent.isPlayerParticipant(player.getObjectId()))
|
||||
{
|
||||
return SystemMessage.getSystemMessage(SystemMessageId.THE_GAME_HAS_BEEN_CANCELLED_BECAUSE_THE_OTHER_PARTY_DOES_NOT_MEET_THE_REQUIREMENTS_FOR_JOINING_THE_GAME);
|
||||
}
|
||||
|
||||
SystemMessage sm;
|
||||
if (player.isDead())
|
||||
{
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.C1_CANNOT_PARTICIPATE_OLYMPIAD_WHILE_DEAD);
|
||||
sm.addPcName(player);
|
||||
player.sendPacket(sm);
|
||||
return SystemMessage.getSystemMessage(SystemMessageId.THE_GAME_HAS_BEEN_CANCELLED_BECAUSE_THE_OTHER_PARTY_DOES_NOT_MEET_THE_REQUIREMENTS_FOR_JOINING_THE_GAME);
|
||||
}
|
||||
if (player.isSubClassActive())
|
||||
{
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.C1_CANNOT_PARTICIPATE_IN_OLYMPIAD_WHILE_CHANGED_TO_SUB_CLASS);
|
||||
sm.addPcName(player);
|
||||
player.sendPacket(sm);
|
||||
return SystemMessage.getSystemMessage(SystemMessageId.THE_GAME_HAS_BEEN_CANCELLED_BECAUSE_THE_OTHER_PARTY_DOES_NOT_MEET_THE_REQUIREMENTS_FOR_JOINING_THE_GAME);
|
||||
}
|
||||
if (player.isCursedWeaponEquipped())
|
||||
{
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.C1_CANNOT_JOIN_OLYMPIAD_POSSESSING_S2);
|
||||
sm.addPcName(player);
|
||||
sm.addItemName(player.getCursedWeaponEquippedId());
|
||||
player.sendPacket(sm);
|
||||
return SystemMessage.getSystemMessage(SystemMessageId.THE_GAME_HAS_BEEN_CANCELLED_BECAUSE_THE_OTHER_PARTY_DOES_NOT_MEET_THE_REQUIREMENTS_FOR_JOINING_THE_GAME);
|
||||
}
|
||||
if (!player.isInventoryUnder80(true))
|
||||
{
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.C1_CANNOT_PARTICIPATE_IN_OLYMPIAD_INVENTORY_SLOT_EXCEEDS_80_PERCENT);
|
||||
sm.addPcName(player);
|
||||
player.sendPacket(sm);
|
||||
return SystemMessage.getSystemMessage(SystemMessageId.THE_GAME_HAS_BEEN_CANCELLED_BECAUSE_THE_OTHER_PARTY_DOES_NOT_MEET_THE_REQUIREMENTS_FOR_JOINING_THE_GAME);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static final boolean portPlayerToArena(Participant par, Location loc, int id)
|
||||
{
|
||||
final L2PcInstance player = par.player;
|
||||
if ((player == null) || !player.isOnline())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
player.setLastCords(player.getX(), player.getY(), player.getZ());
|
||||
if (player.isSitting())
|
||||
{
|
||||
player.standUp();
|
||||
}
|
||||
player.setTarget(null);
|
||||
|
||||
player.setOlympiadGameId(id);
|
||||
player.setIsInOlympiadMode(true);
|
||||
player.setIsOlympiadStart(false);
|
||||
player.setOlympiadSide(par.side);
|
||||
player.olyBuff = 5;
|
||||
player.setInstanceId(0);
|
||||
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().getHasCastle() > 0)
|
||||
{
|
||||
CastleManager.getInstance().getCastleByOwner(player.getClan()).removeResidentialSkills(player);
|
||||
}
|
||||
if (player.getClan().getHasFort() > 0)
|
||||
{
|
||||
FortManager.getInstance().getFortByOwner(player.getClan()).removeResidentialSkills(player);
|
||||
}
|
||||
}
|
||||
// Abort casting if player casting
|
||||
player.abortAttack();
|
||||
player.abortCast();
|
||||
|
||||
// Force the character to be visible
|
||||
player.getAppearance().setVisible();
|
||||
|
||||
// Remove Hero Skills
|
||||
if (player.isHero())
|
||||
{
|
||||
for (L2Skill skill : HeroSkillTable.getHeroSkills())
|
||||
{
|
||||
player.removeSkill(skill, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Heal Player fully
|
||||
player.setCurrentCp(player.getMaxCp());
|
||||
player.setCurrentHp(player.getMaxHp());
|
||||
player.setCurrentMp(player.getMaxMp());
|
||||
|
||||
// Remove Summon's Buffs
|
||||
final L2Summon summon = player.getPet();
|
||||
if (summon != null)
|
||||
{
|
||||
summon.stopAllEffectsExceptThoseThatLastThroughDeath();
|
||||
summon.abortAttack();
|
||||
summon.abortCast();
|
||||
|
||||
if (summon instanceof L2PetInstance)
|
||||
{
|
||||
summon.unSummon(player);
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
// Remove Agathion
|
||||
if (player.getAgathionId() > 0)
|
||||
{
|
||||
player.setAgathionId(0);
|
||||
player.broadcastUserInfo();
|
||||
}
|
||||
|
||||
player.checkItemRestriction();
|
||||
|
||||
// Remove shot automation
|
||||
player.disableAutoShotsAll();
|
||||
|
||||
// Discharge any active shots
|
||||
if (player.getActiveWeaponInstance() != null)
|
||||
{
|
||||
player.getActiveWeaponInstance().setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
|
||||
player.getActiveWeaponInstance().setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
|
||||
}
|
||||
|
||||
// enable skills with cool time <= 15 minutes
|
||||
for (L2Skill 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 summon = player.getPet();
|
||||
if ((summon != null) && !summon.isDead())
|
||||
{
|
||||
summon.setTarget(null);
|
||||
summon.abortAttack();
|
||||
summon.abortCast();
|
||||
summon.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
|
||||
summon.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();
|
||||
}
|
||||
|
||||
player.setIsInOlympiadMode(false);
|
||||
player.setIsOlympiadStart(false);
|
||||
player.setOlympiadSide(-1);
|
||||
player.setOlympiadGameId(-1);
|
||||
player.sendPacket(new ExOlympiadMode(0));
|
||||
|
||||
// Add Clan Skills
|
||||
if (player.getClan() != null)
|
||||
{
|
||||
player.getClan().addSkillEffects(player);
|
||||
if (player.getClan().getHasCastle() > 0)
|
||||
{
|
||||
CastleManager.getInstance().getCastleByOwner(player.getClan()).giveResidentialSkills(player);
|
||||
}
|
||||
if (player.getClan().getHasFort() > 0)
|
||||
{
|
||||
FortManager.getInstance().getFortByOwner(player.getClan()).giveResidentialSkills(player);
|
||||
}
|
||||
}
|
||||
|
||||
// Add Hero Skills
|
||||
if (player.isHero())
|
||||
{
|
||||
for (L2Skill skill : HeroSkillTable.getHeroSkills())
|
||||
{
|
||||
player.addSkill(skill, false);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
if ((player.getLastX() == 0) && (player.getLastY() == 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
player.teleToLocation(player.getLastX(), player.getLastY(), player.getLastZ());
|
||||
player.setLastCords(0, 0, 0);
|
||||
}
|
||||
|
||||
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.EARNED_S2_S1_S);
|
||||
sm.addItemName(it[0]);
|
||||
sm.addNumber(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();
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.l2jserver.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
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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.l2jserver.gameserver.model.olympiad;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javolution.util.FastList;
|
||||
|
||||
import com.l2jserver.gameserver.datatables.SpawnTable;
|
||||
import com.l2jserver.gameserver.model.L2Spawn;
|
||||
import com.l2jserver.gameserver.model.actor.L2Npc;
|
||||
import com.l2jserver.gameserver.network.clientpackets.Say2;
|
||||
import com.l2jserver.gameserver.network.serverpackets.NpcSay;
|
||||
|
||||
/**
|
||||
* @author DS
|
||||
*/
|
||||
public final class OlympiadAnnouncer implements Runnable
|
||||
{
|
||||
private static final int OLY_MANAGER = 31688;
|
||||
|
||||
private final List<L2Spawn> _managers = new FastList<>();
|
||||
private int _currentStadium = 0;
|
||||
|
||||
public OlympiadAnnouncer()
|
||||
{
|
||||
for (L2Spawn spawn : SpawnTable.getInstance().getSpawnTable())
|
||||
{
|
||||
if ((spawn != null) && (spawn.getNpcid() == OLY_MANAGER))
|
||||
{
|
||||
_managers.add(spawn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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())
|
||||
{
|
||||
int msg;
|
||||
final String arenaId = String.valueOf(task.getGame().getStadiumId() + 1);
|
||||
switch (task.getGame().getType())
|
||||
{
|
||||
case NON_CLASSED:
|
||||
// msg = "Olympiad class-free individual match is going to begin in Arena " + arenaId + " in a moment.";
|
||||
msg = 1300166;
|
||||
break;
|
||||
case CLASSED:
|
||||
// msg = "Olympiad class-specific individual match is going to begin in Arena " + arenaId + " in a moment.";
|
||||
msg = 1300167;
|
||||
break;
|
||||
case TEAMS:
|
||||
// msg = "Olympiad class-free team match is going to begin in Arena " + arenaId + " in a moment.";
|
||||
msg = 1300132;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
L2Npc manager;
|
||||
NpcSay packet;
|
||||
for (L2Spawn spawn : _managers)
|
||||
{
|
||||
manager = spawn.getLastSpawn();
|
||||
if (manager != null)
|
||||
{
|
||||
packet = new NpcSay(manager.getObjectId(), Say2.SHOUT, manager.getNpcId(), msg);
|
||||
packet.addStringParameter(arenaId);
|
||||
manager.broadcastPacket(packet);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.l2jserver.gameserver.model.olympiad;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.l2jserver.Config;
|
||||
import com.l2jserver.util.Rnd;
|
||||
|
||||
/**
|
||||
* @author DS
|
||||
*/
|
||||
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 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final int[][] getReward()
|
||||
{
|
||||
return Config.ALT_OLY_CLASSED_REWARD;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* 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.l2jserver.gameserver.model.olympiad;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jserver.gameserver.instancemanager.ZoneManager;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jserver.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;
|
||||
|
||||
private 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);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("synthetic-access")
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final OlympiadGameManager _instance = new OlympiadGameManager();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, either version 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.l2jserver.gameserver.model.olympiad;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.l2jserver.Config;
|
||||
|
||||
/**
|
||||
* @author DS
|
||||
*/
|
||||
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 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final int[][] getReward()
|
||||
{
|
||||
return Config.ALT_OLY_NONCLASSED_REWARD;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,726 @@
|
||||
/*
|
||||
* 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.l2jserver.gameserver.model.olympiad;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
import com.l2jserver.Config;
|
||||
import com.l2jserver.L2DatabaseFactory;
|
||||
import com.l2jserver.gameserver.model.L2World;
|
||||
import com.l2jserver.gameserver.model.Location;
|
||||
import com.l2jserver.gameserver.model.actor.L2Character;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jserver.gameserver.model.zone.type.L2OlympiadStadiumZone;
|
||||
import com.l2jserver.gameserver.network.SystemMessageId;
|
||||
import com.l2jserver.gameserver.network.serverpackets.ExOlympiadUserInfo;
|
||||
import com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket;
|
||||
import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
|
||||
import com.l2jserver.util.Rnd;
|
||||
|
||||
/**
|
||||
* @author GodKratos, Pere, DS
|
||||
*/
|
||||
abstract public 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.player.setOlympiadGameId(id);
|
||||
_playerTwo.player.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;
|
||||
}
|
||||
|
||||
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.objectId == playerId) || (_playerTwo.objectId == 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)
|
||||
{
|
||||
_playerOne.updatePlayer();
|
||||
if (_playerOne.player != null)
|
||||
{
|
||||
_playerOne.player.sendPacket(packet);
|
||||
}
|
||||
|
||||
_playerTwo.updatePlayer();
|
||||
if (_playerTwo.player != null)
|
||||
{
|
||||
_playerTwo.player.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.player, true);
|
||||
removals(_playerTwo.player, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final boolean makeCompetitionStart()
|
||||
{
|
||||
if (!super.makeCompetitionStart())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((_playerOne.player == null) || (_playerTwo.player == null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_playerOne.player.setIsOlympiadStart(true);
|
||||
_playerOne.player.updateEffectIcons();
|
||||
_playerTwo.player.setIsOlympiadStart(true);
|
||||
_playerTwo.player.updateEffectIcons();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void cleanEffects()
|
||||
{
|
||||
if ((_playerOne.player != null) && !_playerOne.defaulted && !_playerOne.disconnected && (_playerOne.player.getOlympiadGameId() == _stadiumID))
|
||||
{
|
||||
cleanEffects(_playerOne.player);
|
||||
}
|
||||
|
||||
if ((_playerTwo.player != null) && !_playerTwo.defaulted && !_playerTwo.disconnected && (_playerTwo.player.getOlympiadGameId() == _stadiumID))
|
||||
{
|
||||
cleanEffects(_playerTwo.player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void portPlayersBack()
|
||||
{
|
||||
if ((_playerOne.player != null) && !_playerOne.defaulted && !_playerOne.disconnected)
|
||||
{
|
||||
portPlayerBack(_playerOne.player);
|
||||
}
|
||||
if ((_playerTwo.player != null) && !_playerTwo.defaulted && !_playerTwo.disconnected)
|
||||
{
|
||||
portPlayerBack(_playerTwo.player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void playersStatusBack()
|
||||
{
|
||||
if ((_playerOne.player != null) && !_playerOne.defaulted && !_playerOne.disconnected && (_playerOne.player.getOlympiadGameId() == _stadiumID))
|
||||
{
|
||||
playerStatusBack(_playerOne.player);
|
||||
}
|
||||
|
||||
if ((_playerTwo.player != null) && !_playerTwo.defaulted && !_playerTwo.disconnected && (_playerTwo.player.getOlympiadGameId() == _stadiumID))
|
||||
{
|
||||
playerStatusBack(_playerTwo.player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void clearPlayers()
|
||||
{
|
||||
_playerOne.player = null;
|
||||
_playerOne = null;
|
||||
_playerTwo.player = null;
|
||||
_playerTwo = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void handleDisconnect(L2PcInstance player)
|
||||
{
|
||||
if (player.getObjectId() == _playerOne.objectId)
|
||||
{
|
||||
_playerOne.disconnected = true;
|
||||
}
|
||||
else if (player.getObjectId() == _playerTwo.objectId)
|
||||
{
|
||||
_playerTwo.disconnected = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final boolean checkBattleStatus()
|
||||
{
|
||||
if (_aborted)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((_playerOne.player == null) || _playerOne.disconnected)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((_playerTwo.player == null) || _playerTwo.disconnected)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final boolean haveWinner()
|
||||
{
|
||||
if (!checkBattleStatus())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean playerOneLost = true;
|
||||
try
|
||||
{
|
||||
if (_playerOne.player.getOlympiadGameId() == _stadiumID)
|
||||
{
|
||||
playerOneLost = _playerOne.player.isDead();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
playerOneLost = true;
|
||||
}
|
||||
|
||||
boolean playerTwoLost = true;
|
||||
try
|
||||
{
|
||||
if (_playerTwo.player.getOlympiadGameId() == _stadiumID)
|
||||
{
|
||||
playerTwoLost = _playerTwo.player.isDead();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
playerTwoLost = true;
|
||||
}
|
||||
|
||||
return playerOneLost || playerTwoLost;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateWinner(L2OlympiadStadiumZone stadium)
|
||||
{
|
||||
if (_aborted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean _pOneCrash = ((_playerOne.player == null) || _playerOne.disconnected);
|
||||
final boolean _pTwoCrash = ((_playerTwo.player == null) || _playerTwo.disconnected);
|
||||
|
||||
final int playerOnePoints = _playerOne.stats.getInteger(POINTS);
|
||||
final int playerTwoPoints = _playerTwo.stats.getInteger(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.defaulted || _playerTwo.defaulted)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_playerOne.defaulted)
|
||||
{
|
||||
try
|
||||
{
|
||||
points = Math.min(playerOnePoints / 3, Config.ALT_OLY_MAX_POINTS);
|
||||
removePointsFromParticipant(_playerOne, points);
|
||||
_playerOne.updateNobleStats();
|
||||
|
||||
if (Config.ALT_OLY_LOG_FIGHTS)
|
||||
{
|
||||
LogRecord record = new LogRecord(Level.INFO, _playerOne.name + " default");
|
||||
record.setParameters(new Object[]
|
||||
{
|
||||
_playerOne.name,
|
||||
_playerTwo.name,
|
||||
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.defaulted)
|
||||
{
|
||||
try
|
||||
{
|
||||
points = Math.min(playerTwoPoints / 3, Config.ALT_OLY_MAX_POINTS);
|
||||
removePointsFromParticipant(_playerTwo, points);
|
||||
_playerTwo.updateNobleStats();
|
||||
|
||||
if (Config.ALT_OLY_LOG_FIGHTS)
|
||||
{
|
||||
LogRecord record = new LogRecord(Level.INFO, _playerTwo.name + " default");
|
||||
record.setParameters(new Object[]
|
||||
{
|
||||
_playerOne.name,
|
||||
_playerTwo.name,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
points,
|
||||
getType().toString()
|
||||
});
|
||||
_logResults.log(record);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Exception on validateWinner(): " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
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.C1_HAS_WON_THE_GAME);
|
||||
sm.addString(_playerOne.name);
|
||||
stadium.broadcastPacket(sm);
|
||||
|
||||
_playerOne.updateStat(COMP_WON, 1);
|
||||
addPointsToParticipant(_playerOne, pointDiff);
|
||||
|
||||
_playerTwo.updateStat(COMP_LOST, 1);
|
||||
removePointsFromParticipant(_playerTwo, pointDiff);
|
||||
|
||||
rewardParticipant(_playerOne.player, getReward());
|
||||
|
||||
if (Config.ALT_OLY_LOG_FIGHTS)
|
||||
{
|
||||
LogRecord record = new LogRecord(Level.INFO, _playerTwo.name + " crash");
|
||||
record.setParameters(new Object[]
|
||||
{
|
||||
_playerOne.name,
|
||||
_playerTwo.name,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
pointDiff,
|
||||
getType().toString()
|
||||
});
|
||||
_logResults.log(record);
|
||||
}
|
||||
}
|
||||
else if (_pOneCrash && !_pTwoCrash)
|
||||
{
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.C1_HAS_WON_THE_GAME);
|
||||
sm.addString(_playerTwo.name);
|
||||
stadium.broadcastPacket(sm);
|
||||
|
||||
_playerTwo.updateStat(COMP_WON, 1);
|
||||
addPointsToParticipant(_playerTwo, pointDiff);
|
||||
|
||||
_playerOne.updateStat(COMP_LOST, 1);
|
||||
removePointsFromParticipant(_playerOne, pointDiff);
|
||||
|
||||
rewardParticipant(_playerTwo.player, getReward());
|
||||
|
||||
if (Config.ALT_OLY_LOG_FIGHTS)
|
||||
{
|
||||
LogRecord record = new LogRecord(Level.INFO, _playerOne.name + " crash");
|
||||
record.setParameters(new Object[]
|
||||
{
|
||||
_playerOne.name,
|
||||
_playerTwo.name,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
pointDiff,
|
||||
getType().toString()
|
||||
});
|
||||
_logResults.log(record);
|
||||
}
|
||||
}
|
||||
else if (_pOneCrash && _pTwoCrash)
|
||||
{
|
||||
stadium.broadcastPacket(SystemMessage.getSystemMessage(SystemMessageId.THE_GAME_ENDED_IN_A_TIE));
|
||||
|
||||
_playerOne.updateStat(COMP_LOST, 1);
|
||||
removePointsFromParticipant(_playerOne, pointDiff);
|
||||
|
||||
_playerTwo.updateStat(COMP_LOST, 1);
|
||||
removePointsFromParticipant(_playerTwo, pointDiff);
|
||||
|
||||
if (Config.ALT_OLY_LOG_FIGHTS)
|
||||
{
|
||||
LogRecord record = new LogRecord(Level.INFO, "both crash");
|
||||
record.setParameters(new Object[]
|
||||
{
|
||||
_playerOne.name,
|
||||
_playerTwo.name,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
pointDiff,
|
||||
getType().toString()
|
||||
});
|
||||
_logResults.log(record);
|
||||
}
|
||||
}
|
||||
|
||||
_playerOne.updateStat(COMP_DONE, 1);
|
||||
_playerTwo.updateStat(COMP_DONE, 1);
|
||||
|
||||
_playerOne.updateNobleStats();
|
||||
_playerTwo.updateNobleStats();
|
||||
return;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Exception on validateWinner(): " + e.getMessage(), e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
String winner = "draw";
|
||||
|
||||
// Calculate Fight time
|
||||
long _fightTime = (System.currentTimeMillis() - _startTime);
|
||||
|
||||
double playerOneHp = 0;
|
||||
if ((_playerOne.player != null) && !_playerOne.player.isDead())
|
||||
{
|
||||
playerOneHp = _playerOne.player.getCurrentHp() + _playerOne.player.getCurrentCp();
|
||||
if (playerOneHp < 0.5)
|
||||
{
|
||||
playerOneHp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
double playerTwoHp = 0;
|
||||
if ((_playerTwo.player != null) && !_playerTwo.player.isDead())
|
||||
{
|
||||
playerTwoHp = _playerTwo.player.getCurrentHp() + _playerTwo.player.getCurrentCp();
|
||||
if (playerTwoHp < 0.5)
|
||||
{
|
||||
playerTwoHp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// if players crashed, search if they've relogged
|
||||
_playerOne.updatePlayer();
|
||||
_playerTwo.updatePlayer();
|
||||
|
||||
if (((_playerOne.player == null) || !_playerOne.player.isOnline()) && ((_playerTwo.player == null) || !_playerTwo.player.isOnline()))
|
||||
{
|
||||
_playerOne.updateStat(COMP_DRAWN, 1);
|
||||
_playerTwo.updateStat(COMP_DRAWN, 1);
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.THE_GAME_ENDED_IN_A_TIE);
|
||||
stadium.broadcastPacket(sm);
|
||||
}
|
||||
else if ((_playerTwo.player == null) || !_playerTwo.player.isOnline() || ((playerTwoHp == 0) && (playerOneHp != 0)) || ((_damageP1 > _damageP2) && (playerTwoHp != 0) && (playerOneHp != 0)))
|
||||
{
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.C1_HAS_WON_THE_GAME);
|
||||
sm.addString(_playerOne.name);
|
||||
stadium.broadcastPacket(sm);
|
||||
|
||||
_playerOne.updateStat(COMP_WON, 1);
|
||||
_playerTwo.updateStat(COMP_LOST, 1);
|
||||
|
||||
addPointsToParticipant(_playerOne, pointDiff);
|
||||
removePointsFromParticipant(_playerTwo, pointDiff);
|
||||
|
||||
winner = _playerOne.name + " won";
|
||||
|
||||
// Save Fight Result
|
||||
saveResults(_playerOne, _playerTwo, 1, _startTime, _fightTime, getType());
|
||||
rewardParticipant(_playerOne.player, getReward());
|
||||
}
|
||||
else if ((_playerOne.player == null) || !_playerOne.player.isOnline() || ((playerOneHp == 0) && (playerTwoHp != 0)) || ((_damageP2 > _damageP1) && (playerOneHp != 0) && (playerTwoHp != 0)))
|
||||
{
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.C1_HAS_WON_THE_GAME);
|
||||
sm.addString(_playerTwo.name);
|
||||
stadium.broadcastPacket(sm);
|
||||
|
||||
_playerTwo.updateStat(COMP_WON, 1);
|
||||
_playerOne.updateStat(COMP_LOST, 1);
|
||||
|
||||
addPointsToParticipant(_playerTwo, pointDiff);
|
||||
removePointsFromParticipant(_playerOne, pointDiff);
|
||||
|
||||
winner = _playerTwo.name + " won";
|
||||
|
||||
// Save Fight Result
|
||||
saveResults(_playerOne, _playerTwo, 2, _startTime, _fightTime, getType());
|
||||
rewardParticipant(_playerTwo.player, getReward());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Save Fight Result
|
||||
saveResults(_playerOne, _playerTwo, 0, _startTime, _fightTime, getType());
|
||||
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.THE_GAME_ENDED_IN_A_TIE);
|
||||
stadium.broadcastPacket(sm);
|
||||
|
||||
removePointsFromParticipant(_playerOne, Math.min(playerOnePoints / getDivider(), Config.ALT_OLY_MAX_POINTS));
|
||||
removePointsFromParticipant(_playerTwo, Math.min(playerTwoPoints / getDivider(), Config.ALT_OLY_MAX_POINTS));
|
||||
}
|
||||
|
||||
_playerOne.updateStat(COMP_DONE, 1);
|
||||
_playerTwo.updateStat(COMP_DONE, 1);
|
||||
|
||||
_playerOne.updateNobleStats();
|
||||
_playerTwo.updateNobleStats();
|
||||
|
||||
if (Config.ALT_OLY_LOG_FIGHTS)
|
||||
{
|
||||
LogRecord record = new LogRecord(Level.INFO, winner);
|
||||
record.setParameters(new Object[]
|
||||
{
|
||||
_playerOne.name,
|
||||
_playerTwo.name,
|
||||
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.player == null) || (_playerTwo.player == null))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (player == _playerOne.player)
|
||||
{
|
||||
_damageP1 += damage;
|
||||
}
|
||||
else if (player == _playerTwo.player)
|
||||
{
|
||||
_damageP2 += damage;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String[] getPlayerNames()
|
||||
{
|
||||
return new String[]
|
||||
{
|
||||
_playerOne.name,
|
||||
_playerTwo.name
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkDefaulted()
|
||||
{
|
||||
SystemMessage reason;
|
||||
_playerOne.updatePlayer();
|
||||
_playerTwo.updatePlayer();
|
||||
|
||||
reason = checkDefaulted(_playerOne.player);
|
||||
if (reason != null)
|
||||
{
|
||||
_playerOne.defaulted = true;
|
||||
if (_playerTwo.player != null)
|
||||
{
|
||||
_playerTwo.player.sendPacket(reason);
|
||||
}
|
||||
}
|
||||
|
||||
reason = checkDefaulted(_playerTwo.player);
|
||||
if (reason != null)
|
||||
{
|
||||
_playerTwo.defaulted = true;
|
||||
if (_playerOne.player != null)
|
||||
{
|
||||
_playerOne.player.sendPacket(reason);
|
||||
}
|
||||
}
|
||||
|
||||
return _playerOne.defaulted || _playerTwo.defaulted;
|
||||
}
|
||||
|
||||
@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)
|
||||
{
|
||||
Connection con = null;
|
||||
try
|
||||
{
|
||||
con = L2DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement statement = con.prepareStatement("INSERT INTO olympiad_fights (charOneId, charTwoId, charOneClass, charTwoClass, winner, start, time, classed) values(?,?,?,?,?,?,?,?)");
|
||||
statement.setInt(1, one.objectId);
|
||||
statement.setInt(2, two.objectId);
|
||||
statement.setInt(3, one.baseClass);
|
||||
statement.setInt(4, two.baseClass);
|
||||
statement.setInt(5, _winner);
|
||||
statement.setLong(6, _startTime);
|
||||
statement.setLong(7, _fightTime);
|
||||
statement.setInt(8, (type == CompetitionType.CLASSED ? 1 : 0));
|
||||
statement.execute();
|
||||
statement.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
if (_log.isLoggable(Level.SEVERE))
|
||||
{
|
||||
_log.log(Level.SEVERE, "SQL exception while saving olympiad fight.", e);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
L2DatabaseFactory.close(con);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,523 @@
|
||||
/*
|
||||
* 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.l2jserver.gameserver.model.olympiad;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jserver.Config;
|
||||
import com.l2jserver.gameserver.ThreadPoolManager;
|
||||
import com.l2jserver.gameserver.model.zone.type.L2OlympiadStadiumZone;
|
||||
import com.l2jserver.gameserver.network.SystemMessageId;
|
||||
import com.l2jserver.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
|
||||
|
||||
public static final int[] TELEPORT_TO_ARENA =
|
||||
{
|
||||
120,
|
||||
60,
|
||||
30,
|
||||
15,
|
||||
10,
|
||||
5,
|
||||
4,
|
||||
3,
|
||||
2,
|
||||
1,
|
||||
0
|
||||
};
|
||||
public static final int[] BATTLE_START_TIME_FIRST =
|
||||
{
|
||||
60,
|
||||
50,
|
||||
40,
|
||||
30,
|
||||
20,
|
||||
10,
|
||||
0
|
||||
};
|
||||
public static final int[] BATTLE_START_TIME_SECOND =
|
||||
{
|
||||
10,
|
||||
5,
|
||||
4,
|
||||
3,
|
||||
2,
|
||||
1,
|
||||
0
|
||||
};
|
||||
public static final int[] TELEPORT_TO_TOWN =
|
||||
{
|
||||
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_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().executeTask(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)
|
||||
{
|
||||
SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_WILL_ENTER_THE_OLYMPIAD_STADIUM_IN_S1_SECOND_S);
|
||||
sm.addNumber(_countDown);
|
||||
_game.broadcastPacket(sm);
|
||||
}
|
||||
|
||||
delay = getDelay(TELEPORT_TO_ARENA);
|
||||
if (_countDown <= 0)
|
||||
{
|
||||
_state = GameState.GAME_STARTED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Game start, port players to arena
|
||||
case GAME_STARTED:
|
||||
{
|
||||
if (!startGame())
|
||||
{
|
||||
_state = GameState.GAME_STOPPED;
|
||||
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)
|
||||
{
|
||||
SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.THE_GAME_WILL_START_IN_S1_SECOND_S);
|
||||
sm.addNumber(_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)
|
||||
{
|
||||
SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.THE_GAME_WILL_START_IN_S1_SECOND_S);
|
||||
sm.addNumber(_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;
|
||||
}
|
||||
// End of the battle
|
||||
case GAME_STOPPED:
|
||||
{
|
||||
_state = GameState.TELEPORT_TO_TOWN;
|
||||
_countDown = TELEPORT_TO_TOWN[0];
|
||||
stopGame();
|
||||
delay = getDelay(TELEPORT_TO_TOWN);
|
||||
break;
|
||||
}
|
||||
// Teleport to town countdown
|
||||
case TELEPORT_TO_TOWN:
|
||||
{
|
||||
if (_countDown > 0)
|
||||
{
|
||||
SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_WILL_BE_MOVED_TO_TOWN_IN_S1_SECONDS);
|
||||
sm.addNumber(_countDown);
|
||||
_game.broadcastPacket(sm);
|
||||
}
|
||||
|
||||
delay = getDelay(TELEPORT_TO_TOWN);
|
||||
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. Returns 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. Returns 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.STARTS_THE_GAME));
|
||||
_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.
|
||||
*/
|
||||
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
@@ -0,0 +1,562 @@
|
||||
/*
|
||||
* 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.l2jserver.gameserver.model.olympiad;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javolution.util.FastList;
|
||||
import javolution.util.FastMap;
|
||||
|
||||
import com.l2jserver.Config;
|
||||
import com.l2jserver.gameserver.ThreadPoolManager;
|
||||
import com.l2jserver.gameserver.instancemanager.AntiFeedManager;
|
||||
import com.l2jserver.gameserver.model.L2Party;
|
||||
import com.l2jserver.gameserver.model.L2World;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jserver.gameserver.model.entity.TvTEvent;
|
||||
import com.l2jserver.gameserver.network.SystemMessageId;
|
||||
import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
|
||||
import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
|
||||
import com.l2jserver.gameserver.templates.StatsSet;
|
||||
|
||||
/**
|
||||
* @author DS
|
||||
*/
|
||||
public class OlympiadManager
|
||||
{
|
||||
private final List<Integer> _nonClassBasedRegisters;
|
||||
private final Map<Integer, List<Integer>> _classBasedRegisters;
|
||||
private final List<List<Integer>> _teamsBasedRegisters;
|
||||
|
||||
private OlympiadManager()
|
||||
{
|
||||
_nonClassBasedRegisters = new FastList<Integer>().shared();
|
||||
_classBasedRegisters = new FastMap<Integer, List<Integer>>().shared();
|
||||
_teamsBasedRegisters = new FastList<List<Integer>>().shared();
|
||||
}
|
||||
|
||||
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 FastList<>();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_ALREADY_REGISTERED_NON_CLASS_LIMITED_EVENT_TEAMS);
|
||||
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_NON_CLASS_LIMITED_MATCH_WAITING_LIST);
|
||||
sm.addPcName(noble);
|
||||
player.sendPacket(sm);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
final List<Integer> classed = _classBasedRegisters.get(noble.getBaseClass());
|
||||
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_NON_CLASS_LIMITED_MATCH_WAITING_LIST);
|
||||
sm.addPcName(noble);
|
||||
player.sendPacket(sm);
|
||||
break;
|
||||
}
|
||||
case TEAMS:
|
||||
{
|
||||
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_ALREADY_REGISTERED_NON_CLASS_LIMITED_EVENT_TEAMS);
|
||||
sm.addPcName(noble);
|
||||
player.sendPacket(sm);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public final boolean registerNoble(L2PcInstance player, CompetitionType type)
|
||||
{
|
||||
SystemMessage sm;
|
||||
if (!Olympiad._inCompPeriod)
|
||||
{
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.THE_OLYMPIAD_GAME_IS_NOT_CURRENTLY_IN_PROGRESS);
|
||||
player.sendPacket(sm);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Olympiad.getInstance().getMillisToCompEnd() < 600000)
|
||||
{
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.GAME_REQUEST_CANNOT_BE_MADE);
|
||||
player.sendPacket(sm);
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case CLASSED:
|
||||
{
|
||||
if (!checkNoble(player, player))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
List<Integer> classed = _classBasedRegisters.get(player.getBaseClass());
|
||||
if (classed != null)
|
||||
{
|
||||
classed.add(player.getObjectId());
|
||||
}
|
||||
else
|
||||
{
|
||||
classed = new FastList<Integer>().shared();
|
||||
classed.add(player.getObjectId());
|
||||
_classBasedRegisters.put(player.getBaseClass(), classed);
|
||||
}
|
||||
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_BEEN_REGISTERED_IN_A_WAITING_LIST_OF_CLASSIFIED_GAMES);
|
||||
player.sendPacket(sm);
|
||||
break;
|
||||
}
|
||||
case NON_CLASSED:
|
||||
{
|
||||
if (!checkNoble(player, player))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_nonClassBasedRegisters.add(player.getObjectId());
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_BEEN_REGISTERED_IN_A_WAITING_LIST_OF_NO_CLASS_GAMES);
|
||||
player.sendPacket(sm);
|
||||
break;
|
||||
}
|
||||
case TEAMS:
|
||||
{
|
||||
final L2Party party = player.getParty();
|
||||
if ((party == null) || (party.getMemberCount() != 3))
|
||||
{
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.PARTY_REQUIREMENTS_NOT_MET);
|
||||
player.sendPacket(sm);
|
||||
return false;
|
||||
}
|
||||
if (!party.isLeader(player))
|
||||
{
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.ONLY_PARTY_LEADER_CAN_REQUEST_TEAM_MATCH);
|
||||
player.sendPacket(sm);
|
||||
return false;
|
||||
}
|
||||
|
||||
int teamPoints = 0;
|
||||
ArrayList<Integer> team = new ArrayList<>(party.getMemberCount());
|
||||
for (L2PcInstance noble : party.getPartyMembers())
|
||||
{
|
||||
if (!checkNoble(noble, player))
|
||||
{
|
||||
// remove previously registered party members
|
||||
if (Config.L2JMOD_DUALBOX_CHECK_MAX_OLYMPIAD_PARTICIPANTS_PER_IP > 0)
|
||||
{
|
||||
for (L2PcInstance unreg : party.getPartyMembers())
|
||||
{
|
||||
if (unreg == noble)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
AntiFeedManager.getInstance().removePlayer(AntiFeedManager.OLYMPIAD_ID, unreg);
|
||||
}
|
||||
}
|
||||
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.getPartyMembers())
|
||||
{
|
||||
AntiFeedManager.getInstance().removePlayer(AntiFeedManager.OLYMPIAD_ID, unreg);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
party.broadcastToPartyMembers(SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_REGISTERED_IN_A_WAITING_LIST_OF_TEAM_GAMES));
|
||||
_teamsBasedRegisters.add(team);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public final boolean unRegisterNoble(L2PcInstance noble)
|
||||
{
|
||||
SystemMessage sm;
|
||||
if (!Olympiad._inCompPeriod)
|
||||
{
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.THE_OLYMPIAD_GAME_IS_NOT_CURRENTLY_IN_PROGRESS);
|
||||
noble.sendPacket(sm);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!noble.isNoble())
|
||||
{
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.C1_DOES_NOT_MEET_REQUIREMENTS_ONLY_NOBLESS_CAN_PARTICIPATE_IN_THE_OLYMPIAD);
|
||||
sm.addString(noble.getName());
|
||||
noble.sendPacket(sm);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isRegistered(noble, noble, false))
|
||||
{
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_NOT_BEEN_REGISTERED_IN_A_WAITING_LIST_OF_A_GAME);
|
||||
noble.sendPacket(sm);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isInCompetition(noble, noble, false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_BEEN_DELETED_FROM_THE_WAITING_LIST_OF_A_GAME);
|
||||
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(sm);
|
||||
return true;
|
||||
}
|
||||
|
||||
final List<Integer> classed = _classBasedRegisters.get(noble.getBaseClass());
|
||||
if ((classed != null) && classed.remove(objId))
|
||||
{
|
||||
_classBasedRegisters.remove(noble.getBaseClass());
|
||||
_classBasedRegisters.put(noble.getBaseClass(), classed);
|
||||
|
||||
if (Config.L2JMOD_DUALBOX_CHECK_MAX_OLYMPIAD_PARTICIPANTS_PER_IP > 0)
|
||||
{
|
||||
AntiFeedManager.getInstance().removePlayer(AntiFeedManager.OLYMPIAD_ID, noble);
|
||||
}
|
||||
|
||||
noble.sendPacket(sm);
|
||||
return true;
|
||||
}
|
||||
|
||||
for (List<Integer> team : _teamsBasedRegisters)
|
||||
{
|
||||
if ((team != null) && team.contains(objId))
|
||||
{
|
||||
_teamsBasedRegisters.remove(team);
|
||||
ThreadPoolManager.getInstance().executeTask(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.getBaseClass());
|
||||
if ((classed != null) && classed.remove(objId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (List<Integer> team : _teamsBasedRegisters)
|
||||
{
|
||||
if ((team != null) && team.contains(objId))
|
||||
{
|
||||
_teamsBasedRegisters.remove(team);
|
||||
ThreadPoolManager.getInstance().executeTask(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_REQUIREMENTS_ONLY_NOBLESS_CAN_PARTICIPATE_IN_THE_OLYMPIAD);
|
||||
sm.addPcName(noble);
|
||||
player.sendPacket(sm);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (noble.isSubClassActive())
|
||||
{
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.C1_CANT_JOIN_THE_OLYMPIAD_WITH_A_SUB_CLASS_CHARACTER);
|
||||
sm.addPcName(noble);
|
||||
player.sendPacket(sm);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (noble.isCursedWeaponEquipped())
|
||||
{
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.C1_CANNOT_JOIN_OLYMPIAD_POSSESSING_S2);
|
||||
sm.addPcName(noble);
|
||||
sm.addItemName(noble.getCursedWeaponEquippedId());
|
||||
player.sendPacket(sm);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!noble.isInventoryUnder80(true))
|
||||
{
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.C1_CANNOT_PARTICIPATE_IN_OLYMPIAD_INVENTORY_SLOT_EXCEEDS_80_PERCENT);
|
||||
sm.addPcName(noble);
|
||||
player.sendPacket(sm);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TvTEvent.isPlayerParticipant(noble.getObjectId()))
|
||||
{
|
||||
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(noble.getObjectId());
|
||||
if (statDat == null)
|
||||
{
|
||||
statDat = new StatsSet();
|
||||
statDat.set(Olympiad.CLASS_ID, noble.getBaseClass());
|
||||
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("to_save", true);
|
||||
Olympiad.updateNobleStats(noble.getObjectId(), statDat);
|
||||
}
|
||||
|
||||
final int points = Olympiad.getInstance().getNoblePoints(noble.getObjectId());
|
||||
if (points <= 0)
|
||||
{
|
||||
NpcHtmlMessage message = new NpcHtmlMessage(0);
|
||||
message.setFile(player.getHtmlPrefix(), "data/html/olympiad/noble_nopoints1.htm");
|
||||
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))
|
||||
{
|
||||
NpcHtmlMessage message = new NpcHtmlMessage(0);
|
||||
message.setFile(player.getHtmlPrefix(), "data/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()
|
||||
{
|
||||
L2PcInstance teamMember;
|
||||
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_BEEN_DELETED_FROM_THE_WAITING_LIST_OF_A_GAME);
|
||||
for (int objectId : _team)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
teamMember = null;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("synthetic-access")
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final OlympiadManager _instance = new OlympiadManager();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.l2jserver.gameserver.model.olympiad;
|
||||
|
||||
import com.l2jserver.gameserver.model.L2World;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jserver.gameserver.templates.StatsSet;
|
||||
|
||||
/**
|
||||
* @author DS
|
||||
*/
|
||||
public final class Participant
|
||||
{
|
||||
public final int objectId;
|
||||
public L2PcInstance player;
|
||||
public final String name;
|
||||
public final int side;
|
||||
public final int baseClass;
|
||||
public boolean disconnected = false;
|
||||
public boolean defaulted = false;
|
||||
public final StatsSet stats;
|
||||
|
||||
public Participant(L2PcInstance plr, int olympiadSide)
|
||||
{
|
||||
objectId = plr.getObjectId();
|
||||
player = plr;
|
||||
name = plr.getName();
|
||||
side = olympiadSide;
|
||||
baseClass = plr.getBaseClass();
|
||||
stats = Olympiad.getNobleStats(objectId);
|
||||
}
|
||||
|
||||
public Participant(int objId, int olympiadSide)
|
||||
{
|
||||
objectId = objId;
|
||||
player = null;
|
||||
name = "-";
|
||||
side = olympiadSide;
|
||||
baseClass = 0;
|
||||
stats = null;
|
||||
}
|
||||
|
||||
public final void updatePlayer()
|
||||
{
|
||||
if ((player == null) || !player.isOnline())
|
||||
{
|
||||
player = L2World.getInstance().getPlayer(objectId);
|
||||
}
|
||||
}
|
||||
|
||||
public final void updateStat(String statName, int increment)
|
||||
{
|
||||
stats.set(statName, Math.max(stats.getInteger(statName) + increment, 0));
|
||||
}
|
||||
|
||||
public final void updateNobleStats()
|
||||
{
|
||||
Olympiad.updateNobleStats(objectId, stats);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user