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

goalMessengerUtil.py (31920B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\corporation\client\goals\goalMessengerUtil.py
      2 import eveProto.generated.eve_public.corporationgoal.contribution.configuration_pb2 as CorpGoalContributionConfiguration
      3 import evetypes
      4 import logging
      5 import shipgroup
      6 import uuid
      7 from eve.common.script.sys import idCheckers
      8 from eveProto.generated.eve_public.goal.goal_pb2 import ContributionConfiguration
      9 from eveProto.monolith_converters.units import get_single_value_from_split_precision_message
     10 from goals.common.errors import ContributionMethodTypeNotSupported
     11 from goals.common.goalConst import ConflictType
     12 from goals.common.goalConst import ContributionMethodTypes, OrganizationType, CAREER_PATH_IDS
     13 from industry.const import ON_BEHALF_OF_SELF, ON_BEHALF_OF_CORP
     14 from localization import GetByMessageID
     15 logger = logging.getLogger('corporation_goals')
     16 
     17 def add_owner_identity_to_proto(identity_type, matcher):
     18     if identity_type is None:
     19         matcher.identity.any = True
     20     elif idCheckers.IsCharacter(identity_type):
     21         matcher.identity.match_character_value.sequential = identity_type
     22     elif idCheckers.IsCorporation(identity_type):
     23         matcher.identity.match_corporation_value.sequential = identity_type
     24     elif idCheckers.IsAlliance(identity_type):
     25         matcher.identity.match_alliance_value.sequential = identity_type
     26     elif idCheckers.IsFaction(identity_type):
     27         matcher.identity.match_faction_value.sequential = identity_type
     28 
     29 
     30 def add_owner_identities_to_proto(identities, set_matcher):
     31     if not identities:
     32         set_matcher.all = True
     33         return
     34     for identity_id in identities:
     35         if idCheckers.IsCharacter(identity_id):
     36             matcher = set_matcher.sets.characters.add()
     37             matcher.character.sequential = identity_id
     38         elif idCheckers.IsCorporation(identity_id):
     39             matcher = set_matcher.sets.characters.add()
     40             matcher.corporation.sequential = identity_id
     41         elif idCheckers.IsAlliance(identity_id):
     42             matcher = set_matcher.sets.characters.add()
     43             matcher.alliance.sequential = identity_id
     44         elif idCheckers.IsFaction(identity_id):
     45             matcher = set_matcher.sets.characters.add()
     46             matcher.faction.sequential = identity_id
     47 
     48 
     49 def get_owner_identity_from_proto(identity):
     50     if identity.HasField('match_character_value'):
     51         return int(identity.match_character_value.sequential)
     52     if identity.HasField('match_corporation_value'):
     53         return int(identity.match_corporation_value.sequential)
     54     if identity.HasField('match_alliance_value'):
     55         return int(identity.match_alliance_value.sequential)
     56     if identity.HasField('match_faction_value'):
     57         return int(identity.match_faction_value.sequential)
     58 
     59 
     60 def get_owner_identities_from_proto(identities):
     61     if not identities.HasField('sets'):
     62         return None
     63     result = set()
     64     for entry in identities.sets.characters:
     65         if entry.HasField('character'):
     66             result.add(int(entry.character.sequential))
     67         elif entry.HasField('corporation'):
     68             result.add(int(entry.corporation.sequential))
     69         elif entry.HasField('alliance'):
     70             result.add(int(entry.alliance.sequential))
     71         elif entry.HasField('faction'):
     72             result.add(int(entry.faction.sequential))
     73 
     74     if result:
     75         return list(result)
     76 
     77 
     78 def add_conflict_type_to_proto(conflict_type, matcher):
     79     if conflict_type == ConflictType.ALL:
     80         matcher.all = True
     81     elif conflict_type == ConflictType.PVP:
     82         matcher.pvp = True
     83     elif conflict_type == ConflictType.PVE:
     84         matcher.pve = True
     85 
     86 
     87 def get_conflict_type_from_proto(conflict_type):
     88     if conflict_type.HasField('all'):
     89         return ConflictType.ALL
     90     if conflict_type.HasField('pvp'):
     91         return ConflictType.PVP
     92     if conflict_type.HasField('pve'):
     93         return ConflictType.PVE
     94 
     95 
     96 def add_corporations_to_proto(corporations, set_matcher):
     97     if not corporations:
     98         set_matcher.all = True
     99         return
    100     for corporation_id in corporations:
    101         if idCheckers.IsCorporation(corporation_id):
    102             matcher = set_matcher.set.ids.add()
    103             matcher.sequential = corporation_id
    104 
    105 
    106 def get_corporations_from_proto(identities):
    107     if not identities.HasField('set'):
    108         return None
    109     result = set()
    110     for entry in identities.set.ids:
    111         result.add(int(entry.sequential))
    112 
    113     if result:
    114         return list(result)
    115 
    116 
    117 def add_ship_type_to_proto(ship_type, matcher):
    118     if ship_type is None:
    119         matcher.ship_type.any = True
    120     else:
    121         matcher.ship_type.match_value.sequential = ship_type
    122 
    123 
    124 def add_ships_to_proto(ships, set_matcher):
    125     if not ships:
    126         set_matcher.all = True
    127         return
    128     for entry_type, entry_id in ships:
    129         if entry_type == 'ship_type':
    130             if idCheckers.IsShipType(entry_id):
    131                 matcher = set_matcher.sets.ships.add()
    132                 matcher.ship_type.sequential = entry_id
    133         elif entry_type == 'ship_class':
    134             if entry_id in shipgroup.ALL_GROUPS:
    135                 matcher = set_matcher.sets.ships.add()
    136                 matcher.ship_class.sequential = entry_id
    137 
    138 
    139 def get_ship_type_from_proto(ship_type):
    140     if ship_type.HasField('match_value'):
    141         return int(ship_type.match_value.sequential)
    142 
    143 
    144 def get_ships_from_proto(ships):
    145     if not ships.HasField('sets'):
    146         return None
    147     result = set()
    148     for entry in ships.sets.ships:
    149         if entry.HasField('ship_type'):
    150             result.add(('ship_type', int(entry.ship_type.sequential)))
    151         elif entry.HasField('ship_class'):
    152             result.add(('ship_class', int(entry.ship_class.sequential)))
    153 
    154     if result:
    155         return list(result)
    156 
    157 
    158 def add_ores_to_proto(ores, set_matcher):
    159     if not ores:
    160         set_matcher.all = True
    161         return
    162     allowed_type_ids = evetypes.GetTypeIDsByListID(evetypes.TYPE_LIST_ALL_MINABLE_TYPES)
    163     allowed_group_ids = {evetypes.GetGroupID(type_id) for type_id in allowed_type_ids}
    164     for entry_type, entry_id in ores:
    165         if entry_type == 'item_type':
    166             if entry_id in allowed_type_ids:
    167                 matcher = set_matcher.sets.ores.add()
    168                 matcher.ore_type.sequential = entry_id
    169         elif entry_type == 'item_group':
    170             if entry_id in allowed_group_ids:
    171                 matcher = set_matcher.sets.ores.add()
    172                 matcher.ore_group.sequential = entry_id
    173 
    174 
    175 def get_ores_from_proto(ores):
    176     if not ores.HasField('sets'):
    177         return None
    178     result = set()
    179     for entry in ores.sets.ores:
    180         if entry.HasField('ore_type'):
    181             result.add(('item_type', int(entry.ore_type.sequential)))
    182         elif entry.HasField('ore_group'):
    183             result.add(('item_group', int(entry.ore_group.sequential)))
    184 
    185     if result:
    186         return list(result)
    187 
    188 
    189 def add_solar_system_to_proto(solar_system, matcher):
    190     if solar_system is None:
    191         matcher.solar_system.any = True
    192     else:
    193         matcher.solar_system.match_value.sequential = solar_system
    194 
    195 
    196 def add_solar_systems_to_proto(solar_systems, set_matcher):
    197     if not solar_systems:
    198         set_matcher.all = True
    199         return
    200     for location_id in solar_systems:
    201         if idCheckers.IsSolarSystem(location_id):
    202             matcher = set_matcher.sets.systems.add()
    203             matcher.solar_system.sequential = location_id
    204         elif idCheckers.IsConstellation(location_id):
    205             matcher = set_matcher.sets.systems.add()
    206             matcher.constellation.sequential = location_id
    207         elif idCheckers.IsRegion(location_id):
    208             matcher = set_matcher.sets.systems.add()
    209             matcher.region.sequential = location_id
    210 
    211 
    212 def get_solar_system_from_proto(solar_system):
    213     if solar_system.HasField('match_value'):
    214         return int(solar_system.match_value.sequential)
    215 
    216 
    217 def get_solar_systems_from_proto(solar_systems):
    218     if not solar_systems.HasField('sets'):
    219         return None
    220     result = set()
    221     for entry in solar_systems.sets.systems:
    222         if entry.HasField('solar_system'):
    223             result.add(entry.solar_system.sequential)
    224         elif entry.HasField('constellation'):
    225             result.add(entry.constellation.sequential)
    226         elif entry.HasField('region'):
    227             result.add(entry.region.sequential)
    228 
    229     if result:
    230         return list(result)
    231 
    232 
    233 def construct_generic_ship_dict_from_proto(data, as_multi_value = False):
    234     solar_system_id = get_solar_system_from_proto(data.solar_system)
    235     ship_type = get_ship_type_from_proto(data.ship_type)
    236     organization_type = get_owner_identity_from_proto(data.identity)
    237     if as_multi_value:
    238         return {'solar_system': [solar_system_id] if solar_system_id else None,
    239          'ship': [('ship_type', ship_type)] if ship_type else None,
    240          'organization': [organization_type] if organization_type else None}
    241     else:
    242         return {'solar_system': solar_system_id,
    243          'ship': ship_type,
    244          'organization': organization_type}
    245 
    246 
    247 def add_generic_ship_matchers(method, solar_system, ship, organization_type):
    248     matcher = method.contribution_methods.add()
    249     add_solar_system_to_proto(solar_system, matcher)
    250     add_ship_type_to_proto(ship, matcher)
    251     add_owner_identity_to_proto(organization_type, matcher)
    252 
    253 
    254 def construct_deliver_item_proto(item_type, office_id):
    255     method = ContributionConfiguration.DeliverItemContributionConfiguration()
    256     matcher = method.contribution_methods.add()
    257     matcher.delivered_item_type.sequential = item_type
    258     if office_id is None:
    259         matcher.free_office = True
    260     else:
    261         matcher.office.sequential = office_id
    262     return method
    263 
    264 
    265 def construct_deliver_item_dict_from_proto(data):
    266     office = None
    267     if data.HasField('office'):
    268         office = data.office.sequential
    269     return {'item_type': int(data.delivered_item_type.sequential),
    270      'office': office}
    271 
    272 
    273 def construct_kill_npc_proto(solar_system_id):
    274     method = ContributionConfiguration.KillNPCContributionConfiguration()
    275     matcher = method.contribution_methods.add()
    276     if solar_system_id is None:
    277         matcher.free_solar_system = True
    278     else:
    279         matcher.solar_system.sequential = solar_system_id
    280     return method
    281 
    282 
    283 def construct_kill_npc_dict_from_proto(data):
    284     solar_system_id = None
    285     if data.HasField('solar_system'):
    286         solar_system_id = int(data.solar_system.sequential)
    287     return {'solar_system': solar_system_id}
    288 
    289 
    290 def construct_damage_ship_proto(solar_systems, ships, identities):
    291     method = CorpGoalContributionConfiguration.DamageShip()
    292     add_solar_systems_to_proto(solar_systems, method.solar_systems)
    293     add_ships_to_proto(ships, method.ships)
    294     add_owner_identities_to_proto(identities, method.attacked_identities)
    295     return method
    296 
    297 
    298 def construct_deprecated_damage_ship_dict_from_proto(data):
    299     solar_system_id = None
    300     if data.HasField('solar_system'):
    301         solar_system_id = [int(data.solar_system.sequential)]
    302     ship_type = None
    303     if data.HasField('ship_type'):
    304         ship_type = [('ship_type', int(data.ship_type.sequential))]
    305     organization_type = None
    306     if data.HasField('character'):
    307         organization_type = [int(data.character.sequential)]
    308     elif data.HasField('corporation'):
    309         organization_type = [int(data.corporation.sequential)]
    310     elif data.HasField('alliance'):
    311         organization_type = [int(data.alliance.sequential)]
    312     elif data.HasField('faction'):
    313         organization_type = [int(data.faction.sequential)]
    314     return {'solar_system': solar_system_id,
    315      'ship': ship_type,
    316      'organization': organization_type}
    317 
    318 
    319 def construct_damage_ship_dict_from_proto(data):
    320     return {'solar_system': get_solar_systems_from_proto(data.solar_systems),
    321      'ship': get_ships_from_proto(data.ships),
    322      'organization': get_owner_identities_from_proto(data.attacked_identities)}
    323 
    324 
    325 def construct_mine_ore_proto(solar_systems, ores):
    326     method = CorpGoalContributionConfiguration.MineOre()
    327     add_solar_systems_to_proto(solar_systems, method.solar_systems)
    328     add_ores_to_proto(ores, method.ores)
    329     return method
    330 
    331 
    332 def construct_deprecated_mine_ore_dict_from_proto(data):
    333     solar_system_id = None
    334     if data.HasField('solar_system'):
    335         solar_system_id = [int(data.solar_system.sequential)]
    336     ore_type = None
    337     if data.HasField('ore'):
    338         ore_type = [('item_type', int(data.ore.sequential))]
    339     return {'solar_system': solar_system_id,
    340      'ore': ore_type}
    341 
    342 
    343 def construct_mine_ore_dict_from_proto(data):
    344     return {'solar_system': get_solar_systems_from_proto(data.solar_systems),
    345      'ore': get_ores_from_proto(data.ores)}
    346 
    347 
    348 def construct_destroy_player_ship_proto(solar_systems, ships, identities):
    349     method = CorpGoalContributionConfiguration.DestroyPlayerShip()
    350     add_solar_systems_to_proto(solar_systems, method.solar_systems)
    351     add_ships_to_proto(ships, method.ships)
    352     add_owner_identities_to_proto(identities, method.destroyed_identities)
    353     return method
    354 
    355 
    356 def construct_deprecated_destroy_player_ship_dict_from_proto(data):
    357     return construct_generic_ship_dict_from_proto(data, as_multi_value=True)
    358 
    359 
    360 def construct_destroy_player_ship_dict_from_proto(data):
    361     return {'solar_system': get_solar_systems_from_proto(data.solar_systems),
    362      'ship': get_ships_from_proto(data.ships),
    363      'organization': get_owner_identities_from_proto(data.destroyed_identities)}
    364 
    365 
    366 def construct_capture_fw_complex_dict_from_proto(data):
    367     solar_system_id = get_solar_system_from_proto(data.solar_system)
    368     faction = None
    369     if data.previous_owner.HasField('match_value'):
    370         faction = int(data.previous_owner.match_value.sequential)
    371     complex_type = None
    372     if data.archetype.HasField('match_value'):
    373         complex_type = data.archetype.match_value.sequential
    374     return {'solar_system': solar_system_id,
    375      'faction': faction,
    376      'complex_type': complex_type}
    377 
    378 
    379 def construct_capture_fw_complex_proto(previous_owner, solar_system_id, archetype):
    380     method = ContributionConfiguration.CaptureFacWarComplex()
    381     matcher = method.contribution_methods.add()
    382     if previous_owner is None:
    383         matcher.previous_owner.any = True
    384     else:
    385         matcher.previous_owner.match_value.sequential = previous_owner
    386     add_solar_system_to_proto(solar_system_id, matcher)
    387     if archetype is None:
    388         matcher.archetype.any = True
    389     else:
    390         matcher.archetype.match_value.sequential = archetype
    391     return method
    392 
    393 
    394 def construct_defend_fw_complex_dict_from_proto(data):
    395     solar_system_id = get_solar_system_from_proto(data.solar_system)
    396     faction = None
    397     if data.owner.HasField('match_value'):
    398         faction = int(data.owner.match_value.sequential)
    399     complex_type = None
    400     if data.archetype.HasField('match_value'):
    401         complex_type = data.archetype.match_value.sequential
    402     return {'solar_system': solar_system_id,
    403      'faction': faction,
    404      'complex_type': complex_type}
    405 
    406 
    407 def construct_defend_fw_complex_proto(owner, solar_system_id, archetype):
    408     method = ContributionConfiguration.DefendFacWarComplex()
    409     matcher = method.contribution_methods.add()
    410     if owner is None:
    411         matcher.owner.any = True
    412     else:
    413         matcher.owner.match_value.sequential = owner
    414     add_solar_system_to_proto(solar_system_id, matcher)
    415     if archetype is None:
    416         matcher.archetype.any = True
    417     else:
    418         matcher.archetype.match_value.sequential = archetype
    419     return method
    420 
    421 
    422 def construct_remote_repair_shield_proto(solar_system, ship, organization_type):
    423     method = ContributionConfiguration.RemoteShieldRepair()
    424     add_generic_ship_matchers(method, solar_system=solar_system, ship=ship, organization_type=organization_type)
    425     return method
    426 
    427 
    428 def construct_remote_repair_armor_proto(solar_system, ship, organization_type):
    429     method = ContributionConfiguration.RemoteArmorRepair()
    430     add_generic_ship_matchers(method, solar_system=solar_system, ship=ship, organization_type=organization_type)
    431     return method
    432 
    433 
    434 def construct_ship_lost_pvp_proto(solar_system, ship, organization_type):
    435     method = ContributionConfiguration.ShipLostPVP()
    436     add_generic_ship_matchers(method, solar_system=solar_system, ship=ship, organization_type=organization_type)
    437     return method
    438 
    439 
    440 def construct_scan_signature_dict_from_proto(data):
    441     solar_system_id = get_solar_system_from_proto(data.solar_system)
    442     signature_type = None
    443     if data.signature_type.HasField('match_value'):
    444         signature_type = data.signature_type.match_value.sequential
    445     return {'solar_system': solar_system_id,
    446      'signature_type': signature_type}
    447 
    448 
    449 def construct_scan_signature_proto(solar_system, signature_type):
    450     method = ContributionConfiguration.ScanSignature()
    451     matcher = method.contribution_methods.add()
    452     add_solar_system_to_proto(solar_system, matcher)
    453     if signature_type is None:
    454         matcher.signature_type.any = True
    455     else:
    456         matcher.signature_type.match_value.sequential = signature_type
    457     return method
    458 
    459 
    460 def construct_manufacture_items_dict_from_proto(data):
    461     item_type = None
    462     if data.item_type.HasField('item_type'):
    463         item_type = int(data.item_type.item_type.sequential)
    464     owner = ON_BEHALF_OF_CORP
    465     if data.job_owner_type.HasField('match_any_character'):
    466         owner = ON_BEHALF_OF_SELF
    467     job_location = None
    468     if data.job_location.HasField('station'):
    469         job_location = data.job_location.station.sequential
    470     elif data.job_location.HasField('structure'):
    471         job_location = data.job_location.structure.sequential
    472     return {'item_type': item_type,
    473      'owner': owner,
    474      'facility_location': job_location}
    475 
    476 
    477 def construct_manufacture_items_proto(item_type, owner, facility_location):
    478     method = ContributionConfiguration.InstallManufacturingJob()
    479     matcher = method.contribution_methods.add()
    480     if item_type:
    481         matcher.item_type.item_type.sequential = item_type
    482     else:
    483         matcher.item_type.any = True
    484     if owner == ON_BEHALF_OF_SELF:
    485         matcher.job_owner_type.match_any_character = True
    486     elif owner == ON_BEHALF_OF_CORP:
    487         matcher.job_owner_type.match_any_corporation = True
    488     if facility_location is None:
    489         matcher.job_location.any = True
    490     elif idCheckers.IsStation(facility_location):
    491         matcher.job_location.station.sequential = facility_location
    492     else:
    493         matcher.job_location.structure.sequential = facility_location
    494     return method
    495 
    496 
    497 def construct_salvage_wreck_dict_from_proto(data):
    498     solar_system_id = get_solar_system_from_proto(data.solar_system)
    499     return {'solar_system': solar_system_id}
    500 
    501 
    502 def construct_salvage_wreck_proto(solar_system):
    503     method = ContributionConfiguration.SalvageWreck()
    504     matcher = method.contribution_methods.add()
    505     add_solar_system_to_proto(solar_system, matcher)
    506     return method
    507 
    508 
    509 def construct_earn_loyalty_points_proto(corporations):
    510     method = CorpGoalContributionConfiguration.EarnLoyaltyPoints()
    511     add_corporations_to_proto(corporations, method.corporations)
    512     return method
    513 
    514 
    515 def construct_deprecated_earn_loyalty_points_dict_from_proto(data):
    516     corporation_id = None
    517     if data.corporation.HasField('match_value'):
    518         corporation_id = [int(data.corporation.match_value.sequential)]
    519     return {'corporation_id': corporation_id}
    520 
    521 
    522 def construct_earn_loyalty_points_dict_from_proto(data):
    523     return {'corporation_id': get_corporations_from_proto(data.corporations)}
    524 
    525 
    526 def construct_ship_insurance_proto(solar_systems, ships, identities, conflict_type, cover_implants):
    527     method = CorpGoalContributionConfiguration.ShipInsurance()
    528     add_solar_systems_to_proto(solar_systems, method.solar_systems)
    529     add_ships_to_proto(ships, method.ships)
    530     add_owner_identities_to_proto(identities, method.killer_identities)
    531     add_conflict_type_to_proto(conflict_type, method.conflict_type)
    532     method.include_implants = cover_implants
    533     return method
    534 
    535 
    536 def construct_ship_insurance_dict_from_proto(data):
    537     return {'solar_system': get_solar_systems_from_proto(data.solar_systems),
    538      'ship': get_ships_from_proto(data.ships),
    539      'organization': get_owner_identities_from_proto(data.killer_identities),
    540      'conflict_type': get_conflict_type_from_proto(data.conflict_type),
    541      'cover_implants': data.include_implants}
    542 
    543 
    544 def add_contribution_method(request, method_id, data = None):
    545     if method_id == ContributionMethodTypes.MANUAL:
    546         config = ContributionConfiguration.ManualContributionConfiguration()
    547         request.contribution_configuration.manual.CopyFrom(config)
    548     elif ContributionMethodTypes.DELIVER_ITEM == method_id:
    549         method = construct_deliver_item_proto(item_type=data.get('item_type'), office_id=data.get('office'))
    550         request.contribution_configuration.deliver_item.CopyFrom(method)
    551     elif method_id == ContributionMethodTypes.KILL_NPC:
    552         method = construct_kill_npc_proto(solar_system_id=data.get('solar_system'))
    553         request.contribution_configuration.kill_npc.CopyFrom(method)
    554     elif method_id == ContributionMethodTypes.MINE_ORE:
    555         method = construct_mine_ore_proto(solar_systems=data.get('solar_system'), ores=data.get('ore'))
    556         request.contribution_configuration.mined_ore.CopyFrom(method)
    557     elif method_id == ContributionMethodTypes.DAMAGE_SHIP:
    558         method = construct_damage_ship_proto(solar_systems=data.get('solar_system'), ships=data.get('ship'), identities=data.get('organization'))
    559         request.contribution_configuration.damaged_ship.CopyFrom(method)
    560     elif method_id == ContributionMethodTypes.DESTROY_PLAYER_SHIP:
    561         method = construct_destroy_player_ship_proto(solar_systems=data.get('solar_system'), ships=data.get('ship'), identities=data.get('organization'))
    562         request.contribution_configuration.pvp_destroyed_ship.CopyFrom(method)
    563     elif method_id == ContributionMethodTypes.CAPTURE_FACWAR_COMPLEX:
    564         method = construct_capture_fw_complex_proto(previous_owner=data.get('faction'), solar_system_id=data.get('solar_system'), archetype=data.get('complex_type'))
    565         request.contribution_configuration.fw_capture.CopyFrom(method)
    566     elif method_id == ContributionMethodTypes.DEFEND_FACWAR_COMPLEX:
    567         method = construct_defend_fw_complex_proto(owner=data.get('faction'), solar_system_id=data.get('solar_system'), archetype=data.get('complex_type'))
    568         request.contribution_configuration.fw_defend.CopyFrom(method)
    569     elif method_id == ContributionMethodTypes.REMOTE_REPAIR_SHIELD:
    570         method = construct_remote_repair_shield_proto(solar_system=data.get('solar_system'), ship=data.get('ship'), organization_type=data.get('organization'))
    571         request.contribution_configuration.remote_shield_repair.CopyFrom(method)
    572     elif method_id == ContributionMethodTypes.REMOTE_REPAIR_ARMOR:
    573         method = construct_remote_repair_armor_proto(solar_system=data.get('solar_system'), ship=data.get('ship'), organization_type=data.get('organization'))
    574         request.contribution_configuration.remote_armor_repair.CopyFrom(method)
    575     elif method_id == ContributionMethodTypes.MANUFACTURE_ITEM:
    576         method = construct_manufacture_items_proto(item_type=data.get('item_type'), owner=data.get('owner'), facility_location=data.get('facility_location'))
    577         request.contribution_configuration.install_manufacturing_job.CopyFrom(method)
    578     elif method_id == ContributionMethodTypes.SCAN_SIGNATURE:
    579         method = construct_scan_signature_proto(solar_system=data.get('solar_system'), signature_type=data.get('signature_type'))
    580         request.contribution_configuration.scan_signature.CopyFrom(method)
    581     elif method_id == ContributionMethodTypes.COMPLETE_GOAL:
    582         config = ContributionConfiguration.CompleteGoal()
    583         request.contribution_configuration.complete_goal.CopyFrom(config)
    584     elif method_id == ContributionMethodTypes.SALVAGE_WRECK:
    585         method = construct_salvage_wreck_proto(solar_system=data.get('solar_system'))
    586         request.contribution_configuration.salvage_wreck.CopyFrom(method)
    587     elif method_id == ContributionMethodTypes.EARN_LOYALTY_POINTS:
    588         method = construct_earn_loyalty_points_proto(corporations=data.get('corporation_id'))
    589         request.contribution_configuration.earned_loyaltypoints.CopyFrom(method)
    590     elif method_id == ContributionMethodTypes.SHIP_LOSS:
    591         method = construct_ship_lost_pvp_proto(solar_system=data.get('solar_system'), ship=data.get('ship'), organization_type=data.get('organization'))
    592         request.contribution_configuration.ship_lost_pvp.CopyFrom(method)
    593     elif method_id == ContributionMethodTypes.SHIP_INSURANCE:
    594         method = construct_ship_insurance_proto(solar_systems=data.get('solar_system'), ships=data.get('ship'), identities=data.get('organization'), conflict_type=data.get('conflict_type'), cover_implants=data.get('cover_implants'))
    595         request.contribution_configuration.ship_insurance.CopyFrom(method)
    596     else:
    597         raise ContributionMethodTypeNotSupported(u'Method type {} not supported'.format(method_id))
    598 
    599 
    600 def _find_contribution_method_id(config):
    601     if config.HasField('manual'):
    602         return (ContributionMethodTypes.MANUAL, config.manual)
    603     if config.HasField('deliver_item'):
    604         field_dict = construct_deliver_item_dict_from_proto(config.deliver_item.contribution_methods[0])
    605         return (ContributionMethodTypes.DELIVER_ITEM, field_dict)
    606     if config.HasField('kill_npc'):
    607         field_dict = construct_kill_npc_dict_from_proto(config.kill_npc.contribution_methods[0])
    608         return (ContributionMethodTypes.KILL_NPC, field_dict)
    609     if config.HasField('mine_ore'):
    610         field_dict = construct_deprecated_mine_ore_dict_from_proto(config.mine_ore.contribution_methods[0])
    611         return (ContributionMethodTypes.MINE_ORE, field_dict)
    612     if config.HasField('mined_ore'):
    613         field_dict = construct_mine_ore_dict_from_proto(config.mined_ore)
    614         return (ContributionMethodTypes.MINE_ORE, field_dict)
    615     if config.HasField('damage_ship'):
    616         field_dict = construct_deprecated_damage_ship_dict_from_proto(config.damage_ship.contribution_methods[0])
    617         return (ContributionMethodTypes.DAMAGE_SHIP, field_dict)
    618     if config.HasField('damaged_ship'):
    619         field_dict = construct_damage_ship_dict_from_proto(config.damaged_ship)
    620         return (ContributionMethodTypes.DAMAGE_SHIP, field_dict)
    621     if config.HasField('destroy_player_ship'):
    622         field_dict = construct_deprecated_destroy_player_ship_dict_from_proto(config.destroy_player_ship.contribution_methods[0])
    623         return (ContributionMethodTypes.DESTROY_PLAYER_SHIP, field_dict)
    624     if config.HasField('pvp_destroyed_ship'):
    625         field_dict = construct_destroy_player_ship_dict_from_proto(config.pvp_destroyed_ship)
    626         return (ContributionMethodTypes.DESTROY_PLAYER_SHIP, field_dict)
    627     if config.HasField('fw_capture'):
    628         field_dict = construct_capture_fw_complex_dict_from_proto(config.fw_capture.contribution_methods[0])
    629         return (ContributionMethodTypes.CAPTURE_FACWAR_COMPLEX, field_dict)
    630     if config.HasField('fw_defend'):
    631         field_dict = construct_defend_fw_complex_dict_from_proto(config.fw_defend.contribution_methods[0])
    632         return (ContributionMethodTypes.DEFEND_FACWAR_COMPLEX, field_dict)
    633     if config.HasField('remote_shield_repair'):
    634         field_dict = construct_generic_ship_dict_from_proto(config.remote_shield_repair.contribution_methods[0])
    635         return (ContributionMethodTypes.REMOTE_REPAIR_SHIELD, field_dict)
    636     if config.HasField('remote_armor_repair'):
    637         field_dict = construct_generic_ship_dict_from_proto(config.remote_armor_repair.contribution_methods[0])
    638         return (ContributionMethodTypes.REMOTE_REPAIR_ARMOR, field_dict)
    639     if config.HasField('scan_signature'):
    640         field_dict = construct_scan_signature_dict_from_proto(config.scan_signature.contribution_methods[0])
    641         return (ContributionMethodTypes.SCAN_SIGNATURE, field_dict)
    642     if config.HasField('install_manufacturing_job'):
    643         field_dict = construct_manufacture_items_dict_from_proto(config.install_manufacturing_job.contribution_methods[0])
    644         return (ContributionMethodTypes.MANUFACTURE_ITEM, field_dict)
    645     if config.HasField('complete_goal'):
    646         return (ContributionMethodTypes.COMPLETE_GOAL, config.complete_goal)
    647     if config.HasField('salvage_wreck'):
    648         field_dict = construct_salvage_wreck_dict_from_proto(config.salvage_wreck.contribution_methods[0])
    649         return (ContributionMethodTypes.SALVAGE_WRECK, field_dict)
    650     if config.HasField('earn_loyalty_points'):
    651         field_dict = construct_deprecated_earn_loyalty_points_dict_from_proto(config.earn_loyalty_points.contribution_methods[0])
    652         return (ContributionMethodTypes.EARN_LOYALTY_POINTS, field_dict)
    653     if config.HasField('earned_loyaltypoints'):
    654         field_dict = construct_earn_loyalty_points_dict_from_proto(config.earned_loyaltypoints)
    655         return (ContributionMethodTypes.EARN_LOYALTY_POINTS, field_dict)
    656     if config.HasField('ship_lost_pvp'):
    657         field_dict = construct_generic_ship_dict_from_proto(config.ship_lost_pvp.contribution_methods[0])
    658         return (ContributionMethodTypes.SHIP_LOSS, field_dict)
    659     if config.HasField('ship_insurance'):
    660         field_dict = construct_ship_insurance_dict_from_proto(config.ship_insurance)
    661         return (ContributionMethodTypes.SHIP_INSURANCE, field_dict)
    662 
    663 
    664 def format_payments(payments):
    665     if not payments:
    666         return None
    667     payment = payments[0]
    668     return {'amount_per_unit': get_single_value_from_split_precision_message(payment.unit.amount),
    669      'asset_id': uuid.UUID(bytes=payment.asset.uuid)}
    670 
    671 
    672 def _format_organization(org_data):
    673     if org_data.HasField('corporation'):
    674         return (OrganizationType.CORPORATION, org_data.corporation.sequential)
    675     elif org_data.HasField('character'):
    676         return (OrganizationType.CHARACTER, org_data.character.sequential)
    677     else:
    678         return (None, None)
    679 
    680 
    681 def goal_formatter(goal_id, goal):
    682     client_method_id, contribution_fields = _find_contribution_method_id(goal.contribution_config)
    683     reward = format_payments(goal.payment)
    684     assigner_type, assigner_id = _format_organization(goal.assigner)
    685     assignee_type, assignee_id = _format_organization(goal.assignee)
    686     if goal.HasField('user_input_name'):
    687         name = goal.user_input_name
    688     elif goal.HasField('name_message'):
    689         name = GetByMessageID(goal.name_message)
    690     else:
    691         name = None
    692     if goal.HasField('user_input_description'):
    693         description = goal.user_input_description
    694     elif goal.HasField('description_message'):
    695         description = GetByMessageID(goal.description_message)
    696     else:
    697         description = None
    698     return {'goal_id': goal_id,
    699      'created': goal.created.ToDatetime(),
    700      'name': name,
    701      'description': description,
    702      'state': goal.state,
    703      'desired_progress': goal.progress.desired,
    704      'current_progress': goal.progress.current,
    705      'creator': goal.creator.sequential,
    706      'assigner_organization_type': assigner_type,
    707      'assigner_organization_id': assigner_id,
    708      'assignee_organization_type': assignee_type,
    709      'assignee_organization_id': assignee_id,
    710      'method_id': client_method_id,
    711      'contribution_fields': contribution_fields,
    712      'career_path': CAREER_PATH_IDS[goal.career],
    713      'finish_time': goal.finished.ToDatetime() if goal.HasField('finished') else None,
    714      'due_time': goal.due.ToDatetime() if goal.HasField('due') else None,
    715      'reward': reward,
    716      'ui_annotations': {x.key:x.value for x in goal.ui_annotations},
    717      'participation_limit': None if goal.HasField('unlimited') else goal.limit,
    718      'coverage_limit': None if goal.HasField('contribution_unlimited') else goal.contribution_limit,
    719      'multiplier': None if not goal.HasField('scalar') else goal.scalar}