1111
This commit is contained in:
117
Service/Application.Web/Controllers/Chat/ChatController.cs
Normal file
117
Service/Application.Web/Controllers/Chat/ChatController.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Application.Web.Controllers.Chat;
|
||||
|
||||
/// <summary>
|
||||
/// 公聊接口
|
||||
/// </summary>
|
||||
[Route("Chat/[controller]/[action]")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class ChatController : ControllerBase
|
||||
{
|
||||
private readonly IGameChatService _chatService;
|
||||
|
||||
public ChatController(IGameChatService chatService)
|
||||
{
|
||||
_chatService = chatService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取公聊信息
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> GetChatData(int type, int page)
|
||||
{
|
||||
int areaId = StateHelper.areaId;
|
||||
string teamId = "";
|
||||
string groupId = "";
|
||||
RefAsync<int> Total = 0;
|
||||
var data = await _chatService.GetChatData(type, areaId, teamId, groupId, page, 10, Total);
|
||||
//物品数量
|
||||
int sendGoodsCount = 0;
|
||||
string sendGoodsName = "";
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
sendGoodsCount = 199;
|
||||
sendGoodsName = "小海螺";
|
||||
break;
|
||||
case 3:
|
||||
sendGoodsCount = 15;
|
||||
sendGoodsName = "大海螺";
|
||||
break;
|
||||
case 4:
|
||||
sendGoodsCount = 9;
|
||||
sendGoodsName = "金海螺";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return PoAction.Ok(new { data, total = Total.Value ,sendGoodsCount,sendGoodsName});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发言
|
||||
/// </summary>
|
||||
/// <param name="pars"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IPoAction> SendChat([FromBody] SendChatParms pars)
|
||||
{
|
||||
if (string.IsNullOrEmpty(pars.sign))
|
||||
{
|
||||
return PoAction.Message("发言内容不能为空!");
|
||||
}
|
||||
|
||||
string userId = StateHelper.userId;
|
||||
int areaId = StateHelper.areaId;
|
||||
string par = string.Empty;
|
||||
string code = GameChatEnum.Code.Public.ToString();
|
||||
bool isSend = false;
|
||||
switch (pars.type)
|
||||
{
|
||||
case 0:
|
||||
isSend = true;
|
||||
code =nameof(GameChatEnum.Code.Public);
|
||||
break;
|
||||
case 1:
|
||||
isSend = true;
|
||||
code = nameof(GameChatEnum.Code.Team);
|
||||
par = "";
|
||||
break;
|
||||
case 2:
|
||||
isSend = true;
|
||||
code = nameof(GameChatEnum.Code.Group);
|
||||
par="";
|
||||
break;
|
||||
case 3:
|
||||
isSend = true;
|
||||
code = nameof(GameChatEnum.Code.Region);
|
||||
break;
|
||||
case 4:
|
||||
isSend = true;
|
||||
code = nameof(GameChatEnum.Code.Dress);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (isSend == false)
|
||||
{
|
||||
return PoAction.Message("无法发言!");
|
||||
}
|
||||
string sign = StringAssist.NoHTML(pars.sign);
|
||||
bool result = await _chatService.SendChat(userId, areaId, code, sign, par);
|
||||
if (result)
|
||||
{
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("发送失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,11 +13,13 @@ public class MapController : ControllerBase
|
||||
{
|
||||
private readonly IUnitUserService _userService;
|
||||
private readonly IGameMapService _mapService;
|
||||
private readonly IGameChatService _chatService;
|
||||
|
||||
public MapController(IUnitUserService userService, IGameMapService mapService)
|
||||
public MapController(IUnitUserService userService, IGameMapService mapService, IGameChatService chatService)
|
||||
{
|
||||
_userService = userService;
|
||||
_mapService = mapService;
|
||||
_chatService = chatService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -29,6 +31,7 @@ public class MapController : ControllerBase
|
||||
public async Task<IPoAction> GetMapData(string? map)
|
||||
{
|
||||
string userId = StateHelper.userId;
|
||||
int area = StateHelper.areaId;
|
||||
var onMap = await _mapService.GetUserOnMap(userId);
|
||||
game_city_map mapInfo = new game_city_map();
|
||||
if (string.IsNullOrEmpty(map))
|
||||
@@ -40,10 +43,14 @@ public class MapController : ControllerBase
|
||||
mapInfo = await _mapService.GetMapInfo(map);
|
||||
}
|
||||
|
||||
//公聊信息
|
||||
string teamId = "";
|
||||
string groupId = "";
|
||||
var chatData = await _chatService.GetChatTop(area, 2, teamId, groupId);
|
||||
//NPC信息
|
||||
|
||||
|
||||
var npcData = await _mapService.GetMapNpc(mapInfo.mapId);
|
||||
npcData = npcData.FindAll(it => GameTool.AreaVerify(StateHelper.areaId,it.areaId));
|
||||
npcData = npcData.FindAll(it => GameTool.AreaVerify(StateHelper.areaId, it.areaId));
|
||||
//城市信息
|
||||
var cityInfo = await _mapService.GetCityInfo((int)mapInfo.cityId);
|
||||
|
||||
@@ -54,7 +61,7 @@ public class MapController : ControllerBase
|
||||
|
||||
#endregion
|
||||
|
||||
object ret = new { mapInfo, cityInfo, npcData };
|
||||
object ret = new { mapInfo, cityInfo, npcData, chatData };
|
||||
|
||||
return PoAction.Ok(ret);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user