public float GetWeight(DiplomacyAction action, DiplomaticMood mood, object type = null) { if (DiplomacyActionWeights.RequiresType(action) && type == null) { throw new Exception("Action requires a type."); } DiplomacyActionWeights.DiplomacyActionWeight diplomacyActionWeight = type != null?this.Weights.FirstOrDefault <DiplomacyActionWeights.DiplomacyActionWeight>((Func <DiplomacyActionWeights.DiplomacyActionWeight, bool>)(x => { if (x.DiplomacyAction == action && x.Mood == mood) { return(x.Type.Equals(type)); } return(false); })) : this.Weights.FirstOrDefault <DiplomacyActionWeights.DiplomacyActionWeight>((Func <DiplomacyActionWeights.DiplomacyActionWeight, bool>)(x => { if (x.DiplomacyAction == action) { return(x.Mood == mood); } return(false); })); if (diplomacyActionWeight == null) { return(1f); } return(diplomacyActionWeight.Value); }
public DiplomacyActionWeights(XmlDocument doc) { foreach (XmlElement source in doc[nameof(DiplomacyActionWeights)].OfType <XmlElement>().Where <XmlElement>((Func <XmlElement, bool>)(x => x.Name == "DiplomacyReaction"))) { DiplomaticMood diplomaticMood = (DiplomaticMood)Enum.Parse(typeof(DiplomaticMood), source.GetAttribute("value")); foreach (XmlElement element in source.OfType <XmlElement>().Where <XmlElement>((Func <XmlElement, bool>)(x => x.Name == "Action"))) { DiplomacyActionWeights.DiplomacyActionWeight weight = new DiplomacyActionWeights.DiplomacyActionWeight(); weight.Mood = diplomaticMood; weight.DiplomacyAction = (DiplomacyAction)Enum.Parse(typeof(DiplomacyAction), element.GetAttribute("id")); weight.Value = float.Parse(element.GetAttribute("value")); if (DiplomacyActionWeights.RequiresType(weight.DiplomacyAction) && !element.HasAttribute("type")) { throw new Exception(string.Format("XML node for diplomatic action type: {0} requires a type.", (object)weight.DiplomacyAction.ToString())); } switch (weight.DiplomacyAction) { case DiplomacyAction.REQUEST: this.ProcessRequest(element, weight); break; case DiplomacyAction.DEMAND: this.ProcessDemand(element, weight); break; case DiplomacyAction.TREATY: this.ProcessTreaty(element, weight); break; case DiplomacyAction.LOBBY: this.ProcessLobby(element, weight); break; } this.Weights.Add(weight); } } }
public Dictionary <object, float> GetWeights( DiplomacyAction action, DiplomaticMood mood) { Dictionary <object, float> dictionary = new Dictionary <object, float>(); List <Type> types = DiplomacyActionWeights.GetTypes(action); if (types != null) { foreach (Type enumType in types) { foreach (object obj in Enum.GetValues(enumType)) { dictionary.Add(obj, this.GetWeight(action, mood, obj)); } } } else { float weight = this.GetWeight(action, mood, (object)null); dictionary.Add((object)action, weight); } return(dictionary); }
private Faction(string filename) { for (int index = 0; index < 3; ++index) { this.MaxPopulationMod[index] = 1f; this.MaxAlienPopulationMod[index] = 1f; } for (int index = 0; index < 6; ++index) { this.AIFastResearchRate[index] = 0.6f; } this.FactionFileName = filename; this.Directory = Path.GetDirectoryName(filename); this.Name = Path.GetFileNameWithoutExtension(Path.GetDirectoryName(filename)); this.DefaultBattleRiderShipRoles = Faction.EnumerateDefaultBattleRiderShipRoles(this.Name).ToArray <ShipRole>(); this.DefaultStandardShipRoles = Faction.EnumerateDefaultStandardShipRoles(this.Name).ToArray <ShipRole>(); this.DefaultCombinedShipRoles = Faction.EnumerateDefaultCombinedShipRoles(this.Name).ToArray <ShipRole>(); this.DefaultAIShipRoles = Faction.EnumerateDefaultAIShipRoles(this.Name).ToArray <ShipRole>(); switch (this.Name) { case "human": case "tarkas": case "liir_zuul": case "zuul": case "morrigi": case "hiver": case "loa": this.IsPlayable = true; break; default: this.IsPlayable = false; break; } switch (this.Name) { case "human": this._dlcID = new int?(202240); this.Subfactions = new Subfaction[2] { new Subfaction(), new Subfaction() { DlcID = new SteamDLCIdentifiers?(SteamDLCIdentifiers.SolForceImmersionPack), MountName = "dlc_human" } }; break; case "tarkas": this._dlcID = new int?(202220); this.Subfactions = new Subfaction[2] { new Subfaction(), new Subfaction() { DlcID = new SteamDLCIdentifiers?(SteamDLCIdentifiers.HiverAndTarkasImmersionPack), MountName = "dlc_tarkas" } }; break; case "hiver": this._dlcID = new int?(202220); this.Subfactions = new Subfaction[2] { new Subfaction(), new Subfaction() { DlcID = new SteamDLCIdentifiers?(SteamDLCIdentifiers.HiverAndTarkasImmersionPack), MountName = "dlc_hiver" } }; break; case "liir_zuul": this._dlcID = new int?(202230); this.Subfactions = new Subfaction[2] { new Subfaction(), new Subfaction() { DlcID = new SteamDLCIdentifiers?(SteamDLCIdentifiers.LiirAndMorrigiImmersionPack), MountName = "dlc_liir_zuul" } }; break; case "morrigi": this._dlcID = new int?(202230); this.Subfactions = new Subfaction[2] { new Subfaction(), new Subfaction() { DlcID = new SteamDLCIdentifiers?(SteamDLCIdentifiers.LiirAndMorrigiImmersionPack), MountName = "dlc_morrigi" } }; break; case "zuul": this._dlcID = new int?(203050); this.Subfactions = new Subfaction[2] { new Subfaction(), new Subfaction() { DlcID = new SteamDLCIdentifiers?(SteamDLCIdentifiers.TheHordeImmersionPack), MountName = "dlc_zuul" } }; break; case "loa": this.Subfactions = new Subfaction[1] { new Subfaction() { DlcID = new SteamDLCIdentifiers?(), MountName = "eof" } }; break; default: this.Subfactions = new Subfaction[1] { new Subfaction() }; break; } this.AssetPath = Path.Combine("factions", this.Name); this.WeaponModelPath = Path.Combine(this.AssetPath, "models", "weapons"); XmlElement source1 = Faction.LoadMergedXMLDocument(filename)[nameof(Faction)]; XmlElement xmlElement1 = source1["DiplomacyActionWeights"]; if (xmlElement1 != null) { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(ScriptHost.FileSystem, xmlElement1.InnerText); this.DiplomacyWeights = new DiplomacyActionWeights(xmlDocument); } else { this.DiplomacyWeights = new DiplomacyActionWeights(); } this.IndyDescrition = (IndyDesc)null; if (this.IsIndependent()) { XmlElement xmlElement2 = source1["IndyDescriptions"]; if (xmlElement2 != null) { this.IndyDescrition = new IndyDesc(); this.IndyDescrition.CoreSpecialAttributes = new List <SpecialAttribute>(); this.IndyDescrition.RandomSpecialAttributes = new List <SpecialAttribute>(); this.IndyDescrition.TechLevel = xmlElement2["TechLevel"] != null?int.Parse(xmlElement2["TechLevel"].InnerText) : 1; this.IndyDescrition.MinPlanetSize = xmlElement2["MinPlanetSize"] != null?int.Parse(xmlElement2["MinPlanetSize"].InnerText) : 0; this.IndyDescrition.MaxPlanetSize = xmlElement2["MaxPlanetSize"] != null?int.Parse(xmlElement2["MaxPlanetSize"].InnerText) : 0; this.IndyDescrition.StellarBodyType = xmlElement2["StellarBodyType"] != null ? xmlElement2["StellarBodyType"].InnerText : string.Empty; this.IndyDescrition.BaseFactionSuitability = xmlElement2["Hazard"] != null ? xmlElement2["Hazard"].GetAttribute("faction").ToLower() : string.Empty; this.IndyDescrition.Suitability = xmlElement2["Hazard"] != null ? (float)int.Parse(xmlElement2["Hazard"].GetAttribute("deviation")) : 0.0f; this.IndyDescrition.BasePopulationMod = xmlElement2["BasePopulationMod"] != null?float.Parse(xmlElement2["BasePopulationMod"].InnerText) : 1f; this.IndyDescrition.BiosphereMod = xmlElement2["BiosphereMod"] != null?float.Parse(xmlElement2["BiosphereMod"].InnerText) : 0.0f; this.IndyDescrition.TradeFTL = xmlElement2["TradeFTL"] != null?float.Parse(xmlElement2["TradeFTL"].InnerText) : 0.0f; } } this.ID = int.Parse(source1.GetAttribute(nameof(ID))); this.MaterialDictionaries = source1.OfType <XmlElement>().Where <XmlElement>((Func <XmlElement, bool>)(x => x.Name.Equals("MaterialDictionary", StringComparison.InvariantCulture))).Select <XmlElement, string>((Func <XmlElement, string>)(x => x.InnerText)).ToArray <string>(); this.BadgeTexturePaths = source1.OfType <XmlElement>().Where <XmlElement>((Func <XmlElement, bool>)(x => x.Name.Equals("Badge", StringComparison.InvariantCulture))).Select <XmlElement, string>((Func <XmlElement, string>)(x => x.GetAttribute("texture").ToLowerInvariant())).ToArray <string>(); this.AvatarTexturePaths = source1.OfType <XmlElement>().Where <XmlElement>((Func <XmlElement, bool>)(x => x.Name.Equals("Avatar", StringComparison.InvariantCulture))).Select <XmlElement, string>((Func <XmlElement, string>)(x => x.GetAttribute("texture").ToLowerInvariant())).ToArray <string>(); List <string> stringList1 = new List <string>(); List <string> stringList2 = new List <string>(); foreach (XmlElement element in source1.OfType <XmlElement>().Where <XmlElement>((Func <XmlElement, bool>)(x => x.Name == "TechTree"))) { stringList1.AddRange((IEnumerable <string>)AssetDatabase.LoadTechTreeModels(element)); stringList2.AddRange((IEnumerable <string>)AssetDatabase.LoadTechTreeRoots(element)); } this.TechTreeModels = (IEnumerable <string>)stringList1; this.TechTreeRoots = (IEnumerable <string>)stringList2; Random random = new Random(); this.DesignNames = new LocalizedNameGrabBag(source1[nameof(DesignNames)], random); this.EmpireNames = new LocalizedNameGrabBag(source1[nameof(EmpireNames)], random); this.UsesNPCCombatAI = bool.Parse(source1["UseNPCCombatAI"].InnerText); this.EntryPointOffset = source1[nameof(EntryPointOffset)] != null?float.Parse(source1[nameof(EntryPointOffset)].InnerText) : 0.0f; this.StarTearTechEnteryPointOffset = source1[nameof(StarTearTechEnteryPointOffset)] != null?float.Parse(source1[nameof(StarTearTechEnteryPointOffset)].InnerText) : 0.0f; this.PsionicPowerPerCrew = source1["PsiPowerPerCrew"] != null?float.Parse(source1["PsiPowerPerCrew"].InnerText) : 0.0f; this.PsionicPowerModifier = source1["PsiPowerModifier"] != null?float.Parse(source1["PsiPowerModifier"].InnerText) : 1f; this.CrewEfficiencyValue = source1[nameof(CrewEfficiencyValue)] != null?float.Parse(source1[nameof(CrewEfficiencyValue)].InnerText) : 1f; this.ResearchBoostFailureMod = source1["ResearchBoostAccidentMod"] != null?float.Parse(source1["ResearchBoostAccidentMod"].InnerText) : 1f; if (source1[nameof(NoAvatar)] != null) { this.NoAvatar = source1[nameof(NoAvatar)].GetAttribute("texture"); } List <FactionDecalInfo> source2 = new List <FactionDecalInfo>(); List <FactionDecalInfo> source3 = new List <FactionDecalInfo>(); XmlElement source4 = source1["FactionDamageDecals"]; if (source4 != null) { IEnumerable <XmlElement> source5 = source4.OfType <XmlElement>().Where <XmlElement>((Func <XmlElement, bool>)(x => x.Name.Equals("Structure", StringComparison.InvariantCulture))); foreach (XmlElement xmlElement2 in source5) { FactionDecalInfo fdi = new FactionDecalInfo(); fdi.DecalShipClass = (ShipClass)Enum.Parse(typeof(ShipClass), xmlElement2.GetAttribute("class")); if (!source2.Any <FactionDecalInfo>((Func <FactionDecalInfo, bool>)(x => x.DecalShipClass == fdi.DecalShipClass))) { List <DecalStageInfo> decalStageInfoList = new List <DecalStageInfo>(); foreach (XmlElement xmlElement3 in source5.Where <XmlElement>((Func <XmlElement, bool>)(x => (ShipClass)Enum.Parse(typeof(ShipClass), x.GetAttribute("class")) == fdi.DecalShipClass))) { DecalStageInfo decalStageInfo; decalStageInfo.DecalStage = int.Parse(xmlElement3.GetAttribute("stage")); decalStageInfo.DecalSize = float.Parse(xmlElement3.GetAttribute("size")); decalStageInfo.DecalMaterial = xmlElement3.GetAttribute("material"); decalStageInfoList.Add(decalStageInfo); } fdi.DecalStages = decalStageInfoList.ToArray(); source2.Add(fdi); } } foreach (XmlElement xmlElement2 in source4.OfType <XmlElement>().Where <XmlElement>((Func <XmlElement, bool>)(x => x.Name.Equals("Scorch", StringComparison.InvariantCulture)))) { FactionDecalInfo fdi = new FactionDecalInfo(); fdi.DecalShipClass = (ShipClass)Enum.Parse(typeof(ShipClass), xmlElement2.GetAttribute("class")); if (!source3.Any <FactionDecalInfo>((Func <FactionDecalInfo, bool>)(x => x.DecalShipClass == fdi.DecalShipClass))) { List <DecalStageInfo> decalStageInfoList = new List <DecalStageInfo>(); foreach (XmlElement xmlElement3 in source5.Where <XmlElement>((Func <XmlElement, bool>)(x => (ShipClass)Enum.Parse(typeof(ShipClass), x.GetAttribute("class")) == fdi.DecalShipClass))) { DecalStageInfo decalStageInfo; decalStageInfo.DecalStage = int.Parse(xmlElement3.GetAttribute("stage")); decalStageInfo.DecalSize = float.Parse(xmlElement3.GetAttribute("size")); decalStageInfo.DecalMaterial = xmlElement3.GetAttribute("material"); decalStageInfoList.Add(decalStageInfo); } fdi.DecalStages = decalStageInfoList.ToArray(); source3.Add(fdi); } } } this.StructDecalInfo = source2.ToArray(); this.ScorchDecalInfo = source3.ToArray(); XmlElement xmlElement4 = source1["BoardingActionModifiers"]; if (xmlElement4 != null) { this.BoardingActionMods.FreshAgentStrength = xmlElement4["FreshAgentStrength"] != null?float.Parse(xmlElement4["FreshAgentStrength"].InnerText) : 1f; this.BoardingActionMods.TiredAgentStrength = xmlElement4["TiredAgentStrength"] != null?float.Parse(xmlElement4["TiredAgentStrength"].InnerText) : 0.5f; this.BoardingActionMods.ExhaustedAgentStrength = xmlElement4["ExhaustedAgentStrength"] != null?float.Parse(xmlElement4["ExhaustedAgentStrength"].InnerText) : 0.25f; this.BoardingActionMods.LocationStrength.Default = xmlElement4["AgentLocationStrength"] != null?float.Parse(xmlElement4["AgentLocationStrength"].GetAttribute("default")) : 1f; this.BoardingActionMods.LocationStrength.Cruiser = xmlElement4["AgentLocationStrength"] != null?float.Parse(xmlElement4["AgentLocationStrength"].GetAttribute("cruiser")) : 1f; this.BoardingActionMods.LocationStrength.Dreadnought = xmlElement4["AgentLocationStrength"] != null?float.Parse(xmlElement4["AgentLocationStrength"].GetAttribute("dreadnought")) : 1f; this.BoardingActionMods.LocationStrength.Leviathan = xmlElement4["AgentLocationStrength"] != null?float.Parse(xmlElement4["AgentLocationStrength"].GetAttribute("leviathan")) : 1f; this.BoardingActionMods.EfficiencyVSBoarding.Default = xmlElement4["EfficiencyVSBoarding"] != null?float.Parse(xmlElement4["EfficiencyVSBoarding"].GetAttribute("default")) : 0.5f; this.BoardingActionMods.EfficiencyVSBoarding.Cruiser = xmlElement4["EfficiencyVSBoarding"] != null?float.Parse(xmlElement4["EfficiencyVSBoarding"].GetAttribute("cruiser")) : 0.5f; this.BoardingActionMods.EfficiencyVSBoarding.Dreadnought = xmlElement4["EfficiencyVSBoarding"] != null?float.Parse(xmlElement4["EfficiencyVSBoarding"].GetAttribute("dreadnought")) : 0.5f; this.BoardingActionMods.EfficiencyVSBoarding.Leviathan = xmlElement4["EfficiencyVSBoarding"] != null?float.Parse(xmlElement4["EfficiencyVSBoarding"].GetAttribute("leviathan")) : 0.5f; } else { this.BoardingActionMods.FreshAgentStrength = 1f; this.BoardingActionMods.TiredAgentStrength = 0.5f; this.BoardingActionMods.ExhaustedAgentStrength = 0.25f; this.BoardingActionMods.LocationStrength.Default = 1f; this.BoardingActionMods.LocationStrength.Cruiser = 1f; this.BoardingActionMods.LocationStrength.Dreadnought = 1f; this.BoardingActionMods.LocationStrength.Leviathan = 1f; this.BoardingActionMods.EfficiencyVSBoarding.Default = 0.5f; this.BoardingActionMods.EfficiencyVSBoarding.Cruiser = 0.5f; this.BoardingActionMods.EfficiencyVSBoarding.Dreadnought = 0.5f; this.BoardingActionMods.EfficiencyVSBoarding.Leviathan = 0.5f; } XmlElement source6 = source1["DefaultDiplomacyReactions"]; if (source6 != null) { foreach (XmlElement xmlElement2 in source6.OfType <XmlElement>()) { string attribute = xmlElement2.GetAttribute("faction"); if (!this._defaultReactionValue.ContainsKey(attribute)) { this._defaultReactionValue.Add(attribute, Math.Min(Math.Max(int.Parse(xmlElement2.GetAttribute("value")), DiplomacyInfo.MinDeplomacyRelations), DiplomacyInfo.MaxDeplomacyRelations)); } } } XmlElement source7 = source1["ImmigrationPopBonus"]; if (source7 != null) { foreach (XmlElement xmlElement2 in source7.OfType <XmlElement>()) { string attribute = xmlElement2.GetAttribute("faction"); if (!this._ImmigrationPopBonusValue.ContainsKey(attribute)) { this._ImmigrationPopBonusValue.Add(attribute, float.Parse(xmlElement2.GetAttribute("value"))); } } } XmlElement source8 = source1["SpyingBonus"]; if (source8 != null) { foreach (XmlElement xmlElement2 in source8.OfType <XmlElement>()) { string attribute = xmlElement2.GetAttribute("faction"); if (!this._SpyingBonusValue.ContainsKey(attribute)) { this._SpyingBonusValue.Add(attribute, float.Parse(xmlElement2.GetAttribute("value"))); } } } this.StratModifiers = source1[nameof(StratModifiers)]; XmlElement xmlElement5 = source1["SalvageModifiers"]; if (xmlElement5 != null) { this.RepSel = int.Parse(xmlElement5["RepSal"].InnerText); this.DefaultRepSel = int.Parse(xmlElement5["default"].InnerText); } XmlElement xmlElement6 = source1["MoralEventModifiers"]; if (xmlElement6 != null) { foreach (GovernmentInfo.GovernmentType key1 in Enum.GetValues(typeof(GovernmentInfo.GovernmentType))) { XmlElement xmlElement2 = xmlElement6[key1.ToString()]; if (xmlElement2 != null) { foreach (MoralEvent key2 in Enum.GetValues(typeof(MoralEvent))) { XmlElement xmlElement3 = xmlElement2[key2.ToString()]; if (xmlElement3 != null) { if (!this._factionSpecificMoral.ContainsKey(key1)) { this._factionSpecificMoral.Add(key1, new Dictionary <MoralEvent, int>()); } this._factionSpecificMoral[key1].Add(key2, int.Parse(xmlElement3.InnerText)); } } } } } XmlElement xmlElement7 = source1["ResearchRates"]; if (xmlElement7 != null) { foreach (AIStance aiStance in Enum.GetValues(typeof(AIStance))) { XmlElement xmlElement2 = xmlElement7[aiStance.ToString()]; if (xmlElement2 != null) { float val1 = float.Parse(xmlElement2.InnerText); this.AIFastResearchRate[(int)aiStance] = Math.Max(Math.Min(val1, 1f), 0.0f); } } } XmlElement source9 = source1[nameof(InitialDesigns)]; if (source9 != null) { string weaponBiasTechFamilyID = source9.GetAttribute("weaponbias"); this.InitialDesigns = source9.OfType <XmlElement>().Where <XmlElement>((Func <XmlElement, bool>)(x => x.Name == "Design")).Select <XmlElement, InitialDesign>((Func <XmlElement, InitialDesign>)(y => new InitialDesign() { Name = y.GetAttribute("name"), WeaponBiasTechFamilyID = weaponBiasTechFamilyID, Sections = y.OfType <XmlElement>().Where <XmlElement>((Func <XmlElement, bool>)(z => z.Name == "Section")).Select <XmlElement, string>((Func <XmlElement, string>)(w => w.GetAttribute("name"))).ToArray <string>() })).ToArray <InitialDesign>(); } else { this.InitialDesigns = (InitialDesign[])null; } }