158 lines
6.6 KiB
C#
158 lines
6.6 KiB
C#
using Assets.Scenes.Ride.Scripts.Model.RiderModels;
|
||
using Assets.Scripts;
|
||
using Assets.Scripts.Apis.Models;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
|
||
namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
||
{
|
||
public class GameModel : BaseCycling
|
||
{
|
||
/// <summary>
|
||
/// 第一个到终点的时间
|
||
/// </summary>
|
||
public DateTime? FirstEndTime { get; private set; }
|
||
public int? FirstUserId { get; private set; }
|
||
public GameRoomModel GameRoom { get; private set; }
|
||
public List<RoomRankItem> mapWorkoutRecordRankings = new List<RoomRankItem>();
|
||
public List<CompetitionResultModel> gameRoomResult;//new List<CompetitionResultModel>();
|
||
public GameModel(Route route,RouteResultParam param)
|
||
: base(route, CyclingModel.Single)
|
||
{
|
||
this.IsRecord = true;
|
||
recorderData = new RecorderDataModel()
|
||
{
|
||
CurrentUser = App.CurrentUser,
|
||
Competitionid = 0,
|
||
ContinueIndex = 0,
|
||
ContinueMark = Guid.NewGuid().ToString(),
|
||
EndDistance = 0,
|
||
IsCompleted = false,
|
||
IsNeedRanking = true,
|
||
CyclingState = CyclingStateEnum.Prepare,
|
||
CurrentRoute = route,
|
||
CurrentRouteStartDistance = 0,
|
||
StartTime = DateTime.Now,//UIManager.Now.GetDateTime(),//DateTime.Now
|
||
selectParam = param,
|
||
RoomId = App.gameRoomDetail.RoomId,
|
||
};
|
||
GameRoom = App.gameRoomDetail;
|
||
App.gameRoomDetail = null;
|
||
if (param != null)
|
||
{
|
||
recorderData.EndDistance = param.EndDistance;
|
||
recorderData.CurrentRouteStartDistance = param.EndDistance;
|
||
if (!string.IsNullOrWhiteSpace(param.ContinueMark))
|
||
{
|
||
recorderData.ContinueMark = param.ContinueMark;
|
||
}
|
||
else
|
||
{
|
||
param.ContinueMark = recorderData.ContinueMark;
|
||
}
|
||
recorderData.ContinueIndex = param.ContinueIndex.GetValueOrDefault(0);
|
||
}
|
||
|
||
recorderData.PreDistance = recorderData.EndDistance;
|
||
|
||
riders = new List<BaseRider>();
|
||
}
|
||
|
||
public override void Run(TargetData targetData)
|
||
{
|
||
#region 获取当前路线在线用户
|
||
riders.Clear();
|
||
var onlineUsers = MapUDPService.GetOnlineUsers(recorderData.CurrentRoute.RouteInstance.Id, recorderData.RoomId).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,
|
||
WeightKg = item.WeightKg,
|
||
Sex = item.Sex,
|
||
FrameRate = item.FrameRate,
|
||
Speed = item.Speed
|
||
});
|
||
}
|
||
|
||
#endregion
|
||
base.Run(targetData);
|
||
}
|
||
|
||
protected override void BeforeRunAfterPakcData()
|
||
{
|
||
base.BeforeRunAfterPakcData();
|
||
int index = 0;
|
||
List<CompetitionRankingSortModel> sort = new List<CompetitionRankingSortModel>();
|
||
var userList = MapUDPService.GetOnlineUsers(recorderData.CurrentRoute.RouteInstance.Id,recorderData.RoomId).OrderByDescending(u => u.Saved).ThenBy(d => d.CreateTime).ThenByDescending(d => d.EndDistance);
|
||
if (userList.Any())
|
||
{
|
||
//计算关门时间
|
||
foreach (var item in userList)
|
||
{
|
||
if (!FirstEndTime.HasValue && item.IsCompleted)
|
||
{
|
||
FirstEndTime = Now.AddMinutes(GameRoom.CloseTime);
|
||
FirstUserId = item.Id;
|
||
}
|
||
index++;
|
||
double near = Math.Round(item.EndDistance - currentDistance, 2); //Math.Round(TurfHelper.GetDistances(point, item.Point), 2);
|
||
|
||
if (item.IsCompleted)
|
||
{
|
||
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,
|
||
});
|
||
}
|
||
}
|
||
|
||
#region 骑行结束,比赛结果展示数据
|
||
gameRoomResult = new List<CompetitionResultModel>();
|
||
if (recorderData.IsCompleted || recorderData.Saved)
|
||
{
|
||
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))
|
||
{
|
||
var result = ConfigHelper.GameRoomApi.GetDetail(GameRoom.RoomId);
|
||
if (result.result)
|
||
{
|
||
mapWorkoutRecordRankings = result.data.RoomRankingList;
|
||
}
|
||
}
|
||
|
||
foreach (var ranking in mapWorkoutRecordRankings)
|
||
{
|
||
var needUpdate = sort.Where(c => c.UserId == ranking.UserId).FirstOrDefault();
|
||
if (needUpdate != null)
|
||
{
|
||
ranking.WeightKG = needUpdate.KGWeight;
|
||
needUpdate.Index = ranking.Rank;
|
||
needUpdate.IsCompleted = true;
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
}
|
||
}
|
||
}
|