NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

utils.py (12294B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\dailygoals\client\utils.py
      2 import uuid
      3 import logging
      4 from dailygoals.client.const import RewardType
      5 from eveProto.monolith_converters.units import get_single_value_from_split_precision_message
      6 from goals.common.goalConst import CAREER_PATH_IDS, ContributionMethodTypes
      7 from industry.const import ON_BEHALF_OF_CORP, ON_BEHALF_OF_SELF
      8 from inventorycommon.const import typeskillpoints10000, typeskillpoints25000, typeskillpoints50000, typeskillpoints75000, typeskillpoints100000, typeskillpoints150000, typeskillpoints250000, typeskillpoints500000, typeskillpoints750000
      9 logger = logging.getLogger('dailygoals')
     10 
     11 def format_goal_from_payload(goal_id, goal_attributes, goal_progress, earnings, paid_completion = False):
     12     try:
     13         contribution_method_id, contribution_fields = _format_contribution_config(goal_attributes.contribution_configuration)
     14     except Exception as e:
     15         logger.exception(e)
     16         return None
     17 
     18     formatted_goal = {'goal_id': goal_id,
     19      'category': goal_attributes.category,
     20      'career_id': CAREER_PATH_IDS[goal_attributes.career],
     21      'assigner_id': goal_attributes.assigner.sequential,
     22      'contribution_method_id': contribution_method_id,
     23      'contribution_fields': contribution_fields,
     24      'name_id': goal_attributes.name_message.sequential,
     25      'desc_id': goal_attributes.description_message.sequential,
     26      'help_text_id': goal_attributes.help_text_message.sequential,
     27      'target': goal_attributes.target,
     28      'active_after': goal_attributes.active_after.ToDatetime(),
     29      'active_until': goal_attributes.active_until.ToDatetime(),
     30      'progress': goal_progress,
     31      'rewards': [],
     32      'has_earnings': bool(earnings),
     33      'omega_restricted_earnings': earnings[0].omega_required if earnings else goal_attributes.omega,
     34      'is_omega': goal_attributes.omega,
     35      'paid_completion': paid_completion}
     36     for payment in goal_attributes.payment:
     37         reward_info = get_reward_info_from_unit(payment.unit)
     38         if not reward_info:
     39             continue
     40         reward_info['asset_id'] = uuid.UUID(bytes=payment.asset.uuid)
     41         formatted_goal['rewards'].append(reward_info)
     42 
     43     return formatted_goal
     44 
     45 
     46 def get_reward_info_from_unit(unit):
     47     reward_info = {}
     48     if unit.HasField('isk'):
     49         reward_info['reward_type'] = RewardType.ISK
     50         reward_info['amount'] = get_single_value_from_split_precision_message(unit.isk.amount)
     51     elif unit.HasField('lp'):
     52         reward_info['reward_type'] = RewardType.LOYALTY_POINTS
     53         reward_info['amount'] = unit.lp.amount.amount
     54     elif unit.HasField('sp'):
     55         reward_info['reward_type'] = RewardType.SKILL_POINTS
     56         reward_info['amount'] = unit.sp.amount
     57     elif unit.HasField('plex'):
     58         reward_info['reward_type'] = RewardType.PLEX
     59         reward_info['amount'] = unit.plex.amount.total_in_cents / 100
     60     elif unit.HasField('item'):
     61         reward_info['reward_type'] = RewardType.ITEM
     62         reward_info['amount'] = unit.item.amount
     63         reward_info['item_type_id'] = unit.item.type.sequential
     64     return reward_info
     65 
     66 
     67 def _format_contribution_config(config):
     68     if config.HasField('kill_npc'):
     69         methods = _construct_kill_npc_dict_from_proto(config.kill_npc.contribution_methods)
     70         return (ContributionMethodTypes.KILL_NPC, methods[0] if len(methods) > 0 else {})
     71     if config.HasField('damage_ship'):
     72         methods = _construct_damage_ship_dict_from_proto(config.damage_ship.contribution_methods)
     73         return (ContributionMethodTypes.DAMAGE_SHIP, methods[0] if len(methods) > 0 else {})
     74     if config.HasField('mine_ore'):
     75         methods = _construct_mine_ore_dict_from_proto(config.mine_ore.contribution_methods)
     76         return (ContributionMethodTypes.MINE_ORE, methods[0] if len(methods) > 0 else {})
     77     if config.HasField('fw_capture'):
     78         methods = _construct_capture_fw_complex_dict_from_proto(config.fw_capture.contribution_methods)
     79         return (ContributionMethodTypes.CAPTURE_FACWAR_COMPLEX, methods[0] if len(methods) > 0 else {})
     80     if config.HasField('fw_defend'):
     81         methods = _construct_defend_fw_complex_dict_from_proto(config.fw_defend.contribution_methods)
     82         return (ContributionMethodTypes.DEFEND_FACWAR_COMPLEX, methods[0] if len(methods) > 0 else {})
     83     if config.HasField('remote_shield_repair'):
     84         methods = _construct_remote_repair_dict_from_proto(config.remote_shield_repair.contribution_methods)
     85         return (ContributionMethodTypes.REMOTE_REPAIR_SHIELD, methods[0] if len(methods) > 0 else {})
     86     if config.HasField('remote_armor_repair'):
     87         methods = _construct_remote_repair_dict_from_proto(config.remote_armor_repair.contribution_methods)
     88         return (ContributionMethodTypes.REMOTE_REPAIR_ARMOR, methods[0] if len(methods) > 0 else {})
     89     if config.HasField('scan_signature'):
     90         methods = _construct_scan_signature_dict_from_proto(config.scan_signature.contribution_methods)
     91         return (ContributionMethodTypes.SCAN_SIGNATURE, methods[0] if len(methods) > 0 else {})
     92     if config.HasField('install_manufacturing_job'):
     93         methods = _construct_install_manufacturing_job_dict_from_proto(config.install_manufacturing_job.contribution_methods)
     94         return (ContributionMethodTypes.MANUFACTURE_ITEM, methods[0] if len(methods) > 0 else {})
     95     if config.HasField('complete_daily_goal'):
     96         methods = _construct_complete_goals_dict_from_proto(config.complete_daily_goal.contribution_methods)
     97         return (ContributionMethodTypes.COMPLETE_GOAL, methods[0] if len(methods) > 0 else {})
     98     if config.HasField('salvage_wreck'):
     99         methods = _construct_salvage_wreck_dict_from_proto(config.salvage_wreck.contribution_methods)
    100         return (ContributionMethodTypes.SALVAGE_WRECK, methods[0] if len(methods) > 0 else {})
    101     if config.HasField('earn_loyalty_points'):
    102         methods = _construct_earn_loyalty_points_dict_from_proto(config.earn_loyalty_points.contribution_methods)
    103         return (ContributionMethodTypes.EARN_LOYALTY_POINTS, methods[0] if len(methods) > 0 else {})
    104     if config.HasField('space_jump'):
    105         return (ContributionMethodTypes.SPACE_JUMP, {})
    106 
    107 
    108 def _get_value_from_generic_matcher(matcher):
    109     if matcher.HasField('match_value'):
    110         return matcher.match_value.sequential
    111     else:
    112         return None
    113 
    114 
    115 def _construct_kill_npc_dict_from_proto(data):
    116     result = []
    117     for method in data:
    118         result.append({'solar_system': _get_value_from_generic_matcher(method.solar_system)})
    119 
    120     return result
    121 
    122 
    123 def _construct_damage_ship_dict_from_proto(data):
    124     result = []
    125     for method in data:
    126         result.append({'solar_system': _get_value_from_generic_matcher(method.solar_system),
    127          'ship': _get_value_from_generic_matcher(method.ship_type),
    128          'organization': _get_identity_from_matcher(method.identity)})
    129 
    130     return result
    131 
    132 
    133 def _construct_mine_ore_dict_from_proto(data):
    134     result = []
    135     for method in data:
    136         result.append({'solar_system': _get_value_from_generic_matcher(method.solar_system),
    137          'ore': _get_ore_type_from_matcher(method.ore)})
    138 
    139     return result
    140 
    141 
    142 def _construct_capture_fw_complex_dict_from_proto(data):
    143     result = []
    144     for method in data:
    145         result.append({'solar_system': _get_value_from_generic_matcher(method.solar_system),
    146          'faction': _get_value_from_generic_matcher(method.previous_owner),
    147          'complex_type': _get_value_from_generic_matcher(method.archetype)})
    148 
    149     return result
    150 
    151 
    152 def _construct_defend_fw_complex_dict_from_proto(data):
    153     result = []
    154     for method in data:
    155         result.append({'solar_system': _get_value_from_generic_matcher(method.solar_system),
    156          'faction': _get_value_from_generic_matcher(method.owner),
    157          'complex_type': _get_value_from_generic_matcher(method.archetype)})
    158 
    159     return result
    160 
    161 
    162 def _construct_remote_repair_dict_from_proto(data):
    163     result = []
    164     for method in data:
    165         result.append({'solar_system': _get_value_from_generic_matcher(method.solar_system),
    166          'ship': _get_value_from_generic_matcher(method.ship_type),
    167          'organization': _get_identity_from_matcher(method.identity)})
    168 
    169     return result
    170 
    171 
    172 def _construct_scan_signature_dict_from_proto(data):
    173     result = []
    174     for method in data:
    175         result.append({'solar_system': _get_value_from_generic_matcher(method.solar_system),
    176          'signature_type': _get_value_from_generic_matcher(method.signature_type)})
    177 
    178     return result
    179 
    180 
    181 def _construct_install_manufacturing_job_dict_from_proto(data):
    182     result = []
    183     for method in data:
    184         result.append({'owner': _get_owner_type_from_matcher(method.job_owner_type),
    185          'facility_location': _get_job_location_from_matcher(method.job_location),
    186          'item_type': _get_item_type_from_matcher(method.item_type)})
    187 
    188     return result
    189 
    190 
    191 def _construct_complete_goals_dict_from_proto(data):
    192     result = []
    193     for method in data:
    194         result.append({'daily_goal': _get_goal_id_from_matcher(method.daily_goal)})
    195 
    196     return result
    197 
    198 
    199 def _construct_salvage_wreck_dict_from_proto(data):
    200     result = []
    201     for method in data:
    202         result.append({'solar_system': _get_value_from_generic_matcher(method.solar_system)})
    203 
    204     return result
    205 
    206 
    207 def _construct_earn_loyalty_points_dict_from_proto(data):
    208     result = []
    209     for method in data:
    210         result.append({'corporation_id': _get_value_from_generic_matcher(method.corporation)})
    211 
    212     return result
    213 
    214 
    215 def _get_identity_from_matcher(matcher):
    216     if matcher.HasField('match_character_value'):
    217         return matcher.match_character_value.sequential
    218     elif matcher.HasField('match_corporation_value'):
    219         return matcher.match_corporation_value.sequential
    220     elif matcher.HasField('match_alliance_value'):
    221         return matcher.match_alliance_value.sequential
    222     elif matcher.HasField('match_faction_value'):
    223         return matcher.match_faction_value.sequential
    224     else:
    225         return None
    226 
    227 
    228 def _get_owner_type_from_matcher(matcher):
    229     if matcher.HasField('match_any_character'):
    230         return ON_BEHALF_OF_SELF
    231     elif matcher.HasField('match_any_corporation'):
    232         return ON_BEHALF_OF_CORP
    233     else:
    234         return None
    235 
    236 
    237 def _get_job_location_from_matcher(matcher):
    238     if matcher.HasField('station'):
    239         return matcher.station.sequential
    240     elif matcher.HasField('structure'):
    241         return matcher.structure.sequential
    242     else:
    243         return None
    244 
    245 
    246 def _get_item_type_from_matcher(matcher):
    247     if matcher.HasField('item_type'):
    248         return matcher.item_type.sequential
    249     else:
    250         return None
    251 
    252 
    253 def _get_ore_type_from_matcher(matcher):
    254     if matcher.HasField('ore'):
    255         return matcher.ore.sequential
    256     else:
    257         return None
    258 
    259 
    260 def _get_goal_id_from_matcher(matcher):
    261     if matcher.HasField('goal'):
    262         return uuid.UUID(bytes=matcher.goal.uuid)
    263     else:
    264         return None
    265 
    266 
    267 def find_skill_icon_from_amount(amount):
    268     if amount <= 10000:
    269         return 'res:/UI/Texture/Icons/SkillPoints/10k.png'
    270     if amount <= 25000:
    271         return 'res:/UI/Texture/Icons/SkillPoints/25k.png'
    272     if amount <= 50000:
    273         return 'res:/UI/Texture/Icons/SkillPoints/50k.png'
    274     if amount <= 100000:
    275         return 'res:/UI/Texture/Icons/SkillPoints/100k.png'
    276     if amount <= 150000:
    277         return 'res:/UI/Texture/Icons/SkillPoints/150k.png'
    278     if amount <= 250000:
    279         return 'res:/UI/Texture/Icons/SkillPoints/250k.png'
    280     if amount <= 500000:
    281         return 'res:/UI/Texture/Icons/SkillPoints/500k.png'
    282     if amount <= 750000:
    283         return 'res:/UI/Texture/Icons/SkillPoints/750k.png'
    284     return 'res:/UI/Texture/Icons/SkillPoints/1m.png'
    285 
    286 
    287 def find_type_id_from_amount(amount):
    288     if amount <= 10000:
    289         return typeskillpoints10000
    290     if amount <= 25000:
    291         return typeskillpoints25000
    292     if amount <= 50000:
    293         return typeskillpoints50000
    294     if amount <= 75000:
    295         return typeskillpoints75000
    296     if amount <= 100000:
    297         return typeskillpoints100000
    298     if amount <= 150000:
    299         return typeskillpoints150000
    300     if amount <= 250000:
    301         return typeskillpoints250000
    302     if amount <= 500000:
    303         return typeskillpoints500000
    304     return typeskillpoints750000