public static ArmoryCharacterSheet getFreshCharacterSheet(string name, string server, string url, out XmlDocument rawSheet) { ArmoryCharacterSheet output = null; //Request the new character sheet xml XmlDocument sheet = RequestXml.RequestCharacterSheetXML(url); BaseStats baseStats = null; Spell spellData = null; int MaxHP; XmlNodeList xList, xList2; #region BaseStats xList = sheet.GetElementsByTagName("health"); if (xList.Count > 0) { MaxHP = Convert.ToInt32(sheet.GetElementsByTagName("health")[0].Attributes["effective"].Value); } else MaxHP = 0; xList = sheet.GetElementsByTagName("baseStats"); xList2 = sheet.GetElementsByTagName("secondBar"); if (xList.Count > 0 && xList2.Count > 0) { baseStats = new BaseStats(xList[0], MaxHP, xList2[0]); } #endregion if (baseStats != null) { output = new ArmoryCharacterSheet(baseStats, name, server, url); //We got new data, so save it to the DB. SaveBaseStats(name, server, baseStats); } #region Spell data xList = sheet.GetElementsByTagName("spell"); if (xList.Count > 0) { spellData = new Spell(xList[0]); } #endregion if (spellData != null) { SaveSpellData(name,server,spellData); if (output != null) output.SetSpell(spellData); } //For their records rawSheet = sheet; return output; }
public static ArmoryCharacterSheet getCharacterSheet(string name, string server, string url) { checkSqlConnections(); ArmoryCharacterSheet output = null; bool RequestNewData = false; #region Query SQL for Cached Data lock (cReaderLock) { DateTime LastUpdate = DateTime.MinValue; using (SqlCommand cmd = cSqlReader.CreateCommand()) { cmd.Parameters.Add("@NAME", SqlDbType.VarChar, 512).Value = name; cmd.Parameters.Add("@SERVER", SqlDbType.VarChar, 128).Value = server; cmd.CommandText = "Select * from armory_CharacterBaseStats Where name = @NAME and server = @SERVER"; using (SqlDataReader rd = cmd.ExecuteReader()) { if (rd.HasRows) { rd.Read(); LastUpdate = rd.GetDateTime(30); if (DateTime.Now - LastUpdate > maxCacheTime) RequestNewData = true; int maxHP = (int)rd["maxHP"], baseStr = (int)rd["baseStr"], effectiveStr = (int)rd["effectiveStr"], atkFromStr = (int)rd["atkFromStr"], blockFromStr = (int)rd["blockFromStr"], baseAgi = (int)rd["baseAgi"], effectiveAgi = (int)rd["effectiveAgi"], armorFromAgi = (int)rd["armorFromAgi"], atkFromAgi = (int)rd["atkFromAgi"], baseSta = (int)rd["baseSta"], effectiveSta = (int)rd["effectiveSta"], hpFromSta = (int)rd["hpFromSta"], petBonusStam = (int)rd["petBonusStam"], baseInt = (int)rd["baseInt"], effectiveInt = (int)rd["effectiveInt"], mpFromInt = (int)rd["mpFromInt"], petBonusInt = (int)rd["petBonusInt"], baseSpir = (int)rd["baseSpir"], effectiveSpir = (int)rd["effectiveSpir"], hpRegenFromSpir = (int)rd["hpRegenFromSpir"], mpRegenFromSpir = (int)rd["mpRegenFromSpir"], baseArmor = (int)rd["baseArmor"], effectiveArmor = (int)rd["effectiveArmor"], petArmorBonus = (int)rd["petArmorBonus"], effectiveSecondBar = (int)rd["effectiveSecondBar"], secondBarCasting = (int)rd["secondBarCasting"], secondBarNotCasting = (int)rd["secondBarNotCasting"], secondBarPerFive = (int)rd["secondBarPerFive"]; //throw new Exception(rd["critFromAgi"].ToString()); float critFromAgi = (float)(double)rd["critFromAgi"], critFromInt = (float)(double)rd["critFromInt"], armorMitigation = (float)(double)rd["armorMitigation"]; char secondBarType = ((string)rd["secondBarType"])[0]; output = new ArmoryCharacterSheet(new BaseStats(maxHP, new BaseStats.atribStr(baseStr, effectiveStr, atkFromStr, blockFromStr), new BaseStats.atribAgi(baseAgi, effectiveAgi, atkFromAgi, armorFromAgi, critFromAgi), new BaseStats.atribSta(baseSta, effectiveSta, hpFromSta, petBonusStam), new BaseStats.atribInt(baseInt, effectiveInt, mpFromInt, petBonusInt, critFromInt), new BaseStats.atribSpir(baseSpir, effectiveSpir, hpRegenFromSpir, mpRegenFromSpir), new BaseStats.atribArmor(baseArmor, effectiveArmor, petArmorBonus, armorMitigation), new SecondBar(effectiveSecondBar, secondBarCasting, secondBarNotCasting, secondBarPerFive, secondBarType)),//TODO Setup Second Bar here name, server, url); } else RequestNewData = true; } } } #endregion //If we need new data add it to the data queue if (RequestNewData) AddCharacterSheetToQueue(name, server, url); return output; }