Ejemplo n.º 1
0
    def viscidus_poison_tick(cls, log_id):
        log_object, msg = BaseService.get_wcl_log_by_id(log_id=log_id)
        if not log_object:
            return True, msg

        fight_list, msg = BaseService.get_fight_list(
            log_id=log_id, name=CONSTANT_SERVICE.Viscidus_name)
        if not fight_list or len(fight_list) == 0:
            return True, 'no viscidus fight in this log'

        for fight in fight_list:
            start = fight.start
            end = fight.end
            time = end - start
            params = {
                "start": start,
                "end": end,
                "abilityid": CONSTANT_SERVICE.Poison_Bolt_Volley_ability_id
            }

            success, result = WclApiService.get_api(
                api=CONSTANT_SERVICE.TABLES_API,
                view=CONSTANT_SERVICE.DAMAGE_TAKEN_VIEW,
                code=log_object.code,
                params=params)
            if not success:
                return False, result

            entries = result.get("entries")
            if len(entries) == 0:
                continue
                # return False, 'no poison data in log or parms error'

            for entry in entries:
                total = entry.get("total", 0)
                hitCount = entry.get("hitCount", 0)
                tickCount = entry.get("tickCount", 0)
                uptime = entry.get("uptime", 0)
                id = entry.get("id", 0)
                name = entry.get("name", "")
                viscidusPoisonTick = ViscidusPoisonTick()
                viscidusPoisonTick.fight = fight
                viscidusPoisonTick.log = log_object
                friendly, msg = BaseService.get_friendly_by_id(friendly_id=id,
                                                               log_id=log_id)
                if not friendly:
                    return False, msg
                viscidusPoisonTick.friendly = friendly
                viscidusPoisonTick.name = name
                viscidusPoisonTick.damage = total
                viscidusPoisonTick.hit = hitCount
                viscidusPoisonTick.tick = tickCount
                viscidusPoisonTick.uptime = round(uptime * 100 / time, 2)
                viscidusPoisonTick.save()

        return True, ''
Ejemplo n.º 2
0
    def boss_nature_protection_summary(cls, log_id, boss_name):
        fight_list, msg = BaseService.get_fight_list(log_id=log_id,
                                                     name=boss_name)
        if not fight_list or len(fight_list) == 0:
            return True, 'no %s fight in this log' % boss_name

        log_object, msg = BaseService.get_wcl_log_by_id(log_id=log_id)
        if not log_object:
            return False, msg

        for fight in fight_list:
            # 先获取该场boss站所有的参加人员
            success, result = WclApiService.get_api(
                api=CONSTANT_SERVICE.FIGHT_API,
                code=log_object.code,
                view=None,
                params=None)
            if not success:
                return success, result

            enemy_obj, msg = BaseService.get_enemy_by_name(log_id=log_id,
                                                           name=fight.name)
            if not enemy_obj:
                continue
            fight_id_dict = {"id": fight.fight_id}
            total_result_dict = dict()
            friendlies = result.get("friendlies")
            for friendly in friendlies:
                if fight_id_dict in friendly["fights"]:
                    # this player joined the fight
                    total_result_dict[friendly["id"]] = {
                        "nature_protection_absorb": 0,
                        "nature_protection_cast": 0,
                        "nature_protection_uptime": 0.00,
                        "major_nature_protection_absorb": 0,
                        "major_nature_protection_cast": 0,
                        "major_nature_protection_uptime": 0.00,
                    }

            start = fight.start
            end = fight.end
            time = end - start

            # 小自然抗
            params = {
                "start": start,
                "end": end,
                "abilityid": CONSTANT_SERVICE.Nature_Protection_id
            }

            success, result = WclApiService.get_api(
                api=CONSTANT_SERVICE.TABLES_API,
                view=CONSTANT_SERVICE.HEALING_VIEW,
                code=log_object.code,
                params=params)

            if not success:
                return False, result

            if len(result.get("entries")) > 0:
                for entry in result.get("entries"):
                    total = entry.get("total", 0)
                    uptime = entry.get('uptime', 0)
                    friendly_id = entry.get('id', 0)
                    if friendly_id in total_result_dict.keys():
                        total_result_dict[friendly_id][
                            "nature_protection_absorb"] = total
                        total_result_dict[friendly_id][
                            "nature_protection_uptime"] = round(
                                uptime * 100 / time, 2)

            success, result = WclApiService.get_api(
                api=CONSTANT_SERVICE.TABLES_API,
                view=CONSTANT_SERVICE.CASTS_VIEW,
                code=log_object.code,
                params=params)

            if not success:
                return False, result

            if len(result.get("entries")) > 0:
                for entry in result.get("entries"):
                    total = entry.get("total", 0)
                    friendly_id = entry.get('id', 0)
                    if friendly_id in total_result_dict.keys():
                        total_result_dict[friendly_id][
                            "nature_protection_cast"] = total

            # 大自然抗
            params = {
                "start": start,
                "end": end,
                "abilityid": CONSTANT_SERVICE.Major_Nature_Protection_id
            }

            success, result = WclApiService.get_api(
                api=CONSTANT_SERVICE.TABLES_API,
                view=CONSTANT_SERVICE.HEALING_VIEW,
                code=log_object.code,
                params=params)

            if not success:
                return False, result

            if len(result.get("entries")) > 0:
                for entry in result.get("entries"):
                    total = entry.get("total", 0)
                    uptime = entry.get('uptime', 0)
                    friendly_id = entry.get('id', 0)
                    if friendly_id in total_result_dict.keys():
                        total_result_dict[friendly_id][
                            "major_nature_protection_absorb"] = total
                        total_result_dict[friendly_id][
                            "major_nature_protection_uptime"] = round(
                                uptime * 100 / time, 2)

            success, result = WclApiService.get_api(
                api=CONSTANT_SERVICE.TABLES_API,
                view=CONSTANT_SERVICE.CASTS_VIEW,
                code=log_object.code,
                params=params)

            if not success:
                return False, result

            if len(result.get("entries")) > 0:
                for entry in result.get("entries"):
                    total = entry.get("total")
                    friendly_id = entry.get('id')
                    if friendly_id in total_result_dict.keys():
                        total_result_dict[friendly_id][
                            "major_nature_protection_cast"] = total

            # import json
            # print(json.dumps(total_result_dict))
            for key, value in total_result_dict.items():
                friendly_obj, msg = BaseService.get_friendly_by_id(
                    friendly_id=key, log_id=log_id)
                if not friendly_obj:
                    continue
                bossNatureProtection = BossNatureProtection()
                bossNatureProtection.friendly = friendly_obj
                bossNatureProtection.log = log_object
                bossNatureProtection.fight = fight
                bossNatureProtection.enemy = enemy_obj
                bossNatureProtection.name = friendly_obj.name
                bossNatureProtection.nature_protection_absorb = value.get(
                    "nature_protection_absorb", 0)
                bossNatureProtection.nature_protection_cast = value.get(
                    "nature_protection_cast", 0)
                bossNatureProtection.nature_protection_uptime = value.get(
                    "nature_protection_uptime", 0)
                bossNatureProtection.major_nature_protection_absorb = value.get(
                    "major_nature_protection_absorb", 0)
                bossNatureProtection.major_nature_protection_cast = value.get(
                    "major_nature_protection_cast", 0)
                bossNatureProtection.major_nature_protection_uptime = value.get(
                    "major_nature_protection_uptime", 0)
                if boss_name == CONSTANT_SERVICE.Hururan_name:
                    if friendly_obj.is_melee():
                        # melee
                        if bossNatureProtection.nature_protection_absorb > 0 and bossNatureProtection.major_nature_protection_cast == 0:
                            bossNatureProtection.importance = BossNatureProtection.IMPORTANCE_L1
                        elif bossNatureProtection.nature_protection_absorb > 0 or bossNatureProtection.major_nature_protection_cast == 0:
                            bossNatureProtection.importance = BossNatureProtection.IMPORTANCE_L2
                        else:
                            bossNatureProtection.importance = BossNatureProtection.IMPORTANCE_L3
                    else:
                        if bossNatureProtection.nature_protection_absorb > 0:
                            bossNatureProtection.importance = BossNatureProtection.IMPORTANCE_L1
                        else:
                            bossNatureProtection.importance = BossNatureProtection.IMPORTANCE_L3
                else:
                    if bossNatureProtection.nature_protection_absorb > 0:
                        bossNatureProtection.importance = BossNatureProtection.IMPORTANCE_L1
                    else:
                        bossNatureProtection.importance = BossNatureProtection.IMPORTANCE_L3

                bossNatureProtection.save()

        return True, ''