Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using BattleCore;
- using BattleCore.Events;
- using BattleCorePsyOps;
- using System.Timers;
- namespace SpecRPG
- {
- [Behavior("Body", "true", "0.01", "KenNPsy", "SpecRPG")]
- public class Body : BotEventListener
- {
- public Body()
- {
- //Makes sure spam control is on
- msg.SpamControl = true;
- //Log bot into channel
- msg.SCPubCommand(JoinChatCommand);
- RegisterCommand("!map", doPrintMap);
- }
- // -----------------------------Variables and Needed Classes---+
- //Psy's Module to help with chat events
- ShortChat msg = new ShortChat();
- //Stores botname and arena
- string BotName, Arena = "";
- //Game Timer
- Timer GameTimer = new Timer();
- //Random for dice
- Random random = new Random();
- //Game Tick
- DateTime ts_GameUpdate = DateTime.Now;
- //MapOps
- SPMapOps gm = new SPMapOps();
- //Time in Minutes to tick
- double delay_GameUpdate = 5000;
- //In case of a Bot disconnect BUT not a crash bot rejoins chat
- DateTime ts_RejoinChats = DateTime.Now;
- //Time in minutes that you want bot to rejoin chats
- double delay_RejoinChats = 5;
- //lists
- List<Spec> SpecList = new List<Spec>();
- List<SPlayer> PlayerList = new List<SPlayer>();
- List<SPMap> MapList = new List<SPMap>();
- // -----------------------------Game Timer---+
- public void TimerMethod(object sender, ElapsedEventArgs e)
- {
- //Check to see if we have any commands in our command chat q
- if (msg.NeedUpdate) Game(msg.sendNextBCommand());
- // One game cycle
- GameUpdate();
- // Safety in case bot lags out
- // Joins chat every 5 min
- ReJoinChatCheck();
- }
- // -----------------------------SubSpace Events ---+
- //Monitor all incoming chat events
- public void MonitorChatEvents(object sender, ChatEvent c)
- {
- //Core sends each bot a pm with its own info 500ms after startup
- //Use it to Initialize Bot
- if (c.ChatType == ChatTypes.Private && c.Message.StartsWith("@BotInfo@"))
- {
- // Catch and store bot info that core sends
- string[] data = c.Message.Split(':');
- BotName = data[1];
- Arena = data[2];
- // Initialize everything needed to get bot started
- InitializeBot();
- }
- }
- public void MonitorPlayerEnter(object sender, PlayerEnteredEvent pe)
- {
- if (pe.ShipType == ShipTypes.Spectator)
- {
- msg.SCChanMessage(1, pe.PlayerName + " has joined spec! [Entered Zone/Arena]");
- Spec inspec = new Spec();
- inspec.PlayerName = pe.PlayerName;
- PlayerJoinGame(pe.PlayerName);
- }
- if (pe.ShipType != ShipTypes.Spectator)
- {
- msg.SCChanMessage(1, pe.PlayerName + " has left spec! [Not in Spec]");
- SpecList.RemoveAll(a => a.PlayerName == pe.PlayerName);
- }
- }
- public void MonitorPlayerLeave(object sender, PlayerLeftEvent pl)
- {
- msg.SCChanMessage(1, pl.PlayerName + " has left spec! [Left Zone/Arena]");
- SpecList.RemoveAll(a => a.PlayerName == pl.PlayerName);
- }
- public void MonitorShipEvents(object sender, ShipChangeEvent sc)
- {
- //Checks if player changed into spec
- if (sc.ShipType == ShipTypes.Spectator)
- {
- msg.SCChanMessage(1, sc.PlayerName + " has joined spec! [Ship Change]");
- Spec inspec = new Spec();
- inspec.PlayerName = sc.PlayerName;
- PlayerJoinGame(sc.PlayerName);
- }
- //Checks if player changed out of spec
- if (sc.ShipType != ShipTypes.Spectator)
- {
- msg.SCChanMessage(1, sc.PlayerName + " has left spec! [Ship Change]");
- SpecList.RemoveAll(a => a.PlayerName == sc.PlayerName);
- }
- }
- public void doPrintMap(ChatEvent c)
- {
- Queue<string> m = gm.MapPrintOut(BotName);
- while (m.Count > 0) Game(msg.pm(c.PlayerName, m.Dequeue()));
- }
- // -----------------------------Main RPG Code---+
- public void GameUpdate()
- {
- if ((DateTime.Now - ts_GameUpdate).TotalMilliseconds > delay_GameUpdate)
- {
- // Update time stamp
- ts_GameUpdate = DateTime.Now;
- // Grab random player
- SPlayer RPlayer = GetRandomPlayer();
- // u can tweak 10 up or down depending on how you wanna weigh event ignore
- switch (0)
- {
- case 0://Move Event
- gm.MovePlayer(RPlayer);
- msg.SCChanMessage(1, "|MOVE| - "+RPlayer.PlayerName+ " has moved to " + gm.MapList[1].MapName+"!");
- break;
- case 1://Duel Event
- msg.SCChanMessage(1, "Event dice rolled a [1]");
- break;
- case 2://Mob Event
- msg.SCChanMessage(1, "Event dice rolled a [2]");
- break;
- case 3://Item Event
- msg.SCChanMessage(1, "Event dice rolled a [3]");
- break;
- case 4://Luck Event
- msg.SCChanMessage(1, "Event dice rolled a [4]");
- break;
- default:
- msg.SCChanMessage(1, "Ignore events.");
- break;
- }
- }
- }
- // -----------------------------RPG Functions---+
- //Dice Roll
- //Creates 30 random numbers from Min,Max and selects 1 from that 30 randomly
- public int DiceRoll(int MinValue, int MaxValue)
- {
- int[] intbag = new int[30];
- for (int i = 0; i < 30; i++)
- {
- intbag[i] = random.Next(MinValue, MaxValue);
- }
- return intbag[random.Next(0, 30)];
- }
- //Create Player with default attributes
- public SPlayer CreatePlayer(string PlayerName)
- {
- //Default Values
- SPlayer cp = new SPlayer();
- cp.PlayerName = PlayerName;
- cp.MapIndex = 4;
- cp.Experience = 0;
- cp.Level = 1;
- cp.WepCon = 0;
- cp.WepMat = 0;
- cp.Weapon = 0;
- return cp;
- }
- //Let Player Join Game
- public void PlayerJoinGame(string PlayerName)
- {
- //Var to hold player
- SPlayer Player;
- //If Player not found - Register Player
- if (PlayerList.Exists(a => a.PlayerName == PlayerName))
- {
- msg.SCChanMessage(1, "|LOGIN| " + GetPlayer(PlayerName).PlayerName + " has Logged on!!");
- }
- else
- {
- Player = CreatePlayer(PlayerName);
- msg.SCChanMessage(1, "|REGISTER| " + Player.PlayerName + " was born!");
- PlayerList.Add(Player);
- }
- }
- //Get player from list
- public SPlayer GetPlayer(string PlayerName)
- {
- //Loop through list
- for (int i = 0; i < PlayerList.Count; i += 1)
- {
- //if there is a name match, send back player
- if (PlayerName == PlayerList[i].PlayerName)
- return PlayerList[i];
- }
- return null;
- }
- public Spec GetSpecPlayer(string PlayerName)
- {
- //Loop through list
- for (int i = 0; i < SpecList.Count; i += 1)
- {
- //if there is a name match, send back player
- if (PlayerName == SpecList[i].PlayerName)
- return SpecList[i];
- }
- return null;
- }
- public SPlayer GetRandomPlayer()
- {
- return PlayerList[DiceRoll(0, PlayerList.Count)];
- }
- // -----------------------------Misc Functions---+
- //Join chat command for bot to send
- string JoinChatCommand = "?chat=specrpg";
- public void ReJoinChatCheck()
- {
- //Saftey chat rejoin in case bot lags out - NOT a crash
- if ((DateTime.Now - ts_RejoinChats).TotalMinutes > delay_RejoinChats)
- {
- //Updates time stamp
- ts_RejoinChats = DateTime.Now;
- msg.SCPubCommand(JoinChatCommand);
- }
- }
- public void InitializeBot()
- {
- //Configure and start main game timer
- GameTimer.Elapsed += new ElapsedEventHandler(TimerMethod);
- GameTimer.Interval = 10;
- GameTimer.Start();
- //Creates map in MapList if need be
- gm.MapCreate(9);
- //update chat with bot initialized msg
- msg.SCChanMessage(1, BotName + " initialized.");
- }
- public override void Dispose()
- {
- throw new NotImplementedException();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment