What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

Parsing spell tooltips

exemplar

New Member
Joined
Mar 16, 2010
Messages
167
Reaction score
32
Not sure how useful this is and knowing my luck (and the superbly documented API ;)) there's probably a function that already does this, but this has come in handy for me for a few things. I didn't spend a heap of time on this and it was a bit of trial and error for a few items, but it seems to give a fairly accurate, parsed spell description for the most part. Mostly have been only using it for items and a modified auto equipper.

Code:
Regex desc_eval = new Regex(@"\${(.+?)}");
Regex desc_effect = new Regex(@"\$(\d*?)([a-z])(\d?)");
DataTable _dt = new DataTable();
public string ParseSpellDescription(WoWSpell spell)
{
	if (spell == null || spell.Description == null)
	{
		return "";
	}
	string res = desc_effect.Replace(spell.Description, delegate(Match m)
	{
		string type = m.Groups[2].Value;
		switch (type)
		{
			case "d":
				return (spell.BaseDuration / 1000).ToString();

			case "z":
				return Lua.GetReturnVal<string>("return GetBindLocation();", 0);
		}
		int spellid = toint(m.Groups[1].Value);
		int spelleffectid = toint(m.Groups[3].Value);
		if (spellid > 0)
		{
			spell = WoWSpell.FromId(spellid);
			if (spell == null)
			{
				return "";
			}
		}
		if (spelleffectid > 0)
		{
			spelleffectid--;
		}
		SpellEffect spelleffect = spell.GetSpellEffect(spelleffectid);
		if (spelleffect == null)
		{
			return "";
		}
		switch (type)
		{
			case "o":
				return (spelleffect.BasePoints / 5 * spell.BaseDuration / 1000).ToString();

			case "s":
			case "m":
				return spelleffect.BasePoints.ToString();

			default:
				Logging.Write("ParseSpellDescription(): unknown type: " + type);
				return "";
		}
	});
	res = desc_eval.Replace(res, delegate(Match m)
	{
		try
		{
			_dt.Reset();
			return _dt.Compute(m.Groups[1].Value, null).ToString();
		}
		catch (Exception) { }
		return "";
	});
	return res;
}
public int toint(string s) //haxhaxhaxhaxhaxhahxhaxhahxh
{
	try
	{
		return int.Parse(s);
	}
	catch (Exception) { }
	return 0;
}
 
Back
Top