public static void CalculateSpeed(RouteStart routeStart, VibrationData data) { var distance = CalculateDistance(routeStart.StartLocationLongitude, routeStart.StartLocationLatitude, data.LocationLongitude, data.LocationLatitude); var timeDiff = routeStart.BeginTime - data.TimeStamp; var speed = distance / Math.Abs(timeDiff.TotalHours); data.Speed = speed; }
public int StartRoute([FromBody] RouteStart route) { var newRoute = new Route { UserId = route.UserId, BeginTime = route.BeginTime, StartLocationLatitude = route.StartLocationLatitude, StartLocationLongitude = route.StartLocationLongitude }; _dbContext.Add(newRoute); _dbContext.SaveChanges(); return(newRoute.RouteId); }
public void Post([FromBody] VibrationData data) { var previousData = _dbContext.VibrationDatas.Where(vb => vb.RouteId == data.RouteId).OrderByDescending(vb => vb.TimeStamp).FirstOrDefault(); if (previousData == null) { //First mesurement in route var route = _dbContext.Routes.Where(r => r.RouteId == data.RouteId).FirstOrDefault(); var routeStart = new RouteStart { BeginTime = route.BeginTime, StartLocationLatitude = route.StartLocationLatitude, StartLocationLongitude = route.StartLocationLongitude }; SpeedCalculator.CalculateSpeed(routeStart, data); } else { SpeedCalculator.CalculateSpeed(previousData, data); } _dbContext.Add(data); _dbContext.SaveChanges(); }
// Update is called once per frame void Update() { // temp path testing Vector3 direction = Vector3.Normalize(RouteStart.transform.position - transform.position); GetComponent <Rigidbody>().velocity = Vector3.Lerp(GetComponent <Rigidbody>().velocity, direction * Speed, Time.deltaTime * LerpSpeed); // if close then move on to next node float distance = Vector3.Distance(transform.position, RouteStart.transform.position); if (distance < 1.5f) { GameObject nextnode = RouteStart.GetComponent <EnemyPathNodeScript>().NextNode; if (nextnode) { RouteStart = nextnode; } } UpdateFall(); UpdateHat(); }
private void LoadSettings() { bool arrowLoaded = false; FileInfo settingsFile; try { settingsFile = new FileInfo(Util.FullPath("settings.xml")); if (!settingsFile.Exists) { LoadArrowImage("Chrome"); arrowLoaded = true; mSettingsLoaded = true; return; } } catch (Exception ex) { Util.HandleException(ex); LoadArrowImage("Chrome"); arrowLoaded = true; mSettingsLoaded = true; return; } try { XmlDocument doc = new XmlDocument(); doc.Load(settingsFile.FullName); if (doc.DocumentElement.HasAttribute("version")) { int.TryParse(doc.DocumentElement.GetAttribute("version"), out mLoadedSettingsVersion); } string val; int intVal; double dblVal; bool boolVal; Coordinates coords; Point pt; Rectangle rect; foreach (XmlElement ele in doc.DocumentElement.SelectNodes("setting")) { val = ele.GetAttribute("value"); switch (ele.GetAttribute("name")) { case "ViewPosition": if (TryParsePoint(val, out pt)) { SetViewLocation(pt); } break; case "nbkMain": if (int.TryParse(val, out intVal)) { if (intVal > 0 && intVal < MainTab.COUNT) { nbkMain.ActiveTab = intVal; } } break; case "nbkHuds": if (int.TryParse(val, out intVal)) { if (intVal > 0 && intVal < HudsTab.COUNT) { nbkHuds.ActiveTab = intVal; } } break; case "nbkAtlas": if (int.TryParse(val, out intVal)) { if (intVal >= 0 && intVal < AtlasTab.COUNT) { nbkAtlas.ActiveTab = intVal; } } break; case "nbkSettings": if (int.TryParse(val, out intVal)) { if (intVal > 0 && intVal < SettingsTab.COUNT) { nbkSettings.ActiveTab = intVal; } } break; case "nbkRouteSettings": if (int.TryParse(val, out intVal)) { if (intVal > 0 && intVal < RouteSettingsTab.COUNT) { nbkRouteSettings.ActiveTab = intVal; } } break; // // HUDs > Arrow HUD Tab // case "ArrowHud.Visible": if (bool.TryParse(val, out boolVal)) { mArrowHud.Visible = boolVal; } break; case "ArrowHud.Location": if (TryParsePoint(val, out pt)) { mArrowHud.Location = pt; } break; // -- Old v case "ArrowHud.DestinationCoords": if (Coordinates.TryParse(val, out coords)) { mArrowHud.DestinationCoords = coords; } break; case "ArrowHud.DestinationLocation": if (int.TryParse(val, out intVal)) { Location loc; if (mLocDb.TryGet(intVal, out loc) && loc.Coords == mArrowHud.DestinationCoords) { mArrowHud.DestinationLocation = loc; } } break; // -- Old ^ case "ArrowHud.DisplayIndoors": if (bool.TryParse(val, out boolVal)) { mArrowHud.DisplayIndoors = boolVal; } break; case "ArrowHud.ShowDestinationOver": if (bool.TryParse(val, out boolVal)) { mArrowHud.ShowDestinationOver = boolVal; } break; case "ArrowHud.ShowDistanceUnder": if (bool.TryParse(val, out boolVal)) { mArrowHud.ShowDistanceUnder = boolVal; } break; case "ArrowHud.PositionLocked": if (bool.TryParse(val, out boolVal)) { mArrowHud.PositionLocked = boolVal; } break; case "ArrowHud.ArrowName": LoadArrowImage(val); arrowLoaded = true; break; case "ArrowHud.TextSize": if (int.TryParse(val, out intVal)) { mArrowHud.TextSize = intVal; } break; case "ArrowHud.TextColor": // Setting choTextColor.Selected calls its change event handler, // which changes mArrowHud's text color, unless the color is at // index 0, which should always be white (the default for mArrowHud) for (int i = 0; i < choTextColor.Count; i++) { if (val == (string)choTextColor.Data[i]) { choTextColor.Selected = i; choTextColor_Change(choTextColor, new MyClasses.MetaViewWrappers.MVIndexChangeEventArgs(0, i)); break; } } break; case "ArrowHud.TextBold": if (bool.TryParse(val, out boolVal)) { mArrowHud.TextBold = boolVal; } break; // // HUDs > Dereth Map Tab // case "DerethMap.Region": if (TryParseRectangle(val, out rect)) { mMapHud.Region = rect; } break; case "DerethMap.Sticky": if (bool.TryParse(val, out boolVal)) { mMapHud.Sticky = boolVal; } break; case "DerethMap.CenterOnPlayer": if (bool.TryParse(val, out boolVal)) { mMapHud.CenterOnPlayer = boolVal; } break; case "DerethMap.ShowRoute": if (bool.TryParse(val, out boolVal)) { mMapHud.ShowRoute = boolVal; } break; case "DerethMap.ShowLocations": if (bool.TryParse(val, out boolVal)) { mMapHud.ShowLocations = boolVal; } break; case "DerethMap.ShowLocationsAllZooms": if (bool.TryParse(val, out boolVal)) { mMapHud.ShowLocationsAllZooms = boolVal; } break; case "DerethMap.ShowLabels": if (bool.TryParse(val, out boolVal)) { mMapHud.ShowLabels = boolVal; } break; // -- Old v case "DerethMap.AlphaActive": if (int.TryParse(val, out intVal)) { SetWindowAlpha(mMapHud, true, intVal); } break; case "DerethMap.AlphaInactive": if (int.TryParse(val, out intVal)) { SetWindowAlpha(mMapHud, false, intVal); } break; // -- Old ^ case "DerethMap.Zoom": if (double.TryParse(val, out dblVal)) { mMapHud.Zoom = (float)dblVal; } break; case "DerethMap.DragButton": try { mMapHud.DragButton = (MouseButtons)Enum.Parse(typeof(MouseButtons), val, true); } catch { /* Ignore */ } break; case "DerethMap.SelectLocationButton": try { mMapHud.SelectLocationButton = (MouseButtons)Enum.Parse(typeof(MouseButtons), val, true); } catch { /* Ignore */ } break; case "DerethMap.ContextMenuButton": try { mMapHud.ContextMenuButton = (MouseButtons)Enum.Parse(typeof(MouseButtons), val, true); } catch { /* Ignore */ } break; case "DerethMap.DetailsButton": try { mMapHud.DetailsButton = (MouseButtons)Enum.Parse(typeof(MouseButtons), val, true); } catch { /* Ignore */ } break; // // HUDs > Dungeon Map Tab // case "DungeonMap.Region": if (TryParseRectangle(val, out rect)) { mDungeonHud.Region = rect; } break; case "DungeonMap.Sticky": if (bool.TryParse(val, out boolVal)) { mDungeonHud.Sticky = boolVal; } break; case "DungeonMap.CurrentDungeon": if (int.TryParse(val, out intVal)) { mDungeonHud.LoadDungeonById(intVal); } break; case "DungeonMap.AutoLoadMaps": if (bool.TryParse(val, out boolVal)) { mDungeonHud.AutoLoadMaps = boolVal; } break; case "DungeonMap.ShowCompass": if (bool.TryParse(val, out boolVal)) { mDungeonHud.ShowCompass = boolVal; } break; case "DungeonMap.AutoRotateMap": if (bool.TryParse(val, out boolVal)) { mDungeonHud.AutoRotateMap = boolVal; } break; case "DungeonMap.MoveWithPlayer": if (bool.TryParse(val, out boolVal)) { mDungeonHud.MoveWithPlayer = boolVal; } break; case "DungeonMap.DragButton": try { mDungeonHud.DragButton = (MouseButtons)Enum.Parse(typeof(MouseButtons), val, true); } catch { /* Ignore */ } break; // // HUDs > General Tab // case "Toolbar.Visible": if (bool.TryParse(val, out boolVal)) { mToolbar.Visible = boolVal; } break; case "Toolbar.Location": if (TryParsePoint(val, out pt)) { mToolbar.Location = pt; } break; case "Toolbar.Display": try { mToolbar.Display = (ToolbarDisplay)Enum.Parse(typeof(ToolbarDisplay), val, true); } catch { /* Ignore */ } break; case "Toolbar.Orientation": try { mToolbar.Orientation = (ToolbarOrientation)Enum.Parse(typeof(ToolbarOrientation), val, true); } catch { /* Ignore */ } break; case "MainViewToolButton.Visible": if (bool.TryParse(val, out boolVal)) { mMainViewToolButton.Visible = boolVal; } break; case "ArrowToolButton.Visible": if (bool.TryParse(val, out boolVal)) { mArrowToolButton.Visible = boolVal; } break; case "DerethToolButton.Visible": if (bool.TryParse(val, out boolVal)) { mDerethToolButton.Visible = boolVal; } break; case "DungeonToolButton.Visible": if (bool.TryParse(val, out boolVal)) { mDungeonToolButton.Visible = boolVal; } break; case "chkAllowBothMaps": if (bool.TryParse(val, out boolVal)) { chkAllowBothMaps.Checked = boolVal; } break; case "Huds.AlphaActive": if (int.TryParse(val, out intVal)) { mArrowHud.Alpha = intVal; SetWindowAlpha(mMapHud, true, intVal); SetWindowAlpha(mDungeonHud, true, intVal); } break; case "Huds.AlphaInactive": if (int.TryParse(val, out intVal)) { SetWindowAlpha(mMapHud, false, intVal); SetWindowAlpha(mDungeonHud, false, intVal); } break; // // Atlas > Update Tab // case "edtLocationsUrl": edtLocationsUrl.Text = val; break; case "chkUpdateRemind": if (bool.TryParse(val, out boolVal)) { chkUpdateRemind.Checked = boolVal; } break; // // Settings > Chat Tab // case "chkLinkCoords": if (bool.TryParse(val, out boolVal)) { chkLinkCoords.Checked = boolVal; } break; case "Util.DefaultTargetWindows": { ChatWindow windows; if (Util.TryParseEnum <ChatWindow>(val, out windows) && windows != ChatWindow.Default) { Util.DefaultWindow = windows; } } break; // -- Old v case "choWriteMessagesTo": if (int.TryParse(val, out intVal)) { switch (intVal) { case 0: { Util.DefaultWindow = ChatWindow.MainChat; break; } case 1: { Util.DefaultWindow = ChatWindow.One; break; } case 2: { Util.DefaultWindow = ChatWindow.Two; break; } case 3: { Util.DefaultWindow = ChatWindow.Three; break; } case 4: { Util.DefaultWindow = ChatWindow.Four; break; } } } break; // -- Old ^ case "chkAlwaysShowErrors": if (bool.TryParse(val, out boolVal)) { chkAlwaysShowErrors.Checked = boolVal; Util.WriteErrorsToMainChat = boolVal; } break; case "edtChatCommand": edtChatCommand.Text = val; break; case "chkEnableCoordsCommand": if (bool.TryParse(val, out boolVal)) { chkEnableCoordsCommand.Checked = boolVal; } break; case "edtCoordsCommand": edtCoordsCommand.Text = val; break; case "chkEnableDestCommand": if (bool.TryParse(val, out boolVal)) { chkEnableDestCommand.Checked = boolVal; } break; case "edtDestCommand": edtDestCommand.Text = val; break; case "chkEnableFindCommand": if (bool.TryParse(val, out boolVal)) { chkEnableFindCommand.Checked = boolVal; } break; case "edtFindCommand": edtFindCommand.Text = val; break; case "chkTrackCorpses": if (bool.TryParse(val, out boolVal)) { chkTrackCorpses.Checked = boolVal; } break; // // Settings > Route Finding Tab // case "chkAutoUpdateRecalls": if (bool.TryParse(val, out boolVal)) { chkAutoUpdateRecalls.Checked = boolVal; } break; case "edtMaxRunDist": if (double.TryParse(val, out dblVal) && dblVal > 0) { edtMaxRunDist.Text = dblVal.ToString(); RouteFinder.MaxRunDistance = dblVal; } break; case "edtPortalRunDist": if (double.TryParse(val, out dblVal) && dblVal > 0) { edtPortalRunDist.Text = dblVal.ToString(); RouteFinder.PortalWeight = dblVal; } break; case "chkAutoDetectPortalDevices": if (bool.TryParse(val, out boolVal)) { chkAutoDetectPortalDevices.Checked = boolVal; } break; } } // Reset setting if (mLoadedSettingsVersion < 2) { chkAutoUpdateRecalls.Checked = true; } XmlElement arrowNode = doc.DocumentElement.SelectSingleNode("arrowTarget") as XmlElement; if (arrowNode != null) { mArrowHud.LoadDestinationXml(arrowNode, mLocDb); } XmlElement startLocationsNode = doc.DocumentElement.SelectSingleNode("startLocations") as XmlElement; if (startLocationsNode != null) { mStartLocations.Clear(); foreach (XmlElement node in startLocationsNode.ChildNodes) { RouteStart loc; if (RouteStart.TryParseXml(node, out loc, Core.CharacterFilter.Id, Core.CharacterFilter.Name, MonarchId, MonarchName, Core.CharacterFilter.AccountName)) { mStartLocations[loc.Name] = loc; } } } string portalDevicesXpath = "portalDevices/monarch[@guid='" + MonarchId.ToString("X") + "']"; XmlElement portalDevicesMonarchNode = doc.DocumentElement.SelectSingleNode(portalDevicesXpath) as XmlElement; if (portalDevicesMonarchNode != null) { foreach (PortalDevice device in mPortalDevices.Values) { device.LoadSettingsXml(portalDevicesMonarchNode); } } XmlElement favoriteLocationsNode = doc.DocumentElement.SelectSingleNode("favoriteLocations") as XmlElement; if (favoriteLocationsNode != null) { foreach (XmlElement node in favoriteLocationsNode.GetElementsByTagName("favorite")) { Location loc = GetLocation(node.GetAttribute("id")); if (loc != null) { loc.IsFavorite = true; } } } XmlElement recentLocationsNode = doc.DocumentElement.SelectSingleNode("recentLocations") as XmlElement; if (recentLocationsNode != null) { lstRecent.Clear(); int ct = 0; foreach (XmlElement node in recentLocationsNode.GetElementsByTagName("recent")) { Location loc = GetLocation(node.GetAttribute("id")); if (loc != null) { MyClasses.MetaViewWrappers.IListRow row = lstRecent.Add(); row[LocationList.Icon][1] = loc.Icon; row[LocationList.Name][0] = loc.Name; row[LocationList.GoIcon][1] = GoIcon; row[LocationList.ID][0] = loc.Id.ToString(); } if (ct++ >= MaxRecentLocations) { break; } } UpdateListCoords(lstRecent, chkRecentShowRelative.Checked); } XmlElement recentCoordsNode = doc.DocumentElement.SelectSingleNode("recentCoords") as XmlElement; if (recentCoordsNode != null) { lstRecentCoords.Clear(); foreach (XmlElement node in recentCoordsNode.GetElementsByTagName("recent")) { if (Coordinates.TryParse(node.GetAttribute("coords"), out coords)) { MyClasses.MetaViewWrappers.IListRow row = lstRecentCoords.Add(); row[RecentCoordsList.Coords][0] = coords.ToString(); if (node.HasAttribute("name")) { row[RecentCoordsList.Name][0] = node.GetAttribute("name"); } if (node.HasAttribute("icon")) { int icon; string iconHex = node.GetAttribute("icon"); if (int.TryParse(iconHex, NumberStyles.HexNumber, null, out icon)) { row[RecentCoordsList.Icon][1] = icon; } } } } } if (!arrowLoaded) { LoadArrowImage("Chrome"); } } catch (Exception ex) { Util.HandleException(ex, "Error encountered while loading settings.xml file", true); string errorPath = Util.FullPath("settings_error.xml"); if (File.Exists(errorPath)) { File.Delete(errorPath); } settingsFile.MoveTo(errorPath); Util.SevereError("The old settings.xml file has been renamed to settings_error.xml " + "and a new settings.xml will be created with the defaults."); } finally { mSettingsLoaded = true; mSettingsLoadTime = DateTime.Now; } }
void Update() { // Get the forward direction for travelling in Vector3 direction = RouteStart.transform.position - transform.position; { direction.y = 0; } direction.Normalize(); // Move if (Moving) { // temp path testing GetComponent <Rigidbody>().angularVelocity = Vector3.Lerp( GetComponent <Rigidbody>().angularVelocity, (transform.right * Speed), Time.deltaTime * LerpSpeed ); // if close then move on to next node float distance = Vector3.Distance(transform.position, RouteStart.transform.position); if (distance < 1.5f) { GameObject nextnode = RouteStart.GetComponent <EnemyPathNodeScript>().NextNode; if (nextnode) { RouteStart = nextnode; // Reset movement of cube, allow for turning Moving = false; } } } // Rotate else { if (GetComponent <Rigidbody>().angularVelocity.magnitude < 0.1f) { GetComponent <Rigidbody>().isKinematic = true; Vector3 lookdirection = Vector3.RotateTowards(transform.forward, direction, Time.deltaTime * LerpSpeed / 2.0f, 0.0F); transform.rotation = Quaternion.LookRotation(lookdirection); float distance = Vector3.Distance(transform.forward, direction); if (distance < 0.1f) { Moving = true; GetComponent <Rigidbody>().isKinematic = false; } } } // Ensure it hasn't fallen over float distancepos = Vector3.Distance(transform.right, new Vector3(0, 1, 0)); float distanceneg = Vector3.Distance(-transform.right, new Vector3(0, 1, 0)); if ((distancepos < 0.1f) || (distanceneg < 0.1f)) { transform.rotation = Quaternion.LookRotation(direction); } UpdateFall(); UpdateHat(); }