targetUtils.py (1202B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\parklife\targetUtils.py 2 from collections import namedtuple 3 from inventorycommon.const import categoryEntity 4 5 def get_closest_entity_target(target_priority = None, max_radius = 500000): 6 michelle = sm.GetService('michelle') 7 ballpark = michelle.GetBallpark() 8 if ballpark is None or michelle.InWarp(): 9 return 10 entities_in_range = ballpark.GetItemsAndDistanceByCategory(categoryID=categoryEntity, maxRadius=max_radius) 11 TargetCandidate = namedtuple('TargetCandidate', 'groupID, distance, itemID') 12 target_candidates = [ TargetCandidate(entity.groupID, distance, entity.itemID) for distance, entity in entities_in_range ] 13 if target_priority is None: 14 target_candidates = sorted(target_candidates, key=lambda candidate: candidate.distance) 15 else: 16 target_candidates = sorted([ candidate for candidate in target_candidates if candidate.groupID in target_priority ], key=lambda candidate: (target_priority.index(candidate.groupID), candidate.distance)) 17 if target_candidates: 18 _, _, closest_entity_id = target_candidates[0] 19 return closest_entity_id