2021-06-24 18:19:28 +08:00
|
|
|
|
using Assets.Scenes.Ride.Scripts.Model.RiderModels;
|
|
|
|
|
|
using Assets.Scripts;
|
|
|
|
|
|
using Assets.Scripts.Apis;
|
|
|
|
|
|
using Assets.Scripts.Apis.Models;
|
2021-06-29 18:03:20 +08:00
|
|
|
|
using Mapbox.Utils;
|
2021-06-24 18:19:28 +08:00
|
|
|
|
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 CompetitionModel : BaseCycling
|
|
|
|
|
|
{
|
2021-06-29 18:03:20 +08:00
|
|
|
|
private Vector2d firstPoint { get; set; }
|
|
|
|
|
|
public CompetitionRankingModel competitionRankingModel { get; set; }
|
|
|
|
|
|
|
2021-06-24 18:19:28 +08:00
|
|
|
|
private MapCompetitionApi mapCompetitionApi;
|
|
|
|
|
|
|
2021-06-29 18:03:20 +08:00
|
|
|
|
public MapCompetition mapCompetition;
|
2021-06-24 18:19:28 +08:00
|
|
|
|
|
|
|
|
|
|
private List<CompetitionRankingResultModel> mapWorkoutRecordRankings = new List<CompetitionRankingResultModel>();
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 第一个到终点的时间
|
|
|
|
|
|
/// </summary>
|
2021-06-29 18:03:20 +08:00
|
|
|
|
private DateTime? FirstEndTime { get; set; }
|
2021-06-24 18:19:28 +08:00
|
|
|
|
|
|
|
|
|
|
public override bool CanPause => false;
|
|
|
|
|
|
|
2021-06-29 18:03:20 +08:00
|
|
|
|
public override string ShowTime
|
2021-06-24 18:19:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2021-07-23 09:04:56 +08:00
|
|
|
|
//if (CanStart())
|
2021-06-24 18:19:28 +08:00
|
|
|
|
{
|
2021-06-29 18:03:20 +08:00
|
|
|
|
var second = Math.Ceiling((Now - mapCompetition.StartTime.ToLocalTime()).TotalSeconds);
|
2021-06-24 18:19:28 +08:00
|
|
|
|
|
|
|
|
|
|
var ts = TimeSpan.FromSeconds(second);
|
|
|
|
|
|
return $"{ (int)ts.TotalHours }:{ts:mm}:{ts:ss}";
|
|
|
|
|
|
}
|
|
|
|
|
|
return "00:00:00";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-06-29 18:03:20 +08:00
|
|
|
|
AbstractPlayer currentPlayer;
|
|
|
|
|
|
public CompetitionModel(Route route1, RouteResultParam param,AbstractPlayer player)
|
2021-06-24 18:19:28 +08:00
|
|
|
|
: base(route1, CyclingModel.Competition)
|
2021-06-29 18:03:20 +08:00
|
|
|
|
{
|
|
|
|
|
|
currentPlayer = player;//当前选中用户
|
2021-06-24 18:19:28 +08:00
|
|
|
|
mapCompetitionApi = new MapCompetitionApi();
|
|
|
|
|
|
//param.EndDistance = 18;
|
|
|
|
|
|
recorderData = new RecorderDataModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
CurrentUser = App.CurrentUser,
|
|
|
|
|
|
//BelongUserId = PubCommData.CurrentUser.Id,
|
|
|
|
|
|
Competitionid = param.CompetitionId??0,
|
|
|
|
|
|
ContinueIndex = param.ContinueIndex == null ? 0 : (int)param.ContinueIndex + 1,
|
2021-06-29 18:03:20 +08:00
|
|
|
|
ContinueMark = string.IsNullOrEmpty(param.ContinueMark) ? Guid.NewGuid().ToString() : param.ContinueMark,
|
2021-06-24 18:19:28 +08:00
|
|
|
|
EndDistance = param.EndDistance == 0 ? 0 : param.EndDistance,
|
|
|
|
|
|
IsCompleted = false,
|
|
|
|
|
|
IsNeedRanking = true,
|
|
|
|
|
|
CyclingState = CyclingStateEnum.Prepare,
|
|
|
|
|
|
//ManufacturerId = ManufacturerId,
|
|
|
|
|
|
CurrentRoute = route,
|
|
|
|
|
|
CurrentRouteStartDistance = param.EndDistance == 0 ? 0 : param.EndDistance,
|
|
|
|
|
|
//DeviceNumber = DeviceNumber,
|
|
|
|
|
|
//AntModelId = antModelId
|
2021-12-07 16:44:36 +08:00
|
|
|
|
selectParam = param,
|
2021-06-24 18:19:28 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
IsRecord = true;
|
|
|
|
|
|
|
|
|
|
|
|
riders = new List<BaseRider>();
|
|
|
|
|
|
var rider = new OnlineRiderModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
NickName = App.CurrentUser.Nickname,
|
|
|
|
|
|
UserId = App.CurrentUser.Id,
|
|
|
|
|
|
WxHeadImg = App.CurrentUser.WxHeadImg,
|
|
|
|
|
|
EndDistance = param.EndDistance == 0 ? 0 : param.EndDistance
|
|
|
|
|
|
};
|
|
|
|
|
|
if (recorderData.CurrentRouteStartDistance > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
rider.Point = _turfHelper.Along(param.EndDistance);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
rider.Point = new GeoJSON.Net.Geometry.GeographicPosition(this.route.RouteInstance.Point[0], this.route.RouteInstance.Point[1]);
|
|
|
|
|
|
}
|
2021-06-29 18:03:20 +08:00
|
|
|
|
//riders.Add(rider);//剔除自己
|
2021-06-24 18:19:28 +08:00
|
|
|
|
|
|
|
|
|
|
var result = mapCompetitionApi.GetById(param.CompetitionId??0);
|
2021-06-29 18:03:20 +08:00
|
|
|
|
if (result.result == false || result.data == null)
|
2021-06-24 18:19:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2021-06-29 18:03:20 +08:00
|
|
|
|
mapCompetition = result.data;
|
2021-06-24 18:19:28 +08:00
|
|
|
|
FirstEndTime = mapCompetition.FirstEndTime;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-29 18:03:20 +08:00
|
|
|
|
protected override void BeforeRunAfterPakcData()
|
2021-06-24 18:19:28 +08:00
|
|
|
|
{
|
2021-06-29 18:03:20 +08:00
|
|
|
|
//#region 设置第一名的坐标
|
|
|
|
|
|
//if (!FirstEndTime.HasValue)
|
2021-06-24 18:19:28 +08:00
|
|
|
|
//{
|
2021-06-29 18:03:20 +08:00
|
|
|
|
// var firstItem = base.realRiders.OrderByDescending(w => w.NextDistance).FirstOrDefault();
|
|
|
|
|
|
// if (firstItem != null)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// firstPoint = new Vector2d(firstItem.Point.Latitude, firstItem.Point.Longitude);
|
|
|
|
|
|
// }
|
2021-06-24 18:19:28 +08:00
|
|
|
|
//}
|
2021-06-29 18:03:20 +08:00
|
|
|
|
//#endregion
|
2021-06-24 18:19:28 +08:00
|
|
|
|
|
2021-08-10 16:36:13 +08:00
|
|
|
|
var userList = MapUDPService.GetCompetitionOnlineUsers(recorderData.Competitionid).OrderByDescending(u => u.IsCompleted).ThenBy(d => d.CreateTime).ThenByDescending(d => d.EndDistance);
|
2021-06-24 18:19:28 +08:00
|
|
|
|
riders.RemoveAll(r => r.IsSelf == false);
|
|
|
|
|
|
int index = 0;
|
|
|
|
|
|
List<CompetitionRankingSortModel> sort = new List<CompetitionRankingSortModel>();
|
|
|
|
|
|
|
|
|
|
|
|
if (userList.Any())
|
|
|
|
|
|
{
|
2021-06-29 18:03:20 +08:00
|
|
|
|
var currentDistance = currentPlayer.TotalDistance;
|
2021-06-24 18:19:28 +08:00
|
|
|
|
foreach (var item in userList)
|
|
|
|
|
|
{
|
|
|
|
|
|
#region 记录第一个冲线的时间
|
|
|
|
|
|
if (item.IsCompleted && !FirstEndTime.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
FirstEndTime = Now;
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
if (item.IsSelf == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
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,
|
2021-07-23 09:04:56 +08:00
|
|
|
|
PreDistance = item.PreDistance,
|
|
|
|
|
|
Power = item.Power,
|
|
|
|
|
|
HeartRate = item.HeartRate,
|
|
|
|
|
|
Cadence = item.Cadence,
|
|
|
|
|
|
TotalTicks = item.TotalTicks,
|
2021-07-30 15:38:40 +08:00
|
|
|
|
WeightKg = item.WeightKg,
|
2021-06-24 18:19:28 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
{
|
2021-09-17 22:20:05 +08:00
|
|
|
|
index++;
|
|
|
|
|
|
double near = Math.Round(item.EndDistance - currentDistance, 2); //Math.Round(TurfHelper.GetDistances(point, item.Point), 2);
|
|
|
|
|
|
|
|
|
|
|
|
sort.Add(new CompetitionRankingSortModel
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = index,
|
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
|
Near = near,
|
|
|
|
|
|
KGWeight = Math.Round(item.WeightKg, 2).ToString(),
|
|
|
|
|
|
Speed = Math.Round(item.Speed, 1),
|
|
|
|
|
|
CountryImg = item.Country,//ConfigHelper.Host + $"User/GetCountryImg?userid={ item.Id }",
|
|
|
|
|
|
UserId = item.Id,
|
|
|
|
|
|
IsSelf = item.IsSelf,
|
|
|
|
|
|
Headimage = item.HeadImage,
|
|
|
|
|
|
CreateTime = DateTime.MaxValue,
|
|
|
|
|
|
EndDistance = item.EndDistance,
|
|
|
|
|
|
IsCompleted = item.IsCompleted
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2021-06-24 18:19:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region 骑行结束,比赛结果展示数据
|
|
|
|
|
|
var results = new List<CompetitionResultModel>();
|
2021-07-29 20:01:38 +08:00
|
|
|
|
if (recorderData.IsCompleted || recorderData.Saved || mapCompetition.HasRecord || CanShowTopList())
|
2021-06-24 18:19:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
var users1 = userList.Where(d => d.IsCompleted || d.Saved);
|
|
|
|
|
|
if ((users1.Any() && users1.Any(d => mapWorkoutRecordRankings.All(u => u.UserId != d.Id)))
|
|
|
|
|
|
|| mapWorkoutRecordRankings.All(u => u.UserId != recorderData.BelongUserId))
|
|
|
|
|
|
{
|
2021-09-07 16:11:15 +08:00
|
|
|
|
var rrr = mapCompetitionApi.GetRankingListAsync(recorderData.Competitionid);
|
2021-06-24 18:19:28 +08:00
|
|
|
|
if (rrr.result)
|
|
|
|
|
|
{
|
|
|
|
|
|
mapWorkoutRecordRankings = rrr.data;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-09-17 22:20:05 +08:00
|
|
|
|
|
2021-06-24 18:19:28 +08:00
|
|
|
|
foreach (var ranking in mapWorkoutRecordRankings)
|
|
|
|
|
|
{
|
|
|
|
|
|
//var ranking = mapWorkoutRecordRankings.SingleOrDefault(r => r.UserId == item.Id);
|
2021-08-10 16:36:13 +08:00
|
|
|
|
var needUpdate = sort.Where(c => c.UserId == ranking.UserId).FirstOrDefault();
|
|
|
|
|
|
if (needUpdate != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
needUpdate.CreateTime = ranking.CreateTime.ToLocalTime();
|
2021-09-17 18:31:00 +08:00
|
|
|
|
needUpdate.Index = ranking.Index;
|
|
|
|
|
|
needUpdate.IsCompleted = true;
|
2021-08-10 16:36:13 +08:00
|
|
|
|
}
|
2021-06-24 18:19:28 +08:00
|
|
|
|
|
|
|
|
|
|
var createTime = "";
|
|
|
|
|
|
if (ranking != null)
|
|
|
|
|
|
{
|
2021-08-10 16:36:13 +08:00
|
|
|
|
createTime = ranking.CreateTime.ToLocalTime().ToString(); //.ToString("yyyy-MM-dd HH:mm:ss");
|
2021-06-24 18:19:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
results.Add(new CompetitionResultModel
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = ranking.Index,
|
|
|
|
|
|
Name = ranking.NickName,
|
2021-07-16 18:37:02 +08:00
|
|
|
|
UserId = ranking.UserId,
|
2021-06-24 18:19:28 +08:00
|
|
|
|
Weight = ranking?.Weight ?? 0,
|
|
|
|
|
|
WeightKg = ranking?.WeightKg ?? 0,
|
|
|
|
|
|
//Time = ranking?.TotalTime ?? "",
|
|
|
|
|
|
Power = ranking?.AveragePower ?? 0,
|
|
|
|
|
|
BicycleWeight = ranking?.BicycleWeight ?? 0,
|
2021-08-10 16:36:13 +08:00
|
|
|
|
HeartRate = ranking?.AverageHeartRate,
|
2021-06-24 18:19:28 +08:00
|
|
|
|
DeviceType = ranking?.DeviceType ?? "",
|
|
|
|
|
|
CreateTime = createTime,
|
|
|
|
|
|
TripTime = ranking?.TripTime ?? "",
|
|
|
|
|
|
CompleteTime = ranking?.CompleteTime,
|
2021-07-23 09:04:56 +08:00
|
|
|
|
Gap = ranking?.Gap ?? "",
|
|
|
|
|
|
Country = ranking.Country,
|
|
|
|
|
|
WxHeadImg = ranking.WxHeadImg
|
2021-06-24 18:19:28 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2021-07-23 09:04:56 +08:00
|
|
|
|
#region 骑行实时排名&比赛结果列表 取前六名
|
|
|
|
|
|
|
|
|
|
|
|
List<CompetitionTopModel> CompetitionTopList = new List<CompetitionTopModel>();
|
|
|
|
|
|
|
2021-07-29 20:01:38 +08:00
|
|
|
|
var resultList = results.Take(6);
|
2021-07-30 09:53:49 +08:00
|
|
|
|
//var count = 6 - resultList.Count();
|
2021-07-23 09:04:56 +08:00
|
|
|
|
//先取比赛结果
|
|
|
|
|
|
foreach (var item in resultList)
|
|
|
|
|
|
{
|
|
|
|
|
|
CompetitionTopList.Add(new CompetitionTopModel
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = item.Index,
|
|
|
|
|
|
TripTime = item.TripTime,
|
|
|
|
|
|
Country = item.Country,
|
|
|
|
|
|
Name = item.Name,
|
2021-07-27 19:34:33 +08:00
|
|
|
|
UserId = item.UserId,
|
|
|
|
|
|
Head = item.WxHeadImg,
|
2021-07-23 09:04:56 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-30 09:53:49 +08:00
|
|
|
|
//if (count > 0)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// var ss = sort.Where(c => !resultList.Select(p => p.UserId).Contains(c.UserId)).Take(count);
|
|
|
|
|
|
// foreach (var item in ss)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// CompetitionTopList.Add(new CompetitionTopModel
|
|
|
|
|
|
// {
|
|
|
|
|
|
// Index = item.Index,
|
|
|
|
|
|
// TripTime = "———",
|
|
|
|
|
|
// Country = item.CountryImg,
|
|
|
|
|
|
// Name = item.Name,
|
|
|
|
|
|
// UserId = item.UserId,
|
|
|
|
|
|
// Head = item.Headimage,
|
|
|
|
|
|
// });
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
2021-07-23 09:04:56 +08:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2021-06-29 18:03:20 +08:00
|
|
|
|
competitionRankingModel = new CompetitionRankingModel
|
2021-06-24 18:19:28 +08:00
|
|
|
|
{
|
2021-06-29 18:03:20 +08:00
|
|
|
|
Sorts = sort,//骑行实时排名
|
|
|
|
|
|
MyRanking = sort.FindIndex(n => n.UserId == currentPlayer.UserId) + 1,//切换人物显示对应人物的排名
|
|
|
|
|
|
Total = sort.Count,//总人数
|
2021-07-23 09:04:56 +08:00
|
|
|
|
Results = results,//比赛结果列表,
|
|
|
|
|
|
TopList = CompetitionTopList,
|
2021-06-24 18:19:28 +08:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 赛事模式有继续骑行,重写执行方法
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="targetData"></param>
|
|
|
|
|
|
public override void Run(TargetData targetData)
|
|
|
|
|
|
{
|
2021-06-29 18:03:20 +08:00
|
|
|
|
|
|
|
|
|
|
#region 获取当前路线在线用户
|
|
|
|
|
|
riders.RemoveAll(r => r.IsSelf == false);
|
|
|
|
|
|
var onlineUsers = MapUDPService.GetCompetitionOnlineUsers(mapCompetition.Id).Where(d => d.IsSelf == false)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
foreach (var item in onlineUsers)
|
2021-06-24 18:19:28 +08:00
|
|
|
|
{
|
2021-06-29 18:03:20 +08:00
|
|
|
|
riders.Add(new OnlineRiderModel()
|
2021-06-24 18:19:28 +08:00
|
|
|
|
{
|
2021-06-29 18:03:20 +08:00
|
|
|
|
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,
|
|
|
|
|
|
WeightKg = item.WeightKg,
|
|
|
|
|
|
});
|
2021-06-24 18:19:28 +08:00
|
|
|
|
}
|
2021-06-29 18:03:20 +08:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
//TODO:接力赛
|
|
|
|
|
|
////base.BeforeRun(targetData);
|
|
|
|
|
|
//if (recorderData.CyclingState == CyclingStateEnum.Prepare)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// if (recorderData.EndDistance != 0)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// currentDistance = recorderData.EndDistance;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else
|
|
|
|
|
|
// {
|
|
|
|
|
|
// currentDistance = 0;
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
//else if (recorderData.CyclingState == CyclingStateEnum.Cycling)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// currentDistance = recorderData.EndDistance + SpeedToDistance(targetData._Speed);
|
|
|
|
|
|
//}
|
|
|
|
|
|
base.Run(targetData);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//显示结果当前用户保存或者产生第一名
|
|
|
|
|
|
public bool CanShowResult()
|
|
|
|
|
|
{
|
|
|
|
|
|
return mapCompetition?.HasRecord ?? false || mapCompetition ?.FirstEndTime != null;
|
|
|
|
|
|
}
|
|
|
|
|
|
//关门时间到了退出骑行场景
|
|
|
|
|
|
public bool CanQuit()
|
|
|
|
|
|
{
|
2021-07-28 16:30:07 +08:00
|
|
|
|
var end1 = (int)Math.Floor((mapCompetition.EndTime.ToLocalTime() - Now).TotalSeconds);
|
|
|
|
|
|
if (!FirstEndTime.HasValue)
|
2021-06-24 18:19:28 +08:00
|
|
|
|
{
|
2021-07-28 16:30:07 +08:00
|
|
|
|
return end1 <= 0;
|
2021-06-24 18:19:28 +08:00
|
|
|
|
}
|
2021-07-28 16:30:07 +08:00
|
|
|
|
|
|
|
|
|
|
var end2 = (int)Math.Floor((FirstEndTime.Value.ToLocalTime().AddMinutes(mapCompetition.CloseTime) - Now).TotalSeconds);
|
|
|
|
|
|
return end2 <= 0;
|
2021-06-24 18:19:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-29 20:01:38 +08:00
|
|
|
|
public bool CanShowTopList()
|
|
|
|
|
|
{
|
|
|
|
|
|
var end1 = (int)Math.Floor((mapCompetition.EndTime.ToLocalTime() - Now).TotalSeconds);
|
|
|
|
|
|
if (!FirstEndTime.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
return end1 <= 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var end2 = (int)Math.Floor((FirstEndTime.Value.ToLocalTime() - Now).TotalSeconds);
|
|
|
|
|
|
return end2 <= 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-24 18:19:28 +08:00
|
|
|
|
public bool CanStart()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (mapCompetition == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
//if (mapCompetition.CanStart)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// return true;
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
if (mapCompetition.HasRecord)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//已结束
|
|
|
|
|
|
if (mapCompetition.Status == 4)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2021-06-29 18:03:20 +08:00
|
|
|
|
if (mapCompetition.StartTime.ToLocalTime() <= Now && mapCompetition.EndTime.ToLocalTime() > Now)
|
2021-06-24 18:19:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int StartCountdown()
|
|
|
|
|
|
{
|
2021-09-09 16:29:22 +08:00
|
|
|
|
if (CanStart()) return -1;
|
2021-06-29 18:03:20 +08:00
|
|
|
|
return (int)Math.Floor((mapCompetition.StartTime.ToLocalTime() - Now).TotalSeconds);
|
2021-06-24 18:19:28 +08:00
|
|
|
|
}
|
2021-07-30 15:38:40 +08:00
|
|
|
|
|
|
|
|
|
|
public int RaceStartTime()
|
|
|
|
|
|
{
|
|
|
|
|
|
return (int)Math.Floor((Now - mapCompetition.StartTime.ToLocalTime() ).TotalSeconds);
|
|
|
|
|
|
}
|
2021-06-24 18:19:28 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 结束倒计时,bool值为true说明倒计时是关门时间
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
2021-07-30 15:38:40 +08:00
|
|
|
|
public (int,int, bool) EndCountDown()
|
2021-06-24 18:19:28 +08:00
|
|
|
|
{
|
2021-07-23 09:04:56 +08:00
|
|
|
|
//if (CanStart() == false) return (0, false);
|
2021-06-24 18:19:28 +08:00
|
|
|
|
//if (recorderData.IsCompleted) return 0;
|
2021-07-30 15:38:40 +08:00
|
|
|
|
var now = Now ;
|
|
|
|
|
|
var mi = now.Millisecond;
|
|
|
|
|
|
now = now.AddMilliseconds(-mi);
|
|
|
|
|
|
|
|
|
|
|
|
var end1 = (int)Math.Floor((mapCompetition.EndTime.ToLocalTime() - now).TotalSeconds);
|
|
|
|
|
|
var s = (int)Math.Floor((now - mapCompetition.EndTime.ToLocalTime()).TotalSeconds);
|
|
|
|
|
|
var start = (int)Math.Floor((now - mapCompetition.StartTime.ToLocalTime()).TotalSeconds);
|
2021-06-24 18:19:28 +08:00
|
|
|
|
if (!FirstEndTime.HasValue)
|
|
|
|
|
|
{
|
2021-07-30 15:38:40 +08:00
|
|
|
|
return (end1, start, false);
|
2021-06-24 18:19:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
//var end2 = (int)Math.Floor((FirstEndTime.Value - Now).TotalSeconds);
|
2021-07-28 14:57:11 +08:00
|
|
|
|
var end2 = (int)Math.Floor((FirstEndTime.Value.ToLocalTime().AddMinutes(mapCompetition.CloseTime) - Now).TotalSeconds);
|
2021-06-24 18:19:28 +08:00
|
|
|
|
if (end1 < end2)
|
|
|
|
|
|
{
|
2021-07-30 15:38:40 +08:00
|
|
|
|
return (end1, start, false);
|
2021-06-24 18:19:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
//return Math.Min(end1, end2);
|
2021-07-30 15:38:40 +08:00
|
|
|
|
return (end2, start, true);
|
2021-06-24 18:19:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|