This commit is contained in:
Putoo
2026-07-09 22:46:28 +08:00
parent 010ca90575
commit cfe6612a7a
33 changed files with 1355 additions and 39 deletions

View File

@@ -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;
}
/// <summary>
@@ -102,4 +103,66 @@ public class MapBusController : ControllerBase
return PoAction.Message("操作失败,请稍后尝试!");
}
}
/// <summary>
/// 打开宝箱
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> 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<RandomModel>(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("操作失败,请稍后尝试!");
}
}
}

View File

@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Mvc;
namespace Application.Web.Controllers.Map;
/// <summary>
@@ -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<UserTaskModel> task = new List<UserTaskModel>();
if (data.code == nameof(MapEnum.NpcCode.Task))
{
task = await _taskService.GetTaskDataByNpc(userId, npcId);
}
return PoAction.Ok(new { data, task });
}
#endregion

View File

@@ -0,0 +1,298 @@
using Newtonsoft.Json;
namespace Application.Web.Controllers.Map;
/// <summary>
/// 任务接口
/// </summary>
[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;
}
/// <summary>
/// 获取NPC任务
/// </summary>
/// <param name="npcId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> 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 });
}
/// <summary>
/// 完成任务
/// </summary>
/// <param name="npcId"></param>
/// <param name="taskId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> 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<TowerGet> award = JsonConvert.DeserializeObject<List<TowerGet>>(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("不满足任务条件!");
}
}
/// <summary>
/// 物品道具点传送
/// </summary>
/// <param name="task"></param>
/// <param name="num"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> 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("传送失败,请稍后尝试!");
}
}
/// <summary>
/// 任务提交传送
/// </summary>
/// <param name="task"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> 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("传送失败,请稍后尝试!");
}
}
}

View File

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