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

📄 itemmgr.cpp

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

	ChangeItemAttribute(TargetItem,IATTR_MUCH,TargetItem.attr[IATTR_MUCH]+SourceItem.attr[IATTR_MUCH]);
	DeleteItem(SourceItem);

	return 1;
}


int	CItemMgr::DeleteItem(ITEMATTR &item)
{
	return ::DeleteItem( &item );
}

int CItemMgr::DecItemDur(ITEMATTR &item, const DWORD iValue)//剧荐肺 持阑巴 澜荐肺 持栏搁 郴备档 刘啊
{
	CItem* t = ConvertItemNoToCItem(item.item_no);
	if(!t){return 0;}

	if(t->GetRbutton() == DIVIDE_ITEM)
	{
		if(item.attr[IATTR_MUCH] <= iValue)//滑 荐樊捞 利芭唱 鞍促.
		{
			item.attr[IATTR_MUCH]  =0;//绝绢脸栏搁	
			return 1;
		}//困炼扒俊辑 逞绢 吭栏搁 哗档 等促
		item.attr[IATTR_MUCH] -=iValue;
		return 2;// 荐樊捞 函沁促
	}
	else
	{
		WORD wNow=0,wMax=0;
		if(!GetItemDur( item, wNow, wMax ))
		{
			return 0;
		}

		WORD dOld = wNow;

		if(wNow <= iValue)//滑 蔼捞 巢篮芭 焊促 腹促搁
		{
			DeleteItem( item );
			return 1;
		}//哗档 登绰 芭扼搁
		else
		{
			wNow -= iValue;
			
			if( wNow <= 0 ){return 0;}
			
			item.attr[IATTR_DURATION] = MAKELONG( wNow, wMax );

			if( wNow/10 == 0 ) // Duration捞 0捞 登菌促.
			{
				return 1;
			}
			if( wNow/10 != dOld/10 )  // 锅拳等 加己阑 PC俊霸 焊郴霖促.
			{
				return 2;
			}
		}
	}
	return 0;

	
	
}

ItemAttr CItemMgr::GiveLegendItem(const int item_no, const int iDur)
{
	ItemAttr Item= {0,};
	CItem * t = ItemUnit(item_no);
	if(!t){ return Item; }
	
	const int iLegendAble = t->GetLegendAble();
	if(!iLegendAble){return Item;}

	//iDur捞 0捞搁 扁夯栏肺 父甸绢 林绊 酒囱 版快绰 弊措肺 技泼茄促 澜荐捞搁 府畔
	if( iDur > 0)		{	Item = GenerateItem( item_no, IATTR_MUCH ,iDur); }
	else if	(iDur==0)	{	Item = GenerateItem( item_no);}
	else if	(iDur<0)	{	return Item;	}

	const int iLegendGroupNo = t->GetLegendGroup();
	if(!iLegendGroupNo){return Item;}
	//s1 --> 畴富 , s2 --> 弊缝逞滚 --> s3-->弊缝牢郸胶
	const int iGroupIndex = RareEM.GetAbleGroupIndex(iLegendGroupNo);
	const int iRareKind = RareEM.GetLegendBasicRareKind(iLegendGroupNo,iGroupIndex,t->GetWearAble());

	const int aSucessRate[6] = {5,10,15,30,40,60};//醚钦捞 160
	const int iNow = rand()%160;//
	
	int iTemp = 0;
	int iResultGrade = 0;
	for(int i = 0; 6 > i; i++)
	{
		iTemp += aSucessRate[i];
		if(iTemp> iNow)
		{
			iResultGrade = i+3;//0~5 捞扁 锭巩俊
			break;
		}
	}
	MakeRareAttr(Item.attr[IATTR_RARE_MAIN],iResultGrade,iRareKind,iLegendGroupNo,iGroupIndex,H_LV_LEGEND_ITEM,0);
	return Item;
}
//


