소스 검색

【游戏服】增加客户端礼物测试接口,直接调用游戏服礼物处理接口

大爷 1 년 전
부모
커밋
6739bfa4cb
1개의 변경된 파일47개의 추가작업 그리고 25개의 파일을 삭제
  1. 47 25
      DotNet/Hotfix/Scenes/Game/Handler/C2G_BattleNotifyHandler.cs

+ 47 - 25
DotNet/Hotfix/Scenes/Game/Handler/C2G_BattleNotifyHandler.cs

@@ -1,4 +1,6 @@
 using System;
+using System.Collections.Generic;
+using System.Linq;
 using System.Text.Json;
 
 namespace ET.Server
@@ -7,6 +9,7 @@ namespace ET.Server
     /// 向战斗服发送特定消息(触发编辑器事件)
     /// </summary>
     [MessageHandler(SceneType.Game)]
+    [FriendOfAttribute(typeof(ET.Server.GameMapComponent))]
     public class C2G_BattleNotifyHandler : AMRpcHandler<C2G_BattleNotify, G2C_BattleNotify>
     {
         protected override async ETTask Run(Session session, C2G_BattleNotify request, G2C_BattleNotify response, Action reply)
@@ -29,41 +32,60 @@ namespace ET.Server
                 return;
             }
 
-            //TODO:从玩家的openid换取在战场中的objectID
-            int objid = 7;
-
-            //甜甜圈礼物功能示例
-            if(request.Message == BattleNotify.TiktokGift_52.ToString())//eventname = "甜甜圈")
+            //客户端测试功能
+            if (request.Message.StartsWith("test:"))
             {
-                //TODO: 游戏服记录单位level,初始level为1,level=3为顶级
-                int level = 1;
-                if (level < 3)
+                var map = player.Map;
+                var players = map.UnitPlayers.Values.ToArray();
+                var rand = new Random();
+                var randunit = players[rand.Next(players.Length)];
+
+                long roomId = 0;
+                var maphash = GameMapComponent.Instance.rooms;
+                foreach ( var rid in maphash.Keys )
+                {
+                    if (maphash[rid] == map.Id)
+                    {
+                        roomId = rid;
+                        break;
+                    }
+                }
+
+                long instanceid = 0;
+                List<StartSceneConfig> list = RealmGateAddressHelper.GetAllGame(1);
+                foreach (StartSceneConfig config in list.Where(config => config is { Id: 10001 }))
+                {
+                    instanceid = config.InstanceId;
+                    break;
+                }
+
+                var funcIndex = int.Parse(request.Message[5..]);
+                if (funcIndex == 7)
                 {
-                    player.GetXmdsManager().notifyBattleServer(player.Map.Id.ToString(), NotifyBSName.TriggerEvent,
-                        JsonSerializer.Serialize(new Struct.TriggerEventNotify() { message = BattleNotify.TiktokGift_52.ToString(), TriggerUnits = objid.ToString() }));
+                    MessageHelper.SendActor(instanceid, new R2G_LiveLike() { OpenId = randunit.OpenId, RoomId = roomId, NickName = randunit.Name, Url = randunit.Url, Likes = 10 });
                 }
                 else
                 {
-                    //已经升到顶级的单位,触发其它甜甜圈效果
-                    player.GetXmdsManager().notifyBattleServer(player.Map.Id.ToString(), NotifyBSName.TriggerEvent,
-                        JsonSerializer.Serialize(new Struct.TriggerEventNotify() { message = BattleNotify.TiktokGift_52_ext.ToString(), TriggerUnits = objid.ToString() }));
+                    string[] GIFT = { DouyinItem.GiftId_1, DouyinItem.GiftId_10, DouyinItem.GiftId_52, DouyinItem.GiftId_99, DouyinItem.GiftId_199, DouyinItem.GiftId_520 };
+                    int cnt = 1;
+                    switch(funcIndex)
+                    {
+                        case 1:
+                            cnt = (int)Math.Sqrt(rand.Next(1, 100));
+                            break;
+                        case 2:
+                            cnt = rand.Next(1, 10);
+                            break;
+                    }
+
+                    MessageHelper.SendActor(instanceid, new R2G_LiveGift() { OpenId = randunit.OpenId, RoomId = roomId, NickName = randunit.Name, Url = randunit.Url, GiftId = GIFT[funcIndex-1], GiftNum = cnt, GiftValue = funcIndex * 80 });
                 }
+                
                 return;
             }
 
-            Struct.TriggerEventNotify notifyMsg = new Struct.TriggerEventNotify() { message = request.Message };
-            if (request.Message == BattleNotify.TiktokGift_1.ToString() )    //仙女棒
-            {
-                //礼物的效果如果专门针对送礼人自己,则需要把送礼人的objectid填入到TriggerUnits中
-                notifyMsg.TriggerUnits = objid.ToString();
-            }
-            else if(request.Message == BattleNotify.TiktokGift_10.ToString())
-            {
-                notifyMsg.TriggerUnits = objid.ToString();
-            }
-
             // 通知战斗服
-            player.GetXmdsManager().notifyBattleServer(player.Map.Id.ToString(), NotifyBSName.TriggerEvent, JsonSerializer.Serialize(notifyMsg));
+            player.GetXmdsManager().notifyBattleServer(player.Map.Id.ToString(), NotifyBSName.TriggerEvent, JsonSerializer.Serialize(new Struct.TriggerEventNotify() { message = request.Message }));
 
             reply();
             await ETTask.CompletedTask;