12121
This commit is contained in:
298
Service/Application.Web/Controllers/Map/TaskController.cs
Normal file
298
Service/Application.Web/Controllers/Map/TaskController.cs
Normal 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("传送失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user