using System; using System.Collections.Generic; using System.Linq; using System.Text.Json; namespace ET.Server { /// /// 向战斗服发送特定消息(触发编辑器事件) /// [MessageHandler(SceneType.Game)] [FriendOfAttribute(typeof(ET.Server.GameMapComponent))] public class C2G_BattleNotifyHandler : AMRpcHandler { protected override async ETTask Run(Session session, C2G_BattleNotify request, G2C_BattleNotify response, Action reply) { WNPlayer player = session.GetComponent().GetMyPlayer(); if (player == null) { Log.Debug($"操作错误, player is null"); response.Error = ErrorCode.ERR_OperationError; reply(); return; } // 判断参数 if (string.IsNullOrEmpty(request.Message)) { Log.Debug($"参数错误, request.NameType={request.Message}"); response.Error = ErrorCode.ERR_ParameterError; reply(); return; } //客户端测试功能 if (request.Message.StartsWith("test:")) { var map = player.Map; if(map == null || map.UnitPlayers == null) { Log.Debug("map not exist, abort cmd"); return; } var players = map.UnitPlayers.Values.ToArray(); if(players.Length == 0) { Log.Debug("Player count == 0, abort cmd"); return; } 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 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) { MessageHelper.SendActor(instanceid, new R2G_LiveLike() { OpenId = randunit.OpenId, RoomId = roomId, NickName = randunit.Name, Url = randunit.Url, Likes = 10 }); } else if(funcIndex <= 6 && funcIndex >= 1) { 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; } // 通知战斗服 player.GetXmdsManager().notifyBattleServer(player.Map.Id.ToString(), NotifyBSName.TriggerEvent, JsonSerializer.Serialize(new Struct.TriggerEventNotify() { message = request.Message })); reply(); await ETTask.CompletedTask; } } }