PsyOps

SpectatePlayers

Jan 14th, 2013
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.01 KB | None | 0 0
  1.    /// <summary>
  2.    /// Behavior to spectate players in the arena to refresh the
  3.    /// internal core player information.
  4.    /// </summary>
  5.    [Behavior ("SpectatePlayers", "false", "2.0", "udp/psyops", "Spectates players in arena")]
  6.    public class SpectatePlayers : BotEventListener
  7.    {
  8.       // Create a player information event to hold all players
  9.       List<UInt16> m_playerIdentifiers = new List<UInt16> ();
  10.       List<UInt16[]> m_regions = new List<UInt16[]>();
  11.  
  12.       UInt16[] xcor = new UInt16[] { 8000, 8192, 8384 };
  13.       UInt16[] ycor = new UInt16[] { 8000, 8192, 8384 };
  14.  
  15.       /// <summary>
  16.       /// SpectatePlayers constructor
  17.       /// </summary>
  18.       public SpectatePlayers ()
  19.       {
  20.          // Register the timed event to spectate the next player
  21.          RegisterTimedEvent ("Spectate", 60, SpectateNextPlayer);
  22.       }
  23.  
  24.       /// <summary>
  25.       /// Handle the timer tick to check if it is time to get
  26.       /// the next player in the player information.
  27.       /// </summary>
  28.       public void SpectateNextPlayer ()
  29.       {
  30.          // If the player list has members
  31.           if ((m_playerIdentifiers.Count > 0) && (m_playerIdentifiers.Count < 10))
  32.          {
  33.             // Create the player spectate event
  34.             SpectatePlayerEvent spectateEvent = new SpectatePlayerEvent ();
  35.  
  36.             // Set the player identifier for the next player
  37.             spectateEvent.PlayerId = m_playerIdentifiers[0];
  38.  
  39.             // Remove the player from the player list
  40.             m_playerIdentifiers.RemoveAt (0);
  41.  
  42.             // Send the player spectate event
  43.             SendGameEvent (spectateEvent);
  44.          }
  45.               // if members are more then 9 we will use regions
  46.           else if (m_playerIdentifiers.Count >= 10)
  47.           {
  48.               // Create player position event
  49.               PlayerPositionEvent p = new PlayerPositionEvent();
  50.              
  51.               // Set the next player position
  52.               p.MapPositionX = m_regions[0][0];
  53.               p.MapPositionY = m_regions[0][1];
  54.  
  55.               // remove position from the list
  56.               m_regions.RemoveAt(0);
  57.  
  58.               // Send player position event
  59.               SendGameEvent(p);
  60.           }
  61.           if (m_regions.Count == 0)
  62.           {
  63.               // Send the player info request event
  64.               SendGameEvent(new PlayerInfoEvent());
  65.           }
  66.  
  67.          // If we are at the end of the player list
  68.          if (m_playerIdentifiers.Count == 0)
  69.          {
  70.             // Send the player info request event
  71.             SendGameEvent (new PlayerInfoEvent ());
  72.          }
  73.       }
  74.  
  75.       /// <summary>
  76.       /// Handle the player information received from the core to
  77.       /// double check against the current counters.
  78.       /// </summary>
  79.       /// <param name="sender">sending object</param>
  80.       /// <param name="e">Player information event</param>
  81.       public void HandlePlayerInfo (object sender, PlayerInfoEvent e)
  82.       {
  83.          // Check if we are refreshing the player list
  84.          if (m_playerIdentifiers.Count == 0)
  85.          {
  86.             // Search the player list for active players
  87.             foreach (PlayerInfo p in e.PlayerList)
  88.             {
  89.                // If the player is not a spectator
  90.                if (p.Ship != ShipTypes.Spectator)
  91.                {
  92.                   // Add the player identifier to the list
  93.                   m_playerIdentifiers.Add (p.PlayerId);
  94.                }
  95.             }
  96.          }
  97.       }
  98.       public void repop_m_regions()
  99.       {
  100.           // refreshes region list
  101.           if (m_regions.Count == 0)
  102.           {
  103.               for (int i = 0; i < 3; i++)
  104.               {
  105.                   for (int j = 0; j < 3; j++)
  106.                   {
  107.                       m_regions.Add(new UInt16[] { xcor[i], ycor[j] });
  108.                   }
  109.               }
  110.           }
  111.       }
  112.       /// <summary>
  113.       /// Dispose method implementation
  114.       /// </summary>
  115.       public override void Dispose ()
  116.       {
  117.  
  118.       }
  119.    }
Advertisement
Add Comment
Please, Sign In to add comment