103 lines
4.1 KiB
C#
103 lines
4.1 KiB
C#
using Assets.Scenes.Ride.Scripts.Model.RiderModels;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
|
{
|
|
public class SingleModel : BaseCycling
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="route1"></param>
|
|
/// <param name="manufacturerId"></param>
|
|
/// <param name="deviceNumber"></param>
|
|
/// <param name="antModelId"></param>
|
|
public SingleModel(Route route1, SelectParamModel param)
|
|
: base(route1, CyclingModel.Single)
|
|
{
|
|
//recorderData = recorderData1;
|
|
this.IsRecord = true;
|
|
recorderData = new RecorderDataModel()
|
|
{
|
|
CurrentUser = PubCommData.CurrentUser,
|
|
//BelongUserId = PubCommData.CurrentUser.Id,
|
|
Competitionid = 0,
|
|
ContinueIndex = 0,
|
|
ContinueMark = Guid.NewGuid().ToString(),
|
|
EndDistance = 0,
|
|
IsCompleted = false,
|
|
IsNeedRanking = true,
|
|
CyclingState = CyclingStateEnum.Prepare,
|
|
//ManufacturerId = manufacturerId, //ManufacturerId,
|
|
CurrentRoute = route,
|
|
CurrentRouteStartDistance = 0,
|
|
//DeviceNumber = deviceNumber,//DeviceNumber
|
|
//AntModelId = antModelId,
|
|
StartTime = DateTime.Now
|
|
};
|
|
if (param != null)
|
|
{
|
|
recorderData.EndDistance = param.EndDistance;
|
|
recorderData.CurrentRouteStartDistance = param.EndDistance;
|
|
if (!string.IsNullOrWhiteSpace(param.ContinueMark))
|
|
{
|
|
recorderData.ContinueMark = param.ContinueMark;
|
|
}
|
|
recorderData.ContinueIndex = param.ContinueIndex.GetValueOrDefault(0);
|
|
}
|
|
recorderData.PreDistance = recorderData.EndDistance;
|
|
//Rhino.PowerFun.Services.MapUDPService.Send(route.RouteInstance.Id, riders.First().UserId, route.Point.First());
|
|
|
|
|
|
riders = new List<BaseRider>();
|
|
var rider = new OnlineRiderModel()
|
|
{
|
|
NickName = PubCommData.CurrentUser.Nickname,
|
|
UserId = PubCommData.CurrentUser.Id,
|
|
WxHeadImg = PubCommData.CurrentUser.WxHeadImg + "?t=1",
|
|
//Point = new GeoJSON.Net.Geometry.GeographicPosition(this.route.RouteInstance.Point[0], this.route.RouteInstance.Point[1]),
|
|
EndDistance = recorderData.EndDistance
|
|
};
|
|
rider.Point = _turfHelper.Along(rider.EndDistance);
|
|
|
|
riders.Add(rider);
|
|
}
|
|
|
|
protected override void Run(TargetData targetData)
|
|
{
|
|
//base.BeforeRun(targetData);
|
|
var dis1 = SpeedToDistance(targetData._Speed);
|
|
currentDistance = recorderData.EndDistance + dis1;//实时计算距离
|
|
if (recorderData.CyclingState == CyclingStateEnum.Prepare || recorderData.CyclingState == CyclingStateEnum.Stop)
|
|
{
|
|
currentDistance = recorderData.EndDistance;
|
|
}
|
|
if (recorderData.CyclingState == CyclingStateEnum.Cycling)
|
|
{
|
|
//Console.WriteLine($"{Ticks + 1}, 总距离:{currentDistance},速度:{ targetData._Speed },移动距离:{ dis1 }");
|
|
}
|
|
riders.RemoveAll(r => r.IsSelf == false);
|
|
var onlineUsers = MapUDPService.GetOnlineUsers(recorderData.CurrentRoute.RouteInstance.Id).Where(d => d.IsSelf == false)
|
|
.ToList();
|
|
|
|
foreach (var item in onlineUsers)
|
|
{
|
|
riders.Add(new OnlineRiderModel()
|
|
{
|
|
NickName = item.Name,
|
|
UserId = item.Id,
|
|
WxHeadImg = item.HeadImage,
|
|
Point = new GeoJSON.Net.Geometry.GeographicPosition(item.Point[0], item.Point[1]),
|
|
EndDistance = item.EndDistance,
|
|
PreDistance = item.PreDistance,
|
|
});
|
|
}
|
|
base.Run(targetData);
|
|
}
|
|
}
|
|
}
|