⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 op_magic.cpp

📁 国内著名网络游戏dragon的服务端完整源码 内附完整数据库结构
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include "..\stdafx.h"
#include "..\LowerLayers\mylog.h"
#include "..\LowerLayers\protocol.h"
#include "..\LowerLayers\servertable.h"
#include "DefaultHeader.h"
#include "CItem.h"
#include "Scrp_exe.h"
#include "map.h"

#include "op_Magic.h"
#include "WeatherControl.h"
#include "SealStoneGameServer.h"
#include "NationSys.h"
#include "ArenaManager.h"

#define PLAYER	0
#define NPC		1

#define MAGIC_TRAP		1
#define MAGIC_OBJECT	2

// MAGIC Operation
MAGICTRAP   g_MagicTrap;
LPMAGICTRAP g_lpMagicTrap[8][8];
int			g_Condition_Table[8][8] ;	

extern		MAGICTABLE Magic_Ref[] ;
extern		t_connection connections[] ;

extern NPCName_by_Gender	NPC_Name_Ref[Num_Of_NPC_Name];
extern NPCLev_to_Exp		NPC_Lev_Ref[Num_Of_NPC_Lev] ;
extern NPC_Generation		NPC_Gen_Ref[Num_Of_NPC_Generation] ;

extern void SendItemAttrDurationChange( t_connection c[], int cn, int pos );
extern void rollDice(int, int &) ;
extern bool isLevelUp(CHARLIST*);
extern void CheckNK( int, int, int );
extern int  BreakItemByDuration( CHARLIST *ch, POS pos );

extern NPC_Generation		NPC_Gen_Ref[Num_Of_NPC_Generation] ;

///////////////////////// 0726 lkh 眠啊 ///////////////////////////
extern void TameNpcAI( LPCHARLIST master );			//林牢俊霸 加秦 乐绰 抛怪NPC狼 青悼阑 力绢

///////////////////////// 0803 lkh 眠啊 ///////////////////////////
extern void SendSkillResult( int cn, int skillno, int target_id, int x, int y, int result );
extern void SendNK( int id, int nk );
extern void SendNK( int id, int nk3, int nk4, int nk6 );

//////////////////////// 0809 lkh 眠啊 /////////////////////////////
extern bool CanBattleArea( LPCHARLIST a, LPCHARLIST  d);
extern void CheckNK( int a_id, int d_id, int type  );
extern void InNK( LPCHARLIST ch, int nation, short int add_nk );
extern inline int IsNKNation( LPCHARLIST ch );
extern inline int IsHeNK( LPCHARLIST ch, int nation );
BOOL	  Doing_MagicEX(CHARLIST*	Char);
void	  CheckTimeTrap(void);

extern bool ExtraExp(void);
extern int addEXP(CHARLIST *a, CHARLIST *d, int criteria, int damage );
extern int GetEnemyEnemy( CHARLIST *attacker, CHARLIST *defender );

void SendCMD_MAGIC_POSITION( t_server_magic_position *);
BOOL InsertTrap(short int, short int, short int, DWORD);
void AddTrap( LPMAGICTRAP *Header, LPMAGICTRAP lpMagicTrap_add );
extern LPMAGICTRAP	FindTrap( LPMAGICTRAP *Header, short int tile_X, short int tile_Y );
extern BOOL			ReturnSuccessResult(int small_Dice, int big_Dice, CHARLIST *caster);
void Recv_fight_stone(int cn, t_packet packet);
void Fight_Stone_End(int cn, int flag);

static BOOL	 result;  
static int	 dice1, dice2 ;

// 付过单固瘤 魂免矫 阿 努饭胶喊 惑己包拌 抛捞喉
int		classCorrection[5][5]={0,-1,0,0,-1, 1,0,0,-1,0, 0,0,0,1,1, 0,1,-1,0,0, -1,0,1,0,0 };


POINT	tab44[44]={6,0, 6,-1, 5,-1, 5,-2, 5,-3, 4,-3, 3,-3, 3,-4, 2,-4, 1,-4, 1,-5, 0,-5, -1,-5, -1,-4, -2,-4, -3,-4, -3,-3,
-4,-3, -5,-3, -5,-2, -5,-1, -6,-1, -6,0, -6,1, -5,1, -5,2, -5,3, -4,3, -3,3, -3,4, -2,4, -1,4, -1,5, 0,5, 1,5,
1,4, 2,4, 3,4, 3,3, 4,3, 5,3, 5,2, 5,1, 6,1};

POINT	tab36[36]={5,0, 5,-1, 4,-1, 4,-2, 3,-2, 3,-3, 2,-3, 1,-3, 1,-4, 0,-4, -1,-4, -1,-3, -2,-3, -3,-3, -3,-2, -4,-2, -4,-1,
-5,-1, -5,0, -5,1, -4,1, -4,2, -3,2, -3,3, -2,3, -1,3, -1,4, 0,4, 1,4, 1,3, 2,3, 3,3, 3,2, 4,2, 4,1, 5,1 };

void SendViewType(CHARLIST *target, int view_Type, int continue_Time)
{	
	short int target_id=0;
	
	if (target->SprType == SPRITETYPE_NPC)
	{
		target_id = target->GetServerID() + 10000;
	}
	else
	{
		target_id = target->GetServerID();
	}
	
	t_packet	packet;
	
	packet.h.header.type							= CMD_SERVER_MAGICVIEWTYPE;
	packet.h.header.size							= sizeof(t_server_magicviewtype);
	
	packet.u.angra.server_magicviewtype.target_id	= target_id;
	packet.u.angra.server_magicviewtype.view_Type	= view_Type;
	packet.u.angra.server_magicviewtype.second_Time	= continue_Time;
	
	if( target_id < 10000 )		//PC牢 版快父 焊晨
	{
		QueuePacket(connections, target_id, &packet, 1);	//措惑眉俊霸 傈价
		CastMe2Other( target_id, &packet );					//措惑眉甫 官扼焊绊 乐绰 葛电 PC
	}
	else
		CastMe2Other( target_id-10000, &packet );			//措惑眉甫 官扼焊绊 乐绰 葛电 PC
}	

// PC/NPC狼 惑怕/眉仿摹函拳甫 舅府绰 窃荐
void SendCharacterCondition(CHARLIST* lpChar, int change_HP)
{
	t_packet p;
	
	p.h.header.type		= CMD_SERVER_CHARACTER_CONDITION;
	p.h.header.size		= sizeof(t_server_character_condition);
	p.u.angra.server_character_condition.nLife = change_HP;
	p.u.angra.server_character_condition.nState = lpChar->GetState();
	
	if( lpChar->SprType == SPRITETYPE_NPC )
	{
		p.u.angra.server_character_condition.idTarget = lpChar->GetServerID() + 10000;
		CastNPC2Other( lpChar->GetServerID(), &p );
	}
	else 
	{
		p.u.angra.server_character_condition.idTarget = lpChar->GetServerID();
		QueuePacket( connections, lpChar->GetServerID(), &p, 1);
		CastMe2Other( lpChar->GetServerID(), &p );
	}
}

bool SummonMonster(CHARLIST* pMaster, int nCreate, int nX, int nY)
{ // 阁胶磐 家券
	// 混酒乐绰 NPC狼 付瘤阜 阁胶磐狼 ID 备窍扁
	const int nNumber = GetAliveNPCList();	
	if (nNumber == -1)  return false;
	//MyLog(LOG_NORMAL, "SummonMonster : %d", nCreate); // CSD-LOG
	// NPC 积己
	if (pMaster->IsPlayer())
	{
		if (::NPC_Create(nNumber, nCreate, nX, nY, -1, 0, GT_SKILL_SUMMON) == 0)
		{
			return false;
		}
	}
	else
	{	//< CSD-040407
		if (::NPC_Create(nNumber, nCreate, nX, nY, -1, 0, GT_SKILL_SUMMON) == 0)
		{
			return false;
		}  
	}	//> CSD-040407
	// 家券阁 刘啊  
	const WORD idMaster = pMaster->GetServerID();
	pMaster->m_xSummon.Increase(nNumber);
	// 家券阁栏肺 汲沥
	CHARLIST*	pFollowing = &NPCList[nNumber];
	pFollowing->SetMaster(idMaster);
	pFollowing->viewtype = VIEWTYPE_STAND_UP_;
	
	if (pMaster->IsPlayer())
	{
		const int nSprNo = pFollowing->SprNo;
		pFollowing->SetSummonMonster(true);
		pFollowing->ctrlpc = idMaster;
		pFollowing->tame = NPC_Gen_Ref[nSprNo].Taming_max;
		pFollowing->SetTamed(true);
		pFollowing->MoveP = pMaster->MoveP;
		pFollowing->tamingcountdown = 60;
		pFollowing->tame_cmd	= LC_TAME_FOLLOWME;
		pFollowing->oldpatterntype = pFollowing->patterntype;
		pFollowing->patterntype = NPC_PATTERN_TAME_;
		strcpy(pFollowing->HostName, connections[idMaster].chrlst.Name);
	}
	
	RunArea(connections);	// 家券阁 龋免	 
	
	if (pMaster->IsPlayer())
	{
		const WORD idFollowing = pFollowing->GetServerID();
		SendNPC_Parameter(idFollowing, NPC_PARAMETER_TAME_CMD, pFollowing->tame_cmd);
		SendNPC_Parameter(idFollowing, NPC_PARAMETER_OLDPATTERNTYPE, pFollowing->oldpatterntype);
		SendNPC_Parameter(idFollowing, NPC_PARAMETER_PATTERNTYPE, pFollowing->patterntype);
		SendToAllHostName(idFollowing, pFollowing);
		// 家券阁 青悼 贸府
		t_tame_command packet;
		packet.cmd = LC_TAME_FOLLOWME;
		strcpy(packet.mybaby, pFollowing->Name);
		RecvTameCommand(idMaster, &packet);
	}
	
	return true;
}

bool FollowSummon(WORD idFollowing, WORD idMaster)
{
	CHARLIST* pFollowing = GetCharListPtr(idFollowing + 10000);
	if (pFollowing == NULL)  return false;
	
	t_tame_command packet;
	packet.cmd = LC_TAME_FOLLOWME;
	
	const string strName = pFollowing->Name;                                              
	
	if (strName.length() < NM_LENGTH)
	{
		strcpy(packet.mybaby, strName.c_str());
		::RecvTameCommand(idMaster, &packet);
		return true;
	} 
	
	return false;
}

void KillMonster(WORD wNumber)
{
	if (wNumber >= NPC_LIST_START && wNumber < MAX_NPC_LIST)
	{ // 阁胶磐狼 ID啊 蜡瓤茄瘤 咯何 八荤
		CHARLIST* pTarget = &NPCList[wNumber];
		
		if (pTarget != NULL)
		{
			killCharacter(NULL, pTarget);
			SendCharacterCondition(pTarget, 0);
		}
	}
}

void CheckCharacterCondition(CHARLIST* pTarget)
{
	if (pTarget->attackedblock > 0)  --pTarget->attackedblock;
	if (pTarget->IsPlayer())
	{
		if (pTarget->GetState() == CON_DEATH)
		{ // 家券等 阁胶磐啊 乐促搁 傈何 力芭
			pTarget->m_xSummon.Remove(KillMonster); 
		}
	}
	// 蜡瘤矫埃捞 瘤抄 付过俊 措窍咯 惑怕甫 雀汗
	pTarget->Recovery(g_curr_time);
}

void CheckTransparency(CHARLIST* pTarget, bool bAuto)
{
	if (bAuto)  
	{ // 磊悼栏肺 辆丰登档废 汲沥
		pTarget->dwTransparency = 0;
	}
	
	if (pTarget->dwTransparency <= 0 && pTarget->viewtype == VIEWTYPE_TRANSPARENCY_)
	{
		pTarget->viewtype = VIEWTYPE_NORMAL_;
		SendViewType(pTarget, VIEWTYPE_NORMAL_, 0);
	}
}

////////////////////////// 0811 lkh 荐沥 - 漂沥 努扼捞攫飘俊霸父 傈价 //////////////////////////
void SendMagicCommand(CHARLIST* lpChar, short int slot1, short int slot2, short int slot3)
{
	////////////////////// 0308 lkh 眠啊 ///////////////////////
	if(lpChar->GetServerID() == 0)	return;
	
	t_packet p;
	
	p.h.header.type		= CMD_SERVER_MAGICCOMMAND;
	p.h.header.size		= sizeof( t_server_magic_command );
	p.u.angra.server_magic_command.command			= (short) slot1;
	p.u.angra.server_magic_command.sub_command		= (short) slot2;
	p.u.angra.server_magic_command.sub_term			= (short) slot3;
	
	QueuePacket( connections, lpChar->GetServerID(), &p, 1);
}

int	 CorrectionMagicState(CHARLIST *target, int total_MagicDamage, int magic_No)	//阿 拌凯喊 惑己 棺 硅版俊 蝶弗 焊沥
{					
	int correction_Rate =0;
	
	//阿 拌凯喊 惑己/焊沥 荐摹 利侩
	switch(Magic_Ref[magic_No].order_Type)
	{				
	case 1://积		
	case 2://荤		
	case 3://老馆	
	case 4://拳堪	
	case 5://葫		
	case 6://傈拜	
	case 7://家券	
	case 8://矫傍	
	case 9://脚己	
	case 10://沥悼	
	case 11://沥充	
	case 12://漂荐	
		break;		
	}				
	return correction_Rate;
}					

/*******************************************************************************************/
//	
//	
// Wizard Spell 备泅 窃荐甸....
//	
//	
//	
/*******************************************************************************************/

///////////////////// 矫傈磊狼 版氰摹客 饭骇 / 扁贱版氰摹甫 悼矫俊 贸府窃
///////////////////// 0726 lkh 荐沥 //////////////////////
void AddCasterEXP(CHARLIST *attacker, CHARLIST *defender, int result, int magicType, int magic_Num, int damage)
{	//< CSD-030509
	if (g_pArenaManager->IsColossusArena())
	{
		return;
	}
	
	if (attacker->IsNpc())
	{
		return;
	}
	//> CSD-030509  
	DWORD exp;
	int base_point;
	extern NPCLev_to_Exp		NPC_Lev_Ref[Num_Of_NPC_Lev];
	
	if( defender->SprType == SPRITETYPE_NPC )
	{
		if( defender->Race == HUMAN ) return;
	}
	
	if (defender->IsTamedNpc() == true) return;	// 怕怪等 局茄抛辑绰 版摹甫 掘阑荐 绝促. 
	//	result->0:角菩茄 版快 / 1:傍拜栏肺 利阑 磷看阑 版快 / 2:付过捞 己傍茄 版快
	//	magicType->0:老馆 付过 1,2,3->傍拜 付过 
	
	//	1 : 老馆 傍拜					
	//	2 : 							
	//	3 : 历林拌凯付过.				
	
	switch( magicType )				
	{			
	case 0 : //老馆付过(亮篮 付过/ 巢阑 档客林芭唱 巢俊霸 乔秦甫 林瘤 臼绰付过 )
		{			
			if(result)	//己傍 沁阑 版快
			{		
				switch(magic_Num)
				{	
					// Healing
				case 1 :
					// GreatHealing
				case 6 :
					// 雀汗狼鼻瓷
				case 151 :
					//肯摹狼 扁利
				case 156 :		
					exp = (DWORD)(damage*2/100) + 15;	// 棵妨霖 hp蔼狼 2%甫 版氰摹肺 霖促. 
					break;
					
				default:		base_point = (int)Magic_Ref[magic_Num].Exp;			//老馆 付过捞 己傍茄 版快 版氰摹樊
					exp = (DWORD)(base_point);
					break;
				}	
				
				switch( defender->SprNo )
				{	
				case 92 :	// 扁嫡..
				case 93 :	// 扁嫡..
				case 94 :	// 苞翅..
				case 95 :	// 倾荐酒厚.
					{
						if (attacker->GetLevel() <= ENABLE_DUMMY_LEVEL)
						{	//< CSD-030806  
							attacker->ChangeUpAddExp(exp);
							attacker->ChangeUpTacExp(2, exp*3);
							isLevelUp(attacker);
						}	//> CSD-030806
						
						break;
					}
				case 96  : //  怕平荐访侩.			
					{
						attacker->ChangeUpTacExp(3, exp/3);
						
						if (attacker->Mana < attacker->ManaMax)
						{								
							attacker->Mana = attacker->ManaMax;
							attacker->SendCharInfoBasic( MP, attacker->Mana );//020704 lsw
							//							attacker->TempMana = attacker->Mana;//020214 lsw
						}								
						break;							
					}									
				default :							
					{ //< CSD-020821  
						attacker->ChangeUpAddExp(exp);
						attacker->ChangeUpTacExp(2, exp*3);
						isLevelUp(attacker);
						break;
					} //> CSD-020821
				}
			}		
			break;
		}			
	case 1 :
	case 2 :
	case 3 :
		{			
			switch( defender->SprNo )
			{	
			case 92 :	// 扁嫡..
			case 93 :	// 扁嫡..
			case 94 :	// 苞翅..
			case 95 :	// 倾荐酒厚.
				{
					if (attacker->GetLevel() > ENABLE_DUMMY_LEVEL)
					{	//< CSD-030806
						break;
					}	//> CSD-030806

					exp = addEXP( attacker, defender, result, damage );
					attacker->ChangeUpTacExp(2, damage);
					isLevelUp(attacker);
					break;
				}
			case 96 : //  怕平荐访侩. 
				{
					int d = (attacker->GetLevel()/10); //< CSD-030806
					if( d == 0 ) d = 1;
					attacker->ChangeUpTacExp(3, damage/2/d);
					attacker->Mana = attacker->ManaMax;
					attacker->SendCharInfoBasic(MP, attacker->Mana );//020704 lsw
					//					attacker->TempMana = attacker->Mana; //020214 lsw
					break;
				}
			default :
				exp = addEXP( attacker, defender, result, damage );
				attacker->ChangeUpTacExp(2, exp*3);
				isLevelUp(attacker);
				break;
			}	
			break;
		}		
	}			
}				

bool IsMovable(int& rX, int& rY)
{
	if (g_lpMapFile->wWidth <= rX)   rX = g_lpMapFile->wWidth - 1;
	if (g_lpMapFile->wHeight <= rY)  rY = g_lpMapFile->wHeight - 1;
	// Don't 加己, 笼救, 促弗 某腐磐俊 狼秦 痢蜡等 惑怕扼搁 捞悼 阂啊
	//< CSD-030210
	if (TileMap[rX][rY].attr_dont)    return false;
	if (TileMap[rX][rY].attr_inside)  return false;
	if (TileMap[rX][rY].attr_light)   return false;
	//< CSD-030210
	return true;
}

void TransArea(BYTE nType, CHARLIST* pTarget, int nX, int nY)
{ // 困摹 捞悼
	//< CSD-020909 : 辑滚狼 矫傈磊 困摹 函版
	pTarget->MoveGox = pTarget->X = nX<<5;
	pTarget->MoveGoy = pTarget->Y = nY<<5;
	pTarget->MoveSx	= nX;
	pTarget->MoveSy	= nY;
	pTarget->MovePathCount	= 0;
	pTarget->MoveLength		= 0;	
	//> CSD-020909
	if (pTarget->IsNpc())
	{
		SetArea(MOVE_NPC_AREA, pTarget->GetServerID());
	}
	else
	{
		SetArea(MOVE_PC_AREA, pTarget->GetServerID());
	}
    
	t_server_magic_position	smp;
	smp.nType =	nType;
	smp.idTarget = (pTarget->IsNpc()) ? (pTarget->GetServerID() + 10000):(pTarget->GetServerID());
	smp.nX = nX;
	smp.nY = nY;  
	SendCMD_MAGIC_POSITION(&smp);
}

void TransMap(CHARLIST* pTarget)
{ // 甘 捞悼
	// 扁撅等 捞悼 厘家 沥焊 备窍扁
	int nPort = 0, nX = 0, nY = 0;
	pTarget->GetTransMap(nPort, nX, nY);
	// 甘捞抚 备窍扁
	const string strMapName = GetMapName(nPort);
	
	if (strMapName == pTarget->MapName)
	{ // 鞍篮 甘俊辑 厘家 捞悼
		TransArea(PT_TELEPORT, pTarget, nX, nY);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -