// NPC wei.c 韦一笑
// Modify By River@SJ 99.06
#include <ansi.h>
inherit NPC;
inherit F_MASTER;
string *drugs = ({
       MEDICINE_D("sanhuang"),
       MEDICINE_D("huiyang"),
       MEDICINE_D("yuling"),
       MEDICINE_D("yuzhen"),
       MEDICINE_D("tianwang"),
});

void destroy(object ob);
void create()
{
        set_name("韦一笑",({"wei yixiao","wei","yixiao"}));
        set("title","明教护教法王");
        set("nickname",GRN"青翼蝠王"NOR);
        set("long", "他是明教的四大护法之一的青翼蝠王。\n"+
                    "他身材高大，形如竹杆，生就一身好轻功。\n");
        set("age", 51);
        set("attitude", "peaceful");
        set("shen", -12000);
        set("str", 26);
        set("int", 26);
        set("con", 25);
        set("dex", 45);        
        set("max_qi", 3000);
        set("max_jing", 2400);
        set("eff_jingli", 2000);
        set("jiali", 100);
        set("combat_exp", 1200000);
        set("unique", 1);
set("vendetta_mark", "lcc");
        set_skill("strike",150); 
        set_skill("literate",110);
        set_skill("dodge",190);
        set_skill("force", 150);
        set_skill("piaoyi-shenfa", 190);
        set_skill("hanbing-mianzhang",130);
        set_skill("shenghuo-shengong", 130);
        set_skill("parry", 140);
        map_skill("force", "shenghuo-shengong");
        map_skill("dodge", "piaoyi-shenfa");
        map_skill("strike", "hanbing-mianzhang");
        map_skill("parry", "hanbing-mianzhang");
        prepare_skill("strike","hanbing-mianzhang");

        create_family("明教",36,"法王");
        set("chat_chance_combat", 30);
        set("chat_msg_combat", ({
                (: perform_action, "strike.xixue":),
        }));
        setup();
        carry_object("/d/mingjiao/obj/yel-cloth")->wear();
}


void init()
{
	::init();
        add_action("do_kill", "kill");
        add_action("do_kill", "tk");
        add_action("do_kill", "teamkill");
        add_action("do_kill", "hit");
}
void attempt_apprentice(object ob)
{
        object me  = this_object();
        mapping fam = ob->query("family");
        mapping my_fam = me->query("family");
        if(!fam || fam["family_name"] != "明教"){
                command("say "+RANK_D->query_respect(ob) + "与本派素无来往，不知此话从何谈起？");
                return;
        }
        if(fam["master_name"] == "张无忌"){
                command("haha");
                command("say "+RANK_D->query_respect(ob)+"已是教主亲传弟子，"+RANK_D->query_self(me)+"怎敢再收你为徒？"); 
                return;
        }
        if (fam["generation"] == my_fam["generation"]){
                command("shake");
                command("say "+RANK_D->query_respect(ob)+"已拜光明使为师，"+RANK_D->query_self(me)+"怎敢再收你为徒？");
                return;
        }        
        if ((int)ob->query_skill("shenghuo-shengong", 1) < 100) {
                command("say 要学更为高深的武功，必须有高深的内功修为。"); 
                command("say " + RANK_D->query_respect(ob)+"是否还应该在圣火神功上多下点功夫？");
                return;
        }        
        if ((int)ob->query_skill("dodge",1) < 100) {
                command("say 想学我的轻功身法，必须有一定的轻功基础。");
                command("say 在轻功方面，" + RANK_D->query_respect(ob)+"是否还做得不够？");
                return;
        }
        command("say 嗯，看你还是个学武的料，我就收下你吧！");
        command("say 多谢明尊敝佑，让我明教又得一良材，为康扶正义，把我明教发扬光大吧。");
        command("recruit " + ob->query("id"));
        ob->set("title", this_object()->query("title")+"属下教众");
}

int accept_object(object who, object ob,object me)
{
//      object drug;
        int exp,job,pot,bonus,gold, i, j =0;
        object* ppl;

        me = this_object();
        if(ob->query("name") != "巡逻令" || ob->query("id") != "xunluo ling") {
               command("? "+who->query("id"));  
               return 0;
        }
        if(ob->query("owner") != who->query("id")){
               command("say 哼，你这是从哪偷来的？");
               call_out("destroy", 1, ob);  
               return 1;
        }
        if(!ob->query("task_ok")){
               command("say 这令牌你还是先拿给殷无禄吧。");
               command("pat "+who->query("id"));  
               return 0;
        }
        if(!who->query_condition("mj_xunluo")){
               command("say 这么长时间，你都干吗去了？");
               command("disapp "+who->query("id"));
               call_out("destroy", 1, ob);  
               return 1;
        }
        command("nod");
        command("say 愿我明尊座下所有弟子都如此勤奋向上！");
//      message_vision("\n$N取出一粒药丸交给$n。\n",me, who);
//      drug = new(drugs[random(sizeof(drugs))] );
//      drug->move(who);
        bonus = who->query_temp("mj/attacker1");
        if(bonus > 7) bonus = 7;
        exp = 400 + random(350)+ bonus * 50;
        job = who->query("mingjiao_job");
        gold = job/50 + random(job/50);
        if( gold < 1) gold = 1;
        if( gold > 15) gold = 14 + random(3);
        if (who->query("combat_exp") < 2000000) who->add("combat_exp",exp);
         if (who->query("combat_exp") > 2000000) pot=600/6+random(600/10);
        else
         pot= exp/5 + random(exp/6);
        who->add("potential", pot);
        who->add("mingjiao_job", 1);
        who->delete_temp("mj/attacker1");
        who->delete_temp("mj/over");
        if(who->query("potential") > who->query("max_pot")) 
           who->set("potential", who->query("max_pot"));
        MONEY_D->pay_player(who, gold * 10000);
        message_vision("\n$N给了$n一些"HIY"黄金"NOR"。\n"NOR,this_object(),who);
        command("whisper "+who->query("id")+" 你辛苦了，这些金子拿去好好快活一番吧。");
        tell_object(who,"你已经为明教完成"+chinese_number(job)+"次工作了，再好好努力吧。\n");
        log_file("job/mj_job",sprintf("%s %s(%s)%d次任务奖励经验%d，潜能%d，现在经验%d。\n",
                ctime(time())[4..19],who->name(1),who->query("id"),job,exp,pot,who->query("combat_exp")));
        call_out("destroy", 1, ob);
        i = sizeof(ppl);
        while(i--) {
            if (userp(ppl[i]) && !wizardp(ppl[i]) && ppl[i]->query("jiuyang/wei"))
            j++;
        } 
        if( random(job) > 200
         && job < 2001
         && job %50 == 0
         && random(who->query_int()) >= 30
         && random(who->query_dex()) >= 30
         && random(who->query("kar")+ who->query("pur")+ who->query("per")) >= 30
         && j < 4
         && !who->query("jiuyang/wei")){
          command("whisper "+who->query("id")+" 你快去张教主那里一次，他好象有什么传闻要告诉你。");
          log_file("quest/jiuyang",sprintf("%s %s(%s)做明教任务第%s次的时候，得到韦一笑的指示，听到有关九阳神功的传闻。\n",
            ctime(time())[4..19],who->name(1), capitalize(getuid(who)),chinese_number(job)));
          who->set("jiuyang/wei", 1);
        }
        return 1;
}

void destroy(object ob)
{
        destruct(ob);
        return;
}

int do_kill(string arg)
{
        object ob,ob2; 
        object me = this_player();
        ob2 = this_object();

        if (!arg) return 0;
        ob = present(arg, environment(me));
        if (ob == this_object() || ob == me) return 0;
        if (!ob || !ob->is_character()) return 0;

        
        if (userp(ob)&& ob->query("family/family_name") == "明教") {
                if (me->query("family/family_name") == "明教") { 
        message_vision(ob2->name()+"对$N喝道：身为明教弟子，竟然杀自己的同门？我宰了你！\n", me);
                }
                else {
                        message_vision(ob2->name()+"对$N喝道：大胆狂徒，居然敢来明教撒野！\n", me);
                        kill_ob(me);
                }
                me->set("vendetta/明教", 1);
                return 1;
        }
        return 0;
}


