12121
This commit is contained in:
@@ -12,6 +12,7 @@ public interface IGameMapService
|
||||
Task<game_city_map> GetMapInfo(string mapId);
|
||||
Task<int> GetMapCityByMapId(string mapId);
|
||||
Task<List<game_city_npc>> GetMapNpc(string mapId);
|
||||
Task<List<GameNpcModel>> GetMapNpcModel(string userId, string mapId, int areaId);
|
||||
Task<game_city_npc> GetNpcInfo(int npcId);
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public interface IGameTaskService
|
||||
{
|
||||
#region 任务基础
|
||||
|
||||
Task<game_task> GetTaskInfo(int taskId);
|
||||
Task<List<UserTaskModel>> GetTaskDataByNpc(string userId, int npcId);
|
||||
Task<game_task_item> GetTaskItemInfo(int itemId);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 个人任务
|
||||
|
||||
Task<unit_user_task> GetUserTaskInfo(string userId, int taskId);
|
||||
Task<bool> UpdateUserTaskInfo(string userId, int itemId);
|
||||
Task<int> GetUserTaskCount(string userId, int taskId);
|
||||
Task<UserTaskModel> GetUserTaskModel(string userId, game_task_item task);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -187,6 +187,12 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
result = await db.SaveQueuesAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
if (fightData.keyId != fightData.fightId)
|
||||
{
|
||||
var monsterService = App.GetService<IGameMonsterService>();
|
||||
await monsterService.RemoveCreateMonster(fightData.keyId);
|
||||
}
|
||||
|
||||
foreach (var item in data)
|
||||
{
|
||||
await ClearFightInfoCache(item.fightId, item.keyId, true);
|
||||
|
||||
@@ -119,6 +119,40 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<List<GameNpcModel>> GetMapNpcModel(string userId, string mapId, int areaId)
|
||||
{
|
||||
var taskService = App.GetService<IGameTaskService>();
|
||||
List<GameNpcModel> result = new List<GameNpcModel>();
|
||||
var data = await GetMapNpc(mapId);
|
||||
foreach (var item in data)
|
||||
{
|
||||
if (GameTool.AreaVerify(areaId, item.areaId) == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
GameNpcModel temp = new GameNpcModel()
|
||||
{
|
||||
npcId = item.npcId,
|
||||
name = item.npcName,
|
||||
tips = item.tips,
|
||||
state = 0
|
||||
};
|
||||
if (item.code == nameof(MapEnum.NpcCode.Task))
|
||||
{
|
||||
var task = await taskService.GetTaskDataByNpc(userId,item.npcId);
|
||||
if (task.Count > 0)
|
||||
{
|
||||
temp.state = task.Any(it => it.state == 0) ? 1 : 2;
|
||||
}
|
||||
}
|
||||
|
||||
result.Add(temp);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<game_city_npc> GetNpcInfo(int npcId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "NpcInfo");
|
||||
@@ -183,6 +217,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
isOnline = isOnline
|
||||
};
|
||||
}
|
||||
|
||||
public async Task UpdateUserOnMap(string userId)
|
||||
{
|
||||
unit_user_online onLine = await GetUserOnMap(userId);
|
||||
@@ -194,6 +229,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
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();
|
||||
|
||||
@@ -75,6 +75,7 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
monsterName = monsterInfo.name,
|
||||
code = monsterInfo.code,
|
||||
par = par,
|
||||
state = 0,
|
||||
addTime = onTime,
|
||||
endTime = endTime
|
||||
});
|
||||
@@ -106,11 +107,12 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_monster>();
|
||||
var data = await db.Queryable<unit_user_monster>().Where(it => it.mapId == mapId).ToListAsync();
|
||||
var data = await db.Queryable<unit_user_monster>().Where(it => it.mapId == mapId && it.state == 0)
|
||||
.ToListAsync();
|
||||
await redis.AddHashAsync(key, mapId, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
public async Task<unit_user_monster> GetCreateMonsterInfo(string umId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_monster>();
|
||||
@@ -123,14 +125,14 @@ 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);
|
||||
result = await RemoveCreateMonster(data);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -139,7 +141,9 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
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;
|
||||
bool result = await db.Updateable<unit_user_monster>()
|
||||
.SetColumns(it => it.state == 1)
|
||||
.Where(it => it.umId == data.umId).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearCreateMonster(data.mapId);
|
||||
@@ -174,7 +178,6 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
await redis.DelHashAsync(key, mapIds.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async Task<List<MapMonsterModel>> GetMapMonster(string userId, string mapId, string teamId)
|
||||
@@ -258,9 +261,9 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
|
||||
#endregion
|
||||
|
||||
#region 怪物模型
|
||||
#region 怪物模型
|
||||
|
||||
public async Task<UserAttrModel> GetMonsterAttrModel(string keyId,string monsterId)
|
||||
public async Task<UserAttrModel> GetMonsterAttrModel(string keyId, string monsterId)
|
||||
{
|
||||
UserAttrModel temp = new UserAttrModel();
|
||||
var monsterInfo = await GetMonsterInfo(monsterId);
|
||||
@@ -283,7 +286,7 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
temp.morale = 0;
|
||||
temp = GameAttrTool.GetRoleAttrTempMerge(temp, monsterInfo.attr);
|
||||
temp.score = 0;
|
||||
|
||||
|
||||
//处理负面
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
var loadState = await attrService.GetUserLoadState(keyId);
|
||||
@@ -293,6 +296,7 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
private async Task<int> GetMonsterBlood(string keyId, int maxBlood)
|
||||
{
|
||||
int blood = maxBlood;
|
||||
|
||||
@@ -0,0 +1,318 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameTaskService(ISqlSugarClient DbClient, IRedisCache redis) : IGameTaskService, ITransient
|
||||
{
|
||||
#region 任务基础
|
||||
|
||||
public async Task<game_task> GetTaskInfo(int taskId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "TaskCache", "TaskInfo");
|
||||
if (await redis.HExistsHashAsync(key, taskId.ToString()))
|
||||
{
|
||||
return await redis.GetHashAsync<game_task>(key, taskId.ToString());
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_task>();
|
||||
var data = await db.Queryable<game_task>().Where(it => it.taskId == taskId).SingleAsync();
|
||||
await redis.AddHashAsync(key, taskId.ToString(), data);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<List<UserTaskModel>> GetTaskDataByNpc(string userId, int npcId)
|
||||
{
|
||||
List<game_task_item> data = new List<game_task_item>();
|
||||
List<UserTaskModel> result = new List<UserTaskModel>();
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "TaskCache", "NpcTask");
|
||||
if (await redis.HExistsHashAsync(key, npcId.ToString()))
|
||||
{
|
||||
data = await redis.GetHashAsync<List<game_task_item>>(key, npcId.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_task_item>();
|
||||
data = await db.Queryable<game_task_item>().Where(it => it.npcId == npcId).ToListAsync();
|
||||
await redis.AddHashAsync(key, npcId.ToString(), data);
|
||||
}
|
||||
|
||||
foreach (var item in data)
|
||||
{
|
||||
var temp = await GetUserTaskModel(userId, item);
|
||||
if (temp.state != -1)
|
||||
{
|
||||
result.Add(temp);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<game_task_item> GetTaskItemInfo(int itemId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "TaskCache", "TaskItemInfo");
|
||||
if (await redis.HExistsHashAsync(key, itemId.ToString()))
|
||||
{
|
||||
return await redis.GetHashAsync<game_task_item>(key, itemId.ToString());
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_task_item>();
|
||||
var data = await db.Queryable<game_task_item>().Where(it => it.tiId == itemId).SingleAsync();
|
||||
await redis.AddHashAsync(key, itemId.ToString(), data);
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 个人任务
|
||||
|
||||
public async Task<unit_user_task> GetUserTaskInfo(string userId, int taskId)
|
||||
{
|
||||
string utId = $"{userId}_{taskId}";
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "TaskCache", "UserTaskInfo");
|
||||
if (await redis.HExistsHashAsync(key, utId.ToString()))
|
||||
{
|
||||
return await redis.GetHashAsync<unit_user_task>(key, utId);
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_task>();
|
||||
var data = await db.Queryable<unit_user_task>().Where(it => it.utId == utId).SingleAsync();
|
||||
await redis.AddHashAsync(key, utId, data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateUserTaskInfo(string userId, int itemId)
|
||||
{
|
||||
bool result = false;
|
||||
var taskInfo = await GetTaskItemInfo(itemId);
|
||||
if (taskInfo != null)
|
||||
{
|
||||
string utId = $"{userId}_{taskInfo.taskId}";
|
||||
if (taskInfo.itemType == 2)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_task>();
|
||||
result = await db.Deleteable<unit_user_task>().Where(it => it.utId == utId).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "TaskCache", "UserTaskInfo");
|
||||
await redis.DelHashAsync(key, utId);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var onTask = await GetUserTaskInfo(userId, (int)taskInfo.taskId);
|
||||
if (onTask == null)
|
||||
{
|
||||
onTask = new unit_user_task();
|
||||
onTask.utId = utId;
|
||||
onTask.userId = userId;
|
||||
onTask.taskId = taskInfo.taskId;
|
||||
onTask.itemId = taskInfo.tiId;
|
||||
onTask.name = taskInfo.name;
|
||||
onTask.code = taskInfo.code;
|
||||
onTask.endTime = await GetItemEndTime((int)taskInfo.taskId, (int)taskInfo.time);
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_task>();
|
||||
result = await db.Insertable(onTask).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
onTask.itemId = taskInfo.tiId;
|
||||
onTask.name = taskInfo.name;
|
||||
onTask.code = taskInfo.code;
|
||||
onTask.endTime = await GetItemEndTime((int)taskInfo.taskId, (int)taskInfo.time);
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_task>();
|
||||
result = await db.Updateable(onTask).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "TaskCache", "UserTaskInfo");
|
||||
await redis.AddHashAsync(key, utId, onTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
if (taskInfo.itemType == 0)
|
||||
{
|
||||
await AddUserTaskLog(userId, (int)taskInfo.taskId);
|
||||
}
|
||||
else if (taskInfo.itemType == 1)
|
||||
{
|
||||
//初始化下一环任务
|
||||
await ResetNextTask(userId, taskInfo.tiId + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<int> GetUserTaskCount(string userId, int taskId)
|
||||
{
|
||||
string utId = $"{userId}_{taskId}";
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "TaskCache", "UserTaskCount");
|
||||
if (await redis.HExistsHashAsync(key, taskId.ToString()))
|
||||
{
|
||||
return await redis.GetHashAsync<int>(key, utId);
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_task_log>();
|
||||
var data = await db.Queryable<unit_user_task_log>().Where(it => it.userId == userId && it.taskId == taskId)
|
||||
.CountAsync();
|
||||
await redis.AddHashAsync(key, utId, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
private async Task AddUserTaskLog(string userId, int taskId)
|
||||
{
|
||||
string utId = $"{userId}_{taskId}";
|
||||
long endTime = await GetEndTime(taskId);
|
||||
unit_user_task_log log = new unit_user_task_log()
|
||||
{
|
||||
utId = utId,
|
||||
userId = userId,
|
||||
taskId = taskId,
|
||||
addTime = DateTime.Now,
|
||||
endTime = endTime
|
||||
};
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_task_log>();
|
||||
bool result = await db.Insertable(log).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "TaskCache", "UserTaskCount");
|
||||
await redis.DelHashAsync(key, utId);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ResetNextTask(string userId, int nextId)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task<UserTaskModel> GetUserTaskModel(string userId, game_task_item task)
|
||||
{
|
||||
UserTaskModel model = new UserTaskModel()
|
||||
{
|
||||
code = task.code,
|
||||
taskId = (int)task.taskId,
|
||||
itemId = task.tiId,
|
||||
name = task.name,
|
||||
state = -1
|
||||
};
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
int myLev = await attrService.GetUserLev(userId);
|
||||
if (myLev < task.lev)
|
||||
{
|
||||
return model;
|
||||
}
|
||||
|
||||
if (task.itemType == 0) //判断是否可接
|
||||
{
|
||||
var taskInfo = await GetTaskInfo((int)task.taskId);
|
||||
if (taskInfo == null)
|
||||
{
|
||||
return model;
|
||||
}
|
||||
|
||||
if (taskInfo.status == 0)
|
||||
{
|
||||
return model;
|
||||
}
|
||||
|
||||
int time = TimeAssist.GetHourNum;
|
||||
if (time < taskInfo.sTime || time > taskInfo.eTime)
|
||||
{
|
||||
return model;
|
||||
}
|
||||
|
||||
var userTask = await GetUserTaskInfo(userId, (int)task.taskId);
|
||||
if (userTask != null) //判断是否接取
|
||||
{
|
||||
return model;
|
||||
}
|
||||
|
||||
var onCount = await GetUserTaskCount(userId, (int)task.taskId);
|
||||
if (onCount >= taskInfo.count)
|
||||
{
|
||||
return model;
|
||||
}
|
||||
|
||||
model.result = await GameBus.CheckNeed(userId, task.needData);
|
||||
model.state = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
var userTask = await GetUserTaskInfo(userId, (int)task.taskId);
|
||||
if (userTask == null) //判断是否接取
|
||||
{
|
||||
return model;
|
||||
}
|
||||
|
||||
if (task.tiId != (userTask.itemId + 1))
|
||||
{
|
||||
return model;
|
||||
}
|
||||
|
||||
var result = await GameBus.CheckNeed(userId, task.needData);
|
||||
model.result = result;
|
||||
if (result.result)
|
||||
{
|
||||
model.state = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
model.state = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 辅助
|
||||
|
||||
private async Task<long> GetItemEndTime(int taskId, int time)
|
||||
{
|
||||
long result = TimeExtend.GetTimeStampSeconds;
|
||||
if (time == 0)
|
||||
{
|
||||
var taskInfo = await GetTaskInfo(taskId);
|
||||
if (taskInfo.time == 0)
|
||||
{
|
||||
result += 3650 * 24 * 60 * 60;
|
||||
}
|
||||
else
|
||||
{
|
||||
result += (int)taskInfo.time * 60;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result += time * 60;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<long> GetEndTime(int taskId)
|
||||
{
|
||||
long result = TimeExtend.GetTimeStampSeconds;
|
||||
var taskInfo = await GetTaskInfo(taskId);
|
||||
if (taskInfo != null)
|
||||
{
|
||||
if (taskInfo.time == 0)
|
||||
{
|
||||
result += 3650 * 24 * 60 * 60;
|
||||
}
|
||||
else
|
||||
{
|
||||
result += (int)taskInfo.time * 60;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user