202 lines
5.9 KiB
C#
202 lines
5.9 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Application.Web.Controllers.Map;
|
|
|
|
/// <summary>
|
|
/// 地图接口
|
|
/// </summary>
|
|
[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;
|
|
private readonly IUnitUserAttrService _attrService;
|
|
private readonly IMessageService _messageService;
|
|
|
|
public MapController(IUnitUserService userService, IGameMapService mapService, IGameChatService chatService,
|
|
IUnitUserAttrService attrService, IMessageService messageService)
|
|
{
|
|
_userService = userService;
|
|
_mapService = mapService;
|
|
_chatService = chatService;
|
|
_attrService = attrService;
|
|
_messageService = messageService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取地图主页信息
|
|
/// </summary>
|
|
/// <param name="map"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> GetMapData(string? map)
|
|
{
|
|
string userId = StateHelper.userId;
|
|
int area = StateHelper.areaId;
|
|
game_city_map mapInfo = new game_city_map();
|
|
|
|
#region 地图导向处理
|
|
|
|
bool isSelfMap = false;
|
|
if (!isSelfMap)
|
|
{
|
|
//血量为0得时候地图点为本身
|
|
var myBlood = await _attrService.GetUserBlood(userId);
|
|
if (myBlood.blood < 1)
|
|
{
|
|
//设置默认地图点
|
|
await _mapService.SetUserMapDefult(userId);
|
|
isSelfMap = true;
|
|
}
|
|
}
|
|
|
|
if (isSelfMap)
|
|
{
|
|
var onMap = await _mapService.GetUserOnMap(userId);
|
|
mapInfo = await _mapService.GetMapInfo(onMap.mapId);
|
|
}
|
|
else
|
|
{
|
|
mapInfo = await _mapService.GetToMapInfo(userId, map, false);
|
|
}
|
|
|
|
#endregion
|
|
|
|
//公聊信息
|
|
string teamId = "";
|
|
string groupId = "";
|
|
var chatData = await _chatService.GetChatTop(userId, 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<string> { userId },
|
|
3); //获取附近的人
|
|
|
|
var cityInfo = await _mapService.GetCityInfo((int)mapInfo.cityId); //城市信息
|
|
var cityShow = await _mapService.GetCityShowMap(cityInfo.cityId); //城内地图
|
|
|
|
var noReadMsg = await _messageService.GetNoReadCount(userId);
|
|
|
|
#region 更新在线
|
|
|
|
string ip = ComHelper.GetClientUserIp(HttpContext);
|
|
await _mapService.UpdateUserOnMap(userId, ip, mapInfo.mapId);
|
|
|
|
#endregion
|
|
|
|
object ret = new { mapInfo, cityInfo, npcData, chatData, cityShow, nearUser, noReadMsg = noReadMsg[3] };
|
|
|
|
return PoAction.Ok(ret);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取地图在线玩家
|
|
/// </summary>
|
|
/// <param name="map"></param>
|
|
/// <param name="page"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> GetMapUser(int page)
|
|
{
|
|
RefAsync<int> 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<string> { userId },
|
|
page,
|
|
10, Total);
|
|
|
|
return PoAction.Ok(new { data, total = Total.Value });
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取当前城市所有地图
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> GetUserOnCityMap(string? search)
|
|
{
|
|
string userId = StateHelper.userId;
|
|
var onMap = await _mapService.GetUserOnMap(userId);
|
|
var mapInfo = await _mapService.GetMapInfo(onMap.mapId);
|
|
var data = await _mapService.GetCityMap((int)mapInfo.cityId);
|
|
if (!string.IsNullOrEmpty(search))
|
|
{
|
|
data = data.FindAll(it => it.mapName.Contains(search));
|
|
}
|
|
|
|
return PoAction.Ok(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取自动寻路路径
|
|
/// </summary>
|
|
/// <param name="toMap"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> GetAutoMapPath(string? toMap)
|
|
{
|
|
if (string.IsNullOrEmpty(toMap))
|
|
{
|
|
return PoAction.Message("目标地点不能为空!");
|
|
}
|
|
|
|
string userId = StateHelper.userId;
|
|
var onMap = await _mapService.GetUserOnMap(userId);
|
|
var result = await _mapService.CreateAutoMap(onMap.mapId, toMap);
|
|
if (result.Count > 0)
|
|
{
|
|
return PoAction.Ok(result);
|
|
}
|
|
else
|
|
{
|
|
return PoAction.Message("无法自动寻路!");
|
|
}
|
|
}
|
|
|
|
#region npc相关
|
|
|
|
/// <summary>
|
|
/// 获取NPC相关信息
|
|
/// </summary>
|
|
/// <param name="npcId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> GetNpcInfo(int npcId)
|
|
{
|
|
string userId = StateHelper.userId;
|
|
var data = await _mapService.GetNpcInfo(npcId);
|
|
if (data == null)
|
|
{
|
|
return PoAction.Message("Npc不存在!");
|
|
}
|
|
|
|
if (data.status != 1)
|
|
{
|
|
return PoAction.Message("Npc不存在!");
|
|
}
|
|
|
|
var onMap = await _mapService.GetUserOnMapId(userId);
|
|
if (data.mapId != onMap)
|
|
{
|
|
return PoAction.Message("Npc不存在!");
|
|
}
|
|
|
|
return PoAction.Ok(data);
|
|
}
|
|
|
|
#endregion
|
|
} |