Mocha Example: suck_blood

The following code is used on the ochre gulls in the Brown River valley. The basic idea is that whenever a gull hits, it has some chance to suck blood from the victim, causing minimal damage but lowering the strength of the victim for some period of time. If strength drops past a certain point, the victim dies instantly.


person {
    public:
        integer chance = 50, is_weak = 4, collapse = 0;
        action[PV] suck_mob = "You drive your beak into @N and drink deeply "
                              "of his blood!\n",
                   suck_vict = "@+n drives @h beak into you and sucks your "
                               "blood!\n",
                   suck_room = "@+n drives @h beak into @N and sucks @H "
                               "blood!\n";
        action[P] death_pc = "You collapse in a heap.\n",
                  death_room = "@+n collapses in a heap.\n",
                  when_weak = "You feel your life slipping away!\n",
                  when_ok = "You feel weaker!\n";
        boolean minimal_damage = true;
        dice duration = 0d1+3, penalty = 1d2;
}

special
do_attack (person mob, person pc, object wpn, integer type, integer amt,
           integer quality)
{
    if (number (1, 100) > chance || pc.nohassled || amt == 0)
        return ignored;

    /* Add a strength penalty modifier to the victim. */
    add_modifier (pc, spell_drain_blood, duration.roll, modify_strength, 
                  -penalty.roll, true, false);

    show_action (suck_mob, to_player, mob, pc);
    show_action (suck_vict, to_victim, mob, pc);
    show_action (suck_room, to_room, sight, if_visible, mob, pc);

    if (pc.strength <= collapse) {
        /* Set total damage to double remaining hit points to kill
           pc--make sure sanctuary doesn't cause problems. */
        show_action (death_pc, to_player, pc);
        show_action (death_room, to_room, sight, if_visible, pc);
        return do_damage (mob, pc, type_none, pc.hit_points * 2 + 1000);
    }

    if (pc.strength <= is_weak)
        show_action (when_weak, to_player, pc);
    else
        show_action (when_ok, to_player, pc);

    /* Do minimal damage if blood is drawn. */
    if (minimal_damage)
        amt = 2;

    return do_damage (mob, pc, type, amt);
}

Return to Mocha's Main Page