[jetrix-cvs] jetrix/src/java/net/jetrix/filter StatsFilter.java,1.1,1.2
Brought to you by:
smanux
From: <sm...@us...> - 2003-07-06 15:57:50
|
Update of /cvsroot/jetrix/jetrix/src/java/net/jetrix/filter In directory sc8-pr-cvs1:/tmp/cvs-serv23864/src/java/net/jetrix/filter Modified Files: StatsFilter.java Log Message: One bloc count is removed on every add to all Index: StatsFilter.java =================================================================== RCS file: /cvsroot/jetrix/jetrix/src/java/net/jetrix/filter/StatsFilter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StatsFilter.java 10 May 2003 15:10:31 -0000 1.1 --- StatsFilter.java 6 Jul 2003 15:57:47 -0000 1.2 *************** *** 39,42 **** --- 39,43 ---- private long totalTime; private long lastStart; + private long startTime; private static DecimalFormat df = new DecimalFormat("0.00"); *************** *** 57,61 **** // register the date of the last start/resume ! lastStart = new Date().getTime(); // initialize the stats --- 58,63 ---- // register the date of the last start/resume ! lastStart = System.currentTimeMillis(); ! startTime = lastStart; // initialize the stats *************** *** 79,117 **** // forward the message out.add(m); ! long now = System.currentTimeMillis(); ! totalTime += (now - lastStart); ! ! for (int slot = 1; slot <= 6; slot++) ! { ! PlayerStats playerStats = (PlayerStats) stats.get(slot - 1); ! User user = getChannel().getPlayer(slot); ! ! if (playerStats != null && user != null) ! { ! // update the play time of the remaining players ! if (playerStats.playing) ! { ! playerStats.timePlayed += (now - lastStart); ! } ! ! // display the stats ! String ppm = df.format(playerStats.getBlocksPerMinute()); ! ! PlineMessage result = new PlineMessage(); ! result.setText("<purple>" + user.getName() + "</purple> : " ! + playerStats.blockCount + " <aqua>blocks @<red>" + ppm + "</red> bpm, " ! + "<black>" + playerStats.linesAdded + "</black> added, " ! + "<black>" + playerStats.tetrisCount +"</black> tetris, " ! + "<black>" + playerStats.specialsSent + " / " + playerStats.specialsReceived + "</black> specials"); ! ! out.add(result); ! } ! } ! ! // display the total game time ! PlineMessage time = new PlineMessage(); ! time.setText("<brown>Total game time: <black>" + (totalTime / 1000) + "</black> seconds"); ! out.add(time); } --- 81,91 ---- // forward the message out.add(m); + displayStats(out); + } ! public void onMessage(StopGameMessage m, List out) ! { ! out.add(m); ! displayStats(out); } *************** *** 135,139 **** } - public void onMessage(ResumeMessage m, List out) { --- 109,112 ---- *************** *** 149,153 **** // increasing block count for the updated slot PlayerStats playerStats = (PlayerStats) stats.get(m.getSlot() - 1); ! if (playerStats != null) { playerStats.blockCount++; } } --- 122,129 ---- // increasing block count for the updated slot PlayerStats playerStats = (PlayerStats) stats.get(m.getSlot() - 1); ! if (playerStats != null && (System.currentTimeMillis() - startTime > 1500)) ! { ! playerStats.blockCount++; ! } } *************** *** 159,163 **** out.add(m); PlayerStats playerStats = (PlayerStats) stats.get(m.getFromSlot() - 1); ! if (playerStats != null) { playerStats.linesAdded++; } } --- 135,144 ---- out.add(m); PlayerStats playerStats = (PlayerStats) stats.get(m.getFromSlot() - 1); ! if (playerStats != null) ! { ! playerStats.linesAdded++; ! // remove 1 block count from any player in an opposite team ! removeBloc(m); ! } } *************** *** 166,170 **** out.add(m); PlayerStats playerStats = (PlayerStats) stats.get(m.getFromSlot() - 1); ! if (playerStats != null) { playerStats.linesAdded += 2; } } --- 147,156 ---- out.add(m); PlayerStats playerStats = (PlayerStats) stats.get(m.getFromSlot() - 1); ! if (playerStats != null) ! { ! playerStats.linesAdded += 2; ! // remove 1 block count from any player in an opposite team ! removeBloc(m); ! } } *************** *** 177,180 **** --- 163,168 ---- playerStats.linesAdded += 4; playerStats.tetrisCount++; + // remove 1 block count from any player in an opposite team + removeBloc(m); } } *************** *** 218,221 **** --- 206,276 ---- playerStats.timePlayed += (now - lastStart); } + } + + /** + * Decrease the bloc count of players receiving an add to all message since + * they will send back a field message assimilated by mistake as a bloc fall. + */ + private void removeBloc(SpecialMessage m) + { + int slot = m.getFromSlot(); + + if (slot > 0) + { + Client fromClient = (Client) m.getSource(); + + for (int i = 1; i <= 6; i++) + { + Client client = getChannel().getClient(i); + if (i != slot && client != null) + { + User user = client.getUser(); + + if (user.isPlaying() && (user.getTeam() == null || !user.getTeam().equals(fromClient.getUser().getTeam()))) + { + PlayerStats playerStats = (PlayerStats) stats.get(i - 1); + playerStats.blockCount--; + } + } + } + } + } + + private void displayStats(List out) + { + long now = System.currentTimeMillis(); + totalTime += (now - lastStart); + + for (int slot = 1; slot <= 6; slot++) + { + PlayerStats playerStats = (PlayerStats) stats.get(slot - 1); + User user = getChannel().getPlayer(slot); + + if (playerStats != null && user != null) + { + // update the play time of the remaining players + if (playerStats.playing) + { + playerStats.timePlayed += (now - lastStart); + } + + // display the stats + String ppm = df.format(playerStats.getBlocksPerMinute()); + + PlineMessage result = new PlineMessage(); + result.setText("<purple>" + user.getName() + "</purple> : " + + playerStats.blockCount + " <aqua>blocks @<red>" + ppm + "</red> bpm, " + + "<black>" + playerStats.linesAdded + "</black> added, " + + "<black>" + playerStats.tetrisCount +"</black> tetris, " + + "<black>" + playerStats.specialsSent + " / " + playerStats.specialsReceived + "</black> specials"); + + out.add(result); + } + } + + // display the total game time + PlineMessage time = new PlineMessage(); + time.setText("<brown>Total game time: <black>" + (totalTime / 1000) + "</black> seconds"); + out.add(time); } |