All pastes #44434 Raw Edit

Anonymous

public text v1 · immutable
#44434 ·published 2006-03-04 13:08 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Common;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.IO;
using AoLib.Utils;

namespace VhaBot.Plugins
{
    [XmlRoot("Levels", Namespace = "", IsNullable = false)]
    public class LevelAnswers {
        [XmlElement("level")]
        public LevelAnswer[] Levels;
    }
    public class LevelAnswer
    {
        [XmlElement("level")]
        public int Level;
        [XmlElement("teamlow")]
        public int TeamLow;
        [XmlElement("teamhigh")]
        public int TeamHigh;
        [XmlElement("pvplow")]
        public int PvPLow;
        [XmlElement("pvphigh")]
        public int PvPHigh;
        [XmlElement("m1")]
        public int M1;
        [XmlElement("m2")]
        public int M2;
        [XmlElement("m3")]
        public int M3;
        [XmlElement("m4")]
        public int M4;
        [XmlElement("m5")]
        public int M5;
        [XmlElement("m6")]
        public int M6;
        [XmlElement("m7")]
        public int M7;
        [XmlElement("m8")]
        public int M8;
        [XmlElement("m9")]
        public int M9;
        [XmlElement("m10")]
        public int M10;
        [XmlElement("m11")]
        public int M11;
        [XmlElement("m12")]
        public int M12;
        [XmlElement("xpsk")]
        public int XpSk;
    }


    public class LevelPlugin : PluginBase
    {
        public string[] Mission;
        
        public LevelPlugin()
        {
            this.Settings.Name = "Level Plugin";
            this.Settings.InternalName = "LevelPlugin";
            this.Settings.Version = 1;
            this.Settings.Author = "Daniel Eriksson";

            this.Settings.RegisterCommand("level", new BotCommandRights(UserLevel.Guest, UserLevel.Member, UserLevel.Guest));
            this.Settings.RegisterCommandAlias("mission", "level");
            this.Settings.RegisterCommandAlias("lvl", "level");
            this.Settings.RegisterCommandAlias("l", "level");
        }

        public string ParseXML(string level)
        {
            string msg = "";
            int val = 0;

            try
            {
                val = int.Parse(level);
            }
            catch
            {
                msg = "You must specify a valid number.";
                return msg;
            }
            try
            {
                FileStream stream = File.Open("Level.xml", FileMode.Open, FileAccess.Read);
                XmlSerializer serializer = new XmlSerializer(typeof(LevelAnswers));
                LevelAnswers result = (LevelAnswers)serializer.Deserialize(stream);
                foreach (LevelAnswer answer in result.Levels)
                {
                    if (answer.Level == val)
                    {
                        msg = "L " + val + ": ";
                        msg += "Team " + answer.TeamLow + "-" + answer.TeamHigh + " | ";
                        msg += "PvP " + answer.PvPLow + "-" + answer.PvPHigh + " | ";
                        msg += answer.XpSk;
                        if (val > 200)
                            msg += " SK";
                        else
                            msg += " XP";
                        msg += " | ";
                        msg += "Missions ";
                        msg += answer.M1 + ", ";
                        msg += answer.M2 + ", ";
                        msg += answer.M3 + ", ";
                        msg += answer.M4 + ", ";
                        msg += answer.M5 + ", ";
                        msg += answer.M6 + ", ";
                        msg += answer.M7 + ", ";
                        msg += answer.M8 + ", ";
                        msg += answer.M9 + ", ";
                        msg += answer.M10 + ", ";
                        msg += answer.M11 + ", ";
                        msg += answer.M12;
                    }
                }
                stream.Close();
            }
            catch (Exception ex)
            {
                msg = "Cant open the tard file" + ex.ToString();
            }
            if (msg == "")
                msg = "Can't find that level in database.";
            return msg;
        }
  
        public override void OnInstall()
        {

        }

        public override void OnUninstall()
        {
        }

        public override void OnLoad()
        {
        }

        public override void OnUnload()
        {

        }

        public override void OnCommand(BotShell sender, CommandArgs e)
        {
            if (e.Args.Length > 0)
                Bot.SendReply(e, "Level »» " + ParseXML(e.Args[0]));
            else
                Bot.SendReply(e, "Level »» You got to append a level to. Syntax: level [level]");
        }
    }
}