This commit is contained in:
Putoo
2026-06-01 18:49:17 +08:00
parent 8a5b6d31ca
commit eb81a1c381
50 changed files with 1367 additions and 59 deletions

View File

@@ -41,5 +41,10 @@ namespace Application.Domain.Entity
/// </summary>
[SugarColumn(IsNullable = true)]
public int? giveRole { get; set; }
/// <summary>
/// 消息权限0封禁 1正常
/// </summary>
[SugarColumn(IsNullable = true)]
public int? msgRole { get; set; }
}
}

View File

@@ -0,0 +1,33 @@
namespace Application.Domain.Entity;
public class EquSuitAttr
{
private System.String _NeedType;
/// <summary>
///
/// </summary>
public System.String NeedType
{ get { return this._NeedType; } set { this._NeedType = value; } }
public String[] _NeedData;
public System.String[] NeedData
{ get { return this._NeedData; } set { this._NeedData = value; } }
private System.Int32 _Type;
/// <summary>
/// 0特殊属性 1隐藏属性
/// </summary>
public System.Int32 Type
{ get { return this._Type; } set { this._Type = value; } }
private List<AttrItem> _AttrItem;
/// <summary>
///
/// </summary>
public List<AttrItem> AttrItem
{ get { return this._AttrItem; } set { this._AttrItem = value; } }
}

View File

@@ -0,0 +1,20 @@
namespace Application.Domain.Entity;
public class EquSuitList
{
private System.Int32 _equId;
/// <summary>
/// 装备表Id--goods表
/// </summary>
public System.Int32 equId
{ get { return this._equId; } set { this._equId = value; } }
private System.String _equName;
/// <summary>
///
/// </summary>
public System.String equName
{ get { return this._equName; } set { this._equName = value; } }
}

View File

@@ -2,6 +2,7 @@
public class NpcBus
{
public string code { get; set; }
public string name { get; set; }
public string url { get; set; }
}

View File

@@ -14,14 +14,14 @@
public string remark { get; set; }
public string TmImg { get; set; }
public int lev { get; set; }//等级
public decimal minAtk { get; set; }//最小攻击
public decimal maxAtk { get; set; }//最大攻击
public decimal defense { get; set; }//防御
public decimal agility { get; set; }//敏捷
public decimal blood { get; set; }//血量
public decimal upBlood { get; set; }//最大血量
public decimal morale { get; set; }//士气
public decimal upMorale { get; set; }//最大士气
public int minAtk { get; set; }//最小攻击
public int maxAtk { get; set; }//最大攻击
public int defense { get; set; }//防御
public int agility { get; set; }//敏捷
public int blood { get; set; }//血量
public int upBlood { get; set; }//最大血量
public int morale { get; set; }//士气
public int upMorale { get; set; }//最大士气
public decimal score { get; set; }//评分
public decimal InBlood { get; set; }//吸血
public decimal Crit { get; set; }//暴击

View File

@@ -0,0 +1,45 @@
using SqlSugar;
using System;
namespace Application.Domain.Entity
{
[Tenant("Kg.SeaTime.Resource")]
public class game_equ_suit
{
/// <summary>
/// 套装编码
/// </summary>
[SugarColumn(IsPrimaryKey = true, Length = 50)]
public string suitCode { get; set; }
/// <summary>
/// 套装名称
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? suitName { get; set; }
/// <summary>
/// 套装介绍
/// </summary>
[SugarColumn(Length = 500, IsNullable = true)]
public string? sign { get; set; }
/// <summary>
/// 属性
/// </summary>
[SugarColumn(IsNullable = true,IsJson = true)]
public List<EquSuitAttr>? attr { get; set; }
/// <summary>
/// 套装组成装备
/// </summary>
[SugarColumn(IsNullable = true,IsJson = true)]
public List<EquSuitList> onEqu { get; set; }
/// <summary>
/// 套装特权
/// </summary>
[SugarColumn(IsNullable = true)]
public string? role { get; set; }
}
}

View File

@@ -44,4 +44,11 @@ public static class GameEnum
,
}
public enum NpcBusCode
{
RetBlood,
RetMorale,
RetVigour,
}
}

