Skip to content
Merged
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
91 changes: 36 additions & 55 deletions scripts/ebounty.lic
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
game: Gemstone
tags: bounty, adventure's guild, advguild, bounties
required: Lich >= 5.12.10
version: 1.9.3
version: 1.9.4

Version Control:
Major_change.feature_addition.bugfix
v1.9.4 (2025-02-04)
- optimize location_list finding in forage_find room logic
v1.9.3 (2025-02-04)
- bugfix in forage_find room
v1.9.2 (2025-01-27)
Expand Down Expand Up @@ -2924,72 +2926,51 @@ module EBounty
def self.forage_find(herb, herb_fix, location)
EBounty.msg("debug", " #{__method__} | caller: #{caller[0]}")

case herb
when /ayana (weed|lichen|berry|root)/
herb = 'ayana leaf'
when /ayana'al (weed|lichen|berry|root)/
herb = "ayana'al leaf"
when 'trollear mushroom'
herb = 'trollfear mushroom'
end
# Normalize herb names
herb = case herb
when /ayana (weed|lichen|berry|root)/
'ayana leaf'
when /ayana'al (weed|lichen|berry|root)/
"ayana'al leaf"
when 'trollear mushroom'
'trollfear mushroom'
else
herb
end

herb_alt = herb.gsub(/^some /, "")
herb_pattern = /#{Regexp.escape(herb)}|#{Regexp.escape(herb_alt)}|#{Regexp.escape(herb_fix)}/

# Grab all the rooms that mostly match.
location_list = []
Room.list.find_all do |r|
if r.tags.any? { |tag| (tag.end_with? herb) || ((herb.start_with? tag) && herb =~ /ayana/) || (herb.end_with? tag) }
location_list.push(r.id)
end
end
# Find rooms with matching herb tags
location_list = Room.list.select do |r|
r.tags.any? { |tag| tag.end_with?(herb) || (herb.start_with?(tag) && herb =~ /ayana/) || herb.end_with?(tag) }
end.map(&:id)

# Reject the rooms with herbs that don't match
location_list = location_list.reject do |room|
!Room[room].tags.any? { |tag| tag =~ /#{herb}|#{herb_alt}|#{herb_fix}/ }
# Filter to rooms where tags actually match the herb pattern
location_list.select! do |room_id|
Room[room_id].tags.any? { |tag| tag =~ herb_pattern }
end

# This is for CLI herb foraging
# ;ebounty forage "<type of herb>" <number to find> for example ;ebounty forage "some acantha leaf" 3
if location == "nearest"
_previous, shortest_distances = Room.current.dijkstra
location_list.delete_if { |room_id| shortest_distances[room_id].nil? }
location_list = location_list.sort { |a, b| shortest_distances[a] <=> shortest_distances[b] }

location_list = location_list.first(10)

location_list.each do |room|
next if room.eql?(Room.current.id)
if Room.current.path_to(room).nil?
location_list.delete(room)
else
travel = Map.estimate_time(Room.current.path_to(room))
location_list.delete(room) if travel.to_i > 90
end
# Apply location filter if not "nearest"
if location != "nearest"
location_pattern = /#{Regexp.escape(location.strip)}/
location_list.select! do |room_id|
Room[room_id].location.to_s =~ location_pattern
end

return location_list
end

# Reject the locations that don't match
location_list = location_list.reject do |room|
Room[room].location.to_s !~ /#{location.strip}/
end

# Calculate distances and filter by reachability and distance
_previous, shortest_distances = Room.current.dijkstra
location_list.delete_if { |room_id| shortest_distances[room_id].nil? }
location_list = location_list.sort { |a, b| shortest_distances[a] <=> shortest_distances[b] }

location_list.each do |room|
next if room.eql?(Room.current.id)
if Room.current.path_to(room).nil?
location_list.delete(room)
else
travel = Map.estimate_time(Room.current.path_to(room))
location_list.delete(room) if travel.to_i > 90
end
end
location_list = location_list.select do |room_id|
distance = shortest_distances[room_id]
distance && distance <= 90
end.sort_by { |room_id| shortest_distances[room_id] }

# Limit to 10 nearest if location is "nearest"
location_list = location_list.first(10) if location == "nearest"

return location_list
location_list
end

def self.forage_bounty(herb, quantity, location = "nearest")
Expand Down