/// <summary> /// This converts the KACAlarmList actual object to a new List for consumption /// </summary> /// <param name="actualAlarmList"></param> /// <returns></returns> private KACAlarmList ExtractAlarmList(Object actualAlarmList) { KACAlarmList ListToReturn = new KACAlarmList(); try { //iterate each "value" in the dictionary for (var i = ((IList)actualAlarmList).Count - 1; i >= 0; i--) { var item = ((IList)actualAlarmList)[i]; //foreach (var item in (IList)actualAlarmList) //{ KACAlarm r1 = new KACAlarm(item); ListToReturn.Add(r1); } } catch (Exception) { //LogFormatted("Arrggg: {0}", ex.Message); //throw ex; // } return(ListToReturn); }
/// <summary> /// This converts the KACAlarmList actual object to a new List for consumption /// </summary> /// <param name="actualAlarmList"></param> /// <returns></returns> private KACAlarmList ExtractAlarmList(Object actualAlarmList) { KACAlarmList ListToReturn = new KACAlarmList(); try { //iterate each "value" in the dictionary foreach (var item in (IList)actualAlarmList) { KACAlarm r1 = new KACAlarm(item); ListToReturn.Add(r1); } } catch (Exception ex) { LogFormatted("ExtractAlarmList failed: {0}", ex.Message); //throw ex; // } return(ListToReturn); }
private void ParseAlarmsAndAffectWarpAndPause(double SecondsTillNextUpdate) { KACAlarmList alarmsToAdd = new KACAlarmList(); KACAlarm alarmAddTemp; foreach (KACAlarm tmpAlarm in alarms) { //reset each alarms WarpInfluence flag if (KACWorkerGameState.CurrentWarpInfluenceStartTime == null) tmpAlarm.WarpInfluence = false; else //if the lights been on long enough if (KACWorkerGameState.CurrentWarpInfluenceStartTime.AddSeconds(settings.WarpTransitions_ShowIndicatorSecs) < DateTime.Now) tmpAlarm.WarpInfluence = false; //Update Remaining interval for each alarm if (tmpAlarm.TypeOfAlarm != KACAlarm.AlarmTypeEnum.EarthTime) tmpAlarm.Remaining.UT = tmpAlarm.AlarmTime.UT - KACWorkerGameState.CurrentTime.UT; else tmpAlarm.Remaining.UT = (EarthTimeDecode(tmpAlarm.AlarmTime.UT) - DateTime.Now).TotalSeconds; //set triggered for passed alarms so the OnGUI part can draw the window later //if ((KACWorkerGameState.CurrentTime.UT >= tmpAlarm.AlarmTime.UT) && (tmpAlarm.Enabled) && (!tmpAlarm.Triggered)) if ((tmpAlarm.Remaining.UT<=0) && (tmpAlarm.Enabled) && (!tmpAlarm.Triggered)) { //if (tmpAlarm.ActionedAt > 0) //{ // LogFormatted("Suppressing Alarm due to Actioned At being set:{0}", tmpAlarm.Name); // tmpAlarm.Triggered = true; // tmpAlarm.Actioned = true; // tmpAlarm.AlarmWindowClosed = true; //} //else //{ LogFormatted("Triggering Alarm - " + tmpAlarm.Name); tmpAlarm.Triggered = true; if (CreateAlarmRepeats(tmpAlarm, out alarmAddTemp)) alarmsToAdd.Add(alarmAddTemp); try { APIInstance_AlarmStateChanged(tmpAlarm, AlarmStateEventsEnum.Triggered); } catch (Exception ex) { LogFormatted("Error Raising API Event-Triggered Alarm: {0}\r\n{1}", ex.Message, ex.StackTrace); } //If we are simply past the time make sure we halt the warp //only do this in flight mode //if (!ViewAlarmsOnly) //{ if (tmpAlarm.PauseGame) { LogFormatted(String.Format("{0}-Pausing Game", tmpAlarm.Name)); if (tmpAlarm.Actions.Message != AlarmActions.MessageEnum.Yes) tmpAlarm.Actions.Message = AlarmActions.MessageEnum.Yes; //Make sure we cancle autowarp if its engaged TimeWarp.fetch.CancelAutoWarp(); TimeWarp.SetRate(0, true); FlightDriver.SetPause(true); } else if (tmpAlarm.HaltWarp) { if (!FlightDriver.Pause) { LogFormatted(String.Format("{0}-Halt Warp", tmpAlarm.Name)); //Make sure we cancle autowarp if its engaged TimeWarp.fetch.CancelAutoWarp(); TimeWarp.SetRate(0, true); } else { LogFormatted(String.Format("{0}-Game paused, skipping Halt Warp", tmpAlarm.Name)); } } //} //} } //skip this if we aren't in flight mode //if (!ViewAlarmsOnly) //{ //if in the next two updates we would pass the alarm time then slow down the warp if (!tmpAlarm.Actioned && tmpAlarm.Enabled && (tmpAlarm.HaltWarp || tmpAlarm.PauseGame)) { if (settings.WarpTransitions_Instant) { Double TimeNext = KACWorkerGameState.CurrentTime.UT + SecondsTillNextUpdate * 2; //LogFormatted(CurrentTime.UT.ToString() + "," + TimeNext.ToString()); if (TimeNext > tmpAlarm.AlarmTime.UT) { tmpAlarm.WarpInfluence = true; KACWorkerGameState.CurrentlyUnderWarpInfluence = true; KACWorkerGameState.CurrentWarpInfluenceStartTime = DateTime.Now; TimeWarp w = TimeWarp.fetch; if (w.current_rate_index > 0) { LogFormatted("Reducing Warp"); //Make sure we cancel autowarp if its engaged TimeWarp.fetch.CancelAutoWarp(); TimeWarp.SetRate(w.current_rate_index - 1, true); } } } else { if (WarpTransitionCalculator.UTToRateTimesOne * settings.WarpTransitions_UTToRateTimesOneTenths / 10 > tmpAlarm.AlarmTime.UT - KACWorkerGameState.CurrentTime.UT) { tmpAlarm.WarpInfluence = true; KACWorkerGameState.CurrentlyUnderWarpInfluence = true; KACWorkerGameState.CurrentWarpInfluenceStartTime = DateTime.Now; TimeWarp w = TimeWarp.fetch; if (w.current_rate_index > 0 && WarpTransitionCalculator.UTToRateTimesOne > (tmpAlarm.AlarmTime.UT - KACWorkerGameState.CurrentTime.UT)) { LogFormatted("Reducing Warp-Transition Instant"); //Make sure we cancel autowarp if its engaged TimeWarp.fetch.CancelAutoWarp(); TimeWarp.SetRate(w.current_rate_index - 1, true); } else if (w.current_rate_index > 0) { LogFormatted("Reducing Warp-Transition"); //Make sure we cancel autowarp if its engaged TimeWarp.fetch.CancelAutoWarp(); TimeWarp.SetRate(w.current_rate_index - 1, false); } } } } //} if (tmpAlarm.Triggered && !tmpAlarm.Actioned) { tmpAlarm.Actioned = true; //Play the sounds if necessary if (tmpAlarm.Actions.PlaySound) { //first get the right sound AlarmSound s = settings.AlarmSounds.FirstOrDefault(st => st.Types.Contains(tmpAlarm.TypeOfAlarm)); if (s == null || s.Enabled == false) { s = settings.AlarmSounds[0]; } if (!tmpAlarm.ShowMessage && s.RepeatCount > 5) { audioController.Play(KACResources.clipAlarms[s.SoundName], 5); } else { audioController.Play(KACResources.clipAlarms[s.SoundName], s.RepeatCount); } } //if (tmpAlarm.AlarmActionConvert == KACAlarm.AlarmActionEnum.KillWarpOnly // || tmpAlarm.AlarmActionConvert == KACAlarm.AlarmActionEnum.DoNothingDeleteWhenPassed // || tmpAlarm.AlarmActionConvert == KACAlarm.AlarmActionEnum.DoNothing) if((tmpAlarm.Actions.Message==AlarmActions.MessageEnum.No) || ( tmpAlarm.Actions.Message == AlarmActions.MessageEnum.YesIfOtherVessel && KACWorkerGameState.CurrentVessel!=null && tmpAlarm.VesselID == KACWorkerGameState.CurrentVessel.id.ToString() )) { tmpAlarm.AlarmWindowClosed = true; try { APIInstance_AlarmStateChanged(tmpAlarm, AlarmStateEventsEnum.Closed); } catch (Exception ex) { LogFormatted("Error Raising API Event-Closed Alarm: {0}\r\n{1}", ex.Message, ex.StackTrace); } } LogFormatted("Actioning Alarm"); LogFormatted("{0}",tmpAlarm.Actions); } } //Add any extra alarms that were created in the parse loop foreach (KACAlarm a in alarmsToAdd) { alarms.Add(a); } // Delete the do nothing/delete alarms - One loop to find the ones to delete - cant delete inside the foreach or it breaks the iterator List<KACAlarm> ToDelete = new List<KACAlarm>(); //foreach (KACAlarm tmpAlarm in alarms.Where(a => (a.AlarmActionConvert == KACAlarm.AlarmActionEnum.DoNothingDeleteWhenPassed) || (a.ActionDeleteWhenDone))) foreach (KACAlarm tmpAlarm in alarms.Where(a => a.Actions.Warp == AlarmActions.WarpEnum.DoNothing && a.Actions.DeleteWhenDone )) { if (tmpAlarm.Triggered && tmpAlarm.Actioned) ToDelete.Add(tmpAlarm); } foreach (KACAlarm a in ToDelete) { alarms.Remove(a); } }
internal static Boolean Loadv2Alarms(out String LoadMessage, out KACAlarmList oldAlarms) { oldAlarms = new KACAlarmList(); Boolean blnReturn = false; try { //Find old files String[] AlarmFiles = System.IO.Directory.GetFiles(KACUtils.PathTriggerTech, "Alarms-*.txt", System.IO.SearchOption.AllDirectories); String FileToLoad = ""; foreach (String item in AlarmFiles) { System.IO.FileInfo File = new System.IO.FileInfo(item); MonoBehaviourExtended.LogFormatted_DebugOnly("File:{0}", File.Name); if (File.Name == String.Format("Alarms-{0}.txt", HighLogic.CurrentGame.Title)) { FileToLoad = File.FullName; break; } } if (FileToLoad != "") { //parse it to a new list MonoBehaviourExtended.LogFormatted("Loading {0}", FileToLoad); String strFile = System.IO.File.ReadAllText(FileToLoad); String AlarmsFileVersion = ""; while (strFile.Contains("|<ENDLINE>")) { String strAlarm = strFile.Substring(0, strFile.IndexOf("|<ENDLINE>")); strFile = strFile.Substring(strAlarm.Length + "|<ENDLINE>".Length).TrimStart("\r\n".ToCharArray()); if (strAlarm.StartsWith("AlarmsFileVersion|")) { AlarmsFileVersion = strAlarm.Split("|".ToCharArray())[1]; MonoBehaviourExtended.LogFormatted("AlarmsFileVersion:{0}", AlarmsFileVersion); } else if (!strAlarm.StartsWith("VesselID|")) { KACAlarm tmpAlarm; switch (AlarmsFileVersion) { case "3": MonoBehaviourExtended.LogFormatted_DebugOnly("Loading Alarm via v3 loader"); tmpAlarm = UtilitiesLegacy.LoadFromString3(strAlarm, KACWorkerGameState.CurrentTime.UT); break; default: MonoBehaviourExtended.LogFormatted_DebugOnly("Loading Alarm via v2 loader"); tmpAlarm = UtilitiesLegacy.LoadFromString2(strAlarm); break; } oldAlarms.Add(tmpAlarm); } } blnReturn = true; LoadMessage = "Successfully parsed Alarm File"; } else { MonoBehaviourExtended.LogFormatted("Could not find alarms file for: {0}", HighLogic.CurrentGame.Title); LoadMessage = "File not found in TriggerTech Folder"; } } catch (Exception ex) { MonoBehaviourExtended.LogFormatted("Error occured:{0}\r\n{1}", ex.Message,ex.StackTrace); LoadMessage = "Unknown error occured trying to load old file\r\n\r\nError details in output_log.txt"; } return blnReturn; }