Index: C:/eclipse/workspace/L2_GameServer/java/net/sf/l2j/gameserver/model/AutoChatHandler.java
===================================================================
--- C:/eclipse/workspace/L2_GameServer/java/net/sf/l2j/gameserver/model/AutoChatHandler.java (revision 1338)
+++ C:/eclipse/workspace/L2_GameServer/java/net/sf/l2j/gameserver/model/AutoChatHandler.java (working copy)
@@ -35,18 +35,18 @@
* at a set time interval.
*
* 1.04 - Fixed the use of player name replacement in chat strings.
- * 1.03 - boolean removeChat(int npcId) can now be used to remove auto chat facility for specified NPC ID.
- * Returns true if NPC ID found, false otherwise.
- * (Added for use with Seven Signs implementation)
- * 1.02 - If %player_random% is used in an auto chat string:
- * NPC will direct chat at random nearby player.
- * or %player_cabal_dawn% or %player_cabal_dusk% used:
- * NPC will direct chat at player in respective cabal.
- * 1.01 - Rewrote most of the start() code to allow more than one instance
- * of an NPC type to "chat" without problems. Now only visible objects
- * in the world are retrieved, so is now more efficient.
- * (Modded L2World.java - added getAllVisibleObjects() method).
- * - Modified run() method of RunCreatureChat to allow chat for multiple instances.
+ * 1.03 - boolean removeChat(int npcId) can now be used to remove auto chat facility for specified NPC ID.
+ * Returns true if NPC ID found, false otherwise.
+ * (Added for use with Seven Signs implementation)
+ * 1.02 - If %player_random% is used in an auto chat string:
+ * NPC will direct chat at random nearby player.
+ * or %player_cabal_dawn% or %player_cabal_dusk% used:
+ * NPC will direct chat at player in respective cabal.
+ * 1.01 - Rewrote most of the start() code to allow more than one instance
+ * of an NPC type to "chat" without problems. Now only visible objects
+ * in the world are retrieved, so is now more efficient.
+ * (Modded L2World.java - added getAllVisibleObjects() method).
+ * - Modified run() method of RunCreatureChat to allow chat for multiple instances.
*
* @version 1.04
* @author Tempy
@@ -57,14 +57,14 @@
private static AutoChatHandler _instance = new AutoChatHandler();
protected static long _chatDelay = 180000; // 3 mins by default
- protected static boolean _useRandomChat = false;
+ protected static boolean _useRandomChat = false;
protected HashMap<Integer, String[]> _texts;
protected HashMap<Integer, ArrayList<L2NpcInstance>> _npcInsts;
public AutoChatHandler()
{
- _texts = new HashMap<Integer, String[]>();
+ _texts = new HashMap<Integer, String[]>();
_npcInsts = new HashMap<Integer, ArrayList<L2NpcInstance>>();
L2Spawn.addSpawnListener(this);
@@ -88,13 +88,13 @@
public synchronized void start() {
if (Config.DEBUG)
_log.info("AutoChatHandler: Searching spawned objects for instances of NPC IDs: " + _npcInsts.keySet());
-
+
RunCreatureChat rcc = new RunCreatureChat(0);
- ClientScheduler.getInstance().scheduleMed(rcc, _chatDelay);
+ ClientScheduler.getInstance().scheduleMed(rcc, _chatDelay);
}
public void registerChat(int npcId, String[] chatText)
- {
+ {
_texts.put(npcId, chatText);
_npcInsts.put(npcId, new ArrayList<L2NpcInstance>());
@@ -103,13 +103,13 @@
}
public boolean removeChat(int npcId)
- {
+ {
if (_npcInsts.containsKey(npcId)) {
_npcInsts.remove(npcId);
_texts.remove(npcId);
if (Config.DEBUG)
- _log.config("AutoChatHandler: Removed auto chat for NPC ID " + npcId);
+ _log.config("AutoChatHandler: Removed auto chat for NPC ID " + npcId);
return true;
}
@@ -159,7 +159,7 @@
nearbyPlayers.add(player);
int lastIndex = _texts.get(npcId).length;
-
+
if (lastIndex > maxIndex)
maxIndex = lastIndex;
@@ -183,46 +183,53 @@
int randomPlayerIndex = rnd.nextInt(nearbyPlayers.size());
L2PcInstance randomPlayer = nearbyPlayers.get(randomPlayerIndex);
- boolean playerFound = false;
- if (text.indexOf("%player_random%") > -1)
+ final int winningCabal = SevenSigns.getInstance().getCabalHighestScore();
+ int losingCabal = SevenSigns.CABAL_NULL;
+
+ if (winningCabal == SevenSigns.CABAL_DAWN)
+ losingCabal = SevenSigns.CABAL_DUSK;
+ else if (winningCabal == SevenSigns.CABAL_DUSK)
+ losingCabal = SevenSigns.CABAL_DAWN;
+
+ if (text.indexOf("%player_random%") > -1)
text = text.replaceAll("%player_random%", randomPlayer.getName());
- if (text.indexOf("%player_cabal_dawn%") > -1)
+ if (text.indexOf("%player_cabal_winner%") > -1)
{
+ boolean playerFound = false;
+
for (L2PcInstance nearbyPlayer : nearbyPlayers) {
- if (SevenSigns.getInstance().getPlayerCabal(nearbyPlayer) == SevenSigns.CABAL_DAWN)
+ if (SevenSigns.getInstance().getPlayerCabal(nearbyPlayer) == winningCabal)
{
- text = text.replaceAll("%player_cabal_dawn%", randomPlayer.getName());
+ text = text.replaceAll("%player_cabal_winner%", randomPlayer.getName());
playerFound = true;
break;
}
}
- // If a player on the side of Dawn isn't nearby, just use the randomly selected player.
+ // If a player on the winning side isn't nearby, just use the randomly selected player.
if (!playerFound)
- text = text.replaceAll("%player_cabal_dawn%", randomPlayer.getName());
+ text = text.replaceAll("%player_cabal_winner%", randomPlayer.getName());
}
- if (text.indexOf("%player_cabal_dusk%") > -1)
+ if (text.indexOf("%player_cabal_loser%") > -1)
{
+ boolean playerFound = false;
+
for (L2PcInstance nearbyPlayer : nearbyPlayers) {
- if (SevenSigns.getInstance().getPlayerCabal(nearbyPlayer) == SevenSigns.CABAL_DUSK)
+ if (SevenSigns.getInstance().getPlayerCabal(nearbyPlayer) == losingCabal)
{
- text = text.replaceAll("%player_cabal_dusk%", randomPlayer.getName());
- playerFound = true;
+ text = text.replaceAll("%player_cabal_loser%", randomPlayer.getName());
+ playerFound = true;
break;
}
}
-
- // If a player on the side of Dusk isn't nearby, just use the randomly selected player.
+ // If a player on the winning side isn't nearby, just use the randomly selected player.
if (!playerFound)
- text = text.replaceAll("%player_cabal_dusk%", randomPlayer.getName());
+ text = text.replaceAll("%player_cabal_loser%", randomPlayer.getName());
}
- }
- else {
- continue;
}
}
catch (Exception e) {
@@ -249,7 +256,7 @@
ClientScheduler.getInstance().scheduleMed(rcc, _chatDelay);
}
}
-
+
public void npcSpawned(L2NpcInstance npc)
{
synchronized (_npcInsts)