The Reliques of Tolti-Aph

An interactive fiction by Graham Nelson (2005) - the Inform 7 source text

Home page

Contents
Previous
Next

Complete text
Section 3(f) - Striking blows

The to-hit roll is a number that varies.

To modify to-hit roll by (amount - a number) for (reason - text):
    if the amount >= 0, say ", +[amount] for [reason]";
    otherwise say ", [amount] for [reason]";
    increase the to-hit roll by the amount.

Calculating combat modifiers of something is an activity.

For calculating combat modifiers of the player:
    modify to-hit roll by the level of the player for "your level";
    continue the activity.

To make (attacker - a person) strike a blow against (defender - a person):
    if the attacker is the player, say "You attack "; otherwise say "[The attacker] attacks ";
    if the defender is the player, say "you, "; otherwise say "[the defender], ";
    let the damage done be the unarmed combat hit dice of the attacker;
    if the attacker carries a weapon
    begin;
        let the instrument be the savagest weapon carried by the attacker;
        let the damage done be the hit dice of the instrument;
        say "[technique of the instrument] [the instrument]";
    otherwise;
        say hand-to-hand combat method of the attacker;
    end if;
    change the to-hit roll to a random number from 1 to 20;
    say ", making an attack roll (1d20) of [to-hit roll]";
    carry out the calculating combat modifiers activity with the attacker;
    if the instrument is a weapon and the to-hit bonus of the instrument is not 0, modify to-hit roll by the to-hit bonus of the instrument for "wielding a blessed weapon";
    if the to-hit roll <= 2
    begin;
        say " - critical miss (2 or less): ";
        if the instrument is a weapon
        begin;
            if the attacker is the player
            begin;
                silently try dropping the instrument;
                if the player does not carry the instrument, say "you dropped [the instrument]!";
                otherwise say "[the instrument] shook in your hand!";
            otherwise;
                now the instrument is in the location;
                say "[the attacker] drops [the instrument]!";
            end if;
        otherwise;
            decrease the strength of the attacker by 1;
            if the attacker is the player
            begin;
                say "you actually injure yourself!";
                if the player is killed, end the game saying "You have fumbled into an inglorious demise";
            otherwise;
                say "[the attacker] roars with impotent rage!";
            end if;
        end if;
        stop;
    end if;
    if the to-hit roll <= 10
    begin;
        say " - miss (3 to 10): no damage done!";
        stop;
    end if;
    if the to-hit roll <= 19
    begin;
        say " - hit (11 to 19), doing [damage done] of damage: ";
        let the hits be the roll of the damage done;
        if the hits is 1, say " point"; otherwise say " points";
    otherwise;
        say " - critical hit (20 or more), doing [damage done] doubled of damage: ";
        let the hits be the roll of the damage done;
        let the hits be the hits multiplied by 2;
        say ", doubled up to [hits] points";
    end if;
    let the counter-charm be the defensive charm of the attacker;
    if the defender is affected by the counter-charm
    begin;
        say ", soaked up by the [counter-charm] spell.";
        stop;
    end if;
    make the defender take hits points of damage.