void set_from_me(object me) { mixed exp; mapping my; NPC_D->init_npc_skill(this_object(), NPC_D->check_level(me)); my = query_entire_dbase(); if (my["max_qi"] > 9000) my["max_qi"] = 9000; if (my["max_jing"] < my["max_qi"] / 2) my["max_jing"] = my["max_qi"] / 2; if (my["max_jing"] > 6000) my["max_jing"] = 6000; my["eff_jing"] = my["max_jing"]; my["jing"] = my["max_jing"]; my["eff_qi"] = my["max_qi"]; my["qi"] = my["max_qi"]; exp = count_div(count_mul(me->query("combat_exp"), 11), 10); if (count_gt(exp, query("combat_exp"))) set("combat_exp", exp); }
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); }
int update_sex_status() { mapping my; string dodge, force, spells; int sex_per, update_flag, sex_affair; update_flag = 0; my = query_entire_dbase(); if (!mapp(my)) return 0; if (my["want"] > 0 && my["want"] > my["eff_want"]) { my["want"] -= 1; update_flag++; } if (my["enjoy"] > 0) { my["enjoy"] -= 1; update_flag++; } sex_per = my["per"] + query_temp("apply/personality"); dodge = query_skill_mapped("dodge"); force = query_skill_mapped("force"); spells = query_skill_mapped("spells"); sex_affair = 0; if (dodge) { sex_affair += SKILL_D(dodge)->query_sex_affair(); if (sex_affair == 0) ; else if (sex_affair < 0) { my["want"] += sex_affair; update_flag++; } else if (sex_affair > 0) { sex_per += sex_affair; } } if (force) { sex_affair += SKILL_D(force)->query_sex_affair(); if (sex_affair == 0) ; else if (sex_affair < 0) { my["want"] += sex_affair; update_flag++; } else if (sex_affair > 0) { sex_per += sex_affair; } } if (spells) { sex_affair += SKILL_D(spells)->query_sex_affair(); if (sex_affair == 0) ; else if (sex_affair < 0) { my["want"] += sex_affair; update_flag++; } else if (sex_affair > 0) { sex_per += sex_affair; } } sex_per += query_temp("apply/sex_personality"); if (sex_affair > 0) { object env = environment(); if (environment()) { object ob = first_inventory(environment()); while (ob) { if (living(ob)) { ob->add("want", sex_per); update_flag++; } ob = next_inventory(ob); } } } return update_flag; }
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; }
int heal_up() { int update_flag, i; mapping my; // if( this_object()->is_fighting() ) return -1; update_flag = 0; my = query_entire_dbase(); if( my["water"] > 0 ) { my["water"] -= 1; update_flag++; } if( my["food"] > 0 ) { my["food"] -= 1; update_flag++; } if( my["water"] < 1 && userp(this_object()) ) return update_flag; if( my["food"] < 1 && userp(this_object()) ) return update_flag; if( this_object()->is_fighting() ) my["jing"] += my["con"] / 9 + my["max_jingli"] / 30; else my["jing"] += my["con"] / 3 + my["max_jingli"] / 10; if( my["jing"] >= my["eff_jing"] ) { my["jing"] = my["eff_jing"]; if( my["eff_jing"] < my["max_jing"] ) { my["eff_jing"] ++; update_flag++; } } else update_flag++; if( this_object()->is_fighting() ) my["qi"] += my["con"] / 9 + my["max_neili"] / 30; else my["qi"] += my["con"] / 3 + my["max_neili"] / 10; if( my["qi"] >= my["eff_qi"] ) { my["qi"] = my["eff_qi"]; if( my["eff_qi"] < my["max_qi"] ) { my["eff_qi"] ++; update_flag++; } } else update_flag++; if( my["max_jingli"] && my["jingli"] < my["max_jingli"] ) { if( this_object()->is_fighting() ) my["jingli"] += (my["str"] + my["dex"]) / 12; else my["jingli"] += (my["str"] + my["dex"]) / 4; if( my["jingli"] > my["max_jingli"]*2 ) my["jingli"] = my["max_jingli"]*2; update_flag++; } if( my["max_neili"] && my["neili"] < my["max_neili"] ) { if( this_object()->is_fighting() ) my["neili"] += (int)this_object()->query_skill("force", 1) / 6; else my["neili"] += (int)this_object()->query_skill("force", 1) / 2; if( my["neili"] > my["max_neili"] ) my["neili"] = my["max_neili"]; update_flag++; } return update_flag; }
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); }