add geo info and do refractor on workers

This commit is contained in:
2021-04-29 20:44:21 +02:00
parent f7799bb514
commit c5190b48f8
32 changed files with 241 additions and 205 deletions

View File

@@ -0,0 +1,62 @@
# frozen_string_literal: true
class WowCharacterPositionsWorker < WowSidekiqWorker
def perform(wow_character_id)
return unless (wow_character = WowCharacter.find_by(character_id: wow_character_id))
# Protected data
RBattlenet.set_options(locale: 'all')
params = { character_id: wow_character_id, realm_id: wow_character.wow_realm.realm_id, token: wow_character.user.token }
result = RBattlenet::Wow::Profile::ProtectedSummary.find(params)
return unless result.status_code == 200
if (last_position = result.position)
wow_character_last_position = wow_character.last_position || WowGeoPosition.new(last_position_character: wow_character)
wow_character_last_position.wow_geo_zone = find_or_create_wow_geo_zone(last_position.zone)
wow_character_last_position.wow_geo_map = find_or_create_wow_geo_map(last_position.map)
wow_character_last_position.x = last_position.x
wow_character_last_position.y = last_position.y
wow_character_last_position.z = last_position.z
wow_character_last_position.facing = last_position.facing
wow_character_last_position.save
end
if (bind_position = result.bind_position)
wow_character_bind_position = wow_character.bind_position || WowGeoPosition.new(bind_position_character: wow_character)
wow_character_bind_position.wow_geo_zone = find_or_create_wow_geo_zone(bind_position.zone)
wow_character_bind_position.wow_geo_map = find_or_create_wow_geo_map(bind_position.map)
wow_character_bind_position.x = bind_position.x
wow_character_bind_position.y = bind_position.y
wow_character_bind_position.z = bind_position.z
wow_character_bind_position.facing = bind_position.facing
wow_character_bind_position.save
end
end
private
def find_or_create_wow_geo_zone(zone)
wow_geo_zone = WowGeoZone.find_or_initialize_by(zone_id: zone.id)
locales.each do |locale|
Mobility.with_locale(locale[0]) do
wow_geo_zone.name = zone.name[locale[1]]
end
end
wow_geo_zone.save
wow_geo_zone.persisted? ? wow_geo_zone : nil
end
def find_or_create_wow_geo_map(map)
wow_geo_map = WowGeoMap.find_or_initialize_by(map_id: map.id)
locales.each do |locale|
Mobility.with_locale(locale[0]) do
wow_geo_map.name = map.name[locale[1]]
end
end
wow_geo_map.save
wow_geo_map.persisted? ? wow_geo_map : nil
end
end