222
This commit is contained in:
@@ -15,4 +15,5 @@ public static class GameConfig
|
||||
public const int GameUserFriendMaxCount = 50;//好友最大上限人数
|
||||
public const int GameAutoBagGoodsId = 10001;//百宝箱物品ID
|
||||
public const int GameAutoDrugGoodsId = 10001;//急救箱物品ID
|
||||
public const int GameToMapNeedCopper = 5;//传送每海里费用
|
||||
}
|
||||
@@ -50,5 +50,6 @@ public static class GameEnum
|
||||
RetBlood,
|
||||
RetMorale,
|
||||
RetVigour,
|
||||
MapTo,
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,8 @@ public interface IGameMapService
|
||||
Task<UserOnMap> GetUserOnMapInfo(string userId);
|
||||
Task SetUserMapDefult(string userId);
|
||||
Task<game_city_map> GetToMapInfo(string userId, string toMap, bool isUpUserMap = true, bool isChangeCity = false);
|
||||
Task<List<unit_user_map>> GetUserCityMapData(string userId);
|
||||
Task<bool> AddUserCityMap(string userId, int cityId);
|
||||
#endregion
|
||||
|
||||
#region 其他相关
|
||||
|
||||
@@ -290,6 +290,42 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<unit_user_map>> GetUserCityMapData(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKey, "UserCityMap");
|
||||
if (await redis.HExistsHashAsync(key, userId))
|
||||
{
|
||||
return await redis.GetHashAsync<List<unit_user_map>>(key, userId);
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_map>();
|
||||
var data = await db.Queryable<unit_user_map>().Where(it => it.userId == userId).ToListAsync();
|
||||
await redis.AddHashAsync(key, userId, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
private async Task ClearUserCityMapCache(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKey, "UserCityMap");
|
||||
await redis.DelHashAsync(key, userId);
|
||||
}
|
||||
|
||||
public async Task<bool> AddUserCityMap(string userId, int cityId)
|
||||
{
|
||||
unit_user_map map = new unit_user_map();
|
||||
map.umId = $"{userId}_{cityId}";
|
||||
map.userId = userId;
|
||||
map.cityId = cityId;
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_map>();
|
||||
bool result = await db.Storageable(map).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearUserCityMapCache(userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 其他相关
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Application.Domain;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameTool
|
||||
{
|
||||
@@ -87,4 +89,39 @@ public class GameTool
|
||||
|
||||
return weight;
|
||||
}
|
||||
#region 距离计算
|
||||
|
||||
/// <summary>
|
||||
/// 计算海里
|
||||
/// </summary>
|
||||
/// <param name="onMap"></param>
|
||||
/// <param name="toMap"></param>
|
||||
/// <returns></returns>
|
||||
public static int ComputeMile(string onMap, string toMap)
|
||||
{
|
||||
string[] _OnMap = onMap.Split('_');
|
||||
int sx = Convert.ToInt32(_OnMap[0]);
|
||||
int sy = Convert.ToInt32(_OnMap[1]);
|
||||
string[] _ToMap = toMap.Split('_');
|
||||
int ex = Convert.ToInt32(_ToMap[0]);
|
||||
int ey = Convert.ToInt32(_ToMap[1]);
|
||||
return GetDistanceByLocation(sx, sy, ex, ey) * 10;
|
||||
}
|
||||
|
||||
private static int GetDistance(PointF start, PointF end)
|
||||
{
|
||||
double value = Math.Sqrt(Math.Abs(start.X - end.X) * Math.Abs(start.X - end.X) + Math.Abs(start.Y - end.Y) * Math.Abs(start.Y - end.Y));
|
||||
|
||||
return Convert.ToInt32(value);
|
||||
}
|
||||
|
||||
private static int GetDistanceByLocation(int onX, int onY, int toX, int toY)
|
||||
{
|
||||
PointF start = new PointF(onX, onY);
|
||||
PointF end = new PointF(toX, toY);
|
||||
return GetDistance(start, end);
|
||||
}
|
||||
|
||||
#endregion 距离计算
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user