using System; using System.Text.Json; namespace ET.Server { /// /// 向战斗服发送特定消息(触发编辑器事件) /// [MessageHandler(SceneType.Game)] 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; } //TODO:从玩家的openid换取在战场中的objectID int objid = 7; //甜甜圈礼物功能示例 if(request.Message == BattleNotify.TiktokGift_52.ToString())//eventname = "甜甜圈") { //TODO: 游戏服记录单位level,初始level为1,level=3为顶级 int level = 1; if (level < 3) { player.GetXmdsManager().notifyBattleServer(player.Map.Id.ToString(), NotifyBSName.TriggerEvent, JsonSerializer.Serialize(new Struct.TriggerEventNotify() { message = BattleNotify.TiktokGift_52.ToString(), TriggerUnits = objid.ToString() })); } else { //已经升到顶级的单位,触发其它甜甜圈效果 player.GetXmdsManager().notifyBattleServer(player.Map.Id.ToString(), NotifyBSName.TriggerEvent, JsonSerializer.Serialize(new Struct.TriggerEventNotify() { message = BattleNotify.TiktokGift_52_ext.ToString(), TriggerUnits = objid.ToString() })); } 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)); reply(); await ETTask.CompletedTask; } } }