R2G_LiveCommentHandler.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.Numerics;
  3. namespace ET.Server
  4. {
  5. /// <summary>
  6. /// 抖音推送回调, 评论
  7. /// </summary>
  8. [ActorMessageHandler(SceneType.Game)]
  9. public class R2G_LiveCommentHandler: AMActorHandler<Scene, R2G_LiveComment>
  10. {
  11. protected override async ETTask Run(Scene scene, R2G_LiveComment request)
  12. {
  13. if (string.IsNullOrEmpty(request.OpenId))
  14. {
  15. Log.Debug($"未找到openId...");
  16. return;
  17. }
  18. // 房间是否存在
  19. Map map = scene.GetComponent<GameMapComponent>().GetMapByRoomId(request.RoomId);
  20. if (map == null)
  21. {
  22. Log.Debug($"未找到房间...");
  23. return;
  24. }
  25. // 初始模板id
  26. int[] units = new int[] { 101, 121, 111, 131 };
  27. int templateId = 0;
  28. switch (request.Content)
  29. {
  30. case "0":
  31. // 随机
  32. templateId = RandomGenerator.RandomArray(units);
  33. break;
  34. case "1":
  35. // 蜜蜂
  36. templateId = units[0];
  37. break;
  38. case "2":
  39. // 花
  40. templateId = units[1];
  41. break;
  42. case "3":
  43. // 鸟
  44. templateId = units[2];
  45. break;
  46. case "4":
  47. // 蘑菇
  48. templateId = units[3];
  49. break;
  50. }
  51. Vector2 pos = map.GetRandomPlayerPos();
  52. Struct.MonsterUnit unit = new Struct.MonsterUnit();
  53. unit.id = templateId;
  54. unit.force = 1;
  55. unit.x = pos.X;
  56. unit.y = pos.Y;
  57. unit.autoGuard = true;
  58. unit.name = request.NickName;
  59. unit.alias = request.Url;
  60. int objId = await map.AddUnits(unit, true);
  61. map.AddUnitPlayer(request.OpenId, templateId, objId, 0, request.NickName, request.Url);
  62. await ETTask.CompletedTask;
  63. }
  64. }
  65. }