Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Behavior to spectate players in the arena to refresh the
- /// internal core player information.
- /// </summary>
- [Behavior ("SpectatePlayers", "false", "2.0", "udp/psyops", "Spectates players in arena")]
- public class SpectatePlayers : BotEventListener
- {
- // Create a player information event to hold all players
- List<UInt16> m_playerIdentifiers = new List<UInt16> ();
- List<UInt16[]> m_regions = new List<UInt16[]>();
- UInt16[] xcor = new UInt16[] { 8000, 8192, 8384 };
- UInt16[] ycor = new UInt16[] { 8000, 8192, 8384 };
- /// <summary>
- /// SpectatePlayers constructor
- /// </summary>
- public SpectatePlayers ()
- {
- // Register the timed event to spectate the next player
- RegisterTimedEvent ("Spectate", 60, SpectateNextPlayer);
- }
- /// <summary>
- /// Handle the timer tick to check if it is time to get
- /// the next player in the player information.
- /// </summary>
- public void SpectateNextPlayer ()
- {
- // If the player list has members
- if ((m_playerIdentifiers.Count > 0) && (m_playerIdentifiers.Count < 10))
- {
- // Create the player spectate event
- SpectatePlayerEvent spectateEvent = new SpectatePlayerEvent ();
- // Set the player identifier for the next player
- spectateEvent.PlayerId = m_playerIdentifiers[0];
- // Remove the player from the player list
- m_playerIdentifiers.RemoveAt (0);
- // Send the player spectate event
- SendGameEvent (spectateEvent);
- }
- // if members are more then 9 we will use regions
- else if (m_playerIdentifiers.Count >= 10)
- {
- // Create player position event
- PlayerPositionEvent p = new PlayerPositionEvent();
- // Set the next player position
- p.MapPositionX = m_regions[0][0];
- p.MapPositionY = m_regions[0][1];
- // remove position from the list
- m_regions.RemoveAt(0);
- // Send player position event
- SendGameEvent(p);
- }
- if (m_regions.Count == 0)
- {
- // Send the player info request event
- SendGameEvent(new PlayerInfoEvent());
- }
- // If we are at the end of the player list
- if (m_playerIdentifiers.Count == 0)
- {
- // Send the player info request event
- SendGameEvent (new PlayerInfoEvent ());
- }
- }
- /// <summary>
- /// Handle the player information received from the core to
- /// double check against the current counters.
- /// </summary>
- /// <param name="sender">sending object</param>
- /// <param name="e">Player information event</param>
- public void HandlePlayerInfo (object sender, PlayerInfoEvent e)
- {
- // Check if we are refreshing the player list
- if (m_playerIdentifiers.Count == 0)
- {
- // Search the player list for active players
- foreach (PlayerInfo p in e.PlayerList)
- {
- // If the player is not a spectator
- if (p.Ship != ShipTypes.Spectator)
- {
- // Add the player identifier to the list
- m_playerIdentifiers.Add (p.PlayerId);
- }
- }
- }
- }
- public void repop_m_regions()
- {
- // refreshes region list
- if (m_regions.Count == 0)
- {
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- m_regions.Add(new UInt16[] { xcor[i], ycor[j] });
- }
- }
- }
- }
- /// <summary>
- /// Dispose method implementation
- /// </summary>
- public override void Dispose ()
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment