R2G_LiveCommentHandler.cs 2.0 KB

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