Partial sync L2jUnity free release Feb 20th 2015.

This commit is contained in:
MobiusDev
2016-10-28 08:58:02 +00:00
parent 4628bd3d86
commit 01a48c62cd
219 changed files with 1825 additions and 2935 deletions

View File

@@ -172,7 +172,7 @@ public final class FortManager implements InstanceListManager
_log.info(getClass().getSimpleName() + ": Loaded: " + _forts.size() + " fortress");
for (Fort fort : _forts)
{
fort.getSiege().getSiegeGuardManager().loadSiegeGuard();
fort.getSiege().loadSiegeGuard();
}
}
catch (Exception e)

View File

@@ -1,146 +0,0 @@
/*
* 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.instancemanager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.model.L2Spawn;
import com.l2jmobius.gameserver.model.entity.Fort;
public final class FortSiegeGuardManager
{
private static final Logger _log = Logger.getLogger(FortSiegeGuardManager.class.getName());
private final Fort _fort;
private final Map<Integer, List<L2Spawn>> _siegeGuards = new HashMap<>();
public FortSiegeGuardManager(Fort fort)
{
_fort = fort;
}
/**
* Spawn guards.
*/
public void spawnSiegeGuard()
{
try
{
final List<L2Spawn> monsterList = _siegeGuards.get(getFort().getResidenceId());
if (monsterList != null)
{
for (L2Spawn spawnDat : monsterList)
{
spawnDat.doSpawn();
if (spawnDat.getRespawnDelay() == 0)
{
spawnDat.stopRespawn();
}
else
{
spawnDat.startRespawn();
}
}
}
}
catch (Exception e)
{
_log.log(Level.WARNING, "Error spawning siege guards for fort " + getFort().getName() + ":" + e.getMessage(), e);
}
}
/**
* Unspawn guards.
*/
public void unspawnSiegeGuard()
{
try
{
final List<L2Spawn> monsterList = _siegeGuards.get(getFort().getResidenceId());
if (monsterList != null)
{
for (L2Spawn spawnDat : monsterList)
{
spawnDat.stopRespawn();
if (spawnDat.getLastSpawn() != null)
{
spawnDat.getLastSpawn().doDie(spawnDat.getLastSpawn());
}
}
}
}
catch (Exception e)
{
_log.log(Level.WARNING, "Error unspawning siege guards for fort " + getFort().getName() + ":" + e.getMessage(), e);
}
}
/**
* Load guards.
*/
void loadSiegeGuard()
{
_siegeGuards.clear();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("SELECT npcId, x, y, z, heading, respawnDelay FROM fort_siege_guards WHERE fortId = ?"))
{
final int fortId = getFort().getResidenceId();
ps.setInt(1, fortId);
try (ResultSet rs = ps.executeQuery())
{
final List<L2Spawn> siegeGuardSpawns = new ArrayList<>();
while (rs.next())
{
final L2Spawn spawn = new L2Spawn(rs.getInt("npcId"));
spawn.setAmount(1);
spawn.setX(rs.getInt("x"));
spawn.setY(rs.getInt("y"));
spawn.setZ(rs.getInt("z"));
spawn.setHeading(rs.getInt("heading"));
spawn.setRespawnDelay(rs.getInt("respawnDelay"));
spawn.setLocationId(0);
siegeGuardSpawns.add(spawn);
}
_siegeGuards.put(fortId, siegeGuardSpawns);
}
}
catch (Exception e)
{
_log.log(Level.WARNING, "Error loading siege guard for fort " + getFort().getName() + ": " + e.getMessage(), e);
}
}
public final Fort getFort()
{
return _fort;
}
public final Map<Integer, List<L2Spawn>> getSiegeGuardSpawn()
{
return _siegeGuards;
}
}

View File

