server/gamedata/npc_scripts_test.go (5661B)
1 package gamedata_test 2 3 import ( 4 "ao/server/gamedata" 5 "strings" 6 "testing" 7 ) 8 9 func TestNPCScriptsResolveMaintainedGroups(t *testing.T) { 10 names := map[string]string{ 11 "710/district/0/fixed/23": "Ida Schuller", 12 "710/district/0/fixed/22": "Horatio Campbell", 13 "550/district/8/fixed/3": "Sam Cadena", 14 "545/district/1/fixed/8": "Mr. Gips", 15 "600/district/7/fixed/8": "Eric Mendelson", 16 "610/district/11/fixed/1": "Richelieu", 17 "550/district/2/fixed/9": "Sun Tzu", 18 "565/district/13/fixed/0": "Stolt Jensenberg", 19 "560/district/18/fixed/4": "Zoftig Blimp", 20 "610/district/1/fixed/46": "Tsunayoshi Smith", 21 "595/district/8/fixed/0": "Kendric Kuzio", 22 "685/district/5/fixed/0": "Susan Furor", 23 "1941/district/0/fixed/179": "Quintus Romulus", 24 "1833/district/0/fixed/0": "Janella Gheron", 25 "125/district/0/fixed/218": "Robin Raag", 26 "566/district/1/fixed/5": "Good Time Party Mixer", 27 } 28 29 if len(gamedata.NPCScripts) != len(names) { 30 t.Fatalf("got %d NPC scripts, want %d", len(gamedata.NPCScripts), len(names)) 31 } 32 for id, script := range gamedata.NPCScripts { 33 group := gamedata.NPCGroups[id] 34 if group == nil || names[id] == "" || group.Name != names[id] { 35 t.Fatalf("script %s does not resolve to its maintained NPC", id) 36 } 37 if !strings.HasPrefix(script.Source, "https://anarchyonline.fandom.com/wiki/") || script.Talk == nil { 38 t.Fatalf("script %s has no source or conversation", id) 39 } 40 } 41 } 42 43 func TestIdaSchullerRecordedConversation(t *testing.T) { 44 script := gamedata.NPCScripts["710/district/0/fixed/23"] 45 46 greeting := script.Talk("") 47 answer := script.Talk("topic-1") 48 49 if greeting.Text != "Hi." || len(greeting.Choices) != 21 { 50 t.Fatalf("unexpected Ida greeting: %#v", greeting) 51 } 52 if greeting.Choices[0].ID != "topic-1" || greeting.Choices[0].Text != "Tell me about yourself." { 53 t.Fatalf("unexpected first topic: %#v", greeting.Choices[0]) 54 } 55 if !strings.HasPrefix(answer.Text, "I'm Ida Sculler. I'm a nano-technician.") || !strings.Contains(answer.Text, "\nShe smiles brightly at you.\n") { 56 t.Fatalf("Ida answer lost recorded speech or narration: %q", answer.Text) 57 } 58 } 59 60 func TestNPCScriptChoicesFitNativeConversationProtocol(t *testing.T) { 61 topicCount := 0 62 for id, script := range gamedata.NPCScripts { 63 greeting := script.Talk("") 64 unknown := script.Talk("not-a-recorded-choice") 65 66 if len(greeting.Choices) < 1 || len(greeting.Choices) > 1000 || len(greeting.Text) > 10000 { 67 t.Fatalf("script %s has an invalid opening", id) 68 } 69 if greeting.Text == "" && gamedata.NPCGroups[id].Name != "Sun Tzu" { 70 t.Fatalf("script %s lost its recorded greeting", id) 71 } 72 if unknown.Text != "" || len(unknown.Choices) != 0 { 73 t.Fatalf("script %s accepted an unrecorded choice", id) 74 } 75 seen := make(map[string]bool) 76 texts := []string{greeting.Text} 77 for _, choice := range greeting.Choices { 78 if choice.ID == "" || seen[choice.ID] || len(choice.Text) < 1 || len(choice.Text) > 1000 { 79 t.Fatalf("script %s has an invalid or duplicate choice: %#v", id, choice) 80 } 81 seen[choice.ID] = true 82 answer := script.Talk(choice.ID) 83 if len(answer.Text) < 1 || len(answer.Text) > 10000 || (choice.ID != "goodbye" && len(answer.Choices) != len(greeting.Choices)) || (choice.ID == "goodbye" && len(answer.Choices) != 0) { 84 t.Fatalf("script %s choice %s has an invalid answer", id, choice.ID) 85 } 86 texts = append(texts, choice.ID, choice.Text, answer.Text) 87 topicCount++ 88 } 89 for _, text := range texts { 90 for _, character := range text { 91 if character > 127 || (character < 32 && character != '\n' && character != '\t') { 92 t.Fatalf("script %s contains unsupported conversation text: %q", id, text) 93 } 94 } 95 } 96 } 97 if topicCount != 164 { 98 t.Fatalf("got %d recovered topics, want 164", topicCount) 99 } 100 } 101 102 func TestNPCScriptsOmitUnrecoveredOrUnsupportedTopics(t *testing.T) { 103 omitted := map[string][]string{ 104 "710/district/0/fixed/23": {"topic-20", "topic-21"}, 105 "710/district/0/fixed/22": {"topic-19", "topic-20", "topic-21", "topic-22"}, 106 "550/district/8/fixed/3": {"topic-39"}, 107 "545/district/1/fixed/8": {"topic-13"}, 108 "610/district/11/fixed/1": {"topic-8"}, 109 "550/district/2/fixed/9": {"topic-6"}, 110 "595/district/8/fixed/0": {"topic-7"}, 111 "685/district/5/fixed/0": {"topic-4"}, 112 "1941/district/0/fixed/179": {"topic-6", "topic-7"}, 113 "1833/district/0/fixed/0": {"topic-2"}, 114 "125/district/0/fixed/218": {"topic-7", "topic-8"}, 115 "566/district/1/fixed/5": {"topic-2"}, 116 } 117 118 for id, choices := range omitted { 119 for _, choice := range choices { 120 answer := gamedata.NPCScripts[id].Talk(choice) 121 if answer.Text != "" || len(answer.Choices) != 0 { 122 t.Fatalf("script %s exposes omitted topic %s", id, choice) 123 } 124 } 125 } 126 } 127 128 func TestEricMendelsonRecordedFarewellClosesConversation(t *testing.T) { 129 script := gamedata.NPCScripts["600/district/7/fixed/8"] 130 131 answer := script.Talk("goodbye") 132 133 if answer.Text != "Goodbye." || len(answer.Choices) != 0 { 134 t.Fatalf("unexpected Eric farewell: %#v", answer) 135 } 136 } 137 138 func TestQuestNPCsRetainRecordedLore(t *testing.T) { 139 cases := []struct { 140 id string 141 topic string 142 text string 143 }{ 144 {"595/district/8/fixed/0", "topic-5", "Winford was my best hunting buddy"}, 145 {"1941/district/0/fixed/179", "topic-2", "I'm Dr. Romelus- I'm a doctor researching"}, 146 {"125/district/0/fixed/218", "topic-5", "I am studying the effects of strong magnetic fields"}, 147 } 148 for _, test := range cases { 149 answer := gamedata.NPCScripts[test.id].Talk(test.topic) 150 151 if !strings.Contains(answer.Text, test.text) { 152 t.Fatalf("NPC %s lost its recorded lore: %q", test.id, answer.Text) 153 } 154 } 155 }