12121
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Game")]
|
||||
public class unit_user_skill
|
||||
{
|
||||
/// <summary>
|
||||
/// usId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, Length = 50)]
|
||||
public string usId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// userId
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? userId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// skill
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? skill { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// code
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// name
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// lev
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? lev { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// sign
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? sign { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// remark
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? remark { get; set; }
|
||||
}
|
||||
}
|
||||
11
Service/Application.Domain.Entity/model/MapResModel.cs
Normal file
11
Service/Application.Domain.Entity/model/MapResModel.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Application.Domain.Entity;
|
||||
|
||||
public class MapResModel
|
||||
{
|
||||
public string resId { get; set; }
|
||||
public string resName { get; set; }
|
||||
public int lev { get; set; }
|
||||
public long lockTime { get; set; }
|
||||
public int needVigour { get; set; }
|
||||
public int gather { get; set; }
|
||||
}
|
||||
@@ -18,6 +18,12 @@ namespace Application.Domain.Entity
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? mapId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 等级
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? lev { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源名称
|
||||
/// </summary>
|
||||
@@ -45,8 +51,8 @@ namespace Application.Domain.Entity
|
||||
/// <summary>
|
||||
/// 成功率
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 18, IsNullable = true)]
|
||||
public decimal? okRadio { get; set; }
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? okRadio { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 采集锁定时间
|
||||
@@ -54,4 +60,4 @@ namespace Application.Domain.Entity
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? gatherTime { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Resource")]
|
||||
public class game_skill
|
||||
{
|
||||
/// <summary>
|
||||
/// skill
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public int skill { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// code
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// name
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// lev
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? lev { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// sign
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? sign { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// remark
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? remark { get; set; }
|
||||
}
|
||||
}
|
||||
19
Service/Application.Domain/Enum/SkillEnum.cs
Normal file
19
Service/Application.Domain/Enum/SkillEnum.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public static class SkillEnum
|
||||
{
|
||||
public enum code
|
||||
{
|
||||
GATHER,//采集术
|
||||
FISH,//钓鱼术
|
||||
DIVE,//潜水术
|
||||
NEGOTI,//谈判术
|
||||
FINANC,//理财术
|
||||
ATK,//攻击术
|
||||
DEFENCE,//防御术
|
||||
AGILE,//敏捷术
|
||||
RIDI,//乘骑术
|
||||
WING,//翼形术
|
||||
Collect,//采集术
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,11 @@ public interface IGameMapService
|
||||
|
||||
#region 地图资源
|
||||
|
||||
Task<game_city_map_res> GetMapResInfo(string resId);
|
||||
Task<List<game_city_map_res>> GetMapRes(string mapId);
|
||||
|
||||
Task<List<MapResModel>> GetMapResData(string mapId, int area);
|
||||
Task<long> GetMapResLockTime(string resId, int area);
|
||||
Task SetMapResLockTime(string resId, int area, int lockTime);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public interface IGameSkillService
|
||||
{
|
||||
Task<game_skill> GetGameSkillInfo(int skillId);
|
||||
Task<unit_user_skill> GetUserSkillInfo(string userId, string code);
|
||||
Task<List<AttrItem>> GetUserSkillAttr(string userId);
|
||||
Task<List<unit_user_skill>> GetUserSkill(string userId);
|
||||
Task<bool> UpdateUserSkill(string userId, int skillId);
|
||||
|
||||
}
|
||||
@@ -877,14 +877,15 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
|
||||
public async Task<game_city_map_bus> GetMapBusInfo(int busId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CITY_MAP_BUS","BUS_INFO");
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CITY_MAP_BUS", "BUS_INFO");
|
||||
if (await redis.HExistsHashAsync(key, busId.ToString()))
|
||||
{
|
||||
return await redis.GetHashAsync<game_city_map_bus>(key, busId.ToString());
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_map_bus>();
|
||||
var data = await db.Queryable<game_city_map_bus>().Where(it => it.busId == busId).SingleAsync();
|
||||
await redis.AddHashAsync(key,busId.ToString(), data);
|
||||
var data = await db.Queryable<game_city_map_bus>().Where(it => it.busId == busId).SingleAsync();
|
||||
await redis.AddHashAsync(key, busId.ToString(), data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -924,7 +925,19 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
#endregion
|
||||
|
||||
#region 地图资源
|
||||
public async Task<game_city_map_res> GetMapResInfo(string resId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "MapResInfo");
|
||||
var data = await redis.GetHashAsync<game_city_map_res>(key, resId);
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_map_res>();
|
||||
data = await db.Queryable<game_city_map_res>().Where(it => it.resId == resId).SingleAsync();
|
||||
await redis.AddHashAsync(key, resId, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
public async Task<List<game_city_map_res>> GetMapRes(string mapId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "MapRes");
|
||||
@@ -933,12 +946,56 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_map_res>();
|
||||
data = await db.Queryable<game_city_map_res>().Where(it => it.mapId == mapId).ToListAsync();
|
||||
await redis.AddHashAsync(key, mapId,data);
|
||||
await redis.AddHashAsync(key, mapId, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<List<MapResModel>> GetMapResData(string mapId, int area)
|
||||
{
|
||||
var data = await GetMapRes(mapId);
|
||||
List<MapResModel> result = new List<MapResModel>();
|
||||
foreach (var item in data)
|
||||
{
|
||||
long lockTime = await GetMapResLockTime(item.resId, area);
|
||||
MapResModel temp = new MapResModel()
|
||||
{
|
||||
resId = item.resId,
|
||||
resName = item.resName,
|
||||
lev = (int)item.lev,
|
||||
lockTime = lockTime,
|
||||
needVigour = (int)item.needVigour,
|
||||
gather = (int)item.gatherTime
|
||||
};
|
||||
result.Add(temp);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<long> GetMapResLockTime(string resId, int area)
|
||||
{
|
||||
long result = 0;
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "MapResLockTime");
|
||||
string field = $"{area}_{resId}";
|
||||
if (await redis.HExistsHashAsync(key, field))
|
||||
{
|
||||
long lockTime = await redis.GetHashAsync<long>(key, field);
|
||||
result = lockTime - TimeExtend.GetTimeStampSeconds;
|
||||
result = result <= 0 ? 0 : result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task SetMapResLockTime(string resId, int area, int lockTime)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "MapResLockTime");
|
||||
string field = $"{area}_{resId}";
|
||||
long atTime = TimeExtend.GetTimeStampSeconds + lockTime;
|
||||
await redis.AddHashAsync(key, field, atTime);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameSkillService(ISqlSugarClient DbClient, IRedisCache redis) : IGameSkillService, ITransient
|
||||
{
|
||||
public async Task<game_skill> GetGameSkillInfo(int skillId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "SkillData", "SkillInfo");
|
||||
var data = await redis.GetHashAsync<game_skill>(key, skillId.ToString());
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_skill>();
|
||||
data = await db.Queryable<game_skill>().Where(it => it.skill == skillId).SingleAsync();
|
||||
await redis.AddHashAsync(key, skillId.ToString(), data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private string GetUserSkillKey(string userId, string code)
|
||||
{
|
||||
return $"{userId}_{code}";
|
||||
}
|
||||
|
||||
public async Task<unit_user_skill> GetUserSkillInfo(string userId, string code)
|
||||
{
|
||||
string usId = GetUserSkillKey(userId, code);
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "SkillData", "UserSkill");
|
||||
if (await redis.HExistsHashAsync(key,usId))
|
||||
{
|
||||
return await redis.GetHashAsync<unit_user_skill>(key,usId);
|
||||
}
|
||||
else
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_skill>();
|
||||
var data = await db.Queryable<unit_user_skill>().Where(it => it.usId == usId).SingleAsync();
|
||||
await redis.AddHashAsync(key,usId, data);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<AttrItem>> GetUserSkillAttr(string userId)
|
||||
{
|
||||
List<AttrItem> result = new List<AttrItem>();
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "SkillData", "UserSkillAttr");
|
||||
if (await redis.HExistsHashAsync(key,userId))
|
||||
{
|
||||
result = await redis.GetHashAsync<List<AttrItem>>(key,userId);
|
||||
}
|
||||
else
|
||||
{
|
||||
var data = await GetUserSkill(userId);
|
||||
foreach (var item in data)
|
||||
{
|
||||
if (item.code == nameof(SkillEnum.code.ATK) || item.code ==nameof(SkillEnum.code.DEFENCE) ||
|
||||
item.code == nameof(SkillEnum.code.AGILE))
|
||||
{
|
||||
List<AttrItem> attr = JsonConvert.DeserializeObject<List<AttrItem>>(item.sign);
|
||||
result.AddRange(attr);
|
||||
}
|
||||
}
|
||||
|
||||
await redis.AddHashAsync(key,userId, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<List<unit_user_skill>> GetUserSkill(string userId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_skill>();
|
||||
return await db.Queryable<unit_user_skill>().Where(it => it.userId == userId)
|
||||
.OrderBy(it => it.name, OrderByType.Asc).ToListAsync();
|
||||
}
|
||||
|
||||
private async Task ClearUserSkillInfo(string userId, string code)
|
||||
{
|
||||
string usId = GetUserSkillKey(userId, code);
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "SkillData", "UserSkill");
|
||||
await redis.DelHashAsync(key,usId);
|
||||
key = string.Format(BaseCache.BaseCacheKeys, "SkillData", "UserSkillAttr");
|
||||
await redis.DelHashAsync(key);
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateUserSkill(string userId, int skillId)
|
||||
{
|
||||
bool result = false;
|
||||
var skillInfo = await GetGameSkillInfo(skillId);
|
||||
if (skillInfo != null)
|
||||
{
|
||||
unit_user_skill usInfo = new unit_user_skill();
|
||||
usInfo.usId = GetUserSkillKey(userId, skillInfo.code);
|
||||
usInfo.userId = userId;
|
||||
usInfo.code = skillInfo.code;
|
||||
usInfo.skill = skillInfo.skill;
|
||||
usInfo.name = skillInfo.name;
|
||||
usInfo.lev = skillInfo.lev;
|
||||
usInfo.sign = skillInfo.sign;
|
||||
usInfo.remark = skillInfo.remark;
|
||||
var userSkill = await GetUserSkillInfo(userId, skillInfo.code);
|
||||
if (userSkill == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_skill>();
|
||||
result = await db.Insertable(usInfo).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
else if (userSkill.lev < skillInfo.lev)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_skill>();
|
||||
result = await db.Updateable(usInfo).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
await ClearUserSkillInfo(userId, skillInfo.code);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -18,10 +18,11 @@ public class MapController : ControllerBase
|
||||
private readonly IMessageService _messageService;
|
||||
private readonly IUnitUserWeight _weightService;
|
||||
private readonly IUnitUserAccService _accService;
|
||||
|
||||
private readonly IGameSkillService _skillService;
|
||||
private readonly IGameGoodsService _goodsService;
|
||||
public MapController(IUnitUserService userService, IGameMapService mapService, IGameChatService chatService,
|
||||
IUnitUserAttrService attrService, IMessageService messageService, IUnitUserWeight weightService,
|
||||
IUnitUserAccService accService)
|
||||
IUnitUserAccService accService, IGameSkillService skillService,IGameGoodsService goodsService)
|
||||
{
|
||||
_userService = userService;
|
||||
_mapService = mapService;
|
||||
@@ -30,6 +31,8 @@ public class MapController : ControllerBase
|
||||
_messageService = messageService;
|
||||
_weightService = weightService;
|
||||
_accService = accService;
|
||||
_skillService = skillService;
|
||||
_goodsService = goodsService;
|
||||
}
|
||||
|
||||
#region 地图相关
|
||||
@@ -118,10 +121,10 @@ public class MapController : ControllerBase
|
||||
}
|
||||
|
||||
//地图资源
|
||||
List<game_city_map_res> mapRes = new List<game_city_map_res>();
|
||||
List<MapResModel> mapRes = new List<MapResModel>();
|
||||
if (mapInfo.isRes == 1)
|
||||
{
|
||||
mapRes = await _mapService.GetMapRes(mapInfo.mapId);
|
||||
mapRes = await _mapService.GetMapResData(mapInfo.mapId, area);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -635,4 +638,78 @@ public class MapController : ControllerBase
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 采集相关
|
||||
|
||||
/// <summary>
|
||||
/// 采集接口
|
||||
/// </summary>
|
||||
/// <param name="resId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> CollectMapRes(string resId)
|
||||
{
|
||||
var resInfo = await _mapService.GetMapResInfo(resId);
|
||||
if (resInfo == null)
|
||||
{
|
||||
return PoAction.Message("特产不存在!");
|
||||
}
|
||||
|
||||
var userId = StateHelper.userId;
|
||||
int area = StateHelper.areaId;
|
||||
var onMap = await _mapService.GetUserOnMap(userId);
|
||||
if (onMap.mapId != resInfo.mapId)
|
||||
{
|
||||
return PoAction.Message("特产不存在!");
|
||||
}
|
||||
|
||||
long lockTime = await _mapService.GetMapResLockTime(resId, area);
|
||||
if (lockTime > 0)
|
||||
{
|
||||
return PoAction.Message($"{lockTime}秒后可采集!");
|
||||
}
|
||||
|
||||
var skillInfo = await _skillService.GetUserSkillInfo(userId, nameof(SkillEnum.code.Collect));
|
||||
if (skillInfo == null)
|
||||
{
|
||||
return PoAction.Message("未学习采集术!");
|
||||
}
|
||||
|
||||
if (skillInfo.lev < resInfo.lev)
|
||||
{
|
||||
return PoAction.Message($"需要{resInfo.lev}级采集术才可以采集哦!");
|
||||
}
|
||||
|
||||
var myVigour = await _attrService.GetUserVigourInfo(userId);
|
||||
Console.WriteLine($"{myVigour.vitality }-{resInfo.needVigour}");
|
||||
if (myVigour.vitality < resInfo.needVigour)
|
||||
{
|
||||
return PoAction.Message("活力不足!");
|
||||
}
|
||||
|
||||
if (await _attrService.UpdateUserVigour(userId, 0, (int)resInfo.needVigour))
|
||||
{
|
||||
await _mapService.SetMapResLockTime(resId, area, (int)resInfo.gatherTime);
|
||||
if (RandomAssist.CheakRandom((int)resInfo.okRadio))
|
||||
{
|
||||
//采集成功
|
||||
string[] counts = resInfo.count.Split('-');
|
||||
int onCount =
|
||||
RandomAssist.GetFormatedNumeric(Convert.ToInt32(counts[0]), Convert.ToInt32(counts[1]) + 1);
|
||||
await _goodsService.UpdateUserGoods(userId, 1, (int)resInfo.goodsId, onCount, "采集获得");
|
||||
return PoAction.Ok(resInfo.gatherTime, $"成功采集{resInfo.resName}×{onCount}!");
|
||||
}
|
||||
else
|
||||
{
|
||||
await _mapService.SetMapResLockTime(resId, area, (int)resInfo.gatherTime);
|
||||
return PoAction.Ok(resInfo.gatherTime, "抱歉,采集失败!提升技能会提高成功率哦!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("采集失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -15,10 +15,10 @@ public class UserController : ControllerBase
|
||||
private readonly IUnitUserRelationService _relationService;
|
||||
private readonly IGameGoodsService _goodsService;
|
||||
private readonly IGameChatService _chatService;
|
||||
|
||||
private readonly IGameSkillService _skillService;
|
||||
public UserController(IUnitUserService userService, IUnitUserAttrService attrService,
|
||||
IUnitUserAccService accService, IGameMapService mapService, IUnitUserRelationService relationService,
|
||||
IGameGoodsService goodsService, IGameChatService chatService)
|
||||
IGameGoodsService goodsService, IGameChatService chatService,IGameSkillService skillService)
|
||||
{
|
||||
_userService = userService;
|
||||
_attrService = attrService;
|
||||
@@ -27,6 +27,7 @@ public class UserController : ControllerBase
|
||||
_relationService = relationService;
|
||||
_goodsService = goodsService;
|
||||
_chatService = chatService;
|
||||
_skillService = skillService;
|
||||
}
|
||||
|
||||
|
||||
@@ -280,4 +281,16 @@ public class UserController : ControllerBase
|
||||
return PoAction.Message("操作失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户技能
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction>GetUserSkill()
|
||||
{
|
||||
var userId = StateHelper.userId;
|
||||
var data = await _skillService.GetUserSkill(userId);
|
||||
return PoAction.Ok(data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user