@@ -40,8 +40,6 @@ import com.l2jmobius.gameserver.model.events.EventDispatcher;
import com.l2jmobius.gameserver.model.events.impl.character.npc.OnNpcMoveNodeArrived;
import com.l2jmobius.gameserver.model.holders.NpcRoutesHolder;
import com.l2jmobius.gameserver.network.NpcStringId;
import com.l2jmobius.gameserver.network.serverpackets.NpcSay;
import com.l2jmobius.gameserver.util.Broadcast;
import com.l2jmobius.util.data.xml.IXmlReader;
/**
@@ -413,11 +411,11 @@ public final class WalkingManager implements IXmlReader
if (node.getNpcString() != null)
{
Broadcast.toKnownPlayers(npc, new NpcSay(npc, ChatType.NPC_GENERAL, node.getNpcString()));
npc.broadcastSay(ChatType.NPC_GENERAL, node.getNpcString());
}
else if (!node.getChatText().isEmpty())
{
Broadcast.toKnownPlayers(npc, new NpcSay(npc, ChatType.NPC_GENERAL, node.getChatText()));
npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText());
}
if (npc.isDebug())

View File

@@ -94,6 +94,14 @@ public class L2Party extends AbstractPlayerGroup
protected PartyMemberPosition _positionPacket;
private boolean _disbanding = false;
private static Map<Integer, L2Character> _tacticalSigns = null;
private static final int[] TACTICAL_SYS_STRINGS =
{
0,
2664,
2665,
2666,
2667
};
/**
* The message type send to the party members.
@@ -402,7 +410,7 @@ public class L2Party extends AbstractPlayerGroup
_tacticalSigns.entrySet().forEach(entry -> player.sendPacket(new ExTacticalSign(entry.getValue(), remove ? 0 : entry.getKey())));
}
public void addTacticalSign(int tacticalSignId, L2Character target)
public void addTacticalSign(L2PcInstance activeChar, int tacticalSignId, L2Character target)
{
final L2Character tacticalTarget = getTacticalSigns().get(tacticalSignId);
@@ -413,17 +421,42 @@ public class L2Party extends AbstractPlayerGroup
// Add the new sign
_tacticalSigns.put(tacticalSignId, target);
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_USED_S3_ON_C2);
sm.addPcName(activeChar);
sm.addCharName(target);
sm.addSystemString(TACTICAL_SYS_STRINGS[tacticalSignId]);
getMembers().forEach(m ->
{
m.sendPacket(new ExTacticalSign(target, tacticalSignId));
m.sendPacket(sm);
});
}
else if (tacticalTarget == target)
{
// Sign already assigned
// If the sign is applied on the same target, remove it
_tacticalSigns.remove(tacticalSignId);
getMembers().forEach(m -> m.sendPacket(new ExTacticalSign(tacticalTarget, 0)));
}
else
{
// Otherwise, delete the old sign, and apply it to the new target
_tacticalSigns.replace(tacticalSignId, target);
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_USED_S3_ON_C2);
sm.addPcName(activeChar);
sm.addCharName(target);
sm.addSystemString(TACTICAL_SYS_STRINGS[tacticalSignId]);
getMembers().forEach(m ->
{
m.sendPacket(new ExTacticalSign(tacticalTarget, 0));
m.sendPacket(new ExTacticalSign(target, tacticalSignId));
m.sendPacket(sm);
});
}
getMembers().forEach(m -> m.sendPacket(new ExTacticalSign(target, tacticalSignId)));
}
public void setTargetBasedOnTacticalSignId(L2PcInstance player, int tacticalSignId)

View File

@@ -34,6 +34,7 @@ import com.l2jmobius.gameserver.datatables.ItemTable;
import com.l2jmobius.gameserver.datatables.NpcPersonalAIData;
import com.l2jmobius.gameserver.enums.AISkillScope;
import com.l2jmobius.gameserver.enums.AIType;
import com.l2jmobius.gameserver.enums.ChatType;
import com.l2jmobius.gameserver.enums.InstanceType;
import com.l2jmobius.gameserver.enums.PrivateStoreType;
import com.l2jmobius.gameserver.enums.Race;
@@ -82,6 +83,7 @@ import com.l2jmobius.gameserver.model.olympiad.Olympiad;
import com.l2jmobius.gameserver.model.skills.Skill;
import com.l2jmobius.gameserver.model.variables.NpcVariables;
import com.l2jmobius.gameserver.model.zone.type.L2TownZone;
import com.l2jmobius.gameserver.network.NpcStringId;
import com.l2jmobius.gameserver.network.SystemMessageId;
import com.l2jmobius.gameserver.network.serverpackets.ActionFailed;
import com.l2jmobius.gameserver.network.serverpackets.ExChangeNpcState;
@@ -89,6 +91,7 @@ import com.l2jmobius.gameserver.network.serverpackets.MagicSkillUse;
import com.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jmobius.gameserver.network.serverpackets.NpcInfo;
import com.l2jmobius.gameserver.network.serverpackets.NpcInfoAbnormalVisualEffect;
import com.l2jmobius.gameserver.network.serverpackets.NpcSay;
import com.l2jmobius.gameserver.network.serverpackets.ServerObjectInfo;
import com.l2jmobius.gameserver.network.serverpackets.SocialAction;
import com.l2jmobius.gameserver.taskmanager.DecayTaskManager;
@@ -1740,6 +1743,60 @@ public class L2Npc extends L2Character
}
}
/**
* Broadcasts NpcSay packet to all known players.
* @param chatType the chat type
* @param text the text
*/
public void broadcastSay(ChatType chatType, String text)
{
Broadcast.toKnownPlayers(this, new NpcSay(this, chatType, text));
}
/**
* Broadcasts NpcSay packet to all known players with NPC string id.
* @param chatType the chat type
* @param npcStringId the NPC string id
* @param parameters the NPC string id parameters
*/
public void broadcastSay(ChatType chatType, NpcStringId npcStringId, String... parameters)
{
final NpcSay npcSay = new NpcSay(this, chatType, npcStringId);
if (parameters != null)
{
for (String parameter : parameters)
{
if (parameter != null)
{
npcSay.addStringParameter(parameter);
}
}
}
Broadcast.toKnownPlayers(this, npcSay);
}
/**
* Broadcasts NpcSay packet to all known players with custom string in specific radius.
* @param chatType the chat type
* @param text the text
* @param radius the radius
*/
public void broadcastSay(ChatType chatType, String text, int radius)
{
Broadcast.toKnownPlayersInRadius(this, new NpcSay(this, chatType, text), radius);
}
/**
* Broadcasts NpcSay packet to all known players with NPC string id in specific radius.
* @param chatType the chat type
* @param npcStringId the NPC string id
* @param radius the radius
*/
public void broadcastSay(ChatType chatType, NpcStringId npcStringId, int radius)
{
Broadcast.toKnownPlayersInRadius(this, new NpcSay(this, chatType, npcStringId), radius);
}
@Override
public int getMinShopDistance()
{

View File

@@ -25,7 +25,6 @@ import java.util.logging.Level;
import java.util.stream.Stream;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.cache.HtmCache;
import com.l2jmobius.gameserver.data.sql.impl.TeleportLocationTable;
import com.l2jmobius.gameserver.data.xml.impl.MultisellData;
import com.l2jmobius.gameserver.data.xml.impl.TeleportersData;
@@ -390,7 +389,6 @@ public final class L2TeleporterInstance extends L2Npc
}
else if (command.startsWith("Chat"))
{
final Calendar cal = Calendar.getInstance();
int val = 0;
try
{
@@ -402,17 +400,6 @@ public final class L2TeleporterInstance extends L2Npc
catch (NumberFormatException nfe)
{
}
if ((val == 1) && (player.getLevel() < 41))
{
showNewbieHtml(player);
return;
}
if ((val == 1) && (cal.get(Calendar.HOUR_OF_DAY) >= 20) && (cal.get(Calendar.HOUR_OF_DAY) <= 23) && ((cal.get(Calendar.DAY_OF_WEEK) == 1) || (cal.get(Calendar.DAY_OF_WEEK) == 7)))
{
showHalfPriceHtml(player);
return;
}
showChatWindow(player, val);
}
super.onBypassFeedback(player, command);
@@ -424,43 +411,6 @@ public final class L2TeleporterInstance extends L2Npc
return "html/teleporter/" + (val == 0 ? "" + npcId : npcId + "-" + val) + ".htm";
}
private void showNewbieHtml(L2PcInstance player)
{
if (player == null)
{
return;
}
final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
String filename = "html/teleporter/free/" + getTemplate().getId() + ".htm";
if (!HtmCache.getInstance().isLoadable(filename))
{
filename = "html/teleporter/" + getTemplate().getId() + "-1.htm";
}
html.setFile(player.getHtmlPrefix(), filename);
html.replace("%objectId%", String.valueOf(getObjectId()));
html.replace("%npcname%", getName());
player.sendPacket(html);
}
private void showHalfPriceHtml(L2PcInstance player)
{
if (player == null)
{
return;
}
final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
final String filename = !HtmCache.getInstance().isLoadable("html/teleporter/half/" + getId() + ".htm") ? "html/teleporter/" + getId() + "-1.htm" : "html/teleporter/half/" + getId() + ".htm";
html.setFile(player.getHtmlPrefix(), filename);
html.replace("%objectId%", String.valueOf(getObjectId()));
html.replace("%npcname%", getName());
player.sendPacket(html);
}
@Override
public void showChatWindow(L2PcInstance player)
{

View File

@@ -20,9 +20,11 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Calendar;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -35,7 +37,6 @@ import com.l2jmobius.gameserver.enums.ChatType;
import com.l2jmobius.gameserver.enums.FortTeleportWhoType;
import com.l2jmobius.gameserver.enums.SiegeClanType;
import com.l2jmobius.gameserver.instancemanager.FortManager;
import com.l2jmobius.gameserver.instancemanager.FortSiegeGuardManager;
import com.l2jmobius.gameserver.instancemanager.FortSiegeManager;
import com.l2jmobius.gameserver.model.CombatFlag;
import com.l2jmobius.gameserver.model.FortSiegeSpawn;
@@ -54,7 +55,6 @@ import com.l2jmobius.gameserver.model.events.impl.sieges.fort.OnFortSiegeFinish;
import com.l2jmobius.gameserver.model.events.impl.sieges.fort.OnFortSiegeStart;
import com.l2jmobius.gameserver.network.NpcStringId;
import com.l2jmobius.gameserver.network.SystemMessageId;
import com.l2jmobius.gameserver.network.serverpackets.NpcSay;
import com.l2jmobius.gameserver.network.serverpackets.SystemMessage;
public class FortSiege implements Siegable
@@ -223,13 +223,13 @@ public class FortSiege implements Siegable
}
}
private final List<L2SiegeClan> _attackerClans = new CopyOnWriteArrayList<>();
private final Set<L2SiegeClan> _attackerClans = ConcurrentHashMap.newKeySet();
// Fort setting
protected List<L2Spawn> _commanders = new CopyOnWriteArrayList<>();
protected Set<L2Spawn> _commanders = ConcurrentHashMap.newKeySet();
protected final Fort _fort;
private boolean _isInProgress = false;
private FortSiegeGuardManager _siegeGuardManager;
private final Collection<L2Spawn> _siegeGuards = new LinkedList<>();
ScheduledFuture<?> _siegeEnd = null;
ScheduledFuture<?> _siegeRestore = null;
ScheduledFuture<?> _siegeStartTask = null;
@@ -248,54 +248,56 @@ public class FortSiege implements Siegable
@Override
public void endSiege()
{
if (!isInProgress())
if (isInProgress())
{
return;
_isInProgress = false; // Flag so that siege instance can be started
removeFlags(); // Removes all flags. Note: Remove flag before teleporting players
unSpawnFlags();
updatePlayerSiegeStateFlags(true);
int ownerId = -1;
if (getFort().getOwnerClan() != null)
{
ownerId = getFort().getOwnerClan().getId();
}
getFort().getZone().banishForeigners(ownerId);
getFort().getZone().setIsActive(false);
getFort().getZone().updateZoneStatusForCharactersInside();
getFort().getZone().setSiegeInstance(null);
saveFortSiege(); // Save fort specific data
clearSiegeClan(); // Clear siege clan from db
removeCommanders(); // Remove commander from this fort
getFort().spawnNpcCommanders(); // Spawn NPC commanders
unspawnSiegeGuard(); // Remove all spawned siege guard from this fort
getFort().resetDoors(); // Respawn door to fort
ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleSuspiciousMerchantSpawn(), FortSiegeManager.getInstance().getSuspiciousMerchantRespawnDelay() * 60 * 1000L); // Prepare 3hr task for suspicious merchant respawn
setSiegeDateTime(true); // store suspicious merchant spawn in DB
if (_siegeEnd != null)
{
_siegeEnd.cancel(true);
_siegeEnd = null;
}
if (_siegeRestore != null)
{
_siegeRestore.cancel(true);
_siegeRestore = null;
}
if ((getFort().getOwnerClan() != null) && (getFort().getFlagPole().getMeshIndex() == 0))
{
getFort().setVisibleFlag(true);
}
_log.info("Siege of " + getFort().getName() + " fort finished.");
// Notify to scripts.
EventDispatcher.getInstance().notifyEventAsync(new OnFortSiegeFinish(this), getFort());
}
_isInProgress = false; // Flag so that siege instance can be started
removeFlags(); // Removes all flags. Note: Remove flag before teleporting players
unSpawnFlags();
updatePlayerSiegeStateFlags(true);
final int ownerId = getFort().getOwnerClan() != null ? getFort().getOwnerClan().getId() : -1;
getFort().getZone().banishForeigners(ownerId);
getFort().getZone().setIsActive(false);
getFort().getZone().updateZoneStatusForCharactersInside();
getFort().getZone().setSiegeInstance(null);
saveFortSiege(); // Save fort specific data
clearSiegeClan(); // Clear siege clan from db
removeCommanders(); // Remove commander from this fort
getFort().spawnNpcCommanders(); // Spawn NPC commanders
getSiegeGuardManager().unspawnSiegeGuard(); // Remove all spawned siege guard from this fort
getFort().resetDoors(); // Respawn door to fort
ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleSuspiciousMerchantSpawn(), FortSiegeManager.getInstance().getSuspiciousMerchantRespawnDelay() * 60 * 1000L); // Prepare 3hr task for suspicious merchant respawn
setSiegeDateTime(true); // store suspicious merchant spawn in DB
if (_siegeEnd != null)
{
_siegeEnd.cancel(true);
_siegeEnd = null;
}
if (_siegeRestore != null)
{
_siegeRestore.cancel(true);
_siegeRestore = null;
}
if ((getFort().getOwnerClan() != null) && (getFort().getFlagPole().getMeshIndex() == 0))
{
getFort().setVisibleFlag(true);
}
_log.info("Siege of " + getFort().getName() + " fort finished.");
// Notify to scripts.
EventDispatcher.getInstance().notifyEventAsync(new OnFortSiegeFinish(this), getFort());
}
/**
@@ -304,50 +306,48 @@ public class FortSiege implements Siegable
@Override
public void startSiege()
{
if (isInProgress())
if (!isInProgress())
{
return;
if (_siegeStartTask != null) // used admin command "admin_startfortsiege"
{
_siegeStartTask.cancel(true);
getFort().despawnSuspiciousMerchant();
}
_siegeStartTask = null;
if (getAttackerClans().isEmpty())
{
return;
}
_isInProgress = true; // Flag so that same siege instance cannot be started again
loadSiegeClan(); // Load siege clan from db
updatePlayerSiegeStateFlags(false);
teleportPlayer(FortTeleportWhoType.Attacker, TeleportWhereType.TOWN); // Teleport to the closest town
getFort().despawnNpcCommanders(); // Despawn NPC commanders
spawnCommanders(); // Spawn commanders
getFort().resetDoors(); // Spawn door
spawnSiegeGuard(); // Spawn siege guard
getFort().setVisibleFlag(false);
getFort().getZone().setSiegeInstance(this);
getFort().getZone().setIsActive(true);
getFort().getZone().updateZoneStatusForCharactersInside();
// Schedule a task to prepare auto siege end
_siegeEnd = ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleEndSiegeTask(), FortSiegeManager.getInstance().getSiegeLength() * 60 * 1000L); // Prepare auto end task
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.THE_FORTRESS_BATTLE_S1_HAS_BEGUN);
sm.addCastleId(getFort().getResidenceId());
announceToPlayer(sm);
saveFortSiege();
_log.info("Siege of " + getFort().getName() + " fort started.");
// Notify to scripts.
EventDispatcher.getInstance().notifyEventAsync(new OnFortSiegeStart(this), getFort());
}
if (_siegeStartTask != null) // used admin command "admin_startfortsiege"
{
_siegeStartTask.cancel(true);
getFort().despawnSuspiciousMerchant();
}
_siegeStartTask = null;
if (getAttackerClans().isEmpty())
{
return;
}
_isInProgress = true; // Flag so that same siege instance cannot be started again
loadSiegeClan(); // Load siege clan from db
updatePlayerSiegeStateFlags(false);
teleportPlayer(FortTeleportWhoType.Attacker, TeleportWhereType.TOWN); // Teleport to the closest town
getFort().despawnNpcCommanders(); // Despawn NPC commanders
spawnCommanders(); // Spawn commanders
getFort().resetDoors(); // Spawn door
spawnSiegeGuard(); // Spawn siege guard
getFort().setVisibleFlag(false);
getFort().getZone().setSiegeInstance(this);
getFort().getZone().setIsActive(true);
getFort().getZone().updateZoneStatusForCharactersInside();
// Schedule a task to prepare auto siege end
_siegeEnd = ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleEndSiegeTask(), FortSiegeManager.getInstance().getSiegeLength() * 60 * 1000L); // Prepare auto end task
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.THE_FORTRESS_BATTLE_S1_HAS_BEGUN);
sm.addCastleId(getFort().getResidenceId());
announceToPlayer(sm);
saveFortSiege();
_log.info("Siege of " + getFort().getName() + " fort started.");
// Notify to scripts.
EventDispatcher.getInstance().notifyEventAsync(new OnFortSiegeStart(this), getFort());
}
/**
@@ -363,19 +363,21 @@ public class FortSiege implements Siegable
clan = ClanTable.getInstance().getClan(siegeclan.getClanId());
for (L2PcInstance member : clan.getOnlineMembers(0))
{
member.sendPacket(sm);
if (member != null)
{
member.sendPacket(sm);
}
}
}
if (getFort().getOwnerClan() == null)
if (getFort().getOwnerClan() != null)
{
return;
}
clan = ClanTable.getInstance().getClan(getFort().getOwnerClan().getId());
for (L2PcInstance member : clan.getOnlineMembers(0))
{
if (member != null)
clan = ClanTable.getInstance().getClan(getFort().getOwnerClan().getId());
for (L2PcInstance member : clan.getOnlineMembers(0))
{
member.sendPacket(sm);
if (member != null)
{
member.sendPacket(sm);
}
}
}
}
@@ -394,6 +396,11 @@ public class FortSiege implements Siegable
clan = ClanTable.getInstance().getClan(siegeclan.getClanId());
for (L2PcInstance member : clan.getOnlineMembers(0))
{
if (member == null)
{
continue;
}
if (clear)
{
member.setSiegeState((byte) 0);
@@ -414,36 +421,35 @@ public class FortSiege implements Siegable
member.broadcastUserInfo();
}
}
if (getFort().getOwnerClan() == null)
if (getFort().getOwnerClan() != null)
{
return;
}
clan = ClanTable.getInstance().getClan(getFort().getOwnerClan().getId());
for (L2PcInstance member : clan.getOnlineMembers(0))
{
if (member == null)
clan = ClanTable.getInstance().getClan(getFort().getOwnerClan().getId());
for (L2PcInstance member : clan.getOnlineMembers(0))
{
continue;
}
if (clear)
{
member.setSiegeState((byte) 0);
member.setSiegeSide(0);
member.setIsInSiege(false);
member.stopFameTask();
}
else
{
member.setSiegeState((byte) 2);
member.setSiegeSide(getFort().getResidenceId());
if (checkIfInZone(member))
if (member == null)
{
member.setIsInSiege(true);
member.startFameTask(Config.FORTRESS_ZONE_FAME_TASK_FREQUENCY * 1000, Config.FORTRESS_ZONE_FAME_AQUIRE_POINTS);
continue;
}
if (clear)
{
member.setSiegeState((byte) 0);
member.setSiegeSide(0);
member.setIsInSiege(false);
member.stopFameTask();
}
else
{
member.setSiegeState((byte) 2);
member.setSiegeSide(getFort().getResidenceId());
if (checkIfInZone(member))
{
member.setIsInSiege(true);
member.startFameTask(Config.FORTRESS_ZONE_FAME_TASK_FREQUENCY * 1000, Config.FORTRESS_ZONE_FAME_AQUIRE_POINTS);
}
}
member.broadcastUserInfo();
}
member.broadcastUserInfo();
}
}
@@ -464,7 +470,7 @@ public class FortSiege implements Siegable
*/
public boolean checkIfInZone(int x, int y, int z)
{
return isInProgress() && getFort().checkIfInZone(x, y, z); // Fort zone during siege
return (isInProgress() && (getFort().checkIfInZone(x, y, z))); // Fort zone during siege
}
/**
@@ -474,7 +480,7 @@ public class FortSiege implements Siegable
@Override
public boolean checkIsAttacker(L2Clan clan)
{
return getAttackerClan(clan) != null;
return (getAttackerClan(clan) != null);
}
/**
@@ -484,7 +490,12 @@ public class FortSiege implements Siegable
@Override
public boolean checkIsDefender(L2Clan clan)
{
return (clan != null) && (getFort().getOwnerClan() == clan);
if ((clan != null) && (getFort().getOwnerClan() == clan))
{
return true;
}
return false;
}
/** Clear all registered siege clans from database for fort */
@@ -541,8 +552,14 @@ public class FortSiege implements Siegable
final List<L2PcInstance> players = new LinkedList<>();
for (L2SiegeClan siegeclan : getAttackerClans())
{
for (L2PcInstance player : ClanTable.getInstance().getClan(siegeclan.getClanId()).getOnlineMembers(0))
final L2Clan clan = ClanTable.getInstance().getClan(siegeclan.getClanId());
for (L2PcInstance player : clan.getOnlineMembers(0))
{
if (player == null)
{
continue;
}
if (player.isInSiege())
{
players.add(player);
@@ -576,6 +593,11 @@ public class FortSiege implements Siegable
for (L2PcInstance player : clan.getOnlineMembers(0))
{
if (player == null)
{
continue;
}
if (player.isInSiege())
{
players.add(player);
@@ -592,85 +614,76 @@ public class FortSiege implements Siegable
*/
public void killedCommander(L2FortCommanderInstance instance)
{
if (_commanders.isEmpty() || (getFort() == null))
if ((getFort() != null) && (!_commanders.isEmpty()))
{
return;
}
final L2Spawn spawn = instance.getSpawn();
if (spawn != null)
{
final List<FortSiegeSpawn> commanders = FortSiegeManager.getInstance().getCommanderSpawnList(getFort().getResidenceId());
for (FortSiegeSpawn spawn2 : commanders)
L2Spawn spawn = instance.getSpawn();
if (spawn != null)
{
if (spawn2.getId() == spawn.getId())
for (FortSiegeSpawn spawn2 : FortSiegeManager.getInstance().getCommanderSpawnList(getFort().getResidenceId()))
{
NpcStringId npcString = null;
switch (spawn2.getMessageId())
if (spawn2.getId() == spawn.getId())
{
case 1:
NpcStringId npcString = null;
switch (spawn2.getMessageId())
{
npcString = NpcStringId.YOU_MAY_HAVE_BROKEN_OUR_ARROWS_BUT_YOU_WILL_NEVER_BREAK_OUR_WILL_ARCHERS_RETREAT;
break;
case 1:
npcString = NpcStringId.YOU_MAY_HAVE_BROKEN_OUR_ARROWS_BUT_YOU_WILL_NEVER_BREAK_OUR_WILL_ARCHERS_RETREAT;
break;
case 2:
npcString = NpcStringId.AIIEEEE_COMMAND_CENTER_THIS_IS_GUARD_UNIT_WE_NEED_BACKUP_RIGHT_AWAY;
break;
case 3:
npcString = NpcStringId.AT_LAST_THE_MAGIC_CIRCLE_THAT_PROTECTS_THE_FORTRESS_HAS_WEAKENED_VOLUNTEERS_STAND_BACK;
break;
case 4:
npcString = NpcStringId.I_FEEL_SO_MUCH_GRIEF_THAT_I_CAN_T_EVEN_TAKE_CARE_OF_MYSELF_THERE_ISN_T_ANY_REASON_FOR_ME_TO_STAY_HERE_ANY_LONGER;
break;
}
case 2:
if (npcString != null)
{
npcString = NpcStringId.AIIEEEE_COMMAND_CENTER_THIS_IS_GUARD_UNIT_WE_NEED_BACKUP_RIGHT_AWAY;
break;
}
case 3:
{
npcString = NpcStringId.AT_LAST_THE_MAGIC_CIRCLE_THAT_PROTECTS_THE_FORTRESS_HAS_WEAKENED_VOLUNTEERS_STAND_BACK;
break;
}
case 4:
{
npcString = NpcStringId.I_FEEL_SO_MUCH_GRIEF_THAT_I_CAN_T_EVEN_TAKE_CARE_OF_MYSELF_THERE_ISN_T_ANY_REASON_FOR_ME_TO_STAY_HERE_ANY_LONGER;
break;
instance.broadcastSay(ChatType.NPC_SHOUT, npcString);
}
}
if (npcString != null)
{
instance.broadcastPacket(new NpcSay(instance.getObjectId(), ChatType.NPC_SHOUT, instance.getId(), npcString));
}
}
}
_commanders.remove(spawn);
if (_commanders.isEmpty())
{
// spawn fort flags
spawnFlag(getFort().getResidenceId());
// cancel door/commanders respawn
if (_siegeRestore != null)
_commanders.remove(spawn);
if (_commanders.isEmpty())
{
_siegeRestore.cancel(true);
}
// open doors in main building
for (L2DoorInstance door : getFort().getDoors())
{
if (door.getIsShowHp())
// spawn fort flags
spawnFlag(getFort().getResidenceId());
// cancel door/commanders respawn
if (_siegeRestore != null)
{
continue;
_siegeRestore.cancel(true);
}
// TODO this also opens control room door at big fort
door.openMe();
// open doors in main building
for (L2DoorInstance door : getFort().getDoors())
{
if (door.getIsShowHp())
{
continue;
}
// TODO this also opens control room door at big fort
door.openMe();
}
getFort().getSiege().announceToPlayer(SystemMessage.getSystemMessage(SystemMessageId.ALL_BARRACKS_ARE_OCCUPIED));
}
// schedule restoring doors/commanders respawn
else if (_siegeRestore == null)
{
getFort().getSiege().announceToPlayer(SystemMessage.getSystemMessage(SystemMessageId.THE_BARRACKS_HAVE_BEEN_SEIZED));
_siegeRestore = ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleSiegeRestore(), FortSiegeManager.getInstance().getCountDownLength() * 60 * 1000L);
}
else
{
getFort().getSiege().announceToPlayer(SystemMessage.getSystemMessage(SystemMessageId.THE_BARRACKS_HAVE_BEEN_SEIZED));
}
getFort().getSiege().announceToPlayer(SystemMessage.getSystemMessage(SystemMessageId.ALL_BARRACKS_ARE_OCCUPIED));
}
else
{
getFort().getSiege().announceToPlayer(SystemMessage.getSystemMessage(SystemMessageId.THE_BARRACKS_HAVE_BEEN_SEIZED));
if (_siegeRestore == null)
{
_siegeRestore = ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleSiegeRestore(), FortSiegeManager.getInstance().getCountDownLength() * 60 * 1000L);
}
_log.warning("FortSiege.killedCommander(): killed commander, but commander not registered for fortress. NpcId: " + instance.getId() + " FortId: " + getFort().getResidenceId());
}
}
else
{
_log.warning("FortSiege.killedCommander(): killed commander, but commander not registered for fortress. NpcId: " + instance.getId() + " FortId: " + getFort().getResidenceId());
}
}
/**
@@ -720,7 +733,12 @@ public class FortSiege implements Siegable
for (Fort fort : FortManager.getInstance().getForts())
{
if ((fort.getSiege().getAttackerClan(player.getClanId()) != null) || ((fort.getOwnerClan() == player.getClan()) && (fort.getSiege().isInProgress() || (fort.getSiege()._siegeStartTask != null))))
if (fort.getSiege().getAttackerClan(player.getClanId()) != null)
{
return 3; // Players clan is already registered to siege
}
if ((fort.getOwnerClan() == player.getClan()) && (fort.getSiege().isInProgress() || (fort.getSiege()._siegeStartTask != null)))
{
return 3; // Players clan is already registered to siege
}
@@ -760,14 +778,14 @@ public class FortSiege implements Siegable
{
final String query = (clanId != 0) ? DELETE_FORT_SIEGECLANS_BY_CLAN_ID : DELETE_FORT_SIEGECLANS;
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(query))
PreparedStatement statement = con.prepareStatement(query))
{
ps.setInt(1, getFort().getResidenceId());
statement.setInt(1, getFort().getResidenceId());
if (clanId != 0)
{
ps.setInt(2, clanId);
statement.setInt(2, clanId);
}
ps.execute();
statement.execute();
loadSiegeClan();
if (getAttackerClans().isEmpty())
@@ -890,19 +908,13 @@ public class FortSiege implements Siegable
switch (teleportWho)
{
case Owner:
{
players = getOwnersInZone();
break;
}
case Attacker:
{
players = getAttackersInZone();
break;
}
default:
{
players = getPlayersInZone();
}
}
for (L2PcInstance player : players)
@@ -938,9 +950,16 @@ public class FortSiege implements Siegable
continue;
}
if ((siege.getSiegeDate().get(Calendar.DAY_OF_WEEK) == getSiegeDate().get(Calendar.DAY_OF_WEEK)) && (siege.checkIsAttacker(clan) || siege.checkIsDefender(clan)))
if (siege.getSiegeDate().get(Calendar.DAY_OF_WEEK) == getSiegeDate().get(Calendar.DAY_OF_WEEK))
{
return true;
if (siege.checkIsAttacker(clan))
{
return true;
}
if (siege.checkIsDefender(clan))
{
return true;
}
}
}
@@ -949,7 +968,7 @@ public class FortSiege implements Siegable
private void setSiegeDateTime(boolean merchant)
{
final Calendar newDate = Calendar.getInstance();
Calendar newDate = Calendar.getInstance();
if (merchant)
{
newDate.add(Calendar.MINUTE, FortSiegeManager.getInstance().getSuspiciousMerchantRespawnDelay());
@@ -987,10 +1006,6 @@ public class FortSiege implements Siegable
/** Remove commanders. */
private void removeCommanders()
{
if ((_commanders == null) || _commanders.isEmpty())
{
return;
}
// Remove all instance of commanders for this fort
for (L2Spawn spawn : _commanders)
{
@@ -1053,11 +1068,11 @@ public class FortSiege implements Siegable
}
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("INSERT INTO fortsiege_clans (clan_id,fort_id) values (?,?)"))
PreparedStatement statement = con.prepareStatement("INSERT INTO fortsiege_clans (clan_id,fort_id) values (?,?)"))
{
ps.setInt(1, clan.getId());
ps.setInt(2, getFort().getResidenceId());
ps.execute();
statement.setInt(1, clan.getId());
statement.setInt(2, getFort().getResidenceId());
statement.execute();
addAttacker(clan.getId());
}
@@ -1116,18 +1131,91 @@ public class FortSiege implements Siegable
}
}
public void loadSiegeGuard()
{
_siegeGuards.clear();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("SELECT npcId, x, y, z, heading, respawnDelay FROM fort_siege_guards WHERE fortId = ?"))
{
final int fortId = getFort().getResidenceId();
ps.setInt(1, fortId);
try (ResultSet rs = ps.executeQuery())
{
while (rs.next())
{
final L2Spawn spawn = new L2Spawn(rs.getInt("npcId"));
spawn.setAmount(1);
spawn.setX(rs.getInt("x"));
spawn.setY(rs.getInt("y"));
spawn.setZ(rs.getInt("z"));
spawn.setHeading(rs.getInt("heading"));
spawn.setRespawnDelay(rs.getInt("respawnDelay"));
spawn.setLocationId(0);
_siegeGuards.add(spawn);
}
}
}
catch (Exception e)
{
_log.log(Level.WARNING, "Error loading siege guard for fort " + getFort().getName() + ": " + e.getMessage(), e);
}
}
/**
* Spawn siege guard.
*/
private void spawnSiegeGuard()
{
getSiegeGuardManager().spawnSiegeGuard();
try
{
for (L2Spawn spawnDat : _siegeGuards)
{
spawnDat.doSpawn();
if (spawnDat.getRespawnDelay() == 0)
{
spawnDat.stopRespawn();
}
else
{
spawnDat.startRespawn();
}
}
}
catch (Exception e)
{
_log.log(Level.WARNING, "Error spawning siege guards for fort " + getFort().getName() + ":" + e.getMessage(), e);
}
}
private void unspawnSiegeGuard()
{
try
{
for (L2Spawn spawnDat : _siegeGuards)
{
spawnDat.stopRespawn();
if (spawnDat.getLastSpawn() != null)
{
spawnDat.getLastSpawn().doDie(spawnDat.getLastSpawn());
}
}
}
catch (Exception e)
{
_log.log(Level.WARNING, "Error unspawning siege guards for fort " + getFort().getName() + ":" + e.getMessage(), e);
}
}
@Override
public final L2SiegeClan getAttackerClan(L2Clan clan)
{
return clan == null ? null : getAttackerClan(clan.getId());
if (clan == null)
{
return null;
}
return getAttackerClan(clan.getId());
}
@Override
@@ -1145,7 +1233,7 @@ public class FortSiege implements Siegable
}
@Override
public final List<L2SiegeClan> getAttackerClans()
public final Collection<L2SiegeClan> getAttackerClans()
{
return _attackerClans;
}
@@ -1171,7 +1259,7 @@ public class FortSiege implements Siegable
{
if (clan != null)
{
final L2SiegeClan sc = getAttackerClan(clan);
L2SiegeClan sc = getAttackerClan(clan);
if (sc != null)
{
return sc.getFlag();
@@ -1181,16 +1269,6 @@ public class FortSiege implements Siegable
return null;
}
public final FortSiegeGuardManager getSiegeGuardManager()
{
if (_siegeGuardManager == null)
{
_siegeGuardManager = new FortSiegeGuardManager(getFort());
}
return _siegeGuardManager;
}
public void resetSiege()
{
// reload commanders and repair doors
@@ -1199,7 +1277,7 @@ public class FortSiege implements Siegable
getFort().resetDoors();
}
public List<L2Spawn> getCommanders()
public Set<L2Spawn> getCommanders()
{
return _commanders;
}

View File

@@ -448,7 +448,7 @@ public abstract class ClanHallSiegeEngine extends Quest implements Siegable
public final void broadcastNpcSay(L2Npc npc, ChatType type, NpcStringId messageId)
{
final NpcSay npcSay = new NpcSay(npc.getObjectId(), type, npc.getId(), messageId);
final NpcSay npcSay = new NpcSay(npc, type, messageId);
final int sourceRegion = MapRegionManager.getInstance().getMapRegionLocId(npc);
for (L2PcInstance pc : L2World.getInstance().getPlayers())
{

View File

@@ -23,7 +23,6 @@ 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
@@ -78,16 +77,12 @@ public final class OlympiadAnnouncer implements Runnable
}
}
L2Npc manager;
NpcSay packet;
for (L2Spawn spawn : _managers)
{
manager = spawn.getLastSpawn();
final L2Npc manager = spawn.getLastSpawn();
if (manager != null)
{
packet = new NpcSay(manager.getObjectId(), ChatType.NPC_SHOUT, manager.getId(), npcString);
packet.addStringParameter(arenaId);
manager.broadcastPacket(packet);
manager.broadcastSay(ChatType.NPC_SHOUT, npcString, arenaId);
}
}
break;

View File

@@ -1040,7 +1040,7 @@ public final class QuestState
public boolean isNowAvailable()
{
final String val = get("restartTime");
return (val == null) || !Util.isDigit(val) || (Long.parseLong(val) <= System.currentTimeMillis());
return (val != null) && (!Util.isDigit(val) || (Long.parseLong(val) <= System.currentTimeMillis()));
}
/**

View File

@@ -465,7 +465,7 @@ public final class RequestActionUse extends L2GameClientPacket
{
if ((activeChar.getParty() != null) && (activeChar.getTarget() != null) && activeChar.getTarget().isCharacter())
{
activeChar.getParty().addTacticalSign(_actionId - 77, (L2Character) activeChar.getTarget());
activeChar.getParty().addTacticalSign(activeChar, _actionId - 77, (L2Character) activeChar.getTarget());
}
else
{

View File

@@ -1,68 +0,0 @@
/*
* 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.script;
/**
* @author Luis Arias
*/
public class IntList
{
public static int[] parse(String range)
{
if (range.contains("-"))
{
return getIntegerRange(range.split("-"));
}
else if (range.contains(","))
{
return getIntegerList(range.split(","));
}
final int[] list =
{
getInt(range)
};
return list;
}
private static int getInt(String number)
{
return Integer.parseInt(number);
}
private static int[] getIntegerList(String[] numbers)
{
final int[] list = new int[numbers.length];
for (int i = 0; i < list.length; i++)
{
list[i] = getInt(numbers[i]);
}
return list;
}
private static int[] getIntegerRange(String[] numbers)
{
final int min = getInt(numbers[0]);
final int max = getInt(numbers[1]);
final int[] list = new int[(max - min) + 1];
for (int i = 0; i < list.length; i++)
{
list[i] = min + i;
}
return list;
}
}

View File

@@ -1,130 +0,0 @@
/*
* 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.script;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import com.l2jmobius.Config;
/**
* @author Luis Arias
*/
public class ScriptPackage
{
private static final Logger _log = Logger.getLogger(ScriptPackage.class.getName());
private final List<ScriptDocument> _scriptFiles = new ArrayList<>();
private final List<String> _otherFiles = new ArrayList<>();
private final String _name;
public ScriptPackage(ZipFile pack)
{
_name = pack.getName();
addFiles(pack);
}
/**
* @return Returns the otherFiles.
*/
public List<String> getOtherFiles()
{
return _otherFiles;
}
/**
* @return Returns the scriptFiles.
*/
public List<ScriptDocument> getScriptFiles()
{
return _scriptFiles;
}
/**
* @param pack
*/
private void addFiles(ZipFile pack)
{
for (Enumeration<? extends ZipEntry> e = pack.entries(); e.hasMoreElements();)
{
final ZipEntry entry = e.nextElement();
if (entry.getName().endsWith(".xml"))
{
try
{
_scriptFiles.add(new ScriptDocument(entry.getName(), pack.getInputStream(entry)));
}
catch (IOException io)
{
_log.warning(getClass().getSimpleName() + ": " + io.getMessage());
}
}
else if (!entry.isDirectory())
{
_otherFiles.add(entry.getName());
}
}
}
/**
* @return Returns the name.
*/
public String getName()
{
return _name;
}
@Override
public String toString()
{
if (getScriptFiles().isEmpty() && getOtherFiles().isEmpty())
{
return "Empty Package.";
}
final StringBuilder out = new StringBuilder();
out.append("Package Name: ");
out.append(getName());
out.append(Config.EOL);
if (!getScriptFiles().isEmpty())
{
out.append("Xml Script Files..." + Config.EOL);
for (ScriptDocument script : getScriptFiles())
{
out.append(script.getName());
out.append(Config.EOL);
}
}
if (!getOtherFiles().isEmpty())
{
out.append("Other Files..." + Config.EOL);
for (String fileName : getOtherFiles())
{
out.append(fileName);
out.append(Config.EOL);
}
}
return out.toString();
}
}

View File

@@ -1,56 +0,0 @@
/*
* 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.script;
/**
* @author -Nemesiss-
*/
public class ShortList
{
public static short[] parse(String range)
{
if (range.contains("-"))
{
return getShortList(range.split("-"));
}
else if (range.contains(","))
{
return getShortList(range.split(","));
}
final short[] list =
{
getShort(range)
};
return list;
}
private static short getShort(String number)
{
return Short.parseShort(number);
}
private static short[] getShortList(String[] numbers)
{
final short[] list = new short[numbers.length];
for (int i = 0; i < list.length; i++)
{
list[i] = getShort(numbers[i]);
}
return list;
}
}