Advertisement
PsyOps

EventTest.cs

Dec 18th, 2015
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 13.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. // Add the following namespaces
  6. using AlphaCore;
  7. using AlphaCore.Events;
  8.  
  9. namespace EventTest
  10. {
  11.     // Add the attribute and the base class
  12.     [Behavior("EventsTest", "false", "0.52", "lightbender", "Tests all the event handlers")]
  13.    
  14.     [CommandHelp("!flags", "Stops the FlagClaimed event from outputting", ModLevels.Mod)]
  15.     [CommandHelp("!prize", "Toggles the displaying of the PrizeCollectedEvent", ModLevels.Mod)]
  16.     [CommandHelp("!position", "Toggles the displaying of the PlayerPositionEvent", ModLevels.Mod)]
  17.     [CommandHelp("!timer", "Kills the periodic timer event", ModLevels.Mod)]
  18.     [CommandHelp("!damage", "<player> Toggles the displaying of WatchDamageEvent for that player",  ModLevels.Mod)]
  19.     [CommandHelp("!spec", "<player>  Gets the bot to spec a player, so !display will work", ModLevels.Mod)]
  20.     [CommandHelp("!display", "<player>  Displays all the information of a player who has been !specced", ModLevels.Mod)]
  21.     [CommandHelp("!moreinfo", "<player>  Displays PlayerPosition and WeaponInfo of a previously !specced player", ModLevels.Mod)]
  22.    
  23.        
  24.     public class EventTest : BotEventListener
  25.     {
  26.         bool displayFlags = false;  //prevent some level of spam...
  27.         bool displayPrize = false;  //same as above
  28.         bool displayPosition = true;
  29.         bool watchDamage = true;
  30.  
  31.         // ChatEvent
  32.         public EventTest()
  33.         {
  34.             RegisterCommand("!flags", ToggleFlagEvent);
  35.             RegisterCommand("!prize", TogglePrizeEvent);
  36.             RegisterCommand("!position", TogglePositionEvent);
  37.            
  38.             RegisterCommand("!damage", ToggleWatchDamage);
  39.             RegisterCommand("!spec", HandleSpecRequest);
  40.             RegisterCommand("!display", HandleInfoRequest);
  41.            
  42.             RegisterTimedEvent("Timer", 10000, SendPeriodicMessage);
  43.             RegisterCommand("!timer", DisableTimer);
  44.         }
  45.  
  46.         // Toggle whether the FlagClaimedEvent is displayed
  47.         public void ToggleFlagEvent(ChatEvent e)
  48.         {
  49.             if (e.ModLevel >= ModLevels.Mod)
  50.             {
  51.                 if (displayFlags == true)
  52.                     displayFlags = false;
  53.                 if (displayFlags == false)
  54.                     displayFlags = true;
  55.  
  56.                 e.Message = "Display on FlagClaimedEvent is now set to " + displayFlags;
  57.                 e.ChatType = ChatTypes.Arena;
  58.                 SendGameEvent(e);
  59.             }
  60.         }
  61.  
  62.         // Toggle whether the PrizeCollectedEvent is displayed
  63.         public void TogglePrizeEvent(ChatEvent e)
  64.         {
  65.             if (e.ModLevel >= ModLevels.Mod)
  66.             {
  67.                 if (displayPrize == true)
  68.                     displayPrize = false;
  69.                 else if (displayPrize == false)
  70.                     displayPrize = true;
  71.                
  72.                 e.Message = "Display on PrizeCollectedEvent is now set to " + displayPrize;
  73.                 e.ChatType = ChatTypes.Arena;
  74.                 SendGameEvent(e);
  75.             }
  76.         }
  77.  
  78.         // Toggle whether the PlayerPositionEvent is displayed
  79.         public void TogglePositionEvent(ChatEvent e)
  80.         {
  81.             if (e.ModLevel >= ModLevels.Mod)
  82.             {
  83.                 if (displayPosition == true)
  84.                     displayPosition = false;
  85.                 else if (displayPosition == false)
  86.                     displayPosition = true;
  87.  
  88.                 e.Message = "Display on PlayerPositionEvent is now set to " + displayPrize;
  89.                 e.ChatType = ChatTypes.Arena;
  90.                 SendGameEvent(e);
  91.             }
  92.         }
  93.  
  94.         // Toggle whether the WatchDamageEvent is displayed - fixed in latest version
  95.         public void ToggleWatchDamage(ChatEvent e)
  96.         {
  97.             if (e.ModLevel >= ModLevels.Mod)
  98.             {
  99.                 ChatEvent notify = new ChatEvent();
  100.                 notify.PlayerName = e.Message.Remove(0, 8);
  101.                 notify.ChatType = ChatTypes.Private;
  102.                 notify.Message = "*watchdamage";
  103.                 SendGameEvent(notify);
  104.             }
  105.         }
  106.  
  107.         //Get the bot to spectate a player, in preparation for !display
  108.         public void HandleSpecRequest(ChatEvent e)
  109.         {
  110.             if (e.ModLevel >= ModLevels.Mod)
  111.             {
  112.                 ChatEvent notify = new ChatEvent();
  113.                 notify.Message = "The bot is now speccing " + e.Message.Remove(0, 6);
  114.                 notify.ChatType = ChatTypes.Private;
  115.                 notify.PlayerName = e.PlayerName;   //send to the same person
  116.                 SendGameEvent(notify);
  117.  
  118.                 SpectatePlayerEvent spec = new SpectatePlayerEvent();
  119.                 spec.PlayerName = e.Message.Remove(0, 6);
  120.                 SendGameEvent(spec);
  121.             }
  122.         }
  123.  
  124.         //Display a player's information
  125.         public void HandleInfoRequest(ChatEvent e)
  126.         {
  127.             if (e.ModLevel >= ModLevels.Mod)
  128.             {                
  129.                 PlayerInfoEvent pinfo = new PlayerInfoEvent();
  130.                 pinfo.Players.Add(e.Message.Remove(0, 9));    //<-- possible error
  131.                 SendGameEvent(pinfo);
  132.             }
  133.         }
  134.  
  135.         //Sends a periodic message until disabled via RegisterPeriodicTimer
  136.         public void SendPeriodicMessage()
  137.         {
  138.             ChatEvent timed = new ChatEvent();
  139.             timed.ChatType = ChatTypes.Arena;
  140.             timed.Message = "This message is played via PeriodicTimer.";
  141.             SendGameEvent(timed);
  142.         }
  143.  
  144.         //Disables the periodic timer
  145.         public void DisableTimer(ChatEvent e)
  146.         {
  147.             RemoveTimedEvent("Timer");
  148.         }
  149.  
  150.  
  151.         // AlphaCore events
  152.         // FlagClaimEvent
  153.         public void FlagClaimed(object sender, FlagClaimEvent e)    //works
  154.         {
  155.             if (displayFlags == true)
  156.             {
  157.                 ChatEvent notify = new ChatEvent();
  158.                 notify.ChatType = ChatTypes.Arena;
  159.  
  160.                 notify.Message = e.PlayerName + " has triggered a FlagClaimEvent.";
  161.                 SendGameEvent(notify);
  162.             }
  163.         }
  164.  
  165.         // FlagDropEvent
  166.         public void FlagDropped(object sender, FlagDropEvent e) //untested
  167.         {
  168.             ChatEvent notify = new ChatEvent();
  169.             notify.ChatType = ChatTypes.Arena;
  170.  
  171.             notify.Message = e.PlayerName + " has triggered a FlagDropEvent.";
  172.             SendGameEvent(notify);
  173.         }
  174.  
  175.         // FlagPositionEvent
  176.         public void FlagPosition(object sender, FlagPositionEvent e)    //untested
  177.         {
  178.             ChatEvent notify = new ChatEvent();
  179.             notify.ChatType = ChatTypes.Arena;
  180.  
  181.             notify.Message = "Flag " + e.FlagId + " is now at X: " + e.MapPositionX + "  Y: " + e.MapPositionY + ".";
  182.             SendGameEvent(e);
  183.         }
  184.  
  185.         // PlayerDeathEvent
  186.         public void PlayerDeath(object sender, PlayerDeathEvent e)  //works
  187.         {
  188.             ChatEvent notify = new ChatEvent();
  189.             notify.ChatType = ChatTypes.Arena;
  190.  
  191.             notify.Message = e.KilledName + " killed by " + e.KillerName + ".";
  192.             SendGameEvent(notify);
  193.         }
  194.  
  195.         //PlayerEnteredEvent
  196.         public void PlayerEntered(object sender, PlayerEnteredEvent e)  //works
  197.         {
  198.             ChatEvent notify = new ChatEvent();
  199.             notify.ChatType = ChatTypes.Arena;
  200.  
  201.             notify.Message = e.PlayerName + " has entered the arena.";
  202.             SendGameEvent(notify);
  203.         }
  204.  
  205.         //PlayerLeftEvent
  206.         public void PlayerLeft(object sender, PlayerLeftEvent e)    //works
  207.         {
  208.             ChatEvent notify = new ChatEvent();
  209.             notify.ChatType = ChatTypes.Arena;
  210.  
  211.             notify.Message = e.PlayerName + " has left the arena.";
  212.             SendGameEvent(notify);
  213.         }
  214.  
  215.         // PlayerPositionEvent
  216.         public void PlayerPosition(object sender, PlayerPositionEvent e)
  217.         {
  218.             if ( (displayPosition == true) && (e.Weapon.Type != WeaponTypes.NoWeapon) )
  219.             {
  220.                 ChatEvent notify = new ChatEvent();
  221.  
  222.                 notify.ChatType = ChatTypes.Arena;
  223.                 notify.Message = e.PlayerName + " at X: " + e.MapPositionX + "  Y: " + e.MapPositionY + "  has fired a " + e.Weapon.Type + ".";
  224.                 SendGameEvent(notify);
  225.  
  226.  
  227.                 notify.ChatType = ChatTypes.Arena;
  228.                 notify.Message = e.PlayerName + " Bounty: " + e.Bounty + "  Energy: " + e.Energy + "  Ping: " + e.Ping + "  S2C: " + e.ServerToClientLag;
  229.                 SendGameEvent(notify);
  230.             }
  231.  
  232.         }
  233.  
  234.         // PlayerSoundEvent
  235.         public void PlayerSound(object sender, PlayerSoundEvent e)  //untested
  236.         {
  237.             ChatEvent notify = new ChatEvent();
  238.             notify.ChatType = ChatTypes.Arena;
  239.  
  240.             notify.Message = e.PlayerName + " sent a sound file to the bot.";
  241.             SendGameEvent(notify);
  242.         }
  243.  
  244.         // PrizeCollectedEvent
  245.         public void PrizeCollected(object sender, PrizeCollectedEvent e)    //works
  246.         {
  247.             if (displayPrize == true)
  248.             {
  249.                 ChatEvent notify = new ChatEvent();
  250.                 notify.ChatType = ChatTypes.Arena;
  251.  
  252.                 notify.Message = e.PlayerName + " collected a " + e.PrizeType + ".";
  253.                 SendGameEvent(notify);
  254.             }
  255.         }
  256.  
  257.         // PrizeGrantedEvent
  258.         public void PrizeGranted(object sender, PrizeGrantedEvent e)    //untested
  259.         {
  260.             ChatEvent notify = new ChatEvent();
  261.             notify.ChatType = ChatTypes.Arena;
  262.  
  263.             notify.Message = e.Count + " of " + e.PrizeType + " have been granted.";
  264.             SendGameEvent(notify);
  265.         }
  266.  
  267.         // ScoreUpdateEvent
  268.         // this event interacts with PlayerInfo rather strangely...
  269.         public void ScoreUpdate(object sender, ScoreUpdateEvent e)  //partially works?
  270.         {
  271.             ChatEvent notify = new ChatEvent();
  272.             notify.ChatType = ChatTypes.Arena;
  273.  
  274.             notify.Message = e.PlayerName + " has had their score updated.";
  275.             SendGameEvent(notify);
  276.         }
  277.  
  278.         // ShipChangeEvent
  279.         public void ShipChange(object sender, ShipChangeEvent e)    //works
  280.         {
  281.             ChatEvent notify = new ChatEvent();
  282.             notify.ChatType = ChatTypes.Arena;
  283.  
  284.             notify.Message = e.PlayerName + " has changed from ship " + e.PreviousShipType + " to ship " + e.ShipType + ".";
  285.             SendGameEvent(notify);
  286.         }
  287.  
  288.         // SoccerGoalEvent
  289.         public void SoccerGoal(object sender, SoccerGoalEvent e)    //works
  290.         {
  291.             ChatEvent notify = new ChatEvent();
  292.             notify.ChatType = ChatTypes.Arena;
  293.  
  294.             notify.Message = "Freq " + e.Frequency + " has scored a goal.";
  295.             SendGameEvent(notify);
  296.         }
  297.  
  298.         // SpectatePlayerEvent - used above
  299.  
  300.         // TeamChangeEvent
  301.         public void TeamChange(object sender, TeamChangeEvent e)    //works
  302.         {
  303.             ChatEvent notify = new ChatEvent();
  304.             notify.ChatType = ChatTypes.Arena;
  305.  
  306.             notify.Message = e.PlayerName + " is now on freq " + e.Frequency + ".";
  307.             SendGameEvent(notify);
  308.         }
  309.  
  310.         // WatchDamageEvent
  311.         public void WatchDamage(object sender, WatchDamageEvent e)  //works in latest version
  312.         {
  313.             if (watchDamage == true)
  314.             {
  315.                 ChatEvent notify = new ChatEvent();
  316.                 notify.ChatType = ChatTypes.Arena;
  317.  
  318.                 notify.Message = e.PlayerName + " hit by " + e.AttackerName + " " + e.Weapon + " for " + e.Damage + ".";
  319.                 SendGameEvent(notify);
  320.             }
  321.         }
  322.  
  323.  
  324.         // AlphaCore Data Classes
  325.         public void DisplayPlayerInfo(object sender, PlayerInfoEvent e)
  326.         {
  327.             ChatEvent notify = new ChatEvent();
  328.             PlayerInfo p = e.PlayerList[0];
  329.  
  330.             //send the contents of PlayerInfo
  331.             notify.ChatType = ChatTypes.Arena;
  332.             notify.Message = p.PlayerName + " (Freq:" + p.Frequency
  333.                             + " Wins:" + p.Wins
  334.                             + " Losses:" + p.Losses
  335.                             + " Points:" + p.KillPoints
  336.                             + " Squad: " + p.SquadName + ")";
  337.             SendGameEvent(notify);
  338.            
  339.             //send the contents of ItemInfo
  340.             p = e.PlayerList[0];
  341.             notify.ChatType = ChatTypes.Arena;
  342.             notify.Message = p.PlayerName + " (Bursts:" + p.Items.BurstCount
  343.                             + " Repels:" + p.Items.RepelCount
  344.                             + " Decoys:" + p.Items.DecoyCount
  345.                             + " Thors:" + p.Items.ThorCount
  346.                             + " Bricks:" + p.Items.BrickCount
  347.                             + " Rockets:" + p.Items.RocketCount
  348.                             + " Portals:" + p.Items.PortalCount + ")";
  349.             SendGameEvent(notify);
  350.            
  351.             //send the contents of ShipStateInfo
  352.             p = e.PlayerList[0];
  353.             notify.ChatType = ChatTypes.Arena;
  354.             notify.Message = p.PlayerName + " (Stealth: " + p.ShipState.StealthActive
  355.                             + "  Cloak: " + p.ShipState.CloakActive
  356.                             + "  X-Radar: " + p.ShipState.XRadarActive
  357.                             + "  Anti: " + p.ShipState.AntiwarpActive
  358.                             + "  Flashing: " + p.ShipState.IsFlashing
  359.                             + "  Safe: " + p.ShipState.IsSafe
  360.                             + "  UFO: " + p.ShipState.IsUFO + ")";
  361.             SendGameEvent(notify);
  362.  
  363.             e.Players.Clear();   //clear the entire PlayerList...not sure if this is necessary
  364.         }
  365.  
  366.         // This method is required by the base class
  367.         // perform any cleanup here
  368.         public override void Dispose()
  369.         {
  370.         }
  371.    
  372.     }
  373. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement