This commit is contained in:
Putoo
2026-06-02 17:58:36 +08:00
parent eb81a1c381
commit 8550d85659
11 changed files with 392 additions and 2 deletions

View File

@@ -16,17 +16,24 @@ public class MapController : ControllerBase
private readonly IGameChatService _chatService;
private readonly IUnitUserAttrService _attrService;
private readonly IMessageService _messageService;
private readonly IUnitUserWeight _weightService;
private readonly IUnitUserAccService _accService;
public MapController(IUnitUserService userService, IGameMapService mapService, IGameChatService chatService,
IUnitUserAttrService attrService, IMessageService messageService)
IUnitUserAttrService attrService, IMessageService messageService, IUnitUserWeight weightService,
IUnitUserAccService accService)
{
_userService = userService;
_mapService = mapService;
_chatService = chatService;
_attrService = attrService;
_messageService = messageService;
_weightService = weightService;
_accService = accService;
}
#region
/// <summary>
/// 获取地图主页信息
/// </summary>
@@ -167,6 +174,179 @@ public class MapController : ControllerBase
}
}
/// <summary>
/// 获取传送/航海城市列表
/// </summary>
/// <param name="npcId"></param>
/// <param name="cityId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetCityData(int npcId, int cityId)
{
string userId = StateHelper.userId;
#region NPC验证
var npcInfo = await _mapService.GetNpcInfo(npcId);
if (npcInfo == null)
{
return PoAction.Message("Npc不存在!");
}
if (npcInfo.status != 1)
{
return PoAction.Message("Npc不存在!");
}
if (!npcInfo.bus.Any(it => it.code == nameof(GameEnum.NpcBusCode.MapTo)))
{
return PoAction.Message("业务不可用!");
}
var onMap = await _mapService.GetUserOnMapId(userId);
if (npcInfo.mapId != onMap)
{
return PoAction.Message("Npc不存在!");
}
#endregion
var cityData = await _mapService.GetCityData();
cityData = cityData.FindAll(it => it.type == "DEF_MAP");
List<game_city> area = cityData.FindAll(it => it.parent == 0);
if (cityId == 0)
{
cityId = area[0].cityId;
}
var onCityData = cityData.FindAll(it => it.parent == cityId);
var userCity = await _mapService.GetUserCityMapData(userId);
var AtCity = await _mapService.GetMapCityByMapId(onMap);
List<MapTemp> city = new List<MapTemp>();
onCityData.ForEach(item =>
{
if (userCity.Any(it => it.cityId == item.cityId) && item.cityId != AtCity)
{
MapTemp temp = new MapTemp();
temp.cityId = item.cityId;
temp.cityName = item.cityName;
temp.distance = GameTool.ComputeMile(onMap, item.toMap);
temp.copper = temp.distance * GameConfig.GameToMapNeedCopper;
city.Add(temp);
}
});
string tips = $"*传送消耗:{GameConfig.GameToMapNeedCopper}铜贝/海里<br>*等级低于80级不需要传送费!";
return PoAction.Ok(new { area, city, cityId, tips });
}
/// <summary>
/// 用户传送到地图
/// </summary>
/// <param name="npcId"></param>
/// <param name="cityId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> UserToMap(int npcId, int cityId)
{
string userId = StateHelper.userId;
#region NPC验证
var npcInfo = await _mapService.GetNpcInfo(npcId);
if (npcInfo == null)
{
return PoAction.Message("Npc不存在!");
}
if (npcInfo.status != 1)
{
return PoAction.Message("Npc不存在!");
}
if (!npcInfo.bus.Any(it => it.code == nameof(GameEnum.NpcBusCode.MapTo)))
{
return PoAction.Message("业务不可用!");
}
var onMap = await _mapService.GetUserOnMap(userId);
if (npcInfo.mapId != onMap.mapId)
{
return PoAction.Message("Npc不存在!");
}
#endregion
var cityInfo = await _mapService.GetCityInfo(cityId);
if (cityInfo == null)
{
return PoAction.Message("城市不存在!");
}
var userWeight = await _weightService.GetUserWeightInfo(userId);
if (userWeight.shipOnWeight > 0)
{
return PoAction.Message("背包中存在货物,不可传送,你可以进行航行!");
}
var onMapInfo = await _mapService.GetMapInfo(onMap.mapId);
if (onMapInfo.cityId == cityId)
{
return PoAction.Message("您已在当前城市,无需传送!");
}
var MySeaMap = await _mapService.GetUserCityMapData(userId);
if (MySeaMap.Any(it => it.cityId == cityId)==false)
{
return PoAction.Message("您暂未获取该城市海图!");
}
bool isCanTo = false;
var MyLev = await _attrService.GetUserLev(userId);
if (MyLev < 80)
{
isCanTo = true;
}
int need = 0;
if (isCanTo == false) //判断费用
{
var myAcc = await _accService.GetUserAccInfo(userId, nameof(AccEnum.AccType.copper));
need = GameTool.ComputeMile(onMap.mapId, cityInfo.toMap) * GameConfig.GameToMapNeedCopper;
if (myAcc < need)
{
return PoAction.Message("铜贝不足!");
}
isCanTo = true;
}
if (isCanTo)
{
if (await _mapService.UpdateUserOnMap(onMap, cityInfo.toMap))
{
if (need > 0)
{
await _accService.UpdateUserCopper(userId, 0, need, $"传送到【{cityInfo.cityName}】费用");
}
return PoAction.Ok(true);
}
else
{
return PoAction.Message("传送失败,请稍后尝试!");
}
}
else
{
return PoAction.Message("传送失败,请稍后尝试!");
}
}
#endregion
#region npc相关
/// <summary>