116 lines
4.0 KiB
C#
116 lines
4.0 KiB
C#
using Assets.Scripts.Apis.Models;
|
|
using GeoJSON.Net.Geometry;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
|
{
|
|
public abstract class BaseCycling
|
|
{
|
|
public CyclingModel Mode { get; private set; }
|
|
|
|
/// <summary>
|
|
/// 是否记录数据
|
|
/// </summary>
|
|
internal bool IsRecord { get; set; }
|
|
|
|
/// <summary>
|
|
/// 骑行数据记录器
|
|
/// </summary>
|
|
public RecorderDataModel recorderData { get; protected set; }
|
|
|
|
public List<BaseRider> riders { get; protected set; }
|
|
/// <summary>
|
|
/// 骑行的路线
|
|
/// </summary>
|
|
public Route route;
|
|
/// <summary>
|
|
/// 计时器
|
|
/// </summary>
|
|
public int Ticks = 0;
|
|
/// <summary>
|
|
/// 当前骑行的距离
|
|
/// </summary>
|
|
protected double currentDistance { get; set; }
|
|
|
|
public virtual bool CanPause => true;
|
|
|
|
protected TurfHelper _turfHelper;
|
|
|
|
protected double Zoom { get; private set; }
|
|
protected string Bounds { get; private set; }
|
|
|
|
protected List<OutUser> realRiders;
|
|
|
|
protected GeographicPosition CenterPoint { get; private set; }
|
|
|
|
/// <summary>
|
|
/// 结束的时间
|
|
/// </summary>
|
|
protected DateTime? EndTime { get; set; }
|
|
|
|
public BaseCycling(Route route, CyclingModel cyclingModel)
|
|
{
|
|
this.route = route;
|
|
this.Mode = cyclingModel;
|
|
_turfHelper = new TurfHelper(route.JsonData.List.Select(d => d.Point));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 骑行函数(如果此方法不满足,可以在子类中重写此方法)
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
public virtual void Run(TargetData targetData)
|
|
{
|
|
//将当前用户的位置发送到udf服务
|
|
SendUserPositionToServer();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// =>发送用户的位置信息到服务端
|
|
/// </summary>
|
|
private void SendUserPositionToServer()
|
|
{
|
|
try
|
|
{
|
|
if (recorderData.RiderDatas.Any())
|
|
{
|
|
var lastData = recorderData.RiderDatas.Last();
|
|
var preDistance = recorderData.PreDistance;
|
|
|
|
var weightKg = Math.Round(lastData._Power / recorderData.CurrentUser.Weight, 2);
|
|
MapUDPService.Send(route.RouteInstance.Id, recorderData.BelongUserId,
|
|
new double[] { lastData._Lat, lastData._Lon },
|
|
recorderData.IsCompleted, false, recorderData.EndDistance,
|
|
true, 1, lastData._Speed, false, preDistance, weightKg, competitionId: recorderData.Competitionid, recorderData.Saved);
|
|
}
|
|
else if (recorderData.EndDistance > 0)//没有骑,但是有初始位置的情况
|
|
{
|
|
var point = _turfHelper.Along(recorderData.EndDistance);
|
|
//MapUDPService.Send(route.RouteInstance.Id, recorderData.BelongUserId, new double[] { point.Latitude, point.Longitude }, competitionId: recorderData.Competitionid);
|
|
MapUDPService.Send(route.RouteInstance.Id, recorderData.BelongUserId, new double[] { point.Latitude, point.Longitude }, endDistance:recorderData.EndDistance,preDistance: recorderData.EndDistance, competitionId: recorderData.Competitionid);
|
|
}
|
|
else
|
|
{
|
|
MapUDPService.Send(route.RouteInstance.Id, recorderData.BelongUserId, route.Point.First().Reverse().ToArray(), competitionId: recorderData.Competitionid);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
protected double SpeedToDistance(double speed)
|
|
{
|
|
return Math.Round(speed / 3600, 5, MidpointRounding.AwayFromZero);
|
|
//return 0.08;
|
|
}
|
|
}
|
|
}
|