168 lines
5.1 KiB
C#
168 lines
5.1 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Application.Web.Controllers.Map;
|
|
|
|
[ApiExplorerSettings(GroupName = "Map")]
|
|
[Route("Map/[controller]/[action]")]
|
|
[ApiController]
|
|
[Authorize]
|
|
public class MapBusController : ControllerBase
|
|
{
|
|
private readonly IGameMapService _mapService;
|
|
private readonly IMessageService _messageService;
|
|
public MapBusController(IGameMapService mapService,IMessageService messageService)
|
|
{
|
|
_mapService = mapService;
|
|
_messageService = messageService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取业务信息
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> GetBusiness(int id)
|
|
{
|
|
string userId = StateHelper.userId;
|
|
var busData = await _mapService.GetMapBusInfo(id);
|
|
if (busData == null)
|
|
{
|
|
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);
|
|
return PoAction.Ok(new { data = busData, result = checkResult });
|
|
}
|
|
|
|
/// <summary>
|
|
/// 传送
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="num"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> MapBusTo(int id, int num)
|
|
{
|
|
string userId = StateHelper.userId;
|
|
var busData = await _mapService.GetMapBusInfo(id);
|
|
if (busData == null)
|
|
{
|
|
return PoAction.Message("业务不存在!");
|
|
}
|
|
|
|
if (busData.busType != "ToMap")
|
|
{
|
|
return PoAction.Message("业务不存在!");
|
|
}
|
|
|
|
var toData = JsonConvert.DeserializeObject<List<MapBusTo> >(busData.busContent);
|
|
if (num > (toData.Count - 1))
|
|
{
|
|
return PoAction.Message("业务不存在!");
|
|
}
|
|
var onMap = await _mapService.GetUserOnMapId(userId);
|
|
if (busData.busCode != onMap)
|
|
{
|
|
return PoAction.Message("业务不存在!");
|
|
}
|
|
var mapToData = toData[num];
|
|
if (TimeAssist.GetHourNum < mapToData.sTime || TimeAssist.GetHourNum > mapToData.eTime)
|
|
{
|
|
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, "业务传送"))
|
|
{
|
|
var ResultMap = await _mapService.GetToMapInfo(userId, mapToData.mapId, true, true);
|
|
if (ResultMap != null)
|
|
{
|
|
return PoAction.Ok(true);
|
|
}
|
|
else
|
|
{
|
|
return PoAction.Message("操作失败,请稍后尝试!");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
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("操作失败,请稍后尝试!");
|
|
}
|
|
}
|
|
} |