using Newtonsoft.Json;
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;
private readonly IUnitUserAttrService _attrService;
private readonly IMessageService _messageService;
private readonly IUnitUserWeight _weightService;
private readonly IUnitUserAccService _accService;
private readonly IGameSkillService _skillService;
private readonly IGameGoodsService _goodsService;
private readonly IGameTeamService _teamService;
private readonly IGameMonsterService _monsterService;
private readonly IGameFightService _fightService;
private readonly IOnHookService _hookService;
private readonly IGameTaskService _taskService;
private readonly INoticeService _noticeService;
public MapController(IUnitUserService userService, IGameMapService mapService, IGameChatService chatService,
IUnitUserAttrService attrService, IMessageService messageService, IUnitUserWeight weightService,
IUnitUserAccService accService, IGameSkillService skillService, IGameGoodsService goodsService,
IGameTeamService teamService, IGameMonsterService monsterService, IGameFightService fightService,
IOnHookService hookService, IGameTaskService taskService, INoticeService noticeService)
{
_userService = userService;
_mapService = mapService;
_chatService = chatService;
_attrService = attrService;
_messageService = messageService;
_weightService = weightService;
_accService = accService;
_skillService = skillService;
_goodsService = goodsService;
_teamService = teamService;
_monsterService = monsterService;
_fightService = fightService;
_hookService = hookService;
_taskService = taskService;
_noticeService = noticeService;
}
#region 地图相关
///
/// 获取地图主页信息
///
///
///
[HttpGet]
public async Task GetMapData(string? map)
{
string userId = StateHelper.userId;
int area = StateHelper.areaId;
string gameTips = string.Empty;
game_city_map mapInfo = new game_city_map();
#region 前置条件处理
var userRunInfo = await _mapService.GetUserRun(userId);
if (userRunInfo.status != 0)
{
return PoAction.Message("正在航行状态", 103);
}
#endregion
#region 地图导向处理
bool isSelfMap = string.IsNullOrEmpty(map);
if (!isSelfMap)
{
//血量为0得时候地图点为本身
var myBlood = await _attrService.GetUserBlood(userId);
if (myBlood.blood < 1)
{
//设置默认地图点
await _mapService.SetUserMapDefault(userId);
isSelfMap = true;
gameTips = "➢当前体力为0,恢复一下吧!";
}
}
if (isSelfMap)
{
var onMap = await _mapService.GetUserOnMap(userId);
mapInfo = await _mapService.GetMapInfo(onMap.mapId);
}
else
{
mapInfo = await _mapService.GetToMapInfo(userId, map, false);
}
#endregion
//公聊信息
var myTeam = await _teamService.GetUserTeamData(userId);
string teamId = myTeam.teamId;
string groupId = "";
var chatData = await _chatService.GetChatTop(userId, area, 2, teamId, groupId);
var npcData = await _mapService.GetMapNpcModel(userId, mapInfo.mapId, area); //NPC信息
//获取怪物
var monsterData = await _monsterService.GetMapMonster(userId, mapInfo.mapId, teamId);
var nearUser =
await _mapService.GetMapUser(mapInfo.mapId, area, (int)mapInfo.lookArea, [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
var busData = await _mapService.GetMapBus(mapInfo.mapId, 0, 0); //地图业务
IEnumerable