1212
This commit is contained in:
@@ -6,4 +6,5 @@ public interface IExchangeService
|
||||
Task<game_exchange> GetExchangeInfo(int exId);
|
||||
Task<int> GetExchangeCount(string userId, int exId);
|
||||
Task<bool> AddUserExchangeLog(string userId, int exId, int count, long endTime);
|
||||
Task HandleExchangeLogData();
|
||||
}
|
||||
@@ -9,4 +9,5 @@ public interface IOnHookService
|
||||
|
||||
Task<bool> StopOnHook(string userId);
|
||||
Task HandleHook();
|
||||
Task HandleOnHookGoods(OnHookAwardModel data);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public interface IRankService
|
||||
{
|
||||
Task<string> GetRankUpdateTime();
|
||||
Task<List<GameRankModel>> GetGameRank(int type, int area, int page, int limit, RefAsync<int> total);
|
||||
Task<List<GameRankModel>> GetGameCopperRank(int area, int page, int limit, RefAsync<int> total);
|
||||
Task<List<GameRankModel>> GetGameTeachAndRenownRank(int type, int area, int page, int limit, RefAsync<int> total);
|
||||
Task HandleRank();
|
||||
}
|
||||
@@ -14,6 +14,7 @@ public interface IGameEquService
|
||||
Task<List<unit_user_equ>> GetUserEquData(string userId, int type, string equName, int PageIndex, int PageSize,
|
||||
RefAsync<int> Total, bool isRemOn = false, bool isRemLock = false);
|
||||
|
||||
Task<List<unit_user_equ>> GetUserEquData(string userId, string query);
|
||||
Task<List<unit_user_equ>> GetUserEquData(string userId, int equId);
|
||||
Task<List<unit_user_equ>> GetUserEquData(string userId, string code, List<string> noUeId);
|
||||
Task<unit_user_equ> GetUserEquInfo(string ueId);
|
||||
@@ -62,6 +63,13 @@ public interface IGameEquService
|
||||
|
||||
Task<int> GetUserEquWeightSum(string userId);
|
||||
Task<game_equ_make> GetMakeEquByGoodsId(int goodsId);
|
||||
Task RemoveUserOnEqu(string userId, string type, int count);
|
||||
#endregion
|
||||
|
||||
#region 耐久
|
||||
|
||||
Task UpdateUserOnEquDurability(string userId);
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -16,7 +16,7 @@ public interface IGameFightService
|
||||
string userId, long exp = 0, long copper = 0, long petExp = 0, string award = "", string pars = "");
|
||||
|
||||
Task<bool> SetFightWin(game_fight_data fightData, string winUser,bool setDefMap=true);
|
||||
|
||||
Task HandleFightData();
|
||||
|
||||
#endregion
|
||||
#region 战斗相关
|
||||
@@ -28,7 +28,7 @@ public interface IGameFightService
|
||||
Task<game_map_goods> GetFightGoodsInfo(string mapId, string mgId);
|
||||
Task RemoveFightGoods(string mapId, string mgId);
|
||||
Task AutoUseDrug(UserAttrModel user, game_fight_data fight);
|
||||
Task HandelFightEnd(string userId, List<dynamic> data);
|
||||
Task HandelFightEnd(string userId, List<FightRemoveData> data);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -20,6 +20,7 @@ public interface IGameMapService
|
||||
Task<string> GetUserOnMapId(string userId);
|
||||
Task<game_city_map> GetUserOnToMapInfo(string userId);
|
||||
Task<unit_user_online> GetUserOnMap(string userId);
|
||||
Task UpdateUserOnMap(string userId);
|
||||
Task UpdateUserOnMap(string userId, string ip, string mapId);
|
||||
Task<bool> UpdateUserOnMap(unit_user_online data, string mapId);
|
||||
Task<UserOnMap> GetUserOnMapInfo(string userId);
|
||||
|
||||
@@ -14,8 +14,11 @@ public interface IGameMonsterService
|
||||
int count = 1, int time = 0, string par = "");
|
||||
|
||||
Task<unit_user_monster> GetCreateMonsterInfo(string umId);
|
||||
Task<bool> RemoveCreateMonster(string umId);
|
||||
Task<bool> RemoveCreateMonster(unit_user_monster data);
|
||||
Task HandleCreateMonster();
|
||||
Task<List<MapMonsterModel>> GetMapMonster(string userId, string mapId, string teamId);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 怪物模型
|
||||
|
||||
@@ -16,6 +16,8 @@ public interface IUnitUserAccService
|
||||
|
||||
Task<unit_user_copper> GetUserCopperInfo(string userId);
|
||||
Task<bool> UpdateUserCopper(string userId, int type, long count, string remark = "");
|
||||
Task<unit_user_data> GetUserDataInfo(string userId);
|
||||
Task<bool> UpdateUserData(string userId, int type, string accType, long count, string remark = "");
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public interface IUnitUserAttrService
|
||||
#region 在线时间
|
||||
|
||||
Task<bool> UpdateOnLineTime(string userId, string code, int time);
|
||||
|
||||
Task HandleOnLineTimeData();
|
||||
#endregion
|
||||
|
||||
#region 药品栏
|
||||
|
||||
@@ -17,14 +17,12 @@ public class ExchangeService(ISqlSugarClient DbClient, IRedisCache redis) : IExc
|
||||
|
||||
public async Task<int> GetExchangeCount(string userId, int exId)
|
||||
{
|
||||
int result = 0;
|
||||
string key = $"{userId}_{exId}";
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_exchange_log>();
|
||||
return await db.Queryable<game_exchange_log>().Where(it => it.userId == userId && it.exId == exId)
|
||||
.SumAsync(it => (int)it.count);
|
||||
}
|
||||
|
||||
public async Task<bool> AddUserExchangeLog(string userId, int exId, int count,long endTime)
|
||||
public async Task<bool> AddUserExchangeLog(string userId, int exId, int count, long endTime)
|
||||
{
|
||||
game_exchange_log log = new game_exchange_log();
|
||||
log.ueId = StringAssist.NewGuid;
|
||||
@@ -38,4 +36,11 @@ public class ExchangeService(ISqlSugarClient DbClient, IRedisCache redis) : IExc
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task HandleExchangeLogData()
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_exchange_log>();
|
||||
await db.Deleteable<game_exchange_log>().Where(it => it.endTime <= TimeExtend.GetTimeStampSeconds)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameAutoJobService(ISqlSugarClient DbClient, IRedisCache redis,ITimerJobManager jobManager) : IGameAutoJobService, ITransient
|
||||
public class GameAutoJobService(ISqlSugarClient DbClient, IRedisCache redis, ITimerJobManager jobManager)
|
||||
: IGameAutoJobService, ITransient
|
||||
{
|
||||
public async Task<List<game_job>> GetJobData()
|
||||
{
|
||||
@@ -12,11 +13,12 @@ public class GameAutoJobService(ISqlSugarClient DbClient, IRedisCache redis,ITim
|
||||
|
||||
public async Task<game_job> GetJobInfo(string jobId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKey,"JobData");
|
||||
string key = string.Format(BaseCache.BaseCacheKey, "JobData");
|
||||
if (await redis.HExistsHashAsync(key, jobId))
|
||||
{
|
||||
return await redis.GetHashAsync<game_job>(key, jobId);
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_job>();
|
||||
var data = await db.Queryable<game_job>().Where(it => it.jobId == jobId).SingleAsync();
|
||||
await redis.AddHashAsync(key, jobId, data);
|
||||
@@ -53,12 +55,41 @@ public class GameAutoJobService(ISqlSugarClient DbClient, IRedisCache redis,ITim
|
||||
|
||||
public async Task HandleJob(game_job data)
|
||||
{
|
||||
if (data.code == nameof(GameEnum.JobCode.OnHook))//挂机
|
||||
if (data.code == nameof(GameEnum.JobCode.OnHook)) //挂机
|
||||
{
|
||||
var _eventPublisher = App.GetService<IEventPublisher>();
|
||||
await _eventPublisher.PublishAsync(new ChannelEventSource(BusEventsEnum.BusEventsName.HandleOnHook,
|
||||
data));
|
||||
}
|
||||
|
||||
else if (data.code == nameof(GameEnum.JobCode.UpdateRank)) //更新排名
|
||||
{
|
||||
var _eventPublisher = App.GetService<IEventPublisher>();
|
||||
await _eventPublisher.PublishAsync(new ChannelEventSource(BusEventsEnum.BusEventsName.HandleUpdateRank,
|
||||
data));
|
||||
}
|
||||
else if (data.code == nameof(GameEnum.JobCode.UpdateOnlineTime)) //更新在线时间
|
||||
{
|
||||
var _eventPublisher = App.GetService<IEventPublisher>();
|
||||
await _eventPublisher.PublishAsync(new ChannelEventSource(BusEventsEnum.BusEventsName.HandleOnlineTime,
|
||||
data));
|
||||
}
|
||||
else if (data.code == nameof(GameEnum.JobCode.UpdateCreateMonster)) //更新创建得怪物
|
||||
{
|
||||
var _eventPublisher = App.GetService<IEventPublisher>();
|
||||
await _eventPublisher.PublishAsync(new ChannelEventSource(BusEventsEnum.BusEventsName.HandleCreateMonster,
|
||||
data));
|
||||
}
|
||||
else if (data.code == nameof(GameEnum.JobCode.UpdateFightData)) //更新战斗记录
|
||||
{
|
||||
var _eventPublisher = App.GetService<IEventPublisher>();
|
||||
await _eventPublisher.PublishAsync(new ChannelEventSource(BusEventsEnum.BusEventsName.HandleFightData,
|
||||
data));
|
||||
}
|
||||
else if (data.code == nameof(GameEnum.JobCode.UpdateExchangeData)) //更新兑换类记录
|
||||
{
|
||||
var _eventPublisher = App.GetService<IEventPublisher>();
|
||||
await _eventPublisher.PublishAsync(new ChannelEventSource(BusEventsEnum.BusEventsName.HandleExchangeData,
|
||||
data));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,8 +111,9 @@ public class OnHookService(ISqlSugarClient DbClient, IRedisCache redis) : IOnHoo
|
||||
public async Task HandleHook()
|
||||
{
|
||||
long onTime = TimeExtend.GetTimeStampSeconds;
|
||||
var accService = App.GetService<IUnitUserAccService>();
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
var _eventPublisher = App.GetService<IEventPublisher>();
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_onhook>();
|
||||
var data = await db.Queryable<game_onhook>().Where(it => it.status == 1).ToListAsync();
|
||||
foreach (var hook in data)
|
||||
@@ -147,19 +148,74 @@ public class OnHookService(ISqlSugarClient DbClient, IRedisCache redis) : IOnHoo
|
||||
|
||||
if (await UpdateOnHook(hook.userId, exp, copper))
|
||||
{
|
||||
if (exp > 0)
|
||||
OnHookAwardModel push = new OnHookAwardModel()
|
||||
{
|
||||
await attrService.UpdateUserExp(hook.userId, exp);
|
||||
}
|
||||
userId = hook.userId,
|
||||
exp = exp,
|
||||
copper = copper,
|
||||
useTime = allTime,
|
||||
award = award
|
||||
|
||||
};
|
||||
|
||||
await _eventPublisher.PublishAsync(new ChannelEventSource(BusEventsEnum.BusEventsName.PutOnHookAward,
|
||||
push));
|
||||
}
|
||||
|
||||
if (copper > 0)
|
||||
{
|
||||
await accService.UpdateUserCopper(hook.userId, 1, copper, "挂机获得");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (award.Count > 0)
|
||||
public async Task HandleOnHookGoods(OnHookAwardModel data)
|
||||
{
|
||||
var accService = App.GetService<IUnitUserAccService>();
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
var mapService = App.GetService<IGameMapService>();
|
||||
var equService = App.GetService<IGameEquService>();
|
||||
|
||||
int onlineTime = Convert.ToInt32(data.useTime / 1000 / 60);
|
||||
if (onlineTime > 0)
|
||||
{
|
||||
await attrService.UpdateOnLineTime(data.userId, "OnHook", onlineTime); //更新在线时间
|
||||
}
|
||||
|
||||
await mapService.UpdateUserOnMap(data.userId);//更新在线
|
||||
await equService.UpdateUserOnEquDurability(data.userId);//更新耐久
|
||||
if (data.exp > 0)
|
||||
{
|
||||
await attrService.UpdateUserExp(data.userId, data.exp);
|
||||
}
|
||||
|
||||
if (data.copper > 0)
|
||||
{
|
||||
await accService.UpdateUserCopper(data.userId, 1, data.copper, "挂机获得");
|
||||
}
|
||||
|
||||
if (data.award.Count > 0)
|
||||
{
|
||||
var userService = App.GetService<IUnitUserService>();
|
||||
var userConfig = await userService.GetUserConfigInfo(data.userId);
|
||||
if (userConfig.autoBag != 0)
|
||||
{
|
||||
var weightService = App.GetService<IUnitUserWeight>();
|
||||
bool auto = true;
|
||||
foreach (var item in data.award)
|
||||
{
|
||||
await GameBus.UpdateBag(hook.userId, 1, award, "挂机获得");
|
||||
if (auto == false)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (await weightService.CheckUserWeight(data.userId, item))
|
||||
{
|
||||
await GameBus.UpdateBag(data.userId, 1, item.code, item.parameter, item.count,
|
||||
"挂机获得");
|
||||
}
|
||||
else
|
||||
{
|
||||
auto = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class RankService(ISqlSugarClient DbClient, IRedisCache redis) : IRankService, ITransient
|
||||
{
|
||||
public async Task<string> GetRankUpdateTime()
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKey, "RankTime");
|
||||
if (await redis.ExistsAsync(key))
|
||||
{
|
||||
return await redis.GetAsync<string>(key);
|
||||
}
|
||||
|
||||
return "更新时间:/-/-/ 00:00:00";
|
||||
}
|
||||
|
||||
private async Task SetRankUpdateTime()
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKey, "RankTime");
|
||||
await redis.SetAsync(key, $"更新时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
|
||||
}
|
||||
|
||||
public async Task<List<GameRankModel>> GetGameRank(int type, int area, int page, int limit, RefAsync<int> total)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_temp>();
|
||||
var data = await db.Queryable<unit_user_temp>()
|
||||
.WhereIF(area != 0, it => it.areaId == area)
|
||||
.WhereIF(type == 0, it => it.lev > 30)
|
||||
.WhereIF(type == 1, it => it.atk > 100)
|
||||
.WhereIF(type == 2, it => it.defense > 100)
|
||||
.WhereIF(type == 3, it => it.agility > 100)
|
||||
.WhereIF(type == 4, it => it.upBlood > 100)
|
||||
.WhereIF(type == 5, it => it.upMorale > 0)
|
||||
.WhereIF(type == 6, it => it.luck > 0)
|
||||
.WhereIF(type == 7, it => it.score > 1000)
|
||||
.OrderByIF(type == 0, it => it.lev, OrderByType.Desc)
|
||||
.OrderByIF(type == 0, it => it.upTime, OrderByType.Desc)
|
||||
.OrderByIF(type == 1, it => it.atk, OrderByType.Desc)
|
||||
.OrderByIF(type == 2, it => it.defense, OrderByType.Desc)
|
||||
.OrderByIF(type == 3, it => it.agility, OrderByType.Desc)
|
||||
.OrderByIF(type == 4, it => it.upBlood, OrderByType.Desc)
|
||||
.OrderByIF(type == 5, it => it.upMorale, OrderByType.Desc)
|
||||
.OrderByIF(type == 6, it => it.luck, OrderByType.Desc)
|
||||
.OrderByIF(type == 7, it => it.score, OrderByType.Desc)
|
||||
.Take(100)
|
||||
.ToListAsync();
|
||||
total = data.Count;
|
||||
data = PageExtend.GetPageList(data, page, limit);
|
||||
List<GameRankModel> result = new List<GameRankModel>();
|
||||
foreach (var item in data)
|
||||
{
|
||||
GameRankModel temp = new GameRankModel();
|
||||
temp.userId = item.userId;
|
||||
temp.user = await UserModelTool.GetUserView(item.userId);
|
||||
temp.sign = GetRankSign(item, type);
|
||||
temp.par = "";
|
||||
result.Add(temp);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private string GetRankSign(unit_user_temp data, int type)
|
||||
{
|
||||
string result = "0";
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
result = $"{Convert.ToString(data.lev)}级";
|
||||
break;
|
||||
case 1:
|
||||
result = Convert.ToString(data.atk);
|
||||
break;
|
||||
case 2:
|
||||
result = Convert.ToString(data.defense);
|
||||
break;
|
||||
case 3:
|
||||
result = Convert.ToString(data.agility);
|
||||
break;
|
||||
case 4:
|
||||
result = Convert.ToString(data.upBlood);
|
||||
break;
|
||||
case 5:
|
||||
result = Convert.ToString(data.upMorale);
|
||||
break;
|
||||
case 6:
|
||||
result = (Convert.ToDecimal(data.luck) * 100).ToString("#0");
|
||||
break;
|
||||
case 7:
|
||||
result = Convert.ToDecimal(data.score).ToString("#0.00");
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<List<GameRankModel>> GetGameCopperRank(int area, int page, int limit, RefAsync<int> total)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_copper>();
|
||||
var data = await db.Queryable<unit_user_copper>().LeftJoin<unit_user>((uc, u) => uc.userId == u.userId)
|
||||
.WhereIF(area != 0, (uc, u) => u.areaId == area)
|
||||
.Where((uc, u) => uc.copper > 1000000)
|
||||
.Select<unit_user_copper>()
|
||||
.OrderByDescending(uc => uc.copper)
|
||||
.Take(100)
|
||||
.ToListAsync();
|
||||
total = data.Count;
|
||||
data = PageExtend.GetPageList(data, page, limit);
|
||||
List<GameRankModel> result = new List<GameRankModel>();
|
||||
foreach (var item in data)
|
||||
{
|
||||
GameRankModel temp = new GameRankModel();
|
||||
temp.userId = item.userId;
|
||||
temp.user = await UserModelTool.GetUserView(item.userId);
|
||||
temp.sign = GameTool.ConvertCopperName((long)item.copper);
|
||||
temp.par = "";
|
||||
result.Add(temp);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
public async Task<List<GameRankModel>> GetGameTeachAndRenownRank(int type, int area, int page, int limit, RefAsync<int> total)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_data>();
|
||||
var data = await db.Queryable<unit_user_data>().LeftJoin<unit_user>((uc, u) => uc.userId == u.userId)
|
||||
.WhereIF(area != 0, (uc, u) => u.areaId == area)
|
||||
.WhereIF(type == 9, (uc, u) => uc.teach > 0)
|
||||
.WhereIF(type == 10, (uc, u) => uc.renown > 0)
|
||||
.WhereIF(type == 11, (uc, u) => uc.charm > 0)
|
||||
.Select<unit_user_data>()
|
||||
.OrderByIF(type == 9, uc => uc.teach, OrderByType.Desc)
|
||||
.OrderByIF(type == 10, uc => uc.renown, OrderByType.Desc)
|
||||
.OrderByIF(type == 11, uc => uc.charm, OrderByType.Desc)
|
||||
.Take(100)
|
||||
.ToListAsync();
|
||||
total = data.Count;
|
||||
data = PageExtend.GetPageList(data, page, limit);
|
||||
List<GameRankModel> result = new List<GameRankModel>();
|
||||
foreach (var item in data)
|
||||
{
|
||||
GameRankModel temp = new GameRankModel();
|
||||
temp.userId = item.userId;
|
||||
temp.user = await UserModelTool.GetUserView(item.userId);
|
||||
if (type == 9)
|
||||
{
|
||||
temp.sign = item.teach.ToString();
|
||||
}
|
||||
else if(type==10)
|
||||
{
|
||||
temp.sign = item.renown.ToString();
|
||||
}
|
||||
temp.par = "";
|
||||
result.Add(temp);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
public async Task HandleRank()
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_temp>();
|
||||
await db.Deleteable<unit_user_temp>().ExecuteCommandAsync();
|
||||
|
||||
long endTime = TimeExtend.GetTimeStampBySeconds(TimeAssist.GetDateTimeYMD(0));
|
||||
var data = await db.Queryable<unit_user_online>().Where(it => it.upTime > endTime).ToListAsync();
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
List<unit_user_temp> addData = new List<unit_user_temp>();
|
||||
foreach (var item in data)
|
||||
{
|
||||
var attrInfo = await attrService.GetUserAttrModel(item.userId);
|
||||
unit_user_temp temp = new unit_user_temp()
|
||||
{
|
||||
userId = attrInfo.id,
|
||||
areaId = attrInfo.area,
|
||||
lev = attrInfo.lev,
|
||||
upTime = attrInfo.upTime,
|
||||
luck = attrInfo.luck,
|
||||
score = attrInfo.score,
|
||||
atk = attrInfo.maxAtk,
|
||||
defense = attrInfo.defense,
|
||||
agility = attrInfo.agility,
|
||||
upBlood = attrInfo.upBlood,
|
||||
upMorale = attrInfo.upMorale
|
||||
};
|
||||
addData.Add(temp);
|
||||
}
|
||||
|
||||
if (addData.Count > 0)
|
||||
{
|
||||
await db.Insertable(addData).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
await SetRankUpdateTime();
|
||||
}
|
||||
}
|
||||
@@ -136,6 +136,10 @@ public class GameChatService : IGameChatService, ITransient
|
||||
case "System":
|
||||
chat.delTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddHours(6));
|
||||
break;
|
||||
case "Notice":
|
||||
chat.delTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddDays(1));
|
||||
chat.code = nameof(GameChatEnum.Code.System);
|
||||
break;
|
||||
case "Group":
|
||||
chat.delTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddHours(6));
|
||||
break;
|
||||
|
||||
@@ -55,6 +55,15 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
.OrderByDescending(it => it.lev)
|
||||
.OrderByDescending(it => it.ueId).ToPageListAsync(PageIndex, PageSize, Total);
|
||||
}
|
||||
public async Task<List<unit_user_equ>> GetUserEquData(string userId,string query)
|
||||
{
|
||||
long onTime = TimeExtend.GetTimeStampSeconds;
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
|
||||
return await db.Queryable<unit_user_equ>().Where(it => it.userId == userId)
|
||||
.WhereIF(!string.IsNullOrEmpty(query),
|
||||
it => it.equName.Contains(query) || it.unitEquName.Contains(query))
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<unit_user_equ>> GetUserEquData(string userId, int equId)
|
||||
{
|
||||
@@ -93,7 +102,7 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
.ToList();
|
||||
return userEqu;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<bool> AddUserEqu(string userId, int equId, int count, string remark)
|
||||
{
|
||||
@@ -369,6 +378,7 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var opData = userEqu.Take(count).ToList();
|
||||
return await DeductUserEqu(userId, opData, remark);
|
||||
}
|
||||
@@ -595,6 +605,7 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
result.AddRange(attr.AttrItem);
|
||||
}
|
||||
}
|
||||
|
||||
await redis.SetAsync(key, result, 300);
|
||||
}
|
||||
|
||||
@@ -834,5 +845,90 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
return onMakeEqu;
|
||||
}
|
||||
|
||||
public async Task RemoveUserOnEqu(string userId, string type, int count)
|
||||
{
|
||||
var userOnEqu = await GetUserOnEqu(userId);
|
||||
userOnEqu = userOnEqu.FindAll(it => it.code == type);
|
||||
if (userOnEqu.Count >= count)
|
||||
{
|
||||
var opEqu = userOnEqu.Take(count).ToList();
|
||||
foreach (var item in opEqu)
|
||||
{
|
||||
await EquOnOrDown(item, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 耐久
|
||||
|
||||
private async Task<long> GetUserDurabilityTimer(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "Timer", "Durability");
|
||||
if (await redis.HExistsHashAsync(key, userId))
|
||||
{
|
||||
return await redis.GetHashAsync<long>(key, userId);
|
||||
}
|
||||
|
||||
long result = TimeExtend.GetTimeStampSeconds + 5 * 60;
|
||||
await redis.AddHashAsync(key, userId, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task SetUserDurabilityTimer(string userId, long endTime)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "Timer", "Durability");
|
||||
await redis.AddHashAsync(key, userId, endTime);
|
||||
}
|
||||
|
||||
public async Task UpdateUserOnEquDurability(string userId)
|
||||
{
|
||||
long onTime = TimeExtend.GetTimeStampSeconds;
|
||||
long endTime = await GetUserDurabilityTimer(userId);
|
||||
if (onTime > endTime) //进行耐久更新
|
||||
{
|
||||
await SetUserDurabilityTimer(userId, onTime + 5 * 60);
|
||||
var onEquData = await GetUserOnEqu(userId);
|
||||
List<string> noCode = new List<string>() { "Fashion", "Decorate" };
|
||||
onEquData = onEquData.FindAll(it => it.durability > 0 && !noCode.Contains(it.code));
|
||||
if (onEquData.Count > 0)
|
||||
{
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
var stockDurability = await attrService.GetUserStock(userId, nameof(GameEnum.GameStockCode.Durability));
|
||||
if (stockDurability.Count > 0)
|
||||
{
|
||||
if (stockDurability.Any(it => it.type == nameof(GameEnum.GameStockType.Time)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var onStock = stockDurability.Find(it =>
|
||||
it.type == nameof(GameEnum.GameStockType.Number) && it.sign >= onEquData.Count);
|
||||
if (onStock != null)
|
||||
{
|
||||
onStock.sign = onStock.sign - onEquData.Count;
|
||||
if (await attrService.UpdateUserStock(onStock))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in onEquData)
|
||||
{
|
||||
item.durability = item.durability - 1;
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
|
||||
bool result = await db.Updateable(onEquData).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearUserOnEqu(userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -39,12 +39,6 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task RemoveUserFight(string userId)
|
||||
{
|
||||
string key = string.Format(FightCache.FightCacheKey, "UserFight");
|
||||
bool result = await redis.AddHashAsync(key, userId, new List<string>());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 战斗信息
|
||||
@@ -167,7 +161,7 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> SetFightWin(game_fight_data fightData, string winUser,bool setDefMap=true)
|
||||
public async Task<bool> SetFightWin(game_fight_data fightData, string winUser, bool setDefMap = true)
|
||||
{
|
||||
bool result = false;
|
||||
long okTime = TimeExtend.GetTimeStampMilliseconds;
|
||||
@@ -215,11 +209,10 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
nameof(UserEnum.AttrCode.Monster), winUser, fightData.userId, okTime);
|
||||
if (result)
|
||||
{
|
||||
await RemoveUserFight(fightData.userId);
|
||||
if (setDefMap)
|
||||
{
|
||||
await UserStateTool.SetUserMapDefault(fightData.userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -230,14 +223,26 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
nameof(UserEnum.AttrCode.Person), winUser, lowUser, okTime);
|
||||
if (result)
|
||||
{
|
||||
await RemoveUserFight(lowUser);
|
||||
if (setDefMap)
|
||||
{
|
||||
await UserStateTool.SetUserMapDefault(lowUser);
|
||||
}
|
||||
|
||||
fightData.state = 1;
|
||||
fightData.winCode = nameof(UserEnum.AttrCode.Person);
|
||||
fightData.winUser = winUser;
|
||||
fightData.okTime = okTime;
|
||||
//此处调用战斗结束相关
|
||||
var _eventPublisher = App.GetService<IEventPublisher>();
|
||||
await _eventPublisher.PublishAsync(new ChannelEventSource(BusEventsEnum.BusEventsName.PutFightAward,
|
||||
fightData));
|
||||
}
|
||||
}
|
||||
|
||||
//更新耐久
|
||||
var equService = App.GetService<IGameEquService>();
|
||||
await equService.UpdateUserOnEquDurability(fightData.userId);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -290,6 +295,49 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public async Task HandleFightData()
|
||||
{
|
||||
long endTime = TimeExtend.GetTimeStampSeconds;
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_fight_data>();
|
||||
var data = await db.Queryable<game_fight_data>()
|
||||
.Where(it => it.state == 0 && it.endTime < endTime)
|
||||
.ToListAsync();
|
||||
List<string> dels = data.Select(it => it.fightId).ToList();
|
||||
bool result = await db.Deleteable<game_fight_data>().Where(it => dels.Contains(it.fightId))
|
||||
.ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
List<string> fightIdKeys = new List<string>();
|
||||
List<string> monsterBloodKeys = new List<string>();
|
||||
List<string> fightHarmKeys = new List<string>();
|
||||
foreach (var item in data)
|
||||
{
|
||||
fightIdKeys.Add(string.Format(FightCache.FightCacheKeys, "FightData:Info", item.fightId));
|
||||
fightHarmKeys.Add(string.Format(FightCache.FightCacheKeys, "FightData:Harm", item.fightId));
|
||||
if (item.code == nameof(GameEnum.FightCode.PVE))
|
||||
{
|
||||
monsterBloodKeys.Add(string.Format(FightCache.FightCacheKeys, "FightData:Blood", item.keyId));
|
||||
}
|
||||
}
|
||||
|
||||
if (fightIdKeys.Count > 0)
|
||||
{
|
||||
await redis.DelAsync(fightIdKeys.ToArray());
|
||||
}
|
||||
|
||||
if (monsterBloodKeys.Count > 0)
|
||||
{
|
||||
await redis.DelAsync(monsterBloodKeys.ToArray());
|
||||
}
|
||||
|
||||
if (fightHarmKeys.Count > 0)
|
||||
{
|
||||
await redis.DelAsync(fightHarmKeys.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 战斗相关
|
||||
@@ -303,7 +351,7 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
result = await redis.GetHashAsync<int>(key, userId);
|
||||
}
|
||||
|
||||
if (result > 0)
|
||||
if (result != 0)
|
||||
{
|
||||
await redis.AddHashAsync(key, userId, 0);
|
||||
}
|
||||
@@ -322,6 +370,7 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
public async Task HandleFight(game_fight_data fightData)
|
||||
{
|
||||
string winUser = fightData.winUser;
|
||||
string lowUser = fightData.userId == winUser ? fightData.mainId : fightData.userId;
|
||||
|
||||
#region 发放基础奖励
|
||||
|
||||
@@ -347,6 +396,40 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 场景处理
|
||||
|
||||
if (fightData.code == nameof(GameEnum.FightCode.PVP))
|
||||
{
|
||||
var mapService = App.GetService<IGameMapService>();
|
||||
var userService = App.GetService<IUnitUserService>();
|
||||
var messageService = App.GetService<IMessageService>();
|
||||
var mapInfo = await mapService.GetMapInfo(fightData.mapId);
|
||||
var cityInfo = await mapService.GetCityInfo((int)mapInfo.cityId);
|
||||
var winUserInfo = await userService.GetUserInfoByUserId(winUser);
|
||||
var lowUserInfo = await userService.GetUserInfoByUserId(lowUser);
|
||||
|
||||
//系统广播
|
||||
string boradMsg =
|
||||
$"[{UbbTool.HomeUbb(winUserInfo.userNo, winUserInfo.nick)}]在{cityInfo.cityName}·{mapInfo.mapName}击杀了[{UbbTool.HomeUbb(lowUserInfo.userNo, lowUserInfo.nick)}]!";
|
||||
await messageService.SendBroadcast("0", nameof(MessageEnum.BroadcastCode.Remind), boradMsg);
|
||||
//个人通知
|
||||
var chatService = App.GetService<IGameChatService>();
|
||||
string noticeMsg =
|
||||
$"您在{cityInfo.cityName}·{mapInfo.mapName}被[{UbbTool.HomeUbb(winUserInfo.userNo, winUserInfo.nick)}]击杀!";
|
||||
await chatService.SendChat(lowUser, (int)lowUserInfo.areaId, nameof(GameChatEnum.Code.Notice), noticeMsg);
|
||||
if (mapInfo.isPk == 1)
|
||||
{
|
||||
var relationService = App.GetService<IUnitUserRelationService>();
|
||||
if (await relationService.CheckUserEnemy(winUser, lowUser) == false)
|
||||
{
|
||||
var accService = App.GetService<IUnitUserAccService>();
|
||||
await accService.UpdateUserData(winUser, 1, nameof(AccEnum.AccType.enemy), 5, "击杀玩家"); //加罪恶
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
private async Task PutFightAwardGoods(game_fight_data fightData)
|
||||
@@ -492,7 +575,7 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
if (config[0] == fight.code || config[0] == "ALL")
|
||||
{
|
||||
decimal okLimit = Convert.ToDecimal(config[1]);
|
||||
if ((Convert.ToDecimal(addBlood) / Convert.ToDecimal(user.upBlood) ) > okLimit)
|
||||
if ((Convert.ToDecimal(addBlood) / Convert.ToDecimal(user.upBlood)) > okLimit)
|
||||
{
|
||||
if (item.type == "Number")
|
||||
{
|
||||
@@ -541,7 +624,7 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
}
|
||||
|
||||
//使用普通药品
|
||||
if (addBlood > 0)
|
||||
if (addBlood > 0 && (addBlood / user.upMorale / 1.0M) > 0.6M)
|
||||
{
|
||||
var unitDrug = myDrug.drug.Find(it => it.code == nameof(GoodsEnum.DrugCls.Blood) && it.count > 0);
|
||||
if (unitDrug != null)
|
||||
@@ -563,9 +646,19 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
|
||||
#endregion
|
||||
|
||||
public async Task HandelFightEnd(string userId, List<dynamic> data)
|
||||
public async Task HandelFightEnd(string userId, List<FightRemoveData> data)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
var equService = App.GetService<IGameEquService>();
|
||||
foreach (var item in data)
|
||||
{
|
||||
if (item.code == "Equ")
|
||||
{
|
||||
await equService.RemoveUserOnEqu(userId, item.par, item.count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -183,7 +183,17 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
isOnline = isOnline
|
||||
};
|
||||
}
|
||||
|
||||
public async Task UpdateUserOnMap(string userId)
|
||||
{
|
||||
unit_user_online onLine = await GetUserOnMap(userId);
|
||||
onLine.upTime = TimeExtend.GetTimeStampSeconds;
|
||||
string key = string.Format(UserCache.BaseCacheKey, "UserOnline");
|
||||
if (await redis.AddHashAsync(key, userId, onLine))
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_online>();
|
||||
await db.Updateable<unit_user_online>(onLine).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
public async Task UpdateUserOnMap(string userId, string ip, string mapId)
|
||||
{
|
||||
unit_user_online onLine = new unit_user_online();
|
||||
|
||||
@@ -123,6 +123,59 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MonsterData", "CreateMonsterOnMap");
|
||||
await redis.DelHashAsync(key, mapId);
|
||||
}
|
||||
|
||||
public async Task<bool> RemoveCreateMonster(string umId)
|
||||
{
|
||||
bool result = false;
|
||||
var data = await GetCreateMonsterInfo(umId);
|
||||
if (data != null)
|
||||
{
|
||||
result = await RemoveCreateMonster(data);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> RemoveCreateMonster(unit_user_monster data)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_monster>();
|
||||
bool result = await db.Deleteable<unit_user_monster>().Where(it => it.umId == data.umId).ExecuteCommandAsync()>0;
|
||||
if (result)
|
||||
{
|
||||
await ClearCreateMonster(data.mapId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task HandleCreateMonster()
|
||||
{
|
||||
var endTime = TimeExtend.GetTimeStampSeconds;
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_monster>();
|
||||
var data = await db.Queryable<unit_user_monster>().Where(it => it.endTime < endTime).ToListAsync();
|
||||
List<string> delIds = new List<string>();
|
||||
List<string> mapIds = new List<string>();
|
||||
foreach (var item in data)
|
||||
{
|
||||
delIds.Add(item.umId);
|
||||
if (mapIds.Any(it => it == item.mapId) == false)
|
||||
{
|
||||
mapIds.Add(item.mapId);
|
||||
}
|
||||
}
|
||||
|
||||
if (delIds.Count > 0)
|
||||
{
|
||||
bool result = await db.Deleteable<unit_user_monster>().Where(it => delIds.Contains(it.umId))
|
||||
.ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MonsterData", "CreateMonsterOnMap");
|
||||
await redis.DelHashAsync(key, mapIds.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async Task<List<MapMonsterModel>> GetMapMonster(string userId, string mapId, string teamId)
|
||||
{
|
||||
|
||||
@@ -22,14 +22,24 @@ public class UnitUserAccService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
}
|
||||
else if (accType == nameof(AccEnum.AccType.teach))
|
||||
{
|
||||
var info = await GetUserAccInfo(userId);
|
||||
var info = await GetUserDataInfo(userId);
|
||||
result = (long)info.teach;
|
||||
}
|
||||
else if (accType == nameof(AccEnum.AccType.renown))
|
||||
{
|
||||
var info = await GetUserAccInfo(userId);
|
||||
var info = await GetUserDataInfo(userId);
|
||||
result = (long)info.renown;
|
||||
}
|
||||
else if (accType == nameof(AccEnum.AccType.charm))
|
||||
{
|
||||
var info = await GetUserDataInfo(userId);
|
||||
result = (long)info.charm;
|
||||
}
|
||||
else if (accType == nameof(AccEnum.AccType.enemy))
|
||||
{
|
||||
var info = await GetUserDataInfo(userId);
|
||||
result = (long)info.enemy;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -55,8 +65,6 @@ public class UnitUserAccService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
isOk = await db.Updateable<unit_user_acc>()
|
||||
.SetColumnsIF(accType.Equals(nameof(AccEnum.AccType.cowry)), it => it.cowry == it.cowry + opCount)
|
||||
.SetColumnsIF(accType.Equals(nameof(AccEnum.AccType.gold)), it => it.gold == it.gold + opCount)
|
||||
.SetColumnsIF(accType.Equals(nameof(AccEnum.AccType.teach)), it => it.teach == it.teach + opCount)
|
||||
.SetColumnsIF(accType.Equals(nameof(AccEnum.AccType.renown)), it => it.renown == it.renown + opCount)
|
||||
.Where(it => it.userId == userId).ExecuteCommandAsync() > 0;
|
||||
//生成日志
|
||||
if (isOk)
|
||||
@@ -94,10 +102,14 @@ public class UnitUserAccService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
{
|
||||
result = await UpdateUserCopper(userId, type, count, remark);
|
||||
}
|
||||
else
|
||||
else if (accType == nameof(AccEnum.AccType.gold)||accType == nameof(AccEnum.AccType.cowry))
|
||||
{
|
||||
result = await UpdateUserAcc(userId, type, accType, count, name, remark);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await UpdateUserData(userId, type, accType, count, remark);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -138,5 +150,38 @@ public class UnitUserAccService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
return isOk;
|
||||
}
|
||||
|
||||
public async Task<unit_user_data> GetUserDataInfo(string userId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_data>();
|
||||
return await db.Queryable<unit_user_data>().Where(i => i.userId == userId).SingleAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateUserData(string userId, int type, string accType, long count, string remark = "")
|
||||
{
|
||||
bool isOk = false;
|
||||
decimal opCount = type == 0 ? (0 - count) : count;
|
||||
try
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_data>();
|
||||
await DbClient.AsTenant().BeginTranAsync();
|
||||
|
||||
isOk = await db.Updateable<unit_user_data>()
|
||||
.SetColumnsIF(accType.Equals(nameof(AccEnum.AccType.teach)), it => it.teach == it.teach + opCount)
|
||||
.SetColumnsIF(accType.Equals(nameof(AccEnum.AccType.renown)), it => it.renown == it.renown + opCount)
|
||||
.SetColumnsIF(accType.Equals(nameof(AccEnum.AccType.charm)), it => it.charm == it.charm + opCount)
|
||||
.SetColumnsIF(accType.Equals(nameof(AccEnum.AccType.enemy)), it => it.enemy == it.enemy + opCount)
|
||||
.Where(it => it.userId == userId).ExecuteCommandAsync() > 0;
|
||||
|
||||
await DbClient.AsTenant().CommitTranAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
isOk = false;
|
||||
await DbClient.AsTenant().RollbackTranAsync();
|
||||
}
|
||||
|
||||
return isOk;
|
||||
}
|
||||
|
||||
#endregion 账户操作
|
||||
}
|
||||
@@ -18,6 +18,7 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
result.code = nameof(UserEnum.AttrCode.Person);
|
||||
var unitAttr = await GetUserAttr(userId);
|
||||
result.lev = (int)unitAttr.lev;
|
||||
result.upTime = (long)unitAttr.levUpdate;
|
||||
result.minAtk = (int)unitAttr.minAtk;
|
||||
result.maxAtk = (int)unitAttr.maxAtk;
|
||||
result.defense = (int)unitAttr.defense;
|
||||
@@ -489,6 +490,16 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
|
||||
public async Task<bool> UpdateOnLineTime(string userId, string code, int time)
|
||||
{
|
||||
if (code == "Default")
|
||||
{
|
||||
var hookService = App.GetService<IOnHookService>();
|
||||
var hookInfo = await hookService.GetUserOnHook(userId);
|
||||
if (hookInfo.status == 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_online_time>();
|
||||
bool result = await db.Updateable<unit_user_online_time>()
|
||||
.SetColumns(it => it.dayTime == it.dayTime + time)
|
||||
@@ -498,6 +509,15 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task HandleOnLineTimeData()
|
||||
{
|
||||
int day = DateTime.Now.Day;
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_online_time>();
|
||||
await db.Updateable<unit_user_online_time>().SetColumns(it => it.dayTime == 0)
|
||||
.WhereIF(day == 1, it => it.monthTime == 0)
|
||||
.Where(it => true).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 药品栏
|
||||
@@ -657,6 +677,7 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
{
|
||||
result.AddRange(item.attr);
|
||||
}
|
||||
|
||||
return GameAttrTool.GetAttrItemValue(nameof(GameEnum.AttrCode.AddExp), result, 0);
|
||||
}
|
||||
|
||||
@@ -766,7 +787,7 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
var result = await db.Updateable(data).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearUserAttrCache(data.userId);
|
||||
await ClearUserStockCache(data.userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -816,6 +837,7 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task AddUserLoadState(string userId, List<string> codes)
|
||||
{
|
||||
foreach (var code in codes)
|
||||
@@ -851,9 +873,11 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
name = "麻痹";
|
||||
break;
|
||||
}
|
||||
|
||||
await AddUserLoadState(userId, name, code);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> RandomRemoveUserLoadState(string userId, int count)
|
||||
{
|
||||
var data = await GetUserLoadState(userId);
|
||||
@@ -879,7 +903,6 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "AttrData", "LoadState");
|
||||
await redis.DelHashAsync(key, userId);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -185,9 +185,15 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni
|
||||
acc.userId = userId;
|
||||
acc.cowry = 0;
|
||||
acc.gold = 0;
|
||||
acc.teach = 0;
|
||||
acc.renown = 0;
|
||||
db.Insertable(acc).AddQueue();
|
||||
|
||||
unit_user_data userData = new unit_user_data();
|
||||
userData.userId = userId;
|
||||
userData.teach = 0;
|
||||
userData.renown = 0;
|
||||
userData.charm = 0;
|
||||
userData.enemy = 0;
|
||||
db.Insertable(userData).AddQueue();
|
||||
//注册游戏货币
|
||||
unit_user_copper copper = new unit_user_copper();
|
||||
copper.userId = userId;
|
||||
|
||||
Reference in New Issue
Block a user