
#include <ss_types.h>
#include <stdproperties.h>
#include <formulas.h>
#include <macros.h>
#include <comb_mag.h>
#include <cmdparse.h>
#include <filter_funs.h>

#define CAST_LIMIT      20  
#define MANA_LIMIT      100


void tell_watcher(string str, object me, object enemy);


nomask mixed
promien_start_fail(string str)
{
    return 0;
}


nomask mixed
promien(string str)
{
    object obj, *a;

    if (str)
    {
	a = CMDPARSE_ONE_ITEM(str, "kill_access", "kill_access");
	if (sizeof(a))
	    obj = a[0];
    }
    if (!obj)
        obj = this_player()->query_attack();
    if (!obj)
        return "Na kogo chcesz rzucic ten czar?\n";

    if (this_player()->query_ghost())
	return "Jestes duchem nie mozesz nikogo zabic.\n";

    if (NPMATTACK(obj)) 
        return "Z dziwnych powodow nie mozesz rzucic tego czaru.\n";

    if (!F_DARE_ATTACK(this_player(), obj))
	return "Nie odwazysz sie rzucic tego czaru.\n";

    if (this_player()->query_mana() < MANA_LIMIT)
        return "Nie jestes wystarczajaco skoncentrowany aby rzucic ten czar.\n";

    if (random(this_player()->query_skill(SS_ELEMENT_DEATH) +
        this_player()->query_stat(SS_WIS)) < random(CAST_LIMIT))
    {
        write("Nie udalo ci sie poprawnie wypowiedziec pradawnych slow.\n");
        this_player()->add_mana(-MANA_LIMIT / 3);
        return 1;
    }

    this_player()->add_mana(-MANA_LIMIT);

    this_player()->attack_object(obj); //automatycznie rozpoczynamy walke
    this_player()->add_prop(LIVE_O_SPELL_ATTACK, this_object());
    return 1;
}


public void
spell_attack(object attacker, object target)
{
    int hurt;
    mixed *hitresult;
    string how;
    hurt = 1000;

    hitresult=target->hit_me(hurt, MAGIC_DT, 1,attacker,-1);
//    hitresult = target->hit_me(hurt, 0, attacker, 0);
    how = " brak efektu";
    if (hitresult[0] > 0)
        how == "";
    if (hitresult[0] > 10)
        how = " mocno";
    if (hitresult[0] > 20)
        how = " bardzo mocno";
    attacker->catch_msg("Wypuszczasz promien z reki w " + QTNAME(target)+" raniac go"+how + ".\n");
    target->catch_msg(QCTNAME(attacker) + " wypuszcza magiczny promien z reki raniac cie" + how +".\n");
    
    tell_watcher(QCTNAME(attacker) + " wypuszcza magiczny promien z "+
    "reki w " + QTNAME(target)+" raniac go" + how +".\n",attacker, target);

    if (target->query_hp() <= 0)
        target->do_die(attacker);
}


int
kill_access(object ob)
{
    if (!living(ob) || ob->query_ghost() || ob == this_player())
	return 0;
    else
	return 1;
}


static void
tell_watcher(string str, object me, object enemy)
{
    object *ob;
    int i;

    ob = FILTER_LIVE(all_inventory(environment(me))) - ({ me });
    ob -= ({ enemy });
    for (i = 0; i < sizeof(ob); i++)
        if (ob[i]->query_see_blood())
            ob[i]->catch_msg(str);
}

