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("操作失败,请稍后尝试!");
}
}
}