亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? npc.c

?? 最新的仙鏡傳說服務(wù)器C語言源碼
?? C
?? 第 1 頁 / 共 3 頁
字號(hào):
// $Id: npc.c,v 1.12 2003/07/01 00:29:54 lemit Exp $
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
#include <time.h>

#include "map.h"
#include "npc.h"
#include "clif.h"
#include "pc.h"
#include "itemdb.h"
#include "script.h"
#include "mob.h"
#include "db.h"
#include "timer.h"
#include "pet.h"
#include "battle.h"
#include "skill.h"

#ifdef MEMWATCH
#include "memwatch.h"
#endif

struct npc_src_list {
	struct npc_src_list * next;
	char name[4];
} ;

static struct npc_src_list *npc_src_first,*npc_src_last;
static int npc_id=START_NPC_NUM;
static int npc_warp,npc_shop,npc_script,npc_mob;

int npc_get_new_npc_id(void){ return npc_id++; }

static struct dbt *ev_db;
static struct dbt *npcname_db;

struct event_data {
	struct npc_data *nd;
	int pos;
};
static struct tm ev_tm_b;	// 帪寁僀儀儞僩梡


/*==========================================
 * NPC偺?hào)硨鴫?桳岠壔
 *------------------------------------------
 */
int npc_enable(const char *name,int flag)
{
	struct npc_data *nd=strdb_search(npcname_db,name);
	if (nd==NULL)
		return 0;
	
	if (flag) {	// 桳岠壔
		nd->flag&=~1;
		clif_spawnnpc(nd);
	}else{		// 柍岠壔
		nd->flag|=1;
		clif_clearchar(&nd->bl,0);
	}
	return 0;
}

/*==========================================
 * NPC傪柤慜偱扵偡
 *------------------------------------------
 */
struct npc_data* npc_name2id(const char *name)
{
	return strdb_search(npcname_db,name);
}
/*==========================================
 * 僀儀儞僩僉儏乕偺僀儀儞僩張棟
 *------------------------------------------
 */
int npc_event_dequeue(struct map_session_data *sd)
{
	sd->npc_id=0;
	if (sd->eventqueue[0][0]) {	// 僉儏乕偺僀儀儞僩張棟
		char *name=calloc(50, 1);
		int i;
		if (name==NULL) {
			printf("run_script: out of memory !\n");
			exit(1);
		}
		memcpy(name,sd->eventqueue[0],50);
		for(i=MAX_EVENTQUEUE-2;i>=0;i--)
			memcpy(sd->eventqueue[i],sd->eventqueue[i+1],50);
		add_timer(gettick()+100,npc_event_timer,sd->bl.id,(int)name);
	}
	return 0;
}

/*==========================================
 * 僀儀儞僩偺抶墑幚峴
 *------------------------------------------
 */
int npc_event_timer(int tid,unsigned int tick,int id,int data)
{
	struct map_session_data *sd=map_id2sd(id);
	if (sd==NULL)
		return 0;
	
	npc_event(sd,(const char *)data);
	free((void*)data);
	return 0;
}
/*==========================================
 * 慡偰偺N(yùn)PC偺On*僀儀儞僩幚峴
 *------------------------------------------
 */
int npc_event_doall_sub(void *key,void *data,va_list ap)
{
	char *p=(char *)key;
	struct event_data *ev=(struct event_data *)data;
	int *c=va_arg(ap,int *);
	const char *name=va_arg(ap,const char *);

	if( (p=strchr(p,':')) && p && strcasecmp(name,p)==0 ){
		run_script(ev->nd->u.scr.script,ev->pos,0,ev->nd->bl.id);
		(*c)++;
	}
	
	return 0;
}
int npc_event_doall(const char *name)
{
	int c=0;
	char buf[64]="::";
	
	strcpy(buf+2,name);
	strdb_foreach(ev_db,npc_event_doall_sub,&c,buf);
	return c;	
}

int npc_event_do_sub(void *key,void *data,va_list ap)
{
	char *p=(char *)key;
	struct event_data *ev=(struct event_data *)data;
	int *c=va_arg(ap,int *);
	const char *name=va_arg(ap,const char *);

	if (p && strcasecmp(name,p)==0 ) {
		run_script(ev->nd->u.scr.script,ev->pos,0,ev->nd->bl.id);
		(*c)++;
	}

	return 0;
}
int npc_event_do(const char *name)
{
	int c=0;
	
	if (*name==':' && name[1]==':') {
		return npc_event_doall(name+2);
	}

	strdb_foreach(ev_db,npc_event_do_sub,&c,name);
	return c;
}