ItemAttr CItemMgr::GiveRareItem(const int item_no, const int iDur,const int iCallType,const int iTryMulti, 
								const int iGradeMin, const int iGradeMax, RareMain &RareAttr,const int iHighLevel)
{
	ItemAttr Item = {0,};
	memset(&Item,0,sizeof(ItemAttr));

	int iNowGrade=0;
	
	CItem * t = ItemUnit(item_no);
	if(!t){ return Item; }
	
	const int iItemKind = t->GetItemKind();
	
	if( MAX_ITEM_MUTANT_KIND <= iItemKind)	{return Item;}
	
	const int iRareAble = ItemMutantKind[iItemKind].upgrade_type;
	
	//iDur捞 0捞搁 扁夯栏肺 父甸绢 林绊 酒囱 版快绰 弊措肺 技泼茄促 澜荐捞搁 府畔
	if( iDur > 0)		{	Item = GenerateItem( item_no, IATTR_MUCH ,iDur); }
	else if	(iDur==0)	{	Item = GenerateItem( item_no);}
	else if	(iDur<0)	{	return Item;	}

	//钙胶啊 累阑 版快绰 府畔, 鞍栏搁 Min阑 持绢林绊 瞒捞啊 剧荐搁 罚待
	if(iGradeMax > iGradeMin)
	{
		iNowGrade = iGradeMin+rand()%(iGradeMax-iGradeMin+1);//罚待 窍搁 弥绊蔼篮 救唱坷聪鳖.+1阑 茄巴栏肺
	}
	else if( iGradeMax == iGradeMin )
	{
		iNowGrade= iGradeMin;
	}
	else //殿鞭 弥措啊 弥窍焊促 累篮霸 绢调衬
	{
		memset(&Item,0,sizeof(ItemAttr)); return Item;
	}
	
	int iRare1 = 0, iRare2 = 0, iRare3 = 0;
	
	if( iRareAble )//饭绢 啊瓷 老锭
	{
		switch( iTryMulti )
		{
		case 1:
			{
				iRare1 = GetAbleRareKind(iCallType,iHighLevel);
			}break;
		case 2:
			{
				iRare1 = GetAbleRareKind(iCallType,iHighLevel);
				iRare2 = GetAbleRareKind(iCallType,iHighLevel);
			}break;
		case 3:
			{
				iRare1 = GetAbleRareKind(iCallType,iHighLevel);
				iRare2 = GetAbleRareKind(iCallType,iHighLevel);
				iRare3 = GetAbleRareKind(iCallType,iHighLevel);
			}break;
		default:
			{
			}break;							
		}
	}
	MakeRareAttr(Item.attr[IATTR_RARE_MAIN] ,iNowGrade,iRare1,iRare2,iRare3,iHighLevel,false);//020314 lsw
	RareAttr = *(RareMain*)(&Item.attr[IATTR_RARE_MAIN]);
/*
	Send_RareItemMakeLog(	cn,	item_no,
							0,0,0,0,
							0,0,0,0,
							item.attr[IATTR_LIMIT],
							item.attr[IATTR_MUCH],
							0,type,kind,//器飘
							0,0,0,0,
							3000,0
							);*/
	return Item;
}

int CItemMgr::AbleMakeOnThisMap(const int iMapNation, const int iNo)
{	
	const int iAbleNation  = ItemRare[iNo].iAbleNation;
	switch(iMapNation)
	{
	case NW_BY:
		{
			if((iAbleNation%1000)/100)
			{
				return true;
			}
		}break;
	case NW_ZY:
		{
			if((iAbleNation%100)/10)
			{
				return true;
			}
		}break;
	case NW_YL:
		{
			if((iAbleNation%10)/1)
			{
				return true;
			}
		}break;
	case 0:
		{
			if((iAbleNation%10000)/1000)//吝赋惫
			{
				return true;
			}
		}break;

	default :
		{
			return false;
		}break;
	}
	return false;
}

