protected static IEnumerable <T> AllDescendents <T>(ContractParameter p) where T : ContractParameter { for (int i = 0; i < p.ParameterCount; i++) { ContractParameter child = p.GetParameter(i); if (child is T) { yield return(child as T); } foreach (ContractParameter grandChild in AllDescendents <T>(child)) { yield return(grandChild as T); } } }
public parameterContainer(contractContainer Root, ContractParameter cP, int Level) { root = Root; cParam = cP; cParamType = cParam.GetType(); try { title = cParam.Title; } catch (Exception e) { Debug.LogError("[Contract Parser] Contract Parameter Title not set, using type name...\n" + e); title = cParam.GetType().Name; } try { notes = cParam.Notes; } catch (Exception e) { Debug.LogError("[Contract Parser] Contract Parameter Notes not set, blank notes used...\n" + e); notes = ""; } level = Level; paramRewards(); paramPenalties(); waypoint = checkForWaypoint(); customNotes = setCustomNotes(); if (level < 4) { for (int i = 0; i < cParam.ParameterCount; i++) { ContractParameter param = cParam.GetParameter(i); addSubParam(param, level + 1); } } }
private static bool handleContractsForCrew(Vessel vessel, bool arrive, bool depart, ProtoCrewMember crew) { //print("handling crew"); foreach (Contract con in Contracts.ContractSystem.Instance.Contracts) { if (con.ContractState == Contract.State.Active) { if (ReferenceEquals(con.GetType(), typeof(FinePrint.Contracts.TourismContract))) { for (int i = 0; i < con.ParameterCount; i++) { ContractParameter conpara1 = con.GetParameter(i); if (ReferenceEquals(conpara1.GetType(), typeof(FinePrint.Contracts.Parameters.KerbalTourParameter)) && conpara1.State != Contracts.ParameterState.Complete) { FinePrint.Contracts.Parameters.KerbalTourParameter ktp = (FinePrint.Contracts.Parameters.KerbalTourParameter)conpara1; if (crew.name == ktp.kerbalName) { // complete destinations parameters on arrive for kerbals on vessel if (arrive) { for (int u = 0; u < conpara1.ParameterCount; u++) { ContractParameter conpara2 = conpara1.GetParameter(u); if (ReferenceEquals(conpara2.GetType(), typeof(FinePrint.Contracts.Parameters.KerbalDestinationParameter)) && conpara2.State != Contracts.ParameterState.Complete) { FinePrint.Contracts.Parameters.KerbalDestinationParameter kds = (FinePrint.Contracts.Parameters.KerbalDestinationParameter)conpara2; if (RmmUtil.AllowedBody(vessel.mainBody.name)) { if (RmmUtil.HomeBody(kds.targetBody.name) && (kds.targetType == FlightLog.EntryType.Orbit || kds.targetType == FlightLog.EntryType.Suborbit)) { //print("complete1"); CompleteContractParameter(kds); return(false); } } if (RmmUtil.AllowedBody(vessel.mainBody.name) && !RmmUtil.HomeBody(vessel.mainBody.name)) { if (kds.targetBody.name == vessel.mainBody.name && (kds.targetType == FlightLog.EntryType.Orbit || kds.targetType == FlightLog.EntryType.Flyby)) { //print("complete2"); CompleteContractParameter(kds); return(false); } } } } } // complete kerbaltour parameters on depart which have all their destinations completed if (depart) { if (conpara1.State != Contracts.ParameterState.Complete) { bool allDestinationsSucceeded = true; for (int u = 0; u < conpara1.ParameterCount; u++) { ContractParameter conpara2 = conpara1.GetParameter(u); if (conpara2.State != Contracts.ParameterState.Complete) { allDestinationsSucceeded = false; } } if (depart && allDestinationsSucceeded) { //print("complete3"); CompleteContractParameter(ktp); HighLogic.CurrentGame.CrewRoster.Remove(crew); return(false); } } } } } } } } } return(true); }
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; } } }
public parameterContainer(contractContainer Root, ContractParameter cP, int Level) { root = Root; cParam = cP; try { title = cParam.Title; } catch (Exception e) { Debug.LogError("[Contract Parser] Contract Parameter Title not set, using type name...\n" + e); title = cParam.GetType().Name; } try { notes = cParam.Notes; } catch (Exception e) { Debug.LogError("[Contract Parser] Contract Parameter Notes not set, blank notes used...\n" + e); notes = ""; } level = Level; paramRewards(); paramPenalties(); waypoint = checkForWaypoint(); customNotes = setCustomNotes(); if (level < 4) { for (int i = 0; i < cParam.ParameterCount; i++) { ContractParameter param = cParam.GetParameter(i); addSubParam(param, level + 1); } } }
internal parameterContainer(contractContainer Root, ContractParameter cP, int Level, string PartTestName) { root = Root; cParam = cP; showNote = false; level = Level; paramRewards(cP); paramPenalties(cP); title = cParam.Title; notes = cParam.Notes; 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 = ((Contracts.Parameters.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; } }