mj.c
来自「C实现的MUD,对大家基本入门网络游戏很有帮助!」· C语言 代码 · 共 1,663 行 · 第 1/5 页
C
1,663 行
#include <ansi.h>
inherit NPC;
#define MJ_DATA "/data/npc/mj_data.o"
#define END 286
#define START 0
void check_flower(mapping who);
int to_say_play();
int to_say_rule();
int do_check_Mj(string datastr,string str);
int do_check_eat(string num1,string num2,string LastDump);
int delete_last_dump(string whoId);
int do_check_win(string str);
int check_hu(string strW);
int set_mjdata(object me,int *winner);
int *get_mjdata(string id);
int get_tc(mapping who);
varargs int do_dump(string str,object me);
varargs int do_touch(string str,object me);
varargs int wash_mj(int amount);
varargs int do_win(string str,object me);
varargs int do_gon(string str,object me);
varargs int do_pon(string str,object me);
string check_id(string str,string kind);
string do_delete_Mj(string datastr,string str,int amount);
string show_mj(string str,int flag);
string sort_data(string str);
mixed do_check_num(string str,int flag);
//牌只资料
string MjE= "1w2w3w4w5w6w7w8w9w1t2t3t4t5t6t7t8t9t1s2s3s4s5s6s7s8s9seasowenojofabaf1f2f3f4f5f6f7f8";
string *MjC = ({"",
"一万","二万","叁万","四万","伍万","六万","七万","八万","九万",
"一筒","二筒","叁筒","四筒","伍筒","六筒","七筒","八筒","九筒",
"一索","二索","叁索","四索","伍索","六索","七索","八索","九索",
"东风","南风","西风","北风","红中","青发","白板",
"1 春","2 夏","3 秋","4 冬","1 梅","2 兰","3 竹","4 菊","暗杠 "
});
int K;
string Tc = "";
//资料
int Auto;
int Auto_Tin;
int Auto_Gon;
int Auto_Pon;
int Count;
int count;
int end;
int Goned;
int HU_F;
int NO_HU;
int NO_GON;
int Playing;
int Play;
int Times;
int Touched;
int NowPlayer;
string List ="";
string LookP ="";
string *NowPlayerId = ({ "","","","" });
string LastDumpId="";
string LastDump="";
mapping P1Data = ([
"Show": "color","Id": "","Name": "","Mj": "","Out": "","OutGon": "","OutPon": "",
"OutFlower": "","Auto": "","AutoTin": "","AutoGon": "","AutoPon": "","Dump": ""
]);
mapping P2Data = ([
"Show": "color","Id": "","Name": "","Mj": "","Out": "","OutGon": "","OutPon": "",
"OutFlower": "","Auto": "","AutoTin": "","AutoGon": "","AutoPon": "","Dump": ""
]);
mapping P3Data = ([
"Show": "color","Id": "","Name": "","Mj": "","Out": "","OutGon": "","OutPon": "",
"OutFlower": "","Auto": "","AutoTin": "","AutoGon": "","AutoPon": "","Dump": ""
]);
mapping P4Data = ([
"Show": "color","Id": "","Name": "","Mj": "","Out": "","OutGon": "","OutPon": "",
"OutFlower": "","Auto": "","AutoTin": "","AutoGon": "","AutoPon": "","Dump": ""
]);
void create()
{
set_name("白晶晶",({"jing"}));
set_weight(1);
set("per",50);
set("no_kill",1);
set("unit","张");
set("inquiry",([
"mj": (: to_say_play :),
"麻将": (: to_say_play :),
"玩法": (: to_say_play :),
"play": (: to_say_play :),
"规则": (: to_say_rule :),
"rule": (: to_say_rule :),
]));
setup();
seteuid(getuid());
}
void init()
{
add_action("do_addin","addin");
add_action("do_dump","dump");
add_action("do_eat","eat");
add_action("do_gon","gon");
add_action("do_win","hu");
add_action("do_help","help");
add_action("do_look","look");
add_action("do_look",".");
add_action("do_look",".1");
add_action("do_look",".2");
add_action("do_look",".3");
add_action("do_look",".4");
add_action("do_look","..");
add_action("do_touch","mo");
add_action("do_touch","0");
add_action("do_pon","pon");
add_action("do_pon","p");
add_action("do_restart","restart");
add_action("wash_mj","start");
add_action("do_setmj","setmj");
add_action("show_top","top");
add_action("ch","ch");
}
int do_addin()
{
object me=this_player();
if (me->query("id")==P1Data["Id"]
|| me->query("id")==P2Data["Id"]
|| me->query("id")==P3Data["Id"]
|| me->query("id")==P4Data["Id"]){
if (!Playing) message_vision("$N对着欠脚啊~~不停的哭哭啼啼.....。\n",me);
else message_vision("$N对着大家说今天自摸"+(random(12)+1)+"次就好。\n",me);
return 1;
}
if (Playing){
if (random(1))
message_vision(this_object()->name()+
"对着"+me->name()+"说道:牌局正在进行中请到旁边坐一下...。\n",me);
else message_vision("$N对着我也要玩啦~~不停的哭哭啼啼.....。\n",me);
return 1;
}
if (!P1Data["Id"] || P1Data["Id"]==""){
P1Data["Id"]=me->query("id");
NowPlayerId[Play]=me->query("id");
message_vision("$N加入了这场牌局。\n",me);
Play++;
Times=0;
LookP+="在前面有"+me->name()+",";
return 1;
}else if (!P2Data["Id"] || P2Data["Id"]==""){
P2Data["Id"]=me->query("id");
message_vision("$N加入了这场牌局。\n",me);
NowPlayerId[Play]=me->query("id");
Play++;
Times=0;
LookP+=me->name()+",";
return 1;
}else if (!P3Data["Id"] || P3Data["Id"]==""){
P3Data["Id"]=me->query("id");
message_vision("$N加入了这场牌局。\n",me);
NowPlayerId[Play]=me->query("id");
Play++;
Times=0;
LookP+=me->name()+",";
return 1;
}else if (!P4Data["Id"] || P4Data["Id"]==""){
P4Data["Id"]=me->query("id");
message_vision("$N加入了这场牌局。\n",me);
NowPlayerId[Play]=me->query("id");
Play++;
Times=0;
LookP+=me->name();
return wash_mj(Play);
}
return notify_fail("人数已足。\n");
}
int do_dump(string str,object me)
{
int check,i;
int *winner=({0,0,0,0});
string ponid;
mapping who;
object met;
if (!me) me=this_player();
if (check_id(me->query("id"),"player")!="");
else {
command("stare "+me->query("id"));
command("say 这牌局跟你没关系。");
return 1;
}
if (!Playing){
command("kick "+me->query("id"));
command("say 牌局还没开始你拿牌乱丢!!");
return 1;
}
tell_object(me,"换谁打牌:"+NowPlayerId[NowPlayer]+"\n");
if (!str) return notify_fail("指令:dump <代码>\n");
if (me->query("id")!=NowPlayerId[NowPlayer]){
command("hammer "+me->query("id"));
command("say 想偷打牌!!作弊啊?");
return 1;
}
if (!Touched){
command("faint "+me->query("id"));
command("say 你还没摸牌!!");
return 1;
}
if (Goned==5){
message_vision("$N说道:此局因"+HIR+"五 合牌"+NOR+"请再重新开始 start 。\n",this_object());
Playing=0;
Count++;
if (Play==4){
for (i=0;i<Play;i++){
met=present(NowPlayerId[i], environment(this_object()));
if (!met) met=find_player(NowPlayerId[i]);
if (!met);
else{
if (!winner=get_mjdata(NowPlayerId[i])) winner=({0,0,0,0});
winner[0]++;
set_mjdata(met,winner);
}
}
}
return 1;
}
NO_HU=0;
HU_F=0;
NO_GON=0;
if (me->query("id")==P1Data["Id"]) who=P1Data;
else if (me->query("id")==P2Data["Id"]) who=P2Data;
else if (me->query("id")==P3Data["Id"]) who=P3Data;
else if (me->query("id")==P4Data["Id"]) who=P4Data;
check=do_check_Mj(MjE,str);
if (check==0) return notify_fail("没有["+str+"]这种代码。\n");
check=do_check_Mj(who["Mj"],str);
if (check==0) return notify_fail("你没"+do_check_num(str,0)+"这张牌。\n");
tell_object(me,"你说道:"+do_check_num(str,0)+"\n");
tell_room(environment(this_object()),me->name()+"说道:"+do_check_num(str,0)+"\n",me);
command("say "+me->name()+"打出了一张"+do_check_num(str,0));
who["Mj"]=do_delete_Mj(who["Mj"],str,1);
LastDump=str;
who["Dump"]+=str;
LastDumpId=who["Id"];
Touched=0;
NowPlayer++;
NowPlayer%=Play;
message_vision("$N说道:现在轮到"+HIY+NowPlayerId[NowPlayer]+NOR+"摸牌。\n",this_object());
if (Auto_Tin){
ponid=check_id(str,"tin");
if (ponid!=""){
me=present(ponid, environment(this_object()));
if (!me) me=find_player(ponid);
if (!me) return 1;
return do_win(str,me);
}
}
if (Auto_Gon){
ponid=check_id(str,"gon");
if (ponid!=""){
me=present(ponid, environment(this_object()));
if (!me) me=find_player(ponid);
if (!me) return 1;
do_gon(str,me);
}
}
if (Auto_Pon){
ponid=check_id(str,"pon");
if (ponid!=""){
me=present(ponid, environment(this_object()));
if (!me) me=find_player(ponid);
if (!me) return 1;
do_pon(str,me);
}
}
if (count==(end-16-Goned)){
Playing=0;
Count++;
message_vision("$N说道:此局"+HIY+"流局"+NOR+"请再重新开始 "+HIR+"start"+NOR+" 。\n",this_object());
str="所剩下的牌只有:"+show_mj(List[count..end],2)+"\n";
tell_room(environment(this_object()),str);
if (Play==4){
for (i=0;i<Play;i++){
met=present(NowPlayerId[i], environment(this_object()));
if (!met) met=find_player(NowPlayerId[i]);
if (!met);
else{
if (!winner=get_mjdata(NowPlayerId[i])) winner=({0,0,0,0});
winner[0]++;
set_mjdata(met,winner);
}
}
}
return 1;
}
if (Auto){
if (NowPlayerId[NowPlayer]==P1Data["Id"]) who=P1Data;
else if (NowPlayerId[NowPlayer]==P2Data["Id"]) who=P2Data;
else if (NowPlayerId[NowPlayer]==P3Data["Id"]) who=P3Data;
else if (NowPlayerId[NowPlayer]==P4Data["Id"]) who=P4Data;
if (who["Auto"]=="auto"){
me=present(NowPlayerId[NowPlayer], environment(this_object()));
if (!me) me=find_player(NowPlayerId[NowPlayer]);
if (!me) return 1;
call_out("do_touch",1,"AUTO",me);
}
}
return 1;
}
int do_eat(string str)
{
int LastDumpMan,i;
string num1,num2;
object me=this_player();
mapping who;
if (!str || sscanf(str,"%s %s",num1,num2)!=2) return 0;
if (check_id(me->query("id"),"player")!="");
else {
command("stare "+me->query("id"));
command("say 这牌局跟你没关系。");
return 1;
}
if (!Playing){
command("say 牌局还没开始。");
return 1;
}
tell_object(me,"换谁摸牌:"+NowPlayerId[NowPlayer]+"\n");
if (me->query("id")!=NowPlayerId[NowPlayer]){
command("hammer "+me->query("id"));
command("say 还没轮到你。");
return 1;
}
if (!LastDump || LastDump==""){
command("hammer "+me->query("id"));
command("say 摸牌吧。");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?