int CItemMgr::GetAbleRareKind(const int iCallType,const int iHighLevel)
{
	int oklist[MAX_ITEM_RARE+1] = {0,};//扁霖捞登绰 府胶飘 No肺甸绢 乐绰芭.
	int gamble[MAX_ITEM_RARE+1] = {0,};//唱棵 犬伏 拌魂阑 困秦辑
	int iNo = 0;
	int iMax = 0;

	switch( iHighLevel)
	{
	case H_LV_NO_HIGH_ITEM:
		{
			iNo		=0;
			iMax	=MAX_STATIC_RARE;
		}break;
	case H_LV_HIGH_ITEM:
		{
			iNo		= START_HIGH_RARE;
			iMax	= MAX_HIGH_RARE;
		}break;
	
	default:
		{
			return 0;
		}break;
	}
	
	int iList= 0;
	for( ;iNo < iMax ; iNo++)
	{
		if(! (ItemRare[iNo].iMakeAble & iCallType))					{continue;} //父甸扁啊 啊瓷 茄啊? 
		if(! AbleMakeOnThisMap(MapInfo[MapNumber].nation,iNo))		{continue;} //捞惫啊俊辑 唱坷唱??

		if( iCallType & RARE_ABLE )
		{
			if( iCallType == RARE_ABLE )
			{
				gamble[iList] = ItemRare[iNo].RaisePro[0];	
			}
			else if	(iCallType & RARE_ABLE_SQUAD)//惫啊
			{	
				gamble[iList] = ItemRare[iNo].RaisePro[1];	
			}//何措 饭绢
			else if	(iCallType & RARE_ABLE_GAMBLE_ROOM_4)//白喉4锅规 
			{	
				gamble[iList] = ItemRare[iNo].RaisePro[2];	
			}
			else if	(iCallType & RARE_ABLE_GAMBLE_ROOM_5)//白喉5锅规
			{	
				gamble[iList] = ItemRare[iNo].RaisePro[3];	
			}
		}

		if( gamble[iList] )
		{
			oklist[iList] = ItemRare[iNo].iNo;// 府胶飘俊 啊瓷 加己 逞滚 眠啊	
			gamble[MAX_ITEM_RARE] += gamble[iList];//犬伏 配呕 拌魂
			iList++;
		}
	}				

	if(gamble[MAX_ITEM_RARE]<=0)
	{
		return 0;//捞凡老篮 芭狼 绝促..酒聪.. 酒抗.. 弊矾唱.. 
	}

	int NowRating= rand()%gamble[MAX_ITEM_RARE];
	int NowSok=0;
	int CheckRating=0;
	
	for(NowSok=0 ; NowSok<MAX_ITEM_RARE; NowSok++)
	{
		CheckRating+=gamble[NowSok];
		if(NowRating<CheckRating)
		{
			break;
		}
	}

	return oklist[NowSok];
}

bool CItemMgr::MakeRareAttr(unsigned int &attr3 ,const int iNowGrade,
							const int iSokSung1,const int iSokSung2,const int iSokSung3,
							const int iHighLevel,const bool bIsDynamicRare)const
{
	attr3  = 0;
	if( iNowGrade	>15			||	iNowGrade	<=	0	)	{ return false;}
	if( iSokSung1	>UCHAR_MAX	||	iSokSung1	<=	0	)	{ return false;}
	if( iSokSung2	>UCHAR_MAX	||	iSokSung2	<	0	)	{ return false;}
	if( iSokSung3	>UCHAR_MAX	||	iSokSung3	<	0	)	{ return false;}
	if(	iHighLevel	>7			||	iHighLevel	<	0	)	{ return false;}

	((LPRareMain)&attr3)->grade			= iNowGrade	;
	((LPRareMain)&attr3)->soksung1		= iSokSung1	;
	((LPRareMain)&attr3)->soksung2		= iSokSung2	;
	((LPRareMain)&attr3)->soksung3		= iSokSung3	;
	((LPRareMain)&attr3)->iHighLevel	= iHighLevel;
	((LPRareMain)&attr3)->IsDynamicRare = bIsDynamicRare;
	return true;
}

// 021117 YGI
int CItemMgr::MakeDefaultRareItem( ItemAttr *item, const int iItemNo, const int iSok1, const int iGrade, const int iTryMulti)
{
	int iHighLv = 0;
	bool bIsDynamic = false;

	CItem *t = ::ItemUnit( iItemNo );
	if( !t ) {	return -1;	}

	*item = GenerateItem( iItemNo );
	if( !item->item_no ){ return -1;}		// 酒捞袍 锅龋啊 捞惑窍促.

	if( iSok1 >= START_HIGH_RARE )
	{
		iHighLv = H_LV_HIGH_ITEM;
	}
	else
	{
		if( t->GetRbutton() == USE_ITEM )		// 促捞唱雇 酒捞袍...
		{
			bIsDynamic = true;
			iHighLv = H_LV_NO_HIGH_ITEM;
		}
	}

	int iSok2=0, iSok3=0;
	if(iSok1)
	{
		switch( iTryMulti )
		{
		case 0 :
		case 1 :
			{
			}break;
		case 2:
			{
				iSok2 = iSok1;
			}break;
		case 3 :
			{
				iSok3 = iSok2 = iSok1;
			}break;
		}

		if(H_LV_HIGH_ITEM == iHighLv){	iSok3 = iSok2 =0;}

		return (MakeRareAttr( item->attr[IATTR_RARE_MAIN], iGrade, iSok1, iSok2, iSok3, iHighLv, bIsDynamic )?1:0);
	}
	return 1;
}

int CItemMgr::GetSkillPointByItem(const ITEMATTR &item) const 
{
	CItem *t = ItemUnit(item);
	
	if(!t){return 0;}
	
	const int iLv = t->GetLevel();
	if( 0 >= iLv)
	{
		return 0;
	}
	return (iLv * 3 /10 +1);
}

int CItemMgr::GetStaticFunctionNo(const ITEMATTR &item)
{
	CItem *t = ConvertItemNoToCItem(item.item_no);
	return ((t)?t->GetStaticFunctionNo():0);
}

// 031009 CI YGI
//////////////////////////////////////////////////////////////////////////
// CItemLimitMgr member functions
int	CItemLimitMgr::GetLimitNumber( int item_no )
{
	if( !IsCanHaveLimitItem( item_no ) )
	{
		return LIMIT_OF_NO_HAVE_LIMIT_ITEM;
	}

	m_nItemLimitCount++;
	//char str_number[50];
	//sprintf( str_number, "%d", m_nItemLimitCount );
	//WritePrivateProfileString( "option","limit", str_number, MAP_SERVER_INI_ );

	// 瘤陛鳖瘤狼 府固飘 锅龋甫 DB肺 焊辰促.
	t_packet packet;
	packet.h.header.type = CMD_WRITE_LIMIT_NUMBER;
		packet.u.kein.save_limit_number.port = ::GetOwnPort();
		packet.u.kein.save_limit_number.limit_number = m_nItemLimitCount;
	packet.h.header.size = sizeof( k_save_limit_number );
	QueuePacket( connections, DB_DEMON, &packet, 1 );

	return m_nItemLimitCount;
}

int	CItemLimitMgr::LoadHaveLimitItem()
{ 
	m_mapHaveLimitItem.clear();

	HSTMT hStmt = NULL;
	SQLAllocStmt(hDBC, &hStmt);

	RETCODE	retCode = SQLExecDirect(hStmt, (UCHAR*)"SELECT * FROM ItemList_HaveLimit", SQL_NTS);	
	if(retCode != SQL_SUCCESS_WITH_INFO && retCode != SQL_SUCCESS) 
	{
		SQLFreeStmt(hStmt, SQL_DROP);
		return false;
	}
	
	SDWORD cbValue;
	int item_no = 0;
	int item_id= 0;
	int item_imageno= 0;
	char name[20]= {0, };
	while((retCode = SQLFetch(hStmt)) == SQL_SUCCESS)
	{
		SQLGetData(hStmt, 1, SQL_C_SLONG, &item_id, 0, &cbValue);
		SQLGetData(hStmt, 2, SQL_C_CHAR, name, 20, &cbValue);
		SQLGetData(hStmt, 3, SQL_C_SLONG, &item_imageno, 0, &cbValue);
		item_no = ((int)(item_imageno/10000))*100 + item_id;
		m_mapHaveLimitItem.insert( map<int, int>::value_type( item_no, 1 ) );
	}

	SQLFreeStmt(hStmt, SQL_DROP);
	return true;
}

⌨️ 快捷键说明

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