Siege method refactorings, concurrent collections and cleanups.
This commit is contained in:
@@ -80,11 +80,11 @@ public class TakeCastle implements ISkillHandler
|
|||||||
{
|
{
|
||||||
if ((castle != null) && (targets.get(0) instanceof ArtefactInstance))
|
if ((castle != null) && (targets.get(0) instanceof ArtefactInstance))
|
||||||
{
|
{
|
||||||
castle.Engrave(player.getClan(), targets.get(0).getObjectId());
|
castle.engrave(player.getClan(), targets.get(0).getObjectId());
|
||||||
}
|
}
|
||||||
else if (fort != null)
|
else if (fort != null)
|
||||||
{
|
{
|
||||||
fort.EndOfSiege(player.getClan());
|
fort.endOfSiege(player.getClan());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ public class Castle
|
|||||||
loadDoor();
|
loadDoor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Engrave(Clan clan, int objId)
|
public void engrave(Clan clan, int objId)
|
||||||
{
|
{
|
||||||
_engrave.put(objId, clan.getClanId());
|
_engrave.put(objId, clan.getClanId());
|
||||||
|
|
||||||
|
|||||||
@@ -66,12 +66,12 @@ public class Fort
|
|||||||
loadDoor();
|
loadDoor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EndOfSiege(Clan clan)
|
public void endOfSiege(Clan clan)
|
||||||
{
|
{
|
||||||
ThreadPool.schedule(new endFortressSiege(this, clan), 1000);
|
ThreadPool.schedule(new endFortressSiege(this, clan), 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Engrave(Clan clan, int objId)
|
public void engrave(Clan clan, int objId)
|
||||||
{
|
{
|
||||||
getSiege().announceToPlayer("Clan " + clan.getName() + " has finished to raise the flag.", true);
|
getSiege().announceToPlayer("Clan " + clan.getName() + " has finished to raise the flag.", true);
|
||||||
setOwner(clan);
|
setOwner(clan);
|
||||||
@@ -628,7 +628,7 @@ public class Fort
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
_f.Engrave(_clan, 0);
|
_f.engrave(_clan, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,10 @@ import java.sql.ResultSet;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
@@ -271,9 +273,11 @@ public class Siege
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final List<SiegeClan> _attackerClans = new ArrayList<>(); // SiegeClan
|
// Must support Concurrent Modifications
|
||||||
private final List<SiegeClan> _defenderClans = new ArrayList<>(); // SiegeClan
|
private final Collection<SiegeClan> _attackerClans = ConcurrentHashMap.newKeySet();
|
||||||
private final List<SiegeClan> _defenderWaitingClans = new ArrayList<>(); // SiegeClan
|
private final Collection<SiegeClan> _defenderClans = ConcurrentHashMap.newKeySet();
|
||||||
|
private final Collection<SiegeClan> _defenderWaitingClans = ConcurrentHashMap.newKeySet();
|
||||||
|
|
||||||
private int _defenderRespawnDelayPenalty;
|
private int _defenderRespawnDelayPenalty;
|
||||||
private List<ArtefactInstance> _artifacts = new ArrayList<>();
|
private List<ArtefactInstance> _artifacts = new ArrayList<>();
|
||||||
private List<ControlTowerInstance> _controlTowers = new ArrayList<>();
|
private List<ControlTowerInstance> _controlTowers = new ArrayList<>();
|
||||||
@@ -416,7 +420,7 @@ public class Siege
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When control of castle changed during siege
|
* When control of castle changed during siege.
|
||||||
*/
|
*/
|
||||||
public void midVictory()
|
public void midVictory()
|
||||||
{
|
{
|
||||||
@@ -427,22 +431,20 @@ public class Siege
|
|||||||
_siegeGuardManager.removeMercs(); // Remove all merc entry from db
|
_siegeGuardManager.removeMercs(); // Remove all merc entry from db
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((getDefenderClans().isEmpty()) && // If defender doesn't exist (Pc vs Npc)
|
if (getDefenderClans().isEmpty() && // If defender doesn't exist (Pc vs Npc)
|
||||||
(getAttackerClans().size() == 1)) // Only 1 attacker
|
(getAttackerClans().size() == 1)) // Only 1 attacker
|
||||||
{
|
{
|
||||||
final SiegeClan scNewOwner = getAttackerClan(getCastle().getOwnerId());
|
final SiegeClan scNewOwner = getAttackerClan(getCastle().getOwnerId());
|
||||||
removeAttacker(scNewOwner);
|
removeAttacker(scNewOwner);
|
||||||
addDefender(scNewOwner, SiegeClanType.OWNER);
|
addDefender(scNewOwner, SiegeClanType.OWNER);
|
||||||
endSiege();
|
endSiege();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getCastle().getOwnerId() > 0)
|
if (getCastle().getOwnerId() > 0)
|
||||||
{
|
{
|
||||||
final int allyId = ClanTable.getInstance().getClan(getCastle().getOwnerId()).getAllyId();
|
final int allyId = ClanTable.getInstance().getClan(getCastle().getOwnerId()).getAllyId();
|
||||||
// If defender doesn't exist (Pc vs Npc) and only an alliance attacks
|
// If defender doesn't exist (Pc vs Npc) and only an alliance attacks and the player's clan is in an alliance
|
||||||
// The player's clan is in an alliance
|
|
||||||
if (getDefenderClans().isEmpty() && (allyId != 0))
|
if (getDefenderClans().isEmpty() && (allyId != 0))
|
||||||
{
|
{
|
||||||
boolean allinsamealliance = true;
|
boolean allinsamealliance = true;
|
||||||
@@ -1640,7 +1642,7 @@ public class Siege
|
|||||||
* Gets the attacker clans.
|
* Gets the attacker clans.
|
||||||
* @return the attacker clans
|
* @return the attacker clans
|
||||||
*/
|
*/
|
||||||
public List<SiegeClan> getAttackerClans()
|
public Collection<SiegeClan> getAttackerClans()
|
||||||
{
|
{
|
||||||
if (_isNormalSide)
|
if (_isNormalSide)
|
||||||
{
|
{
|
||||||
@@ -1706,7 +1708,7 @@ public class Siege
|
|||||||
* Gets the defender clans.
|
* Gets the defender clans.
|
||||||
* @return the defender clans
|
* @return the defender clans
|
||||||
*/
|
*/
|
||||||
public List<SiegeClan> getDefenderClans()
|
public Collection<SiegeClan> getDefenderClans()
|
||||||
{
|
{
|
||||||
if (_isNormalSide)
|
if (_isNormalSide)
|
||||||
{
|
{
|
||||||
@@ -1750,7 +1752,7 @@ public class Siege
|
|||||||
* Gets the defender waiting clans.
|
* Gets the defender waiting clans.
|
||||||
* @return the defender waiting clans
|
* @return the defender waiting clans
|
||||||
*/
|
*/
|
||||||
public List<SiegeClan> getDefenderWaitingClans()
|
public Collection<SiegeClan> getDefenderWaitingClans()
|
||||||
{
|
{
|
||||||
return _defenderWaitingClans;
|
return _defenderWaitingClans;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,11 +111,31 @@ public class RequestBypassToServer extends GameClientPacket
|
|||||||
}
|
}
|
||||||
else if (_command.equals("come_here") && player.isGM())
|
else if (_command.equals("come_here") && player.isGM())
|
||||||
{
|
{
|
||||||
comeHere(player);
|
final WorldObject obj = player.getTarget();
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj instanceof NpcInstance)
|
||||||
|
{
|
||||||
|
final NpcInstance npc = (NpcInstance) obj;
|
||||||
|
npc.setTarget(player);
|
||||||
|
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new Location(player.getX(), player.getY(), player.getZ(), 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (_command.startsWith("player_help "))
|
else if (_command.startsWith("player_help "))
|
||||||
{
|
{
|
||||||
playerHelp(player, _command.substring(12));
|
final String path = _command.substring(12);
|
||||||
|
if (path.contains(".."))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String filename = "data/html/help/" + path;
|
||||||
|
final NpcHtmlMessage html = new NpcHtmlMessage(1);
|
||||||
|
html.setFile(filename);
|
||||||
|
player.sendPacket(html);
|
||||||
}
|
}
|
||||||
else if (_command.startsWith("npc_"))
|
else if (_command.startsWith("npc_"))
|
||||||
{
|
{
|
||||||
@@ -322,37 +342,4 @@ public class RequestBypassToServer extends GameClientPacket
|
|||||||
LOGGER.warning("Bad RequestBypassToServer: " + e);
|
LOGGER.warning("Bad RequestBypassToServer: " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param player
|
|
||||||
*/
|
|
||||||
private void comeHere(PlayerInstance player)
|
|
||||||
{
|
|
||||||
final WorldObject obj = player.getTarget();
|
|
||||||
if (obj == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj instanceof NpcInstance)
|
|
||||||
{
|
|
||||||
final NpcInstance temp = (NpcInstance) obj;
|
|
||||||
temp.setTarget(player);
|
|
||||||
temp.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new Location(player.getX(), player.getY(), player.getZ(), 0));
|
|
||||||
// temp.moveTo(player.getX(),player.getY(), player.getZ(), 0 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void playerHelp(PlayerInstance player, String path)
|
|
||||||
{
|
|
||||||
if (path.contains(".."))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String filename = "data/html/help/" + path;
|
|
||||||
final NpcHtmlMessage html = new NpcHtmlMessage(1);
|
|
||||||
html.setFile(filename);
|
|
||||||
player.sendPacket(html);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,11 +80,11 @@ public class TakeCastle implements ISkillHandler
|
|||||||
{
|
{
|
||||||
if ((castle != null) && (targets.get(0) instanceof ArtefactInstance))
|
if ((castle != null) && (targets.get(0) instanceof ArtefactInstance))
|
||||||
{
|
{
|
||||||
castle.Engrave(player.getClan(), targets.get(0).getObjectId());
|
castle.engrave(player.getClan(), targets.get(0).getObjectId());
|
||||||
}
|
}
|
||||||
else if (fort != null)
|
else if (fort != null)
|
||||||
{
|
{
|
||||||
fort.EndOfSiege(player.getClan());
|
fort.endOfSiege(player.getClan());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ public class Castle
|
|||||||
loadDoor();
|
loadDoor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Engrave(Clan clan, int objId)
|
public void engrave(Clan clan, int objId)
|
||||||
{
|
{
|
||||||
_engrave.put(objId, clan.getClanId());
|
_engrave.put(objId, clan.getClanId());
|
||||||
|
|
||||||
|
|||||||
@@ -66,12 +66,12 @@ public class Fort
|
|||||||
loadDoor();
|
loadDoor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EndOfSiege(Clan clan)
|
public void endOfSiege(Clan clan)
|
||||||
{
|
{
|
||||||
ThreadPool.schedule(new endFortressSiege(this, clan), 1000);
|
ThreadPool.schedule(new endFortressSiege(this, clan), 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Engrave(Clan clan, int objId)
|
public void engrave(Clan clan, int objId)
|
||||||
{
|
{
|
||||||
getSiege().announceToPlayer("Clan " + clan.getName() + " has finished to raise the flag.", true);
|
getSiege().announceToPlayer("Clan " + clan.getName() + " has finished to raise the flag.", true);
|
||||||
setOwner(clan);
|
setOwner(clan);
|
||||||
@@ -628,7 +628,7 @@ public class Fort
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
_f.Engrave(_clan, 0);
|
_f.engrave(_clan, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,10 @@ import java.sql.ResultSet;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
@@ -271,9 +273,11 @@ public class Siege
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final List<SiegeClan> _attackerClans = new ArrayList<>(); // SiegeClan
|
// Must support Concurrent Modifications
|
||||||
private final List<SiegeClan> _defenderClans = new ArrayList<>(); // SiegeClan
|
private final Collection<SiegeClan> _attackerClans = ConcurrentHashMap.newKeySet();
|
||||||
private final List<SiegeClan> _defenderWaitingClans = new ArrayList<>(); // SiegeClan
|
private final Collection<SiegeClan> _defenderClans = ConcurrentHashMap.newKeySet();
|
||||||
|
private final Collection<SiegeClan> _defenderWaitingClans = ConcurrentHashMap.newKeySet();
|
||||||
|
|
||||||
private int _defenderRespawnDelayPenalty;
|
private int _defenderRespawnDelayPenalty;
|
||||||
private List<ArtefactInstance> _artifacts = new ArrayList<>();
|
private List<ArtefactInstance> _artifacts = new ArrayList<>();
|
||||||
private List<ControlTowerInstance> _controlTowers = new ArrayList<>();
|
private List<ControlTowerInstance> _controlTowers = new ArrayList<>();
|
||||||
@@ -416,7 +420,7 @@ public class Siege
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When control of castle changed during siege
|
* When control of castle changed during siege.
|
||||||
*/
|
*/
|
||||||
public void midVictory()
|
public void midVictory()
|
||||||
{
|
{
|
||||||
@@ -427,22 +431,20 @@ public class Siege
|
|||||||
_siegeGuardManager.removeMercs(); // Remove all merc entry from db
|
_siegeGuardManager.removeMercs(); // Remove all merc entry from db
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((getDefenderClans().isEmpty()) && // If defender doesn't exist (Pc vs Npc)
|
if (getDefenderClans().isEmpty() && // If defender doesn't exist (Pc vs Npc)
|
||||||
(getAttackerClans().size() == 1)) // Only 1 attacker
|
(getAttackerClans().size() == 1)) // Only 1 attacker
|
||||||
{
|
{
|
||||||
final SiegeClan scNewOwner = getAttackerClan(getCastle().getOwnerId());
|
final SiegeClan scNewOwner = getAttackerClan(getCastle().getOwnerId());
|
||||||
removeAttacker(scNewOwner);
|
removeAttacker(scNewOwner);
|
||||||
addDefender(scNewOwner, SiegeClanType.OWNER);
|
addDefender(scNewOwner, SiegeClanType.OWNER);
|
||||||
endSiege();
|
endSiege();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getCastle().getOwnerId() > 0)
|
if (getCastle().getOwnerId() > 0)
|
||||||
{
|
{
|
||||||
final int allyId = ClanTable.getInstance().getClan(getCastle().getOwnerId()).getAllyId();
|
final int allyId = ClanTable.getInstance().getClan(getCastle().getOwnerId()).getAllyId();
|
||||||
// If defender doesn't exist (Pc vs Npc) and only an alliance attacks
|
// If defender doesn't exist (Pc vs Npc) and only an alliance attacks and the player's clan is in an alliance
|
||||||
// The player's clan is in an alliance
|
|
||||||
if (getDefenderClans().isEmpty() && (allyId != 0))
|
if (getDefenderClans().isEmpty() && (allyId != 0))
|
||||||
{
|
{
|
||||||
boolean allinsamealliance = true;
|
boolean allinsamealliance = true;
|
||||||
@@ -1640,7 +1642,7 @@ public class Siege
|
|||||||
* Gets the attacker clans.
|
* Gets the attacker clans.
|
||||||
* @return the attacker clans
|
* @return the attacker clans
|
||||||
*/
|
*/
|
||||||
public List<SiegeClan> getAttackerClans()
|
public Collection<SiegeClan> getAttackerClans()
|
||||||
{
|
{
|
||||||
if (_isNormalSide)
|
if (_isNormalSide)
|
||||||
{
|
{
|
||||||
@@ -1706,7 +1708,7 @@ public class Siege
|
|||||||
* Gets the defender clans.
|
* Gets the defender clans.
|
||||||
* @return the defender clans
|
* @return the defender clans
|
||||||
*/
|
*/
|
||||||
public List<SiegeClan> getDefenderClans()
|
public Collection<SiegeClan> getDefenderClans()
|
||||||
{
|
{
|
||||||
if (_isNormalSide)
|
if (_isNormalSide)
|
||||||
{
|
{
|
||||||
@@ -1750,7 +1752,7 @@ public class Siege
|
|||||||
* Gets the defender waiting clans.
|
* Gets the defender waiting clans.
|
||||||
* @return the defender waiting clans
|
* @return the defender waiting clans
|
||||||
*/
|
*/
|
||||||
public List<SiegeClan> getDefenderWaitingClans()
|
public Collection<SiegeClan> getDefenderWaitingClans()
|
||||||
{
|
{
|
||||||
return _defenderWaitingClans;
|
return _defenderWaitingClans;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,11 +111,31 @@ public class RequestBypassToServer extends GameClientPacket
|
|||||||
}
|
}
|
||||||
else if (_command.equals("come_here") && player.isGM())
|
else if (_command.equals("come_here") && player.isGM())
|
||||||
{
|
{
|
||||||
comeHere(player);
|
final WorldObject obj = player.getTarget();
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj instanceof NpcInstance)
|
||||||
|
{
|
||||||
|
final NpcInstance npc = (NpcInstance) obj;
|
||||||
|
npc.setTarget(player);
|
||||||
|
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new Location(player.getX(), player.getY(), player.getZ(), 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (_command.startsWith("player_help "))
|
else if (_command.startsWith("player_help "))
|
||||||
{
|
{
|
||||||
playerHelp(player, _command.substring(12));
|
final String path = _command.substring(12);
|
||||||
|
if (path.contains(".."))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String filename = "data/html/help/" + path;
|
||||||
|
final NpcHtmlMessage html = new NpcHtmlMessage(1);
|
||||||
|
html.setFile(filename);
|
||||||
|
player.sendPacket(html);
|
||||||
}
|
}
|
||||||
else if (_command.startsWith("npc_"))
|
else if (_command.startsWith("npc_"))
|
||||||
{
|
{
|
||||||
@@ -322,37 +342,4 @@ public class RequestBypassToServer extends GameClientPacket
|
|||||||
LOGGER.warning("Bad RequestBypassToServer: " + e);
|
LOGGER.warning("Bad RequestBypassToServer: " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param player
|
|
||||||
*/
|
|
||||||
private void comeHere(PlayerInstance player)
|
|
||||||
{
|
|
||||||
final WorldObject obj = player.getTarget();
|
|
||||||
if (obj == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj instanceof NpcInstance)
|
|
||||||
{
|
|
||||||
final NpcInstance temp = (NpcInstance) obj;
|
|
||||||
temp.setTarget(player);
|
|
||||||
temp.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new Location(player.getX(), player.getY(), player.getZ(), 0));
|
|
||||||
// temp.moveTo(player.getX(),player.getY(), player.getZ(), 0 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void playerHelp(PlayerInstance player, String path)
|
|
||||||
{
|
|
||||||
if (path.contains(".."))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String filename = "data/html/help/" + path;
|
|
||||||
final NpcHtmlMessage html = new NpcHtmlMessage(1);
|
|
||||||
html.setFile(filename);
|
|
||||||
player.sendPacket(html);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user