using Microsoft.AspNetCore.Mvc; namespace Application.Web.Controllers.Map; /// /// 地图接口 /// [ApiExplorerSettings(GroupName = "Map")] [Route("Map/[controller]/[action]")] [ApiController] [Authorize] public class MapController : ControllerBase { private readonly IUnitUserService _userService; private readonly IGameMapService _mapService; private readonly IGameChatService _chatService; public MapController(IUnitUserService userService, IGameMapService mapService, IGameChatService chatService) { _userService = userService; _mapService = mapService; _chatService = chatService; } /// /// 获取地图主页信息 /// /// /// [HttpGet] public async Task GetMapData(string? map) { string userId = StateHelper.userId; int area = StateHelper.areaId; var onMap = await _mapService.GetUserOnMap(userId); game_city_map mapInfo = new game_city_map(); if (string.IsNullOrEmpty(map)) { mapInfo = await _mapService.GetMapInfo(onMap.mapId); } else { mapInfo = await _mapService.GetMapInfo(map); } //公聊信息 string teamId = ""; string groupId = ""; var chatData = await _chatService.GetChatTop(area, 2, teamId, groupId); var npcData = await _mapService.GetMapNpc(mapInfo.mapId); //NPC信息 npcData = npcData.FindAll(it => GameTool.AreaVerify(StateHelper.areaId, it.areaId)); var nearUser = await _mapService.GetMapUser(mapInfo.mapId, area, (int)mapInfo.lookArea, new List { userId }, 3); //获取附近的人 var cityInfo = await _mapService.GetCityInfo((int)mapInfo.cityId); //城市信息 var cityShow = await _mapService.GetMapCity(cityInfo.cityId); //城内地图 #region 更新在线 string ip = ComHelper.GetClientUserIp(HttpContext); await _mapService.UpdateUserOnMap(userId, ip, mapInfo.mapId); #endregion object ret = new { mapInfo, cityInfo, npcData, chatData, cityShow, nearUser }; return PoAction.Ok(ret); } /// /// 获取地图在线玩家 /// /// /// /// [HttpGet] public async Task GetMapUser(int page) { RefAsync Total = 0; string userId = StateHelper.userId; int areaId = StateHelper.areaId; var onMap = await _mapService.GetUserOnMap(userId); var mapInfo = await _mapService.GetMapInfo(onMap.mapId); if (mapInfo == null) { return PoAction.Message("地图不存在!"); } var data = await _mapService.GetMapUser(onMap.mapId, areaId, (int)mapInfo.lookArea, new List { userId }, page, 10, Total); return PoAction.Ok(new { data, total = Total.Value}); } }