12121
This commit is contained in:
69
Service/Application.Domain.Entity/game/user/unit_user_run.cs
Normal file
69
Service/Application.Domain.Entity/game/user/unit_user_run.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Game")]
|
||||
public class unit_user_run
|
||||
{
|
||||
/// <summary>
|
||||
/// userId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, Length = 50)]
|
||||
public string userId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 区服
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? areaId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 路线
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 255, IsNullable = true)]
|
||||
public string? lineCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// onMap
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 10, IsNullable = true)]
|
||||
public string? onMap { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// toMap
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 10, IsNullable = true)]
|
||||
public string? toMap { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 距离
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? distance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 位置
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? position { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 深度
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? depth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 更新时间
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public long? upTime { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -41,5 +41,11 @@ namespace Application.Domain.Entity
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? weight { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// copper
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? copper { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ public interface IGameMapService
|
||||
#region 城市地图数据
|
||||
|
||||
Task<game_city> GetCityInfo(int cityId);
|
||||
Task<game_city> GetCityInfoByMapId(string mapId);
|
||||
Task<List<game_city>> GetCityData();
|
||||
Task<List<game_city_map>> GetCityMap(int cityId);
|
||||
Task<List<game_city_map>> GetCityShowMap(int cityId);
|
||||
@@ -41,5 +42,15 @@ public interface IGameMapService
|
||||
Task<List<MapLine>> CreateAutoMap(string start, string end);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 航海
|
||||
|
||||
Task<unit_user_run> GetUserRun(string userId);
|
||||
Task<bool> StopUserRun(string userId);
|
||||
Task<bool> SaveUserRunInfo(string userId, int areaId, string onMap, string toMap);
|
||||
|
||||
Task<bool> UpdateUserRunInfo(unit_user_run data);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -17,6 +17,18 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
|
||||
return data;
|
||||
}
|
||||
public async Task<game_city> GetCityInfoByMapId(string mapId)
|
||||
{
|
||||
var data = await GetMapInfo(mapId);
|
||||
if (data != null)
|
||||
{
|
||||
return await GetCityInfo((int)data.cityId);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new game_city();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<game_city>> GetCityData()
|
||||
{
|
||||
@@ -88,6 +100,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<game_city_npc>> GetMapNpc(string mapId)
|
||||
{
|
||||
@@ -566,4 +579,102 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 航海
|
||||
|
||||
public async Task<unit_user_run> GetUserRun(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKey, "UserMapRun");
|
||||
if (await redis.HExistsHashAsync(key, userId))
|
||||
{
|
||||
return await redis.GetHashAsync<unit_user_run>(key, userId);
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_run>();
|
||||
var data = await db.Queryable<unit_user_run>().Where(it => it.userId == userId).SingleAsync();
|
||||
if (data == null)
|
||||
{
|
||||
data = await ResetUserRun(userId,false);
|
||||
}
|
||||
|
||||
await redis.AddHashAsync(key, userId, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
private async Task ClearUserRunCache(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKey, "UserMapRun");
|
||||
await redis.DelHashAsync(key, userId);
|
||||
}
|
||||
|
||||
private async Task<unit_user_run> ResetUserRun(string userId, bool ClearCache = true)
|
||||
{
|
||||
unit_user_run runInfo = new unit_user_run();
|
||||
runInfo.userId = userId;
|
||||
runInfo.areaId = 0;
|
||||
runInfo.lineCode = "";
|
||||
runInfo.onMap = "";
|
||||
runInfo.toMap = "";
|
||||
runInfo.distance = 0;
|
||||
runInfo.position = 0;
|
||||
runInfo.depth = 0;
|
||||
runInfo.status = 0;
|
||||
runInfo.upTime = TimeExtend.GetTimeStampSeconds;
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_run>();
|
||||
bool result = await db.Saveable(runInfo).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
if (ClearCache)
|
||||
{
|
||||
await ClearUserRunCache(userId);
|
||||
}
|
||||
|
||||
return runInfo;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<bool> StopUserRun(string userId)
|
||||
{
|
||||
var data = await ResetUserRun(userId, true);
|
||||
return data == null ? false : true;
|
||||
}
|
||||
|
||||
public async Task<bool> SaveUserRunInfo(string userId, int areaId, string onMap, string toMap)
|
||||
{
|
||||
unit_user_run runInfo = new unit_user_run();
|
||||
runInfo.userId = userId;
|
||||
runInfo.areaId = areaId;
|
||||
runInfo.lineCode = StringAssist.GetSortKey(onMap, toMap);
|
||||
runInfo.onMap = onMap;
|
||||
runInfo.toMap = toMap;
|
||||
int mile = GameTool.ComputeMile(onMap, toMap);
|
||||
runInfo.distance = mile;
|
||||
runInfo.position = 0;
|
||||
runInfo.depth = 0;
|
||||
runInfo.status = 1;
|
||||
runInfo.upTime = TimeExtend.GetTimeStampSeconds;
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_run>();
|
||||
bool result = await db.Saveable(runInfo).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearUserRunCache(userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
public async Task<bool> UpdateUserRunInfo(unit_user_run data)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKey, "UserMapRun");
|
||||
bool result = await redis.AddHashAsync(key, data.userId, data);
|
||||
if (result)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_run>();
|
||||
await db.Updateable(data).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -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