public static bool updateProfile(Elite.MessageBus messageBus, ref Dictionary <string, object> state, ref Dictionary <string, Int16?> shortIntValues, ref Dictionary <string, string> textValues, ref Dictionary <string, int?> intValues, ref Dictionary <string, decimal?> decimalValues, ref Dictionary <string, bool?> booleanValues) { Dictionary <string, dynamic> result = getProfile(messageBus); if (result == null) { textValues["VAEDprofileStatus"] = "error"; return(false); } bool currentlyDocked = false; try { textValues["VAEDprofileStatus"] = "ok"; state["VAEDcompanionDict"] = result; string cmdr = result["commander"]["name"]; int credits = result["commander"]["credits"]; int debt = result["commander"]["debt"]; int shipId = result["commander"]["currentShipId"]; string currentShipId = shipId.ToString(); currentlyDocked = result["commander"]["docked"]; string combatRank = Elite.combatRankToString(result["commander"]["rank"]["combat"]); string tradeRank = Elite.tradeRankToString(result["commander"]["rank"]["trade"]); string exploreRank = Elite.exploreRankToString(result["commander"]["rank"]["explore"]); string cqcRank = Elite.cqcRankToString(result["commander"]["rank"]["cqc"]); string federationRank = Elite.federationRankToString(result["commander"]["rank"]["federation"]); string empireRank = Elite.empireRankToString(result["commander"]["rank"]["empire"]); string powerPlayRank = Elite.powerPlayRankToString(result["commander"]["rank"]["power"]); string currentShip = ""; Dictionary <string, dynamic> allShips = new Dictionary <string, dynamic>(); if (result["ships"].GetType() == typeof(System.Collections.ArrayList)) { for (int counter = 0; counter < result["ships"].Count; counter += 1) { string id = result["ships"][counter]["id"].ToString(); allShips.Add(id, result["ships"][counter]); if (id == currentShipId) { currentShip = result["ships"][counter]["name"]; } } } else { allShips = result["ships"]; currentShip = result["ships"][currentShipId]["name"]; } int howManyShips = allShips.Count; int cargoCapacity = result["ship"]["cargo"]["capacity"]; int quantityInCargo = result["ship"]["cargo"]["qty"]; //Set current System textValues["VAEDcurrentSystem"] = null; if (result.ContainsKey("lastSystem") && result["lastSystem"].ContainsKey("name")) { textValues["VAEDcurrentSystem"] = result["lastSystem"]["name"]; if (messageBus.currentSystem != result["lastSystem"]["name"]) { messageBus.currentSystem = result["lastSystem"]["name"]; if (messageBus.systemIndex["systems"].ContainsKey(messageBus.currentSystem)) { messageBus.currentX = (double)messageBus.systemIndex["Systems"][messageBus.currentSystem]["x"]; messageBus.currentY = (double)messageBus.systemIndex["Systems"][messageBus.currentSystem]["y"]; messageBus.currentZ = (double)messageBus.systemIndex["Systems"][messageBus.currentSystem]["z"]; messageBus.haveSystemCoords = true; } else { messageBus.haveSystemCoords = false; } } } else { Debug.Write("ERROR: Companion API doesn't have current location "); textValues["VAEDprofileStatus"] = "error"; return(false); } // Null out ship locations string[] listOfShips = Elite.listOfShipVariableNames(); foreach (string ship in listOfShips) { textValues["VAEDship-" + ship + "-1"] = null; intValues["VAEDshipCounter-" + ship] = 0; } List <string> keys = new List <string>(allShips.Keys); Dictionary <string, dynamic> theShips = new Dictionary <string, dynamic>(); foreach (string key in keys) { string tempShip = allShips[key]["name"]; string tempSystem = null; if (allShips[key].ContainsKey("starsystem")) { tempSystem = allShips[key]["starsystem"]["name"]; } int currDistance = -1; if (tempSystem != null) { currDistance = Atlas.calcDistanceFromHere(messageBus, tempSystem); } } foreach (string key in keys) { string tempShip = allShips[key]["name"]; string tempSystem = null; if (allShips[key].ContainsKey("starsystem")) { tempSystem = allShips[key]["starsystem"]["name"]; } string variableShipName = Elite.frontierShipToVariable(tempShip); string shipCounterString = "VAEDshipCounter-" + variableShipName; intValues[shipCounterString]++; int counterInt = (int)intValues[shipCounterString]; string counterStr = counterInt.ToString(); textValues["VAEDship-" + variableShipName + "-" + counterStr] = tempSystem; } //Setup ambiguous ship variables textValues["VAEDambiguousViper"] = null; textValues["VAEDambiguousCobra"] = null; textValues["VAEDambiguousDiamondback"] = null; textValues["VAEDambiguousAsp"] = null; textValues["VAEDambiguousEagle"] = null; if ((intValues["VAEDshipCounter-ViperMkIII"] + intValues["VAEDshipCounter-ViperMkIV"]) == 1) { if (textValues["VAEDship-ViperMkIII-1"] != null) { textValues["VAEDambiguousViper"] = textValues["VAEDship-ViperMkIII-1"]; } else { textValues["VAEDambiguousViper"] = textValues["VAEDship-ViperMkIV-1"]; } } if ((intValues["VAEDshipCounter-CobraMkIII"] + intValues["VAEDshipCounter-CobraMkIV"]) == 1) { if (textValues["VAEDship-CobraMkIII-1"] != null) { textValues["VAEDambiguousCobra"] = textValues["VAEDship-CobraMkIII-1"]; } else { textValues["VAEDambiguousCobra"] = textValues["VAEDship-CobraMkIV-1"]; } } if ((intValues["VAEDshipCounter-DiamondbackExplorer"] + intValues["VAEDshipCounter-DiamondbackScout"]) == 1) { if (textValues["VAEDship-DiamondbackScout-1"] != null) { textValues["VAEDambiguousDiamondback"] = textValues["VAEDship-DiamondbackScout-1"]; } else { textValues["VAEDambiguousDiamondback"] = textValues["VAEDship-DiamondBackExplorer-1"]; } } if ((intValues["VAEDshipCounter-AspExplorer"] + intValues["VAEDshipCounter-AspScout"]) == 1) { if (textValues["VAEDship-AspExplorer-1"] != null) { textValues["VAEDambiguousAsp"] = textValues["VAEDship-AspExplorer-1"]; } else { textValues["VAEDambiguousAsp"] = textValues["VAEDship-AspScout-1"]; } } if ((intValues["VAEDshipCounter-Eagle"] + intValues["VAEDshipCounter-ImperialEagle"]) == 1) { if (textValues["VAEDship-Eagle-1"] != null) { textValues["VAEDambiguousEagle"] = textValues["VAEDship-Eagle-1"]; } else { textValues["VAEDambiguousEagle"] = textValues["VAEDship-ImperialEagle-1"]; } } intValues["VAEDnumberOfShips"] = howManyShips; textValues["VAEDcmdr"] = cmdr; intValues["VAEDcredits"] = credits; intValues["VAEDloan"] = debt; booleanValues["VAEDcurrentlyDocked"] = currentlyDocked; textValues["VAEDcombatRank"] = combatRank; textValues["VAEDexploreRank"] = exploreRank; textValues["VAEDtradeRank"] = tradeRank; textValues["VAEDcqcRank"] = cqcRank; textValues["VAEDfederationRank"] = federationRank; textValues["VAEDempireRank"] = empireRank; textValues["VAEDcurrentShip"] = Elite.frontierShipToPretty(currentShip); textValues["VAEDphoneticShip"] = Elite.frontierShipToPhonetic(currentShip).ToLower(); intValues["VAEDcargoCapacity"] = cargoCapacity; intValues["VAEDquantityInCargo"] = quantityInCargo; Ship.Components shipObj = Ship.decode(result); state["VAEDshipObj"] = shipObj; booleanValues["VAEDshipHasCargoScanner"] = shipObj.attributes.hasCargoScanner; booleanValues["VAEDshipHasFrameShiftWakeScanner"] = shipObj.attributes.hasFrameShiftWakeScanner; booleanValues["VAEDshipHasKillWarrantScanner"] = shipObj.attributes.hasKillWarrantScanner; booleanValues["VAEDshipHasShieldBooster"] = shipObj.attributes.hasShieldBooster; booleanValues["VAEDshipHasChaffLauncher"] = shipObj.attributes.hasChaffLauncher; booleanValues["VAEDshipHasElectronicCountermeasures"] = shipObj.attributes.hasElectronicCountermeasures; booleanValues["VAEDshipHasHeatSinkLauncher"] = shipObj.attributes.hasHeatSinkLauncher; booleanValues["VAEDshipHasPointDefence"] = shipObj.attributes.hasPointDefence; textValues["VAEDshipBulkheads"] = shipObj.standard.bulkheads; intValues["VAEDshipPowerPlantClass"] = shipObj.standard.powerPlant.@class; textValues["VAEDshipPowerPlantRating"] = shipObj.standard.powerPlant.rating; textValues["VAEDshipThrustersRating"] = shipObj.standard.thrusters.rating; intValues["VAEDshipThrustersClass"] = shipObj.standard.thrusters.@class; textValues["VAEDshipFrameShiftDriveRating"] = shipObj.standard.frameShiftDrive.rating; intValues["VAEDshipFrameShiftDriveClass"] = shipObj.standard.frameShiftDrive.@class; textValues["VAEDshipLifeSupportRating"] = shipObj.standard.lifeSupport.rating; intValues["VAEDshipLifeSupportClass"] = shipObj.standard.lifeSupport.@class; textValues["VAEDshipPowerDistributorRating"] = shipObj.standard.powerDistributor.rating; intValues["VAEDshipPowerDistributorClass"] = shipObj.standard.powerDistributor.@class; textValues["VAEDshipSensorsRating"] = shipObj.standard.sensors.rating; intValues["VAEDshipSensorsClass"] = shipObj.standard.sensors.@class; textValues["VAEDshipFuelTankRating"] = shipObj.standard.fuelTank.rating; intValues["VAEDshipFuelTankClass"] = shipObj.standard.fuelTank.@class; } catch (Exception ex) { Debug.Write("ERROR: Unable to parse Companion API output " + ex.ToString()); textValues["VAEDprofileStatus"] = "error"; return(false); } try { textValues["VAEDeddbStarportId"] = null; textValues["VAEDcurrentStarport"] = null; textValues["VAEDeddbSystemId"] = null; if (currentlyDocked) { TrackSystems.Add(ref state, result["lastSystem"]["name"]); if (result.ContainsKey("lastStarport") && result["lastStarport"].ContainsKey("name")) { textValues["VAEDcurrentStarport"] = result["lastStarport"]["name"]; } //Set Station Services booleanValues["VAEDstarportCommodities"] = false; booleanValues["VAEDstarportShipyard"] = false; booleanValues["VAEDstarportOutfitting"] = false; if (result["lastStarport"].ContainsKey("commodities")) { booleanValues["VAEDstarportCommodities"] = true; } if (result["lastStarport"].ContainsKey("ships") && result["lastStarport"]["ships"].ContainsKey("shipyard_list")) { booleanValues["VAEDstarportShipyard"] = true; } if (result["lastStarport"].ContainsKey("ships") && result["lastStarport"].ContainsKey("modules")) { booleanValues["VAEDstarportOutfitting"] = true; } Task.Run(() => Eddn.updateEddn(messageBus)); } else { Debug.Write("Not docked, skipping EDDN update"); } if (messageBus.systemIndexLoaded) { if (textValues["VAEDcurrentSystem"] != null && messageBus.systemIndex["systems"].ContainsKey(textValues["VAEDcurrentSystem"])) { textValues["VAEDeddbSystemId"] = messageBus.systemIndex["systems"][textValues["VAEDcurrentSystem"]]["id"].ToString(); if (textValues["VAEDcurrentStarport"] != null && messageBus.systemIndex["systems"][textValues["VAEDcurrentSystem"]]["stations"].ContainsKey(textValues["VAEDcurrentStarport"])) { textValues["VAEDeddbStarportId"] = messageBus.systemIndex["systems"][textValues["VAEDcurrentSystem"]]["stations"][textValues["VAEDcurrentStarport"]].ToString(); } } } } catch (Exception ex) { Debug.Write(ex.ToString()); textValues["VAEDprofileStatus"] = "error"; return(false); } return(true); }
public static void VA_Invoke1(String context, ref Dictionary <string, object> state, ref Dictionary <string, Int16?> shortIntValues, ref Dictionary <string, string> textValues, ref Dictionary <string, int?> intValues, ref Dictionary <string, decimal?> decimalValues, ref Dictionary <string, bool?> booleanValues, ref Dictionary <string, object> extendedValues) { try { Elite.MessageBus messageBus = (Elite.MessageBus)state["VAEDmessageBus"]; messageBus.loggedinState = (string)state["VAEDloggedIn"]; if (state.ContainsKey("VAEDcookieContainer")) { messageBus.cookies = (CookieContainer)state["VAEDcookieContainer"]; } Debug.Write("COMMAND: " + context); switch (context.ToLower()) { case "check for upgrade": if (Upgrade.needUpgradeWithCooldown(ref state)) { booleanValues["VAEDupgradeAvailable"] = true; state["VAEDupgradeAvailable"] = true; } else { booleanValues["VAEDupgradeAvailable"] = false; state["VAEDupgradeAvailable"] = false; } break; case "distance from here": string currentSystem = messageBus.currentSystem; if (currentSystem == null) // If we don't have it from netlog then go get it from the profile { Dictionary <string, dynamic> companion = Companion.getProfile((messageBus)); if (companion.ContainsKey("lastSystem") && companion["lastSystem"].ContainsKey("name")) { currentSystem = currentSystem = companion["lastSystem"]["name"]; messageBus.currentSystem = currentSystem; // We didn't have current system from netlog, so erase out x,y,z messageBus.haveSystemCoords = false; } } decimalValues["VAEDdecimalDistance"] = null; decimalValues["VAEDintDistance"] = null; if (currentSystem != null) { int distance = Atlas.calcDistanceFromHere(messageBus, textValues["VAEDtargetSystem"]); if (distance < 0) { //Cound not find destination system Debug.Write("Error: Could not determine distance to target system"); booleanValues["VAEDerrorTargetSystem"] = true; break; } // Found the system - return distance intValues["VAEDintDistance"] = distance; booleanValues["VAEDerrorTargetSystem"] = false; booleanValues["VAEDerrorSourceSystem"] = false; break; } //Can't find the System Debug.Write("Error: Could not determine current location for command 'distance from here'"); booleanValues["VAEDerrorSourceSystem"] = true; booleanValues["VAEDerrorDestinationSystem"] = false; break; case "dictate system": booleanValues["VAEDrecognitionNotLoaded"] = false; if (messageBus.grammarLoaded) { SpeechRecognitionEngine recognitionEngine = messageBus.recognitionEngine; Tuple <string, string> tSystemNames = EliteGrammar.dictateSystem(recognitionEngine, (List <String>)state["VAEDtrackedSystems"]); textValues["VAEDdictateSystem"] = tSystemNames.Item1; textValues["VAEDdictateSystemPhonetic"] = tSystemNames.Item2; break; } else { booleanValues["VAEDrecognitionNotLoaded"] = true; Debug.Write("Error: Speech Engine not yet Initialized. (Possibly still loading)"); } textValues["VAEDdictateSystem"] = null; textValues["VAEDdictateSystemPhonetic"] = null; break; case "press key bind": // If the Binds file changes then reload the binds. string[] parts = textValues["VAEDkeyBinding"].Split(new char[] { ':' }, 2); EliteBinds eliteBinds = EliteBinds.getBinds(ref state, ref textValues, ref booleanValues, messageBus); if (eliteBinds != null) { string keyboardLanguage; if (state.ContainsKey("VAEDbindsLanguage")) { keyboardLanguage = (string)state["VAEDbindsLanguage"]; } else { keyboardLanguage = "en-US"; } List <uint> scanCodeExs = KeyMouse.MapVkToScanCodeExs(eliteBinds.GetCodes(parts[1], keyboardLanguage)); if (scanCodeExs.Count == 0) { Debug.Write("Warning: No key binding found for: " + textValues["VAEDkeyBinding"]); booleanValues["VAEDkeyBindingError"] = true; break; } switch (parts[0]) { // For now we only "best effort" focus the game before keypressing. Igorning the setFocus return code. case "KEYPRESS": Debug.Write("Key Press " + parts[1]); User32.setFocus(eliteWindowTitle); KeyMouse.KeyPress(scanCodeExs); booleanValues["VAEDkeyBindingError"] = false; break; case "KEYUP": Debug.Write("Key up " + parts[1]); User32.setFocus(eliteWindowTitle); KeyMouse.KeyUp(scanCodeExs); booleanValues["VAEDkeyBindingError"] = false; break; case "KEYDOWN": Debug.Write("Key down " + parts[1]); User32.setFocus(eliteWindowTitle); KeyMouse.KeyDown(scanCodeExs); booleanValues["VAEDkeyBindingError"] = false; break; default: booleanValues["VAEDkeyBindingError"] = true; break; } } else { Debug.Write("Error: Binds not loaded, unable to perform keypress"); } break; case "clear debug": Debug.Clear(); break; case "get debug": string tempDebug = Debug.Path(); textValues["VAEDdebugFile"] = tempDebug; break; case "export for ed shipyard": Companion.updateProfile(messageBus, ref state, ref shortIntValues, ref textValues, ref intValues, ref decimalValues, ref booleanValues); if (state.ContainsKey("VAEDshipObj")) { Ship.Components shipObj = (Ship.Components)state["VAEDshipObj"]; StringBuilder export = EDShipyard.export(shipObj); if (export != null) { booleanValues["VAEDexportEDShipyardError"] = false; Clipboard.SetText(export.ToString()); break; } } Debug.Write("Error: Unable to form ED Shipyard.com Export"); Clipboard.Clear(); booleanValues["VAEDexportEDShipyuardError"] = true; break; case "export for coriolis": Companion.updateProfile(messageBus, ref state, ref shortIntValues, ref textValues, ref intValues, ref decimalValues, ref booleanValues); if (state.ContainsKey("VAEDshipObj")) { Ship.Components shipObj = (Ship.Components)state["VAEDshipObj"]; string json = Coriolis.export(shipObj); if (json != null) { booleanValues["VAEDexportCoriolisError"] = false; Clipboard.SetText(json); break; } } Debug.Write("Error: Unable to form Coriolis.io JSON"); Clipboard.Clear(); booleanValues["VAEDexportCoriolisError"] = true; break; case "edit web variable sources": bool foundWindow = false; foreach (Form form in Application.OpenForms) { if (form.GetType().Name == "EditWebVars") { Debug.Write("Edit Web Variable Sources window is already open"); foundWindow = true; } } if (!foundWindow) { var webVarsForm = new WebVars.EditWebVars(); webVarsForm.ShowDialog(); } break; case "get web variables": GetWebVars.readWebVars(ref state, ref textValues, ref intValues, ref booleanValues); break; case "get file variables": FileVar.readFileVars(ref state, ref textValues, ref intValues, ref booleanValues); break; case "get clipboard": if (Clipboard.ContainsText(TextDataFormat.Text)) { textValues.Add("VAEDclipboard", Clipboard.GetText()); } break; case "get frontier credentials": var configureForm = new ConfigureForm.Configuration((string)state["VAEDloggedIn"]); configureForm.ShowDialog(); CookieContainer loginCookies = configureForm.Cookie; state["VAEDcookieContainer"] = loginCookies; string loginResponse = configureForm.LoginResponse; Debug.Write("Frontier Login Response: " + loginResponse); textValues["VAEDloggedIn"] = loginResponse; break; case "get frontier verification": CookieContainer verifyCookies = new CookieContainer(); if (state.ContainsKey("VAEDcookieContainer")) { verifyCookies = (CookieContainer)state["VAEDcookieContainer"]; } var verificationForm = new VerificationCode.Validate(); verificationForm.Cookie = verifyCookies; verificationForm.ShowDialog(); verifyCookies = verificationForm.Cookie; string verifyResponse = verificationForm.VerifyResponse; state["VAEDloggedIn"] = verifyResponse; state["VAEDcookieContainer"] = verifyCookies; textValues["VAEDloggedIn"] = verifyResponse; if (verifyResponse == "ok") { Web.WriteCookiesToDisk(Config.CookiePath(), verifyCookies); } break; case "update profile and eddn": if (state["VAEDloggedIn"].ToString() == "ok" && state.ContainsKey("VAEDcookieContainer")) { Companion.updateProfile(messageBus, ref state, ref shortIntValues, ref textValues, ref intValues, ref decimalValues, ref booleanValues); } else // Not logged in { textValues["VAEDprofileStatus"] = "credentials"; } break; default: Debug.Write("ERROR: unknown command"); break; } } catch (Exception ex) { Debug.Write(ex.ToString()); } }
public static bool updateProfile(ref Dictionary <string, object> state, ref Dictionary <string, Int16?> shortIntValues, ref Dictionary <string, string> textValues, ref Dictionary <string, int?> intValues, ref Dictionary <string, decimal?> decimalValues, ref Dictionary <string, bool?> booleanValues) { int profileCooldown = Utilities.isCoolingDown(ref state, "VAEDprofileCooldown", 30); if (profileCooldown > 0) { Debug.Write("Get Profile is cooling down: " + profileCooldown.ToString() + " seconds remain."); return(true); } textValues["VAEDprofileStatus"] = "ok"; string htmlData = ""; // Load debug companion JSON if it is present. string debugJson = Path.Combine(Config.Path(), "debug_companion.json"); if (File.Exists(debugJson)) { htmlData = File.ReadAllText(debugJson); } else { CookieContainer profileCookies = (CookieContainer)state["VAEDcookieContainer"]; Tuple <CookieContainer, string> tRespon = Companion.getProfile(profileCookies); state["VAEDcookieContainer"] = tRespon.Item1; Web.WriteCookiesToDisk(Config.CookiePath(), tRespon.Item1); htmlData = tRespon.Item2; if (htmlData.Contains("Please correct the following") || htmlData == "") { textValues["VAEDprofileStatus"] = "error"; return(false); } } JavaScriptSerializer serializer = new JavaScriptSerializer(); var result = new Dictionary <string, dynamic>(); bool currentlyDocked = false; try { result = serializer.Deserialize <Dictionary <string, dynamic> >(htmlData); state["VAEDcompanionDict"] = result; string cmdr = result["commander"]["name"]; int credits = result["commander"]["credits"]; int debt = result["commander"]["debt"]; int shipId = result["commander"]["currentShipId"]; string currentShipId = shipId.ToString(); currentlyDocked = result["commander"]["docked"]; string combatRank = Elite.combatRankToString(result["commander"]["rank"]["combat"]); string tradeRank = Elite.tradeRankToString(result["commander"]["rank"]["trade"]); string exploreRank = Elite.exploreRankToString(result["commander"]["rank"]["explore"]); string cqcRank = Elite.cqcRankToString(result["commander"]["rank"]["cqc"]); string federationRank = Elite.federationRankToString(result["commander"]["rank"]["federation"]); string empireRank = Elite.empireRankToString(result["commander"]["rank"]["empire"]); string powerPlayRank = Elite.powerPlayRankToString(result["commander"]["rank"]["power"]); Dictionary <string, object> allShips = result["ships"]; int howManyShips = allShips.Count; int cargoCapacity = result["ship"]["cargo"]["capacity"]; int quantityInCargo = result["ship"]["cargo"]["qty"]; string currentShip = result["ships"][currentShipId]["name"]; result["commander"]["currentShip"] = currentShip; //Set current System textValues["VAEDcurrentSystem"] = null; if (result.ContainsKey("lastSystem") && result["lastSystem"].ContainsKey("name")) { textValues["VAEDcurrentSystem"] = result["lastSystem"]["name"]; } else { Debug.Write("ERROR: Companion API doesn't have current location "); Debug.Write("----------------FRONTIER COMPANION DATA--------------------"); Debug.Write(htmlData); textValues["VAEDprofileStatus"] = "error"; return(false); } // Null out ship locations string[] listOfShips = Elite.listOfShipVariableNames(); foreach (string ship in listOfShips) { textValues["VAEDship-" + ship + "-1"] = null; intValues["VAEDshipCounter-" + ship] = 0; } List <string> keys = new List <string>(allShips.Keys); Dictionary <string, dynamic> theShips = new Dictionary <string, dynamic>(); foreach (string key in keys) { string tempShip = result["ships"][key]["name"]; string tempSystem = null; if (result["ships"][key].ContainsKey("starsystem")) { tempSystem = result["ships"][key]["starsystem"]["name"]; } int currDistance = -1; if (tempSystem != null) { Dictionary <string, dynamic> tempAtlas = (Dictionary <string, dynamic>)state["VAEDatlasIndex"]; currDistance = Atlas.calcDistance(ref tempAtlas, textValues["VAEDcurrentSystem"], tempSystem); } } foreach (string key in keys) { string tempShip = result["ships"][key]["name"]; string tempSystem = null; if (result["ships"][key].ContainsKey("starsystem")) { tempSystem = result["ships"][key]["starsystem"]["name"]; } string variableShipName = Elite.frontierShipToVariable(tempShip); string shipCounterString = "VAEDshipCounter-" + variableShipName; intValues[shipCounterString]++; int counterInt = (int)intValues[shipCounterString]; string counterStr = counterInt.ToString(); textValues["VAEDship-" + variableShipName + "-" + counterStr] = tempSystem; } //Setup ambiguous ship variables textValues["VAEDambiguousViper"] = null; textValues["VAEDambiguousCobra"] = null; textValues["VAEDambiguousDiamondback"] = null; textValues["VAEDambiguousAsp"] = null; textValues["VAEDambiguousEagle"] = null; if ((intValues["VAEDshipCounter-ViperMkIII"] + intValues["VAEDshipCounter-ViperMkIV"]) == 1) { if (textValues["VAEDship-ViperMkIII-1"] != null) { textValues["VAEDambiguousViper"] = textValues["VAEDship-ViperMkIII-1"]; } else { textValues["VAEDambiguousViper"] = textValues["VAEDship-ViperMkIV-1"]; } } if ((intValues["VAEDshipCounter-CobraMkIII"] + intValues["VAEDshipCounter-CobraMkIV"]) == 1) { if (textValues["VAEDship-CobraMkIII-1"] != null) { textValues["VAEDambiguousCobra"] = textValues["VAEDship-CobraMkIII-1"]; } else { textValues["VAEDambiguousCobra"] = textValues["VAEDship-CobraMkIV-1"]; } } if ((intValues["VAEDshipCounter-DiamondbackExplorer"] + intValues["VAEDshipCounter-DiamondbackScout"]) == 1) { if (textValues["VAEDship-DiamondbackScout-1"] != null) { textValues["VAEDambiguousDiamondback"] = textValues["VAEDship-DiamondBackScout-1"]; } else { textValues["VAEDambiguousDiamondback"] = textValues["VAEDship-DiamondBackExplorer-1"]; } } if ((intValues["VAEDshipCounter-AspExplorer"] + intValues["VAEDshipCounter-AspScout"]) == 1) { if (textValues["VAEDship-AspExplorer-1"] != null) { textValues["VAEDambiguousAsp"] = textValues["VAEDship-AspExplorer-1"]; } else { textValues["VAEDambiguousAsp"] = textValues["VAEDship-AspScout-1"]; } } if ((intValues["VAEDshipCounter-Eagle"] + intValues["VAEDshipCounter-ImperialEagle"]) == 1) { if (textValues["VAEDship-Eagle-1"] != null) { textValues["VAEDambiguousEagle"] = textValues["VAEDship-Eagle-1"]; } else { textValues["VAEDambiguousEagle"] = textValues["VAEDship-ImperialEagle-1"]; } } intValues["VAEDnumberOfShips"] = howManyShips; textValues["VAEDcmdr"] = cmdr; intValues["VAEDcredits"] = credits; intValues["VAEDloan"] = debt; booleanValues["VAEDcurrentlyDocked"] = currentlyDocked; textValues["VAEDcombatRank"] = combatRank; textValues["VAEDexploreRank"] = exploreRank; textValues["VAEDtradeRank"] = tradeRank; textValues["VAEDcqcRank"] = cqcRank; textValues["VAEDfederationRank"] = federationRank; textValues["VAEDempireRank"] = empireRank; textValues["VAEDcurrentShip"] = Elite.frontierShipToPretty(currentShip); textValues["VAEDphoneticShip"] = Elite.frontierShipToPhonetic(currentShip).ToLower(); intValues["VAEDcargoCapacity"] = cargoCapacity; intValues["VAEDquantityInCargo"] = quantityInCargo; Ship.Components shipObj = Ship.decode(result); state["VAEDshipObj"] = shipObj; booleanValues["VAEDshipHasCargoScanner"] = shipObj.attributes.hasCargoScanner; booleanValues["VAEDshipHasFrameShiftWakeScanner"] = shipObj.attributes.hasFrameShiftWakeScanner; booleanValues["VAEDshipHasKillWarrantScanner"] = shipObj.attributes.hasKillWarrantScanner; booleanValues["VAEDshipHasShieldBooster"] = shipObj.attributes.hasShieldBooster; booleanValues["VAEDshipHasChaffLauncher"] = shipObj.attributes.hasChaffLauncher; booleanValues["VAEDshipHasElectronicCountermeasures"] = shipObj.attributes.hasElectronicCountermeasures; booleanValues["VAEDshipHasHeatSinkLauncher"] = shipObj.attributes.hasHeatSinkLauncher; booleanValues["VAEDshipHasPointDefence"] = shipObj.attributes.hasPointDefence; textValues["VAEDshipBulkheads"] = shipObj.standard.bulkheads; intValues["VAEDshipPowerPlantClass"] = shipObj.standard.powerPlant.@class; textValues["VAEDshipPowerPlantRating"] = shipObj.standard.powerPlant.rating; textValues["VAEDshipThrustersRating"] = shipObj.standard.thrusters.rating; intValues["VAEDshipThrustersClass"] = shipObj.standard.thrusters.@class; textValues["VAEDshipFrameShiftDriveRating"] = shipObj.standard.frameShiftDrive.rating; intValues["VAEDshipFrameShiftDriveClass"] = shipObj.standard.frameShiftDrive.@class; textValues["VAEDshipLifeSupportRating"] = shipObj.standard.lifeSupport.rating; intValues["VAEDshipLifeSupportClass"] = shipObj.standard.lifeSupport.@class; textValues["VAEDshipPowerDistributorRating"] = shipObj.standard.powerDistributor.rating; intValues["VAEDshipPowerDistributorClass"] = shipObj.standard.powerDistributor.@class; textValues["VAEDshipSensorsRating"] = shipObj.standard.sensors.rating; intValues["VAEDshipSensorsClass"] = shipObj.standard.sensors.@class; textValues["VAEDshipFuelTankRating"] = shipObj.standard.fuelTank.rating; intValues["VAEDshipFuelTankClass"] = shipObj.standard.fuelTank.@class; } catch (Exception ex) { Debug.Write("ERROR: Unable to parse Companion API output " + ex.ToString()); Debug.Write("----------------FRONTIER COMPANION DATA--------------------"); Debug.Write(htmlData); textValues["VAEDprofileStatus"] = "error"; return(false); } try { textValues["VAEDeddbStarportId"] = null; textValues["VAEDcurrentStarport"] = null; textValues["VAEDeddbSystemId"] = null; if (currentlyDocked) { TrackSystems.Add(ref state, result["lastSystem"]["name"]); if (result.ContainsKey("lastStarport") && result["lastStarport"].ContainsKey("name")) { textValues["VAEDcurrentStarport"] = result["lastStarport"]["name"]; } //Set Station Services booleanValues["VAEDstarportCommodities"] = false; booleanValues["VAEDstarportShipyard"] = false; booleanValues["VAEDstarportOutfitting"] = false; if (result["lastStarport"].ContainsKey("commodities")) { booleanValues["VAEDstarportCommodities"] = true; } if (result["lastStarport"].ContainsKey("ships") && result["lastStarport"]["ships"].ContainsKey("shipyard_list")) { booleanValues["VAEDstarportShipyard"] = true; } if (result["lastStarport"].ContainsKey("ships") && result["lastStarport"].ContainsKey("modules")) { booleanValues["VAEDstarportOutfitting"] = true; } // If we're docked, update the EDDN network. int eddnCooldown = Utilities.isCoolingDown(ref state, "VAEDeddnCooldown", 60 * 10); // Cool down 10 minutes if (state.ContainsKey("VAEDlastStation") && (string)state["VAEDlastStation"] == textValues["VAEDcurrentStarport"] && eddnCooldown > 0) { Debug.Write("EDDN update is cooling down: " + eddnCooldown.ToString() + " seconds remain."); } else { state["VAEDlastStation"] = textValues["VAEDcurrentStarport"]; Task.Run(() => Eddn.updateEddn(result)); } } if (state.ContainsKey("VAEDeddbIndex")) { Dictionary <string, dynamic> tempEddb = (Dictionary <string, dynamic>)state["VAEDeddbIndex"]; if (textValues["VAEDcurrentSystem"] != null && tempEddb.ContainsKey(textValues["VAEDcurrentSystem"])) { textValues["VAEDeddbSystemId"] = tempEddb[textValues["VAEDcurrentSystem"]]["id"].ToString(); if (textValues["VAEDcurrentStarport"] != null && tempEddb[textValues["VAEDcurrentSystem"]]["stations"].ContainsKey(textValues["VAEDcurrentStarport"])) { textValues["VAEDeddbStarportId"] = tempEddb[textValues["VAEDcurrentSystem"]]["stations"][textValues["VAEDcurrentStarport"]].ToString(); } } } } catch (Exception ex) { Debug.Write("----------------FRONTIER COMPANION DATA--------------------"); Debug.Write(htmlData); Debug.Write(ex.ToString()); textValues["VAEDprofileStatus"] = "error"; return(false); } string companionFile = Path.Combine(Config.Path(), "companion.json"); using (StreamWriter outputFile = new StreamWriter(companionFile)) { outputFile.Write(htmlData); } return(true); }
public static string export(Ship.Components shipObj) { try { CoriolisObj coriolis = new CoriolisObj(); coriolis.components.standard = shipObj.standard; List <Ship.Hardpoint> sortedHardpoints = shipObj.hardpoints.OrderBy(o => o.slotSize).ToList(); foreach (Ship.Hardpoint hardpoint in sortedHardpoints) { if (hardpoint.rating == null) { coriolis.components.hardpoints.Add(null); } else { coriolis.components.hardpoints.Add(hardpoint); } } List <Ship.Internal> sortedInternals = [email protected](o => o.slotSize).ToList(); foreach (Ship.Internal @internal in sortedInternals) { if (@internal.rating == null) { [email protected](null); } else { [email protected](@internal); } } List <Ship.Utility> sortedUtilities = shipObj.utility.OrderBy(o => o.slot).ToList(); foreach (Ship.Utility utility in sortedUtilities) { if (utility.rating == null) { coriolis.components.utility.Add(null); } else { coriolis.components.utility.Add(utility); } } string shipType = Elite.frontierShipToCoriolis(shipObj.attributes.shiptype); coriolis.name = "Ocellus - " + shipType; coriolis.ship = shipType; DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(CoriolisObj)); MemoryStream stream = new MemoryStream(); serializer.WriteObject(stream, coriolis); stream.Position = 0; StreamReader sr = new StreamReader(stream); string json = sr.ReadToEnd(); return(json); } catch (Exception ex) { Debug.Write(ex.ToString()); } return(null); }
public static StringBuilder export(Ship.Components shipObj) { string shipType = Elite.frontierShipToPretty(shipObj.attributes.shiptype); StringBuilder EDShipyardExport = new StringBuilder(); EDShipyardExport.AppendLine("[" + shipType + "]"); List <Ship.Hardpoint> sortedHardpoints = shipObj.hardpoints.OrderByDescending(o => o.slotSize).ToList(); foreach (Ship.Hardpoint hardpoint in sortedHardpoints) { if (hardpoint.rating != null) { string name = ""; if (hardpoint.name != null) { name = hardpoint.name + " "; } EDShipyardExport.AppendLine( hardpoint.slotSize.Substring(0, 1) + ": " + [email protected]() + hardpoint.rating + "/" + hardpoint.mount.Substring(0, 1) + hardpoint.missile + " " + name + hardpoint.group ); } } List <Ship.Utility> sortedUtilities = shipObj.utility.OrderByDescending(o => o.slot).ToList(); foreach (Ship.Utility utility in sortedUtilities) { if (utility.rating != null) { string name = ""; if (utility.name == null) { name = utility.group; } else { name = utility.name; } EDShipyardExport.AppendLine( "U: " + [email protected]() + utility.rating + " " + name ); } } EDShipyardExport.AppendLine(""); EDShipyardExport.AppendLine("BH: 1I " + shipObj.standard.bulkheads); EDShipyardExport.AppendLine("RB: " + [email protected]() + shipObj.standard.powerPlant.rating + " Power Plant"); EDShipyardExport.AppendLine("TM: " + [email protected]() + shipObj.standard.thrusters.rating + " Thrusters"); EDShipyardExport.AppendLine("FH: " + [email protected]() + shipObj.standard.frameShiftDrive.rating + " Frame Shift Drive"); EDShipyardExport.AppendLine("EC: " + [email protected]() + shipObj.standard.lifeSupport.rating + " Life Support"); EDShipyardExport.AppendLine("PC: " + [email protected]() + shipObj.standard.powerDistributor.rating + " Power Distributor"); EDShipyardExport.AppendLine("SS: " + [email protected]() + shipObj.standard.sensors.rating + " Sensors"); EDShipyardExport.AppendLine("FS: " + [email protected]() + shipObj.standard.fuelTank.rating + " Fuel Tank (Capacity: " + shipObj.standard.fuelTank.capacity.ToString() + ")"); EDShipyardExport.AppendLine(""); List <Ship.Internal> sortedInternals = [email protected](o => o.slotSize).ToList(); foreach (Ship.Internal @internal in sortedInternals) { if (@internal.rating != null) { string name = ""; if (@internal.name == null) { name = @internal.group; if (@internal.capacity != 0) { name += " (Capacity: " + @internal.capacity.ToString() + ")"; } } else { name = @internal.name; } EDShipyardExport.AppendLine( @internal.slotSize.ToString() + ": " + @[email protected]() + @internal.rating + " " + name ); } } return(EDShipyardExport); }