public static void Start(int npcId, INpcScript NPC, Character chr) { if (NPC == null) { return; } if (chr.NpcSession != null) { return; } var session = new NpcChatSession(npcId, chr); session.SetScript((INpcScript)NPC.GetType().GetMethod("MemberwiseClone", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(NPC, null)); session.HandleThing(); }
public static void HandleNPCChat(Character chr, Packet packet) { if (chr.NpcSession == null) { return; } NpcChatSession session = chr.NpcSession; byte state = packet.ReadByte(); if (state != session.mLastSentType) { InventoryPacket.NoChange(chr); return; } if (!session.WaitingForResponse) { InventoryPacket.NoChange(chr); return; } session.WaitingForResponse = false; Trace.WriteLine(packet.ToString()); byte option = packet.ReadByte(); try { switch (state) { case 0: switch (option) { case 0: // Back button... session.SendPreviousMessage(); break; case 1: // Next button... session.SendNextMessage(); break; default: session.Stop(); break; } break; case 1: switch (option) { case 0: // No. session.HandleThing(session.mRealState, 0, "", 0); break; case 1: // Yes. session.HandleThing(session.mRealState, 1, "", 0); break; default: session.Stop(); break; } break; case 2: switch (option) { case 0: // No text :( session.Stop(); break; case 1: // Oh yea, text session.HandleThing(session.mRealState, 1, packet.ReadString(), 0); break; default: session.Stop(); break; } break; case 3: switch (option) { case 0: // No int :( session.Stop(); break; case 1: // Oh yea, int session.HandleThing(session.mRealState, 1, "", packet.ReadShort()); break; default: session.Stop(); break; } break; case 4: case 5: switch (option) { case 0: // Stopping. session.Stop(); break; case 1: // Got answer var val = packet.ReadByte(); if (val == 255) { val = 0; // Menus do not correctly work when holding enter key } session.HandleThing(session.mRealState, val, "", 0); break; default: session.Stop(); break; } break; default: session.Stop(); Program.MainForm.LogAppend("Unknown NPC chat action: " + packet); break; } } catch (Exception ex) { Program.MainForm.LogAppend($"Exception while handling NPC {session.mID} {session.mRealState}. Packet: " + packet + ". Exception: " + ex); InventoryPacket.NoChange(chr); session?.Stop(); } }