12121
This commit is contained in:
@@ -46,6 +46,15 @@ public class MapController : ControllerBase
|
||||
int area = StateHelper.areaId;
|
||||
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 = false;
|
||||
@@ -97,7 +106,18 @@ public class MapController : ControllerBase
|
||||
|
||||
#endregion
|
||||
|
||||
object ret = new { mapInfo, cityInfo, npcData, chatData, cityShow, nearUser, noReadMsg = noReadMsg[3] };
|
||||
|
||||
|
||||
object ret = new
|
||||
{
|
||||
mapInfo,
|
||||
cityInfo,
|
||||
npcData,
|
||||
chatData,
|
||||
cityShow,
|
||||
nearUser,
|
||||
noReadMsg = noReadMsg[3]
|
||||
};
|
||||
|
||||
return PoAction.Ok(ret);
|
||||
}
|
||||
@@ -298,7 +318,7 @@ public class MapController : ControllerBase
|
||||
}
|
||||
|
||||
var MySeaMap = await _mapService.GetUserCityMapData(userId);
|
||||
if (MySeaMap.Any(it => it.cityId == cityId)==false)
|
||||
if (MySeaMap.Any(it => it.cityId == cityId) == false)
|
||||
{
|
||||
return PoAction.Message("您暂未获取该城市海图!");
|
||||
}
|
||||
@@ -345,6 +365,210 @@ public class MapController : ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户航海接口
|
||||
/// </summary>
|
||||
/// <param name="npcId"></param>
|
||||
/// <param name="cityId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> UserRunMap(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 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("您暂未获取该城市海图!");
|
||||
}
|
||||
|
||||
var userShip = await _weightService.GetUserShip(userId);
|
||||
if (userShip.Count == 0)
|
||||
{
|
||||
return PoAction.Message("购买船只后才可以航行哦!");
|
||||
}
|
||||
|
||||
var runInfo = await _mapService.GetUserRun(userId);
|
||||
if (runInfo.status != 0)
|
||||
{
|
||||
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));
|
||||
int jl = GameTool.ComputeMile(onMap.mapId, cityInfo.toMap);
|
||||
need = userShip.Max(it => (int)it.copper) * jl;
|
||||
if (myAcc < need)
|
||||
{
|
||||
return PoAction.Message("铜贝不足!");
|
||||
}
|
||||
|
||||
isCanTo = true;
|
||||
}
|
||||
|
||||
if (isCanTo)
|
||||
{
|
||||
if (await _mapService.SaveUserRunInfo(userId, StateHelper.areaId, onMap.mapId, 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("传送失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户航行状态
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> GetUserRun()
|
||||
{
|
||||
var userId = StateHelper.userId;
|
||||
var runInfo = await _mapService.GetUserRun(userId);
|
||||
if (runInfo.status != 1)
|
||||
{
|
||||
return PoAction.Message("不在航行状态", 100);
|
||||
}
|
||||
|
||||
var onCity = await _mapService.GetCityInfoByMapId(runInfo.onMap);
|
||||
var toCity = await _mapService.GetCityInfoByMapId(runInfo.toMap);
|
||||
int isShip = 0;
|
||||
int safety = 0;
|
||||
|
||||
return PoAction.Ok(new
|
||||
{
|
||||
onCity = onCity.cityName,
|
||||
toCity = toCity.cityName,
|
||||
distance = runInfo.distance,
|
||||
position = runInfo.position,
|
||||
isShip = isShip,
|
||||
safety = safety
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消航行
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> StopUserRun()
|
||||
{
|
||||
var userId = StateHelper.userId;
|
||||
var runInfo = await _mapService.GetUserRun(userId);
|
||||
if (runInfo.status != 1)
|
||||
{
|
||||
return PoAction.Message("不在航行状态", 100);
|
||||
}
|
||||
|
||||
if (await _mapService.StopUserRun(userId))
|
||||
{
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("取消失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> UserMapRuning()
|
||||
{
|
||||
var userId = StateHelper.userId;
|
||||
var runInfo = await _mapService.GetUserRun(userId);
|
||||
if (runInfo.status != 1)
|
||||
{
|
||||
return PoAction.Message("不在航行状态", 100);
|
||||
}
|
||||
var userShip = await _weightService.GetUserShip(userId);
|
||||
if (userShip.Count == 0)
|
||||
{
|
||||
return PoAction.Message("购买船只后才可以航行哦!");
|
||||
}
|
||||
|
||||
int spend = userShip.Sum(it => (int)it.speed) / userShip.Count;
|
||||
if ((runInfo.position + spend) >= runInfo.distance)
|
||||
{
|
||||
await _mapService.StopUserRun(userId);
|
||||
var onMap = await _mapService.GetUserOnMap(userId);
|
||||
await _mapService.UpdateUserOnMap(onMap, runInfo.toMap);
|
||||
return PoAction.Message("航行完成!", 100);
|
||||
}
|
||||
else
|
||||
{
|
||||
runInfo.position += spend;
|
||||
runInfo.upTime = TimeExtend.GetTimeStampSeconds;
|
||||
if (await _mapService.UpdateUserRunInfo(runInfo))
|
||||
{
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("航行错误,请重试!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region npc相关
|
||||
|
||||
Reference in New Issue
Block a user