R2G_LiveGiftHandler.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System.Text.Json;
  2. namespace ET.Server
  3. {
  4. /// <summary>
  5. /// 抖音推送回调, 送礼物
  6. /// </summary>
  7. [ActorMessageHandler(SceneType.Game)]
  8. public class R2G_LiveGiftHandler: AMActorHandler<Scene, R2G_LiveGift>
  9. {
  10. protected override async ETTask Run(Scene scene, R2G_LiveGift request)
  11. {
  12. // 房间是否存在
  13. Map map = scene.GetComponent<GameMapComponent>().GetMapByRoomId(request.RoomId);
  14. if (map == null)
  15. {
  16. Log.Error($"未找到房间...roomId={request.RoomId}");
  17. return;
  18. }
  19. Struct.UnitPlayerData unitPlayerData = map.GetUnitPlayerData(request.OpenId);
  20. // 数据是否存在
  21. if (unitPlayerData == null)
  22. {
  23. Log.Error($"未找到单位玩家数据...openId={request.OpenId}");
  24. return;
  25. }
  26. unitPlayerData.GiftMoney += (int)request.GiftValue;
  27. // 推送客户端
  28. if (map.Player != null)
  29. {
  30. MessageHelper.SendToClient(map.Player, new G2C_GiftInfoPush { NickName = request.NickName, GiftType = DouyinItem.GiftHash[request.GiftId],
  31. GiftNum = (int)request.GiftNum, Url = "", TotalMoney = unitPlayerData.GiftMoney, UnitId = unitPlayerData.ObjId});
  32. }
  33. Struct.TriggerEventNotify notify = null;
  34. if (request.GiftId == DouyinItem.GiftId_1)
  35. {
  36. //TODO:复活合适的人
  37. map.GetXmdsManager().notifyBattleServer(map.Id.ToString(), NotifyBSName.TriggerEvent, JsonSerializer.Serialize(new Struct.TriggerEventNotify()
  38. {
  39. message = BattleNotify.TiktokGift_1.ToString(),
  40. TriggerUnits = unitPlayerData.ObjId.ToString()
  41. })) ;
  42. return;
  43. }
  44. else if(request.GiftId == DouyinItem.GiftId_10)
  45. {
  46. //TODO:复活合适的人
  47. map.GetXmdsManager().notifyBattleServer(map.Id.ToString(), NotifyBSName.TriggerEvent, JsonSerializer.Serialize(new Struct.TriggerEventNotify()
  48. {
  49. message = BattleNotify.TiktokGift_10.ToString(),
  50. TriggerUnits = unitPlayerData.ObjId.ToString()
  51. }));
  52. return;
  53. }
  54. for (int i = 0; i < request.GiftNum; i++)
  55. {
  56. switch (request.GiftId)
  57. {
  58. case DouyinItem.GiftId_52:
  59. // 甜甜圈
  60. const long maxLevel = 3; // 等级上限
  61. notify = new Struct.TriggerEventNotify();
  62. if (unitPlayerData.Level < maxLevel)
  63. {
  64. ++unitPlayerData.Level;
  65. notify.message = BattleNotify.TiktokGift_52.ToString();
  66. }
  67. else
  68. {
  69. notify.message = BattleNotify.TiktokGift_52_ext.ToString();
  70. }
  71. notify.TriggerUnits = unitPlayerData.ObjId.ToString();
  72. break;
  73. case DouyinItem.GiftId_99:
  74. // 能量电池
  75. notify = new Struct.TriggerEventNotify();
  76. notify.message = BattleNotify.TiktokGift_99.ToString();
  77. notify.TriggerUnits = unitPlayerData.ObjId.ToString();
  78. break;
  79. case DouyinItem.GiftId_199:
  80. // 恶魔炸弹
  81. notify = new Struct.TriggerEventNotify();
  82. notify.message = BattleNotify.TiktokGift_199.ToString();
  83. notify.TriggerUnits = unitPlayerData.ObjId.ToString();
  84. break;
  85. case DouyinItem.GiftId_520:
  86. // 神秘空投
  87. notify = new Struct.TriggerEventNotify();
  88. notify.message = BattleNotify.TiktokGift_520.ToString();
  89. notify.TriggerUnits = unitPlayerData.ObjId.ToString();
  90. break;
  91. }
  92. map.GetXmdsManager().notifyBattleServer(map.Id.ToString(), NotifyBSName.TriggerEvent, JsonSerializer.Serialize(notify));
  93. //间隔30ms,触发一次礼物效果
  94. await TimerComponent.Instance.WaitAsync(30);
  95. }
  96. }
  97. }
  98. }