www.pudn.com > gamedata.rar > monster.c
#include "stdafx.h"
extern struct OBJECT_INFO object_info[MAX_NUM_OBJ];
#if defined _CLIBTHREAD
DWORD WINAPI processmonster(LPVOID lpParameter);
#else
DWORD CALLBACK processmonster(LPVOID lpParameter);
#endif
int installmonster()
{
#if defined _CLIBTHREAD
UINT dwThreadIDForMsg = 0;
#else
DWORD dwThreadIDForMsg = 0;
#endif
HANDLE hThreadForMsg = 0;
#if defined _CLIBTHREAD
hThreadForMsg = (HANDLE)_beginthreadex(NULL, 0, processmonster, NULL, 0, &dwThreadIDForMsg);
#else
hThreadForMsg = CreateThread(NULL, 0, processmonster, NULL, 0, &dwThreadIDForMsg);
#endif
/*
#define THREAD_PRIORITY_LOWEST THREAD_BASE_PRIORITY_MIN
#define THREAD_PRIORITY_BELOW_NORMAL (THREAD_PRIORITY_LOWEST+1)
#define THREAD_PRIORITY_NORMAL 0
#define THREAD_PRIORITY_HIGHEST THREAD_BASE_PRIORITY_MAX
#define THREAD_PRIORITY_ABOVE_NORMAL (THREAD_PRIORITY_HIGHEST-1)
#define THREAD_PRIORITY_ERROR_RETURN (MAXLONG)
*/
SetThreadPriority(hThreadForMsg, THREAD_PRIORITY_BELOW_NORMAL);
return 0;
}
int resetmonster()
{
return 0;
}
// 怪物的线程控制
DWORD WINAPI processmonster(LPVOID lpParameter)
{
int i, j;//, id, index;
// char tmp[100];
while(1)
{
for(i=MAX_NUM_USER + MAX_NUM_DOOR + MAX_NUM_NPC; i= object_info[i].new_time * 1000)
{
// 死亡后在原死亡地点复活这个怪物 初始化数据
object_info[i].life = TRUE;
object_info[i].life_now = object_info[i].life_max;
object_info[i].died = FALSE;
object_info[i].attack_code1 = 0xFF;
object_info[i].attack_code2 = 0xFF;
// sprintf(tmp, "%d - %d", object_info[i].life_now, object_info[i].life_max);
// MessageBox(NULL, tmp, "", 0);
object_info[i].time1 = GetTickCount();
object_info[i].time2 = GetTickCount();
object_info[i].time3 = GetTickCount();
object_info[i].time4 = GetTickCount();
object_info[i].time5 = GetTickCount();
object_info[i].time6 = GetTickCount();
object_info[i].time7 = GetTickCount();
object_info[i].time8 = GetTickCount();
object_info[i].time9 = GetTickCount();
// 怪物复活了 ,向附近的玩家发送,显示怪物的信息
for(j=0; j= 10000)
{
object_info[i].time1 = GetTickCount();
object_info[i].time2 = GetTickCount();
object_info[i].time5 = GetTickCount();
}
// 看看攻击间隔时间到了吗
if (GetTickCount() - object_info[i].time1 >= object_info[i].normal_attack_time)
{
// 如果玩家到了怪物攻击范围里,就攻击玩家
if (findfar(object_info[i].attack_distance, i, index))
attack1(object_info[index].s, i, index, 35, TRUE);
object_info[i].time1 = GetTickCount();
}
// 否则只是在视力范围,就跟随玩家
else if (findfar(20, i, index) == TRUE)
{
if (GetTickCount() - object_info[i].time2 >= object_info[i].move_walk_speed)
{
object_info[i].time1 = GetTickCount();
object_info[i].time2 = GetTickCount();
}
}
else
{
object_info[i].attack_code1 = 0xFF;
object_info[i].attack_code2 = 0xFF;
object_info[i].time1 = GetTickCount();
object_info[i].time2 = GetTickCount();
object_info[i].time5 = GetTickCount();
}
}
}
*/
if (!object_info[i].died)
{
for(j=0; j= object_info[i].normal_attack_time)
{
monsterattack(object_info[j].s, i, j);
object_info[i].attack_code1 = object_info[j].menow1;
object_info[i].attack_code2 = object_info[j].menow2;
object_info[i].time1 = GetTickCount();
object_info[i].time2 = GetTickCount();
}
// MessageBoxA(NULL, "4545$","",0);
break;
}
// 否则只是在视力范围,就跟随玩家
else if (findfar(20, i, j))
{
if (GetTickCount() - object_info[i].time2 >= object_info[i].move_walk_speed)
{
object_info[i].time1 = GetTickCount();
object_info[i].time2 = GetTickCount();
break;
}
}
else
{
object_info[i].attack_code1 = 0xFF;
object_info[i].attack_code2 = 0xFF;
}
}
if ((object_info[i].auto_attack) && (!object_info[j].died) && (object_info[j].status))
{
// 如果玩家到了怪物攻击范围里,就攻击玩家
if (findfar(object_info[i].attack_distance, i, j))
{
if (GetTickCount() - object_info[i].time1 >= object_info[i].normal_attack_time)
{
monsterattack(object_info[j].s, i, j);
object_info[i].attack_code1 = object_info[j].menow1;
object_info[i].attack_code2 = object_info[j].menow2;
object_info[i].time1 = GetTickCount();
object_info[i].time2 = GetTickCount();
}
// MessageBoxA(NULL, "4545$","",0);
break;
}
// 否则只是在视力范围,就跟随玩家
else if (findfar(20, i, j))
{
if (GetTickCount() - object_info[i].time2 >= object_info[i].move_walk_speed)
{
object_info[i].time1 = GetTickCount();
object_info[i].time2 = GetTickCount();
break;
}
}
else
{
object_info[i].attack_code1 = 0xFF;
object_info[i].attack_code2 = 0xFF;
}
}
}
}
}
Sleep(50);
}
return 0L;
}
// 死亡啊!
int objectdied(SOCKET s, struct OBJECT_INFO info, int distance, BOOL broadcast)
{
// 00 01 02 03 04 05 06 07 08 09 10
// 39 00 00 00 71 57 4E CD 00 41 05
int ret;
BYTE buf[2];
BYTE lpSource[11];
memset(lpSource, 0x00, sizeof(lpSource));
lpSource[0] = 0x00;
lpSource[1] = 0x00;
lpSource[2] = 0x00;
lpSource[3] = 0x00;
lpSource[4] = 0x71;
Encode2(buf, info.ServerID);
lpSource[5] = buf[1];
lpSource[6] = buf[0];
Encode2(buf, info.now_x);
lpSource[7] = buf[1];
lpSource[8] = buf[0];
Encode2(buf, info.now_y);
lpSource[9] = buf[1];
lpSource[10] = buf[0];
ret = add_pack_chain(s, lpSource, 11, distance, broadcast);
//
return ret;
}
// 怪物移动
int monstermoveinfo(SOCKET s, BYTE mode, int id, int x, int y, int distance, BOOL broadcast)
{
// 00 01 02 03 04 05 06 07 08 09 10 11 12 13
// C4 00 00 00 5F 01 58 4E 00 00 E5 00 37 05
// C5 00 00 00 5D 01 57 4E 00 00 E1 00 1F 05
int ret;
BYTE buf[2];
BYTE lpSource[11];
memset(lpSource, 0x00, sizeof(lpSource));
lpSource[0] = 0x00;
lpSource[1] = 0x00;
lpSource[2] = 0x00;
lpSource[3] = 0x00;
lpSource[4] = mode;
lpSource[5] = 0x01;
Encode2(buf, id);
lpSource[6] = buf[1];
lpSource[7] = buf[0];
lpSource[8] = 0x00;
lpSource[9] = 0x00;
Encode2(buf, x);
lpSource[10] = buf[1];
lpSource[11] = buf[0];
Encode2(buf, y);
lpSource[12] = buf[1];
lpSource[13] = buf[0];
ret = add_pack_chain(s, lpSource, 14, distance, broadcast);
return ret;
}
/*
3 4 5
2 6
1 0 7
*/