using System;
namespace Server.Commands
{
public class SetSkillCommand
{
public static void Initialize()
{
CommandSystem.Register("SetSkill", AccessLevel.Player, new CommandEventHandler(SetPlayerSkills_OnCommand));
}
private static void SetPlayerSkills_OnCommand(CommandEventArgs e)
{
if (!String.IsNullOrEmpty(e.ArgString))
{
Mobile from = e.Mobile;
if (e.Arguments.Length == 2)
{
try
{
string name = e.Arguments[0];
double value = Convert.ToDouble(e.Arguments[1]);
ChangeSkill(from, name, value);
}
catch (Exception exc)
{
Diagnostics.ExceptionLogging.LogException(exc);
}
}
else
from.SendMessage("Use the next signature to set skills: [SetSkill Anatomy 100");
}
}
private static void ChangeSkill(Mobile from, string name, double value)
{
SkillName index;
if (!Enum.TryParse(name, true, out index))
{
from.SendLocalizedMessage(1005631); // You have specified an invalid skill to set.
return;
}
Skill skill = from.Skills[index];
if (skill != null)
{
if (value < 0 || value > skill.Cap)
{
from.SendMessage(string.Format("Your skill in {0} is capped at {1:F1}.", skill.Info.Name, skill.Cap));
}
else
{
int newFixedPoint = (int)(value * 10.0);
int oldFixedPoint = skill.BaseFixedPoint;
if (((skill.Owner.Total - oldFixedPoint) + newFixedPoint) > skill.Owner.Cap)
{
from.SendMessage("You can not exceed the skill cap. Try setting another skill lower first.");
}
else
{
skill.BaseFixedPoint = newFixedPoint;
}
}
}
else
{
from.SendLocalizedMessage(1005631); // You have specified an invalid skill to set.
}
}
}
}