/// <summary> /// AI - 代理权: 如果我拥有了它的控制权, 则状态机要在这里运行, ActorVisualizer的同名函数会继续运行(接受本函数发送的消息) /// </summary> /// <param name="bytes"></param> private void OnActorAiStateHighReply(byte[] bytes) { ActorAiStateHighReply input = ActorAiStateHighReply.Parser.ParseFrom(bytes); if (input.ActorId != ActorId) { return; // 不是自己,略过 } if (!input.Ret) { return; } // 如果本地AI可以控制本单位, 或者是当前玩家自己, 则继续, 否则这里返回 if (!HasAiRights && input.OwnerId != GameRoomManager.Instance.CurrentPlayer.TokenId) { return; } HighAiState = (StateEnum)input.HighAiState;// 记录高级AI状态 HighAiTargetCell = input.HighAiCellIndexTo; HighAiTargetId = 0; var abTarget = GameRoomManager.Instance.RoomLogic.ActorManager.GetActor(input.HighAiTargetId); if (abTarget != null && !abTarget.IsDead) { HighAiTargetId = input.HighAiTargetId; } HighAiDurationTime = input.HighAiDurationTime; HighAiTotalTime = input.HighAiTotalTime; StateMachine.TriggerTransition((StateEnum)input.HighAiState, input.HighAiCellIndexTo, input.HighAiTargetId, input.HighAiDurationTime, input.HighAiTotalTime); }
private void OnActorAiStateHigh(SocketAsyncEventArgs args, byte[] bytes) { ActorAiStateHigh input = ActorAiStateHigh.Parser.ParseFrom(bytes); if (input.RoomId != RoomId) { return; // 不是自己房间的消息,略过 } // 更新单元Ai信息,在服务器的ActorBehaviour里保存一份 var ab = ActorManager.GetActor(input.ActorId); if (ab != null) { ab.HighAiState = input.HighAiState; ab.HighAiTargetId = input.HighAiTargetId; ab.HighAiCellIndexTo = input.HighAiCellIndexTo; ab.HighAiDurationTime = input.HighAiDurationTime; ab.HighAiTotalTime = input.HighAiTotalTime; ab.HighAiStartTime = DateTime.Now; // 记录得到当前状态的时间, 在存盘的时候再记录一下时间, 把剩余时间保存起来 } ActorAiStateHighReply output2 = new ActorAiStateHighReply() { RoomId = input.RoomId, OwnerId = input.OwnerId, ActorId = input.ActorId, HighAiState = input.HighAiState, HighAiTargetId = input.HighAiTargetId, HighAiCellIndexTo = input.HighAiCellIndexTo, HighAiDurationTime = input.HighAiDurationTime, HighAiTotalTime = input.HighAiTotalTime, Ret = true, }; BroadcastMsg(ROOM_REPLY.ActorAiStateHighReply, output2.ToByteArray()); }