예제 #1
0
def spl_engrave(sn, level, ch, victim, target):
    handler_magic.target_name, arg1 = game_utils.read_word(
        handler_magic.target_name)
    handler_magic.target_name, arg2 = game_utils.read_word(
        handler_magic.target_name)

    if ch.is_npc():
        return

    if not arg1 or not arg2:
        ch.send("What spell do you wish to engrave, and on what?\n")
        return

    sn = handler_magic.find_spell(ch, arg2)
    if not sn or not sn.spell_fun or (not ch.is_npc()
                                      and ch.level < sn.skill_level):
        ch.send("You can't do that.\n")
        return

    if ch.learned[sn] < 100:
        ch.send("You are not adept at that spell.\n")
        return

    item = ch.get_item_carry(arg1)
    if not item:
        ch.send("You are not carrying that.\n")
        return

    if item.item_type != merc.ITEM_STAFF:
        ch.send("That is not a staff.\n")
        return

    if item.value[0] != 0 or item.value[1] != 0 or item.value[
            2] != 0 or item.value[3] != 0:
        ch.send("You need an unenchanted staff.\n")
        return

    item_list = [(merc.PURPLE_MAGIC, "purple"), (merc.RED_MAGIC, "red"),
                 (merc.BLUE_MAGIC, "blue"), (merc.GREEN_MAGIC, "green"),
                 (merc.YELLOW_MAGIC, "yellow")]
    for (aa, bb) in item_list:
        if sn.target == aa:
            item.value[0] = ch.spl[aa] // 4
            col = bb
            break
    else:
        ch.send("Oh dear...big bug...please inform an Immortal.\n")
        return

    item.value[1] = (item.value[0] // 10) + 1
    item.value[2] = (item.value[0] // 10) + 1
    item.value[3] = sn
    item.name = "{} staff {} {}".format(ch.name, col, sn.name)
    item.short_descr = "{}'s {} staff of {}".format(ch.name, col, sn.name)
    item.description = "A {} staff is lying here.".format(col)
    item.flags.take = True
    item.hold = True
    handler_game.act("You engrave $p.", ch, item, None, merc.TO_CHAR)
    handler_game.act("$n engraves $p.", ch, item, None, merc.TO_ROOM)
예제 #2
0
def cmd_cast(ch, argument):
    # Switched NPC's can cast spells, but others can't.
    if ch.is_npc() and not ch.desc:
        return

    # Polymorphed players cannot cast spells
    if not ch.is_npc() and ch.is_affected(
            merc.AFF_POLYMORPH) and not ch.vampaff.is_set(merc.VAM_DISGUISED):
        if not ch.is_obj():
            ch.send("You cannot cast spells in this form.\n")
            return

    if ch.itemaff.is_set(merc.ITEMA_REFLECT):
        ch.send("You are unable to focus your spell.\n")
        return

    argument, arg1 = game_utils.read_word(argument)
    argument, arg2 = game_utils.read_word(argument)
    handler_magic.target_name = arg2

    if not arg1:
        ch.send("Cast which what where?\n")
        return

    sn = handler_magic.find_spell(ch, arg1)
    if not sn or not sn.spell_fun or (not ch.is_npc()
                                      and ch.level < sn.skill_level
                                      or ch.learned.get(sn.name, 0) == 0):
        ch.send("You don't know any spells of that name.\n")
        return

    if ch.position < sn.minimum_position:
        if not ch.is_npc() and not ch.is_vampire() and ch.vampaff.is_set(
                merc.VAM_CELERITY):
            if ch.move < 25:
                ch.send("You can't concentrate enough.\n")
                return

            ch.move -= 25
        else:
            if ch.move < 50:
                ch.send("You can't concentrate enough.\n")
                return

            ch.move -= 50

    mana = 0 if ch.is_npc() else max(
        sn.min_mana, 100 // (2 + (ch.level * 12) - sn.skill_level))

    if not ch.is_npc() and ch.special.is_set(merc.SPC_WOLFMAN):
        if ch.powers[merc.WPOWER_OWL] < 4:
            mana *= 2

    # Locate targets.
    victim = None
    vo = None

    target = merc.TARGET_NONE
    if sn.target == merc.TAR_IGNORE:
        pass
    elif sn.target == merc.TAR_CHAR_OFFENSIVE:
        if not arg2:
            victim = ch.fighting
            if not victim:
                ch.send("Cast the spell on whom?\n")
                return
        else:
            victim = ch.get_char_room(arg2)
            if not victim:
                ch.not_here(arg2)
                return

        if ch == victim:
            ch.send("Cast this on yourself? Ok...\n")

        if victim.itemaff.is_set(merc.ITEMA_REFLECT):
            ch.send("You are unable to focus your spell upon them.\n")
            return

        if not victim.is_npc() and (not ch.can_pk()
                                    or not victim.can_pk()) and victim != ch:
            ch.send("You are unable to affect them.\n")
            return

        if not ch.is_npc():
            if ch.is_affected(merc.AFF_CHARM) and instance.characters[
                    ch.master] == victim:
                ch.send("You can't do that on your own follower.\n")
                return

        vo = victim
        target = merc.TARGET_CHAR
    elif sn.target == merc.TAR_CHAR_DEFENSIVE:
        if not arg2:
            victim = ch
        else:
            victim = ch.get_char_room(handler_magic.target_name)
            if not victim:
                ch.not_here(handler_magic.target_name)
                return

        if victim.itemaff.is_set(merc.ITEMA_REFLECT):
            ch.send("You are unable to focus your spell upon them.\n")
            return

        vo = victim
        target = merc.TARGET_CHAR
    elif sn.target == merc.TAR_CHAR_SELF:
        if arg2 and game_utils.is_name(handler_magic.target_name, ch.name):
            ch.send("You can't cast this spell on another.\n")
            return

        vo = ch
        target = merc.TARGET_CHAR
    elif sn.target == merc.TAR_OBJ_INV:
        if not arg2:
            ch.send("What should the spell be cast upon?\n")
            return

        obj = ch.get_item_carry(handler_magic.target_name)
        if not obj:
            ch.send("You are not carrying that.\n")
            return

        vo = obj
        target = merc.TARGET_ITEM
    else:
        comm.notify("cmd_cast: bad target for sn {}".format(sn),
                    merc.CONSOLE_ERROR)
        return

    if not ch.is_npc() and ch.mana < mana:
        ch.send("You don't have enough mana.\n")
        return

    if not game_utils.str_cmp(sn.name, "ventriloquate"):
        handler_magic.say_spell(ch, sn)

    ch.wait_state(sn.beats)

    if not ch.is_npc() and game_utils.number_percent() > ch.learned[sn.name]:
        ch.send("You lost your concentration.\n")
        ch.mana -= mana // 2
        ch.improve_spl(sn.target)
    else:
        ch.mana -= mana

        if ch.is_npc():
            sn.spell_fun(sn.name, int(ch.level), ch, vo, target)
        else:
            sn.spell_fun(sn.name, int(ch.spl[sn.target] * 0.25), ch, vo,
                         target)
            ch.improve_spl(sn.target)

    if sn.target == merc.TAR_CHAR_OFFENSIVE and victim != ch and (
            victim.master and instance.characters[victim.master] != ch):
        for vch_id in ch.in_room.people[:]:
            vch = instance.characters[vch_id]

            if victim == vch and not victim.fighting:
                fight.multi_hit(victim, ch, merc.TYPE_UNDEFINED)
                break
예제 #3
0
파일: do_cast.py 프로젝트: totalgit/PyRom
def do_cast(ch, argument):
    # Switched NPC's can cast spells, but others can't.
    if ch.is_npc() and not ch.desc:
        return

    argument, arg1 = game_utils.read_word(argument)
    argument, arg2 = game_utils.read_word(argument)
    handler_magic.target_name = arg2

    if not arg1:
        ch.send("Cast which what where?\n")
        return
    sn = handler_magic.find_spell(ch, arg1)
    if not sn or sn.spell_fun is None \
            or (not ch.is_npc()
                and (ch.level < sn.skill_level[ch.guild.name]
                     or ch.learned.get(sn.name, 0) == 0)):
        ch.send("You don't know any spells of that name.\n")
        return
    if ch.position < sn.minimum_position:
        ch.send("You can't concentrate enough.\n")
        return
    if ch.level + 2 == sn.skill_level[ch.guild.name]:
        mana = 50
    else:
        mana = max(sn.min_mana,
                   100 // (2 + ch.level - sn.skill_level[ch.guild.name]))
    # Locate targets.
    victim = None
    obj = None
    vo = None
    target = merc.TARGET_NONE
    if sn.target == merc.TAR_IGNORE:
        pass
    elif sn.target == merc.TAR_CHAR_OFFENSIVE:
        if not arg2:
            victim = ch.fighting
            if not victim:
                ch.send("Cast the spell on whom?\n")
                return
        else:
            victim = ch.get_char_room(arg2)
            if not victim:
                ch.send("They aren't here.\n")
                return
            # if ch == victim:
            # ch.send("You can't do that to yourself.\n")
            # return
        if not ch.is_npc():
            if fight.is_safe(ch, victim) and victim != ch:
                ch.send("Not on that target.\n")
                return

            fight.check_killer(ch, victim)

        if ch.is_affected(merc.AFF_CHARM) and ch.master == victim:
            ch.send("You can't do that on your own follower.\n")
            return
        vo = victim
        target = merc.TARGET_CHAR
    elif sn.target == merc.TAR_CHAR_DEFENSIVE:
        if not arg2:
            victim = ch
        else:
            victim = ch.get_char_room(handler_magic.target_name)
        if not victim:
            ch.send("They aren't here.\n")
            return
        vo = victim
        target = merc.TARGET_CHAR
    elif sn.target == merc.TAR_CHAR_SELF:
        if arg2 and handler_magic.target_name not in ch.name.lower():
            ch.send("You can't cast this spell on another.\n")
            return

        vo = ch
        target = merc.TARGET_CHAR
    elif sn.target == merc.TAR_OBJ_INV:
        if not arg2:
            ch.send("What should the spell be cast upon?\n")
            return
        obj = ch.get_item_carry(handler_magic.target_name, ch)
        if not obj:
            ch.send("You are not carrying that.\n")
            return
        vo = obj
        target = merc.TARGET_ITEM
    elif sn.target == merc.TAR_OBJ_CHAR_OFF:
        if not arg2:
            victim = ch.fighting
            if not victim:
                ch.send("Cast the spell on whom or what?\n")
                return
            target = merc.TARGET_CHAR
        else:
            victim = ch.get_char_room(handler_magic.target_name)
            obj = ch.get_item_here(handler_magic.target_name)
            if victim:
                target = merc.TARGET_CHAR
                # check the sanity of the attack
                if fight.is_safe_spell(ch, victim, False) and victim != ch:
                    ch.send("Not on that target.\n")
                    return
                if ch.is_affected(merc.AFF_CHARM) and ch.master == victim:
                    ch.send("You can't do that on your own follower.\n")
                    return
                if not ch.is_npc():
                    fight.check_killer(ch, victim)
                vo = victim
            elif obj:
                vo = obj
                target = merc.TARGET_ITEM
            else:
                ch.send("You don't see that here.\n")
                return
    elif sn.target == merc.TAR_OBJ_CHAR_DEF:
        if not arg2:
            vo = ch
            target = merc.TARGET_CHAR
        else:
            victim = ch.get_char_room(handler_magic.target_name)
            obj = ch.get_item_carry(handler_magic.target_name, ch)
            if not victim:
                vo = victim
                target = merc.TARGET_CHAR
            elif not obj:
                vo = obj
                target = merc.TARGET_ITEM
            else:
                ch.send("You don't see that here.\n")
                return
    else:
        logging.error("BUG: Do_cast: bad target for sn %s.", sn)
        return

    if not ch.is_npc() and ch.mana < mana:
        ch.send("You don't have enough mana.\n")
        return

    if sn.name != "ventriloquate":
        handler_magic.say_spell(ch, sn)
    state_checks.WAIT_STATE(ch, sn.beats)

    if random.randint(1, 99) > ch.get_skill(sn.name):
        ch.send("You lost your concentration.\n")
        if ch.is_pc():
            ch.check_improve(sn, False, 1)
        ch.mana -= mana // 2
    else:
        ch.mana -= mana
        if ch.is_npc() or ch.guild.fMana:
            # class has spells
            sn.spell_fun(sn, ch.level, ch, vo, target)
        else:
            sn.spell_fun(sn, 3 * ch.level // 4, ch, vo, target)
            if ch.is_pc():
                ch.check_improve(sn, True, 1)

    if (sn.target == merc.TAR_CHAR_OFFENSIVE or (sn.target == merc.TAR_OBJ_CHAR_OFF and target == merc.TARGET_CHAR)) \
            and victim != ch and victim.master != ch:
        for vch_id in ch.in_room.people[:]:
            vch = instance.characters[vch_id]
            if victim == vch and not victim.fighting:
                fight.check_killer(victim, ch)
                fight.multi_hit(victim, ch, merc.TYPE_UNDEFINED)
                break
    return
예제 #4
0
def do_cast(ch, argument):
    # Switched NPC's can cast spells, but others can't.
    if ch.is_npc() and not ch.desc:
        return

    argument, arg1 = game_utils.read_word(argument)
    argument, arg2 = game_utils.read_word(argument)
    handler_magic.target_name = arg2

    if not arg1:
        ch.send("Cast which what where?\n")
        return
    sn = handler_magic.find_spell(ch, arg1)
    if not sn or sn.spell_fun is None \
            or (not ch.is_npc()
                and (ch.level < sn.skill_level[ch.guild.name]
                     or ch.learned.get(sn.name, 0) == 0)):
        ch.send("You don't know any spells of that name.\n")
        return
    if ch.position < sn.minimum_position:
        ch.send("You can't concentrate enough.\n")
        return
    if ch.level + 2 == sn.skill_level[ch.guild.name]:
        mana = 50
    else:
        mana = max(sn.min_mana, 100 // (2 + ch.level - sn.skill_level[ch.guild.name]))
    # Locate targets.
    victim = None
    obj = None
    vo = None
    target = merc.TARGET_NONE
    if sn.target == merc.TAR_IGNORE:
        pass
    elif sn.target == merc.TAR_CHAR_OFFENSIVE:
        if not arg2:
            victim = ch.fighting
            if not victim:
                ch.send("Cast the spell on whom?\n")
                return
        else:
            victim = ch.get_char_room(arg2)
            if not victim:
                ch.send("They aren't here.\n")
                return
            # if ch == victim:
            # ch.send("You can't do that to yourself.\n")
            # return
        if not ch.is_npc():
            if fight.is_safe(ch, victim) and victim != ch:
                ch.send("Not on that target.\n")
                return

            fight.check_killer(ch, victim)

        if ch.is_affected(merc.AFF_CHARM) and ch.master == victim:
            ch.send("You can't do that on your own follower.\n")
            return
        vo = victim
        target = merc.TARGET_CHAR
    elif sn.target == merc.TAR_CHAR_DEFENSIVE:
        if not arg2:
            victim = ch
        else:
            victim = ch.get_char_room(handler_magic.target_name)
        if not victim:
            ch.send("They aren't here.\n")
            return
        vo = victim
        target = merc.TARGET_CHAR
    elif sn.target == merc.TAR_CHAR_SELF:
        if arg2 and handler_magic.target_name not in ch.name.lower():
            ch.send("You can't cast this spell on another.\n")
            return

        vo = ch
        target = merc.TARGET_CHAR
    elif sn.target == merc.TAR_OBJ_INV:
        if not arg2:
            ch.send("What should the spell be cast upon?\n")
            return
        obj = ch.get_item_carry(handler_magic.target_name, ch)
        if not obj:
            ch.send("You are not carrying that.\n")
            return
        vo = obj
        target = merc.TARGET_ITEM
    elif sn.target == merc.TAR_OBJ_CHAR_OFF:
        if not arg2:
            victim = ch.fighting
            if not victim:
                ch.send("Cast the spell on whom or what?\n")
                return
            target = merc.TARGET_CHAR
        else:
            victim = ch.get_char_room(handler_magic.target_name)
            obj = ch.get_item_here(handler_magic.target_name)
            if victim:
                target = merc.TARGET_CHAR
                # check the sanity of the attack
                if fight.is_safe_spell(ch, victim, False) and victim != ch:
                    ch.send("Not on that target.\n")
                    return
                if ch.is_affected(merc.AFF_CHARM) and ch.master == victim:
                    ch.send("You can't do that on your own follower.\n")
                    return
                if not ch.is_npc():
                    fight.check_killer(ch, victim)
                vo = victim
            elif obj:
                vo = obj
                target = merc.TARGET_ITEM
            else:
                ch.send("You don't see that here.\n")
                return
    elif sn.target == merc.TAR_OBJ_CHAR_DEF:
        if not arg2:
            vo = ch
            target = merc.TARGET_CHAR
        else:
            victim = ch.get_char_room(handler_magic.target_name)
            obj = ch.get_item_carry(handler_magic.target_name, ch)
            if not victim:
                vo = victim
                target = merc.TARGET_CHAR
            elif not obj:
                vo = obj
                target = merc.TARGET_ITEM
            else:
                ch.send("You don't see that here.\n")
                return
    else:
        logging.error("BUG: Do_cast: bad target for sn %s.", sn)
        return

    if not ch.is_npc() and ch.mana < mana:
        ch.send("You don't have enough mana.\n")
        return

    if sn.name != "ventriloquate":
        handler_magic.say_spell(ch, sn)
    state_checks.WAIT_STATE(ch, sn.beats)

    if random.randint(1, 99) > ch.get_skill(sn.name):
        ch.send("You lost your concentration.\n")
        if ch.is_pc():
            ch.check_improve( sn, False, 1)
        ch.mana -= mana // 2
    else:
        ch.mana -= mana
        if ch.is_npc() or ch.guild.fMana:
            # class has spells
            sn.spell_fun(sn, ch.level, ch, vo, target)
        else:
            sn.spell_fun(sn, 3 * ch.level // 4, ch, vo, target)
            if ch.is_pc():
                ch.check_improve( sn, True, 1)

    if (sn.target == merc.TAR_CHAR_OFFENSIVE or (sn.target == merc.TAR_OBJ_CHAR_OFF and target == merc.TARGET_CHAR)) \
            and victim != ch and victim.master != ch:
        for vch_id in ch.in_room.people[:]:
            vch = instance.characters[vch_id]
            if victim == vch and not victim.fighting:
                fight.check_killer(victim, ch)
                fight.multi_hit(victim, ch, merc.TYPE_UNDEFINED)
                break
    return