View File

@@ -14,5 +14,6 @@ public static class UserEnum
AutoBag,
AutoDrug,
GiveRole,
MsgRole,
}
}

View File

@@ -5,7 +5,7 @@ public interface IGameEquService
#region
Task<game_equ> GetEquInfo(int equId);
Task<game_equ_suit> GetEuqSuitInfo(string suitCode);
#endregion
#region
@@ -29,4 +29,10 @@ public interface IGameEquService
#endregion
#region
Task<int> GetUserEquWeightSum(string userId);
#endregion
}

View File

@@ -20,5 +20,12 @@ public interface IGameGoodsService
Task<bool> UpdateUserGoods(string userId, int op, int goodsId, int count, string remark = "");
#endregion
#region
Task<int> GetUserGoodWeightSum(string userId, int type);
#endregion
}

View File

@@ -27,13 +27,14 @@ public interface IUnitUserAttrService
Task<unit_user_morale> GetUserMorale(string userId);
Task<bool> UpdateUserMorale(string userId, int op, int count);
Task<bool> CheackRecoverMorale(string userId);
Task LockRecoverMorale(string userId);
#endregion
#region
Task<unit_user_vigour> GetUserVigourInfo(string userId);
Task<bool> UpdateUserVigour(string userId, int op, decimal count, string UpTime = "");
Task<bool> UpdateUserVigour(string userId, int op, long count, string UpTime = "");
Task<bool> UpdateUserUpVigour(string userId, decimal count);
#endregion

View File

@@ -3,10 +3,14 @@
public interface IUnitUserWeight
{
Task<unit_user_weight> GetUserWeightInfo(string userId);
Task<bool> UpdateUserWeight(unit_user_weight data);
Task<bool> UpdateUserWeight(string userId, int op, int weight);
Task<bool> UpdateUserMaxWeight(string userId, int op, int weight);
Task<bool> AddUserWeightLog(string userId, int goodsId, string goodsName, int weight, int count);
Task<bool> CheakUserWeight(string userId, int useWeight);
Task<bool> UpdateUserMaxWeight(string userId, int op, int weight, int count = 1, int goodsId = 0,
string goodsName = "");
Task<List<unit_user_weight_log>> GetUserWeightLog(string userId);
Task<bool> CheckUserWeight(string userId, int useWeight);
#region

View File

@@ -17,6 +17,18 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
return data;
}
public async Task<game_equ_suit> GetEuqSuitInfo(string suitCode)
{
string key = string.Format(BaseCache.BaseCacheKeys, "EquData", "SuitInfo");
var data = await redis.GetHashAsync<game_equ_suit>(key, suitCode);
if (data == null)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<game_equ_suit>();
data = await db.Queryable<game_equ_suit>().Where(it => it.suitCode == suitCode).SingleAsync();
await redis.AddHashAsync(key, suitCode, data);
}
return data;
}
#endregion
@@ -292,5 +304,16 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
await db.Insertable(logs).SplitTable().ExecuteCommandAsync();
}
#endregion
#region
public async Task<int> GetUserEquWeightSum(string userId)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
var data = await db.Queryable<unit_user_equ>().Where(it => it.userId == userId).ToListAsync();
return data.Sum(it => (int)it.weight);
}
#endregion
}

View File

@@ -55,7 +55,8 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
return info == null ? 0 : (int)info.count;
}
public async Task<List<unit_user_goods>> GetUserGoodsData(string userId, List<string> code, List<string> noCode, string search, int page,
public async Task<List<unit_user_goods>> GetUserGoodsData(string userId, List<string> code, List<string> noCode,
string search, int page,
int limit, RefAsync<int> total)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_goods>();
@@ -125,13 +126,13 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
if (weightCount > 0)
{
var weightService = App.GetService<IUnitUserWeight>();
if (UserGoods.code == nameof(GoodsEnum.Code.Cargo))//跑商物品处理
if (UserGoods.code == nameof(GoodsEnum.Code.Cargo)) //跑商物品处理
{
await weightService.UpdateUserShipOnWeight(userId, op, weightCount);
}
else
{
await weightService.UpdateUserWeight(userId, op, weightCount);
await weightService.UpdateUserWeight(userId, op, weightCount);
}
}
@@ -164,5 +165,16 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
return $"{userId}_{goodsId}";
}
public async Task<int> GetUserGoodWeightSum(string userId, int type)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_goods>();
string code = nameof(GoodsEnum.Code.Cargo);
var data = await db.Queryable<unit_user_goods>().Where(it => it.userId == userId)
.WhereIF(type == 0, it => it.code != code)
.WhereIF(type == 1, it => it.code == code)
.ToListAsync();
return data.Sum(it => (int)it.count * (int)it.weight);
}
#endregion
}

View File

@@ -18,14 +18,16 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
result.code = nameof(UserEnum.AttrCode.Person);
var unitAttr = await GetUserAttr(userId);
result.lev = (int)unitAttr.lev;
result.minAtk = (decimal)unitAttr.minAtk;
result.maxAtk = (decimal)unitAttr.maxAtk;
result.defense = (decimal)unitAttr.defense;
result.agility = (decimal)unitAttr.agility;
result.upBlood = (decimal)unitAttr.upBlood;
result.upMorale = (decimal)unitAttr.upMorale;
result.blood = 1;
result.morale = 1;
result.minAtk = (int)unitAttr.minAtk;
result.maxAtk = (int)unitAttr.maxAtk;
result.defense = (int)unitAttr.defense;
result.agility = (int)unitAttr.agility;
result.upBlood = (int)unitAttr.upBlood;
result.upMorale = (int)unitAttr.upMorale;
var bloodInfo = await GetUserBlood(userId);
result.blood = (int)bloodInfo.blood;
var moraleInfo = await GetUserMorale(userId);
result.morale = (int)moraleInfo.morale;
return result;
}
@@ -172,6 +174,7 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
.ExecuteCommandAsync() > 0;
int upVigour = GameConfig.GameBaseVigour + (OnLev * 10);
await UpdateUserUpVigour(userId, upVigour);
IsUpUserAttr = result;
}
}
@@ -199,7 +202,7 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
{
//增加负重
var wightService = App.GetService<IUnitUserWeight>();
await wightService.UpdateUserMaxWeight(userId, 1, GameConfig.UpLevAddWeight);
await wightService.UpdateUserMaxWeight(userId, 1, GameConfig.UpLevAddWeight, 1, 0, "升级增加负重");
await ClearUserAttrCache(userId);
}
@@ -252,6 +255,17 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
return result;
}
public async Task<bool> CheackRecoverMorale(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "Recover:Morale", userId);
return await redis.ExistsAsync(key);
}
public async Task LockRecoverMorale(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "Recover:Morale", userId);
await redis.SetAsync(key, DateTime.Now,TimeAssist.GetDateTimeYMD(1));
}
#endregion
#region
@@ -279,7 +293,7 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
await redis.DelHashAsync(key, userId);
}
public async Task<bool> UpdateUserVigour(string userId, int op, decimal count, string UpTime = "")
public async Task<bool> UpdateUserVigour(string userId, int op, long count, string UpTime = "")
{
bool result = false;
try

View File

@@ -207,6 +207,7 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni
config.autoBag = -1;
config.autoDrug = -1;
config.giveRole = 0;
config.msgRole = 1;
db.Insertable(config).AddQueue();
//注册个人血量
@@ -231,14 +232,14 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni
unit_user_weight weight = new unit_user_weight();
weight.userId = userId;
weight.onWeight = 0;
weight.maxWeight = 100;
weight.maxWeight = 0;
db.Insertable(weight).AddQueue();
//注册活力
unit_user_vigour vitality = new unit_user_vigour();
vitality.userId = userId;
vitality.vitality = GameConfig.GameBaseVigour;
vitality.upVitality = GameConfig.GameBaseVigour;
vitality.upTime = TimeAssist.GetDateTimeYMDString(0);
vitality.upTime = TimeAssist.GetDateTimeYMDString(-1);
db.Insertable(vitality).AddQueue();
//注册在线
@@ -252,6 +253,13 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni
await db.SaveQueuesAsync(false);
}
if (result)//注册各项后处理
{
//赠送初始负重
var weightService = App.GetService<IUnitUserWeight>();
await weightService.UpdateUserMaxWeight(userId, 1, 100, 1, 0, "初始负重");
}
return result;
}
@@ -337,6 +345,9 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni
case "AutoDrug":
result = (int)config.autoDrug;
break;
case "MsgRole":
result = (int)config.msgRole;
break;
}
return result;
@@ -357,6 +368,7 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni
.SetColumnsIF(code == "AutoBag", it => it.autoBag == state)
.SetColumnsIF(code == "AutoDrug", it => it.autoDrug == state)
.SetColumnsIF(code == "GiveRole", it => it.giveRole == state)
.SetColumnsIF(code == "MsgRole", it => it.msgRole == state)
.Where(it => it.userId == userId).ExecuteCommandAsync() > 0;
if (result)
{

View File

@@ -30,6 +30,18 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
await redis.DelHashAsync(key, userId);
}
public async Task<bool> UpdateUserWeight(unit_user_weight data)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_weight>();
bool result = await db.Updateable(data).ExecuteCommandAsync() > 0;
if (result)
{
await ClearUserWeightInfo(data.userId);
}
return result;
}
public async Task<bool> UpdateUserWeight(string userId, int op, int weight)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_weight>();
@@ -46,22 +58,33 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
return result;
}
public async Task<bool> UpdateUserMaxWeight(string userId, int op, int weight)
public async Task<bool> UpdateUserMaxWeight(string userId, int op, int weight, int count = 1, int goodsId = 0,
string goodsName = "")
{
int sumWeight = weight * count;
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_weight>();
bool result = await db.Updateable<unit_user_weight>()
.SetColumnsIF(op == 0, it => it.maxWeight == it.maxWeight - weight)
.SetColumnsIF(op == 1, it => it.maxWeight == it.maxWeight + weight)
.SetColumnsIF(op == 0, it => it.maxWeight == it.maxWeight - sumWeight)
.SetColumnsIF(op == 1, it => it.maxWeight == it.maxWeight + sumWeight)
.Where(it => it.userId == userId).ExecuteCommandAsync() > 0;
if (result)
{
if (op == 1)
{
await AddUserWeightLog(userId, goodsId, goodsName, weight, count);
}
else
{
await AddUserWeightLog(userId, goodsId, goodsName, (0 - weight), count);
}
await ClearUserWeightInfo(userId);
}
return result;
}
public async Task<bool> AddUserWeightLog(string userId, int goodsId, string goodsName, int weight, int count)
private async Task<bool> AddUserWeightLog(string userId, int goodsId, string goodsName, int weight, int count)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_weight_log>();
unit_user_weight_log log = new unit_user_weight_log();
@@ -76,7 +99,14 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
return await db.Insertable(log).ExecuteCommandAsync() > 0;
}
public async Task<bool> CheakUserWeight(string userId, int useWeight)
public async Task<List<unit_user_weight_log>> GetUserWeightLog(string userId)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_weight_log>();
return await db.Queryable<unit_user_weight_log>().Where(it => it.userId == userId)
.ToListAsync();
}
public async Task<bool> CheckUserWeight(string userId, int useWeight)
{
bool result = false;
var weightInfo = await GetUserWeightInfo(userId);
@@ -103,11 +133,13 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
return data;
}
public async Task<int> GetUserShipMaxWeight(string userId)
{
var data = await GetUserShip(userId);
return data.Sum(it => (int)it.weight);
}
private async Task ClearUserShipData(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "WeightData", "Ship");
@@ -142,7 +174,7 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
return result;
}
public async Task<bool> DeleteUserShip(string usId,string userId)
public async Task<bool> DeleteUserShip(string usId, string userId)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_ship>();
bool result = await db.Deleteable<unit_user_ship>().Where(it => it.usId == usId).ExecuteCommandAsync() > 0;
@@ -154,7 +186,7 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
return result;
}
public async Task<bool> AddUserShip(string userId,string name,int goodsId,int speed,int weight)
public async Task<bool> AddUserShip(string userId, string name, int goodsId, int speed, int weight)
{
unit_user_ship ship = new unit_user_ship();
ship.usId = StringAssist.NewGuid;

View File

@@ -214,4 +214,72 @@ public class ChatController : ControllerBase
return PoAction.Message("操作失败,请稍后尝试!");
}
}
/// <summary>
/// 封禁ID
/// </summary>
/// <param name="chatId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> BlackUser(string chatId)
{
var chatInfo = await _chatService.GetChatInfo(chatId);
if (chatInfo == null)
{
return PoAction.Message("发言不存在!");
}
if (chatInfo.state != 1)
{
return PoAction.Message("发言不存在!");
}
if (chatInfo.areaId != StateHelper.areaId)
{
return PoAction.Message("发言不存在!");
}
if (chatInfo.userId == StateHelper.userId)
{
return PoAction.Message("不能封禁自己!");
}
bool IsOp = false;
string userId = StateHelper.userId;
int chatRole = await _userService.GetUserConfigInfo(userId, nameof(UserEnum.ConfigCode.ChatRole));
if ((chatInfo.code == nameof(GameChatEnum.Code.Public) || chatInfo.code == nameof(GameChatEnum.Code.Region)) &&
chatRole > 0)
{
IsOp = true;
}
else if (chatRole > 1 && chatInfo.code == nameof(GameChatEnum.Code.Dress))
{
IsOp = true;
}
if (IsOp == false)
{
return PoAction.Message("无权限!");
}
var otConfig = await _userService.GetUserConfigInfo(chatInfo.userId);
if (otConfig.chatRole < 0)
{
return PoAction.Message("Ta已被禁言,无需封禁!");
}
if (otConfig.chatRole != 0)
{
return PoAction.Message("您无权封禁!");
}
if (await _userService.UpdateUserConfigInfo(chatInfo.userId, nameof(UserEnum.ConfigCode.ChatRole), -1))
{
return PoAction.Ok(true);
}
else
{
return PoAction.Message("操作失败,请稍后尝试!");
}
}
}

View File

@@ -110,7 +110,7 @@ public class StoreController : ControllerBase
//此处需要计算负重
var needWeight = await GameTool.GetPropWeight(storeInfo.type, storeInfo.parameter);
needWeight = needWeight * parms.count;
if (await _weightService.CheakUserWeight(userId, needWeight) == false)
if (await _weightService.CheckUserWeight(userId, needWeight) == false)
{
return PoAction.Message("负重不足!");
}

View File

@@ -0,0 +1,71 @@
using Microsoft.AspNetCore.Mvc;
namespace Application.Web.Controllers.Pub;
/// <summary>
/// 装备接口
/// </summary>
[Route("[controller]/[action]")]
[ApiController]
[Authorize]
public class EquController : ControllerBase
{
private readonly IGameEquService _equService;
public EquController(IGameEquService equService)
{
_equService = equService;
}
/// <summary>
/// 获取装备信息
/// </summary>
/// <param name="equId"></param>
/// <param name="ueId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetEquInfo(int? equId, string? ueId)
{
game_equ equInfo = new game_equ();
game_equ_suit suit = new game_equ_suit();
unit_user_equ ueInfo = new unit_user_equ();
UserModel user = new UserModel();
if (equId != 0)
{
equInfo = await _equService.GetEquInfo((int)equId);
if (equInfo == null)
{
return PoAction.Message("装备不存在!");
}
if (equInfo.suitCode != "0" && !string.IsNullOrEmpty(equInfo.suitCode))
{
suit = await _equService.GetEuqSuitInfo(equInfo.suitCode);
}
}
else
{
ueInfo = await _equService.GetUserEquInfo(ueId);
if (ueInfo == null)
{
return PoAction.Message("装备不存在!");
}
equInfo = await _equService.GetEquInfo((int)ueInfo.equId);
if (equInfo == null)
{
return PoAction.Message("装备不存在!");
}
if (equInfo.suitCode != "0" && !string.IsNullOrEmpty(equInfo.suitCode))
{
suit = await _equService.GetEuqSuitInfo(equInfo.suitCode);
}
user = await UserModelTool.GetUserView(ueInfo.owerId);
}
return PoAction.Ok(new { equ = equInfo, suit, equData = ueInfo,user });
}
}

View File

@@ -0,0 +1,39 @@
using Microsoft.AspNetCore.Mvc;
namespace Application.Web.Controllers.Pub;
/// <summary>
/// 物品接口
/// </summary>
[Route("[controller]/[action]")]
[ApiController]
[Authorize]
public class GoodsController : ControllerBase
{
private readonly IGameGoodsService _goodsService;
public GoodsController(IGameGoodsService goodsService)
{
_goodsService = goodsService;
}
/// <summary>
/// 获取物品信息
/// </summary>
/// <param name="goodsId">物品ID</param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetGoodsInfo(int goodsId)
{
var goodsInfo = await _goodsService.GetGoodsInfo(goodsId);
if (goodsInfo == null)
{
return PoAction.Message("物品不存在!");
}
string userId = StateHelper.userId;
int count = await _goodsService.GetUserGoodsCount(userId, goodsId);
return PoAction.Ok(new { goods = goodsInfo, count });
}
}

View File

@@ -115,6 +115,12 @@ public class MessageController : ControllerBase
string userId = StateHelper.userId;
int areaId = StateHelper.areaId;
var msgRole = await _userService.GetUserConfigInfo(userId, nameof(UserEnum.ConfigCode.MsgRole));
if (msgRole != 1)
{
return PoAction.Message("消息权限已被封禁!");
}
var toUser = await _userService.GetUserInfoByUserNo(parms.no.ToString());
if (toUser == null)
{

View File

@@ -0,0 +1,203 @@
using Microsoft.AspNetCore.Mvc;
namespace Application.Web.Controllers.Pub;
/// <summary>
/// 恢复接口
/// </summary>
[Route("[controller]/[action]")]
[ApiController]
[Authorize]
public class RecoverController : ControllerBase
{
private readonly IUnitUserAttrService _attrService;
private readonly IGameMapService _mapService;
public RecoverController(IUnitUserAttrService attrService, IGameMapService mapService)
{
_attrService = attrService;
_mapService = mapService;
}
/// <summary>
/// 恢复体力
/// </summary>
/// <param name="npcId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> RecoverBlood(int npcId)
{
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.RetBlood)))
{
return PoAction.Message("业务不可用!");
}
var onMap = await _mapService.GetUserOnMapId(userId);
if (npcInfo.mapId != onMap)
{
return PoAction.Message("Npc不存在!");
}
#endregion
var userAttr = await _attrService.GetUserAttrModel(userId);
if (userAttr.blood >= userAttr.upBlood)
{
return PoAction.Message("体力满满,无需恢复!");
}
bool result = await _attrService.UpdateUserBlood(userId, 2, userAttr.upBlood, true);
if (result)
{
return PoAction.Ok(true);
}
else
{
return PoAction.Message("恢复失败,请稍后尝试!");
}
}
/// <summary>
/// 恢复士气
/// </summary>
/// <param name="npcId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> RecoverMorale(int npcId)
{
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.RetMorale)))
{
return PoAction.Message("业务不可用!");
}
var onMap = await _mapService.GetUserOnMapId(userId);
if (npcInfo.mapId != onMap)
{
return PoAction.Message("Npc不存在!");
}
#endregion
if (await _attrService.CheackRecoverMorale(userId))
{
return PoAction.Message("今天已恢复过士气啦!");
}
var userAttr = await _attrService.GetUserAttrModel(userId);
if (userAttr.morale >= userAttr.upMorale)
{
return PoAction.Message("士气满满,无需恢复!");
}
bool result = await _attrService.UpdateUserMorale(userId, 2, userAttr.upMorale);
if (result)
{
await _attrService.LockRecoverMorale(userId);
return PoAction.Ok(true);
}
else
{
return PoAction.Message("恢复失败,请稍后尝试!");
}
}
/// <summary>
/// 获取个人活力
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetUserVigour()
{
string userId = StateHelper.userId;
var data = await _attrService.GetUserVigourInfo(userId);
return PoAction.Ok(data);
}
/// <summary>
/// 恢复活力
/// </summary>
/// <param name="npcId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> RecoverVigour(int npcId)
{
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.RetVigour)))
{
return PoAction.Message("业务不可用!");
}
var onMap = await _mapService.GetUserOnMapId(userId);
if (npcInfo.mapId != onMap)
{
return PoAction.Message("Npc不存在!");
}
#endregion
var data = await _attrService.GetUserVigourInfo(userId);
string time = TimeAssist.GetDateTimeYMDString(0);
if (data.upTime == time)
{
return PoAction.Message("今天已恢复过活力啦!");
}
if (data.vitality >= data.upVitality)
{
return PoAction.Message("活力满满,无需恢复!");
}
bool result = await _attrService.UpdateUserVigour(userId, 2, (long)data.upVitality,time);
if (result)
{
return PoAction.Ok(true);
}
else
{
return PoAction.Message("恢复失败,请稍后尝试!");
}
}
}

View File

@@ -13,11 +13,15 @@ public class SettingController : ControllerBase
{
private readonly IUnitUserService _userService;
private readonly IGameGoodsService _goodsService;
private readonly IGameEquService _equService;
private readonly IUnitUserWeight _weightService;
public SettingController(IUnitUserService userService,IGameGoodsService goodsService)
public SettingController(IUnitUserService userService,IGameGoodsService goodsService,IGameEquService equService,IUnitUserWeight weightService)
{
_userService = userService;
_goodsService = goodsService;
_equService = equService;
_weightService = weightService;
}
/// <summary>
@@ -190,4 +194,45 @@ public class SettingController : ControllerBase
return PoAction.Message("暂无法设置!");
}
}
/// <summary>
/// 刷新/重置设置
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> RefreshSetting(int type)
{
string userId = StateHelper.userId;
if (type == 0)//刷新负重
{
var equWeight = await _equService.GetUserEquWeightSum(userId);
var goodsWeight = await _goodsService.GetUserGoodWeightSum(userId,0);
int onWeight = equWeight + goodsWeight;//当前总占用负重
var weightLog = await _weightService.GetUserWeightLog(userId);
int maxWeight = weightLog.Sum(it => (int)it.sum);
var weightInfo = await _weightService.GetUserWeightInfo(userId);
weightInfo.onWeight = onWeight;
weightInfo.maxWeight = maxWeight;
var shipWeight = await _goodsService.GetUserGoodWeightSum(userId,1);
weightInfo.shipOnWeight = shipWeight;
if (await _weightService.UpdateUserWeight(weightInfo))
{
return PoAction.Ok(true,"负重数据已刷新成功!");
}
else
{
return PoAction.Message("负重刷新失败,请稍后尝试!");
}
}
else if (type == 1)//刷新图标
{
return PoAction.Ok(true, "图标刷新成功!");
}
else
{
return PoAction.Message("无效的操作!");
}
}
}

View File

@@ -84,6 +84,40 @@ public class UserController : ControllerBase
var model = await UserModelTool.GetUserView(userId);
return PoAction.Ok(model);
}
/// <summary>
/// 获取基础属性信息
/// </summary>
/// <param name="no"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetUserBaseAttrInfo(string? no)
{
string userId = StateHelper.userId;
if (!string.IsNullOrEmpty(no))
{
var userInfo = await _userService.GetUserInfoByUserNo(no); //基础资料
if (userInfo == null)
{
return PoAction.Message("玩家不存在!", 102);
}
if (userInfo.userId == userId)
{
return PoAction.Message("用户本身!", 101);
}
if (userInfo.areaId != StateHelper.areaId)
{
return PoAction.Message("玩家不存在!", 102);
}
userId = userInfo.userId;
}
var model = await _attrService.GetUserAttrModel(userId);
return PoAction.Ok(model);
}
/// <summary>
/// 获取用户资料