/*==========================================
 * 帪寁僀儀儞僩幚峴
 *------------------------------------------
 */
int npc_event_do_clock(int tid,unsigned int tick,int id,int data)
{
	time_t timer;
	struct tm *t;
	char buf[64];
	int c=0;
	
	time(&timer);
	t=localtime(&timer);
	
	if (t->tm_min != ev_tm_b.tm_min ) {
		sprintf(buf,"OnMinute%02d",t->tm_min);
		c+=npc_event_doall(buf);
		sprintf(buf,"OnClock%02d%02d",t->tm_hour,t->tm_min);
		c+=npc_event_doall(buf);
	}
	if (t->tm_hour!= ev_tm_b.tm_hour) {
		sprintf(buf,"OnHour%02d",t->tm_hour);
		c+=npc_event_doall(buf);
	}
	if (t->tm_mday!= ev_tm_b.tm_mday) {
		sprintf(buf,"OnDay%02d%02d",t->tm_mon+1,t->tm_mday);
		c+=npc_event_doall(buf);
	}
	memcpy(&ev_tm_b,t,sizeof(ev_tm_b));
	return c;
}
/*==========================================
 * OnInit僀儀儞僩幚峴(&帪寁僀儀儞僩奐巒)
 *------------------------------------------
 */
int npc_event_do_oninit(void)
{
	int c = npc_event_doall("OnInit");
	printf("npc: OnInit Event done. (%d npc)\n",c);

	add_timer_interval(gettick()+100,
		npc_event_do_clock,0,0,1000);

	return 0;
}

/*==========================================
 * 僞僀儅乕僀儀儞僩幚峴
 *------------------------------------------
 */
int npc_timerevent(int tid,unsigned int tick,int id,int data)
{
	int next,t;
	struct npc_data* nd=(struct npc_data *)map_id2bl(id);
	struct npc_timerevent_list *te;
	if( nd==NULL || nd->u.scr.nexttimer<0 ){
		printf("npc_timerevent: ??\n");
		return 0;
	}
	nd->u.scr.timertick=tick;
	te=nd->u.scr.timer_event+ nd->u.scr.nexttimer;
	nd->u.scr.timerid = -1;
	
	t = nd->u.scr.timer+=data;
	nd->u.scr.nexttimer++;
	if( nd->u.scr.timeramount>nd->u.scr.nexttimer ){
		next= nd->u.scr.timer_event[ nd->u.scr.nexttimer ].timer - t;
		nd->u.scr.timerid = add_timer(tick+next,npc_timerevent,id,next);
	}

	run_script(nd->u.scr.script,te->pos,0,nd->bl.id);
	return 0;
}
/*==========================================
 * 僞僀儅乕僀儀儞僩奐巒
 *------------------------------------------
 */
int npc_timerevent_start(struct npc_data *nd)
{
	int j,n=nd->u.scr.timeramount, next;
	if( nd->u.scr.nexttimer>=0 || n==0 )
		return 0;
	
	for(j=0;j<n;j++){
		if( nd->u.scr.timer_event[j].timer > nd->u.scr.timer )
			break;
	}
	nd->u.scr.nexttimer=j;
	nd->u.scr.timertick=gettick();

	if(j>=n)
		return 0;
	
	next = nd->u.scr.timer_event[j].timer - nd->u.scr.timer;
	nd->u.scr.timerid = add_timer(gettick()+next,npc_timerevent,nd->bl.id,next);
	return 0;
}
/*==========================================
 * 僞僀儅乕僀儀儞僩廔椆
 *------------------------------------------
 */
int npc_timerevent_stop(struct npc_data *nd)
{
	if( nd->u.scr.nexttimer>=0 ){
		nd->u.scr.nexttimer = -1;
		nd->u.scr.timer += (int)(gettick() - nd->u.scr.timertick);
		if(nd->u.scr.timerid!=-1)
			delete_timer(nd->u.scr.timerid,npc_timerevent);
		nd->u.scr.timerid = -1;
	}
	return 0;
}
/*==========================================
 * 僞僀儅乕抣偺強(qiáng)摼
 *------------------------------------------
 */
