Advertisement
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 AutoRPG
- {
- [Behavior("Main", "true", "0.01", "KenNPsy", "Rpg game that plays itself.")]
- public class Main: BotEventListener
- {
- public Main()
- {
- //Makes sure spam control is on
- msg.SpamControl = true;
- //Log bot into channel
- msg.SCPubCommand(rpg_JoinChatCommand);
- }
- // ---------------------------------- 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();
- // ---------------------------------- Subspace Game 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();
- }
- }
- // All players coming in should be in spec because of arena settings
- // Have the game check their status here - registered/unregistered
- public void MonitorPlayerEnter(object sender, PlayerEnteredEvent pe)
- { rpg_PlayerJoinGame(pe.PlayerName);}
- // Player needs to be updated as he leaves, and take him out of game
- public void MonitorPlayerLeave(object sender, PlayerLeftEvent pl)
- { rpg_PlayerLeave(pl.PlayerName); }
- // Check to see if players are going into/out of spectator mode
- public void MonitorPlayerShipChanges(object sender, ShipChangeEvent sc)
- {
- // Coming into spec
- if (sc.PreviousShipType != ShipTypes.Spectator && sc.ShipType == ShipTypes.Spectator)
- {
- rpg_PlayerJoinGame(sc.PlayerName);
- return;
- }
- // Going out of spec
- if (sc.PreviousShipType == ShipTypes.Spectator && sc.ShipType != ShipTypes.Spectator)
- {
- rpg_PlayerLeave(sc.PlayerName);
- return;
- }
- }
- public void InitializeBot()
- {
- //Configure and start main game timer
- GameTimer.Elapsed += new ElapsedEventHandler(TimerMethod);
- GameTimer.Interval = 10;
- GameTimer.Start();
- //update chat with bot initialized msg
- msg.SCChanMessage(1, BotName + " initialized.");
- }
- // ---------------------------------- 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());
- // Safety chat rejoin in case bot lags out - NOT a crash
- if ((DateTime.Now - ts_RejoinChats).TotalMinutes > delay_RejoinChats)
- {
- // Update time stamp
- ts_RejoinChats = DateTime.Now;
- msg.SCPubCommand(rpg_JoinChatCommand);
- }
- }
- // ---------------------------------- MAIN CODE FOR RPG ---------------------------------- //
- // Join chat command for bot to send
- string rpg_JoinChatCommand = "?chat=battledev";
- // Main RPG Player List
- List<ARPlayer> rpg_PlayerList = new List<ARPlayer>();
- // In case of a Bot disconnect BUT not a crash we need bot to rejoin chats
- DateTime ts_RejoinChats = DateTime.Now;
- // Time in minutes that you want bot to rejoin chats
- double delay_RejoinChats = 5;
- // Player is joining game
- public void rpg_PlayerJoinGame(string PlayerName)
- {
- // Var to hold player
- ARPlayer rpg_Player;
- // Check DB for updating player info
- rpg_Player = DB_GetPlayer(PlayerName);
- // A safety for player NOT found in DB and player IS in current game somehow
- if (GetPlayer(PlayerName) != null)
- {
- msg.SCChanMessage(1, "*** Check Game Logic *** rpg_PlayerJoinGame found player INGame. Exiting method.");
- return;
- }
- // Player Not found - register player here
- if (rpg_Player == null)
- {
- rpg_Player = rpg_MakeNewPlayer(PlayerName);
- msg.SCChanMessage(1,"A baby in BattleRPG has been born. Welcome baby " + PlayerName + "!");
- }
- // Add player to ongoing game here - (PlayerList)
- rpg_PlayerList.Add(rpg_Player);
- }
- public void rpg_PlayerLeave(string PlayerName)
- {
- // Grab player info from list
- ARPlayer rpg_Player = GetPlayer(PlayerName);
- // If the player was not playing we stop code here
- // example being player left from a non spec ship
- if (rpg_Player == null) return;
- // Update player on the DB if needed
- DB_UpdatePlayerInfo(rpg_Player);
- // Take Player out of the ongoing game
- // not sure if this is going to work
- // may have to loop through list and take out that way
- rpg_PlayerList.Remove(rpg_Player);
- }
- // get player from player list using name
- public ARPlayer GetPlayer(string PlayerName)
- {
- // Loop through list
- for (int i = 0; i < rpg_PlayerList.Count; i+=1)
- {
- // if there is a name match, send back player
- if (PlayerName == rpg_PlayerList[i].PlayerName)
- return rpg_PlayerList[i];
- }
- // No matches were found, send back null
- return null;
- }
- // Create a player and set all default start variables here
- public ARPlayer rpg_MakeNewPlayer(string PlayerName)
- {
- // set default values
- // Maybe have options for a PREMIUM higher lvl start char?!?!?
- ARPlayer np = new ARPlayer();
- np.PlayerName = PlayerName;
- np.Experience = 0;
- np.Level = 0;
- // Possibly update database here to include new player
- // --------------------- //
- // return configured player
- return np;
- }
- // Grab all the needed player info from db here
- // If the player is not found we will return null
- public ARPlayer DB_GetPlayer(string PlayerName)
- {
- // Player was not found - return empty (null)
- return null;
- }
- // Update the databse with new player stats
- public void DB_UpdatePlayerInfo(ARPlayer rpg_Player)
- {
- // Update Player Info on DB
- }
- public override void Dispose()
- {
- throw new NotImplementedException();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement