www.pudn.com > gamedata.rar > player.c
#include "stdafx.h"
extern struct OBJECT_INFO object_info[MAX_NUM_OBJ];
extern struct optiondata option;
extern int skill_code1[4][5];
extern int skill_code2[4][3];
#if defined _CLIBTHREAD
DWORD CALLBACK processplayer(LPVOID lpParameter);
DWORD CALLBACK processnetmessage(LPVOID lpParameter);
#else
DWORD WINAPI processplayer(LPVOID lpParameter);
DWORD WINAPI processnetmessage(LPVOID lpParameter);
#endif
int installplayer()
{
#if defined _CLIBTHREAD
UINT dwThreadIDForMsg = 0;
#else
DWORD dwThreadIDForMsg = 0;
#endif
HANDLE hThreadForMsg = 0;
#if defined _CLIBTHREAD
hThreadForMsg = (HANDLE)_beginthreadex(NULL, 0, processplayer, NULL, 0, &dwThreadIDForMsg);
#else
hThreadForMsg = CreateThread(NULL, 0, processplayer, NULL, 0, &dwThreadIDForMsg);
#endif
SetThreadPriority(hThreadForMsg, THREAD_PRIORITY_BELOW_NORMAL);
return 0;
}
int resetplayer()
{
return 0;
}
// 玩家的线程控制
DWORD WINAPI processplayer(LPVOID lpParameter)
{
int i;
unsigned long time;
int temp;
char tmp[255];
// option.speed_number = 30000;
while(1)
{
time = GetTickCount();
if (time - option.time >= 120000)
{
if (option.systemtime + 1 >= 25)
option.systemtime = 0;
else
option.systemtime ++;
option.time = time;
for(i=0; i 20000)
{
// sprintf(tmp, "GetTickCount() = %d object_info[i].time2 = %d timeout %d, SOCKET == %d\n", GetTickCount(), object_info[i].time2, GetTickCount() - object_info[i].time2, object_info[i].s);
// SaveLog(tmp);
closeusersocket(object_info[i].s);
}
}
if ((object_info[i].status) &&
(!object_info[i].died))
{
if (object_info[i].attack_other > 0)
{
if (time - object_info[i].attack_other >= 20000)
{
object_info[i].attack_other = 0;
sendcitizeninfo(object_info[i].s, object_info[i].ServerID, object_info[i].citizenlevel, 2);
}
}
// 10秒一恢复
if (time - object_info[i].life_time >= object_info[i].life_speed)
{
if (object_info[i].life_now + object_info[i].life_recovery < object_info[i].life_max)
{
object_info[i].life_now += object_info[i].life_recovery;
gamemessage(object_info[i].s, 0x6B, object_info[i].life_now, 0);
}
else if (object_info[i].life_now + object_info[i].life_recovery >= object_info[i].life_max)
{
object_info[i].life_now = object_info[i].life_max;
gamemessage(object_info[i].s, 0x6B, object_info[i].life_now, 0);
}
object_info[i].life_time = time;
}
if (time - object_info[i].mental_time >= object_info[i].mental_speed)
{
if (object_info[i].job == 1) // 如果是法师
{
// 恢复魔法
temp = (int)(object_info[i].mental_recovery + object_info[i].mental_recovery * (0.10 + 0.05*object_info[i].skill1[skill_code1[1][0]]));
}
else
{
temp = object_info[i].mental_recovery;
}
if (object_info[i].mental_now == object_info[i].mental_max)
{
;
}
else if (object_info[i].mental_now + temp < object_info[i].mental_max)
{
object_info[i].mental_now += temp;
gamemessage(object_info[i].s, 0x6C, object_info[i].mental_now, 65535);
}
else if (object_info[i].mental_now + temp >= object_info[i].mental_max)
{
object_info[i].mental_now = object_info[i].mental_max;
gamemessage(object_info[i].s, 0x6C, object_info[i].mental_now, 65535);
}
object_info[i].mental_time = time;
}
if (time - object_info[i].brawn_time >= object_info[i].brawn_speed)
{
// 恢复体力
if (object_info[i].brawn_now == object_info[i].brawn_max)
{
;
}
else if (object_info[i].brawn_now + object_info[i].brawn_recovery < object_info[i].brawn_max)
{
object_info[i].brawn_now += object_info[i].brawn_recovery;
gamemessage(object_info[i].s, 0x66, object_info[i].brawn_now, 0);
}
else if (object_info[i].brawn_now + object_info[i].brawn_recovery >= object_info[i].brawn_max)
{
object_info[i].brawn_now = object_info[i].brawn_max;
gamemessage(object_info[i].s, 0x66, object_info[i].brawn_now, 0);
}
object_info[i].brawn_time = time;
}
}
}
for(i=0; i= 12) &&
(object_info[i].chainbuf[0] == 0xAA) && (object_info[i].chainbuf[1] == 0x55) &&
(object_info[i].chainbuf[object_info[i].chainlen - 2] == 0x55) &&
(object_info[i].chainbuf[object_info[i].chainlen - 1] == 0xAA))*/
if (object_info[i].chainlen >= 12)
{
send(object_info[i].s, object_info[i].chainbuf, object_info[i].chainlen, 0);
memset(object_info[i].chainbuf, 0x00, 8196);
object_info[i].chainlen = 0;
}
}
}
Sleep(1);
}
return 0L;
}
void resetinstallusernumber(int id)
{
;
}
// 复活
void comebacktolife(SOCKET s)
{
int index, i;
index = find_obj(s);
if (index == MAX_NUM_USER) return;
for(i=0;i= 100)
{
// if (object_info[i].chainlen >= 12)
{
// send(object_info[i].s, object_info[i].chainbuf, object_info[i].chainlen, 0);
/*
char szTemp1[8], szTemp[8192];
for(j=0;j