public async Task Handle(Session session, Entity entity, object actorMessage) { Message msg = actorMessage as Message; if (msg == null) { Log.Error($"消息类型转换错误: {actorMessage.GetType().FullName} to {typeof(Message).Name}"); return; } E e = entity as E; if (e == null) { Log.Error($"Actor类型转换错误: {entity.GetType().Name} to {typeof(E).Name}"); return; } this.Run(e, msg); await Task.CompletedTask; }
public async Task Handle(Session session, Entity entity, object actorMessage) { try { Request request = actorMessage as Request; if (request == null) { Log.Error($"消息类型转换错误: {actorMessage.GetType().FullName} to {typeof (Request).Name}"); return; } E e = entity as E; if (e == null) { Log.Error($"Actor类型转换错误: {entity.GetType().Name} to {typeof(E).Name}"); return; } int rpcId = request.RpcId; long instanceId = session.InstanceId; await this.Run(e, request, response => { // 等回调回来,session可以已经断开了,所以需要判断session InstanceId是否一样 if (session.InstanceId != instanceId) { return; } response.RpcId = rpcId; session.Reply(response); }); } catch (Exception e) { throw new Exception($"解释消息失败: {actorMessage.GetType().FullName}", e); } }
public async Task Handle(Session session, Entity entity, ActorRequest message) { try { Request request = message.AMessage as Request; if (request == null) { Log.Error($"消息类型转换错误: {message.GetType().FullName} to {typeof (Request).Name}"); return; } E e = entity as E; if (e == null) { Log.Error($"Actor类型转换错误: {entity.GetType().Name} to {typeof(E).Name}"); return; } await this.Run(e, request, response => { // 等回调回来,session可以已经断开了,所以需要判断session id是否为0 if (session.IsDisposed) { return; } ActorResponse actorResponse = new ActorResponse { AMessage = response }; int rpcId = message.RpcId; actorResponse.RpcId = rpcId; session.Reply(actorResponse); }); } catch (Exception e) { throw new Exception($"解释消息失败: {message.GetType().FullName}", e); } }
public override async ETTask M2C_OnEntityChangedHandler(ETModel.Session session, M2C_OnEntityChanged message) { Log.Debug($"M2C_OnEntityChangedHandler {Dumper.DumpAsString(message)}"); var entityType = EntityDefine.TypeIds.GetKeyByValue((ushort)message.EntityType); ETModel.Entity entity = null; if (entityType == typeof(Unit)) { entity = UnitComponent.Instance.Get(message.EntityId); } if (entityType == typeof(Bullet)) { var bullet = BulletComponent.Instance.Get(message.EntityId); entity = bullet; if (entity is null) { return; } if (bullet.BodyView != null) { bullet.BodyView.transform.DOMove(new Vector3(message.X / 100f, message.Y / 100f, message.Z / 100f), 0.2f); } } if (entityType == typeof(Monster)) { var monster = MonsterComponent.Instance.Get(message.EntityId); entity = monster; if (entity is null) { return; } if (monster.BodyView != null) { monster.BodyView.transform.DOMove(new Vector3(message.X / 100f, message.Y / 100f, message.Z / 100f), 0.2f); } } if (entity is null) { return; } if (message.ComponentType > 0) { entity = entity.GetComponent(EntityDefine.GetType(message.ComponentType)); } var propertyCollection = EntityDefine.PropertyCollectionMap[EntityDefine.GetTypeId(entity.GetType())]; if (propertyCollection.ContainsKey((ushort)message.PropertyId)) { entity.SetPropertyValue((ushort)message.PropertyId, message.PropertyValue.bytes); } await ETTask.CompletedTask; }
public void Add(Entity entity) { Log.Info($"add actor: {entity.Id} {entity.GetType().Name}"); dictionary[entity.Id] = entity; }