Exemple #1
0
def spell_holy_word(sn, level, ch, victim, target):
    # RT really nasty high-level attack spell */
    handler_game.act("$n utters a word of divine power! ", ch, None, None, merc.TO_ROOM)
    ch.send("You utter a word of divine power.\n")

    for vch_id in ch.in_room.people:

        vch = instance.characters[vch_id]
        if (ch.is_good() and vch.is_good()) or (
            ch.is_evil() and vch.is_evil()) or (
            ch.is_neutral() and vch.is_neutral()):
            vch.send("You feel full more powerful.\n")
            const.skill_table['frenzy'].spell_fun('frenzy', level, ch, vch, merc.TARGET_CHAR)
            const.skill_table['bless'].spell_fun('bless', level, ch, vch, merc.TARGET_CHAR)
        elif (ch.is_good() and state_checks.IS_EVIL(vch)) or (
            ch.is_evil() and state_checks.IS_GOOD(vch)):
            if not fight.is_safe_spell(ch, vch, True):
                const.skill_table['curse'].spell_fun('curse', level, ch, vch, merc.TARGET_CHAR)
                vch.send("You are struck down! \n")
                dam = game_utils.dice(level, 6)
                fight.damage(ch, vch, dam, sn, merc.DAM_ENERGY, True)
        elif state_checks.IS_NEUTRAL(ch):
            if not fight.is_safe_spell(ch, vch, True):
                const.skill_table['curse'].spell_fun('curse', level // 2, ch, vch, merc.TARGET_CHAR)
                vch.send("You are struck down! \n")
                dam = game_utils.dice(level, 4)
                fight.damage(ch, vch, dam, sn, merc.DAM_ENERGY, True)
    ch.send("You feel drained.\n")
    ch.move = 0
    ch.hit = ch.hit // 2
def spell_frost_breath(sn, level, ch, victim, target):
    handler_game.act("$n breathes out a freezing cone of frost! ", ch, None, victim, merc.TO_NOTVICT)
    handler_game.act("$n breathes a freezing cone of frost over you! ", ch, None, victim, merc.TO_VICT)
    handler_game.act("You breath out a cone of frost.", ch, None, None, merc.TO_CHAR)

    hpch = max(12, ch.hit)
    hp_dam = random.randint(hpch // 11 + 1, hpch // 6)
    dice_dam = game_utils.dice(level, 16)

    dam = max(hp_dam + dice_dam // 10, dice_dam + hp_dam // 10)
    effects.cold_effect(victim.in_room, level, dam // 2, merc.TARGET_ROOM)

    for vch in victim.in_room.people[:]:
        if fight.is_safe_spell(ch, vch, True) or (vch.is_npc() and ch.is_npc() and (ch.fighting != vch or vch.fighting != ch)):
            continue

        if vch == victim:  # full damage */
            if handler_magic.saves_spell(level, vch, merc.DAM_COLD):
                effects.cold_effect(vch, level // 2, dam // 4, merc.TARGET_CHAR)
                fight.damage(ch, vch, dam // 2, sn, merc.DAM_COLD, True)
            else:
                effects.cold_effect(vch, level, dam, merc.TARGET_CHAR)
                fight.damage(ch, vch, dam, sn, merc.DAM_COLD, True)
        else:
            if handler_magic.saves_spell(level - 2, vch, merc.DAM_COLD):
                effects.cold_effect(vch, level // 4, dam // 8, merc.TARGET_CHAR)
                fight.damage(ch, vch, dam // 4, sn, merc.DAM_COLD, True)
            else:
                effects.cold_effect(vch, level // 2, dam // 4, merc.TARGET_CHAR)
                fight.damage(ch, vch, dam // 2, sn, merc.DAM_COLD, True)
Exemple #3
0
def spell_gas_breath(sn, level, ch, victim, target):
    handler_game.act("$n breathes out a cloud of poisonous gas! ", ch, None,
                     None, merc.TO_ROOM)
    handler_game.act("You breath out a cloud of poisonous gas.", ch, None,
                     None, merc.TO_CHAR)

    hpch = max(16, ch.hit)
    hp_dam = random.randint(hpch // 15 + 1, 8)
    dice_dam = game_utils.dice(level, 12)

    dam = max(hp_dam + dice_dam // 10, dice_dam + hp_dam // 10)
    effects.poison_effect(ch.in_room, level, dam, merc.TARGET_ROOM)

    for vch_id in ch.in_room.people:

        vch = instance.characters[vch_id]
        if fight.is_safe_spell(
                ch, vch, True) or (ch.is_npc() and vch.is_npc() and
                                   (ch.fighting == vch or vch.fighting == ch)):
            continue

        if handler_magic.saves_spell(level, vch, merc.DAM_POISON):
            effects.poison_effect(vch, level // 2, dam // 4, merc.TARGET_CHAR)
            fight.damage(ch, vch, dam // 2, sn, merc.DAM_POISON, True)
        else:
            effects.poison_effect(vch, level, dam, merc.TARGET_CHAR)
            fight.damage(ch, vch, dam, sn, merc.DAM_POISON, True)
def spell_chain_lightning(sn, level, ch, victim, target):
    # H first strike */
    handler_game.act("A lightning bolt leaps from $n's hand and arcs to $N.",
                     ch, None, victim, merc.TO_ROOM)
    handler_game.act("A lightning bolt leaps from your hand and arcs to $N.",
                     ch, None, victim, merc.TO_CHAR)
    handler_game.act("A lightning bolt leaps from $n's hand and hits you! ",
                     ch, None, victim, merc.TO_VICT)

    dam = game_utils.dice(level, 6)
    if handler_magic.saves_spell(level, victim, merc.DAM_LIGHTNING):
        dam = dam // 3
    fight.damage(ch, victim, dam, sn, merc.DAM_LIGHTNING, True)
    last_vict = victim
    level = level - 4  # decrement damage */

    # new targets */
    while level > 0:
        found = False
        for tmp_vict_id in ch.in_room.people:
            tmp_vict = instance.characters[tmp_vict_id]
            if not fight.is_safe_spell(ch, tmp_vict,
                                       True) and tmp_vict is not last_vict:
                found = True
                last_vict = tmp_vict
                handler_game.act("The bolt arcs to $n! ", tmp_vict, None, None,
                                 merc.TO_ROOM)
                handler_game.act("The bolt hits you! ", tmp_vict, None, None,
                                 merc.TO_CHAR)
                dam = game_utils.dice(level, 6)
                if handler_magic.saves_spell(level, tmp_vict,
                                             merc.DAM_LIGHTNING):
                    dam = dam // 3
                fight.damage(ch, tmp_vict, dam, sn, merc.DAM_LIGHTNING, True)
                level = level - 4  # decrement damage */

        if not found:  # no target found, hit the caster */
            if ch == None:
                return

            if last_vict == ch:  # no double hits */
                handler_game.act("The bolt seems to have fizzled out.", ch,
                                 None, None, merc.TO_ROOM)
                handler_game.act("The bolt grounds out through your body.", ch,
                                 None, None, merc.TO_CHAR)
                return

            last_vict = ch
            handler_game.act("The bolt arcs to $n...whoops! ", ch, None, None,
                             merc.TO_ROOM)
            ch.send("You are struck by your own lightning! \n")
            dam = game_utils.dice(level, 6)
            if handler_magic.saves_spell(level, ch, merc.DAM_LIGHTNING):
                dam = dam // 3
            fight.damage(ch, ch, dam, sn, merc.DAM_LIGHTNING, True)
            level = level - 4  # decrement damage */
            if ch == None:
                return
def spell_chain_lightning(sn, level, ch, victim, target):
    # H first strike */
    handler_game.act("A lightning bolt leaps from $n's hand and arcs to $N.", ch, None, victim, merc.TO_ROOM)
    handler_game.act("A lightning bolt leaps from your hand and arcs to $N.", ch, None, victim, merc.TO_CHAR)
    handler_game.act("A lightning bolt leaps from $n's hand and hits you! ", ch, None, victim, merc.TO_VICT)

    dam = game_utils.dice(level, 6)
    if handler_magic.saves_spell(level, victim, merc.DAM_LIGHTNING):
        dam = dam // 3
    fight.damage(ch, victim, dam, sn, merc.DAM_LIGHTNING, True)
    last_vict = victim
    level = level - 4  # decrement damage */

    # new targets */
    while level > 0:
        found = False
        for tmp_vict_id in ch.in_room.people:
            tmp_vict = instance.characters[tmp_vict_id]
            if not fight.is_safe_spell(ch, tmp_vict, True) and tmp_vict is not last_vict:
                found = True
                last_vict = tmp_vict
                handler_game.act("The bolt arcs to $n! ", tmp_vict, None, None, merc.TO_ROOM)
                handler_game.act("The bolt hits you! ", tmp_vict, None, None, merc.TO_CHAR)
                dam = game_utils.dice(level, 6)
                if handler_magic.saves_spell(level, tmp_vict, merc.DAM_LIGHTNING):
                    dam = dam // 3
                fight.damage(ch, tmp_vict, dam, sn, merc.DAM_LIGHTNING, True)
                level = level - 4  # decrement damage */

        if not found:  # no target found, hit the caster */
            if ch == None:
                return

            if last_vict == ch:  # no double hits */
                handler_game.act("The bolt seems to have fizzled out.", ch, None, None, merc.TO_ROOM)
                handler_game.act("The bolt grounds out through your body.", ch, None, None, merc.TO_CHAR)
                return

            last_vict = ch
            handler_game.act("The bolt arcs to $n...whoops! ", ch, None, None, merc.TO_ROOM)
            ch.send("You are struck by your own lightning! \n")
            dam = game_utils.dice(level, 6)
            if handler_magic.saves_spell(level, ch, merc.DAM_LIGHTNING):
                dam = dam // 3
            fight.damage(ch, ch, dam, sn, merc.DAM_LIGHTNING, True)
            level = level - 4  # decrement damage */
            if ch == None:
                return
def spell_earthquake(sn, level, ch, victim, target):
    ch.send("The earth trembles beneath your feet! \n")
    handler_game.act("$n makes the earth tremble and shiver.", ch, None, None, merc.TO_ROOM)

    for vch in instance.characters.values():
        if not vch.in_room:
            continue
        if vch.in_room == ch.in_room:
            if vch != ch and not fight.is_safe_spell(ch, vch, True):
                if state_checks.IS_AFFECTED(vch, merc.AFF_FLYING):
                    fight.damage(ch, vch, 0, sn, merc.DAM_BASH, True)
                else:
                    fight.damage(ch, vch, level + game_utils.dice(2, 8), sn, merc.DAM_BASH, True)
            continue

        if vch.in_room.area == ch.in_room.area:
            vch.send("The earth trembles and shivers.\n")
Exemple #7
0
def spell_earthquake(sn, level, ch, victim, target):
    ch.send("The earth trembles beneath your feet! \n")
    handler_game.act("$n makes the earth tremble and shiver.", ch, None, None,
                     merc.TO_ROOM)

    for vch in instance.characters.values():
        if not vch.in_room:
            continue
        if vch.in_room == ch.in_room:
            if vch != ch and not fight.is_safe_spell(ch, vch, True):
                if state_checks.IS_AFFECTED(vch, merc.AFF_FLYING):
                    fight.damage(ch, vch, 0, sn, merc.DAM_BASH, True)
                else:
                    fight.damage(ch, vch, level + game_utils.dice(2, 8), sn,
                                 merc.DAM_BASH, True)
            continue

        if vch.in_room.area == ch.in_room.area:
            vch.send("The earth trembles and shivers.\n")
Exemple #8
0
def spell_fire_breath(sn, level, ch, victim, target):
    handler_game.act("$n breathes forth a cone of fire.", ch, None, victim,
                     merc.TO_NOTVICT)
    handler_game.act("$n breathes a cone of hot fire over you! ", ch, None,
                     victim, merc.TO_VICT)
    handler_game.act("You breath forth a cone of fire.", ch, None, None,
                     merc.TO_CHAR)

    hpch = max(10, ch.hit)
    hp_dam = random.randint(hpch // 9 + 1, hpch // 5)
    dice_dam = game_utils.dice(level, 20)

    dam = max(hp_dam + dice_dam // 10, dice_dam + hp_dam // 10)
    effects.fire_effect(victim.in_room, level, dam // 2, merc.TARGET_ROOM)

    for vch in victim.in_room.people[:]:
        if fight.is_safe_spell(
                ch, vch, True) or (vch.is_npc() and ch.is_npc() and
                                   (ch.fighting != vch or vch.fighting != ch)):
            continue

        if vch == victim:  # full damage */
            if handler_magic.saves_spell(level, vch, merc.DAM_FIRE):
                effects.fire_effect(vch, level // 2, dam // 4,
                                    merc.TARGET_CHAR)
                fight.damage(ch, vch, dam // 2, sn, merc.DAM_FIRE, True)
            else:
                effects.fire_effect(vch, level, dam, merc.TARGET_CHAR)
                fight.damage(ch, vch, dam, sn, merc.DAM_FIRE, True)
        else:  # partial damage */
            if handler_magic.saves_spell(level - 2, vch, merc.DAM_FIRE):
                effects.fire_effect(vch, level // 4, dam // 8,
                                    merc.TARGET_CHAR)
                fight.damage(ch, vch, dam // 4, sn, merc.DAM_FIRE, True)
            else:
                effects.fire_effect(vch, level // 2, dam // 4,
                                    merc.TARGET_CHAR)
                fight.damage(ch, vch, dam // 2, sn, merc.DAM_FIRE, True)
Exemple #9
0
def spell_frost_breath(sn, level, ch, victim, target):
    handler_game.act("$n breathes out a freezing cone of frost! ", ch, None,
                     victim, merc.TO_NOTVICT)
    handler_game.act("$n breathes a freezing cone of frost over you! ", ch,
                     None, victim, merc.TO_VICT)
    handler_game.act("You breath out a cone of frost.", ch, None, None,
                     merc.TO_CHAR)

    hpch = max(12, ch.hit)
    hp_dam = random.randint(hpch // 11 + 1, hpch // 6)
    dice_dam = game_utils.dice(level, 16)

    dam = max(hp_dam + dice_dam // 10, dice_dam + hp_dam // 10)
    effects.cold_effect(victim.in_room, level, dam // 2, merc.TARGET_ROOM)

    for vch in victim.in_room.people[:]:
        if fight.is_safe_spell(
                ch, vch, True) or (vch.is_npc() and ch.is_npc() and
                                   (ch.fighting != vch or vch.fighting != ch)):
            continue

        if vch == victim:  # full damage */
            if handler_magic.saves_spell(level, vch, merc.DAM_COLD):
                effects.cold_effect(vch, level // 2, dam // 4,
                                    merc.TARGET_CHAR)
                fight.damage(ch, vch, dam // 2, sn, merc.DAM_COLD, True)
            else:
                effects.cold_effect(vch, level, dam, merc.TARGET_CHAR)
                fight.damage(ch, vch, dam, sn, merc.DAM_COLD, True)
        else:
            if handler_magic.saves_spell(level - 2, vch, merc.DAM_COLD):
                effects.cold_effect(vch, level // 4, dam // 8,
                                    merc.TARGET_CHAR)
                fight.damage(ch, vch, dam // 4, sn, merc.DAM_COLD, True)
            else:
                effects.cold_effect(vch, level // 2, dam // 4,
                                    merc.TARGET_CHAR)
                fight.damage(ch, vch, dam // 2, sn, merc.DAM_COLD, True)
Exemple #10
0
def spell_gas_breath(sn, level, ch, victim, target):
    handler_game.act("$n breathes out a cloud of poisonous gas! ", ch, None, None, merc.TO_ROOM)
    handler_game.act("You breath out a cloud of poisonous gas.", ch, None, None, merc.TO_CHAR)

    hpch = max(16, ch.hit)
    hp_dam = random.randint(hpch // 15 + 1, 8)
    dice_dam = game_utils.dice(level, 12)

    dam = max(hp_dam + dice_dam // 10, dice_dam + hp_dam // 10)
    effects.poison_effect(ch.in_room, level, dam, merc.TARGET_ROOM)

    for vch_id in ch.in_room.people:

        vch = instance.characters[vch_id]
        if fight.is_safe_spell(ch, vch, True) or (ch.is_npc() and vch.is_npc() and (ch.fighting == vch or vch.fighting == ch)):
            continue

        if handler_magic.saves_spell(level, vch, merc.DAM_POISON):
            effects.poison_effect(vch, level // 2, dam // 4, merc.TARGET_CHAR)
            fight.damage(ch, vch, dam // 2, sn, merc.DAM_POISON, True)
        else:
            effects.poison_effect(vch, level, dam, merc.TARGET_CHAR)
            fight.damage(ch, vch, dam, sn, merc.DAM_POISON, True)
Exemple #11
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
Exemple #12
0
def obj_cast_spell(sn, level, ch, victim, obj):
    import const
    import fight
    target = merc.TARGET_NONE
    vo = None
    if not sn:
        return
    if sn not in const.skill_table or not const.skill_table[sn].spell_fun:
        print("BUG: Obj_cast_spell: bad sn %d." % sn)
        return
    sn = const.skill_table[sn]
    if sn.target == merc.TAR_IGNORE:
        vo = None
    elif sn.target == merc.TAR_CHAR_OFFENSIVE:
        if not victim:
            victim = ch.fighting
        if not victim:
            ch.send("You can't do that.\n")
            return
        if fight.is_safe(ch, victim) and ch != victim:
            ch.send("Something isn't right...\n")
            return
        vo = victim
        target = merc.TARGET_CHAR
    elif sn.target == merc.TAR_CHAR_DEFENSIVE \
            or sn.target == merc.TAR_CHAR_SELF:
        if not victim:
            victim = ch
        vo = victim
        target = merc.TARGET_CHAR
    elif sn.target == merc.TAR_OBJ_INV:
        if not obj:
            ch.send("You can't do that.\n")
            return
        vo = obj
        target = merc.TARGET_ITEM
    elif sn.target == merc.TAR_OBJ_CHAR_OFF:
        if not victim and not obj:
            if ch.fighting:
                victim = ch.fighting
            else:
                ch.send("You can't do that.\n")
                return
        if victim:
            if fight.is_safe_spell(ch, victim, False) and ch != victim:
                ch.send("Somehting isn't right...\n")
                return
            vo = victim
            target = merc.TARGET_CHAR
        else:
            vo = obj
            target = merc.TARGET_ITEM
    elif sn.target == merc.TAR_OBJ_CHAR_DEF:
        if not victim and not obj:
            vo = ch
            target = merc.TARGET_CHAR
        elif victim:
            vo = victim
            target = merc.TARGET_CHAR
        else:
            vo = obj
            target = merc.TARGET_ITEM
    else:
        print("BUG: Obj_cast_spell: bad target for sn %s." % sn.name)
        return
    target_name = ""
    sn.spell_fun(sn, level, ch, vo, target)
    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 in ch.in_room.people[:]:
            if victim == vch and not victim.fighting:
                fight.check_killer(victim, ch)
                fight.multi_hit(victim, ch, merc.TYPE_UNDEFINED)
Exemple #13
0
def obj_cast_spell(sn, level, ch, victim, obj):
    import const
    import fight
    target = merc.TARGET_NONE
    vo = None
    if not sn:
        return
    if sn not in const.skill_table or not const.skill_table[sn].spell_fun:
        print("BUG: Obj_cast_spell: bad sn %d." % sn)
        return
    sn = const.skill_table[sn]
    if sn.target == merc.TAR_IGNORE:
        vo = None
    elif sn.target == merc.TAR_CHAR_OFFENSIVE:
        if not victim:
            victim = ch.fighting
        if not victim:
            ch.send("You can't do that.\n")
            return
        if fight.is_safe(ch, victim) and ch != victim:
            ch.send("Something isn't right...\n")
            return
        vo = victim
        target = merc.TARGET_CHAR
    elif sn.target == merc.TAR_CHAR_DEFENSIVE \
            or sn.target == merc.TAR_CHAR_SELF:
        if not victim:
            victim = ch
        vo = victim
        target = merc.TARGET_CHAR
    elif sn.target == merc.TAR_OBJ_INV:
        if not obj:
            ch.send("You can't do that.\n")
            return
        vo = obj
        target = merc.TARGET_ITEM
    elif sn.target == merc.TAR_OBJ_CHAR_OFF:
        if not victim and not obj:
            if ch.fighting:
                victim = ch.fighting
            else:
                ch.send("You can't do that.\n")
                return
        if victim:
            if fight.is_safe_spell(ch, victim, False) and ch != victim:
                ch.send("Somehting isn't right...\n")
                return
            vo = victim
            target = merc.TARGET_CHAR
        else:
            vo = obj
            target = merc.TARGET_ITEM
    elif sn.target == merc.TAR_OBJ_CHAR_DEF:
        if not victim and not obj:
            vo = ch
            target = merc.TARGET_CHAR
        elif victim:
            vo = victim
            target = merc.TARGET_CHAR
        else:
            vo = obj
            target = merc.TARGET_ITEM
    else:
        print("BUG: Obj_cast_spell: bad target for sn %s." % sn.name)
        return
    target_name = ""
    sn.spell_fun(sn, level, ch, vo, target)
    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 in ch.in_room.people[:]:
            if victim == vch and not victim.fighting:
                fight.check_killer(victim, ch)
                fight.multi_hit(victim, ch, merc.TYPE_UNDEFINED)
Exemple #14
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