void NpcThinkingFunc(int time) { this.thinkTime += time; if (thinkTime > 1500) { thinkTime = 0; //TODO by the character emotion Random ran = new Random(); bool notfound = true; do { int a = ran.Next(0, GlobalController.NpcPositionList.Count); if (!GlobalController.NpcPositionList[a].IsUsing) { this.targetPosition = GlobalController.NpcPositionList[a]; GlobalController.NpcPositionList[a].IsUsing = true; notfound = false; } }while (notfound); this.path.Clear(); this.action = "move"; this.emotion = string.Empty; } else { this.emotion = "nosay"; } }
private async Task AquireTargetAtCursor(Point clickPostion, NpcPosition npc, bool leftClick = false) { if (leftClick) { await input.LeftClickMouse(clickPostion); } else { await input.RightClickMouse(clickPostion); } logger.LogInformation($"{ this.GetType().Name}.FindAndClickNpc: NPC found! Height={npc.Height}, width={npc.Width}, pos={clickPostion}"); }
//发送Npc位置信息 public void SendNpcPosition(float posX, float posY, float posZ, float angleX, float angleY, float angleZ, int npcId, int npcType, UInt16 stationIndex, UInt16 stationClientType) { if (m_stationModule == null || m_networkModule == null) { return; } List <PlayerActor> u3dPlayerActorList = null; m_stationModule.GetU3DPlayerActors(stationIndex, ref u3dPlayerActorList); if (u3dPlayerActorList == null || u3dPlayerActorList.Count == 0) { return; } PlayerActor stationPlayerActor = null; for (int k = 0; k < u3dPlayerActorList.Count; k++) { stationPlayerActor = m_networkModule.GetStationPlayerActorAboutU3DPlayerActor(u3dPlayerActorList[k], stationIndex, stationClientType); if (stationPlayerActor != null) { Agent agent = stationPlayerActor.Agent; NpcPosition npcPos = new NpcPosition() { m_posX = posX, m_posY = posY, m_posZ = posZ, m_angleX = angleX, m_angleY = angleY, m_angleZ = angleZ, m_npcId = npcId, m_npcType = npcType, m_stationIndex = stationIndex, m_stationClientType = stationClientType, }; byte[] bytes = npcPos.Packet2Bytes(); UInt16 sendId = TDFramework.SingletonMgr.GameGlobalInfo.ServerInfo.Id; UInt16 u3dId = 0; UInt16 msgLen = (UInt16)bytes.Length; Packet packet = new Packet(sendId, u3dId, SingletonMgr.MessageIDMgr.NpcPositionMessageID, msgLen, bytes); agent.SendPacket(packet.Packet2Bytes()); } } }
//客户端重连,同步Npc位置信息 public void SendNpcPositionRelink(PlayerActor stationPlayerActor, float posX, float posY, float posZ, float angleX, float angleY, float angleZ, int npcId, int npcType, UInt16 stationIndex, UInt16 stationClientType) { if (m_networkModule == null) { return; } if (stationPlayerActor == null) { return; } Agent agent = stationPlayerActor.Agent; NpcPosition npcPos = new NpcPosition() { m_posX = posX, m_posY = posY, m_posZ = posZ, m_angleX = angleX, m_angleY = angleY, m_angleZ = angleZ, m_npcId = npcId, m_npcType = npcType, m_stationIndex = stationIndex, m_stationClientType = stationClientType, }; byte[] bytes = npcPos.Packet2Bytes(); UInt16 sendId = TDFramework.SingletonMgr.GameGlobalInfo.ServerInfo.Id; UInt16 u3dId = 0; UInt16 msgLen = (UInt16)bytes.Length; Packet packet = new Packet(sendId, u3dId, SingletonMgr.MessageIDMgr.NpcPositionMessageID, msgLen, bytes); agent.SendPacket(packet.Packet2Bytes()); }