/// <summary> /// Parse the player lord strength and dot configurations /// </summary> /// <param name="gamemodeConfig"></param> /// <returns></returns> static Dictionary <String, BinElement> ParseLordType(Dictionary <String, Object> gamemodeConfig) { Int32 lordMultiplier; List <String> exceptions = new List <string>(); Dictionary <String, BinElement> resultConfig = new Dictionary <string, BinElement>() { { "Strength", new BinSkip(0x4) }, { "Dots", new BinSkip(0x4) }, { "Type", new BinSkip(0x1) } }; dynamic lordConfig; if (gamemodeConfig.TryGetValue("Lord", out lordConfig)) { try { int dotCount = Convert.ToInt32(lordConfig["DotCount"]); String dotColour = lordConfig["DotColour"].ToString(); resultConfig["Dots"] = new BinInt32(lordDots[dotColour][dotCount]); } catch (KeyNotFoundException) { } catch (Exception) { exceptions.Add("lord dots"); } try { lordMultiplier = Convert.ToInt32((double)lordConfig["StrengthMultiplier"] * lordStrengthBase); resultConfig["Strength"] = new BinInt32(lordMultiplier); } catch (KeyNotFoundException) { } catch (Exception e) { exceptions.Add("lord strength" + e.Message); } try { resultConfig["Type"] = new BinBytes(new byte[] { (byte)Enum.Parse(typeof(LordType), lordConfig["Type"]) }); } catch (KeyNotFoundException) { } catch (Exception) { exceptions.Add("lord type"); } if (exceptions.Count > 0) { throw new Exception(String.Join(",", exceptions)); } } return(resultConfig); }
static DefaultHeader CreateResourceHeader(String file, Dictionary <String, Dictionary <String, Object> > resourceConfig) { try { byte[] resources = ParseResources(resourceConfig); byte[] gold = ParseGold(resourceConfig); return(new DefaultHeader(file, true) { BinBytes.CreateEdit("s_resource", resources), BinBytes.CreateEdit("s_gold", gold) }); } catch (Exception e) { throw new Exception("Errors found in " + file + ":\n" + e.Message); } }