int npc_gettimerevent_tick(struct npc_data *nd)
{
	int tick=nd->u.scr.timer;
	if( nd->u.scr.nexttimer>=0 )
		tick += (int)(gettick() - nd->u.scr.timertick);
	return tick;
}
/*==========================================
 * 僞僀儅乕抣偺愝掕
 *------------------------------------------
 */
int npc_settimerevent_tick(struct npc_data *nd,int newtimer)
{
	int flag= nd->u.scr.nexttimer;
	npc_timerevent_stop(nd);
	nd->u.scr.timer=newtimer;
	if(flag>=0)
		npc_timerevent_start(nd);
	return 0;
}

/*==========================================
 * 僀儀儞僩宆偺N(yùn)PC張棟
 *------------------------------------------
 */
int npc_event(struct map_session_data *sd,const char *eventname)
{
	struct event_data *ev=strdb_search(ev_db,eventname);
	struct npc_data *nd;
	int xs,ys;

	if (sd == NULL) return 0;
	if (ev==NULL || (nd=ev->nd)==NULL) {
		if (battle_config.error_log)
			printf("npc_event: event not found [%s]\n",eventname);
		return 0;
	}

	xs=nd->u.scr.xs;
	ys=nd->u.scr.ys;
	if (xs>=0 && ys>=0 ) {
		if (nd->bl.m != sd->bl.m )
			return 0;
		if ( xs>0 && (sd->bl.x<nd->bl.x-xs/2 || nd->bl.x+xs/2<sd->bl.x) )
			return 0;
		if ( ys>0 && (sd->bl.y<nd->bl.y-ys/2 || nd->bl.y+ys/2<sd->bl.y) )
			return 0;
	}

	if ( sd->npc_id!=0) {
//		if (battle_config.error_log)
//			printf("npc_event: npc_id != 0\n");
		int i;
		for(i=0;i<MAX_EVENTQUEUE;i++)
			if (!sd->eventqueue[i][0])
				break;
		if (i==MAX_EVENTQUEUE) {
			if (battle_config.error_log)
				printf("npc_event: event queue is full !\n");
		}else{
//			if (battle_config.etc_log)
//				printf("npc_event: enqueue\n");
			memcpy(sd->eventqueue[i],eventname,50);
		}
		return 1;
	}
	if (nd->flag&1) {	// 柍岠壔偝傟偰偄傞
		npc_event_dequeue(sd);
		return 0;
	}
	
	sd->npc_id=nd->bl.id;
	sd->npc_pos=run_script(nd->u.scr.script,ev->pos,sd->bl.id,nd->bl.id);
	return 0;
}

/*==========================================
 * 愙怗宆偺N(yùn)PC張棟
 *------------------------------------------
 */
int npc_touch_areanpc(struct map_session_data *sd,int m,int x,int y)
{
	int i,f=1;
	int xs,ys;

	for(i=0;i<map[m].npc_num;i++) {
		if (map[m].npc[i]->flag&1) {	// 柍岠壔偝傟偰偄傞
			f=0;
			continue;
		}
	
		switch(map[m].npc[i]->bl.subtype) {
		case WARP:
			xs=map[m].npc[i]->u.warp.xs;
			ys=map[m].npc[i]->u.warp.ys;
			break;
		case SCRIPT:
			xs=map[m].npc[i]->u.scr.xs;
			ys=map[m].npc[i]->u.scr.ys;
			break;
		default:
			continue;
		}
		if (x >= map[m].npc[i]->bl.x-xs/2 && x < map[m].npc[i]->bl.x-xs/2+xs &&
		   y >= map[m].npc[i]->bl.y-ys/2 && y < map[m].npc[i]->bl.y-ys/2+ys)
			break;
	}
	if (i==map[m].npc_num) {
		if (f) {
			if (battle_config.error_log)
				printf("npc_touch_areanpc : some bug \n");
		}
		return 1;
	}
	switch(map[m].npc[i]->bl.subtype) {
	case WARP:
		pc_setpos(sd,map[m].npc[i]->u.warp.name,map[m].npc[i]->u.warp.x,map[m].npc[i]->u.warp.y,0);
		break;
	case SCRIPT:
		npc_click(sd,map[m].npc[i]->bl.id);
		break;
	}

	return 0;
}

/*==========================================
 * 嬤偔偐偳偆偐偺敾掕
 *------------------------------------------
 */
int npc_checknear(struct map_session_data *sd,int id)
{
	struct npc_data *nd;

	nd=(struct npc_data *)map_id2bl(id);
	if (nd==NULL || nd->bl.type!=BL_NPC) {
		if (battle_config.error_log)
			printf("no such npc : %d\n",id);
		return 1;
	}
	
	if (nd->class<0)	// 僀儀儞僩宯偼忢偵OK
		return 1;

	// 僄儕傾敾掕
	if (nd->bl.m!=sd->bl.m ||
	   nd->bl.x<sd->bl.x-AREA_SIZE-1 || nd->bl.x>sd->bl.x+AREA_SIZE+1 ||
	   nd->bl.y<sd->bl.y-AREA_SIZE-1 || nd->bl.y>sd->bl.y+AREA_SIZE+1)
		return 1;

	return 0;
}

/*==========================================
 * 僋儕僢僋帪偺N(yùn)PC張棟
 *------------------------------------------
 */
int npc_click(struct map_session_data *sd,int id)
{
	struct npc_data *nd;

	if (sd->npc_id != 0) {
		if (battle_config.error_log)
			printf("npc_click: npc_id != 0\n");
		return 1;
	}

	if (npc_checknear(sd,id))
		return 1;

	nd=(struct npc_data *)map_id2bl(id);

	if (nd->flag&1)	// 柍岠壔偝傟偰偄傞
		return 1;

	sd->npc_id=id;
	switch(nd->bl.subtype) {
	case SHOP:
		clif_npcbuysell(sd,id);
		npc_event_dequeue(sd);
		break;
	case SCRIPT:
		sd->npc_pos=run_script(nd->u.scr.script,0,sd->bl.id,id);
		break;
	}

	return 0;
}

/*==========================================
 *
 *------------------------------------------

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91麻豆精东视频| 亚洲色图欧美激情| 欧美成人精精品一区二区频| 激情五月婷婷综合网| 亚洲免费av高清| 久久在线观看免费| 欧美日韩国产一区二区三区地区| 国产成人综合在线播放| 丝袜亚洲另类欧美综合| 亚洲天堂2016| 国产午夜精品福利| 欧美成人猛片aaaaaaa| 在线免费观看一区| 成人精品一区二区三区四区| 久久精品国产亚洲aⅴ| 一区二区三区欧美视频| 中文字幕精品在线不卡| 精品久久久久久综合日本欧美| 欧美性猛交xxxxxx富婆| 99国产欧美另类久久久精品| 东方欧美亚洲色图在线| 韩国成人精品a∨在线观看| 爽好多水快深点欧美视频| 亚洲精品福利视频网站| 国产精品免费看片| 国产欧美一区二区三区鸳鸯浴| 日韩丝袜情趣美女图片| 3atv一区二区三区| 欧美日韩电影在线| 欧美精品欧美精品系列| 一区二区三区丝袜| 国产精品福利影院| 亚洲国产高清aⅴ视频| 久久久777精品电影网影网| 日韩精品中文字幕在线不卡尤物| 91精品国产综合久久婷婷香蕉| 日本黄色一区二区| 色综合av在线| 欧美日韩三级视频| 欧美午夜精品免费| 欧美午夜寂寞影院| 欧美亚洲综合一区| 欧美三级在线看| 欧美日韩国产综合草草| 欧美日本一区二区三区四区| 欧美日韩国产精选| 91精品在线一区二区| 欧美一区二区福利视频| 日韩欧美高清一区| 精品美女在线观看| 久久久久亚洲蜜桃| 国产精品色噜噜| 亚洲乱码国产乱码精品精的特点| 亚洲欧美偷拍三级| 亚洲午夜一区二区三区| 亚洲第一狼人社区| 精品在线观看免费| 高清在线成人网| 色婷婷综合久久久| 欧美色视频在线观看| 91精品国产综合久久久久久| 久久综合网色—综合色88| 国产精品卡一卡二卡三| 夜夜操天天操亚洲| 奇米四色…亚洲| 国产成人av一区二区| 91国偷自产一区二区使用方法| 欧美日韩国产a| 久久久一区二区三区| 国产精品剧情在线亚洲| 午夜欧美2019年伦理| 国产馆精品极品| 91久久精品一区二区| 欧美美女黄视频| 久久奇米777| 亚洲欧美经典视频| 美日韩一区二区| 99在线热播精品免费| 欧美日韩在线免费视频| 久久众筹精品私拍模特| 亚洲色图第一区| 精品在线免费观看| 欧美亚洲精品一区| 久久久精品日韩欧美| 亚洲激情在线播放| 国内精品伊人久久久久av一坑| 一本一本久久a久久精品综合麻豆| 欧美一区二区视频在线观看2022 | 国产精品伦一区二区三级视频| 一区二区三区丝袜| 国产盗摄视频一区二区三区| 欧美优质美女网站| 国产欧美一区二区三区网站| 欧美aaa在线| 99国产麻豆精品| 久久久久一区二区三区四区| 亚洲a一区二区| www.欧美精品一二区| 精品久久久久久无| 亚洲成av人片一区二区三区 | 欧美在线free| 国产清纯白嫩初高生在线观看91| 午夜精品福利一区二区蜜股av| 高清不卡一二三区| 欧美成人女星排名| 亚洲aⅴ怡春院| 欧美在线视频全部完| 中文字幕在线一区免费| 久久不见久久见中文字幕免费| 欧美日韩中文精品| 亚洲欧美日韩国产中文在线| 国产高清精品网站| 精品久久久久久久人人人人传媒| 亚洲香肠在线观看| 一本大道av一区二区在线播放| 国产精品免费aⅴ片在线观看| 国产真实乱子伦精品视频| 欧美日韩aaa| 午夜精品福利一区二区蜜股av| 日本精品免费观看高清观看| 成人欧美一区二区三区在线播放| 国产麻豆精品在线| 久久五月婷婷丁香社区| 久久精品国产亚洲aⅴ| 欧美一区二区精品久久911| 午夜久久电影网| 欧美日韩国产精品自在自线| 亚洲国产中文字幕在线视频综合| 91麻豆精品一区二区三区| 国产精品福利av| 成人av在线电影| 国产精品久久久久一区二区三区| 成人在线一区二区三区| 国产精品入口麻豆原神| 成人禁用看黄a在线| 中文字幕不卡在线播放| 成人免费精品视频| 国产精品欧美一区喷水| www.亚洲人| 亚洲免费成人av| 欧美吻胸吃奶大尺度电影| 亚洲国产视频a| 在线成人av影院| 久久99蜜桃精品| 国产亚洲欧洲一区高清在线观看| 高清不卡在线观看av| 国产精品久久久久永久免费观看| av网站一区二区三区| 亚洲精选在线视频| 欧美日韩三级视频| 加勒比av一区二区| 久久精品视频在线看| jizzjizzjizz欧美| 一二三四社区欧美黄| 欧美精三区欧美精三区| 久久99久久99| 欧美激情综合五月色丁香| heyzo一本久久综合| 午夜激情一区二区| 久久这里只有精品6| 91丨九色porny丨蝌蚪| 亚洲国产精品一区二区久久恐怖片| 日韩一区二区电影| 粉嫩13p一区二区三区| 亚洲精品一卡二卡| 欧美一区二区三区视频在线观看| 国产精品中文欧美| 亚洲裸体在线观看| 这里只有精品视频在线观看| 国产精品一品视频| 亚洲精品欧美专区| 91精品婷婷国产综合久久性色| 国产九色精品成人porny| 亚洲三级电影网站| 日韩午夜激情免费电影| 91热门视频在线观看| 日本成人在线电影网| 国产精品午夜电影| 91精品国产综合久久久久久| 不卡在线视频中文字幕| 婷婷久久综合九色综合伊人色| 国产日本亚洲高清| 欧美日韩视频第一区| 成人免费高清在线| 青青草成人在线观看| 亚洲国产成人自拍| 日韩欧美一级在线播放| 91在线云播放| 国产福利91精品一区二区三区| 亚洲一区二区在线观看视频| 久久久精品国产99久久精品芒果| 欧美色中文字幕| 成人精品亚洲人成在线| 久久精品国产77777蜜臀| 亚洲精品五月天| 欧美韩国日本一区| 日韩精品专区在线| 欧美欧美午夜aⅴ在线观看| 成人精品小蝌蚪| 国产一区二区精品久久|