# HG changeset patch # User James D. Callahan III # Date 1346354634 18000 # Node ID e378295b2d6f8118142e10a08f87592028050340 # Parent c4172766561fa6a10f0ce88f87bb4fb01f9b1c74 Handle keyword substitutions in NPC quotes for Race and Class. diff -r c4172766561f -r e378295b2d6f Main.lua --- a/Main.lua Wed Aug 29 15:24:29 2012 -0500 +++ b/Main.lua Thu Aug 30 14:23:54 2012 -0500 @@ -632,10 +632,23 @@ do - local function ReplaceName(text) - if text == PLAYER_NAME then - return "" + local KEYWORD_SUBSTITUTIONS = { + class = PLAYER_CLASS, + name = PLAYER_NAME, + race = PLAYER_RACE, + } + + + local function ReplaceKeywords(text) + if not text or text == "" then + return "" end + + for category, lookup in pairs(KEYWORD_SUBSTITUTIONS) do + local category_format = ("<%s>"):format(category) + text = text:gsub(lookup, category_format):gsub(lookup:lower(), category_format) + end + return text end @@ -646,7 +659,7 @@ local npc = NPCEntry(name_to_id_map[source_name]) npc.quotes = npc.quotes or {} npc.quotes[event_name] = npc.quotes[event_name] or {} - npc.quotes[event_name][message:gsub("(%w+)", ReplaceName)] = true + npc.quotes[event_name][ReplaceKeywords(message)] = true end end -- do-block