Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package twcore.bots.battlebot.PublicOps;
- import java.util.Iterator;
- import twcore.bots.battlebot.ChatBuffer;
- import twcore.bots.battlebot.DoorMan;
- import twcore.core.BotAction;
- import twcore.core.events.Message;
- import twcore.core.events.PlayerPosition;
- import twcore.core.game.Player;
- /*----------------------------------------------------------------------------------\
- * BZ Public Flag Ops Class:
- * This will keep track of any flag event for public.
- * For now there will be 2 types of flag games
- *
- * STQ Flag game:
- * One flag will be available to carry. We will give a player a multiplier(or increase) for points
- * if flag is carried. This will make the flag an item that is sought after.
- *
- * BaseFlag:
- * I will have one flag base on the lower map. The entire game will be bot controlled.
- * Flag is a monitored hotspot for the bot and will use 2 lvz: de/activated
- *----------------------------------------------------------------------------------*/
- public class PublicFlagOps {
- BotAction b;
- ChatBuffer bzChat;
- DoorMan bob;
- public PublicFlagOps(BotAction b, ChatBuffer c, DoorMan d)
- {
- this.b = b;
- this.bzChat = c;
- this.bob = d;
- }
- /*-------------------------------------------------------------------------------\
- * SHARED METHODS
- *-------------------------------------------------------------------------------*/
- // ----------------------------------- Chat commands
- public void chatCommands( Message m)
- {
- // Toggle single flag mode
- if (m.getMessage().startsWith("!flag_stq"))
- {
- toggleSTQ();
- return;
- }
- // Toggle base flag mode
- if (m.getMessage().startsWith("!flag_base"))
- {
- toggleBase();
- return;
- }
- }
- // Simple collision check - seeing if player is in a given region
- private boolean InRegion( PlayerPosition p, short[] Region)
- {
- return (p.getXLocation() > Region[0] &&
- p.getXLocation() < Region[2] &&
- p.getYLocation() > Region[1] &&
- p.getYLocation() < Region[3]) ? true:false;
- }
- public void flagTimer()
- {
- baseGameFlagTimer();
- updateBaseGame();
- }
- /*-------------------------------------------------------------------------------\
- * STQ
- *-------------------------------------------------------------------------------*/
- // if game is on
- private boolean m_STQ_On = false;
- // Current Flag Owner
- private String m_FlagOwner = "";
- public boolean STQ_On() { return m_STQ_On; }
- // Toggles single flag mode on and off
- // Configures arena for 1 or 0 flags, then resets
- private void toggleSTQ()
- {
- m_STQ_On = !m_STQ_On;
- bzChat.sendChatMsg(1, "Single Flag Mode is now set to : [ " + m_STQ_On + " ]");
- int setting = m_STQ_On ? 1:0;
- bzChat.sendChatMsg(0, "?set Flag:MaxFlags=" + setting);
- bzChat.sendChatMsg(0, "*flagreset");
- }
- /*-------------------------------------------------------------------------------\
- * BASE
- *-------------------------------------------------------------------------------*/
- // if game is on
- private boolean m_Base_On = false;
- public boolean Base_On() { return m_Base_On; }
- // Freq that owns Base
- private int m_Base_Freq = 8025;
- // Lvz for flag on/off
- private int m_Base_LVZ_Off = 1427;
- private int m_Base_LVZ_On = 1428;
- // Door used to close off flag room
- private byte m_baseDoor = 5;
- // Base Game Settings
- private boolean m_BGameOn = false;
- private long Delay_BGameOn = 180; //seconds
- public void updateBaseGame()
- {
- if (!m_BGameOn) return;
- }
- private boolean m_FlagTimerON = false;
- private long TS_FlagTimer;
- private int Delay_FlagTimer;//seconds
- private boolean[] m_FlagTimerNotificationsChecks;
- private int[] m_FlagTimerNotificationsTimes;
- private String[] m_FlagTimerNotifications;
- private int[] m_FlagTimerSoundCodes;
- private boolean m_InitialAnnounceSent = false;
- private String m_InitialAnnounce;
- private int m_InitialAnnounceSoundCode;
- private String m_TimerEndAnnounce;
- private int m_TimerEndSoundCode;
- private int m_TimerTask;
- private void baseGameFlagTimer()
- {
- if (!m_FlagTimerON) return;
- if (!m_InitialAnnounceSent)
- {
- m_InitialAnnounceSent = true;
- b.sendArenaMessage(m_InitialAnnounce,m_InitialAnnounceSoundCode);
- return;
- }
- long elapsed = System.currentTimeMillis() - TS_FlagTimer;
- for (int i = 0; i < m_FlagTimerNotificationsChecks.length; i+=1)
- {
- if (!m_FlagTimerNotificationsChecks[i] && (Delay_FlagTimer * 1000) - elapsed <= (m_FlagTimerNotificationsTimes[i]*1000))
- {
- int secs = m_FlagTimerNotificationsTimes[i];
- m_FlagTimerNotificationsChecks[i] = true;
- b.sendArenaMessage(m_FlagTimerNotifications[i],m_FlagTimerSoundCodes[i]);
- }
- }
- if (elapsed > (Delay_FlagTimer *1000))
- {
- m_FlagTimerON = false;
- TS_FlagTimer = System.currentTimeMillis();
- m_InitialAnnounceSent = false;
- b.sendArenaMessage(m_TimerEndAnnounce,m_TimerEndSoundCode);
- switch(m_TimerTask)
- {
- case 0:
- m_BGameOn = true;
- BaseGameTimer();
- break;
- }
- }
- }
- public void BaseStartTimer()
- {
- TS_FlagTimer = System.currentTimeMillis();
- Delay_FlagTimer = 35;//seconds
- m_FlagTimerNotificationsChecks = new boolean[]{ false, false, false, false, false, false };
- m_FlagTimerNotificationsTimes = new int[]{ 30, 5, 4, 3, 2, 1 };
- m_FlagTimerNotifications = new String[]{"30 Seconds for T20 Base Attack, head over to p17 now!!"," - 5 - "," - 4 - "," - 3 - "," - 2 - "," - 1 - "};
- m_FlagTimerSoundCodes = new int[]{ 0, 26, 26, 26, 26, 26};
- m_InitialAnnounce = "T20 BaseAttack starting in 0m 35s ! Hop in to join the fun.";
- m_InitialAnnounceSoundCode = 4;
- m_TimerEndAnnounce = "GO GO GO - Defend T20!.";
- m_TimerEndSoundCode = 104;
- m_TimerTask = 0;
- m_FlagTimerON = true;
- }
- public void BaseGameTimer()
- {
- TS_FlagTimer = System.currentTimeMillis();
- Delay_FlagTimer = 60;//seconds
- m_FlagTimerNotificationsChecks = new boolean[]{ false, false, false, false, false, false };
- m_FlagTimerNotificationsTimes = new int[]{ 30, 5, 4, 3, 2, 1 };
- m_FlagTimerNotifications = new String[]{"30 Seconds left hurraaa!"," - 5 - "," - 4 - "," - 3 - "," - 2 - "," - 1 - "};
- m_FlagTimerSoundCodes = new int[]{ 0, 26, 26, 26, 26, 26};
- m_InitialAnnounce = "[1 minute Game] T20 BaseAttack - capture the p17 flag and defend all your base..";
- m_InitialAnnounceSoundCode = 0;
- m_TimerEndAnnounce = " ----- Score Printout here -----.";
- m_TimerEndSoundCode = 104;
- m_TimerTask = 1;
- m_FlagTimerON = true;
- }
- public void playerPositionHandled(PlayerPosition p)
- {
- // No need to track players unless game has started
- if (!m_BGameOn) return;
- // Flag Room Coords
- if (!InRegion(p,new short[]{ 225 * 16, 778 * 16, 784 * 16, 845 * 16})) return;
- if (InRegion(p, new short[] { 12336, 13328, 12496, 13488 }))
- {
- short freq = b.getPlayer(p.getPlayerID()).getFrequency();
- if (freq != m_Base_Freq)
- {
- m_Base_Freq = freq;
- bzChat.debugMessage("Freq [ "+freq+" ] Has just taken the flag.");
- flagTakenToggle(freq);
- return;
- }
- }
- }
- private void flagTakenToggle(short Freq)
- {
- // Toggle lvz off for all players
- b.sendUnfilteredPublicMessage("*objset -" + m_Base_LVZ_On + ", +" + m_Base_LVZ_Off + ",");
- Iterator<Player> i = b.getPlayingPlayerIterator();
- while( i.hasNext() ){
- Player p = i.next();
- if( p.getFrequency() == Freq){
- // Toggle lvz on for freq
- b.sendUnfilteredPrivateMessage( p.getPlayerID(), "*objset +" + m_Base_LVZ_On + ", -" + m_Base_LVZ_Off + ",");
- }
- }
- }
- private void toggleBase()
- {
- m_Base_On = !m_Base_On;
- m_Base_Freq = 8025;
- bzChat.sendChatMsg(1, "Base Flag Mode is now set to : [ " + m_Base_On + " ]");
- bob.ChangeDoorStatus(m_baseDoor, !m_Base_On);
- String i = m_Base_On ? "+":"-";
- b.sendUnfilteredPublicMessage("*objset "+i+"1427,-1428,");
- if (m_Base_On)
- {
- //m_FlagTimerON = true;
- BaseStartTimer();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement