npc.vns
来自「C实现的MUD,对大家基本入门网络游戏很有帮助!」· VNS 代码 · 共 153 行
VNS
153 行
// npc.c
#include <command.h>
inherit CHARACTER;
inherit F_CLEAN_UP;
object carry_object(string file)
{
object ob;
if( !objectp(ob = new(file)) ) return 0;
ob->move(this_object());
return ob;
}
object add_money(string type, int amount)
{
object ob;
ob = carry_object("/clone/money/" + type);
if( !ob ) return 0;
ob->set_amount(amount);
}
int accept_fight(object who)
{
string att;
att = query("attitude");
if( is_fighting() ) switch(att) {
case "heroism":
command("say 哼!出招吧!\n");
break;
default:
command("say 想倚多为胜,这不是欺人太甚吗!\n");
return 0;
}
if( (int)query("jing") * 100 / (int)query("max_jing") >= 90
&& (int)query("qi") * 100 / (int)query("max_qi") >= 90 ) {
switch(att) {
case "friendly":
command("say " + RANK_D->query_self(this_object())
+ "怎么可能是" + RANK_D->query_respect(who)
+ "的对手?\n");
return 0;
case "aggressive":
case "killer":
command("say 哼!出招吧!\n");
break;
default:
if( !is_fighting() )
command("say 既然" + RANK_D->query_respect(who)
+ "赐教," + RANK_D->query_self(this_object())
+ "只好奉陪。\n");
}
return 1;
} else
return 0;
}
// This function is called by the reset() of the room that creates this
// npc. When this function is called, it means the room demand the npc
// to return its startroom.
int return_home(object home)
{
// Are we at home already?
if( !environment()
|| environment()==home )
return 1;
// Are we able to leave?
if( !living(this_object())
|| is_fighting()
|| !mapp(environment()->query("exits")) ) return 0;
// Leave for home now.
message("vision", this_object()->name() + "急急忙忙地离开了。\n",
environment(), this_object());
return move(home);
}
// This is the chat function dispatcher. If you use function type chat
// message, you can either define your own functions or use the default
// ones.
int chat()
{
string *msg;
int chance, rnd;
if( !environment() ) return 0;
if( !chance = (int)query(is_fighting()? "chat_chance_combat": "chat_chance") )
return 0;
if( arrayp(msg = query(is_fighting()? "chat_msg_combat": "chat_msg"))) {
if( random(100) < chance ) {
rnd = random(sizeof(msg));
if( stringp(msg[rnd]) )
say(msg[rnd]);
else if( functionp(msg[rnd]) )
return evaluate(msg[rnd]);
}
return 1;
}
}
// Default chat function: Let the npc random move to another room.
int random_move()
{
mapping exits;
string *dirs;
if( !mapp(exits = environment()->query("exits")) ) return 0;
dirs = keys(exits);
command("go " + dirs[random(sizeof(dirs))]);
}
// Default chat function: Let the npc cast his/her enabled spells
void cast_spell(string spell)
{
string spell_skill;
if( stringp(spell_skill = query_skill_mapped("spells")))
SKILL_D(spell_skill)->cast_spell(this_object(), spell);
}
// Default chat function: Let the npc exert his/her enabled force
int exert_function(string func)
{
string force_skill;
if( stringp(force_skill = query_skill_mapped("force")))
SKILL_D(force_skill)->exert_function(this_object(), func);
}
// Default chat function: Let the npc perform special action with
// his/her enabled martial art
int perform_action(string action)
{
object weapon;
string martial_skill, act;
if( sscanf(action, "%s.%s", martial_skill, act) != 2 )
return 0;
martial_skill = query_skill_mapped(martial_skill);
if( stringp(martial_skill) )
return SKILL_D(martial_skill)->perform_action(this_object(), act);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?