internal void addContract(Guid id, contractContainer c) { if (!masterList.ContainsKey(id)) { masterList.Add(id, c); } else { DMC_MBE.LogFormatted_DebugOnly("Contract Already Present In List"); } }
private static bool DMAsteroidAvailable() { if (_DMAst != null) { return(true); } if (DMAstRun) { return(false); } DMAstRun = true; try { Type DMAstType = AssemblyLoader.loadedAssemblies.SelectMany(a => a.assembly.GetExportedTypes()) .SingleOrDefault(t => t.FullName == DMAsteroidTypeName); if (DMAstType == null) { DMC_MBE.LogFormatted_DebugOnly("DMagic Asteroid Type Not Found"); return(false); } _DMAstType = DMAstType; MethodInfo DMastMethod = DMAstType.GetMethod("PartName"); if (DMastMethod == null) { DMC_MBE.LogFormatted_DebugOnly("DMagic Asteroid String Method Not Found"); return(false); } else { _DMAst = (DMAstSci)Delegate.CreateDelegate(typeof(DMAstSci), DMastMethod); DMC_MBE.LogFormatted("DMagic Asteroid Reflection Method Assigned"); } return(_DMAst != null); } catch (Exception e) { DMC_MBE.LogFormatted("Exception While Loading DMagic Asteroid Accessor: {0}", e); } return(false); }
private static bool MCEAvailable() { if (_MCE != null) { return(true); } if (MCERun) { return(false); } MCERun = true; try { Type MCEType = AssemblyLoader.loadedAssemblies.SelectMany(a => a.assembly.GetExportedTypes()) .SingleOrDefault(t => t.FullName == MCETypeName); if (MCEType == null) { DMC_MBE.LogFormatted_DebugOnly("Mision Controller Type Not Found"); return(false); } _MCEType = MCEType; MethodInfo MCEMethod = MCEType.GetMethod("iPartName", new Type[] { typeof(ContractParameter) }); if (MCEMethod == null) { DMC_MBE.LogFormatted_DebugOnly("Mission Controller String Method Not Found"); return(false); } _MCE = (MCESci)Delegate.CreateDelegate(typeof(MCESci), MCEMethod); DMC_MBE.LogFormatted("Mission Control Reflection Method Assigned"); return(_MCE != null); } catch (Exception e) { DMC_MBE.LogFormatted("Exception While Loading Mission Controller Accessor: {0}", e); } return(false); }
private static bool FPAssemblyLoaded() { if (_FP != null) { return(true); } if (FPRun) { return(false); } FPRun = true; try { Type FPType = AssemblyLoader.loadedAssemblies.SelectMany(a => a.assembly.GetExportedTypes()) .SingleOrDefault(t => t.FullName == FPContractTypeName); if (FPType == null) { DMC_MBE.LogFormatted_DebugOnly("Fine Print Type Not Found"); return(false); } _FPType = FPType; MethodInfo FPMethod = FPType.GetMethod("PartName", new Type[] { typeof(ContractParameter) }); if (FPMethod == null) { DMC_MBE.LogFormatted_DebugOnly("Fine Print String Method Not Found"); return(false); } _FP = (FPSci)Delegate.CreateDelegate(typeof(FPSci), FPMethod); DMC_MBE.LogFormatted("Fine Print Reflection Method Assigned"); return(_FP != null); } catch (Exception e) { DMC_MBE.LogFormatted("Exception While Loading Fine Print Accessor: {0}", e); } return(false); }
private void contractChanged(float[] originals, contractTypeContainer c) { DMC_MBE.LogFormatted_DebugOnly("Contract Value Event Fired; Type: {0}", c.Name); var cList = ContractSystem.Instance.Contracts; for (int i = 0; i < cList.Count; i++) { if (cList[i].ContractState == Contract.State.Active || cList[i].ContractState == Contract.State.Offered) { updateContractValues(c, cList[i], originals); } } for (int j = 0; j < masterList.Count; j++) { masterList.ElementAt(j).Value.updateContractInfo(); } }
private void updateContractValues(contractTypeContainer cC, Contract c, float[] O) { if (cTypeList.ContainsValue(cC)) { if (c.GetType() == cC.ContractType) { DMC_MBE.LogFormatted_DebugOnly("Contract Values Updating; Type: {0}", cC.Name); DMC_MBE.LogFormatted_DebugOnly("Original Contract Values: {0}; New Values: {1}", printArray(O), printArray(cC.ContractValues)); c.FundsCompletion = (c.FundsCompletion / O[0]) * cC.RewardFund; c.FundsAdvance = (c.FundsAdvance / O[1]) * cC.AdvanceFund; c.FundsFailure = (c.FundsFailure / O[2]) * cC.PenaltyFund; c.ReputationCompletion = (c.ReputationCompletion / O[3]) * cC.RewardRep; c.ReputationFailure = (c.ReputationFailure / O[4]) * cC.PenaltyRep; c.ScienceCompletion = (c.ScienceCompletion / O[5]) * cC.RewardScience; c.TimeDeadline = (c.TimeDeadline / O[6]) * cC.DurationTime; } } }
private void updateParameterValues(paramTypeContainer pC, Contract c, float[] originals) { List <ContractParameter> modifyList = new List <ContractParameter>(); var cParams = c.AllParameters; for (int i = 0; i < cParams.Count(); i++) { if (cParams.ElementAt(i).GetType() == pC.ParamType) { DMC_MBE.LogFormatted_DebugOnly("Found Parameter Of Type: {0}; Updating Values", pC.Name); modifyList.Add(cParams.ElementAt(i)); } } if (modifyList.Count > 0) { DMC_MBE.LogFormatted_DebugOnly("Found {0} Parameters Of Type: {1}", modifyList.Count, pC.Name); updateParameterValues(pC, modifyList, originals); } }
private void updateParameterValues(paramTypeContainer pC, List <ContractParameter> pL, float[] O) { foreach (ContractParameter p in pL) { if (pTypeList.ContainsValue(pC)) { if (p.GetType() == pC.ParamType) { DMC_MBE.LogFormatted_DebugOnly("Updating Param Values; Type: {0}", pC.Name); DMC_MBE.LogFormatted_DebugOnly("Original Param Values: {0}; New Values: {1}", printArray(O), printArray(pC.ParamValues)); p.FundsCompletion = (p.FundsCompletion / O[0]) * pC.RewardFund; p.FundsFailure = (p.FundsFailure / O[1]) * pC.PenaltyFund; p.ReputationCompletion = (p.ReputationCompletion / O[2]) * pC.RewardRep; p.ReputationFailure = (p.ReputationFailure / O[3]) * pC.PenaltyRep; p.ScienceCompletion = (p.ScienceCompletion / O[4]) * pC.RewardScience; } } } }
/// <summary> /// Sets the current Skin to one of the Pre-Defined types /// </summary> /// <param name="DefaultSkin">Which predefined skin to use</param> internal static void SetCurrent(DefSkinType DefaultSkin) { DMC_MBE.LogFormatted_DebugOnly("Setting GUISkin to {0}", DefaultSkin); GUISkin OldSkin = _CurrentSkin; switch (DefaultSkin) { case DefSkinType.Unity: _CurrentSkin = DefUnitySkin; break; case DefSkinType.KSP: _CurrentSkin = DefKSPSkin; break; //case DefSkinType.None: _CurrentSkin = new GUISkin(); break; default: _CurrentSkin = DefKSPSkin; break; } //Now set the tooltip style as well SetCurrentTooltip(); if (OldSkin != CurrentSkin && OnSkinChanged != null) { OnSkinChanged(); } }
/// <summary> /// Sets the current skin to one of the custom skins /// </summary> /// <param name="SkinID">The string ID of the custom skin</param> internal static void SetCurrent(String SkinID) { DMC_MBE.LogFormatted_DebugOnly("Setting GUISkin to {0}", SkinID); GUISkin OldSkin = _CurrentSkin; //check the skin exists, and throw a log line if it doesnt if (List.ContainsKey(SkinID)) { _CurrentSkin = List[SkinID]; } else { DMC_MBE.LogFormatted("Unable to change GUISkin to {0}, GUISkin not found", SkinID); } //Now set the tooltip style as well SetCurrentTooltip(); if (OldSkin != CurrentSkin && OnSkinChanged != null) { OnSkinChanged(); } }
private void updateParameterValues(Contract c) { if (ContractSystem.Instance.Contracts.Contains(c)) { DMC_MBE.LogFormatted_DebugOnly("Updating Parameters For Newly Offered Contract"); var cParams = c.AllParameters; if (cParams.Count() > 0) { for (int i = 0; i < cParams.Count(); i++) { string name = cParams.ElementAt(i).GetType().Name; if (pTypeList.ContainsKey(name)) { updateParameterValues(pTypeList[name], new List <ContractParameter>() { cParams.ElementAt(i) }, new float[5] { 1, 1, 1, 1, 1 }); } } } } }
//Convert all of our saved strings into the appropriate arrays for each game scene public override void OnLoad(ConfigNode node) { instance = this; try { //The first step is manually checking for active contracts from the Game ConfigNode (ie persistent.sfs file); the count of active contracts will be used later when the window is loading ConfigNode gameNode = HighLogic.CurrentGame.config; if (gameNode != null) { ConfigNode contractSystemNode = gameNode.GetNodes("SCENARIO").FirstOrDefault(c => c.GetValue("name") == "ContractSystem"); if (contractSystemNode != null) { ConfigNode cNode = contractSystemNode.GetNode("CONTRACTS"); if (cNode != null) { foreach (ConfigNode C in cNode.GetNodes("CONTRACT")) { if (C == null) { continue; } if (C.HasValue("autoAccept")) { if (C.GetValue("autoAccept") == "True") { continue; } } if (C.HasValue("state")) { if (C.GetValue("state") == "Active") { contractCount++; } } } } else { DMC_MBE.LogFormatted("Contract System Can't Be Checked... Node Invalid"); } } } ConfigNode scenes = node.GetNode("Contracts_Window_Parameters"); if (scenes != null) { windowPos = stringSplit(scenes.GetValue("WindowPosition")); windowVisible = stringSplitBool(scenes.GetValue("WindowVisible")); int[] winPos = new int[4] { windowPos[4 * currentScene(HighLogic.LoadedScene)], windowPos[(4 * currentScene(HighLogic.LoadedScene)) + 1], windowPos[(4 * currentScene(HighLogic.LoadedScene)) + 2], windowPos[(4 * currentScene(HighLogic.LoadedScene)) + 3] }; //All saved contract missions are loaded here //Each mission has a separate contract list foreach (ConfigNode m in scenes.GetNodes("Contracts_Window_Mission")) { if (m == null) { continue; } string name; string activeString = ""; string hiddenString = ""; string vesselString = ""; bool ascending, showActive; int sortMode; bool master = false; if (m.HasValue("MissionName")) { name = m.GetValue("MissionName"); } else { continue; } if (name == "MasterMission") { master = true; } if (m.HasValue("ActiveListID")) { activeString = m.GetValue("ActiveListID"); } if (m.HasValue("HiddenListID")) { hiddenString = m.GetValue("HiddenListID"); } if (m.HasValue("VesselIDs")) { vesselString = m.GetValue("VesselIDs"); } if (!bool.TryParse(m.GetValue("AscendingSort"), out ascending)) { ascending = true; } if (!bool.TryParse(m.GetValue("ShowActiveList"), out showActive)) { showActive = true; } if (!int.TryParse(m.GetValue("SortMode"), out sortMode)) { sortMode = 0; } contractMission mission = new contractMission(name, activeString, hiddenString, vesselString, ascending, showActive, sortMode, master); if (master) { masterMission = mission; DMC_MBE.LogFormatted_DebugOnly("Setting Master Mission During Load"); } if (!missionList.Contains(name)) { missionList.Add(name, mission); } } loadWindow(winPos); } } catch (Exception e) { DMC_MBE.LogFormatted("Contracts Window Settings Cannot Be Loaded: {0}", e); } }
internal parameterContainer(ContractParameter cP, int Level, string PartTestName) { cParam = cP; showNote = false; level = Level; //For some reason parameter rewards/penalties reset to zero upon completion/failure paramRewards(cP); paramPenalties(cP); if (level < 4) { for (int i = 0; i < cParam.ParameterCount; i++) { ContractParameter param = cParam.GetParameter(i); addSubParam(param, level + 1); } } if (!string.IsNullOrEmpty(PartTestName)) { if (PartTestName == "partTest") { part = ((PartTest)cParam).tgtPartInfo; DMC_MBE.LogFormatted_DebugOnly("Part Assigned For Stock Part Test"); } else if (PartTestName == "MCEScience") { if (contractAssembly.MCELoaded) { part = PartLoader.Instance.parts.FirstOrDefault(p => p.partPrefab.partInfo.title == contractAssembly.MCEPartName(cParam)); if (part != null) { DMC_MBE.LogFormatted_DebugOnly("Part Assigned For Mission Controller Contract"); } else { DMC_MBE.LogFormatted_DebugOnly("Part Not Found"); } } } else if (PartTestName == "DMcollectScience") { if (contractAssembly.DMLoaded) { part = PartLoader.getPartInfoByName(contractAssembly.DMagicSciencePartName(cParam)); if (part != null) { DMC_MBE.LogFormatted_DebugOnly("Part Assigned For DMagic Contract"); } else { DMC_MBE.LogFormatted_DebugOnly("Part Not Found"); } } } else if (PartTestName == "DManomalyScience") { if (contractAssembly.DMALoaded) { part = PartLoader.getPartInfoByName(contractAssembly.DMagicAnomalySciencePartName(cParam)); if (part != null) { DMC_MBE.LogFormatted_DebugOnly("Part Assigned For DMagic Anomaly Contract"); } else { DMC_MBE.LogFormatted_DebugOnly("Part Not Found"); } } } else if (PartTestName == "DMasteroidScience") { if (contractAssembly.DMAstLoaded) { part = PartLoader.getPartInfoByName(contractAssembly.DMagicAsteroidSciencePartName(cParam)); if (part != null) { DMC_MBE.LogFormatted_DebugOnly("Part Assigned For DMagic Asteroid Contract"); } else { DMC_MBE.LogFormatted_DebugOnly("Part Not Found"); } } } else if (PartTestName == "FinePrint") { part = PartLoader.getPartInfoByName(contractAssembly.FPPartName(cParam)); if (part != null) { DMC_MBE.LogFormatted_DebugOnly("Part Assigned For Fine Print Contract"); } else { DMC_MBE.LogFormatted_DebugOnly("Part Not Found"); } } else { part = null; } } }
private void contractOffered(Contract c) { Type contractT = c.GetType(); contractTypeContainer cC; if (cTypeList.ContainsKey(contractT.Name)) { cC = cTypeList[contractT.Name]; } else { DMC_MBE.LogFormatted("Contract Type: {0} Not Present; Allowing All Offers", contractT.Name); return; } if (cC.MaxActive < 10f || cC.MaxOffer < 10f) { var cList = ContractSystem.Instance.Contracts; int active = 0; int offered = 0; for (int i = 0; i < cList.Count; i++) { if (cList[i].GetType() == contractT) { if (cList[i].ContractState == Contract.State.Active) { active++; } else if (cList[i].ContractState == Contract.State.Offered) { offered++; } } } int remainingSlots = (int)(cC.MaxActive * 10) - active; if ((offered - 1) >= (int)(cC.MaxOffer * 10) && cC.MaxOffer < 10f) { c.Unregister(); ContractSystem.Instance.Contracts.Remove(c); DMC_MBE.LogFormatted("Removing Contract Of Type: {0} From The Offered List; Offered Limit Exceeded", contractT.Name); } else if ((offered - 1) >= remainingSlots && cC.MaxActive < 10f) { c.Unregister(); ContractSystem.Instance.Contracts.Remove(c); DMC_MBE.LogFormatted("Removing Contract Of Type: {0} From The Offered List; Active Limit Exceeded", contractT.Name); } else { updateContractValues(cC, c, new float[9] { 1, 1, 1, 1, 1, 1, 1, 1, 1 }); updateParameterValues(c); DMC_MBE.LogFormatted_DebugOnly("Contract: {0} Added To Offered List", contractT.Name); } } else { updateContractValues(cC, c, new float[9] { 1, 1, 1, 1, 1, 1, 1, 1, 1 }); updateParameterValues(c); DMC_MBE.LogFormatted_DebugOnly("Contract: {0} Added To Offered List", contractT.Name); } }