C2G_BattleNotifyHandler.cs 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.Json;
  5. namespace ET.Server
  6. {
  7. /// <summary>
  8. /// 向战斗服发送特定消息(触发编辑器事件)
  9. /// </summary>
  10. [MessageHandler(SceneType.Game)]
  11. [FriendOfAttribute(typeof(ET.Server.GameMapComponent))]
  12. public class C2G_BattleNotifyHandler : AMRpcHandler<C2G_BattleNotify, G2C_BattleNotify>
  13. {
  14. protected override async ETTask Run(Session session, C2G_BattleNotify request, G2C_BattleNotify response, Action reply)
  15. {
  16. WNPlayer player = session.GetComponent<SessionPlayerComponent>().GetMyPlayer();
  17. if (player == null)
  18. {
  19. Log.Debug($"操作错误, player is null");
  20. response.Error = ErrorCode.ERR_OperationError;
  21. reply();
  22. return;
  23. }
  24. // 判断参数
  25. if (string.IsNullOrEmpty(request.Message))
  26. {
  27. Log.Debug($"参数错误, request.NameType={request.Message}");
  28. response.Error = ErrorCode.ERR_ParameterError;
  29. reply();
  30. return;
  31. }
  32. //客户端测试功能
  33. if (request.Message.StartsWith("test:"))
  34. {
  35. var map = player.Map;
  36. var players = map.UnitPlayers.Values.ToArray();
  37. var rand = new Random();
  38. var randunit = players[rand.Next(players.Length)];
  39. long roomId = 0;
  40. var maphash = GameMapComponent.Instance.rooms;
  41. foreach ( var rid in maphash.Keys )
  42. {
  43. if (maphash[rid] == map.Id)
  44. {
  45. roomId = rid;
  46. break;
  47. }
  48. }
  49. long instanceid = 0;
  50. List<StartSceneConfig> list = RealmGateAddressHelper.GetAllGame(1);
  51. foreach (StartSceneConfig config in list.Where(config => config is { Id: 10001 }))
  52. {
  53. instanceid = config.InstanceId;
  54. break;
  55. }
  56. var funcIndex = int.Parse(request.Message[5..]);
  57. if (funcIndex == 7)
  58. {
  59. MessageHelper.SendActor(instanceid, new R2G_LiveLike() { OpenId = randunit.OpenId, RoomId = roomId, NickName = randunit.Name, Url = randunit.Url, Likes = 10 });
  60. }
  61. else
  62. {
  63. string[] GIFT = { DouyinItem.GiftId_1, DouyinItem.GiftId_10, DouyinItem.GiftId_52, DouyinItem.GiftId_99, DouyinItem.GiftId_199, DouyinItem.GiftId_520 };
  64. int cnt = 1;
  65. switch(funcIndex)
  66. {
  67. case 1:
  68. cnt = (int)Math.Sqrt(rand.Next(1, 100));
  69. break;
  70. case 2:
  71. cnt = rand.Next(1, 10);
  72. break;
  73. }
  74. MessageHelper.SendActor(instanceid, new R2G_LiveGift() { OpenId = randunit.OpenId, RoomId = roomId, NickName = randunit.Name, Url = randunit.Url, GiftId = GIFT[funcIndex-1], GiftNum = cnt, GiftValue = funcIndex * 80 });
  75. }
  76. return;
  77. }
  78. // 通知战斗服
  79. player.GetXmdsManager().notifyBattleServer(player.Map.Id.ToString(), NotifyBSName.TriggerEvent, JsonSerializer.Serialize(new Struct.TriggerEventNotify() { message = request.Message }));
  80. reply();
  81. await ETTask.CompletedTask;
  82. }
  83. }
  84. }