Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dr][drdefs.rb] Simplify npc detection and add ordinals to them #739

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions lib/dragonrealms/drinfomon/drdefs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,32 @@ def find_pcs_sitting(room_players)
.map { |obj| obj.strip.scan(/\w+$/).first }
end

def find_npcs(room_objs)
def find_all_npcs(room_objs)
room_objs.sub(/You also see/, '').sub(/ with a [\w\s]+ sitting astride its back/, '').strip
.scan(%r{<pushBold/>[^<>]*<popBold/> which appears dead|<pushBold/>[^<>]*<popBold/> \(dead\)|<pushBold/>[^<>]*<popBold/>})
.reject { |obj| obj =~ /which appears dead|\(dead\)/ }
.map { |obj| obj.sub(/.*alfar warrior.*/, 'alfar warrior') }
.map { |obj| obj.sub(/.*sinewy leopard.*/, 'sinewy leopard') }
.map { |obj| obj.sub(/.*lesser naga.*/, 'lesser naga') }
.map { |obj| obj.sub(/.*Shadow Servant.*/, 'Shadow Servant') }
.map { |obj| obj.sub('<pushBold/>', '').sub(%r{<popBold/>.*}, '') }
.map { |obj| obj.split(/\sand\s/).last.sub(/(?:\sglowing)?\swith\s.*/, '') }
.map { |obj| obj.strip.scan(/[A-z'-]+$/).first }
end

def clean_npc_string(npc_string)
tmp_npc_string = npc_string.map { |obj| obj.sub(/.*alfar warrior.*/, 'alfar warrior') }
.map { |obj| obj.sub(/.*sinewy leopard.*/, 'sinewy leopard') }
.map { |obj| obj.sub(/.*lesser naga.*/, 'lesser naga') }
.map { |obj| obj.sub('<pushBold/>', '').sub(%r{<popBold/>.*}, '') }
.map { |obj| obj.split(/\sand\s/).last.sub(/(?:\sglowing)?\swith\s.*/, '') }
.map { |obj| obj.strip.scan(/[A-z'-]+$/).first }
.sort
flat_npcs = []
tmp_npc_string.uniq.each { |npc| flat_npcs << tmp_npc_string.size.times.select { |i| tmp_npc_string[i] == npc }.size.times.map { |number| number.zero? ? tmp_npc_string[0] : tmp_npc_string[number].sub(npc, "#{$ORDINALS[number]} #{npc}") } }
flat_npcs.flatten
end

def find_npcs(room_objs)
npcs = find_all_npcs(room_objs).reject { |obj| obj =~ /which appears dead|\(dead\)/ }
clean_npc_string(npcs)
end

def find_dead_npcs(room_objs)
room_objs.sub(/You also see/, '').sub(/ with a [\w\s]+ sitting astride its back/, '')
.strip.scan(%r{<pushBold/>[^<>]*<popBold/> which appears dead|<pushBold/>[^<>]*<popBold/> \(dead\)|<pushBold/>[^<>]*<popBold/>})
.select { |obj| obj =~ /which appears dead|\(dead\)/ }
.map { |obj| obj.sub('<pushBold/>', '').sub(%r{<popBold/>.*}, '') }
.map { |obj| obj.split(/\sand\s/).last.sub(/(?:\sglowing)?\swith\s.*/, '') }
.map { |obj| obj.strip.scan(/[A-z'-]+$/).first }
dead_npcs = find_all_npcs(room_objs).select { |obj| obj =~ /which appears dead|\(dead\)/ }
clean_npc_string(dead_npcs)
end

def find_objects(room_objs)
Expand Down
Loading