SHOW:
|
|
- or go back to the newest paste.
| 1 | package twcore.bots.battlebot.PublicOps.Flags; | |
| 2 | ||
| 3 | import java.util.ArrayList; | |
| 4 | import java.util.Iterator; | |
| 5 | import java.util.List; | |
| 6 | ||
| 7 | import twcore.bots.battlebot.BZTimer; | |
| 8 | import twcore.bots.battlebot.ChatBuffer; | |
| 9 | import twcore.bots.battlebot.DoorMan; | |
| 10 | import twcore.core.BotAction; | |
| 11 | import twcore.core.events.PlayerDeath; | |
| 12 | import twcore.core.events.PlayerPosition; | |
| 13 | import twcore.core.events.WatchDamage; | |
| 14 | import twcore.core.game.Player; | |
| 15 | ||
| 16 | public class BaseFlagging {
| |
| 17 | BotAction b; | |
| 18 | ChatBuffer bzChat; | |
| 19 | DoorMan bob; | |
| 20 | ||
| 21 | public BaseFlagging(BotAction b, ChatBuffer c, DoorMan bob) | |
| 22 | {
| |
| 23 | this.b = b; | |
| 24 | this.bzChat = c; | |
| 25 | this.bob = bob; | |
| 26 | } | |
| 27 | ||
| 28 | /*-------------------------------------------------------------------------------\ | |
| 29 | * | |
| 30 | - | private String b_AtomicKiller = "~none~"; |
| 30 | + | * NEEDED VARS |
| 31 | - | private int b_AtomicKillerCount = 0; |
| 31 | + | * |
| 32 | *-------------------------------------------------------------------------------*/ | |
| 33 | private boolean m_StartingGame = false; | |
| 34 | private boolean m_GameOn = false; | |
| 35 | public boolean GameOn(){ return this.m_GameOn; }
| |
| 36 | ||
| 37 | private long m_GameStartTimeStamp; | |
| 38 | ||
| 39 | // Flag lvz | |
| 40 | private int m_LvzOn = 1428; | |
| 41 | private int m_LvzOff = 1427; | |
| 42 | ||
| 43 | // Door to toggle on and off | |
| 44 | private byte m_DoorNumber = 5; | |
| 45 | ||
| 46 | // Map room coords | |
| 47 | private short[] m_MapRoom1 = new short[]{ 225 * 16, 778 * 16, 499 * 16, 846 * 16};
| |
| 48 | private short[] m_MapRoom2 = new short[]{ 499 * 16, 792 * 16, 785 * 16, 846 * 16};
| |
| 49 | private short[] m_FlagHotSpot = new short[]{ 12336, 13328, 12496, 13488 };
| |
| 50 | ||
| 51 | // Settings for timer | |
| 52 | private BZTimer m_StartGameSet; | |
| 53 | // settings for game timer | |
| 54 | private BZTimer m_GameTimerSet; | |
| 55 | ||
| 56 | // If base has initially been raided | |
| 57 | private boolean m_BeenRaided = false; | |
| 58 | private String m_WhoRaided = "~nobody~"; | |
| 59 | private short m_FreqRaided = 8025; | |
| 60 | private long m_RaidTime = 0; | |
| 61 | ||
| 62 | // Freq that owns the flag | |
| 63 | private short m_BaseOwner = 8025; | |
| 64 | private long m_BaseTimestamp; | |
| 65 | ||
| 66 | /*-------------------------------------------------------------------------------\ | |
| 67 | * | |
| 68 | * SUBSPACE EVENTS | |
| 69 | * | |
| 70 | *-------------------------------------------------------------------------------*/ | |
| 71 | public void PlayerPositionEvent(PlayerPosition p) | |
| 72 | {
| |
| 73 | // If there is no game check for stragglers in the area | |
| 74 | if (!m_GameOn) | |
| 75 | {
| |
| 76 | // Flag room | |
| 77 | if (InRegion(p,m_MapRoom1)||InRegion(p,m_MapRoom2)) | |
| 78 | {
| |
| 79 | // Warp them back | |
| 80 | b.sendPrivateMessage(p.getPlayerID(), "There are no matches at this time and you are not authorized to be in this area."); | |
| 81 | b.warpTo(p.getPlayerID(), 512,512); | |
| 82 | } | |
| 83 | // No need to track flag hot spot unless game has started | |
| 84 | return; | |
| 85 | } | |
| 86 | ||
| 87 | // Flag HOTSPOT - If a new freq has taken possession | |
| 88 | if (InRegion(p, m_FlagHotSpot) && b.getPlayer(p.getPlayerID()).getFrequency() != m_BaseOwner) | |
| 89 | baseRaided(p); | |
| 90 | } | |
| 91 | public void PlayerDeathEvent(PlayerDeath pd) | |
| 92 | {
| |
| 93 | // Don't continue if game isn't running | |
| 94 | if (!m_GameOn) return; | |
| 95 | ||
| 96 | if (InMapRoom(pd.getKillerID()) || InMapRoom(pd.getKilleeID())) | |
| 97 | {
| |
| 98 | // Get basing freqs | |
| 99 | BaseFreq killerF = getBaseFreq(b.getPlayer(pd.getKillerID()).getFrequency(),b.getPlayerName(pd.getKillerID())); | |
| 100 | BaseFreq killedF = getBaseFreq(b.getPlayer(pd.getKilleeID()).getFrequency(),b.getPlayerName(pd.getKilleeID())); | |
| 101 | // Get players | |
| 102 | BasePlayer killer = killerF.getPlayer(b.getPlayerName(pd.getKillerID())); | |
| 103 | BasePlayer killed = killedF.getPlayer(b.getPlayerName(pd.getKilleeID())); | |
| 104 | ||
| 105 | killer.KilledPlayer(); | |
| 106 | killed.Died(); | |
| 107 | ||
| 108 | if (killerF.getFreq() == killedF.getFreq()) | |
| 109 | killer.killedTeamMate(); | |
| 110 | else if (killer.getMultis() > 1) | |
| 111 | updateMultiKillPlayer(killer); | |
| 112 | } | |
| 113 | } | |
| 114 | public void damageEvent(WatchDamage w) | |
| 115 | {
| |
| 116 | if (!m_GameOn) return; | |
| 117 | ||
| 118 | if (InMapRoom(w.getAttacker()) || InMapRoom(w.getVictim())) | |
| 119 | {
| |
| 120 | // Get basing freqs | |
| 121 | BaseFreq attackerF = getBaseFreq(b.getPlayer(w.getAttacker()).getFrequency(),b.getPlayerName(w.getAttacker())); | |
| 122 | BaseFreq victimF = getBaseFreq(b.getPlayer(w.getVictim()).getFrequency(),b.getPlayerName(w.getVictim())); | |
| 123 | ||
| 124 | BasePlayer a = attackerF.getPlayer(b.getPlayerName(w.getAttacker())); | |
| 125 | BasePlayer v = victimF.getPlayer(b.getPlayerName(w.getVictim())); | |
| 126 | ||
| 127 | if(a.equals(v)) | |
| 128 | a.damagedSelf(w.getEnergyLost()); | |
| 129 | else | |
| 130 | {
| |
| 131 | a.dealtDamage(w.getEnergyLost()); | |
| 132 | v.tookDamage(w.getEnergyLost()); | |
| 133 | } | |
| 134 | } | |
| 135 | } | |
| 136 | /*-------------------------------------------------------------------------------\ | |
| 137 | * | |
| 138 | * MultiKills | |
| 139 | * | |
| 140 | *-------------------------------------------------------------------------------*/ | |
| 141 | // Time setting for multikills | |
| 142 | int m_MultiKillTimeLimit = 3000;//3 seconds | |
| 143 | // Holds all the multi kill messages | |
| 144 | private List<MultiMessageEvent> m_MultiKillMessages = new ArrayList<MultiMessageEvent>(); | |
| 145 | // SoundCodes to messages sent | |
| 146 | private int[] m_MultiAnnouncementsSoundCodes = new int[]{ 2, 2, 2, 21 };
| |
| 147 | // Messages to send according to kill amount | |
| 148 | private String[] m_MultiAnnouncements = new String[] | |
| 149 | {
| |
| 150 | "[MULTIKILL] - @name@ got a DOUBLE kill.",//2 kills | |
| 151 | "[MULTIKILL] - @name@ with the TRIPLE KILL.",//3 kills | |
| 152 | "[MULTIKILL] - Quadruple ownage by @name@!",// 4 kills | |
| 153 | "[MULTIKILL] - Stop the madness! @name@ got @kills@ kills!"//5+ kills | |
| 154 | }; | |
| 155 | // Configures the message and sends it out | |
| 156 | private void announceMultiKillMessage(String PlayerName, int Kills) | |
| 157 | {
| |
| 158 | int index = (Kills - 2) > (m_MultiAnnouncements.length - 1) ? m_MultiAnnouncements.length - 1: Kills - 2; | |
| 159 | ||
| 160 | b.sendArenaMessage( | |
| 161 | m_MultiAnnouncements[index].replace("@name@", PlayerName).replace("@kills@", Integer.toString(Kills))
| |
| 162 | , m_MultiAnnouncementsSoundCodes[index]); | |
| 163 | } | |
| 164 | // This goes in timer - checks for new messages and sends them | |
| 165 | private void updateMultiKillList() | |
| 166 | {
| |
| 167 | // Ignore method if list is empty | |
| 168 | if (m_MultiKillMessages.isEmpty()) return; | |
| 169 | ||
| 170 | // Check next message | |
| 171 | if (m_MultiKillMessages.get(0).timeToSend()) | |
| 172 | {
| |
| 173 | // Send out message and delete | |
| 174 | announceMultiKillMessage(m_MultiKillMessages.get(0).getPlayerName(),m_MultiKillMessages.get(0).getNumberOfKills()); | |
| 175 | m_MultiKillMessages.remove(0); | |
| 176 | } | |
| 177 | } | |
| 178 | // Creates/Updates multikill messages | |
| 179 | private void updateMultiKillPlayer(BasePlayer BPlayer) | |
| 180 | {
| |
| 181 | // If player is already on list - update it | |
| 182 | for (MultiMessageEvent m: m_MultiKillMessages) | |
| 183 | {
| |
| 184 | if (m.getPlayerName() == BPlayer.getPlayerName()) | |
| 185 | {
| |
| 186 | m.updateMultiPlayer(BPlayer.getMultis()); | |
| 187 | return; | |
| 188 | } | |
| 189 | } | |
| 190 | // If he isn't on list create and store it in list | |
| 191 | m_MultiKillMessages.add( new MultiMessageEvent(BPlayer.getPlayerName(),BPlayer.getMultis())); | |
| 192 | } | |
| 193 | // Object to hold multi kill message info | |
| 194 | private class MultiMessageEvent | |
| 195 | {
| |
| 196 | public MultiMessageEvent(String PlayerName, int Kills) | |
| 197 | {
| |
| 198 | this.m_PlayerName = PlayerName; | |
| 199 | this.m_Kills = Kills; | |
| 200 | } | |
| 201 | ||
| 202 | private String m_PlayerName; | |
| 203 | public String getPlayerName(){ return m_PlayerName; }
| |
| 204 | ||
| 205 | private long m_Timestamp = System.currentTimeMillis(); | |
| 206 | public void updateMultiPlayer(int Kills) | |
| 207 | {
| |
| 208 | this.m_Kills = Kills; | |
| 209 | this.m_Timestamp = System.currentTimeMillis(); | |
| 210 | } | |
| 211 | ||
| 212 | private int m_Kills; | |
| 213 | public int getNumberOfKills() { return m_Kills;};
| |
| 214 | ||
| 215 | // Expiration time for new update - send out message | |
| 216 | public boolean timeToSend(){ return (System.currentTimeMillis() - m_Timestamp > m_MultiKillTimeLimit + 1000) ? true: false; }
| |
| 217 | } | |
| 218 | ||
| 219 | /*-------------------------------------------------------------------------------\ | |
| 220 | * | |
| 221 | * BASE FLAG TIMER | |
| 222 | * | |
| 223 | *-------------------------------------------------------------------------------*/ | |
| 224 | // main timer for game | |
| 225 | public void BaseTimer() | |
| 226 | {
| |
| 227 | updateMultiKillList(); | |
| 228 | updateTimerTasks(); | |
| 229 | } | |
| 230 | // List of timed events | |
| 231 | private List<BZTimer> Timers = new ArrayList<BZTimer>(); | |
| 232 | // Updates timers | |
| 233 | public void updateTimerTasks() | |
| 234 | {
| |
| 235 | // sort through timers and update | |
| 236 | for (int i=Timers.size()-1; i> -1; i--) | |
| 237 | {
| |
| 238 | if (!Timers.get(i).TimerExpired() ) | |
| 239 | Timers.get(i).UpdateTimer(b, bzChat); | |
| 240 | else | |
| 241 | {
| |
| 242 | doTimerTask(Timers.get(i).getTimerTask()); | |
| 243 | Timers.remove(i); | |
| 244 | } | |
| 245 | } | |
| 246 | } | |
| 247 | // Timer tasks | |
| 248 | private void doTimerTask(int Task) | |
| 249 | {
| |
| 250 | switch(Task) | |
| 251 | {
| |
| 252 | case 1: doGameTimer(); break; | |
| 253 | case 2: doGameOver(); break; | |
| 254 | } | |
| 255 | } | |
| 256 | /*-------------------------------------------------------------------------------\ | |
| 257 | * | |
| 258 | * MAIN FUNCTIONS | |
| 259 | * | |
| 260 | *-------------------------------------------------------------------------------*/ | |
| 261 | public void m_StartGame() | |
| 262 | {
| |
| 263 | if (m_GameOn || m_StartingGame) | |
| 264 | {
| |
| 265 | bzChat.debugMessage("BaseFlagging has already been activated.");
| |
| 266 | return; | |
| 267 | } | |
| 268 | // starting game duh | |
| 269 | m_StartingGame = true; | |
| 270 | ||
| 271 | b.sendUnfilteredPublicMessage("*objset -" + m_LvzOn + ", +" + m_LvzOff + ",");
| |
| 272 | ||
| 273 | // ## Debug ## | |
| 274 | bzChat.debugMessage(" - [T20 Attack] Starting timer for Game start.");
| |
| 275 | ||
| 276 | // Record the start to timer | |
| 277 | m_StartGameSet.StartTimer(); | |
| 278 | // add to our timer list | |
| 279 | Timers.add(m_StartGameSet); | |
| 280 | } | |
| 281 | private void doGameTimer() | |
| 282 | {
| |
| 283 | // ## Debug ## | |
| 284 | bzChat.debugMessage(" - [T20 Attack] GameStarted");
| |
| 285 | ||
| 286 | // turn game on | |
| 287 | m_GameOn = true; | |
| 288 | // Open the map room doors | |
| 289 | bob.ChangeDoorStatus(m_DoorNumber, !m_GameOn); | |
| 290 | // Start Game timer | |
| 291 | m_GameTimerSet.StartTimer(); | |
| 292 | m_GameStartTimeStamp = System.currentTimeMillis(); | |
| 293 | // add to our timer list | |
| 294 | Timers.add(m_GameTimerSet); | |
| 295 | } | |
| 296 | private void doGameOver() | |
| 297 | {
| |
| 298 | // ## Debug ## | |
| 299 | bzChat.debugMessage(" - [T20 Attack] GameEnded");
| |
| 300 | ||
| 301 | // Close the map room doors | |
| 302 | bob.ChangeDoorStatus(m_DoorNumber, !m_GameOn); | |
| 303 | ||
| 304 | // Record the last time held | |
| 305 | BaseFreq raided = getBaseFreq(m_BaseOwner,""); | |
| 306 | raided.addHoldTime(System.currentTimeMillis() - m_BaseTimestamp); | |
| 307 | ||
| 308 | int winFreqIndex = 999; | |
| 309 | long wintime = 0; | |
| 310 | ||
| 311 | ||
| 312 | for(BaseFreq bf: FreqList) | |
| 313 | {
| |
| 314 | if(bf.getTotalHoldTime() > wintime) | |
| 315 | {
| |
| 316 | winFreqIndex = FreqList.indexOf(bf); | |
| 317 | wintime = bf.getTotalHoldTime(); | |
| 318 | } | |
| 319 | } | |
| 320 | ||
| 321 | FreqList.get(winFreqIndex).doEndGameLoad(); | |
| 322 | ||
| 323 | for (String s:FreqList.get(winFreqIndex).getGamePrintOut()) | |
| 324 | b.sendArenaMessage(s); | |
| 325 | ||
| 326 | for(BaseFreq bf: FreqList) | |
| 327 | {
| |
| 328 | //if (FreqList.indexOf(bf) != winFreqIndex) | |
| 329 | //{
| |
| 330 | // bf.doEndGameLoad(); | |
| 331 | // | |
| 332 | // for (String s:bf.getGamePrintOut()) | |
| 333 | // b.sendArenaMessage(s); | |
| 334 | //} | |
| 335 | /* b.sendArenaMessage("+-----------------------------------------------------------------------------");
| |
| 336 | b.sendArenaMessage("| Freq[ "+padL(Integer.toString(bf.getFreq()),4," ")+" : "+bf.getFreqName()+" ] Total Time[ "+getTimeMs(bf.getTotalHoldTime())+" ] ");
| |
| 337 | b.sendArenaMessage("+-----------------------------------------------------------------------------");
| |
| 338 | for(BasePlayer bp:bf.FreqPlayers()) | |
| 339 | {
| |
| 340 | b.sendPrivateMessage(bp.getPlayerName(),"Player: " + bp.getPlayerName()); | |
| 341 | b.sendPrivateMessage(bp.getPlayerName(),"-------------+ Captured Flags : " + bp.getCapturedFlags()); | |
| 342 | b.sendPrivateMessage(bp.getPlayerName(),"| | Kills : " + (bp.getKills() - bp.getTKs())); | |
| 343 | b.sendPrivateMessage(bp.getPlayerName(),"| | Deaths : " + bp.getDeaths()); | |
| 344 | b.sendPrivateMessage(bp.getPlayerName(),"| | Damage Dealt : " + bp.getDamageDealt()); | |
| 345 | b.sendPrivateMessage(bp.getPlayerName(),"| | Damage Received: " + bp.getDamageTaken()); | |
| 346 | b.sendPrivateMessage(bp.getPlayerName(),"| | Self Damage wtf: " + bp.getDamageSelf()); | |
| 347 | b.sendPrivateMessage(bp.getPlayerName(),"+------------+----------------------------------------------------------------"); | |
| 348 | }*/ | |
| 349 | } | |
| 350 | ||
| 351 | // Reset vars | |
| 352 | m_GameOn = false; | |
| 353 | m_StartingGame = false; | |
| 354 | m_BeenRaided = false; | |
| 355 | m_WhoRaided = "~nobody~"; | |
| 356 | m_FreqRaided = 8025; | |
| 357 | m_RaidTime = 0; | |
| 358 | m_BaseOwner = 8025; | |
| 359 | FreqList = new ArrayList<BaseFreq>(); | |
| 360 | // load timers | |
| 361 | loadTimers(); | |
| 362 | ||
| 363 | // Toggle flag off | |
| 364 | b.sendUnfilteredPublicMessage("*objset -" + m_LvzOn + ", +" + m_LvzOff + ",");
| |
| 365 | } | |
| 366 | // Base has been raided | |
| 367 | private void baseRaided(PlayerPosition p) | |
| 368 | {
| |
| 369 | // Grab freq info | |
| 370 | BaseFreq raiders = getBaseFreq(b.getPlayer(p.getPlayerID()).getFrequency(),b.getPlayerName(p.getPlayerID())); | |
| 371 | BasePlayer raider = raiders.getPlayer(b.getPlayerName(p.getPlayerID())); | |
| 372 | ||
| 373 | raider.capturedAFlag(); | |
| 374 | ||
| 375 | // Has base been initialy raided? | |
| 376 | if (!m_BeenRaided) | |
| 377 | {
| |
| 378 | // Record initial raiders - getTimeMs | |
| 379 | m_BeenRaided = true; | |
| 380 | m_WhoRaided = b.getPlayerName(p.getPlayerID()); | |
| 381 | m_FreqRaided = raiders.getFreq(); | |
| 382 | m_RaidTime = System.currentTimeMillis() - m_GameStartTimeStamp; | |
| 383 | ||
| 384 | // ## DEBUG ## | |
| 385 | bzChat.debugMessage("Initial Base Raid: Player[ "+m_WhoRaided+" ] Freq[ "+m_FreqRaided+" ] Time[ "+getTimeMs(m_RaidTime)+" ]");
| |
| 386 | } | |
| 387 | else | |
| 388 | {
| |
| 389 | // Grab losers info | |
| 390 | BaseFreq raided = getBaseFreq(m_BaseOwner,raider.getPlayerName()); | |
| 391 | raided.addHoldTime(System.currentTimeMillis() - m_BaseTimestamp); | |
| 392 | ||
| 393 | b.sendOpposingTeamMessageByFrequency(m_BaseOwner, "Flag lost. Time held [ "+getTimeMs(System.currentTimeMillis() - m_BaseTimestamp)+" ] TotalHoldTime[ "+getTimeMs(raided.getTotalHoldTime())+" ]"); | |
| 394 | } | |
| 395 | ||
| 396 | // make them owners | |
| 397 | m_BaseOwner = raiders.getFreq(); | |
| 398 | m_BaseTimestamp = System.currentTimeMillis(); | |
| 399 | // Toggle gfx | |
| 400 | FlagToggle(raiders.getFreq()); | |
| 401 | } | |
| 402 | // Toggle flag lvz for raid | |
| 403 | private void FlagToggle(short Freq) | |
| 404 | {
| |
| 405 | // Get all Players | |
| 406 | Iterator<Player> i = b.getPlayingPlayerIterator(); | |
| 407 | ||
| 408 | // Toggle lvz off for all players | |
| 409 | b.sendUnfilteredPublicMessage("*objset -" + m_LvzOn + ", +" + m_LvzOff + ",");
| |
| 410 | ||
| 411 | // Get all players on same freq and toggle lvz. | |
| 412 | while( i.hasNext() ){
| |
| 413 | Player p = i.next(); | |
| 414 | if( p.getFrequency() == Freq){
| |
| 415 | //Toggle lvz on for freq | |
| 416 | b.sendUnfilteredPrivateMessage( p.getPlayerID(), "*objset +" + m_LvzOn + ", -" + m_LvzOff + ","); | |
| 417 | } | |
| 418 | } | |
| 419 | } | |
| 420 | /*-------------------------------------------------------------------------------\ | |
| 421 | * | |
| 422 | * Player Object Methods | |
| 423 | * | |
| 424 | *-------------------------------------------------------------------------------*/ | |
| 425 | private class BasePlayer | |
| 426 | {
| |
| 427 | public BasePlayer(String PlayerName) | |
| 428 | {
| |
| 429 | this.m_PlayerName = PlayerName; | |
| 430 | } | |
| 431 | ||
| 432 | private String m_PlayerName; | |
| 433 | public String getPlayerName(){ return m_PlayerName; }
| |
| 434 | ||
| 435 | private int m_CapturedFlags = 0; | |
| 436 | public int getCapturedFlags(){ return this.m_CapturedFlags;}
| |
| 437 | public void capturedAFlag(){ m_CapturedFlags +=1; }
| |
| 438 | ||
| 439 | private int m_TKs = 0; | |
| 440 | public int getTKs(){ return this.m_TKs;}
| |
| 441 | public void killedTeamMate(){ this.m_TKs += 1;}
| |
| 442 | ||
| 443 | private int m_Multi = 0; | |
| 444 | public int getMultis(){ return this.m_Multi;}
| |
| 445 | private int m_BestMulti = 1; | |
| 446 | public int getBestMulti(){ return this.m_BestMulti;}
| |
| 447 | private long m_KillTimestamp = System.currentTimeMillis(); | |
| 448 | ||
| 449 | private int m_Kills = 0; | |
| 450 | public int getKills(){ return this.m_Kills;}
| |
| 451 | public void KilledPlayer() | |
| 452 | {
| |
| 453 | // add player kills | |
| 454 | this.m_Kills += 1; | |
| 455 | // check for multikill | |
| 456 | if (System.currentTimeMillis() - m_KillTimestamp < m_MultiKillTimeLimit) | |
| 457 | {
| |
| 458 | m_Multi+=1; | |
| 459 | if (m_Multi > m_BestMulti) m_BestMulti = m_Multi; | |
| 460 | } | |
| 461 | else m_Multi = 1; | |
| 462 | ||
| 463 | // update kill timestamp | |
| 464 | m_KillTimestamp = System.currentTimeMillis(); | |
| 465 | } | |
| 466 | ||
| 467 | private int m_Deaths = 0; | |
| 468 | public int getDeaths(){ return this.m_Deaths;}
| |
| 469 | public void Died(){ this.m_Deaths += 1;}
| |
| 470 | ||
| 471 | private int m_DamageSelf = 0; | |
| 472 | public int getDamageSelf() { return this.m_DamageSelf; }
| |
| 473 | public void damagedSelf(int Damage) { this.m_DamageSelf += Damage;}
| |
| 474 | ||
| 475 | private int m_DamageDealt = 0; | |
| 476 | public int getDamageDealt() { return this.m_DamageDealt; }
| |
| 477 | public void dealtDamage(int Damage) { this.m_DamageDealt += Damage;}
| |
| 478 | ||
| 479 | private int m_DamageTaken = 0; | |
| 480 | public int getDamageTaken() { return this.m_DamageTaken; }
| |
| 481 | public void tookDamage(int Damage) { this.m_DamageTaken += Damage;}
| |
| 482 | } | |
| 483 | /*-------------------------------------------------------------------------------\ | |
| 484 | * | |
| 485 | * Freq Object Methods | |
| 486 | * | |
| 487 | *-------------------------------------------------------------------------------*/ | |
| 488 | // Master list of active freqs | |
| 489 | private List<BaseFreq> FreqList = new ArrayList<BaseFreq>(); | |
| 490 | // Get freq object by freq number | |
| 491 | private BaseFreq getBaseFreq(short freq, String PlayerName) | |
| 492 | {
| |
| 493 | for(BaseFreq b:FreqList) | |
| 494 | if (b.getFreq() == freq) return b; | |
| 495 | ||
| 496 | BaseFreq newBF = new BaseFreq(freq,b.getPlayer(PlayerName).getSquadName()); | |
| 497 | FreqList.add(newBF); | |
| 498 | return FreqList.get((FreqList.indexOf(newBF))); | |
| 499 | } | |
| 500 | // Object to store freq info | |
| 501 | private class BaseFreq | |
| 502 | {
| |
| 503 | public BaseFreq(short freq, String FreqName) | |
| 504 | {
| |
| 505 | this.b_Freq = freq; | |
| 506 | this.b_FreqName = FreqName; | |
| 507 | } | |
| 508 | ||
| 509 | private String b_FreqName; | |
| 510 | public String getFreqName() { return b_FreqName; }
| |
| 511 | ||
| 512 | private short b_Freq; | |
| 513 | public short getFreq(){ return this.b_Freq;}
| |
| 514 | ||
| 515 | private List<BasePlayer> b_FreqPlayers = new ArrayList<BasePlayer>(); | |
| 516 | public List<BasePlayer> FreqPlayers() | |
| 517 | { return b_FreqPlayers; }
| |
| 518 | ||
| 519 | /*----------------------------------------------\ | |
| 520 | * STAT VARIABLES | |
| 521 | *---------------------------------------------*/ | |
| 522 | // ----------------------------------- FREQ Stats | |
| 523 | private long b_LongestHoldTime = 0; | |
| 524 | public long getLongestHoldTime() | |
| 525 | { return b_LongestHoldTime; }
| |
| 526 | ||
| 527 | private long b_TotalHoldTime = 0; | |
| 528 | public long getTotalHoldTime() | |
| 529 | { return b_TotalHoldTime; }
| |
| 530 | ||
| 531 | private int b_TotalKills = 0; | |
| 532 | private int b_TotalDeaths = 0; | |
| 533 | private int b_TotalTKs = 0; | |
| 534 | private int b_TotalDamage = 0; | |
| 535 | private int b_TotalDamageTaken = 0; | |
| 536 | private int b_TotalSelfDamage = 0; | |
| 537 | private int b_TotalRaids = 0; | |
| 538 | // ----------------------------- PLAYER STATS | |
| 539 | private String b_BestKiller = "~none~"; | |
| 540 | private int b_BestKillerCount = 0; | |
| 541 | ||
| 542 | private String b_Suicider = "~none~"; | |
| 543 | private int b_SuiciderCount = 0; | |
| 544 | ||
| 545 | private String b_Cannibal = "~none~"; | |
| 546 | private int b_CannibalCount = 0; | |
| 547 | ||
| 548 | private String b_BestPainDealer = "~none~"; | |
| 549 | private int b_BestPainDealerDamage = 0; | |
| 550 | ||
| 551 | private String b_PunchingBag = "~none~"; | |
| 552 | private int b_PunchingBagDamage = 0; | |
| 553 | ||
| 554 | private String b_Masochist = "~none~"; | |
| 555 | private int b_MasochistDamage = 0; | |
| 556 | ||
| 557 | private String b_BestRaider = "~none~"; | |
| 558 | private int b_BestRaidCount = 0; | |
| 559 | ||
| 560 | private String b_AtomicKiller = "~none~";// best mob destroyer | |
| 561 | private int b_AtomicKillerCount = 0; | |
| 562 | ||
| 563 | // most toys used??? | |
| 564 | // biggest lagger | |
| 565 | // most weapon fire | |
| 566 | // least weapons used | |
| 567 | // | |
| 568 | ||
| 569 | /*----------------------------------------------\ | |
| 570 | * TASKS | |
| 571 | *---------------------------------------------*/ | |
| 572 | // Load the stats to vars and load printout | |
| 573 | public void doEndGameLoad() | |
| 574 | {
| |
| 575 | for (BasePlayer b: b_FreqPlayers) | |
| 576 | {
| |
| 577 | // Load raid stats | |
| 578 | this.b_TotalRaids += b.getCapturedFlags(); | |
| 579 | if (b.getCapturedFlags() > b_BestRaidCount) | |
| 580 | {
| |
| 581 | this.b_BestRaider = b.getPlayerName(); | |
| 582 | this.b_BestRaidCount = b.getCapturedFlags(); | |
| 583 | } | |
| 584 | ||
| 585 | // Best multi killer | |
| 586 | if (b.getBestMulti() > b_AtomicKillerCount) | |
| 587 | {
| |
| 588 | this.b_AtomicKillerCount = b.getBestMulti(); | |
| 589 | this.b_AtomicKiller = b.getPlayerName(); | |
| 590 | } | |
| 591 | ||
| 592 | // Load kill stats | |
| 593 | this.b_TotalKills += b.getKills(); | |
| 594 | if (b.getKills() > b_BestKillerCount) | |
| 595 | {
| |
| 596 | this.b_BestKillerCount = b.getKills(); | |
| 597 | this.b_BestKiller = b.getPlayerName(); | |
| 598 | } | |
| 599 | this.b_TotalDeaths += b.getDeaths(); | |
| 600 | if (b.getDeaths() > b_SuiciderCount) | |
| 601 | {
| |
| 602 | this.b_SuiciderCount = b.getDeaths(); | |
| 603 | this.b_Suicider = b.getPlayerName(); | |
| 604 | } | |
| 605 | this.b_TotalTKs += b.getTKs(); | |
| 606 | if (b.getTKs() > b_CannibalCount) | |
| 607 | {
| |
| 608 | this.b_CannibalCount = b.getTKs(); | |
| 609 | this.b_Cannibal = b.getPlayerName(); | |
| 610 | } | |
| 611 | ||
| 612 | // Load most damage | |
| 613 | this.b_TotalDamage += b.getDamageDealt(); | |
| 614 | if (b.getDamageDealt() > b_BestPainDealerDamage) | |
| 615 | {
| |
| 616 | this.b_BestPainDealerDamage = b.getDamageDealt(); | |
| 617 | this.b_BestPainDealer = b.getPlayerName(); | |
| 618 | } | |
| 619 | this.b_TotalDamageTaken += b.getDamageTaken(); | |
| 620 | if (b.getDamageTaken() > b_PunchingBagDamage) | |
| 621 | {
| |
| 622 | this.b_PunchingBagDamage = b.getDamageTaken(); | |
| 623 | this.b_PunchingBag = b.getPlayerName(); | |
| 624 | } | |
| 625 | this.b_TotalSelfDamage += b.getDamageSelf(); | |
| 626 | if (b.getDamageSelf() > b_MasochistDamage) | |
| 627 | {
| |
| 628 | this.b_MasochistDamage = b.getDamageSelf(); | |
| 629 | this.b_Masochist = b.getPlayerName(); | |
| 630 | } | |
| 631 | loadGamePrintOut(); | |
| 632 | } | |
| 633 | } | |
| 634 | ||
| 635 | private String[] m_GamePrintOut = new String[7]; | |
| 636 | public String[] getGamePrintOut() {return m_GamePrintOut;}
| |
| 637 | ||
| 638 | private void loadGamePrintOut() | |
| 639 | {
| |
| 640 | m_GamePrintOut[0] = "+-----------------------------------------------------------------------------"; | |
| 641 | m_GamePrintOut[1] = "| Freq[ "+padL(Integer.toString(this.b_Freq),4,"0")+" :"+padR(this.b_FreqName,10," ")+" ] Total Time[ "+getTimeMs(b_TotalHoldTime)+" ] "; | |
| 642 | m_GamePrintOut[2] = "+---------------+--------------+------------+---------------------------------"; | |
| 643 | m_GamePrintOut[3] = "| Name | Category | Amount | Award "; | |
| 644 | m_GamePrintOut[4] = "+---------------+--------------+------------+---------------------------------"; | |
| 645 | m_GamePrintOut[5] = "| " +padR(b_BestKiller,14," ")+ "| Most Kills | " + padR(Integer.toString(b_BestKillerCount),11," ") + "| Freq AssASSin "; | |
| 646 | m_GamePrintOut[6] = "+---------------+--------------+------------+---------------------------------"; | |
| 647 | } | |
| 648 | ||
| 649 | // Grab player for freq list | |
| 650 | // If not on list add player | |
| 651 | public BasePlayer getPlayer(String PlayerName) | |
| 652 | {
| |
| 653 | // Find player on list | |
| 654 | for (BasePlayer b: b_FreqPlayers) | |
| 655 | if (b.getPlayerName() == PlayerName) return b; | |
| 656 | ||
| 657 | // Make new player if not found | |
| 658 | BasePlayer b = new BasePlayer(PlayerName); | |
| 659 | b_FreqPlayers.add(b); | |
| 660 | return b_FreqPlayers.get(b_FreqPlayers.indexOf(b)); | |
| 661 | } | |
| 662 | // Increment hold time and check to see if its longest | |
| 663 | public void addHoldTime(long time) | |
| 664 | {
| |
| 665 | b_TotalHoldTime+= time; | |
| 666 | ||
| 667 | if (time > b_LongestHoldTime ) b_LongestHoldTime = time; | |
| 668 | } | |
| 669 | } | |
| 670 | /*-------------------------------------------------------------------------------\ | |
| 671 | * | |
| 672 | * MISC FUNCTIONS | |
| 673 | * | |
| 674 | *-------------------------------------------------------------------------------*/ | |
| 675 | public void InitializeBaseFlagging() | |
| 676 | {
| |
| 677 | // Hide flag on start of module | |
| 678 | b.sendUnfilteredPublicMessage("*objset -1427,-1428,");
| |
| 679 | loadTimers(); | |
| 680 | } | |
| 681 | public void loadTimers() | |
| 682 | {
| |
| 683 | // Store all settings for Timer to start game | |
| 684 | m_StartGameSet = new BZTimer(1,35); | |
| 685 | m_StartGameSet.setInitialMessage("T20 BaseAttack starting in @time@ ! Hop in to join the fun.", 4);
| |
| 686 | m_StartGameSet.setEndMessage("GO GO GO - Defend T20!", 104);
| |
| 687 | m_StartGameSet.setNotification(60, "[@time@] until T20 Base Attack starts! Head over to O17 now!!", 0); | |
| 688 | m_StartGameSet.setNotification(30, "[@time@] until T20 Base Attack starts! Head over to O17 now!!", 0); | |
| 689 | m_StartGameSet.setNotification(5, "- 5 -", 26); | |
| 690 | m_StartGameSet.setNotification(4, "- 4 -", 26); | |
| 691 | m_StartGameSet.setNotification(3, "- 3 -", 26); | |
| 692 | m_StartGameSet.setNotification(2, "- 2 -", 26); | |
| 693 | m_StartGameSet.setNotification(1, "- 1 -", 26); | |
| 694 | // Settings for Game Timer | |
| 695 | m_GameTimerSet = new BZTimer(2,360); | |
| 696 | m_GameTimerSet.setInitialMessage("T20 BaseAttack - All your flag are belong to us... Defend the O-17 Flag! [Game Time = @time@] ", 0);
| |
| 697 | m_GameTimerSet.setNoEndMessage(); | |
| 698 | //m_GameTimerSet.setEndMessage(" ----- Score Printout here -----.", 104);
| |
| 699 | m_GameTimerSet.setNotification(180, "T20 Attack - @time@ remaining!", 0); | |
| 700 | m_GameTimerSet.setNotification(60, "T20 Attack - @time@ remaining!", 0); | |
| 701 | m_GameTimerSet.setNotification(30, "T20 Attack - @time@ remaining!", 0); | |
| 702 | m_GameTimerSet.setNotification(5, "- 5 -", 26); | |
| 703 | m_GameTimerSet.setNotification(4, "- 4 -", 26); | |
| 704 | m_GameTimerSet.setNotification(3, "- 3 -", 26); | |
| 705 | m_GameTimerSet.setNotification(2, "- 2 -", 26); | |
| 706 | m_GameTimerSet.setNotification(1, "- 1 -", 26); | |
| 707 | } | |
| 708 | ||
| 709 | // Simple collision check - seeing if player is in a given region | |
| 710 | private boolean InRegion( PlayerPosition p, short[] Region) | |
| 711 | { return InRegion(p.getXLocation(),p.getYLocation(),Region); }
| |
| 712 | private boolean InMapRoom(int PlayerID) | |
| 713 | {
| |
| 714 | return InRegion(b.getPlayer(PlayerID).getXLocation(),b.getPlayer(PlayerID).getYLocation(),m_MapRoom1) | |
| 715 | || InRegion(b.getPlayer(PlayerID).getXLocation(),b.getPlayer(PlayerID).getYLocation(),m_MapRoom2); | |
| 716 | } | |
| 717 | // Simple collision check - seeing if player is in a given region | |
| 718 | private boolean InRegion( short x, short y, short[] Region) | |
| 719 | {
| |
| 720 | return (x > Region[0] && x < Region[2] && | |
| 721 | y > Region[1] && y < Region[3]) ? true:false; | |
| 722 | } | |
| 723 | private String padR(String Str, int Amount, String Char) | |
| 724 | {
| |
| 725 | if (Str.length() < Amount) | |
| 726 | {
| |
| 727 | String NewStr = Str; | |
| 728 | int maxIndex = Amount - Str.length(); | |
| 729 | ||
| 730 | for (int i = 0; i < maxIndex;i++) | |
| 731 | {
| |
| 732 | NewStr += Char; | |
| 733 | } | |
| 734 | return NewStr; | |
| 735 | } | |
| 736 | return Str; | |
| 737 | } | |
| 738 | private String padL(String Str, int Amount, String Char) | |
| 739 | {
| |
| 740 | if (Str.length() < Amount) | |
| 741 | {
| |
| 742 | String NewStr = Str; | |
| 743 | int maxIndex = Amount - Str.length(); | |
| 744 | ||
| 745 | for (int i = 0; i < maxIndex;i++) | |
| 746 | {
| |
| 747 | NewStr = Char + NewStr; | |
| 748 | } | |
| 749 | return NewStr; | |
| 750 | } | |
| 751 | return Str; | |
| 752 | } | |
| 753 | // Format time to print | |
| 754 | public String getTimeMs(long elapsedTime) {
| |
| 755 | String format = String.format("%%0%dd", 2);
| |
| 756 | elapsedTime = elapsedTime / 1000; | |
| 757 | String seconds = String.format(format, elapsedTime % 60); | |
| 758 | String minutes = String.format(format, (elapsedTime % 3600) / 60); | |
| 759 | String hours = String.format(format, elapsedTime / 3600); | |
| 760 | long milli = elapsedTime - ((elapsedTime % 60) + ((elapsedTime % 3600) / 60) + (elapsedTime / 3600)); | |
| 761 | String time = hours + "h:" + minutes + "m:" + seconds +"s:" + milli + "ms"; | |
| 762 | return time; | |
| 763 | } | |
| 764 | } |