Advertisement
Guest User

SpecRPG Main

a guest
Apr 23rd, 2014
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Timers;
  6.  
  7. using BattleCore;
  8. using BattleCore.Events;
  9. using BattleCorePsyOps;
  10.  
  11. namespace KenTestModule
  12. {
  13.     //[Behavior("This is name of Module","(Do you want it to auto-load)","(Version)","(Creator)","(Description)")]
  14.     [Behavior("Main", "true", "0.67", "Kenshin", "My Test Bot.")]
  15.     public class Main : BotEventListener
  16.     {
  17.         public Main()
  18.         {
  19.             //Makes sure spam control is on
  20.             msg.SpamControl = true;
  21.             //Log bot into channel
  22.             msg.SCPubCommand("?chat=specrpg");
  23.         }
  24.  
  25.         //Psy's Module to help with chat events
  26.         ShortChat msg = new ShortChat();
  27.         //Stores botname and arena
  28.         string BotName, Arena = "";
  29.         //Game Timer
  30.         Timer GameTimer = new Timer();
  31.         //Bot dice Timestamp
  32.         DateTime BotDiceTimeStamp = DateTime.Now;
  33.         //1 Min since GameTimer Interval is 10ms
  34.         double BotDiceInterval = 10000;
  35.         //Random for dice
  36.         Random random = new Random();
  37.  
  38.         string[] locar = new string[] { " a Beach", " a Desert", " a Forest", " the Plains" };
  39.         string[] weapon = new string[] { "Dagger", "Sword", "Claymore", "Mace" };
  40.         string[] type2 = new string[] { "Wooden", "Bronze", "Iron", "Steel", "Adamantium" };
  41.         string[] type1 = new string[] { "Broken", "Old", "New", "Shining", "Upgraded", "Godly" };
  42.  
  43.         List<Player> PlayerList = new List<Player>();
  44.         List<Playing> PlayingList = new List<Playing>();
  45.  
  46.         //Monitor all incoming chat events
  47.         public void MonitorChatEvents(object sender, ChatEvent c)
  48.         {
  49.             //Core sends each bot a pm with its own info 500ms after startup
  50.             //Use it to Initialize Bot
  51.             if (c.ChatType == ChatTypes.Private && c.Message.StartsWith("@BotInfo@"))
  52.             {
  53.                 // Catch and store bot info that core sends
  54.                 string[] data = c.Message.Split(':');
  55.                 BotName = data[1];
  56.                 Arena = data[2];
  57.  
  58.                 // Initialize everything needed to get bot started
  59.                 InitializeBot();
  60.             }
  61.         }
  62.  
  63.         public void MonitorPlayerEnter(object sender, PlayerEnteredEvent pe)
  64.         {
  65.             if (PlayerRegistered(pe.PlayerName))
  66.             {
  67.                 //Welcomes if player has played already (Could use this to read player profile from data file)
  68.                 Game(msg.pm(pe.PlayerName, "Welcome back to SpecRPG " + pe.PlayerName + "!"));
  69.                 msg.SCChanMessage(1, "|LOGIN| " + pe.PlayerName + " has spawned into the realm!");
  70.             }
  71.             else
  72.             {
  73.                 // Create Player
  74.                 Player np = new Player();
  75.                 np.PlayerName = pe.PlayerName;
  76.  
  77.                 //Register player first
  78.                 PlayerList.Add(np);
  79.  
  80.                 Game(msg.pm(pe.PlayerName,"Welcome " +pe.PlayerName+ "! Type ?chat=SpecRPG to start playing SpecRPG!"));
  81.                 //Create Player data file here
  82.                 msg.SCChanMessage(1, "|REGISTER| " + pe.PlayerName + " has just been born!");
  83.  
  84.             }
  85.             //Checks if Player is in spec
  86.             if (pe.ShipType == ShipTypes.Spectator)
  87.             {
  88.                 //Sets player to start playing if in spec
  89.                 PlayingList.Add(new Playing(pe.PlayerName));
  90.             }
  91.         }
  92.  
  93.         //Monitor if Player leaves the zone or arena
  94.         public void MonitorPlayerLeave(object sender, PlayerLeftEvent lv)
  95.         {
  96.             //Removes player from playing rpg if he leaves zone or arena
  97.             PlayingList.RemoveAll(a => a.PlayerName == lv.PlayerName);
  98.  
  99.             msg.SCChanMessage(1, "|LOGOUT| " + lv.PlayerName + " has left the realm! [REASON : Left Zone/Arena]");
  100.         }
  101.        
  102.         //Checks to see if player left spec
  103.         public void SpecLeave(object sender, ShipChangeEvent sc)
  104.         {
  105.             if (sc.ShipType == ShipTypes.Spectator)
  106.             {
  107.                 msg.SCChanMessage(1, "|LOGIN| " + sc.PlayerName + " has joined the realm! [REASON : Joined Spec]");
  108.                 PlayingList.Add(new Playing(sc.PlayerName));
  109.             }
  110.             if (PlayingRegistered(sc.PlayerName))
  111.             {
  112.                 if (sc.ShipType != ShipTypes.Spectator)
  113.                 {
  114.                     msg.SCChanMessage(1, "|LOGOUT| " + sc.PlayerName + " has left the realm! [REASON : Left Spec]");
  115.                     PlayingList.RemoveAll(a => a.PlayerName == sc.PlayerName);
  116.                 }
  117.             }
  118.         }
  119.            
  120.         public void InitializeBot()
  121.         {
  122.             //Configure and start main game timer
  123.             GameTimer.Elapsed += new ElapsedEventHandler(updateMainTimer);
  124.             GameTimer.Interval = 10;
  125.             GameTimer.Start();
  126.  
  127.                 //update chat with bot initialized msg
  128.                 msg.SCChanMessage(1,BotName + " initialized.");
  129.         }
  130.  
  131.         public void updateMainTimer(object sender, ElapsedEventArgs e)
  132.         {
  133.             if ((DateTime.Now - BotDiceTimeStamp).TotalMilliseconds > BotDiceInterval)
  134.             {
  135.                 //Event Dice
  136.                 int randomNumber = random.Next(0, 100);
  137.                 //Picks a player from spec
  138.                 int randomPlayer = random.Next(0,PlayingList.Count);
  139.                 //Picks a player from spec to duel
  140.                 int randomDuel = random.Next(0, PlayingList.Count);
  141.                 //Chance of winning duel
  142.                 int randomChance = random.Next(0, 100);
  143.                 //Random Area Selection (want to make it Beach <> Forest <> Plains <> Desert later)
  144.                 int randomArea = random.Next(0, 3);
  145.                 //Random Drop Weapon
  146.                 int randomWep = random.Next(0, 3);
  147.                 //Random Type 1
  148.                 int randomType1 = random.Next(0, 5);
  149.                 //Random Type 2
  150.                 int randomType2 = random.Next(0, 4);
  151.                 BotDiceTimeStamp = DateTime.Now;
  152.  
  153.                 //Retrieves Random players name
  154.                 string rPlayer = PlayingList[randomPlayer].PlayerName;
  155.                 //Retrieves Random enemy players name
  156.                 string rEnemyP = PlayingList[randomDuel].PlayerName;
  157.  
  158.                 //Change Locations
  159.                 if (randomNumber <= 10)
  160.                 {
  161.                     msg.SCChanMessage(1, "|AREA| " +rPlayer+ " has moved to" +locar[randomArea]+ "!");
  162.                 }
  163.  
  164.                 //Encounter Duel
  165.                 if (randomNumber >= 90)
  166.                 {
  167.                     if (randomDuel != randomPlayer)
  168.                     {
  169.                         //Win the duel
  170.                             if (randomChance >= 50)
  171.                             {
  172.                                 msg.SCChanMessage(1, "|DUEL| " + rPlayer + " has challenged " + rEnemyP + " to a duel and Won!");
  173.                             }
  174.                                 //Lose the duel
  175.                             else if (randomChance < 50)
  176.                             {
  177.                                 msg.SCChanMessage(1, "|DUEL| " + rPlayer + " has challenged " + rEnemyP + " to a duel and Lost!");
  178.                             }
  179.                                 //If Dueler rolled same name as him weird event happens
  180.                             else if (randomDuel == randomPlayer)
  181.                             {
  182.                                 msg.SCChanMessage(1, "|ITEM| " + rPlayer + " found " +type1[randomType1]+type2[randomType2]+weapon[randomWep]+ " !");
  183.                             }
  184.                         }
  185.  
  186.                     }
  187.                 //Rolling 69 goes to whore house
  188.                 if (randomNumber == 69)
  189.                 {
  190.                     msg.SCChanMessage(1, "|SEXY| " + rPlayer + " has gone into a whore house!");
  191.                 }
  192.             }
  193.  
  194.             //Check to see if we have any commands in our command chat q
  195.             if (msg.NeedUpdate) Game(msg.sendNextBCommand());
  196.        
  197.         }
  198.  
  199.         //Checks if Player has registered before or not (for Welcome message when entering zone or arena)
  200.         bool PlayerRegistered(string PlayerName)
  201.         {
  202.             for (int i = 0; i < PlayerList.Count; i += 1)
  203.             {
  204.                 if (PlayerName == PlayerList[i].PlayerName)
  205.                 {
  206.                     return true;
  207.                 }
  208.             }
  209.             return false;
  210.         }
  211.  
  212.         //Checks if Player is in spec list or not (playing list)
  213.         bool PlayingRegistered(string PlayerName)
  214.         {
  215.             for (int i = 0; i < PlayingList.Count; i += 1)
  216.             {
  217.                 if (PlayerName == PlayingList[i].PlayerName)
  218.                 {
  219.                     return true;
  220.                 }
  221.             }
  222.             return false;
  223.         }
  224.  
  225.         public override void Dispose()
  226.         {
  227.             throw new NotImplementedException();
  228.         }
  229.     }
  230. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement