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

@@ -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;