R2G_LiveCommentHandler.cs 2.1 KB

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