def load_enemy_data(self, base_dir: str): card_files = [] logger.warning('scanning enemy data for %d cards', len(self.data.all_cards)) for csc in self.data.all_cards: card_file = os.path.join(base_dir, '{}.textproto'.format(csc.monster_id)) if not os.path.exists(card_file): continue card_files.append(card_file) logger.warning('loading enemy data for %d cards', len(card_files)) count_not_approved = 0 count_approved = 0 for card_file in card_files: mbwo = enemy_skill_proto.load_from_file(card_file) mb = MonsterBehavior() mb.monster_id = mbwo.monster_id if mbwo.status == enemy_skills_pb2.MonsterBehaviorWithOverrides.NOT_APPROVED: mb.levels.extend(mbwo.levels) mb.approved = False count_not_approved += 1 else: mb.levels.extend(mbwo.level_overrides) mb.approved = True count_approved += 1 item = EnemyData.from_mb(mb) self.db.insert_or_update(item) logger.warning('done, %d approved %d not approved', count_approved, count_not_approved)
async def serve_enemy_proto_encoded(request): enemy_id = int(request.args.get('id')) data_dir = os.path.join(es_dir, 'behavior_data') monster_file = os.path.join(data_dir, '{}.textproto'.format(enemy_id)) mbwo = enemy_skill_proto.load_from_file(monster_file) v = mbwo.SerializeToString() return text(binascii.hexlify(bytearray(v)).decode('ascii'))
async def serve_save_approved_as_is(request): enemy_id = int(request.args.get('id')) data_dir = os.path.join(es_dir, 'behavior_data') monster_file = os.path.join(data_dir, '{}.textproto'.format(enemy_id)) mbwo = enemy_skill_proto.load_from_file(monster_file) del mbwo.level_overrides[:] mbwo.level_overrides.extend(mbwo.levels) mbwo.status = MonsterBehaviorWithOverrides.APPROVED_AS_IS enemy_skill_proto.save_overrides(monster_file, mbwo) return text('ok')
async def serve_save_approved_with_changes(request): enemy_id = int(request.args.get('id')) data_dir = os.path.join(es_dir, 'behavior_data') monster_file = os.path.join(data_dir, '{}.textproto'.format(enemy_id)) mbwo = enemy_skill_proto.load_from_file(monster_file) del mbwo.level_overrides[:] mbwo_input = MonsterBehaviorWithOverrides() mbwo_input.ParseFromString(binascii.unhexlify(str(request.body.decode('ascii')))) mbwo.level_overrides.extend(mbwo_input.level_overrides) mbwo.status = MonsterBehaviorWithOverrides.APPROVED_WITH_CHANGES enemy_skill_proto.save_overrides(monster_file, mbwo) return text('ok')