public static async ETVoid UpdateFrameAsync(this ServerFrameComponent self) { TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>(); long instanceId = self.InstanceId; while (true) { if (self.InstanceId != instanceId) { return; } await timerComponent.WaitAsync(100); // 不论 FrameMessage.Message 是否有消息内容,都会向客户端转发 MessageHelper.Broadcast(self.FrameMessage); // 转发完,reset FrameMassage ++self.Frame; self.FrameMessage = new FrameMessage() { Frame = self.Frame }; } }
public static Bullet Fire(this Unit self, UnitOperation message) { var bullet = EntityFactory.Create <Bullet>(self.Domain); bullet.OwnerId = self.Id; bullet.Setup(self.Position); var msg = new M2C_OnEnterView(); msg.EnterEntity = new EntiyInfo(); msg.EnterEntity.Type = EntityDefine.GetTypeId <Bullet>(); msg.EnterEntity.BsonBytes.bytes = MongoHelper.ToBson(bullet); var p = bullet.Position; msg.X = (int)(p.x * 100); msg.Y = (int)(p.y * 100); msg.Z = (int)(p.z * 100); MessageHelper.Broadcast(self.Domain, msg); var targetPoint = new Vector3(); targetPoint.x = message.IntParams[0] / 100f; targetPoint.y = message.IntParams[1] / 100f; targetPoint.z = message.IntParams[2] / 100f; bullet.MoveTo(targetPoint); return(bullet); }
protected override async void Run(Session session, G2M_CreateUnit message, Action <M2G_CreateUnit> reply) { M2G_CreateUnit response = new M2G_CreateUnit(); try { Unit unit = ComponentFactory.Create <Unit>(); await unit.AddComponent <MailBoxComponent>().AddLocation(); unit.AddComponent <UnitGateComponent, long>(message.GateSessionId); Game.Scene.GetComponent <UnitComponent>().Add(unit); response.UnitId = unit.Id; response.Count = Game.Scene.GetComponent <UnitComponent>().Count; reply(response); if (response.Count == 2) { Actor_CreateUnits actorCreateUnits = new Actor_CreateUnits(); Unit[] units = Game.Scene.GetComponent <UnitComponent>().GetAll(); Unit u; for (int i = 0; i < units.Length; i++) { u = units[i]; actorCreateUnits.Units.Add(new UnitInfo(u.Id, (int)(u.Position.X * 1000), (int)(u.Position.Z * 1000), i + 1)); } MessageHelper.Broadcast(actorCreateUnits); } } catch (Exception e) { ReplyError(response, e, reply); } }
//广播 本身坐标和向量坐标 public static void BroadcastPath(this MapPathComponent self, List <Vector3> path, int index, int offset) { M2C_KeyboardPosition m2C_KeyboardPosition = new M2C_KeyboardPosition(); Unit unit = self.GetParent <Unit>(); Vector3 unitPos = unit.Position; m2C_KeyboardPosition.X = unitPos.x; m2C_KeyboardPosition.Y = unitPos.y; m2C_KeyboardPosition.Z = unitPos.z; m2C_KeyboardPosition.Id = unit.Id; for (int i = 0; i < offset; ++i) { if (index + i >= self.ABPath.Result.Count) { break; } Vector3 v = self.ABPath.Result[index + i]; m2C_KeyboardPosition.Xs.Add(v.x); m2C_KeyboardPosition.Ys.Add(v.y); m2C_KeyboardPosition.Zs.Add(v.z); } MessageHelper.Broadcast(m2C_KeyboardPosition, unit.GetComponent <AoiUnitComponent>().playerIds.MovesSet.ToArray()); Console.WriteLine(" UnitDirComponentHelper-82-MoveToClient: " + m2C_KeyboardPosition.Id + " ( " + m2C_KeyboardPosition.X + ", " + m2C_KeyboardPosition.Y + ", " + m2C_KeyboardPosition.Z + ")"); }
public static void CancelMove(this UnitPathComponent self) { self.CancellationTokenSource?.Cancel(); self.CancellationTokenSource = null; self.TargetRange = 0; self.Target = Vector3.zero; if (self.BindState != null) { self.Entity.GetComponent <StackFsmComponent>().RemoveState(self.BindState.StateName); self.BindState = null; } if (self.NextState != null) { ReferencePool.Release(self.NextState); self.NextState = null; } Vector3 selfUnitPos = (self.Entity as Unit).Position; M2C_PathfindingResult pathfindingResult = new M2C_PathfindingResult() { X = selfUnitPos.x, Y = selfUnitPos.y, Z = selfUnitPos.z, Id = self.Entity.Id }; pathfindingResult.Xs.Clear(); pathfindingResult.Ys.Clear(); pathfindingResult.Zs.Clear(); MessageHelper.Broadcast(pathfindingResult); }
// 从index找接下来3个点,广播 public static void BroadcastPath(this UnitPathComponent self, List <Vector3> path, int index, int offset) { Unit unit = self.GetParent <Unit>(); Vector3 unitPos = unit.Position; M2C_PathfindingResult m2CPathfindingResult = new M2C_PathfindingResult(); m2CPathfindingResult.X = unitPos.x; m2CPathfindingResult.Y = unitPos.y; m2CPathfindingResult.Z = unitPos.z; m2CPathfindingResult.Id = unit.Id; for (int i = 0; i < offset; ++i) { if (index + i >= self.RecastPath.Results.Count) { break; } Vector3 v = self.RecastPath.Results[index + i]; m2CPathfindingResult.Xs.Add(v.x); m2CPathfindingResult.Ys.Add(v.y); m2CPathfindingResult.Zs.Add(v.z); } MessageHelper.Broadcast(m2CPathfindingResult); }
protected override async ETTask Run(Session session, G2M_CreateUnit request, M2G_CreateUnit response, Action reply) { Unit unit = ComponentFactory.CreateWithId <Unit>(IdGenerater.GenerateId()); unit.Position = new Vector3(-10, 0, -10); unit.AddComponent <MoveComponent>(); unit.AddComponent <UnitPathComponent>(); await unit.AddComponent <MailBoxComponent>().AddLocation(); unit.AddComponent <UnitGateComponent, long>(request.GateSessionId); Game.Scene.GetComponent <UnitComponent>().Add(unit); response.UnitId = unit.Id; // 广播创建的unit M2C_CreateUnits createUnits = new M2C_CreateUnits(); Unit[] units = Game.Scene.GetComponent <UnitComponent>().GetAll(); foreach (Unit u in units) { UnitInfo unitInfo = new UnitInfo(); unitInfo.X = u.Position.x; unitInfo.Y = u.Position.y; unitInfo.Z = u.Position.z; unitInfo.UnitId = u.Id; createUnits.Units.Add(unitInfo); } MessageHelper.Broadcast(createUnits); reply(); }
protected override async void Run(Session session, G2M_CreateUnit message, Action <M2G_CreateUnit> reply) { M2G_CreateUnit response = new M2G_CreateUnit(); try { Unit unit = ComponentFactory.Create <Unit>(); await unit.AddComponent <ActorComponent, IEntityActorHandler>(new MapUnitEntityActorHandler()).AddLocation(); unit.AddComponent <UnitGateComponent, long>(message.GateSessionId); Game.Scene.GetComponent <UnitComponent>().Add(unit); response.UnitId = unit.Id; response.Count = Game.Scene.GetComponent <UnitComponent>().Count; reply(response); if (response.Count == 2) { Actor_CreateUnits actorCreateUnits = new Actor_CreateUnits(); Unit[] units = Game.Scene.GetComponent <UnitComponent>().GetAll(); foreach (Unit u in units) { actorCreateUnits.Units.Add(new UnitInfo() { UnitId = u.Id, X = (int)(u.Position.X * 1000), Z = (int)(u.Position.Z * 1000) }); } MessageHelper.Broadcast(actorCreateUnits); } } catch (Exception e) { ReplyError(response, e, reply); } }
public static void Destroy(this Monster self) { MessageHelper.Broadcast(self.Domain, new M2C_OnLeaveView() { LeaveEntity = self.Id, EntityType = EntityDefine.GetTypeId(self.GetType()) }); }
public static void GetInput(this UnitStateComponent unitStateComponent, int frame, ICommandInput commandInput) { try { //unitStateComponent.collectInput = true; //if (unitStateComponent.currGetInputFrame < frame) // unitStateComponent.currGetInputFrame = frame; //UnitStateDelta unitStateDelta = new UnitStateDelta(); //unitStateDelta.frame = frame; var result = Game.Scene.GetComponent <CommandSimulaterComponent>().commandSimulaters[commandInput.GetType()].Simulate(commandInput, unitStateComponent.unit); switch (result) { case CommandResult_Move result_Move: unitStateComponent.unit.GetComponent <CharacterMoveComponent>().MoveAsync(result_Move.Path).Coroutine(); unitStateComponent.inputResult_Move.Frame = frame; unitStateComponent.inputResult_Move.Id = unitStateComponent.unit.Id; unitStateComponent.inputResult_Move.PathList = new Google.Protobuf.Collections.RepeatedField <Vector3Info>(); for (int i = 0; i < result_Move.Path.Count; i++) { unitStateComponent.inputResult_Move.PathList.Add(new Vector3Info() { X = result_Move.Path[i].x, Y = result_Move.Path[i].y, Z = result_Move.Path[i].z }); } MessageHelper.Broadcast(unitStateComponent.inputResult_Move); break; case CommandResult_UseSkill result_UseSkill: bool checkResult = unitStateComponent.unit.GetComponent <ActiveSkillComponent>().CheckCanUse(result_UseSkill.skillId); if (checkResult) { unitStateComponent.unit.GetComponent <ActiveSkillComponent>().Execute(result_UseSkill.skillId).Coroutine(); } switch ((commandInput as CommandInput_UseSkill).bufferValue) { case BufferValue_Dir bufferValue_Dir: unitStateComponent.useSkill_Dir.SkillId = result_UseSkill.skillId; unitStateComponent.useSkill_Dir.Success = checkResult; unitStateComponent.useSkill_Dir.Id = unitStateComponent.unit.Id; unitStateComponent.useSkill_Dir.PipelineSignal = (commandInput as CommandInput_UseSkill).pipelineSignal; unitStateComponent.useSkill_Dir.Dir = bufferValue_Dir.dir.ToV3Info(); MessageHelper.Broadcast(unitStateComponent.useSkill_Dir); break; } break; } //unitStateDelta.commandResults.Add(result.GetType(), result); //unitStateComponent.unitStatesDic[unitStateComponent.currGetInputFrame] = unitStateDelta; } catch (Exception e) { Log.Error(e.ToString()); } }
protected override async ETTask Run(Unit entity, Movement_Jump message) { M2C_MovementResult m2C_MovementResult = new M2C_MovementResult(); m2C_MovementResult.Id = entity.Id; MessageHelper.Broadcast(m2C_MovementResult); await ETTask.CompletedTask; }
protected override void Run(ETModel.Session session, M2M_AddUnits message) { Console.WriteLine(" M2C_AddUnitHandler-15-unittype/uis/pis: " + (UnitType)message.UnitType + " / " + message.UnitIds.Count + " / " + message.PlayerUnitIds.Count); int unittype = message.UnitType; switch (unittype) { case 0: M2C_AddUnits m2C_AddUnits0 = new M2C_AddUnits() { UnitType = message.UnitType }; foreach (long playerId in message.UnitIds) { Unit player = Game.Scene.GetComponent <UnitComponent>().Get(playerId); if (player != null) { UnitInfo unitInfo = new UnitInfo(); unitInfo.UnitId = player.Id; unitInfo.X = player.Position.x; unitInfo.Y = player.Position.y; unitInfo.Z = player.Position.z; m2C_AddUnits0.Units.Add(unitInfo); } } MessageHelper.Broadcast(m2C_AddUnits0, message.PlayerUnitIds.ToArray()); Console.WriteLine(" M2C_AddUnitHandler-Id-38: " + (int)message.UnitType); break; case 1: M2C_AddUnits m2C_AddUnits1 = new M2C_AddUnits() { UnitType = message.UnitType }; foreach (long monsterId in message.UnitIds) { Unit monster = Game.Scene.GetComponent <MonsterUnitComponent>().Get(monsterId); if (monster != null) { UnitInfo unitInfo = new UnitInfo(); unitInfo.UnitId = monster.Id; unitInfo.X = monster.Position.x; unitInfo.Y = monster.Position.y; unitInfo.Z = monster.Position.z; m2C_AddUnits1.Units.Add(unitInfo); } } MessageHelper.Broadcast(m2C_AddUnits1, message.PlayerUnitIds.ToArray()); Console.WriteLine(" M2C_AddUnitHandler-Id-58: " + (int)message.UnitType); break; case 2: break; } }
public static void BroadcastSkillCmd(Unit unit, string skillCmd) { M2C_UserInput_SkillCmd m2CUserInputSkillCmd = new M2C_UserInput_SkillCmd() { Message = skillCmd, Id = unit.Id }; MessageHelper.Broadcast(m2CUserInputSkillCmd); }
private static async ETVoid StartCommonAttack(this CommonAttackComponent self) { self.CancellationTokenSource?.Cancel(); self.CancellationTokenSource = new CancellationTokenSource(); MessageHelper.Broadcast(new M2C_CommonAttack() { AttackCasterId = self.Entity.Id, TargetUnitId = self.CachedUnitForAttack.Id, CanAttack = true }); await self.CommonAttack_Internal(); }
protected override async ETTask Run(Unit entity, UserInput_SkillCmd message) { M2C_UserInput_SkillCmd m2CUserInputSkillCmd = new M2C_UserInput_SkillCmd() { Message = message.Message, Id = entity.Id }; foreach (var VARIABLE in entity.GetComponent <NP_RuntimeTreeManager>().RuntimeTrees) { VARIABLE.Value.GetBlackboard().Set("PlayerInput", message.Message); } //广播技能指令(BroadcastSkillCmd),让客户端行为树做出反应 MessageHelper.Broadcast(m2CUserInputSkillCmd); await ETTask.CompletedTask; }
protected override void Run(Unit entity, Turn_Map message) { ///ToTo 直接转发给所有 客户端 Vector3 dirPos = new Vector3(message.X, message.Y, message.Z); Console.WriteLine(" Turn_MapHandler-20-dirPos: " + dirPos.ToString()); M2C_KeyboardDirection m2C_KeyboardDirection = new M2C_KeyboardDirection(); m2C_KeyboardDirection.X = dirPos.x; m2C_KeyboardDirection.Y = dirPos.y; m2C_KeyboardDirection.Z = dirPos.z; m2C_KeyboardDirection.Id = entity.Id; MessageHelper.Broadcast(m2C_KeyboardDirection, entity.GetComponent <AoiUnitComponent>().playerIds.MovesSet.ToArray()); }
private static async ETTask CommonAttack_Internal(this CommonAttackComponent self) { MessageHelper.Broadcast(new M2C_CommonAttack() { AttackCasterId = self.Entity.Id, TargetUnitId = self.CachedUnitForAttack.Id, CanAttack = true }); HeroDataComponent heroDataComponent = self.Entity.GetComponent <HeroDataComponent>(); float attackPre = heroDataComponent.NodeDataForHero.OriAttackPre / (1 + heroDataComponent.GetAttribute(NumericType.AttackSpeedAdd)); float attackSpeed = heroDataComponent.GetAttribute(NumericType.AttackSpeed); //播放动画,如果动画播放完成还不能进行下一次普攻,则播放空闲动画 await TimerComponent.Instance.WaitAsync((long)(attackPre * 1000), self.CancellationTokenSource.Token); DamageData damageData = ReferencePool.Acquire <DamageData>().InitData(BuffDamageTypes.PhysicalSingle | BuffDamageTypes.CommonAttack, heroDataComponent.GetAttribute(NumericType.Attack), self.Entity as Unit, self.CachedUnitForAttack); self.Entity.GetComponent <CastDamageComponent>().BaptismDamageData(damageData); float finalDamage = self.CachedUnitForAttack.GetComponent <ReceiveDamageComponent>().BaptismDamageData(damageData); if (finalDamage >= 0) { self.CachedUnitForAttack.GetComponent <HeroDataComponent>().NumericComponent.ApplyChange(NumericType.Hp, -finalDamage); //抛出伤害事件,需要监听伤害的buff(比如吸血buff)需要监听此事件 Game.Scene.GetComponent <BattleEventSystem>().Run($"{EventIdType.ExcuteDamage}{self.Entity.Id}", damageData); //抛出受伤事件,需要监听受伤的Buff(例如反甲)需要监听此事件 Game.Scene.GetComponent <BattleEventSystem>().Run($"{EventIdType.TakeDamage}{self.CachedUnitForAttack.Id}", damageData); } CDComponent.Instance.TriggerCD(self.Entity.Id, "CommonAttack"); CDInfo commonAttackCDInfo = CDComponent.Instance.GetCDData(self.Entity.Id, "CommonAttack"); commonAttackCDInfo.Interval = (long)(1 / attackSpeed - attackPre) * 1000; List <NP_RuntimeTree> targetSkillCanvas = self.Entity.GetComponent <SkillCanvasManagerComponent>().GetSkillCanvas(10001); foreach (var skillCanva in targetSkillCanvas) { skillCanva.GetBlackboard().Set("CastNormalAttack", true); skillCanva.GetBlackboard().Set("NormalAttackUnitIds", new List <long>() { self.CachedUnitForAttack.Id }); } await TimerComponent.Instance.WaitAsync(commonAttackCDInfo.Interval, self.CancellationTokenSource.Token); }
/// <summary> /// 广播指令和碰撞体数据(Debug用,正式上线后请使用上面那个) /// </summary> /// <param name="unit"></param> /// <param name="colliderComponent"></param> /// <param name="skillCmd"></param> public static void BroadcastB2S_ColliderData(Unit unit, B2S_ColliderComponent colliderComponent) { colliderComponent.SyncBody(); //广播碰撞体信息 foreach (var VARIABLE in colliderComponent.Body.FixtureList) { switch (VARIABLE.ShapeType) { case ShapeType.Polygon: //多边形 M2C_B2S_Debugger_Polygon test = new M2C_B2S_Debugger_Polygon() { Id = unit.Id, SustainTime = 2000, }; foreach (var VARIABLE1 in ((PolygonShape)VARIABLE.Shape).Vertices) { Vector2 worldPoint = colliderComponent.Body.GetWorldPoint(VARIABLE1); test.Vects.Add(new M2C_B2S_VectorBase() { X = worldPoint.X, Y = worldPoint.Y }); } MessageHelper.Broadcast(test); break; case ShapeType.Circle: //圆形 CircleShape myShape = (CircleShape)VARIABLE.Shape; M2C_B2S_Debugger_Circle test1 = new M2C_B2S_Debugger_Circle() { Id = unit.Id, SustainTime = 2000, Radius = myShape.Radius, Pos = new M2C_B2S_VectorBase() { X = colliderComponent.Body.GetWorldPoint(myShape.Position).X, Y = colliderComponent.Body.GetWorldPoint(myShape.Position).Y }, }; MessageHelper.Broadcast(test1); //Log.Info($"是圆形,并且已经朝客户端发送绘制数据,半径为{myShape.Radius}"); break; } } }
protected override void Run(Session session, M2M_RemoveUnits message) { Console.WriteLine(" M2M_RemoveUnitHandler-15-unittype/uis/pis: " + (UnitType)message.UnitType + " / " + message.UnitIds.Count + " / " + message.PlayerUnitIds.Count); //1、将服务端Unit 处理一下,如标高为死亡状态,或移出组件管理的字典 //2、删除 客户端Unit实例或其GameObject int unitType = message.UnitType; switch (unitType) { case 0: M2C_RemoveUnits m2C_RemoveUnits0 = new M2C_RemoveUnits() { UnitType = unitType }; foreach (long monsterId in message.UnitIds) { UnitInfo unitInfo = new UnitInfo(); unitInfo.UnitId = monsterId; m2C_RemoveUnits0.Units.Add(unitInfo); } MessageHelper.Broadcast(m2C_RemoveUnits0, message.PlayerUnitIds.ToArray()); Console.WriteLine(" M2M_RemoveUnitHandler-32-sessionId/unitId/unittype: " + session.Id + " / " + message.UnitIds.First() + " / " + (UnitType)message.UnitType); break; case 1: M2C_RemoveUnits m2C_RemoveUnits1 = new M2C_RemoveUnits() { UnitType = unitType }; foreach (long monsterId in message.UnitIds) { UnitInfo unitInfo = new UnitInfo(); unitInfo.UnitId = monsterId; m2C_RemoveUnits1.Units.Add(unitInfo); } MessageHelper.Broadcast(m2C_RemoveUnits1, message.PlayerUnitIds.ToArray()); Console.WriteLine(" M2M_RemoveUnitHandler-45-sessionId/unitId/unittype: " + session.Id + " / " + message.UnitIds.First() + " / " + (UnitType)message.UnitType); break; } }
protected async ETVoid RunAsync(Session session, G2M_CreateUnit message, Action <M2G_CreateUnit> reply) { M2G_CreateUnit response = new M2G_CreateUnit(); try { Unit unit = ComponentFactory.CreateWithId <Unit>(IdGenerater.GenerateId()); unit.AddComponent <MoveComponent>(); unit.AddComponent <UnitPathComponent>(); unit.Position = new Vector3(-10, 0, -10); //unit的id是key,instanceId是Value,两个值都是Create Unit时随机创建的 await unit.AddComponent <MailBoxComponent>().AddLocation(); unit.AddComponent <UnitGateComponent, long>(message.GateSessionId); Game.Scene.GetComponent <UnitComponent>().Add(unit); response.UnitId = unit.Id; // 广播创建的unit M2C_CreateUnits createUnits = new M2C_CreateUnits(); Unit[] units = Game.Scene.GetComponent <UnitComponent>().GetAll(); foreach (Unit u in units) { UnitInfo unitInfo = new UnitInfo(); unitInfo.X = u.Position.x; unitInfo.Y = u.Position.y; unitInfo.Z = u.Position.z; unitInfo.UnitId = u.Id; createUnits.Units.Add(unitInfo); } MessageHelper.Broadcast(createUnits); reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
protected override async ETTask Run(Session session, G2M_CreateUnit request, M2G_CreateUnit response, Action reply) { //并且生成ID 创建Unit实体对象 Unit unit = ComponentFactory.CreateWithId <Unit>(IdGenerater.GenerateId()); unit.AddComponent <MoveComponent>(); unit.AddComponent <UnitPathComponent>(); //设置实体位置 unit.Position = new Vector3(-10, 0, -10); //添加邮箱 await unit.AddComponent <MailBoxComponent>().AddLocation(); //添加单位网关组件 主要是缓存该单位在网关服务器的Session Id //GateSessionActorId = request.GateSessionId unit.AddComponent <UnitGateComponent, long>(request.GateSessionId); //缓存这个单位 Game.Scene.GetComponent <UnitComponent>().Add(unit); //设置响应的字段 UnitId response.UnitId = unit.Id; // 广播协议:创建unit M2C_CreateUnits createUnits = new M2C_CreateUnits(); //获取所有的玩家 然后进行广播 Unit[] units = Game.Scene.GetComponent <UnitComponent>().GetAll(); foreach (Unit u in units) { UnitInfo unitInfo = new UnitInfo(); unitInfo.X = u.Position.x; unitInfo.Y = u.Position.y; unitInfo.Z = u.Position.z; unitInfo.UnitId = u.Id; createUnits.Units.Add(unitInfo); } MessageHelper.Broadcast(createUnits); //响应网关的请求 reply(); }
protected async ETVoid RunAsync(Session session, G2M_CreateShip message, Action <M2G_CreateShip> reply) { //NOTE 第二时间 游戏服务器收到创建Unit的请求 M2G_CreateShip response = new M2G_CreateShip(); try { Ship ship = ComponentFactory.CreateWithId <Ship>(IdGenerater.GenerateId()); ship.AddComponent <MoveComponent>(); ship.AddComponent <ShipSkillComponent>(); ship.Position = new Vector3(-10, 0, -10); await ship.AddComponent <MailBoxComponent>().AddLocation(); ship.AddComponent <ShipGateComponent, long>(message.GateSessionId); Game.Scene.GetComponent <ShipComponent>().Add(ship); response.ShipId = ship.Id; // 广播创建的unit M2C_CreateShips createShips = new M2C_CreateShips(); Ship[] ships = Game.Scene.GetComponent <ShipComponent>().GetAll(); foreach (Ship itemShip in ships) { ShipInfo shipInfo = new ShipInfo(); shipInfo.X = itemShip.Position.x; shipInfo.Y = itemShip.Position.y; shipInfo.Z = itemShip.Position.z; shipInfo.ShipId = itemShip.Id; createShips.Ships.Add(shipInfo); } MessageHelper.Broadcast(createShips); reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
public static async void UpdateFrameAsync(this ServerFrameComponent self) { TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>(); while (true) { if (self.IsDisposed) { return; } await timerComponent.WaitAsync(100); MessageHelper.Broadcast(self.FrameMessage); ++self.Frame; self.FrameMessage = new FrameMessage() { Frame = self.Frame }; } }
protected override ETTask Run(Unit entity, Actor_CreateSpiling message) { Unit unit = UnitFactory.CreateSpiling(message.ParentUnitId); //设置木桩位置 unit.Position = new Vector3(message.X, 0, message.Z); // 广播创建的木桩unit M2C_CreateSpilings createSpilings = new M2C_CreateSpilings(); SpilingInfo spilingInfo = new SpilingInfo(); spilingInfo.X = unit.Position.x; spilingInfo.Y = unit.Position.y; spilingInfo.Z = unit.Position.z; spilingInfo.UnitId = unit.Id; spilingInfo.ParentUnitId = message.ParentUnitId; createSpilings.Spilings = spilingInfo; //向所有小骷髅广播信息 MessageHelper.Broadcast(createSpilings); return(ETTask.CompletedTask); }
protected override async ETTask Run(Session session, G2M_CreateUnit request, M2G_CreateUnit response, Action reply) { Unit targetUnit = UnitFactory.CreateDarius(); //给小骷髅添加信箱组件,队列处理收到的消息,让这个unit正式注册为actor系统一员 await targetUnit.AddComponent <MailBoxComponent>().AddLocation(); //添加同gate服务器通信基础组件,记录GateSeesion的Id为ActorId targetUnit.AddComponent <UnitGateComponent, long>(request.GateSessionId); // 广播创建的unit M2C_CreateUnits createUnits = new M2C_CreateUnits(); Unit[] units = UnitComponent.Instance.GetAll(); foreach (Unit u in units) { UnitInfo unitInfo = new UnitInfo(); if (u.GetComponent <B2S_RoleCastComponent>() != null) { //TODO 诺手UnitTypeId暂定10001 unitInfo.UnitTypeId = 10001; unitInfo.RoleCamp = (int)u.GetComponent <B2S_RoleCastComponent>().RoleCamp; } unitInfo.X = u.Position.x; unitInfo.Y = u.Position.y; unitInfo.Z = u.Position.z; unitInfo.UnitId = u.Id; createUnits.Units.Add(unitInfo); } //向所有unit广播信息 MessageHelper.Broadcast(createUnits); //设置回复消息的Id response.UnitId = targetUnit.Id; //广播完回复客户端,这边搞好了 reply(); }
public static void Update(this EntitySyncComponent self) { if (TimeHelper.Now() - self.Timer > self.Interval) { self.Timer = TimeHelper.Now(); var transform = self.Parent.GetComponent <TransformComponent>(); var lp = transform.lastPosition; var p = transform.position; if (Vector3.Distance(lp, p) < 0.1f) { return; } transform.lastPosition = p; var msg = new M2C_OnEntityChanged(); msg.EntityId = self.Id; msg.EntityType = EntityDefine.GetTypeId(self.Parent.GetType()); msg.X = (int)(p.x * 100); msg.Y = (int)(p.y * 100); msg.Z = (int)(p.z * 100); MessageHelper.Broadcast(self.Domain, msg); } }
public static async void UpdateFrameAsync(this ServerFrameComponent self) { TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>(); long instanceId = self.InstanceId; while (true) { if (self.InstanceId != instanceId) { return; } await timerComponent.WaitAsync(100); //延时100毫秒 MessageHelper.Broadcast(self.FrameMessage); //广播一次帧消息 ++self.Frame; //帧+1 self.FrameMessage = new FrameMessage() { Frame = self.Frame }; } }
protected async ETVoid RunAsync(Session session, G2M_CreateUnit message, Action <M2G_CreateUnit> reply) { M2G_CreateUnit response = new M2G_CreateUnit(); try { UnitData playerData = new UnitData(); if (unitIndex % 2 == 0) { playerData.groupIndex = GroupIndex.Player; playerData.layerMask = UnitLayerMask.ALL; playerData.unitLayer = UnitLayer.Character; playerData.unitTag = UnitTag.Player; } else { playerData.groupIndex = GroupIndex.Monster; playerData.layerMask = UnitLayerMask.ALL; playerData.unitLayer = UnitLayer.Character; playerData.unitTag = UnitTag.Monster; } unitIndex++; Unit unit = UnitFactory.Create(IdGenerater.GenerateId(), 1001, playerData); await unit.AddComponent <MailBoxComponent>().AddLocation(); unit.AddComponent <UnitGateComponent, long>(message.GateSessionId); unit.Position = new Vector3(-10, 0, -10); UnitStateComponent stateCom = unit.GetComponent <UnitStateComponent>(); Game.Scene.GetComponent <UnitStateMgrComponent>().Add(stateCom); response.UnitId = unit.Id; // 广播创建的unit M2C_CreateUnits createUnits = new M2C_CreateUnits(); Unit[] units = Game.Scene.GetComponent <UnitComponent>().GetAll(); foreach (Unit u in units) { UnitInfo unitInfo = new UnitInfo(); UnitStateComponent unitStateComponent = u.GetComponent <UnitStateComponent>(); unitInfo.Position = u.Position.ToV3Info(); unitInfo.Dir = Vector3.forward.ToV3Info(); unitInfo.UnitId = u.Id; unitInfo.GroupIndex = (int)u.UnitData.groupIndex; unitInfo.LayerMask = (int)u.UnitData.layerMask; unitInfo.UnitLayer = (int)u.UnitData.unitLayer; unitInfo.UnitTag = (int)u.UnitData.unitTag; foreach (var v in u.GetComponent <NumericComponent>().NumericDic) { unitInfo.UnitNumerics.Add(new UnitNumeric() { Type = v.Key, Value = v.Value }); } createUnits.Units.Add(unitInfo); } MessageHelper.Broadcast(createUnits); reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
public override async ETTask FireRequestHandler(Unit unit, FireRequest request, MessageResponse response, Action reply) { MessageHelper.Broadcast(unit, request); reply(); await ETTask.CompletedTask; }