diff --git a/Service/Application.Domain.Entity/game/user/unit_user_monster.cs b/Service/Application.Domain.Entity/game/user/unit_user_monster.cs index 2a6a918..71c0fc2 100644 --- a/Service/Application.Domain.Entity/game/user/unit_user_monster.cs +++ b/Service/Application.Domain.Entity/game/user/unit_user_monster.cs @@ -19,7 +19,7 @@ namespace Application.Domain.Entity public string? userId { get; set; } /// - /// areaCode + /// 作用区域 /// [SugarColumn(Length = 255, IsNullable = true)] public string? areaCode { get; set; } @@ -43,17 +43,23 @@ namespace Application.Domain.Entity public string? monsterName { get; set; } /// - /// code + /// 场景 /// [SugarColumn(Length = 50, IsNullable = true)] public string? code { get; set; } /// - /// par + /// 相关参数 /// [SugarColumn(Length = 255, IsNullable = true)] public string? par { get; set; } + /// + /// state + /// + [SugarColumn(IsNullable = true)] + public int? state { get; set; } + /// /// addTime /// diff --git a/Service/Application.Domain.Entity/game/user/unit_user_task.cs b/Service/Application.Domain.Entity/game/user/unit_user_task.cs new file mode 100644 index 0000000..651a21b --- /dev/null +++ b/Service/Application.Domain.Entity/game/user/unit_user_task.cs @@ -0,0 +1,52 @@ +using SqlSugar; +using System; + +namespace Application.Domain.Entity +{ + [Tenant("Kg.SeaTime.Game")] + public class unit_user_task + { + /// + /// utId + /// + [SugarColumn(IsPrimaryKey = true, Length = 50)] + public string utId { get; set; } + + /// + /// userId + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? userId { get; set; } + + /// + /// taskId + /// + [SugarColumn(IsNullable = true)] + public int? taskId { get; set; } + + /// + /// itemId + /// + [SugarColumn(IsNullable = true)] + public int? itemId { get; set; } + + /// + /// name + /// + [SugarColumn(Length = 255, IsNullable = true)] + public string? name { get; set; } + + /// + /// code + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? code { get; set; } + + + /// + /// endTime + /// + [SugarColumn(IsNullable = true)] + public long? endTime { get; set; } + } +} \ No newline at end of file diff --git a/Service/Application.Domain.Entity/game/user/unit_user_task_log.cs b/Service/Application.Domain.Entity/game/user/unit_user_task_log.cs new file mode 100644 index 0000000..6680425 --- /dev/null +++ b/Service/Application.Domain.Entity/game/user/unit_user_task_log.cs @@ -0,0 +1,39 @@ +using SqlSugar; +using System; + +namespace Application.Domain.Entity +{ + [Tenant("Kg.SeaTime.Game")] + public class unit_user_task_log + { + /// + /// utId + /// + [SugarColumn(IsPrimaryKey = true, Length = 50)] + public string utId { get; set; } + + /// + /// userId + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? userId { get; set; } + + /// + /// taskId + /// + [SugarColumn(IsNullable = true)] + public int? taskId { get; set; } + + /// + /// addTime + /// + [SugarColumn(IsNullable = true)] + public DateTime? addTime { get; set; } + + /// + /// endTime + /// + [SugarColumn(IsNullable = true)] + public long? endTime { get; set; } + } +} \ No newline at end of file diff --git a/Service/Application.Domain.Entity/model/GameNpcModel.cs b/Service/Application.Domain.Entity/model/GameNpcModel.cs new file mode 100644 index 0000000..42afacf --- /dev/null +++ b/Service/Application.Domain.Entity/model/GameNpcModel.cs @@ -0,0 +1,9 @@ +namespace Application.Domain.Entity; + +public class GameNpcModel +{ + public int npcId { get; set; } + public string name { get; set; } + public string tips { get; set; } + public int state { get; set; } +} \ No newline at end of file diff --git a/Service/Application.Domain.Entity/model/TaskNeedData.cs b/Service/Application.Domain.Entity/model/TaskNeedData.cs new file mode 100644 index 0000000..a5a0346 --- /dev/null +++ b/Service/Application.Domain.Entity/model/TaskNeedData.cs @@ -0,0 +1,8 @@ +namespace Application.Domain.Entity; + +public class TaskNeedData:TowerNeed +{ + public string areaCode { get; set; } + public string mapId { get; set; } + +} \ No newline at end of file diff --git a/Service/Application.Domain.Entity/model/UserTaskModel.cs b/Service/Application.Domain.Entity/model/UserTaskModel.cs new file mode 100644 index 0000000..467d922 --- /dev/null +++ b/Service/Application.Domain.Entity/model/UserTaskModel.cs @@ -0,0 +1,11 @@ +namespace Application.Domain.Entity; + +public class UserTaskModel +{ + public string code { get; set; } + public int taskId { get; set; } + public int itemId { get; set; } + public string name { get; set; } + public int state { get; set; } + public CheckTowerNeed result { get; set; } +} \ No newline at end of file diff --git a/Service/Application.Domain.Entity/resource/game/game_task.cs b/Service/Application.Domain.Entity/resource/game/game_task.cs new file mode 100644 index 0000000..666e01d --- /dev/null +++ b/Service/Application.Domain.Entity/resource/game/game_task.cs @@ -0,0 +1,81 @@ +using SqlSugar; +using System; + +namespace Application.Domain.Entity +{ + [Tenant("Kg.SeaTime.Resource")] + public class game_task + { + /// + /// taskId + /// + [SugarColumn(IsPrimaryKey = true)] + public int taskId { get; set; } + + /// + /// code + /// + [SugarColumn(Length = 255, IsNullable = true)] + public string? code { get; set; } + + /// + /// name + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? name { get; set; } + + /// + /// itemCount + /// + [SugarColumn(IsNullable = true)] + public int? itemCount { get; set; } + + /// + /// count + /// + [SugarColumn(IsNullable = true)] + public int? count { get; set; } + + /// + /// timeSpan + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? timeSpan { get; set; } + + /// + /// sTime + /// + [SugarColumn(IsNullable = true)] + public int? sTime { get; set; } + + /// + /// eTime + /// + [SugarColumn(IsNullable = true)] + public int? eTime { get; set; } + + /// + /// lev + /// + [SugarColumn(IsNullable = true)] + public int? lev { get; set; } + + /// + /// remark + /// + [SugarColumn(Length = 255, IsNullable = true)] + public string? remark { get; set; } + + /// + /// 任务完成时间分钟 0不限制 + /// + [SugarColumn(IsNullable = true)] + public int? time { get; set; } + + /// + /// status + /// + [SugarColumn(IsNullable = true)] + public int? status { get; set; } + } +} \ No newline at end of file diff --git a/Service/Application.Domain.Entity/resource/game/game_task_item.cs b/Service/Application.Domain.Entity/resource/game/game_task_item.cs new file mode 100644 index 0000000..01bd3d9 --- /dev/null +++ b/Service/Application.Domain.Entity/resource/game/game_task_item.cs @@ -0,0 +1,99 @@ +using SqlSugar; +using System; + +namespace Application.Domain.Entity +{ + [Tenant("Kg.SeaTime.Resource")] + public class game_task_item + { + /// + /// tiId + /// + [SugarColumn(IsPrimaryKey = true)] + public int tiId { get; set; } + + /// + /// taskId + /// + [SugarColumn(IsNullable = true)] + public int? taskId { get; set; } + + /// + /// name + /// + [SugarColumn(Length = 255, IsNullable = true)] + public string? name { get; set; } + + /// + /// 主线、支线 + /// + [SugarColumn(Length = 255, IsNullable = true)] + public string? code { get; set; } + + /// + /// inType + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? inType { get; set; } + + /// + /// 普通,答题 + /// + [SugarColumn(Length = 255, IsNullable = true)] + public string? itemCode { get; set; } + + /// + /// 0起始环 1任务环 2结束环 + /// + [SugarColumn(IsNullable = true)] + public int? itemType { get; set; } + + /// + /// npcId + /// + [SugarColumn(IsNullable = true)] + public int? npcId { get; set; } + + /// + /// needData + /// + [SugarColumn(IsNullable = true,IsJson = true)] + public List needData { get; set; } + + /// + /// 环说明 + /// + [SugarColumn(IsNullable = true)] + public string? taskTips { get; set; } + + /// + /// nextTips + /// + [SugarColumn(IsNullable = true)] + public string? nextTips { get; set; } + + /// + /// 按钮提示 + /// + [SugarColumn(IsNullable = true)] + public string? btnTips { get; set; } + + /// + /// award + /// + [SugarColumn(IsNullable = true)] + public string? award { get; set; } + + /// + /// 任务时长 + /// + [SugarColumn(IsNullable = true)] + public int? time { get; set; } + + /// + /// 等级 + /// + [SugarColumn(IsNullable = true)] + public int? lev { get; set; } + } +} diff --git a/Service/Application.Domain/Config/GameConfig.cs b/Service/Application.Domain/Config/GameConfig.cs index cb4956e..a343937 100644 --- a/Service/Application.Domain/Config/GameConfig.cs +++ b/Service/Application.Domain/Config/GameConfig.cs @@ -18,4 +18,6 @@ public static class GameConfig public const int GameToMapNeedCopper = 5;//传送每海里费用 public const int TeamCacheTime = 300;//队伍缓存时间 public const int GameEquApprGoods = 10019;//鉴定装备道具 + public const int GameGetTaskGoods =10034 ;//引路蜂 + public const int GameRetTaskGoods =10033 ;//领路蝶 } \ No newline at end of file diff --git a/Service/Application.Domain/Enum/MapEnum.cs b/Service/Application.Domain/Enum/MapEnum.cs index b93a5f8..ee43287 100644 --- a/Service/Application.Domain/Enum/MapEnum.cs +++ b/Service/Application.Domain/Enum/MapEnum.cs @@ -16,4 +16,12 @@ public class MapEnum DEF_MAP, Dup_Map } + + public enum NpcCode + { + Default, + Task, + Dup_In, + Dup_Exit + } } \ No newline at end of file diff --git a/Service/Application.Domain/Enum/TaskEnum.cs b/Service/Application.Domain/Enum/TaskEnum.cs new file mode 100644 index 0000000..62f68f8 --- /dev/null +++ b/Service/Application.Domain/Enum/TaskEnum.cs @@ -0,0 +1,16 @@ +namespace Application.Domain; + +public static class TaskEnum +{ + public enum TaskCode + { + 主线, + 支线, + 日常 + } + public enum ItemCode + { + 普通, + 答题 + } +} \ No newline at end of file diff --git a/Service/Application.Domain/Services/Interface/Map/IGameMapService.cs b/Service/Application.Domain/Services/Interface/Map/IGameMapService.cs index b60a372..563aeab 100644 --- a/Service/Application.Domain/Services/Interface/Map/IGameMapService.cs +++ b/Service/Application.Domain/Services/Interface/Map/IGameMapService.cs @@ -12,6 +12,7 @@ public interface IGameMapService Task GetMapInfo(string mapId); Task GetMapCityByMapId(string mapId); Task> GetMapNpc(string mapId); + Task> GetMapNpcModel(string userId, string mapId, int areaId); Task GetNpcInfo(int npcId); #endregion diff --git a/Service/Application.Domain/Services/Interface/Task/IGameTaskService.cs b/Service/Application.Domain/Services/Interface/Task/IGameTaskService.cs new file mode 100644 index 0000000..2749dcc --- /dev/null +++ b/Service/Application.Domain/Services/Interface/Task/IGameTaskService.cs @@ -0,0 +1,21 @@ +namespace Application.Domain; + +public interface IGameTaskService +{ + #region 任务基础 + + Task GetTaskInfo(int taskId); + Task> GetTaskDataByNpc(string userId, int npcId); + Task GetTaskItemInfo(int itemId); + + #endregion + + #region 个人任务 + + Task GetUserTaskInfo(string userId, int taskId); + Task UpdateUserTaskInfo(string userId, int itemId); + Task GetUserTaskCount(string userId, int taskId); + Task GetUserTaskModel(string userId, game_task_item task); + + #endregion +} \ No newline at end of file diff --git a/Service/Application.Domain/Services/Service/Fight/GameFightService.cs b/Service/Application.Domain/Services/Service/Fight/GameFightService.cs index 7eca3ee..94b4ef6 100644 --- a/Service/Application.Domain/Services/Service/Fight/GameFightService.cs +++ b/Service/Application.Domain/Services/Service/Fight/GameFightService.cs @@ -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(); + await monsterService.RemoveCreateMonster(fightData.keyId); + } + foreach (var item in data) { await ClearFightInfoCache(item.fightId, item.keyId, true); diff --git a/Service/Application.Domain/Services/Service/Map/GameMapService.cs b/Service/Application.Domain/Services/Service/Map/GameMapService.cs index a75aaa8..cd7acfa 100644 --- a/Service/Application.Domain/Services/Service/Map/GameMapService.cs +++ b/Service/Application.Domain/Services/Service/Map/GameMapService.cs @@ -119,6 +119,40 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame return data; } + public async Task> GetMapNpcModel(string userId, string mapId, int areaId) + { + var taskService = App.GetService(); + List result = new List(); + 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 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(onLine).ExecuteCommandAsync(); } } + public async Task UpdateUserOnMap(string userId, string ip, string mapId) { unit_user_online onLine = new unit_user_online(); diff --git a/Service/Application.Domain/Services/Service/Monster/GameMonsterService.cs b/Service/Application.Domain/Services/Service/Monster/GameMonsterService.cs index f58e2d0..fc7c8f3 100644 --- a/Service/Application.Domain/Services/Service/Monster/GameMonsterService.cs +++ b/Service/Application.Domain/Services/Service/Monster/GameMonsterService.cs @@ -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(); - var data = await db.Queryable().Where(it => it.mapId == mapId).ToListAsync(); + var data = await db.Queryable().Where(it => it.mapId == mapId && it.state == 0) + .ToListAsync(); await redis.AddHashAsync(key, mapId, data); return data; } - + public async Task GetCreateMonsterInfo(string umId) { var db = DbClient.AsTenant().GetConnectionWithAttr(); @@ -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 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 RemoveCreateMonster(unit_user_monster data) { var db = DbClient.AsTenant().GetConnectionWithAttr(); - bool result = await db.Deleteable().Where(it => it.umId == data.umId).ExecuteCommandAsync()>0; + bool result = await db.Updateable() + .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> 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 GetMonsterAttrModel(string keyId,string monsterId) + public async Task 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(); var loadState = await attrService.GetUserLoadState(keyId); @@ -293,6 +296,7 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I return temp; } + private async Task GetMonsterBlood(string keyId, int maxBlood) { int blood = maxBlood; diff --git a/Service/Application.Domain/Services/Service/Task/GameTaskService.cs b/Service/Application.Domain/Services/Service/Task/GameTaskService.cs new file mode 100644 index 0000000..08c3d94 --- /dev/null +++ b/Service/Application.Domain/Services/Service/Task/GameTaskService.cs @@ -0,0 +1,318 @@ +namespace Application.Domain; + +public class GameTaskService(ISqlSugarClient DbClient, IRedisCache redis) : IGameTaskService, ITransient +{ + #region 任务基础 + + public async Task GetTaskInfo(int taskId) + { + string key = string.Format(BaseCache.BaseCacheKeys, "TaskCache", "TaskInfo"); + if (await redis.HExistsHashAsync(key, taskId.ToString())) + { + return await redis.GetHashAsync(key, taskId.ToString()); + } + + var db = DbClient.AsTenant().GetConnectionWithAttr(); + var data = await db.Queryable().Where(it => it.taskId == taskId).SingleAsync(); + await redis.AddHashAsync(key, taskId.ToString(), data); + return data; + } + + public async Task> GetTaskDataByNpc(string userId, int npcId) + { + List data = new List(); + List result = new List(); + string key = string.Format(BaseCache.BaseCacheKeys, "TaskCache", "NpcTask"); + if (await redis.HExistsHashAsync(key, npcId.ToString())) + { + data = await redis.GetHashAsync>(key, npcId.ToString()); + } + else + { + var db = DbClient.AsTenant().GetConnectionWithAttr(); + data = await db.Queryable().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 GetTaskItemInfo(int itemId) + { + string key = string.Format(BaseCache.BaseCacheKeys, "TaskCache", "TaskItemInfo"); + if (await redis.HExistsHashAsync(key, itemId.ToString())) + { + return await redis.GetHashAsync(key, itemId.ToString()); + } + + var db = DbClient.AsTenant().GetConnectionWithAttr(); + var data = await db.Queryable().Where(it => it.tiId == itemId).SingleAsync(); + await redis.AddHashAsync(key, itemId.ToString(), data); + return data; + } + + #endregion + + #region 个人任务 + + public async 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(key, utId); + } + + var db = DbClient.AsTenant().GetConnectionWithAttr(); + var data = await db.Queryable().Where(it => it.utId == utId).SingleAsync(); + await redis.AddHashAsync(key, utId, data); + + return data; + } + + public async Task 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(); + result = await db.Deleteable().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(); + 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(); + 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 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(key, utId); + } + + var db = DbClient.AsTenant().GetConnectionWithAttr(); + var data = await db.Queryable().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(); + 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 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(); + 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 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 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 +} \ No newline at end of file diff --git a/Service/Application.Domain/Tool/Base/GameBus.cs b/Service/Application.Domain/Tool/Base/GameBus.cs index 30a3d8b..c6f0e21 100644 --- a/Service/Application.Domain/Tool/Base/GameBus.cs +++ b/Service/Application.Domain/Tool/Base/GameBus.cs @@ -101,6 +101,24 @@ public static class GameBus #region 验证 + public static async Task CheckNeed(string userId, dynamic data, int count = 1) + { + List needs = new List(); + foreach (var item in data) + { + needs.Add(new TowerNeed() + { + code = Convert.ToString(item.code), + name = Convert.ToString(item.name), + parameter = Convert.ToString(item.parameter), + count = Convert.ToInt64(item.count), + retCount = Convert.ToInt64(item.retCount) + }); + } + + return await CheckNeed(userId, needs, count); + } + public static async Task CheckNeed(string userId, TowerNeed item, int count = 1) { CheckTowerNeed result = new CheckTowerNeed(); @@ -219,23 +237,23 @@ public static class GameBus int isGive = 1; foreach (var item in needs) { - var cheakResult = await CheckNeed(userId, item, count); + var checkResult = await CheckNeed(userId, item, count); if (isok) { - isok = cheakResult.result; + isok = checkResult.result; } - if (cheakResult.isDeal == 0) + if (checkResult.isDeal == 0) { isDeal = 0; } - if (cheakResult.isGive == 0) + if (checkResult.isGive == 0) { isGive = 0; } - result.Needs.AddRange(cheakResult.Needs); + result.Needs.AddRange(checkResult.Needs); } result.result = isok; diff --git a/Service/Application.Web/Controllers/Map/MapBusController.cs b/Service/Application.Web/Controllers/Map/MapBusController.cs index 5d9649a..fead8a2 100644 --- a/Service/Application.Web/Controllers/Map/MapBusController.cs +++ b/Service/Application.Web/Controllers/Map/MapBusController.cs @@ -10,10 +10,11 @@ namespace Application.Web.Controllers.Map; public class MapBusController : ControllerBase { private readonly IGameMapService _mapService; - - public MapBusController(IGameMapService mapService) + private readonly IMessageService _messageService; + public MapBusController(IGameMapService mapService,IMessageService messageService) { _mapService = mapService; + _messageService = messageService; } /// @@ -102,4 +103,66 @@ public class MapBusController : ControllerBase return PoAction.Message("操作失败,请稍后尝试!"); } } + + /// + /// 打开宝箱 + /// + /// + /// + [HttpGet] + public async Task MapBusBox(int id) + { + string userId = StateHelper.userId; + var busData = await _mapService.GetMapBusInfo(id); + if (busData == null) + { + return PoAction.Message("业务不存在!"); + } + + if (busData.busType != "Box") + { + return PoAction.Message("业务不存在!"); + } + + var onMap = await _mapService.GetUserOnMapId(userId); + if (busData.busCode != onMap) + { + return PoAction.Message("业务不存在!"); + } + + var checkResult = await GameBus.CheckNeed(userId, busData.busNeed, 1); + if (checkResult.result==false) + { + return PoAction.Message("不满足开启要求!"); + } + + if (await GameBus.UpdateBag(userId, 0, busData.busNeed, "业务传送")) + { + string message = ""; + var park = JsonConvert.DeserializeObject(busData.busContent); + var award = GameBus.GetRandomGoods(park); + if (award.Count > 0) + { + message = $"开启了[{park.name}],获得:"; + foreach (var item in award) + { + message += $"{item.name}+{item.count},"; + } + + message = message.TrimEnd(','); + await GameBus.UpdateBag(userId, 1, award, $"开启:{park.name}获得"); + + await _messageService.SendBroadcast(userId, nameof(MessageEnum.BroadcastCode.Award), message); + } + else + { + message = "空空如也,什么也没有得到!"; + } + return PoAction.Ok(true,message); + } + else + { + return PoAction.Message("操作失败,请稍后尝试!"); + } + } } \ No newline at end of file diff --git a/Service/Application.Web/Controllers/Map/MapController.cs b/Service/Application.Web/Controllers/Map/MapController.cs index 161bbc5..c310e03 100644 --- a/Service/Application.Web/Controllers/Map/MapController.cs +++ b/Service/Application.Web/Controllers/Map/MapController.cs @@ -1,5 +1,4 @@ -using Microsoft.AspNetCore.Mvc; - + namespace Application.Web.Controllers.Map; /// @@ -24,12 +23,13 @@ public class MapController : ControllerBase private readonly IGameMonsterService _monsterService; private readonly IGameFightService _fightService; private readonly IOnHookService _hookService; + private readonly IGameTaskService _taskService; public MapController(IUnitUserService userService, IGameMapService mapService, IGameChatService chatService, IUnitUserAttrService attrService, IMessageService messageService, IUnitUserWeight weightService, IUnitUserAccService accService, IGameSkillService skillService, IGameGoodsService goodsService, IGameTeamService teamService, IGameMonsterService monsterService, IGameFightService fightService, - IOnHookService hookService) + IOnHookService hookService, IGameTaskService taskService) { _userService = userService; _mapService = mapService; @@ -44,6 +44,7 @@ public class MapController : ControllerBase _monsterService = monsterService; _fightService = fightService; _hookService = hookService; + _taskService = taskService; } #region 地图相关 @@ -106,8 +107,7 @@ public class MapController : ControllerBase var chatData = await _chatService.GetChatTop(userId, area, 2, teamId, groupId); - var npcData = await _mapService.GetMapNpc(mapInfo.mapId); //NPC信息 - npcData = npcData.FindAll(it => GameTool.AreaVerify(StateHelper.areaId, it.areaId)); + var npcData = await _mapService.GetMapNpcModel(userId, mapInfo.mapId, area); //NPC信息 //获取怪物 var monsterData = await _monsterService.GetMapMonster(userId, mapInfo.mapId, teamId); @@ -668,7 +668,13 @@ public class MapController : ControllerBase return PoAction.Message("Npc不存在!"); } - return PoAction.Ok(data); + List task = new List(); + if (data.code == nameof(MapEnum.NpcCode.Task)) + { + task = await _taskService.GetTaskDataByNpc(userId, npcId); + } + + return PoAction.Ok(new { data, task }); } #endregion diff --git a/Service/Application.Web/Controllers/Map/TaskController.cs b/Service/Application.Web/Controllers/Map/TaskController.cs new file mode 100644 index 0000000..c851694 --- /dev/null +++ b/Service/Application.Web/Controllers/Map/TaskController.cs @@ -0,0 +1,298 @@ +using Newtonsoft.Json; + +namespace Application.Web.Controllers.Map; + +/// +/// 任务接口 +/// +[ApiExplorerSettings(GroupName = "Map")] +[Route("Map/[controller]/[action]")] +[ApiController] +[Authorize] +public class TaskController : ControllerBase +{ + private readonly IGameMapService _mapService; + private readonly IGameTaskService _taskService; + private readonly IGameGoodsService _goodsService; + + public TaskController(IGameMapService mapService, IGameTaskService taskService, IGameGoodsService goodsService) + { + _mapService = mapService; + _taskService = taskService; + _goodsService = goodsService; + } + + /// + /// 获取NPC任务 + /// + /// + /// + [HttpGet] + public async Task GetTaskByNpc(int npcId, int taskId) + { + string userId = StateHelper.userId; + int areaId = StateHelper.areaId; + var npcInfo = await _mapService.GetNpcInfo(npcId); + if (npcInfo == null) + { + return PoAction.Message("Npc不存在!"); + } + + if (npcInfo.status != 1) + { + return PoAction.Message("Npc不存在!"); + } + + if (npcInfo.code != nameof(MapEnum.NpcCode.Task)) + { + return PoAction.Message("Npc错误!"); + } + + if (GameTool.AreaVerify(areaId, npcInfo.areaId) == false) + { + return PoAction.Message("Npc不存在!"); + } + + var onMap = await _mapService.GetUserOnMapId(userId); + if (npcInfo.mapId != onMap) + { + return PoAction.Message("Npc不存在!"); + } + + var taskInfo = await _taskService.GetTaskItemInfo(taskId); + if (taskInfo == null) + { + return PoAction.Message("任务不存在!"); + } + + if (taskInfo.npcId != npcId) + { + return PoAction.Message("任务不存在!"); + } + + string talkMsg = taskInfo.taskTips; + int taskState = 1; + var userOnTask = await _taskService.GetUserTaskInfo(userId, (int)taskInfo.taskId); + if (userOnTask != null) + { + if (userOnTask.itemId == taskId) + { + var nextInfo = await _taskService.GetTaskItemInfo(taskId + 1); + if (taskInfo == null) + { + taskState = 100; + } + else + { + talkMsg = taskInfo.nextTips; + taskInfo = nextInfo; + taskState = taskInfo.npcId == npcId ? 1 : 2; + } + } + } + + var data = await _taskService.GetUserTaskModel(userId, taskInfo); + if (data.state == -1) + { + return PoAction.Message("任务不存在!"); + } + + int toGoods = await _goodsService.GetUserGoodsCount(userId, GameConfig.GameGetTaskGoods); + int retGoods = await _goodsService.GetUserGoodsCount(userId, GameConfig.GameRetTaskGoods); + return PoAction.Ok(new + { npc = npcInfo, data = data, talkMsg, taskState, btnTips = taskInfo.btnTips, toGoods, retGoods }); + } + + /// + /// 完成任务 + /// + /// + /// + /// + [HttpGet] + public async Task OverTask(int npcId, int taskId) + { + string userId = StateHelper.userId; + int areaId = StateHelper.areaId; + var npcInfo = await _mapService.GetNpcInfo(npcId); + if (npcInfo == null) + { + return PoAction.Message("Npc不存在!"); + } + + if (npcInfo.status != 1) + { + return PoAction.Message("Npc不存在!"); + } + + if (npcInfo.code != nameof(MapEnum.NpcCode.Task)) + { + return PoAction.Message("Npc错误!"); + } + + if (GameTool.AreaVerify(areaId, npcInfo.areaId) == false) + { + return PoAction.Message("Npc不存在!"); + } + + var onMap = await _mapService.GetUserOnMapId(userId); + if (npcInfo.mapId != onMap) + { + return PoAction.Message("Npc不存在!"); + } + + var taskInfo = await _taskService.GetTaskItemInfo(taskId); + if (taskInfo == null) + { + return PoAction.Message("任务不存在!"); + } + + if (taskInfo.npcId != npcId) + { + return PoAction.Message("任务不存在!"); + } + + var checkTask = await _taskService.GetUserTaskModel(userId, taskInfo); + if (checkTask.state == -1) + { + return PoAction.Message("任务不存在!"); + } + + if (checkTask.result.result) + { + if (await GameBus.UpdateBag(userId, 0, taskInfo.needData, "完成任务")) + { + if (await _taskService.UpdateUserTaskInfo(userId, taskId)) + { + string message = string.Empty; + if (!string.IsNullOrEmpty(taskInfo.award)) + { + message = "任务完成,获得:"; + List award = JsonConvert.DeserializeObject>(taskInfo.award); + foreach (var item in award) + { + message += $"{item.name}+{item.count},"; + } + + message = message.TrimEnd(','); + } + + return PoAction.Ok(true, message); + } + else + { + return PoAction.Message("任务操作失败,请稍后尝试!"); + } + } + else + { + return PoAction.Message("任务完成失败,请稍后尝试!"); + } + } + else + { + return PoAction.Message("不满足任务条件!"); + } + } + + /// + /// 物品道具点传送 + /// + /// + /// + /// + [HttpGet] + public async Task NeedMapTo(int task, int num) + { + string userId = StateHelper.userId; + var taskInfo = await _taskService.GetTaskItemInfo(task); + + var checkTask = await _taskService.GetUserTaskModel(userId, taskInfo); + if (checkTask.state == -1) + { + return PoAction.Message("无法传送!"); + } + + var toData = taskInfo.needData[num]; + if (string.IsNullOrEmpty(toData.mapId)) + { + return PoAction.Message("该任务要求不提供传送!"); + } + + var goodsCount = await _goodsService.GetUserGoodsCount(userId, GameConfig.GameGetTaskGoods); + if (goodsCount < 1) + { + return PoAction.Message("暂无引路蜂!"); + } + + if (await _goodsService.UpdateUserGoods(userId, 0, GameConfig.GameGetTaskGoods, 1, "传送")) + { + var ResultMap = await _mapService.GetToMapInfo(userId, toData.mapId, true, true); + if (ResultMap != null) + { + return PoAction.Ok(true); + } + else + { + return PoAction.Message("传送失败,请稍后尝试!"); + } + } + else + { + return PoAction.Message("传送失败,请稍后尝试!"); + } + } + + /// + /// 任务提交传送 + /// + /// + /// + [HttpGet] + public async Task ReturnTask(int task) + { + string userId = StateHelper.userId; + var taskInfo = await _taskService.GetTaskItemInfo(task); + + var checkTask = await _taskService.GetUserTaskModel(userId, taskInfo); + if (checkTask.state == -1) + { + return PoAction.Message("无法传送!"); + } + + if (checkTask.result.result == false) + { + return PoAction.Message("任务未完成,无法传送!"); + } + + + var npcInfo = await _mapService.GetNpcInfo((int)taskInfo.npcId); + if (npcInfo == null) + { + return PoAction.Message("任务地点不存在!"); + } + + var goodsCount = await _goodsService.GetUserGoodsCount(userId, GameConfig.GameRetTaskGoods); + if (goodsCount < 1) + { + return PoAction.Message("暂无领路蝶!"); + } + + if (await _goodsService.UpdateUserGoods(userId, 0, GameConfig.GameRetTaskGoods, 1, "传送")) + { + var ResultMap = await _mapService.GetToMapInfo(userId, npcInfo.mapId, true, true); + if (ResultMap != null) + { + return PoAction.Ok(true); + } + else + { + return PoAction.Message("传送失败,请稍后尝试!"); + } + } + else + { + return PoAction.Message("传送失败,请稍后尝试!"); + } + } +} \ No newline at end of file diff --git a/Service/Application.Web/Controllers/Pub/PubController.cs b/Service/Application.Web/Controllers/Pub/PubController.cs index a760885..17673d8 100644 --- a/Service/Application.Web/Controllers/Pub/PubController.cs +++ b/Service/Application.Web/Controllers/Pub/PubController.cs @@ -44,8 +44,6 @@ namespace Application.Web.Controllers.Pub account.pwd = ""; account.npwd = ""; account.token = ""; - account.openId = ""; - isOnline = true; userData = await _userService.GetUserDataByAccId(account.accId); } diff --git a/Web/public/images/site/tg.gif b/Web/public/images/site/tg.gif new file mode 100644 index 0000000..623db82 Binary files /dev/null and b/Web/public/images/site/tg.gif differ diff --git a/Web/public/images/site/tr.gif b/Web/public/images/site/tr.gif new file mode 100644 index 0000000..cb1963f Binary files /dev/null and b/Web/public/images/site/tr.gif differ diff --git a/Web/src/components/Business/GamePopup.vue b/Web/src/components/Business/GamePopup.vue index 5feba96..c8e3374 100644 --- a/Web/src/components/Business/GamePopup.vue +++ b/Web/src/components/Business/GamePopup.vue @@ -42,6 +42,7 @@ const visible = ref(props.isShow) position: relative; padding: 18px 20px; text-align: center; + min-width: 150px; } /* 标题文字 */ diff --git a/Web/src/components/Business/GameTaskPropVerify.vue b/Web/src/components/Business/GameTaskPropVerify.vue new file mode 100644 index 0000000..b9e25b7 --- /dev/null +++ b/Web/src/components/Business/GameTaskPropVerify.vue @@ -0,0 +1,32 @@ + + \ No newline at end of file diff --git a/Web/src/pages/index.vue b/Web/src/pages/index.vue index 461dd5a..992aecc 100644 --- a/Web/src/pages/index.vue +++ b/Web/src/pages/index.vue @@ -119,7 +119,7 @@ const Initialize = async (): Promise => { areaData.value = result.data?.area; noticeData.value = result.data.notice; OnCount.value = result.data.onCount; - AccountInfo.value = result.data.account; + AccountInfo.value = result.data.account; userData.value = result.data.userData; } else { diff --git a/Web/src/pages/map/business.vue b/Web/src/pages/map/business.vue index 60b33e9..4d3a590 100644 --- a/Web/src/pages/map/business.vue +++ b/Web/src/pages/map/business.vue @@ -14,7 +14,13 @@
- 222 +
+ 开启要求:
+ +
+
+ 立即开启 +
\ No newline at end of file diff --git a/Web/src/pages/map/index.vue b/Web/src/pages/map/index.vue index 68c1042..ba94e1a 100644 --- a/Web/src/pages/map/index.vue +++ b/Web/src/pages/map/index.vue @@ -1,6 +1,6 @@ \ No newline at end of file diff --git a/Web/src/services/map/MapBusService.ts b/Web/src/services/map/MapBusService.ts index 26c7ebd..4fb5785 100644 --- a/Web/src/services/map/MapBusService.ts +++ b/Web/src/services/map/MapBusService.ts @@ -14,4 +14,12 @@ export class MapBusService { static async MapBusTo(id: number, num: number) { return await ApiService.Request("get", "/Map/MapBus/MapBusTo", { id, num }); } + + /** + * 打开宝箱 + * GET /Map/MapBus/MapBusBox + */ + static async MapBusBox(id: number) { + return await ApiService.Request("get", "/Map/MapBus/MapBusBox", { id }); + } } \ No newline at end of file diff --git a/Web/src/services/map/TaskService.ts b/Web/src/services/map/TaskService.ts new file mode 100644 index 0000000..38c82ac --- /dev/null +++ b/Web/src/services/map/TaskService.ts @@ -0,0 +1,33 @@ +export class TaskService { + /** + * 获取NPC任务 + * GET /Map/Task/GetTaskByNpc + */ + static async GetTaskByNpc(npcId: number, taskId: number) { + return await ApiService.Request("get", "/Map/Task/GetTaskByNpc", { npcId, taskId }); + } + + /** + * 完成任务 + * GET /Map/Task/OverTask + */ + static async OverTask(npcId: number, taskId: number) { + return await ApiService.Request("get", "/Map/Task/OverTask", { npcId, taskId }); + } + + /** + * 物品道具点传送 + * GET /Map/Task/NeedMapTo + */ + static async NeedMapTo(task: number, num: number) { + return await ApiService.Request("get", "/Map/Task/NeedMapTo", { task, num }); + } + + /** + * 任务提交传送 + * GET /Map/Task/ReturnTask + */ + static async ReturnTask(task: number) { + return await ApiService.Request("get", "/Map/Task/ReturnTask", { task }); + } +} \ No newline at end of file