PsyOps

BaseFlagging.java

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