Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- // Add the following namespaces
- using AlphaCore;
- using AlphaCore.Events;
- namespace EventTest
- {
- // Add the attribute and the base class
- [Behavior("EventsTest", "false", "0.52", "lightbender", "Tests all the event handlers")]
- [CommandHelp("!flags", "Stops the FlagClaimed event from outputting", ModLevels.Mod)]
- [CommandHelp("!prize", "Toggles the displaying of the PrizeCollectedEvent", ModLevels.Mod)]
- [CommandHelp("!position", "Toggles the displaying of the PlayerPositionEvent", ModLevels.Mod)]
- [CommandHelp("!timer", "Kills the periodic timer event", ModLevels.Mod)]
- [CommandHelp("!damage", "<player> Toggles the displaying of WatchDamageEvent for that player", ModLevels.Mod)]
- [CommandHelp("!spec", "<player> Gets the bot to spec a player, so !display will work", ModLevels.Mod)]
- [CommandHelp("!display", "<player> Displays all the information of a player who has been !specced", ModLevels.Mod)]
- [CommandHelp("!moreinfo", "<player> Displays PlayerPosition and WeaponInfo of a previously !specced player", ModLevels.Mod)]
- public class EventTest : BotEventListener
- {
- bool displayFlags = false; //prevent some level of spam...
- bool displayPrize = false; //same as above
- bool displayPosition = true;
- bool watchDamage = true;
- // ChatEvent
- public EventTest()
- {
- RegisterCommand("!flags", ToggleFlagEvent);
- RegisterCommand("!prize", TogglePrizeEvent);
- RegisterCommand("!position", TogglePositionEvent);
- RegisterCommand("!damage", ToggleWatchDamage);
- RegisterCommand("!spec", HandleSpecRequest);
- RegisterCommand("!display", HandleInfoRequest);
- RegisterTimedEvent("Timer", 10000, SendPeriodicMessage);
- RegisterCommand("!timer", DisableTimer);
- }
- // Toggle whether the FlagClaimedEvent is displayed
- public void ToggleFlagEvent(ChatEvent e)
- {
- if (e.ModLevel >= ModLevels.Mod)
- {
- if (displayFlags == true)
- displayFlags = false;
- if (displayFlags == false)
- displayFlags = true;
- e.Message = "Display on FlagClaimedEvent is now set to " + displayFlags;
- e.ChatType = ChatTypes.Arena;
- SendGameEvent(e);
- }
- }
- // Toggle whether the PrizeCollectedEvent is displayed
- public void TogglePrizeEvent(ChatEvent e)
- {
- if (e.ModLevel >= ModLevels.Mod)
- {
- if (displayPrize == true)
- displayPrize = false;
- else if (displayPrize == false)
- displayPrize = true;
- e.Message = "Display on PrizeCollectedEvent is now set to " + displayPrize;
- e.ChatType = ChatTypes.Arena;
- SendGameEvent(e);
- }
- }
- // Toggle whether the PlayerPositionEvent is displayed
- public void TogglePositionEvent(ChatEvent e)
- {
- if (e.ModLevel >= ModLevels.Mod)
- {
- if (displayPosition == true)
- displayPosition = false;
- else if (displayPosition == false)
- displayPosition = true;
- e.Message = "Display on PlayerPositionEvent is now set to " + displayPrize;
- e.ChatType = ChatTypes.Arena;
- SendGameEvent(e);
- }
- }
- // Toggle whether the WatchDamageEvent is displayed - fixed in latest version
- public void ToggleWatchDamage(ChatEvent e)
- {
- if (e.ModLevel >= ModLevels.Mod)
- {
- ChatEvent notify = new ChatEvent();
- notify.PlayerName = e.Message.Remove(0, 8);
- notify.ChatType = ChatTypes.Private;
- notify.Message = "*watchdamage";
- SendGameEvent(notify);
- }
- }
- //Get the bot to spectate a player, in preparation for !display
- public void HandleSpecRequest(ChatEvent e)
- {
- if (e.ModLevel >= ModLevels.Mod)
- {
- ChatEvent notify = new ChatEvent();
- notify.Message = "The bot is now speccing " + e.Message.Remove(0, 6);
- notify.ChatType = ChatTypes.Private;
- notify.PlayerName = e.PlayerName; //send to the same person
- SendGameEvent(notify);
- SpectatePlayerEvent spec = new SpectatePlayerEvent();
- spec.PlayerName = e.Message.Remove(0, 6);
- SendGameEvent(spec);
- }
- }
- //Display a player's information
- public void HandleInfoRequest(ChatEvent e)
- {
- if (e.ModLevel >= ModLevels.Mod)
- {
- PlayerInfoEvent pinfo = new PlayerInfoEvent();
- pinfo.Players.Add(e.Message.Remove(0, 9)); //<-- possible error
- SendGameEvent(pinfo);
- }
- }
- //Sends a periodic message until disabled via RegisterPeriodicTimer
- public void SendPeriodicMessage()
- {
- ChatEvent timed = new ChatEvent();
- timed.ChatType = ChatTypes.Arena;
- timed.Message = "This message is played via PeriodicTimer.";
- SendGameEvent(timed);
- }
- //Disables the periodic timer
- public void DisableTimer(ChatEvent e)
- {
- RemoveTimedEvent("Timer");
- }
- // AlphaCore events
- // FlagClaimEvent
- public void FlagClaimed(object sender, FlagClaimEvent e) //works
- {
- if (displayFlags == true)
- {
- ChatEvent notify = new ChatEvent();
- notify.ChatType = ChatTypes.Arena;
- notify.Message = e.PlayerName + " has triggered a FlagClaimEvent.";
- SendGameEvent(notify);
- }
- }
- // FlagDropEvent
- public void FlagDropped(object sender, FlagDropEvent e) //untested
- {
- ChatEvent notify = new ChatEvent();
- notify.ChatType = ChatTypes.Arena;
- notify.Message = e.PlayerName + " has triggered a FlagDropEvent.";
- SendGameEvent(notify);
- }
- // FlagPositionEvent
- public void FlagPosition(object sender, FlagPositionEvent e) //untested
- {
- ChatEvent notify = new ChatEvent();
- notify.ChatType = ChatTypes.Arena;
- notify.Message = "Flag " + e.FlagId + " is now at X: " + e.MapPositionX + " Y: " + e.MapPositionY + ".";
- SendGameEvent(e);
- }
- // PlayerDeathEvent
- public void PlayerDeath(object sender, PlayerDeathEvent e) //works
- {
- ChatEvent notify = new ChatEvent();
- notify.ChatType = ChatTypes.Arena;
- notify.Message = e.KilledName + " killed by " + e.KillerName + ".";
- SendGameEvent(notify);
- }
- //PlayerEnteredEvent
- public void PlayerEntered(object sender, PlayerEnteredEvent e) //works
- {
- ChatEvent notify = new ChatEvent();
- notify.ChatType = ChatTypes.Arena;
- notify.Message = e.PlayerName + " has entered the arena.";
- SendGameEvent(notify);
- }
- //PlayerLeftEvent
- public void PlayerLeft(object sender, PlayerLeftEvent e) //works
- {
- ChatEvent notify = new ChatEvent();
- notify.ChatType = ChatTypes.Arena;
- notify.Message = e.PlayerName + " has left the arena.";
- SendGameEvent(notify);
- }
- // PlayerPositionEvent
- public void PlayerPosition(object sender, PlayerPositionEvent e)
- {
- if ( (displayPosition == true) && (e.Weapon.Type != WeaponTypes.NoWeapon) )
- {
- ChatEvent notify = new ChatEvent();
- notify.ChatType = ChatTypes.Arena;
- notify.Message = e.PlayerName + " at X: " + e.MapPositionX + " Y: " + e.MapPositionY + " has fired a " + e.Weapon.Type + ".";
- SendGameEvent(notify);
- notify.ChatType = ChatTypes.Arena;
- notify.Message = e.PlayerName + " Bounty: " + e.Bounty + " Energy: " + e.Energy + " Ping: " + e.Ping + " S2C: " + e.ServerToClientLag;
- SendGameEvent(notify);
- }
- }
- // PlayerSoundEvent
- public void PlayerSound(object sender, PlayerSoundEvent e) //untested
- {
- ChatEvent notify = new ChatEvent();
- notify.ChatType = ChatTypes.Arena;
- notify.Message = e.PlayerName + " sent a sound file to the bot.";
- SendGameEvent(notify);
- }
- // PrizeCollectedEvent
- public void PrizeCollected(object sender, PrizeCollectedEvent e) //works
- {
- if (displayPrize == true)
- {
- ChatEvent notify = new ChatEvent();
- notify.ChatType = ChatTypes.Arena;
- notify.Message = e.PlayerName + " collected a " + e.PrizeType + ".";
- SendGameEvent(notify);
- }
- }
- // PrizeGrantedEvent
- public void PrizeGranted(object sender, PrizeGrantedEvent e) //untested
- {
- ChatEvent notify = new ChatEvent();
- notify.ChatType = ChatTypes.Arena;
- notify.Message = e.Count + " of " + e.PrizeType + " have been granted.";
- SendGameEvent(notify);
- }
- // ScoreUpdateEvent
- // this event interacts with PlayerInfo rather strangely...
- public void ScoreUpdate(object sender, ScoreUpdateEvent e) //partially works?
- {
- ChatEvent notify = new ChatEvent();
- notify.ChatType = ChatTypes.Arena;
- notify.Message = e.PlayerName + " has had their score updated.";
- SendGameEvent(notify);
- }
- // ShipChangeEvent
- public void ShipChange(object sender, ShipChangeEvent e) //works
- {
- ChatEvent notify = new ChatEvent();
- notify.ChatType = ChatTypes.Arena;
- notify.Message = e.PlayerName + " has changed from ship " + e.PreviousShipType + " to ship " + e.ShipType + ".";
- SendGameEvent(notify);
- }
- // SoccerGoalEvent
- public void SoccerGoal(object sender, SoccerGoalEvent e) //works
- {
- ChatEvent notify = new ChatEvent();
- notify.ChatType = ChatTypes.Arena;
- notify.Message = "Freq " + e.Frequency + " has scored a goal.";
- SendGameEvent(notify);
- }
- // SpectatePlayerEvent - used above
- // TeamChangeEvent
- public void TeamChange(object sender, TeamChangeEvent e) //works
- {
- ChatEvent notify = new ChatEvent();
- notify.ChatType = ChatTypes.Arena;
- notify.Message = e.PlayerName + " is now on freq " + e.Frequency + ".";
- SendGameEvent(notify);
- }
- // WatchDamageEvent
- public void WatchDamage(object sender, WatchDamageEvent e) //works in latest version
- {
- if (watchDamage == true)
- {
- ChatEvent notify = new ChatEvent();
- notify.ChatType = ChatTypes.Arena;
- notify.Message = e.PlayerName + " hit by " + e.AttackerName + " " + e.Weapon + " for " + e.Damage + ".";
- SendGameEvent(notify);
- }
- }
- // AlphaCore Data Classes
- public void DisplayPlayerInfo(object sender, PlayerInfoEvent e)
- {
- ChatEvent notify = new ChatEvent();
- PlayerInfo p = e.PlayerList[0];
- //send the contents of PlayerInfo
- notify.ChatType = ChatTypes.Arena;
- notify.Message = p.PlayerName + " (Freq:" + p.Frequency
- + " Wins:" + p.Wins
- + " Losses:" + p.Losses
- + " Points:" + p.KillPoints
- + " Squad: " + p.SquadName + ")";
- SendGameEvent(notify);
- //send the contents of ItemInfo
- p = e.PlayerList[0];
- notify.ChatType = ChatTypes.Arena;
- notify.Message = p.PlayerName + " (Bursts:" + p.Items.BurstCount
- + " Repels:" + p.Items.RepelCount
- + " Decoys:" + p.Items.DecoyCount
- + " Thors:" + p.Items.ThorCount
- + " Bricks:" + p.Items.BrickCount
- + " Rockets:" + p.Items.RocketCount
- + " Portals:" + p.Items.PortalCount + ")";
- SendGameEvent(notify);
- //send the contents of ShipStateInfo
- p = e.PlayerList[0];
- notify.ChatType = ChatTypes.Arena;
- notify.Message = p.PlayerName + " (Stealth: " + p.ShipState.StealthActive
- + " Cloak: " + p.ShipState.CloakActive
- + " X-Radar: " + p.ShipState.XRadarActive
- + " Anti: " + p.ShipState.AntiwarpActive
- + " Flashing: " + p.ShipState.IsFlashing
- + " Safe: " + p.ShipState.IsSafe
- + " UFO: " + p.ShipState.IsUFO + ")";
- SendGameEvent(notify);
- e.Players.Clear(); //clear the entire PlayerList...not sure if this is necessary
- }
- // This method is required by the base class
- // perform any cleanup here
- public override void Dispose()
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement