Esempio n. 1
0
void heart_beat() {
    int wimpy_ratio, to_wimpy, cnd_flag, oldbusy;
    mapping my;
    object ob;
    string savemyass;

    if(!this_object()) {
        return;
    }

//	command("say start heart_beat");
//	command("say i am busy"+(string)query_busy());
    if (query_temp("in_heart_beat"))
        return;

    my = query_entire_dbase();

    // If we are dying because of mortal wounds?
    if( my["eff_kee"] < 0 || my["eff_sen"] < 0 || my["eff_gin"] < 0
            || my["kee"] < -2 * my["dur"]  || my["sen"] < -2 * my["dur"] || my["gin"] < -2 * my["dur"]) {
        remove_all_enemy();
        die();
        return;
    }

    // If we are unconcious, just return;
    if(query_temp("is_unconcious"))  {
        return;
    }

    // If we're dying or falling unconcious?
    if( my["kee"] < 0 || my["sen"] < 0 || my["gin"] < 0) {
        remove_all_enemy();
        unconcious();
        return;
    }


// let NPC do something in fight that won't be affected by busy...e.g talk
//	all actions in nb_chat will be executed in fight. They should never have busy()
//	as a consequence and they should be allowed to appear at same time.

    if (is_fighting())
        if(objectp(this_object()) && !userp(this_object())) {
            this_object()->nb_chat();
            if(!this_object()) {
                return;
            }
        }

    if (!is_busy()) {

        // (1) Do attack or clean up enemy if we have fleed.
        if(is_fighting()) {
            // Hey, NPC's 心神 doesn't need to be reduced here, let's save some resource
            // my["sen"]--;
            attack();
        }

        // (2) chat() may do anything -- include destruct(this_object())
        if(objectp(this_object()) && !userp(this_object())) {
            this_object()->chat();
            if(!this_object()) {
                return;
            }
        }
    }

    // If busy, continue action and return here.
    if(is_busy()) {
        continue_action();
        return;
    }

    if(tick--) {
        return;
    } else {
        tick = 5 + random(10);
    }

    cnd_flag = update_condition();
    if (!living(this_object())) return;

    // If we are compeletely in peace, turn off heart beat.
    // heal_up() must be called prior to other two to make sure it is called
    // because the && operator is lazy :P

    if( ((cnd_flag & CND_NO_HEAL_UP) || !heal_up()) && !is_fighting()
            && !interactive(this_object())) {
        if(environment()) {
            ob = first_inventory(environment());
            while(ob && !interactive(ob)) {
                ob = next_inventory(ob);
            }
        }
        if(!ob && !query("ALWAYS_ACTIVE")) set_heart_beat(0);
    }
    if(!this_object()) return;
    if(!interactive(this_object())) return;

}
Esempio n. 2
0
void heart_beat()
{
	int wimpy_ratio, cnd_flag;
	mapping my;
	object ob;

	my = query_entire_dbase();

	// If we are dying because of mortal wounds?
	if( my["eff_kee"] < 0 || my["eff_sen"] < 0 || my["eff_gin"] < 0) {
		remove_all_enemy();
		die();
		return;
	}

	// If we're dying or falling unconcious?
	if( my["kee"] < 0 || my["sen"] < 0 || my["gin"] < 0) {
		remove_all_enemy();
		if( !living(this_object()) ) die();
		else unconcious();
		return;
	}

	// Do attack if we are fighting.
	if( is_busy() ) {
		continue_action();
		// We don't want heart beat be halt eventually, so return here.
		return;
	} else {
		// Is it time to flee?
		if( is_fighting()
		&&	intp(wimpy_ratio = (int)query("env/wimpy"))
		&&	wimpy_ratio > 0
		&&	(	my["kee"] * 100 / my["max_kee"] <= wimpy_ratio
			||	my["sen"] * 100 / my["max_sen"] <= wimpy_ratio
			||	my["gin"] * 100 / my["max_gin"] <= wimpy_ratio) )
			GO_CMD->do_flee(this_object());
		// Do attack or clean up enemy if we have fleed.
		attack();
	}

	if( !userp(this_object()) ) {
		this_object()->chat();
		// chat() may do anything -- include destruct(this_object())
		if( !this_object() ) return;	
	}

	if( tick--  ) return;
	else tick = 5 + random(10);

	cnd_flag = update_condition();

	// If we are compeletely in peace, turn off heart beat.
	// heal_up() must be called prior to other two to make sure it is called
	// because the && operator is lazy :P
	if( ((cnd_flag & CND_NO_HEAL_UP) || !heal_up())
	&&	!is_fighting() 
	&&	!interactive(this_object())) {
		if( environment() ) {
			ob = first_inventory(environment());
			while(ob && !interactive(ob))
				ob = next_inventory(ob);
		}
		if( !ob ) set_heart_beat(0);
	}

	if( !interactive(this_object()) ) return;

	// Make us a bit older. Only player's update_age is defined.
	// Note: update_age() is no need to be called every heart_beat, it
	//       remember how much time has passed since last call.
	this_object()->update_age();

	if(query_idle(this_object()) > IDLE_TIMEOUT)
		this_object()->user_dump(DUMP_IDLE);
}
Esempio n. 3
0
void heart_beat()
{
        int t;
        int period;
        int wimpy_ratio, cnd_flag;
        mapping my;
        object ob;
	object me;
	string prompt;
	int is_player;

	me = this_object();
        my = query_entire_dbase();

        if (userp(me) && living(me) && mapp(my["env"]))
        {
                // update prompt
		prompt = my["env"]["prompt"];
                if ((prompt == "time" || prompt == "mud" || prompt == "hp") &&
		    is_waiting_command() && ! me->is_attach_system())
                    
                {
                        write_prompt();
                }
                
        }

        // If we're dying or falling unconcious?
        if (my["qi"] < 0 || my["jing"] < 0)
        {
                if (! living(me)) die();
                else unconcious();

                // Why does the living test? Because
                // The wizard may set immortal but his
                // qi was -1, so I don't want return,
                // or the continue_action will never be
                // called in such case.
                if (! me || ! living(me))
                        return;
        }

        if (is_p_busy())
        {
                continue_p_busy();
        }
        
        // Do attack if we are fighting.
        if (is_busy())
        {
                continue_action();
                // We don't want heart beat be halt eventually, so return here.
        } else
	if (living(me))
        {
                string apply;
                object apply_ob;

                // Is it time to flee?
                if (is_fighting() &&
                   intp(wimpy_ratio = (int)query("env/wimpy")) &&
                   wimpy_ratio > 0 &&
                   (my["qi"] * 100 / my["max_qi"] <= wimpy_ratio ||
                    my["jing"] * 100 / my["max_jing"] <= wimpy_ratio))
                {
                        if (stringp(apply = query("env/wimpy_apply")) &&
                            objectp(apply_ob = present(apply, me)) &&
                            apply_ob->query("can_apply_for_wimpy"))
                        {
                                apply_ob->apply_for_wimpy(this_object());
                        } else
                                GO_CMD->do_flee(this_object());
                }
                
                if (query("auto_perform") || me->query_auto_perform())
                {                       
                        if (my["eff_jing"] > 0 && my["jing"] * 100 / my["eff_jing"] <= 70)
                                SKILL_D("force/regenerate")->exert(me, me);
                        if (my["eff_qi"] > 0 && my["qi"] * 100 / my["eff_qi"] <= 70)
                                SKILL_D("force/recover")->exert(me, me);

                        // 如果不在打架而且处于受伤状态,则自行疗伤
                        if (! is_fighting())
                        {
                                if (my["eff_jing"] < my["max_jing"])
                                        SKILL_D("force/inspire")->exert(me, me);
                                if (my["eff_qi"] < my["max_qi"])
                                        SKILL_D("force/heal")->exert(me, me);
                        }
                }
                // Do attack or clean up enemy if we have fleed.
                if (is_busy())
                        continue_action();
                else
                        attack();
        }

        if (my["doing"] == "scheme")
                // executing schedule now
                SCHEME_CMD->execute_schedule(me);

        if (! me) return;

        if (! (is_player = playerp(me)))
        {
                me->scan();
                // scan() may do anything -- include destruct(this_object())
                if (! me) return;
        }

        if ((t = time()) < next_beat) return;
        else next_beat = t + 5 + random(10);

	if (! my["not_living"])
        	cnd_flag = update_condition();
	if (! me) return;

	if (! (cnd_flag & CND_NO_HEAL_UP))
		cnd_flag = heal_up();

        // If we are compeletely in peace, turn off heart beat.
        // heal_up() must be called prior to other two to make sure it is called
        // because the && operator is lazy :P
        if (! cnd_flag &&
	    ! is_player &&
            ! keep_beat_flag &&
            ! is_fighting() &&
	    ! is_busy() &&
            ! interactive(this_object()))
        {
                if (environment() && query("chat_msg"))
                {
                        ob = first_inventory(environment());
                        while (ob && ! interactive(ob))
                                ob = next_inventory(ob);
                } else
                        ob = 0;
                if (! ob) set_heart_beat(0);
        }

        update_all_limb_damage();
        
        if (! me || ! is_player) return;

        // Make us a bit older. Only player's update_age is defined.
        // Note: update_age() is no need to be called every heart_beat, it
        //       remember how much time has passed since last call.
        me->update_age();

#ifdef AUTO_SAVE
        if (living(me))
        {
            	period = t - ((int) my["last_save"]);
                if (period < 0 || period > 15 * 60)
            	{
                	string msg;
                        msg = HBCYN HIW "【档案存储】您的档案已经自动存盘,"
                              "欢迎访问论坛 http://bbs.mudbuilder.com/ 。\n" NOR;
                	if (! me->save())
                    	msg = HIR "【数据保护】由于数据异常,您的档"
                              "案本次存盘失败。\n" NOR;
                	set("last_save", t);
                	tell_object(me, msg);
            }
        }
#endif
	if (! interactive(me))
		return;

        if (my["food"] <= 0 || my["water"] <= 0)
        {
		if (environment() &&
		    ! environment()->is_chat_room() &&
                    ! wizardp(me) &&
                    ! query_condition("hunger"))
		{
			// born & enter the world
                        apply_condition("hunger", 1);
		}
        }

        if (query_idle(me) > IDLE_TIMEOUT && ! wizardp(me) &&
            (! mapp(my["env"]) || ! my["env"]["keep_idle"]))
                me->user_dump(DUMP_IDLE);
}