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 BattleCore;
- using BattleCore.Events;
- using System.Drawing;
- using System.Collections;
- using System.Data;
- namespace Behaviors
- {
- // Add the attribute and the base class
- [Behavior ("BotTest", "true", "0.1", "udp", "Testing misc stuff")]
- [CommandHelp("!sql", "Runs an SQL transaction", ModLevels.SMod)]
- public class BotTest : BotEventListener
- {
- private PlayerPositionEvent myPosition = new PlayerPositionEvent();
- // Bot Test
- public BotTest ()
- {
- //Command registration
- RegisterCommand("!sql", HandleSqlEvent);
- RegisterCommand("!die", HandleDieEvent);
- RegisterCommand("!bomb", HandleBombEvent);
- RegisterTimedEvent("Bombs", 100, ShootBomb);
- }
- public void ShootBomb ()
- {
- myPosition.Weapon.Type = WeaponTypes.BounceBullet;
- myPosition.Weapon.Level = 2;
- myPosition.ShipRotation += 1;
- SendGameEvent (myPosition);
- }
- public void HandleDieEvent(ChatEvent e)
- {
- PlayerDeathEvent evt = new PlayerDeathEvent();
- evt.Bounty = 100;
- evt.KillerName = "UDP";
- SendGameEvent(evt);
- }
- public void HandleBombEvent(ChatEvent e)
- {
- myPosition.Weapon.Type = WeaponTypes.ProxBomb;
- myPosition.Weapon.Level = 2;
- SendGameEvent (myPosition);
- }
- public void PlayerPosition(object sender, PlayerPositionEvent e)
- {
- if (e.PlayerName == "UDP")
- {
- myPosition.VelocityX = e.VelocityX;
- myPosition.VelocityY = e.VelocityY;
- myPosition.MapPositionY = e.MapPositionY;
- myPosition.MapPositionX = e.MapPositionX;
- SendGameEvent(e);
- }
- }
- // Execute the Sql command
- public void HandleSqlEvent(ChatEvent e)
- {
- if (e.ModLevel >= ModLevels.SMod && e.Message.Length > 5)
- {
- string commandTest = e.Message.Substring(5);
- if (commandTest.StartsWith("SELECT", true, null))
- {
- SqlQueryEvent sqlEvent = new SqlQueryEvent();
- sqlEvent.Command.CommandText = e.Message.Substring(5);
- SendGameEvent(sqlEvent);
- }
- else
- {
- SqlCommandEvent sqlEvent = new SqlCommandEvent();
- sqlEvent.Command.CommandText = e.Message.Substring(5);
- SendGameEvent(sqlEvent);
- }
- }
- }
- public void OnSqlEvent(object sender, SqlQueryEvent e)
- {
- ChatEvent ce = new ChatEvent();
- ce.Message = "Records Affected = " + e.RecordsAffected;
- SendGameEvent(ce);
- // For each table in the DataSet, print the values of each row.
- foreach (DataRow row in e.QueryData.Rows)
- {
- String nextRecord = "Row:";
- foreach (DataColumn column in e.QueryData.Columns)
- {
- nextRecord += " " + (row[column]).ToString();
- }
- ce.Message = nextRecord;
- SendGameEvent(ce);
- }
- }
- public void OnSqlEvent(object sender, SqlCommandEvent e)
- {
- ChatEvent ce = new ChatEvent();
- ce.Message = "Records Affected = " + e.RecordsAffected;
- SendGameEvent (ce);
- }
- public void OnListModEvent(object sender, ListModEvent e)
- {
- Console.WriteLine(e.Moderator.PlayerName + " - " + e.Moderator.ModeratorLevel);
- }
- // 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