Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package twcore.bots.battlebot.PublicOps;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
- import twcore.core.BotAction;
- import twcore.core.SubspaceBot;
- import twcore.core.events.Message;
- import twcore.core.events.PlayerPosition;
- /*----------------------------------------------------------------------------------\
- * BZ Public Operations Class:
- * Spectating - In 8025 and speccing
- * Public - Inside Main area and playing normal pub
- * Battle - In one of the outside boxes setup for VS battle or Event games
- *----------------------------------------------------------------------------------*/
- public class PublicOps {
- public PublicOps(SubspaceBot Bot)
- {
- this.bot = Bot;
- this.b = bot.ba;
- }
- /*----------------------------------------------\
- * Needed Variables and Classes
- *---------------------------------------------*/
- // Passing over bot functions to class
- SubspaceBot bot;
- BotAction b;
- // Random number class
- Random ran = new Random();
- // List of Public Players
- private List<PublicPlayer> PlayerList = new ArrayList<PublicPlayer>();
- /*----------------------------------------------\
- * MAIN EVENTS FOR PUBLIC
- *---------------------------------------------*/
- // BZ Public command handler
- public boolean isPublicCommand(Message m)
- {
- return checkIfCommand(m);
- }
- // Player just joined into public. - He is in start box from spec
- public void playerJoinedPublic(PlayerPosition p)
- {
- // Player Holder
- PublicPlayer pp;
- // If PLayer is not found in database - create a new player
- if (DB_playerIsNew())
- {
- // Create player
- pp = new PublicPlayer(bot.m_botAction.getPlayerName(p.getPlayerID()));
- // We are going to keep track of player current ship and old ship
- // Dont know if i need this
- pp.updateShip((byte)0);
- pp.updateShip(bot.m_botAction.getPlayer(p.getPlayerID()).getShipType());
- // Update player info in the db so if nothing else and bot lags out - he still has account
- DB_updatePlayerInfo(pp);
- }
- // Load info from db - this code wont get reached until i write the db code
- else
- { pp = DB_getPlayerInfo(); }
- // add player to MasterList
- this.PlayerList.add(pp);
- }
- // - Player Position Event
- // We set this as a bool so we let our main class know if we handled the event here
- // This should cut down on PlayerPosition Checks - if handled, main class will ignore
- public boolean eventHandled(PlayerPosition p)
- {
- // Grab player info from our cutom Player Class
- PublicPlayer pp = getPlayer(bot.m_botAction.getPlayerName( p.getPlayerID()));
- // we shouldnt be getting null here
- // If we do maybe bot lagged out - will try and update player here - later
- if (pp == null) return false;
- // Checking the player warp timestamp
- if (pp.AllowedToWarp())
- {
- // ---- Different Region checks --------- //
- // Start Box Region
- if (InRegion(p,new short[]{ 520 * 16, 510 * 16, 524 * 16, 514 * 16 }))
- {
- if (p.getBounty() == 0 && bot.m_botAction.getPlayer(p.getPlayerID()).getShipType() == 1)
- {
- setShipPlayer(pp);
- }
- bot.m_botAction.warpTo(p.getPlayerID(), ran.nextInt(1023), ran.nextInt(439) + 328);
- }
- // Left Portal Region
- else if (InRegion(p,new short[]{ 17 * 16, 686 * 16, 33 * 16, 702 * 16 }))
- { bot.m_botAction.warpTo(p.getPlayerID(), 934, 508); }
- // Right Portal Region
- else if (InRegion(p,new short[]{ 940 * 16, 500 * 16, 956 * 16, 516 * 16 }))
- { bot.m_botAction.warpTo(p.getPlayerID(), 25, 708); }
- }
- // Let main class know we handled it.
- return true;
- }
- /*----------------------------------------------\
- * PUBLIC GAME TIMER
- *---------------------------------------------*/
- public void pubGameTimer()
- {
- }
- /*----------------------------------------------\
- * Placeholder for DatabaseInfo
- *---------------------------------------------*/
- // Check Database and see if player is registered
- // Need to decide what index to use to retrieve player info
- // PlayerName / SS ID / An alias ID (BZ ID)?
- boolean DB_playerIsNew()
- {
- return true;
- }
- // Return player info with stored data
- PublicPlayer DB_getPlayerInfo()
- {
- return null;
- }
- // Update database with new Player Info
- public void DB_updatePlayerInfo(PublicPlayer p)
- {
- }
- /*----------------------------------------------\
- * CHAT COMMAND CHECKER
- *---------------------------------------------*/
- private boolean checkIfCommand(Message m)
- {
- boolean isCommand = false;
- // Grab player from list if he's in pub
- PublicPlayer p = getPlayer(b.getPlayerName(m.getPlayerID()));
- if (m.getMessageType() == Message.PUBLIC_MESSAGE || m.getMessageType() == Message.PRIVATE_MESSAGE)
- {
- if (m.getMessage().startsWith("!sc"))
- {
- if (p == null)
- {
- b.sendPrivateMessage(m.getPlayerID(), "You must be in Pub to use this command.");
- return true;
- }
- if(m.getMessage().contains(" "))
- {
- switch(isNum(m.getMessage().trim().split(" ",-1)[1]))
- {
- case 1:
- p.setCustomShip1(CustomShipType.Warbird);
- b.sendPrivateMessage(m.getPlayerID(), "Ship 1 is now "+p.Slot1()+".");
- return true;
- case 2:
- p.setCustomShip1(CustomShipType.Javelin);
- b.sendPrivateMessage(m.getPlayerID(), "Ship 1 is now "+p.Slot1()+".");
- return true;
- case 3:
- p.setCustomShip1(CustomShipType.Spider);
- b.sendPrivateMessage(m.getPlayerID(), "Ship 1 is now "+p.Slot1()+".");
- return true;
- case 4:
- p.setCustomShip1(CustomShipType.Leviathan);
- b.sendPrivateMessage(m.getPlayerID(), "Ship 1 is now "+p.Slot1()+".");
- return true;
- }
- }
- b.sendPrivateMessage(m.getPlayerID(), "The correct format for this command is: !sc (desired ship #)");
- b.sendPrivateMessage(m.getPlayerID(), "EXAMPLE: !sc 1");
- isCommand = true;
- }
- }
- return isCommand;
- }
- /*----------------------------------------------\
- * MISC FUNTIONS AND UTILITIES
- *---------------------------------------------*/
- // Spams a list of commands to set a player into a custom ship type
- // All the commands are inside the enum CustomShipTypes
- public void setShipPlayer(PublicPlayer pp)
- {
- for(String s: pp.Slot1().commands())
- bot.ba.sendUnfilteredPrivateMessage(pp.PlayerName(), s);
- }
- // Retrieve Public Player from our MasterList
- PublicPlayer getPlayer(String PlayerName)
- {
- for(PublicPlayer pp:PlayerList)
- {
- if(pp.PlayerName() == PlayerName)
- return pp;
- }
- return null;
- }
- // Simple collision check - seeing if player is in a given region
- boolean InRegion( PlayerPosition p, short[] Region)
- {
- if (p.getXLocation() > Region[0] &&
- p.getXLocation() < Region[2] &&
- p.getYLocation() > Region[1] &&
- p.getYLocation() < Region[3])
- {
- return true;
- }
- return false;
- }
- int isNum(String str)
- {
- try {
- int x = Integer.parseInt(str);
- return x;
- }
- catch (Exception x){}
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement