rendered paste bodyusing 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", Type = typeof(int))]
public int Level;
[XmlElement("teamlow", Type = typeof(int))]
public int TeamLow;
[XmlElement("teamhigh", Type = typeof(int))]
public int TeamHigh;
[XmlElement("pvplow", Type = typeof(int))]
public int PvPLow;
[XmlElement("pvphigh", Type = typeof(int))]
public int PvPHigh;
[XmlElement("mission", Type = typeof(string))]
public string[] Missions;
[XmlElement("xpsk", Type = typeof(int))]
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 GetLevel(string level, LevelAnswers result)
{
string msg = "";
if (result != null)
{
int val = 0;
try
{
val = int.Parse(level);
}
catch
{
msg = "You must specify a valid number.";
return msg;
}
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 += string.Join(", ", answer.Missions);
}
}
if (msg == "")
msg = "Can't find that level in database.";
}
else
{
msg = "Can't access the database.";
}
return msg;
}
public LevelAnswers ParseXML()
{
try
{
using (FileStream stream = File.OpenRead("Level.xml"))
{
XmlSerializer serializer = new XmlSerializer(typeof(LevelAnswers));
LevelAnswers result = (LevelAnswers)serializer.Deserialize(stream);
return result;
}
}
catch
{
Bot.Debug("Can't open the Level.xml file!");
return null;
}
}
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 »» " + GetLevel(e.Args[0], ParseXML()));
else
Bot.SendReply(e, "Level »» You got to append a level to. Syntax: level [level]");
}
}
}