string GetStr(Dict dict, string k) { return(dict.ContainsKey(k) ? dict[k] : "-"); }
string WriteWeapons(string pc) { string prefix = pc + "/_wpn/"; List <WeaponRecord> wpns = new List <WeaponRecord>(); foreach (var k in master.Keys) { if (!k.StartsWith(prefix)) { continue; } Dict d = master[k]; var w = new WeaponRecord(); w.name = k.Substring(prefix.Length); w.sr = GetInt(d, "sr"); w.parry = GetInt(d, "parry"); w.attack = GetInt(d, "attack"); w.ap = GetInt(d, "ap"); w.dmg = GetStr(d, "dmg"); w.goodness = w.parry + w.attack; wpns.Add(w); } wpns.Sort((w1, w2) => { if (w1.goodness > w2.goodness) { return(-1); } if (w1.goodness < w2.goodness) { return(1); } return(String.Compare(w1.name, w2.name)); }); var b = NewTable(); b.Append("<TR>" + "<TD><B>Name</B></TD>" + "<TD><B>Attack</B></TD>" + "<TD><B>Parry</B></TD>" + "<TD><B>Damage</B></TD>" + "<TD><B>AP</B></TD>" + "<TD><B>SR</B></TD>" + "</TR>"); foreach (var w in wpns) { b.Append("<TR><TD>"); b.Append(w.name); b.Append("</TD><TD>"); b.Append(w.attack); b.Append("</TD><TD>"); b.Append(w.parry); b.Append("</TD><TD>"); b.Append(w.dmg); b.Append("</TD><TD>"); b.Append(w.ap); b.Append("</TD><TD>"); b.Append(w.sr); b.Append("</TD></TR>"); } EndTable(b); return(b.ToString()); }
static void AppendMajorItem(Dict dict, string desc, string k, StringBuilder b) { string v = (dict != null && dict.ContainsKey(k)) ? dict[k] : "-"; AppendTwoCols("<b>" + desc + "</b>", v, b); }
static void AppendKeyValueRow(Dict dict, string k, StringBuilder b) { string v = (dict != null && dict.ContainsKey(k)) ? dict[k] : "-"; AppendTwoCols(k, v, b); }
void AppendCategory(string catFormal, string cat, StringBuilder b, string pc) { if (!master.ContainsKey(pc + cat)) { return; } if (b.Length > tableInit.Length) { AppendBlank(b); } AppendHeader(catFormal, b); Dict dict = master[pc + cat]; var keyC = dict.Keys; var keys = new string[keyC.Count]; keyC.CopyTo(keys, 0); Array.Sort(keys); foreach (var k in keys) { if (k.StartsWith("spare_")) { continue; } bool isZero = dict.ContainsKey(k) && dict[k] == "0"; if (isZero && catFormal == "Magic:") { continue; } AppendKeyValueRow(dict, k, b); var sk = new SkillRecord(); sk.name = k .Replace("_0", "") .Replace("_1", "") .Replace("_2", "") .Replace("_3", "") .Replace("_4", "") .Replace("_5", "") .Replace("_6", "") .Replace("_7", "") .Replace("_8", "") .Replace("_9", "") .Replace("_10", "") .Replace("_", " "); sk.category = cat; if (!isZero) { skills.Add(sk); } } }
void FormatPcAsHtml(string pcRaw) { StringBuilder col1 = NewTable(); StringBuilder col2 = NewTable(); StringBuilder col3 = NewTable(); StringBuilder col4 = NewTable(); StringBuilder summary = NewTable(); string pc = null; lock (master) { skills = new List <SkillRecord>(); pc = FindWho(pcRaw); if (pc == null) { WriteSimpleOutput(String.Format("PC '{0}' not found", pcRaw)); return; } string[] bonuses = new string[] { "agility", "attack", "communication", "knowledge", "alchemy", "magic", "manipulation", "parry", "perception", "stealth" }; string[] miscitems = new string[] { "dex_srm", "armor_enc", "battlemagic_enc", "damage_bonus", "encumberence", "endurance", "free_con", "free_int", "life_points", "melee_srm", "movement", "vow_presence", "casting_presence", "siz_srm" }; Dict dict = master[pc]; Dict dictMisc = null; if (master.ContainsKey(pc + "/_misc")) { dictMisc = master[pc + "/_misc"]; } AppendTwoCols("<b>Name:</b>", pc, summary); AppendMajorItem(dictMisc, "Species:", "species", summary); AppendMajorItem(dictMisc, "Religion:", "religion", summary); AppendBlank(summary); AppendHeader("Stats:", col1); AppendStat(dict, dictMisc, "STR", col1); AppendStat(dict, dictMisc, "CON", col1); AppendStat(dict, dictMisc, "SIZ", col1); AppendStat(dict, dictMisc, "INT", col1); AppendStat(dict, dictMisc, "POW", col1); AppendStat(dict, dictMisc, "DEX", col1); AppendStat(dict, dictMisc, "APP", col1); AppendCategory("Magic:", "/magic", col1, pc); AppendCategory("Perception:", "/perception", col1, pc); AppendExplicit("Bonuses:", dictMisc, bonuses, col1); AppendExplicit("Misc:", dictMisc, miscitems, col1); AppendCategory("Agility:", "/agility", col2, pc); AppendCategory("Manipulation:", "/manipulation", col2, pc); AppendCategory("Stealth:", "/stealth", col2, pc); AppendCategory("Knowledge:", "/knowledge", col2, pc); AppendCategory("Alchemy:", "/alchemy", col2, pc); AppendCategory("Communication:", "/communication", col3, pc); AppendCategory("Battlemagic:", "/_battlemagic", col3, pc); AppendCategory("Spells:", "/_spells", col3, pc); AppendCategory("Stored Spells:", "/_stored_spells", col3, pc); AppendCategory("Runemagic:", "/_runemagic", col3, pc); AppendCategory("Herocast:", "/_herocast", col3, pc); AppendCategory("Wizardry:", "/_wizardry", col3, pc); AppendCategory("Music:", "/_music", col3, pc); AppendCategory("One Use:", "/_one_use", col3, pc); AppendCategory("Others Spells:", "/_others_spells", col3, pc); AppendAllSchools(col3, pc); EndTable(col1); EndTable(col2); EndTable(col3); EndTable(summary); col4.Append(WriteWeapons(pc)); var c4 = NewTable(); AppendBlank(c4); WriteLocations(pc, c4); AppendBlank(c4); WriteMana(pc, c4); AppendBlank(c4); WriteFatigue(pc, c4); EndTable(c4); col4.Append(c4.ToString()); WriteSpirits(pc, col4); col4.Append(WriteEquipment(pc)); } // we don't need the lock anymore StringBuilder final = new StringBuilder(); final.AppendFormat("<HTML><HEAD><TITLE>{0}</TITLE></HEAD><BODY>", pc); final.Append(summary); final.Append("<TABLE><TR><TD style=\"vertical-align: top\">"); final.Append(col1); final.Append("</TD><TD> </TD><TD style=\"vertical-align: top\">"); final.Append(col2); final.Append("</TD><TD> </TD><TD style=\"vertical-align: top\">"); final.Append(col3); final.Append("</TD><TD> </TD><TD style=\"vertical-align: top\">"); final.Append(col4); final.Append("</TD><TR></TABLE>"); final.Append("<DIV style=\"font-family: arial, sans-serif; font-size:8pt\">"); bool b = false; foreach (var sk in skills) { if (commonSkills.ContainsKey(sk.name)) { continue; } if (sk.category.EndsWith("_school")) { AppendHelp(sk.name, "shugenja", final); } else { switch (sk.category) { case "/_runemagic": case "/_one_use": AppendHelp(sk.name, "runemagic", final); break; case "/_spells": case "/_stored_spells": case "/_others_spells": b = AppendHelp(sk.name, "battlemagic", final) || AppendHelp(sk.name, "sorcery", final) || AppendHelp(sk.name, "wizardry", final); break; default: b = AppendHelp(sk.name, "skill", final) || AppendHelp(sk.name, "secret", final); ; break; } } } skills = null; final.Append("</DIV>"); final.Append("</BODY></HTML>"); WriteRawOutput(final.ToString()); }
string WriteEquipment(string pc) { string prefix = pc + "/_equipment"; List <EquipRecord> eq = new List <EquipRecord>(); if (!master.ContainsKey(prefix)) { return(""); } Dict dict = master[prefix]; var b = NewTable(); foreach (var k in dict.Keys) { var e = new EquipRecord(); string code; string locs; string name; string ctr; Worker.Parse2Ex(k, out code, out ctr, ":"); Worker.Parse2Ex(ctr, out name, out locs, "."); e.code = code; e.name = name.Replace("_", " "); e.locs = locs; eq.Add(e); } eq.Sort((e1, e2) => String.Compare(e1.code, e2.code)); AppendBlank(b); AppendHeader("Equipped Weapons:", b); foreach (var e in eq) { if (!e.code.StartsWith("W")) { continue; } b.Append("<TR><TD>"); b.Append(e.name); b.Append("</TD><TR>"); } AppendBlank(b); AppendHeader("Equipped Armor:", b); foreach (var e in eq) { if (!e.code.StartsWith("A")) { continue; } b.Append("<TR><TD>"); b.Append(e.name); b.Append("</TD><TD>"); b.Append(e.locs); b.Append("</TD><TR>"); } AppendBlank(b); AppendHeader("Equipped Items:", b); foreach (var e in eq) { if (!e.code.StartsWith("G")) { continue; } b.Append("<TR><TD>"); b.Append(e.name); b.Append("</TD><TD>"); b.Append(e.locs); b.Append("</TD><TR>"); } EndTable(b); return(b.ToString()); }
void WriteMana(string pc, StringBuilder b) { if (!master.ContainsKey(pc + "/mana")) { return; } b.Append("<TR>" + "<TD><B>Mana Type</B></TD>" + "<TD><B>Full</B></TD>" + "<TD><B>Used</B></TD>" + "</TR>"); Dict manaDict = master[pc + "/mana"]; Dict usedMana = null; if (master.ContainsKey("_mana")) { usedMana = master["_mana"]; } if (manaDict.ContainsKey("total_magic_points")) { var m = manaDict["total_magic_points"]; b.Append("<TR>" + "<TD>" + "normal" + "</TD><TD>" + m + "</TD><TD>" + GetUsedMana(usedMana, pc, "mana") + "</TR>"); } var keyC = manaDict.Keys; var keys = new string[keyC.Count]; keyC.CopyTo(keys, 0); Array.Sort(keys); foreach (var k in keys) { if (k == "mpts_per_day" || k == "total_magic_points" || k.StartsWith("spare_")) { continue; } var m = manaDict[k]; b.Append("<TR>" + "<TD>" + k + "</TD><TD>" + m + "</TD><TD>" + GetUsedMana(usedMana, pc, "mana|" + k) + "</TR>"); } }
void WriteSpirits(string pc, StringBuilder col) { var spirits = pc + "/_spirits"; if (!master.ContainsKey(spirits)) { return; } Dict dict = master[spirits]; var keyC = dict.Keys; var keys = new string[keyC.Count]; keyC.CopyTo(keys, 0); Array.Sort(keys); var b = NewTable(); b.Append("<TR><TD> </TD></TR>"); b.Append("<TR>" + "<TD><B>Spirit ID</B></TD>" + "<TD><B>POW</B></TD>" + "<TD><B>Used</B></TD>" + "<TD><B>SC%</B></TD>" + "<TD><B>Stored</B></TD>" + "</TR>"); Dict spiritManaDict = master["_spiritmana"]; foreach (var k in keys) { var value = dict[k]; string sc; string pow; string stored; GameHost.Dict.ExtractSpiritInfoParts(value, out sc, out pow, out stored); var skey = pc + "|" + k; string used = "0"; if (spiritManaDict.ContainsKey(skey)) { used = spiritManaDict.GetRaw(skey); } b.Append("<TR><TD>"); b.Append(k); b.Append("</TD><TD>"); b.Append(pow); b.Append("</TD><TD>"); b.Append(used); b.Append("</TD><TD>"); b.Append(sc); b.Append("</TD><TD>"); b.Append(stored); b.Append("</TD></TR>"); } EndTable(b); col.Append(b); }