12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.Json;
- namespace ET.Server
- {
- /// <summary>
- /// 向战斗服发送特定消息(触发编辑器事件)
- /// </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)
- {
- WNPlayer player = session.GetComponent<SessionPlayerComponent>().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;
- 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)
- {
- MessageHelper.SendActor(instanceid, new R2G_LiveLike() { OpenId = randunit.OpenId, RoomId = roomId, NickName = randunit.Name, Url = randunit.Url, Likes = 10 });
- }
- else
- {
- 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;
- }
- }
- }
|