Advertisement
PsyOps

PublicOps

May 12th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.18 KB | None | 0 0
  1. package twcore.bots.battlebot.PublicOps;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Random;
  6.  
  7. import twcore.core.BotAction;
  8. import twcore.core.SubspaceBot;
  9. import twcore.core.events.Message;
  10. import twcore.core.events.PlayerPosition;
  11. /*----------------------------------------------------------------------------------\
  12.  * BZ Public Operations Class:
  13.  * Spectating  - In 8025 and speccing
  14.  * Public      - Inside Main area and playing normal pub
  15.  * Battle      - In one of the outside boxes setup for VS battle or Event games
  16.  *----------------------------------------------------------------------------------*/
  17. public class PublicOps {
  18.    
  19.     public PublicOps(SubspaceBot Bot)
  20.     {  
  21.         this.bot = Bot;
  22.         this.b = bot.ba;
  23.     }
  24.    
  25.     /*----------------------------------------------\
  26.      *         Needed Variables and Classes
  27.      *---------------------------------------------*/
  28.     // Passing over bot functions to class
  29.     SubspaceBot bot;
  30.     BotAction b;
  31.     // Random number class
  32.     Random ran = new Random();
  33.     // List of Public Players
  34.     private List<PublicPlayer> PlayerList = new ArrayList<PublicPlayer>();
  35.    
  36.     /*----------------------------------------------\
  37.      *         MAIN EVENTS FOR PUBLIC
  38.      *---------------------------------------------*/
  39.     // BZ Public command handler
  40.     public boolean isPublicCommand(Message m)
  41.     {
  42.         return checkIfCommand(m);
  43.     }
  44.     // Player just joined into public. - He is in start box from spec
  45.     public void playerJoinedPublic(PlayerPosition p)
  46.     {
  47.         // Player Holder
  48.         PublicPlayer pp;
  49.        
  50.         // If PLayer is not found in database - create a new player
  51.         if (DB_playerIsNew())
  52.         {
  53.             // Create player
  54.             pp = new PublicPlayer(bot.m_botAction.getPlayerName(p.getPlayerID()));
  55.             // We are going to keep track of player current ship and old ship
  56.             // Dont know if i need this
  57.             pp.updateShip((byte)0);
  58.             pp.updateShip(bot.m_botAction.getPlayer(p.getPlayerID()).getShipType());
  59.            
  60.             // Update player info in the db so if nothing else and bot lags out - he still has account
  61.             DB_updatePlayerInfo(pp);
  62.         }
  63.         // Load info from db - this code wont get reached until i write the db code
  64.         else
  65.         {   pp = DB_getPlayerInfo();    }
  66.  
  67.         // add player to MasterList
  68.         this.PlayerList.add(pp);
  69.     }
  70.    
  71.     // - Player Position Event
  72.     // We set this as a bool so we let our main class know if we handled the event here
  73.     // This should cut down on PlayerPosition Checks - if handled, main class will ignore
  74.     public boolean eventHandled(PlayerPosition p)
  75.     {
  76.         // Grab player info from our cutom Player Class
  77.         PublicPlayer pp = getPlayer(bot.m_botAction.getPlayerName( p.getPlayerID()));
  78.        
  79.         // we shouldnt be getting null here
  80.         // If we do maybe bot lagged out - will try and update player here - later
  81.         if (pp == null) return false;
  82.        
  83.         // Checking the player warp timestamp
  84.         if (pp.AllowedToWarp())
  85.         {
  86.             // ----  Different Region checks --------- //
  87.             // Start Box Region
  88.             if (InRegion(p,new short[]{ 520 * 16, 510 * 16, 524 * 16, 514 * 16 }))
  89.             {
  90.                 if (p.getBounty() == 0 && bot.m_botAction.getPlayer(p.getPlayerID()).getShipType() == 1)
  91.                 {
  92.                     setShipPlayer(pp);
  93.                 }
  94.                
  95.                 bot.m_botAction.warpTo(p.getPlayerID(), ran.nextInt(1023), ran.nextInt(439) + 328);
  96.             }
  97.             // Left Portal Region
  98.             else if (InRegion(p,new short[]{ 17 * 16, 686 * 16, 33 * 16, 702 * 16 }))
  99.             {   bot.m_botAction.warpTo(p.getPlayerID(), 934, 508);  }
  100.             // Right Portal Region
  101.             else if (InRegion(p,new short[]{ 940 * 16, 500 * 16, 956 * 16, 516 * 16 }))
  102.             {   bot.m_botAction.warpTo(p.getPlayerID(), 25, 708);   }
  103.         }
  104.         // Let main class know we handled it.
  105.         return true;
  106.     }
  107.    
  108.     /*----------------------------------------------\
  109.      *            PUBLIC GAME TIMER
  110.      *---------------------------------------------*/
  111.     public void pubGameTimer()
  112.     {
  113.        
  114.     }
  115.    
  116.     /*----------------------------------------------\
  117.      *         Placeholder for DatabaseInfo
  118.      *---------------------------------------------*/
  119.     // Check Database and see if player is registered
  120.     // Need to decide what index to use to retrieve player info
  121.     // PlayerName / SS ID / An alias ID (BZ ID)?
  122.     boolean DB_playerIsNew()
  123.     {
  124.         return true;
  125.     }
  126.     // Return player info with stored data
  127.     PublicPlayer DB_getPlayerInfo()
  128.     {
  129.         return null;
  130.     }
  131.     // Update database with new Player Info
  132.     public void DB_updatePlayerInfo(PublicPlayer p)
  133.     {
  134.        
  135.     }
  136.    
  137.     /*----------------------------------------------\
  138.      *          CHAT COMMAND CHECKER
  139.      *---------------------------------------------*/
  140.     private boolean checkIfCommand(Message m)
  141.     {
  142.         boolean isCommand = false;
  143.        
  144.         // Grab player from list if he's in pub
  145.         PublicPlayer p = getPlayer(b.getPlayerName(m.getPlayerID()));
  146.        
  147.         if (m.getMessageType() == Message.PUBLIC_MESSAGE || m.getMessageType() == Message.PRIVATE_MESSAGE)
  148.         {
  149.             if (m.getMessage().startsWith("!sc"))
  150.             {
  151.                 if (p == null)
  152.                 {
  153.                     b.sendPrivateMessage(m.getPlayerID(), "You must be in Pub to use this command.");
  154.                     return true;
  155.                 }
  156.                
  157.                 if(m.getMessage().contains(" "))
  158.                 {
  159.                     switch(isNum(m.getMessage().trim().split(" ",-1)[1]))
  160.                     {
  161.                         case 1:
  162.                             p.setCustomShip1(CustomShipType.Warbird);
  163.                             b.sendPrivateMessage(m.getPlayerID(), "Ship 1 is now "+p.Slot1()+".");
  164.                             return true;
  165.                         case 2:
  166.                             p.setCustomShip1(CustomShipType.Javelin);
  167.                             b.sendPrivateMessage(m.getPlayerID(), "Ship 1 is now "+p.Slot1()+".");
  168.                             return true;
  169.                         case 3:
  170.                             p.setCustomShip1(CustomShipType.Spider);
  171.                             b.sendPrivateMessage(m.getPlayerID(), "Ship 1 is now "+p.Slot1()+".");
  172.                             return true;
  173.                         case 4:
  174.                             p.setCustomShip1(CustomShipType.Leviathan);
  175.                             b.sendPrivateMessage(m.getPlayerID(), "Ship 1 is now "+p.Slot1()+".");
  176.                             return true;
  177.                     }
  178.                 }
  179.                 b.sendPrivateMessage(m.getPlayerID(), "The correct format for this command is: !sc (desired ship #)");
  180.                 b.sendPrivateMessage(m.getPlayerID(), "EXAMPLE:    !sc 1");
  181.                 isCommand = true;
  182.             }
  183.         }
  184.         return isCommand;
  185.     }
  186.    
  187.     /*----------------------------------------------\
  188.      *         MISC FUNTIONS AND UTILITIES
  189.      *---------------------------------------------*/
  190.     // Spams a list of commands to set a player into a custom ship type
  191.     // All the commands are inside the enum CustomShipTypes
  192.     public void setShipPlayer(PublicPlayer pp)
  193.     {
  194.         for(String s: pp.Slot1().commands())
  195.             bot.ba.sendUnfilteredPrivateMessage(pp.PlayerName(), s);
  196.     }
  197.    
  198.     // Retrieve Public Player from our MasterList
  199.     PublicPlayer getPlayer(String PlayerName)
  200.     {
  201.         for(PublicPlayer pp:PlayerList)
  202.         {
  203.             if(pp.PlayerName() == PlayerName)
  204.                 return pp;
  205.         }
  206.         return null;
  207.     }
  208.    
  209.     // Simple collision check - seeing if player is in a given region
  210.     boolean InRegion( PlayerPosition p, short[] Region)
  211.     {
  212.         if (p.getXLocation() > Region[0] &&
  213.                 p.getXLocation() < Region[2] &&
  214.                 p.getYLocation() > Region[1] &&
  215.                 p.getYLocation() < Region[3])
  216.         {
  217.             return true;
  218.         }
  219.         return false;
  220.     }
  221.    
  222.     int isNum(String str)
  223.     {
  224.         try {  
  225.                 int x = Integer.parseInt(str); 
  226.                 return x;
  227.             }
  228.         catch (Exception x){}
  229.        
  230.         return -1;
  231.     }
  232. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement