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

📄 questfunction.cpp

📁 国内著名网络游戏dragon的服务端完整源码 内附完整数据库结构
💻 CPP
📖 第 1 页 / 共 4 页
字号:

#include "../stdafx.h"
//#include "MySql.h"
#include "Dr_network.h"
#include "QuestFunction.h"
#include "Scrp_exe.h"
#include <assert.h>
#include "RegenManager.h" // 031028 kyo 
#include "SealStone.h"		// BBD 040318
#include "CItem.h"			// BBD 040329

CQuestInMap g_QuestInMap;
extern HDBC hDBC;
extern int  GetAliveNPCList(void);		//npc_list.h
extern void KillMonster(WORD wNumber); //op_magic.h
extern void CastMe2Other( int cn, t_packet *packet );	//Area.cpp
extern int SetRareItemInvPc( const int cn, const int iItemNo, const int iGradeMin, const int iGradeMax, const int iTryMulti, const int iDur, const int iHigh);
extern void FameUp2(const int cn, const int Type, const int Value);
extern SORT_DATA PC_TABLE[DRAGON_MAX_CONNECTIONS_+1];
extern void QuestTeleport( const int nCn, const int nX, const int nY );

//<! BBD 040401		// 惫啊规绢仿俊 蝶弗 搬拌籍 酒捞袍 焊惑侩
int g_RequitalItemRate[8] =
{
	100, 70, 45, 25, 15, 5, 3, 1,

};

int DecideRequitalByNationDefensePoint(CHARLIST * ch);
unsigned short	g_DefensePoint[NW_NATION_COUNT];	// BY,ZY,YL LocalWar Point

#define SEALSTONE_ITEMGIVERATE	2

//> BBD 040401		// 惫啊规绢仿俊 蝶弗 搬拌籍 酒捞袍 焊惑侩


struct IsIDHereInTimer : binary_function<CScriptTimer, int, bool>
{
public:
	bool operator()(const CScriptTimer& rTimer, const int nID) const //, const char* szName) const
	{
		return (rTimer.GetConnectionID() == nID) ? true:false;
	}
};

struct IsEndInTimer : binary_function<CScriptTimer, int, bool>
{
public:
	bool operator()(const CScriptTimer& rTimer, int z) const
	{
		return ( !rTimer.IsStart() );
	}
};

struct IsIDHereInCounter : binary_function<CScriptCounter, int, bool>
{
public:
	bool operator()(const CScriptCounter& rCounter, const int nID) const 
	{
		return (rCounter.GetConnectionID() == nID) ? true:false;
	}
};

struct IsEndInCounter : binary_function<CScriptCounter, int, bool>
{
public:
	bool operator()(const CScriptCounter& rCounter, int z) const //, int z) const
	{
		return ( !rCounter.IsStart() );
	}
};

struct IsNpcIndexHere : binary_function<table_requital_list, int, bool >
{
public:
	bool operator()( const table_requital_list& rRequital, int index) const
	{
		return ( rRequital.Npc_index == index )? true: false;
	}
};
//<! BBD 040329
struct IsItemIndex : binary_function<table_requital_Item, int, bool >
{
public:
	bool operator()( const table_requital_Item& rRequital, int index) const
	{
		return ( rRequital.index== index )? true: false;
	}
};
//> BBD 040329
/*
template <class T>
struct IsCnHere : binary_function<T, int,bool>
{
	bool operator()( const T& rT, int iId ) const
	{
		return ( rT.GetId( ) == iId )? true: false;
	}
};
*/
struct IsCnHere : binary_function<CSpellMove, int,bool>
{
	bool operator()(const CSpellMove &rT, int iId ) const
	{
		return ( rT.GetId() == iId )? true: false;
	}
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CQuestInMap
CQuestInMap::CQuestInMap()
{
}
	
CQuestInMap::~CQuestInMap()
{	// 040305 kyo
	SAFE_DELETE(m_cRequital);
}	

int CQuestInMap::LoadQuestInMap()
{
	char szQuery[0xff];
	HSTMT hStmt= NULL ;
	RETCODE ret ;
	//SWORD	nCols ;
	SDWORD cbValue ;
	
    SQLAllocStmt(hDBC, &hStmt);
	
	strcpy( szQuery, "select * from quest_in_map order by quest_num" );

	ret= SQLExecDirect(hStmt, (UCHAR *)szQuery, SQL_NTS) ;
	
	if(ret == SQL_SUCCESS_WITH_INFO || ret == SQL_SUCCESS)
	{
		ret = SQLFetch( hStmt );
		while( ret == SQL_SUCCESS )
		{
			table_quest_in_map table;
			//quest_num, map_num
			ret = SQLGetData( hStmt, 1, SQL_C_LONG, &table.quest_num, 0, &cbValue );
			ret = SQLGetData( hStmt, 2, SQL_C_LONG, &table.map_num, 0, &cbValue );

			if(ret != SQL_SUCCESS_WITH_INFO && ret != SQL_SUCCESS) 
			{
				MyLog( LOG_FATAL, "Table : quest_in_map: Error!!! (%d)", ret) ;
				return -1;
			}
			SetQuestInMap( table );

			ret = SQLFetch( hStmt );
		}
		return 1;
	}
	return 0;
}	

int CQuestInMap::LoadQuestInfoByStep()
{
	char szQuery[0xff];
	HSTMT hStmt= NULL ;
	RETCODE ret ;
	//SWORD	nCols ;
	SDWORD cbValue ;
	
    SQLAllocStmt(hDBC, &hStmt);
	
	strcpy( szQuery, "select * from quest_info_byStep order by quest_num" );

	ret= SQLExecDirect(hStmt, (UCHAR *)szQuery, SQL_NTS) ;
	
	if(ret == SQL_SUCCESS_WITH_INFO || ret == SQL_SUCCESS)
	{
		ret = SQLFetch( hStmt );
		while( ret == SQL_SUCCESS )
		{
			table_quest_info_bystep table;
			//quest_num, begin_step, end_step, quest_info
			ret = SQLGetData( hStmt, 1, SQL_C_LONG, &table.quest_num, 0, &cbValue );
			ret = SQLGetData( hStmt, 2, SQL_C_LONG, &table.begin_step, 0, &cbValue );
			ret = SQLGetData( hStmt, 3, SQL_C_LONG, &table.end_step, 0, &cbValue );
			ret = SQLGetData( hStmt, 4, SQL_C_LONG, &table.quest_info, 0, &cbValue );

			if(ret != SQL_SUCCESS_WITH_INFO && ret != SQL_SUCCESS) 
			{
				MyLog( LOG_FATAL, "Table : quest_info_bystep: Error!!! (%d)", ret) ;
				return -1;
			}
			SetQuestInfoByMap( table );

			ret = SQLFetch( hStmt );
		}
		return 1;
	}
	return 0;
}

list<int> CQuestInMap::GetQuestInMap( int iMapnumber)
{
	list<int>	retQuest;
	list<table_quest_in_map>::iterator	it;

	for( it = m_tQuestInMap.begin(); it != m_tQuestInMap.end(); it++ )
		if( (*it).map_num == iMapnumber )
			retQuest.push_back( (*it).quest_num );

	return retQuest;
}

int CQuestInMap::GetQuestInfo( int iQuestNum, int iStep)
{//窜 窍唱狼 搬苞父捞 乐阑 挥捞促.  搬苞 绝栏搁 -1
	list<table_quest_info_bystep>::iterator it;
	for( it = m_tQuestInfo.begin(); it != m_tQuestInfo.end(); it++)
		if( (*it).quest_num == iQuestNum )
			if( (*it).begin_step < iStep && iStep <= (*it).end_step )
				return (*it).quest_info;
	return -1;
}

void CQuestInMap::SendQuestInfo( t_quest_in_map *tp, int cn)
{
	if( tp == NULL ) return;

	list<int> lQuestNum;
	lQuestNum = GetQuestInMap( tp->iMapnumber);
	if( lQuestNum.size() <=0 ) return;

	list<int>::iterator it;
	for( it = lQuestNum.begin(); it != lQuestNum.end(); it++)
	{
		//int z= GetQuestInfo( (*it), var[cn][(*it)]);
		if( 0 > (tp->iQuestInfo = GetQuestInfo( (*it), var[cn][(*it)])) ) continue;	// 021126 kyo
		else
			SendShowQuestInfo( tp, cn );
	}

}

void CQuestInMap::SendShowQuestInfo( t_quest_in_map *tp, int cn )
{
	if( tp==NULL ) return;
	t_packet packet;
	packet.h.header.type	= CMD_WHAT_QUEST_IN_MAP;
	packet.h.header.size = sizeof( t_quest_in_map);
	memset( (void**)&packet.u.quest_in_map, 0, sizeof( t_quest_in_map ) );
	memcpy( (void**)&packet.u.quest_in_map, tp, sizeof( t_quest_in_map ) );
	packet.u.quest_in_map.name[20] = '\0';
	
	QueuePacket( connections, cn, &packet, 1 );
}

int CQuestInMap::CheckSpell( const int cn, const char* szSpell)
{	//荤恩捞 决波唱 林巩捞 撇府搁 0,己傍窍搁 1
	//林巩阑 己傍利栏肺 鞠扁窍搁 扁粮 林巩阑 檬扁拳茄促.

	if( m_szClientSpell.size() <=0 ) return 0;
	string spell = GetSpellWord( cn );
	if( spell.size() == NULL ) return 0;

	if( strcmp( spell.c_str(), szSpell ) == 0 )
	{
		DeleteSpellUser( cn);
		return 1;
	}

	return 0;
}

list<CSpellMove>::iterator CQuestInMap::FindSpellUser( const int cn )
{
	SPELLITER itFind = find_if(m_szClientSpell.begin(), m_szClientSpell.end(), bind2nd( IsCnHere(), cn ) );

	if( itFind != m_szClientSpell.end() )
		return itFind;

	return NULL;
}

void CQuestInMap::DeleteSpellUser( const int cn )
{
	if( m_szClientSpell.size() <=0 ) return;

	SPELLITER itFind = find_if(m_szClientSpell.begin(), m_szClientSpell.end(), bind2nd( IsCnHere(), cn ) );

	if( itFind != m_szClientSpell.end() )
		m_szClientSpell.erase(itFind);
}

string CQuestInMap::GetSpellWord( const int cn )
{
	SPELLITER itFind = find_if(m_szClientSpell.begin(), m_szClientSpell.end(), bind2nd( IsCnHere(), cn ) );

	if( itFind != m_szClientSpell.end() )
		return (*itFind).m_szSpell;
  return ""; // 021114 kyo
}

void CQuestInMap::SendSpellMapMove( const int&cn, const char* szSpell, const char* szMap, const int&  x, const int& y)
{// 021128 kyo
	t_packet packet;
	packet.h.header.type	= CMD_SCRIPT_SPELL_MAPMOVE;
	packet.h.header.size	= sizeof( t_script_spellmapmove );
	packet.u.spell_mapmove.cn = cn;
	packet.u.spell_mapmove.iX = x;
	packet.u.spell_mapmove.iY = y;
	strcpy( packet.u.spell_mapmove.szMap, szMap );
	//林巩篮 蜡聪内靛啊 瞪 啊瓷己捞 乐栏聪瘪 皋葛府 墨乔肺 窍磊.
	//strcpy( packet.u.spell_mapmove.szSpell, szSpell );
	memset( (void**)&packet.u.spell_mapmove.szSpell, 0x00, sizeof( packet.u.spell_mapmove.szSpell ) );
	memcpy( (void**)&packet.u.spell_mapmove.szSpell, szSpell, sizeof( packet.u.spell_mapmove.szSpell ) );
	
	QueuePacket( connections, cn, &packet, 1 );	
}

void CQuestInMap::RecvSpellMapMove( const t_script_spellmapmove *spell, const int& cn )
{// 021128 kyo
	if( spell->cn != cn ) return;

	if( !spell->isSuc )
	{
		SendSpellMapMove_Fail(cn);
		return;
	}

	SendSpellMapMove_Suc(spell->szMap, cn);
	::MapMove( cn, spell->szMap, spell->iX, spell->iY );
}

void CQuestInMap::SendSpellMapMove_Suc(const char* szMap, const int& cn)
{// 021128 kyo
	t_packet packet;
	packet.h.header.type	= CMD_SCRIPT_SPELL_MAPMOVE_SUC;
	packet.h.header.size	= sizeof( t_script_spellmapmove);
	memset( packet.u.spell_mapmove.szMap, 0, sizeof( packet.u.spell_mapmove.szMap));
	strcpy( packet.u.spell_mapmove.szMap, szMap );//, strlen( packet.u.spell_mapmove.szMap));
	//memcpy( packet.u.spell_mapmove.szMap, szMap, strlen( packet.u.spell_mapmove.szMap));

	QueuePacket( connections, cn, &packet, 1 );
}

void CQuestInMap::SendSpellMapMove_Fail(const int& cn)
{// 021128 kyo
	t_packet packet;
	packet.h.header.type	= CMD_SCRIPT_SPELL_MAPMOVE_FAIL;
	packet.h.header.size	= 0;
	QueuePacket( connections, cn, &packet, 1 );
}

void CQuestInMap::ShowStateMsg( const int& cn, const char* szMsg, const int& R, const int& G, const int& B )
{
	CHARLIST *ch = CheckServerId( cn );
	if( !ch ) return;
	t_packet packet;
	packet.h.header.type	= CMD_SCRIPT_SHOW_COLOR_MSG;
	packet.h.header.size	= sizeof( t_show_msg);
	packet.u.show_msg.R = R;
	packet.u.show_msg.G = G;
	packet.u.show_msg.B = B;
	//strcpy( packet.u.show_msg.szMsg , szMsg );
	memset( packet.u.show_msg.szMsg, 0, sizeof( packet.u.show_msg.szMsg ) );
	memcpy( packet.u.show_msg.szMsg, szMsg, strlen( szMsg ) );

	QueuePacket( connections, cn, &packet, 1 );	
}

void CQuestInMap::ShowStateMsg( const int& cn, const int& iMsgNum, const int& R, const int& G, const int& B )
{
	t_packet packet;
	packet.h.header.type	= CMD_SCRIPT_SHOW_COLOR_MSG;
	packet.h.header.size	= sizeof( t_show_msg);
	packet.u.show_msg.R = R;
	packet.u.show_msg.G = G;
	packet.u.show_msg.B = B;
	packet.u.show_msg.iMsgNum = iMsgNum;

	QueuePacket( connections, cn, &packet, 1 );
}

inline void RunNothing(){return;};

inline void SendSynchPacket1()
{
	t_packet packet;
	packet.h.header.type	= CMD_SCRIPT_SHOW_COLOR_MSG;
	packet.h.header.size	= sizeof( t_show_msg);
	char tmp[10];
	sprintf( tmp, "%d", EventPC );
	strcpy( packet.u.show_msg.szMsg, tmp);
	packet.u.show_msg.R = 200;
	packet.u.show_msg.G= 200;
	packet.u.show_msg.B= 200;
	
	QueuePacket( connections, EventPC, &packet, 1 );
};

inline void SendSynchPacket2(DWORD dwTmp)
{
	t_packet packet;
	packet.h.header.type	= CMD_SCRIPT_SHOW_COLOR_MSG;
	packet.h.header.size	= sizeof( t_show_msg);
	char tmp[10];
	sprintf( tmp, "%d", (dwTmp/1000) );
	strcpy( packet.u.show_msg.szMsg, tmp);
	packet.u.show_msg.R = 200;
	packet.u.show_msg.G= 0;
	packet.u.show_msg.B= 0;
	
	QueuePacket( connections, EventPC, &packet, 1 );
};


bool CQuestInMap::StartScriptTimer(const int iServerID, const char* szName, const DWORD &dwTimer, const DWORD &dwSync, const char* mapfile, const int& x, const int& y)
{
	//矫埃捞 0捞搁 秦寸 cn苞 name甫 啊柳 鸥捞赣甫 秦力茄促.
	//矫埃捞 剧荐搁 甸绢稠 蔼栏肺 鸥捞赣甫 push茄促.

	_ASSERTE( szName != NULL );
	if( szName == NULL ) return false;
	
	if( dwTimer == 0 )	//0捞搁 秦寸 鸥捞赣 昏力
	{
		//秦寸锅龋肺等 鸥捞赣甫 秦力茄促.
		if( DeleteScriptTimer( iServerID, szName ) ) 
			return true;
		else
			return false;
		//父距 立加捞 盔劝窍瘤 臼酒 iServerID尔 szName啊 老摹窍瘤 臼酒 鸥捞赣甫 秦力且荐 绝绰 版快扼档
		//RunScirtpTimer俊辑 老摹窍瘤 臼绰巴阑 very_long_term俊 蝶扼 犬牢窍扁锭巩俊 惑包绝促.
	}
	else if( dwTimer < 0 )	//澜荐搁 俊矾
		return false;

	//秦寸 蜡历啊 鸥捞赣甫 捞固 角青窍备 乐栏搁 货肺 鸥捞赣甫 倒府瘤 臼绰促. 
	if( FindUserInScriptTimer( iServerID, szName ) != m_cTimer.end() ) 
		return false;
	
	//CScriptTimer CScriptTimer( iServerID, szName, dwTimer, dwSync );	
	CScriptTimer cTimer;//(iServerID, dwTimer, );
	cTimer.SetID( iServerID);
	cTimer.SetName( szName );
	cTimer.SetTimerTime( dwTimer );
	cTimer.SetSynchroneTime( DEFAULT_TIMER_SYNC_TIME ); //5檬俊 茄锅
	cTimer.SetFunction( RunNothing, SendSynchPacket1 );	//泅犁绰 捞 窃荐甫 荤侩窍瘤 臼绰促. 
	cTimer.SetAfterMap( mapfile, x, y);//盔贰 窃荐甫 技泼秦具窍瘤父 

	//cTimer.SendSCRIPT_TIEMER( dwTimer, CMD_SCRIPT_TIMER_START );
	cTimer.StartTimer();

⌨️ 快捷键说明

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