R2G_LiveCommentHandler.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. string[] pos = map.GetCurXY().Split(";");
  51. Random rand = new Random();
  52. float r = (float)Math.Sqrt(rand.Next(2304)) + 12;
  53. double ang = rand.Next(40) / 180.0f * Math.PI + Math.PI/2.0f + Math.PI;
  54. float x = int.Parse(pos[0]) + (float)(r * Math.Cos(ang));
  55. float y = int.Parse(pos[1]) - (float)(r * Math.Sin(ang));
  56. Struct.MonsterUnit unit = new Struct.MonsterUnit();
  57. unit.id = templateId;
  58. unit.force = 1;
  59. unit.x = (int)x;
  60. unit.y = (int)y;
  61. unit.autoGuard = true;
  62. int objId = await map.AddUnits(unit, true);
  63. map.AddUnitPlayer(request.OpenId, templateId, objId, 0);
  64. await ETTask.CompletedTask;
  65. }
  66. }
  67. }