Advertisement
Nik

ExPVPMatchRecord

Nik
Jan 11th, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.74 KB | None | 0 0
  1. package l2r.gameserver.network.serverpackets;
  2.  
  3. import java.util.Collections;
  4. import java.util.List;
  5.  
  6. public class ExPVPMatchRecord extends L2GameServerPacket
  7. {
  8.     public static List<PlayerStats> NO_PLAYER_STATS = Collections.emptyList();
  9.     public enum MatchRecordType
  10.     {
  11.         INIT_SCORE, // 0 = Score (Always 0:0) + Time (Static 10min) + Party Names (if there are ppl in the list) + Match Results button -> http://i.imgur.com/qdwL2JY.png
  12.         UPDATE_SCORE, // 1 = Update Score (Defining Win/Lose/Player Teams is unnecessary)
  13.         FINAL_SCORE_WINDOW, // 2 = Score Window. Stops score timer -> http://i.imgur.com/msrZVR3.png
  14.         ADD_PLAYERS_TO_SCORE_WINDOW // 3+ = Adds players to score window. It will add them ontop of previous records
  15.     }
  16.    
  17.     public enum MatchRecordWinner
  18.     {
  19.         NONE, // 0 - Blank
  20.         BLUE, // 1 - Win
  21.         RED // 2 - Lose
  22.     }
  23.    
  24.     private MatchRecordType _type;
  25.     private MatchRecordWinner _winner;
  26.     private int _blueScore;
  27.     private int _redScore;
  28.     List<PlayerStats> _bluePlayers;
  29.     List<PlayerStats> _redPlayers;
  30.    
  31.     public ExPVPMatchRecord(MatchRecordType type, MatchRecordWinner winner, int blueScore, int redScore, List<PlayerStats> bluePlayers, List<PlayerStats> redPlayers)
  32.     {
  33.         _type = type;
  34.         _winner = winner;
  35.         _blueScore = blueScore;
  36.         _redScore = redScore;
  37.         _bluePlayers = (bluePlayers != null) ? bluePlayers : NO_PLAYER_STATS;
  38.         _redPlayers = (redPlayers != null) ? redPlayers : NO_PLAYER_STATS;
  39.     }
  40.    
  41.     public ExPVPMatchRecord(MatchRecordType type, int blueScore, int redScore, List<PlayerStats> bluePlayers, List<PlayerStats> redPlayers)
  42.     {
  43.         _type = type;
  44.         _winner = blueScore > redScore ? MatchRecordWinner.BLUE : redScore > blueScore ? MatchRecordWinner.RED : MatchRecordWinner.NONE;
  45.         _blueScore = blueScore;
  46.         _redScore = redScore;
  47.         _bluePlayers = (bluePlayers != null) ? bluePlayers : NO_PLAYER_STATS;
  48.         _redPlayers = (redPlayers != null) ? redPlayers : NO_PLAYER_STATS;
  49.     }
  50.    
  51.     public static ExPVPMatchRecord updateScore(int blueScore, int redScore)
  52.     {
  53.         return new ExPVPMatchRecord(MatchRecordType.UPDATE_SCORE, MatchRecordWinner.NONE, blueScore, redScore, null, null);
  54.     }
  55.    
  56.     public static ExPVPMatchRecord initScore(List<PlayerStats> bluePlayers, List<PlayerStats> redPlayers)
  57.     {
  58.         return new ExPVPMatchRecord(MatchRecordType.INIT_SCORE, MatchRecordWinner.NONE, 0, 0, bluePlayers, redPlayers);
  59.     }
  60.    
  61.     public static ExPVPMatchRecord addPlayers(List<PlayerStats> bluePlayers, List<PlayerStats> redPlayers)
  62.     {
  63.         return new ExPVPMatchRecord(MatchRecordType.ADD_PLAYERS_TO_SCORE_WINDOW, MatchRecordWinner.NONE, 0, 0, bluePlayers, redPlayers);
  64.     }
  65.    
  66.     @Override
  67.     protected void writeImpl()
  68.     {
  69.         writeEx(0x7E);
  70.        
  71.         writeD(_type.ordinal()); // Type
  72.         writeD(_winner == MatchRecordWinner.BLUE ? 1 : _winner.ordinal()); // Blue(Left) Blank/Win/Lose
  73.         writeD(_winner == MatchRecordWinner.RED ? 1 : _winner == MatchRecordWinner.BLUE ? 2 : 0); // Red(Red) Blank/Win/Lose
  74.         writeD(_blueScore); // Score Blue
  75.         writeD(_redScore); // Score Red
  76.        
  77.         writeD(_bluePlayers.size()); // Blue Team Player size
  78.         for (PlayerStats ps : _bluePlayers)
  79.         {
  80.             writeS(ps.playerName); // Player Name
  81.             writeD(ps.kills); // Kills
  82.             writeD(ps.deaths); // Deaths
  83.         }
  84.        
  85.         writeD(_redPlayers.size()); // Red Team Player size
  86.         for (PlayerStats ps : _redPlayers)
  87.         {
  88.             writeS(ps.playerName); // Player Name
  89.             writeD(ps.kills); // Kills
  90.             writeD(ps.deaths); // Deaths
  91.         }
  92.     }
  93.    
  94.     public static class PlayerStats
  95.     {
  96.         String playerName;
  97.         int kills;
  98.         int deaths;
  99.        
  100.         public PlayerStats(String playerName, int kills, int deaths)
  101.         {
  102.             this.playerName = playerName;
  103.             this.kills = kills;
  104.             this.deaths = deaths;
  105.         }
  106.        
  107.         public PlayerStats(String playerName)
  108.         {
  109.             this.playerName = playerName;
  110.             kills = 0;
  111.             deaths = 0;
  112.         }
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement