예제 #1
0
def advance_rank():
    """advance the character in the same path as the previous rank
       returns False if this option is not available
    """

    # this function assumes that the character is able to
    # advance in the same path

    from l5r.models.advancements.rank import Rank
    adv = Rank()
    # the insight rank
    adv.rank = api.character.insight_rank()
    # this is the current school for this rank
    adv.school = api.character.schools.get_current()
    # no cost advancing in the same rank
    adv.cost = 0
    # description
    adv.desc = api.tr("Insight Rank {0}. School: {1} rank {2} ").format(
        adv.rank,
        api.data.schools.get(adv.school).name,
        api.character.schools.get_school_rank(adv.school) + 1
    )

    # get 3 spells each rank other than the first
    if api.data.schools.is_shugenja(adv.school) and adv.rank > 1:
        adv.gained_spells_count = __api.pc.get_spells_per_rank()

    # get 2 kiho each rank
    if api.data.schools.is_brotherhood_monk(adv.school) and adv.rank > 1:
        adv.gained_kiho_count = 2

    return api.character.append_advancement(adv)
예제 #2
0
def join_rank1_path(school_id):
    """the character replaces its first technique with a rank1 path"""

    school_ = api.data.schools.get(school_id)
    if not school_:
        log.api.error(u"join_rank1_path, school not found: %s", school_id)
        return

    from l5r.models.advancements.rank import Rank
    adv = Rank()
    # the insight rank
    adv.rank = 1
    # this is the current school for this rank
    adv.school = school_id
    # no cost advancing in the same rank
    adv.cost = 0
    # description

    school_rank = 1
    adv.replaced = api.character.schools.get_current()

    replaced_school = api.data.schools.get(adv.replaced)

    adv.desc = api.tr("Replaced {0} with {1} (Rank1)").format(
        replaced_school.name,
        school_.name,
    )

    return api.character.append_advancement(adv)
예제 #3
0
def advance_rank():
    """advance the character in the same path as the previous rank
       returns False if this option is not available
    """

    # this function assumes that the character is able to
    # advance in the same path

    from l5r.models.advancements.rank import Rank
    adv = Rank()
    # the insight rank
    adv.rank = api.character.insight_rank(strict=True) + 1
    # this is the current school for this rank
    adv.school = api.character.schools.get_current()
    # this is the current school_rank for this school
    adv.school_rank = api.character.schools.get_school_rank(adv.school) + 1

    # no cost advancing in the same rank
    adv.cost = 0
    # description
    adv.desc = api.tr("Insight Rank {0}. School: {1} rank {2} ").format(
        adv.rank,
        api.data.schools.get(adv.school).name, adv.school_rank)

    # get 3 spells each rank other than the first
    if api.data.schools.is_shugenja(adv.school) and adv.rank > 1:
        adv.gained_spells_count = __api.pc.get_spells_per_rank()

    # get 2 kiho each rank
    if api.data.schools.is_brotherhood_monk(adv.school) and adv.rank > 1:
        adv.gained_kiho_count = 2

    return api.character.append_advancement(adv)
예제 #4
0
def join_rank1_path(school_id):
    """the character replaces its first technique with a rank1 path"""

    school_ = api.data.schools.get(school_id)
    if not school_:
        log.api.error(u"join_rank1_path, school not found: %s", school_id)
        return

    from l5r.models.advancements.rank import Rank
    adv = Rank()
    # the insight rank
    adv.rank = 1
    # this is the current school for this rank
    adv.school = school_id
    # no cost advancing in the same rank
    adv.cost = 0
    # description

    school_rank = 1
    adv.replaced = api.character.schools.get_current()

    replaced_school = api.data.schools.get(adv.replaced)

    adv.desc = api.tr("Replaced {0} with {1} (Rank1)").format(
        replaced_school.name,
        school_.name,
    )

    return api.character.append_advancement(adv)
예제 #5
0
def join_new(school_id):
    """the character joins a new school"""

    school_ = api.data.schools.get(school_id)
    if not school_:
        log.api.error(u"join_new, school not found: %s", school_id)
        return

    from l5r.models.advancements.rank import Rank
    adv = Rank()
    # the insight rank
    adv.rank = api.character.insight_rank(strict=True)
    if api.character.insight_rank(strict=True) != api.character.insight_rank():
        adv.rank += 1

    # this is the current school for this rank
    adv.school = school_id
    # this is the current school rank for this school
    adv.school_rank = api.character.schools.get_school_rank(adv.school)

    # no cost advancing in the same rank
    adv.cost = 0

    # get 3 spells each rank other than the first
    if api.data.schools.is_shugenja(school_id) and adv.rank > 1:
        adv.gained_spells_count = __api.pc.get_spells_per_rank()

    if api.data.schools.is_path(adv.school):
        # replaces current school
        adv.replaced = api.character.schools.get_current()
    else:
        adv.school_rank += 1

        # get 2 kiho each rank
        # alternate path doesn't get the bonus
        if api.data.schools.is_brotherhood_monk(school_id) and adv.rank > 1:
            adv.gained_kiho_count = 2

    if school_.affinity:
        if 'any' in school_.affinity or 'nonvoid' in school_.affinity:
            adv.affinities_to_choose.append(school_.affinity)
        else:
            adv.affinities.append(school_.affinity)

    if school_.deficiency:
        if 'any' in school_.deficiency or 'nonvoid' in school_.deficiency:
            adv.deficiencies_to_choose.append(school_.deficiency)
        else:
            adv.deficiencies.append(school_.deficiency)

    # description
    adv.desc = api.tr("Insight Rank {0}. School: {1} rank {2} ").format(
        adv.rank, school_.name, adv.school_rank)

    return api.character.append_advancement(adv)
예제 #6
0
def join_new(school_id):
    """the character joins a new school"""

    school_ = api.data.schools.get(school_id)
    if not school_:
        log.api.error(u"join_new, school not found: %s", school_id)
        return

    from l5r.models.advancements.rank import Rank
    adv = Rank()
    # the insight rank
    adv.rank = api.character.insight_rank()
    # this is the current school for this rank
    adv.school = school_id
    # no cost advancing in the same rank
    adv.cost = 0
    # description

    school_rank = api.character.schools.get_school_rank(adv.school)

    # get 3 spells each rank other than the first
    if api.data.schools.is_shugenja(school_id) and adv.rank > 1:
        adv.gained_spells_count = __api.pc.get_spells_per_rank()

    if api.data.schools.is_path(adv.school):
        # replaces current school
        adv.replaced = api.character.schools.get_current()
    else:
        school_rank += 1

        # get 2 kiho each rank
        # alternate path doesn't get the bonus
        if api.data.schools.is_brotherhood_monk(school_id) and adv.rank > 1:
            adv.gained_kiho_count = 2

    if school_.affinity:
        if 'any' in school_.affinity or 'nonvoid' in school_.affinity:
            adv.affinities_to_choose.append(school_.affinity)
        else:
            adv.affinities.append(school_.affinity)

    if school_.deficiency:
        if 'any' in school_.deficiency or 'nonvoid' in school_.deficiency:
            adv.deficiencies_to_choose.append(school_.deficiency)
        else:
            adv.deficiencies.append(school_.deficiency)

    adv.desc = api.tr("Insight Rank {0}. School: {1} rank {2} ").format(
        adv.rank,
        school_.name,
        school_rank
    )

    return api.character.append_advancement(adv)
예제 #7
0
def purchase_void_rank():
    """purchase a void rank"""

    cur_value = void_rank()
    new_value = cur_value + 1

    cost = api.rules.get_void_rank_cost(new_value)

    adv = l5r.models.VoidAdv(cost)
    adv.desc = (api.tr('Void Ring, Rank {0} to {1}. Cost: {2} xp').format(
        cur_value, new_value, adv.cost))

    return purchase_advancement(adv)
예제 #8
0
def add_spell(spell_id):
    """add a spell, not bound to a specific rank advancement"""
    spell_ = api.data.spells.get(spell_id)
    if not spell_:
        log.api.error(u"add_school_spell. spell not found: %s", spell_id)
        return False

    adv = SpellAdv(spell_id)
    adv.desc = (api.tr('{0}, Mastery {1}. Element: {2}').format(
        spell_.name, spell_.mastery, spell_.element))

    api.character.append_advancement(adv)
    return True
def purchase_void_rank():
    """purchase a void rank"""

    cur_value = void_rank()
    new_value = cur_value + 1

    cost = api.rules.get_void_rank_cost(new_value)

    adv = l5r.models.VoidAdv(cost)
    adv.desc = (api.tr('Void Ring, Rank {0} to {1}. Cost: {2} xp')
                .format(cur_value, new_value, adv.cost))

    return purchase_advancement(adv)
예제 #10
0
def check_kiho_eligibility(kiho_id):
    """returns if the character can acquire the kiho and if not, also returns a reason string"""

    # check eligibility
    kiho_ = api.data.powers.get_kiho(kiho_id)
    if not kiho_:
        log.api.error(u"kiho not found: %s", kiho_id)
        return False, u"internal error"

    is_monk, is_brotherhood = api.character.is_monk()
    is_ninja = api.character.is_ninja()
    is_shugenja = api.character.is_shugenja()

    ninja_rank = 0
    school_bonus = 0

    ring_ = api.data.get_ring(kiho_.element)
    ring_rank = api.character.ring_rank(kiho_.element)

    if is_ninja:
        ninja_schools = api.character.schools.get_schools_by_tag('ninja')
        ninja_rank = sum([api.character.schools.get_rank(x) for x in ninja_schools])

    if is_monk:
        monk_schools = api.character.schools.get_schools_by_tag('monk')
        school_bonus = sum([api.character.schools.get_rank(x) for x in monk_schools])
        if api.character.has_tag_or_rule('monks_the_way_of_fire'):
            if kiho_.element == 'fire':
                school_bonus += 1

    against_mastery = school_bonus + ring_rank

    other_kiho = [api.data.powers.get_kiho(x) for x in get_all_kiho()]

    # check monks_walk_with_the_prophet
    if api.character.has_tag_or_rule('monks_walk_with_the_prophet'):
        # the first 3 kiho should be of the same element
        if 0 < len(other_kiho) < 3:
            first_kiho_element = other_kiho[0].element

            if first_kiho_element != kiho_.element:
                return False, api.tr("Your initial Kiho must be selected from the same element")
        if len(other_kiho) < 3:
            against_mastery += 1

    if is_brotherhood:
        return against_mastery >= kiho_.mastery, api.tr("Your {0} Ring or School Rank are not enough").format(ring_.text)
    elif is_monk:
        return against_mastery >= kiho_.mastery, api.tr("Your {0} Ring or School Rank are not enough").format(ring_.text)
    elif is_shugenja:
        return ring_rank >= kiho_.mastery, api.tr("Your {0} Ring Rank is not enough").format(ring_.text)
    elif is_ninja:
        return ninja_rank >= kiho_.mastery, api.tr("Your School Rank is not enough")

    return False, api.tr("You are not eligible")
예제 #11
0
def purchase_trait_rank(trait_id):
    """purchase the next rank in a trait"""

    trait_nm = l5r.models.chmodel.attrib_name_from_id(trait_id)

    cur_value = trait_rank(trait_nm)
    new_value = cur_value + 1

    cost = api.rules.get_trait_rank_cost(trait_nm, new_value)

    # build advancement model
    adv = l5r.models.advances.AttribAdv(trait_id, cost)

    adv.desc = (api.tr('{0}, Rank {1} to {2}. Cost: {3} xp')
                .format(trait_nm, cur_value, new_value, adv.cost))

    return purchase_advancement(adv)
예제 #12
0
def purchase_trait_rank(trait_id):
    """purchase the next rank in a trait"""

    trait_nm = l5r.models.chmodel.attrib_name_from_id(trait_id)

    cur_value = trait_rank(trait_nm)
    new_value = cur_value + 1

    cost = api.rules.get_trait_rank_cost(trait_nm, new_value)

    # build advancement model
    adv = l5r.models.advances.AttribAdv(trait_id, cost)

    adv.desc = (api.tr('{0}, Rank {1} to {2}. Cost: {3} xp').format(
        trait_nm, cur_value, new_value, adv.cost))

    return purchase_advancement(adv)
예제 #13
0
def purchase_memo_spell(spell_id):
    """purchase a memorized spell"""
    log.api.info(u"purchase memorized spell: %s", spell_id)

    spell_ = api.data.spells.get(spell_id)
    if not spell_:
        log.api.error(u"spell not found")
        return api.data.CMErrors.INTERNAL_ERROR

    # no special rules for memorized spells
    cost = spell_.mastery
    text = spell_.name

    adv = MemoSpellAdv(spell_id, cost)
    adv.desc = (api.tr('{0}, Mastery {1}. Cost: {2} xp').format(
        text, spell_.mastery, adv.cost))

    return api.character.purchase_advancement(adv)
예제 #14
0
def purchase_skill_rank(skill_id):
    log.api.info(u"purchase skill rank: %s", skill_id)

    skill_ = api.data.skills.get(skill_id)
    if not skill_:
        log.api.error(u"skill not found")
        return api.data.CMErrors.INTERNAL_ERROR

    cur_value = get_skill_rank(skill_id)
    new_value = cur_value + 1

    cost = api.rules.get_skill_rank_cost(skill_id, new_value)

    mastery_ability_rank = api.data.skills.get_mastery_ability(skill_id, new_value)

    adv = SkillAdv(skill_id, cost)
    if mastery_ability_rank:
        adv.rule = mastery_ability_rank.rule
    adv.desc = (api.tr('{0}, Rank {1} to {2}. Cost: {3} xp')
                .format(skill_.name, cur_value, new_value, adv.cost))

    return api.character.purchase_advancement(adv)
예제 #15
0
def leave_path():
    """the character resume its former path"""

    # this function assumes that the character is
    # currently following an alternate path

    former_school_ = get_former_school()

    if not former_school_:
        log.api.error(u"former school not found. could not resume old path")
        return False

    from l5r.models.advancements.rank import Rank
    adv = Rank()
    # the insight rank
    adv.rank = api.character.insight_rank(strict=True) + 1
    # this is the current school for this rank
    adv.school = former_school_.school
    # this is the current school rank for this school
    adv.school_rank = api.character.schools.get_school_rank(adv.school) + 1

    # no cost advancing in the same rank
    adv.cost = 0
    # description
    adv.desc = api.tr("Insight Rank {0}. School: {1} rank {2} ").format(
        adv.rank,
        api.data.schools.get(adv.school).name,
        api.character.schools.get_school_rank(adv.school))

    # get 3 spells each rank other than the first
    if api.data.schools.is_shugenja(adv.school) and adv.rank > 1:
        adv.gained_spells_count = __api.pc.get_spells_per_rank()

    # get 2 kiho each rank
    if api.data.schools.is_brotherhood_monk(adv.school) and adv.rank > 1:
        adv.gained_kiho_count = 2

    return api.character.append_advancement(adv)
예제 #16
0
def leave_path():
    """the character resume its former path"""

    # this function assumes that the character is
    # currently following an alternate path

    former_school_ = query(get_all()).where(
        lambda x: not api.data.schools.is_path(x)).order_by(a_('rank')).first_or_default(None)

    if not former_school_:
        log.api.error(u"former school not found. could not resume old path")
        return False

    from l5r.models.advancements.rank import Rank
    adv = Rank()
    # the insight rank
    adv.rank = api.character.insight_rank()
    # this is the current school for this rank
    adv.school = former_school_.school
    # no cost advancing in the same rank
    adv.cost = 0
    # description
    adv.desc = api.tr("Insight Rank {0}. School: {1} rank {2} ").format(
        adv.rank,
        api.data.schools.get(adv.school).name,
        api.character.schools.get_school_rank(adv.school) + 1
    )

    # get 3 spells each rank other than the first
    if api.data.schools.is_shugenja(adv.school) and adv.rank > 1:
        adv.gained_spells_count = __api.pc.get_spells_per_rank()

    # get 2 kiho each rank
    if api.data.schools.is_brotherhood_monk(adv.school) and adv.rank > 1:
        adv.gained_kiho_count = 2

    return api.character.append_advancement(adv)
예제 #17
0
def get_armor_name():
    """return the armor name if any"""
    return __api.pc.armor.name if __api.pc.armor is not None else api.tr("No Armor")
예제 #18
0
def get_armor_name():
    """return the armor name if any"""
    return __api.pc.armor.name if __api.pc.armor is not None else api.tr(
        "No Armor")
예제 #19
0
def check_kiho_eligibility(kiho_id):
    """returns if the character can acquire the kiho and if not, also returns a reason string"""

    # check eligibility
    kiho_ = api.data.powers.get_kiho(kiho_id)
    if not kiho_:
        log.api.error(u"kiho not found: %s", kiho_id)
        return False, u"internal error"

    is_monk, is_brotherhood = api.character.is_monk()
    is_ninja = api.character.is_ninja()
    is_shugenja = api.character.is_shugenja()

    ninja_rank = 0
    school_bonus = 0

    ring_ = api.data.get_ring(kiho_.element)
    ring_rank = api.character.ring_rank(kiho_.element)

    if is_ninja:
        ninja_schools = api.character.schools.get_schools_by_tag('ninja')
        ninja_rank = sum(
            [api.character.schools.get_rank(x) for x in ninja_schools])

    if is_monk:
        monk_schools = api.character.schools.get_schools_by_tag('monk')
        school_bonus = sum(
            [api.character.schools.get_rank(x) for x in monk_schools])
        if api.character.has_tag_or_rule('monks_the_way_of_fire'):
            if kiho_.element == 'fire':
                school_bonus += 1

    against_mastery = school_bonus + ring_rank

    other_kiho = [api.data.powers.get_kiho(x) for x in get_all_kiho()]

    # check monks_walk_with_the_prophet
    if api.character.has_tag_or_rule('monks_walk_with_the_prophet'):
        # the first 3 kiho should be of the same element
        if 0 < len(other_kiho) < 3:
            first_kiho_element = other_kiho[0].element

            if first_kiho_element != kiho_.element:
                return False, api.tr(
                    "Your initial Kiho must be selected from the same element")
        if len(other_kiho) < 3:
            against_mastery += 1

    if is_brotherhood:
        return against_mastery >= kiho_.mastery, api.tr(
            "Your {0} Ring or School Rank are not enough").format(ring_.text)
    elif is_monk:
        return against_mastery >= kiho_.mastery, api.tr(
            "Your {0} Ring or School Rank are not enough").format(ring_.text)
    elif is_shugenja:
        return ring_rank >= kiho_.mastery, api.tr(
            "Your {0} Ring Rank is not enough").format(ring_.text)
    elif is_ninja:
        return ninja_rank >= kiho_.mastery, api.tr(
            "Your School Rank is not enough")

    return False, api.tr("You are not eligible")