comparison Main.lua @ 96:e378295b2d6f

Handle keyword substitutions in NPC quotes for Race and Class.
author James D. Callahan III <jcallahan@curse.com>
date Thu, 30 Aug 2012 14:23:54 -0500
parents c4172766561f
children f6369b88454f
comparison
equal deleted inserted replaced
95:c4172766561f 96:e378295b2d6f
630 table.wipe(action_data) 630 table.wipe(action_data)
631 end 631 end
632 632
633 633
634 do 634 do
635 local function ReplaceName(text) 635 local KEYWORD_SUBSTITUTIONS = {
636 if text == PLAYER_NAME then 636 class = PLAYER_CLASS,
637 return "<name>" 637 name = PLAYER_NAME,
638 end 638 race = PLAYER_RACE,
639 }
640
641
642 local function ReplaceKeywords(text)
643 if not text or text == "" then
644 return ""
645 end
646
647 for category, lookup in pairs(KEYWORD_SUBSTITUTIONS) do
648 local category_format = ("<%s>"):format(category)
649 text = text:gsub(lookup, category_format):gsub(lookup:lower(), category_format)
650 end
651 return text
639 end 652 end
640 653
641 654
642 function WDP:RecordQuote(event_name, message, source_name, language_name) 655 function WDP:RecordQuote(event_name, message, source_name, language_name)
643 if not source_name or not name_to_id_map[source_name] or (language_name ~= "" and not languages_known[language_name]) then 656 if not source_name or not name_to_id_map[source_name] or (language_name ~= "" and not languages_known[language_name]) then
644 return 657 return
645 end 658 end
646 local npc = NPCEntry(name_to_id_map[source_name]) 659 local npc = NPCEntry(name_to_id_map[source_name])
647 npc.quotes = npc.quotes or {} 660 npc.quotes = npc.quotes or {}
648 npc.quotes[event_name] = npc.quotes[event_name] or {} 661 npc.quotes[event_name] = npc.quotes[event_name] or {}
649 npc.quotes[event_name][message:gsub("(%w+)", ReplaceName)] = true 662 npc.quotes[event_name][ReplaceKeywords(message)] = true
650 end 663 end
651 end -- do-block 664 end -- do-block
652 665
653 666
654 do 667 do