int ShopSvc::DropGift(UInt32 roleID,UInt32 num)
{
	char szSql[1024];
	Connection con;
	DBOperate dbo;
	Int16 iRet = 0;
	UInt32 Gift=0;
	con = _cp->GetConnection();
	dbo.SetHandle(con.GetHandle());


	sprintf(szSql, "select Gift from RoleMoney where RoleID=%d",roleID);
	iRet=dbo.QuerySQL(szSql);
	if(iRet==0)
	{
		while(dbo.HasRowData())
		{
			Gift=dbo.GetIntField(0);
			dbo.NextRow();
		}
	}
	else
	{
		//ch
		LOG(LOG_ERROR,__FILE__,__LINE__,"szSql[%s] ", mysql_error(con.GetHandle()), szSql);
		return -1;
	}

	if(Gift>num)
	{

		sprintf(szSql, "Update RoleMoney set Gift=Gift-%d where RoleID=%d",num,roleID);
		iRet=dbo.ExceSQL(szSql);
		if(iRet!=0)
		{

			LOG(LOG_ERROR,__FILE__,__LINE__,"szSql[%s] ", mysql_error(con.GetHandle()), szSql);
 	    return -1;
		}

	}
	else
	{
		//没有足够多的礼券
		LOG(LOG_ERROR,__FILE__,__LINE__," Not so many Gift");
		return 1;
	}

	if(Gift>num)
	{
		Gift=Gift-num;
		NotifyGift(roleID,Gift);
		//S-C礼券
	}
	return 0;
}
int ShopSvc::UpdateDBspecialItem(UInt32 ItemID,UInt32 num)
{
	UInt32	RetCode = 0;
	char szSql[1024];
	Connection con;
	DBOperate dbo;
	Int16 iRet = 0;
	UInt32 LeftNum=0;
	List<ItemList> lis;
	ItemList item;
	con = _cp->GetConnection();
	dbo.SetHandle(con.GetHandle());


	sprintf(szSql, "Update specialItem set leftNum=leftNum-%d where ItemID=%d and leftNum>%d;",num,ItemID,num);
		iRet=dbo.ExceSQL(szSql);
		if(iRet!=0)
		{

			LOG(LOG_ERROR,__FILE__,__LINE__,"szSql[%s] ", mysql_error(con.GetHandle()), szSql);
 	    return -1;
		}


	sprintf(szSql, "select leftNum from specialItem where ItemID=%d",ItemID);

	iRet=dbo.QuerySQL(szSql);
	if(iRet==0)
	{
		while(dbo.HasRowData())
		{
			LeftNum=dbo.GetIntField(0);
			dbo.NextRow();
		}
	}
	else
	{
		//ch
		LOG(LOG_ERROR,__FILE__,__LINE__,"szSql[%s] ", mysql_error(con.GetHandle()), szSql);
		return -1;
	}
	item.ItemID=ItemID;
	item.num=LeftNum;
		lis.push_back(item);
	NotifyspecialItemNum(lis);

	return 0;
}
//角色是否有这么多金钱, 1 绑定银,2 金币。
//返回 0成功,-1 失败 ,1 没有
int OffLineUpdateSvc::IfHasSoMoney(UInt32 roleID, UInt32 money,Byte moneyType)
{
  char szSql[1024];
  char szSql1[1024];
  char szTemp[50];
  char szMoney[50];
  int iRet;
	UInt32 roleMoney;
  Connection con;
	DBOperate dbo;

	//获取DB连接
	con = _cp->GetConnection();
	dbo.SetHandle(con.GetHandle());

	if(1== moneyType)	//银币
	{
		sprintf(szSql,"select %s from RoleMoney where RoleID = %d;","Money",roleID);
		sprintf(szSql1,"select %s from RoleMoney where RoleID = %d;","BindMoney",roleID);

		iRet = dbo.QuerySQL(szSql);
		if(iRet < 0)
		{
			LOG(LOG_ERROR,__FILE__,__LINE__,"DB operate failed !");
			return -1;
		}

		roleMoney = dbo.GetIntField(0);

		iRet = dbo.QuerySQL(szSql1);
		if(iRet < 0)
		{
			LOG(LOG_ERROR,__FILE__,__LINE__,"DB operate failed !");
			return -1;
		}
		roleMoney += dbo.GetIntField(0);
	}
	if(2 == moneyType) //金币
	{
		sprintf(szSql,"select %s from RoleMoney where RoleID = %d;","Gold",roleID);

		iRet = dbo.QuerySQL(szSql);

		if(iRet < 0)
		{
			LOG(LOG_ERROR,__FILE__,__LINE__,"DB operate failed !");
			return -1;
		}
		roleMoney = dbo.GetIntField(0);
	}

	if (iRet == 0) {
		if (roleMoney < money) {
			return -1;
		}
	}

	return 0;
}
//更新商城中出售的物品的总数
int ShopSvc::UpdateDBItemSellCount(UInt32 ItemID,Byte type,UInt32 num)
{
	char szSql[1024];
	Connection con;
	DBOperate dbo;
	Int16 iRet = 0;
	con = _cp->GetConnection();
	dbo.SetHandle(con.GetHandle());


	sprintf(szSql, "update ShopItem set ItemSellTolalNum=ItemSellTolalNum+%d where ItemID =%d and Category=%d;",num,ItemID,type);
	iRet=dbo.ExceSQL(szSql);

	if(iRet!=0)
	{
			LOG(LOG_ERROR,__FILE__,__LINE__,"szSql[%s] ", mysql_error(con.GetHandle()), szSql);
	}

	return 0;
}
//扣除并锁定金钱
//返回值 0 成功,1 失败
int OffLineUpdateSvc::TakeoffAndLockMoney(UInt32 roleID, UInt32 money,Byte moneyType,const OffLineUpdateItem& offHang)
{
	char szSql[1024];
	UInt32	RetCode = 0;
  int iRet;
  char szTemp[100];
	Connection con;
	DBOperate dbo;

	//获取DB连接
	con = _cp->GetConnection();
	dbo.SetHandle(con.GetHandle());

	LOG(LOG_ERROR,__FILE__,__LINE__,"money[%d]",money);

	if(1 == moneyType)
	{
		sprintf(szSql,"select %s from RoleMoney where RoleID = %d;","BindMoney",roleID);

		iRet = dbo.QuerySQL(szSql);
		if(iRet < 0)
		{
			LOG(LOG_ERROR,__FILE__,__LINE__,"DB operate failed !");
			return -1;
		}

		int bindMoney = dbo.GetIntField(0);
		int decreaseMoney = bindMoney - money;
		if(bindMoney >= money){
			  sprintf(szSql,"update RoleMoney set \
			                 BindMoney = %d where RoleID = %d;",decreaseMoney,roleID);

				iRet = dbo.ExceSQL(szSql);
				if(0 != iRet)
				{
					LOG(LOG_ERROR,__FILE__,__LINE__,"DB operate failed !");
					return 1;
				}
		}else{
void ShopSvc::ProcessBuyItem(Session& session,Packet& packet)
{


	UInt32	RetCode = 0;
	DataBuffer	serbuffer(1024);
	char szSql[1024];
	Connection con;
	DBOperate dbo;
	Int16 iRet = 0;
	UInt16 num=0;
	UInt16 cellType=0;
	UInt16 itemType=0;
	UInt16 IsStack=0;
	UInt16 Bind=0;
	UInt32 Dur=0;
	UInt32 price=0;
	UInt32 EntityID=0;
	UInt32 CellIndex=0;
	UInt32 leftnum=0;

	List<UInt16> cell;
	List<ItemCell> lic;
	ItemCell lic1;
	List<UInt16>::iterator itor;

	UInt32 roleID = packet.RoleID;
	UInt32 itemID=0;
	UInt16 count=0;
	UInt32 numcell=1;
	UInt16 Rarity=0;
	UInt32 BuyType=0;
	Byte type=0;
	Byte flag=0;

	//序列化类
	Serializer s(packet.GetBuffer());
	s>>type>>itemID>>num;
	LOG(LOG_ERROR,__FILE__,__LINE__,"type[%d]--itemid[%d]--num[%d]",type,itemID,num);
	//得到物品ID和数量
	if( s.GetErrorCode()!= 0 )
	{
		RetCode = ERR_SYSTEM_SERERROR;
		LOG(LOG_ERROR,__FILE__,__LINE__,"serial error" );
		goto EndOf_Process;
	}

	//获取DB连接
	con = _cp->GetConnection();
	dbo.SetHandle(con.GetHandle());
	//验证价格

	sprintf( szSql, "select NowPrice from ShopItem where ItemID=%d and Category=%d;",itemID,type );
	iRet = dbo.QuerySQL(szSql);
	if(iRet==0)
	{
		price=dbo.GetIntField(0);
	}
	else
	{
		RetCode = ERR_SYSTEM_DBNORECORD;
		LOG(LOG_ERROR,__FILE__,__LINE__,"QuerySQL data not found or erro,szSql[%s] " , szSql);
		goto EndOf_Process;
	}
	if(type==6)
	{
		//表示礼券购买
		iRet=DropGift(roleID,price*num);
		if(iRet==1)
		{
			//没有这么多数量的礼券
			RetCode = NO_MUCH_GIFT;
			LOG(LOG_ERROR,__FILE__,__LINE__,"Not so many Gift!! ");
			goto EndOf_Process;
		}
		else if(iRet==-1)
		{
			//错误
			RetCode = ERR_APP_DATA;
			LOG(LOG_ERROR,__FILE__,__LINE__,"there are some erro!! ");
			goto EndOf_Process;
		}

	}
	else if(type==7)
	{
		//表示限量抢购
		sprintf( szSql, "select ItemID,leftNum from specialItem where ItemID=%d;",itemID);

		iRet = dbo.QuerySQL(szSql);
		if(iRet!=0)
		{
			RetCode = ERR_SYSTEM_DBNORECORD;
			LOG(LOG_ERROR,__FILE__,__LINE__,"QuerySQL data not found ,szSql[%s] " , szSql);
			goto EndOf_Process;
		}

		else
		{
			leftnum=dbo.GetIntField(1);
		}

		if(leftnum<num)
		{
			//数量不足
			RetCode = ERR_SYSTEM_DBNORECORD;
			LOG(LOG_ERROR,__FILE__,__LINE__,"Not so many count!!!! ");
			goto EndOf_Process;
		}

	}
if(type!=6)
{
		// type 为5表示vip折扣
		if (type == 5)
		{
			RolePtr pRole = _mainSvc->GetCoreData()->ProcessGetRolePtr(roleID);
			sprintf( szSql, "select Discount from VipDiscountDesc where VipLevel = %d;",pRole->VIP());

			iRet = dbo.QuerySQL(szSql);
			if( iRet != 0 )
			{
				RetCode = ERR_SYSTEM_DBERROR;
				LOG(LOG_ERROR,__FILE__,__LINE__,",szSql[%s] ", szSql);
				goto EndOf_Process;
				}
			int discount = 0;
			while (dbo.HasRowData())
			{
				discount = dbo.GetIntField(0);
				dbo.NextRow();
			}
			if (discount != 0)
			{
				price = ((price * discount /100) > 0) ? (price * discount /100) :1;
			}
		}
		iRet=_mainSvc->GetBagSvc()->DropGold(roleID,price*num);
		if(iRet==-1)
		{
			//不足
			RetCode = NO_MUCH_GOLD;
			LOG(LOG_ERROR,__FILE__,__LINE__,"Not so many Gold!! ");
			goto EndOf_Process;
		}
		else if(iRet==0)
		{
			//错误
			RetCode = ERR_SYSTEM_DBNORECORD;
			LOG(LOG_ERROR,__FILE__,__LINE__,"there are some erro!! ");
			goto EndOf_Process;
		}
}
	//组合SQL语句,查询出完整的物品信息,查询出来的是物品类型和物品单元格类型
	sprintf( szSql, "select Rarity,IsStack,Bind,CostMoneyType,CostBuy, Durability,ItemType,CellType from Item where ItemID = %d;",itemID );

	iRet = dbo.QuerySQL(szSql);
	if( 1 == iRet)
	{
		RetCode = ERR_SYSTEM_DBNORECORD;
		LOG(LOG_ERROR,__FILE__,__LINE__,"QuerySQL data not found ,szSql[%s] " , szSql);
		goto EndOf_Process;
	}
	if( iRet < 0 )
	{
		RetCode = ERR_SYSTEM_DBERROR;
		LOG(LOG_ERROR,__FILE__,__LINE__,",szSql[%s] ", szSql);
		goto EndOf_Process;
 	}
 	//分离出数据做成变量, IsStack 是否堆叠   绑定属性Bind   Durability耐久度
 	if(iRet==0)
	{
		if(dbo.RowNum()==1)
		while(dbo.HasRowData())
		{
			Rarity=dbo.GetIntField(0);

			IsStack=dbo.GetIntField(1);
			Bind=dbo.GetIntField(2);
			BuyType=dbo.GetIntField(3);
			//price=dbo.GetIntField(4);
			Dur=dbo.GetIntField(5);
			itemType= dbo.GetIntField(6);
			cellType=dbo.GetIntField(7);

			//记录集下一条记录
			dbo.NextRow();
		}
	}
	//可知道物品中一些是不具备实体ID的,下面是进行对实体ID表进行插入数据的代码
	//判断是否具有实体ID函数,是返回1,不是返回0,int isEntity(int itemtype);该函数还没有开始编写代码
	if(itemType==2)//具备实体ID的话进行实体表插入, 更改的话对这里的值做个修改
	{
		flag=0;
		if(IsStack==1)
		{
			RetCode = ERR_SYSTEM_DBNORECORD;
			LOG(LOG_ERROR,__FILE__,__LINE__,"ExceSQL data error ,szSql[%s] " , szSql);
			goto EndOf_Process;
		}

		if(_mainSvc->GetBagSvc()->Ifhassomany(roleID,cell,num)!=1)
		{
			//背包不足
			RetCode = ERR_SYSTEM_DBNORECORD;
			LOG(LOG_ERROR,__FILE__,__LINE__," Bag has not so many room !" );
			goto EndOf_Process;
		}
		lic1.bindStatus=Bind;
 		lic1.durability=Dur;
 		lic1.EntityID=EntityID;
 		lic1.ItemID=itemID;


	}
	else
	{
		if(IsStack==0)
		{//不可以堆叠
		flag=1;
				if(_mainSvc->GetBagSvc()->Ifhassomany(roleID,cell,num)!=1)
				{
				//背包没有那么多空间
					RetCode = ERR_SYSTEM_DBERROR;
					LOG(LOG_ERROR,__FILE__,__LINE__,"Bag has no Room to insert,szSql[%s] ", mysql_error(con.GetHandle()), szSql);
					goto EndOf_Process;
				}
		}
		else
		{
				flag=2;
				numcell=num/TOPSTACK_NUM;//一共这么多个单元
				if(num%TOPSTACK_NUM!=0)
				{
					numcell=numcell+1;
				}

				if(_mainSvc->GetBagSvc()->Ifhassomany(roleID,cell,numcell)==0)
				{
					//背包没有那么多空间
					RetCode = ERR_SYSTEM_DBERROR;
					LOG(LOG_ERROR,__FILE__,__LINE__,"Bag has no Room to insert,szSql[%s] ", mysql_error(con.GetHandle()), szSql);
					goto EndOf_Process;
				}

	 	}
		sprintf( szSql, "select CdTime from Item where ItemID= %d;", itemID);
		iRet = dbo.QuerySQL(szSql);
		if(iRet==0)
		{
			lic1.cdTime=dbo.GetIntField(0);
		}
 		lic1.bindStatus=Bind;
		lic1.durability=Dur;
		lic1.EntityID=EntityID;
		lic1.ItemID=itemID;
 	}
	//向数据库里面进行插入数据!
	for( itor = cell.begin(); itor != cell.end(); itor++ )
	{
	if(flag==0)
	{
		sprintf( szSql,"insert into Entity(ItemID,Durability,BindStatus) values(%d,%d,%d);",itemID,Dur,Bind);

				iRet = dbo.ExceSQL(szSql);
				if( iRet < 0 )
				{
					RetCode = ERR_SYSTEM_DBERROR;
					LOG(LOG_ERROR,__FILE__,__LINE__,"ExceSQL error[%s],szSql[%s] ", mysql_error(con.GetHandle()), szSql);
					goto EndOf_Process;
		 		}

				EntityID=dbo.LastInsertID();

				sprintf(szSql, "insert into Bag(RoleID,CellType,CellIndex,ItemType,ItemID,EntityID,Num)values(%d,%d,%d,%d,%d,%d,1);",roleID,cellType,*itor,itemType,itemID,EntityID);
				iRet=dbo.ExceSQL(szSql);

				if( 1 == iRet )
				{
					RetCode = ERR_SYSTEM_DBNORECORD;
					LOG(LOG_ERROR,__FILE__,__LINE__,"ExceSQL data not found ,szSql[%s] " , szSql);
					goto EndOf_Process;
				}
				if( iRet < 0 )
				{
					RetCode = ERR_SYSTEM_DBERROR;
					LOG(LOG_ERROR,__FILE__,__LINE__,"ExceSQL error[%s],szSql[%s] ", mysql_error(con.GetHandle()), szSql);
					goto EndOf_Process;
				}

				lic1.num=1;
				lic1.celIndex=*itor;
				lic1.EntityID=EntityID;
				lic.push_back(lic1);
	}
	if(flag==2)
	{
				if(numcell==1)
				{
					//数量就是为传输的数量
					if(num%TOPSTACK_NUM==0)
					{
						count=TOPSTACK_NUM;
					}
					else
					{
						count=num%TOPSTACK_NUM;
					}
				}
				else
				{
					count=TOPSTACK_NUM;
				}

				sprintf(szSql, "insert into Bag(RoleID,CellType,CellIndex,ItemType,ItemID,EntityID,Num)values(%d,%d,%d,%d,%d,%d,%d);",roleID,cellType,*itor,itemType,itemID,EntityID,count);
				iRet=dbo.ExceSQL(szSql);

				if( 1 == iRet )
				{
					RetCode = ERR_SYSTEM_DBNORECORD;
					LOG(LOG_ERROR,__FILE__,__LINE__,"ExceSQL data not found ,szSql[%s] " , szSql);
					goto EndOf_Process;
				}
				if( iRet < 0 )
				{
					RetCode = ERR_SYSTEM_DBERROR;
					LOG(LOG_ERROR,__FILE__,__LINE__,"ExceSQL error[%s],szSql[%s] ", mysql_error(con.GetHandle()), szSql);
					goto EndOf_Process;
				}

				lic1.num=count;
				lic1.celIndex=*itor;
				lic.push_back(lic1);
		}
		else if(flag==1)
		{
				sprintf(szSql, "insert into Bag(RoleID,CellType,CellIndex,ItemType,ItemID,EntityID,Num)values(%d,%d,%d,%d,%d,%d,1);",roleID,cellType,*itor,itemType,itemID,EntityID);
				iRet=dbo.ExceSQL(szSql);

				if( 1 == iRet )
				{
					RetCode = ERR_SYSTEM_DBNORECORD;
					LOG(LOG_ERROR,__FILE__,__LINE__,"ExceSQL data not found ,szSql[%s] " , szSql);
					goto EndOf_Process;
				}
				if( iRet < 0 )
				{
					RetCode = ERR_SYSTEM_DBERROR;
					LOG(LOG_ERROR,__FILE__,__LINE__,"ExceSQL error[%s],szSql[%s] ", mysql_error(con.GetHandle()), szSql);
					goto EndOf_Process;
				}

				lic1.num=1;
				lic1.celIndex=*itor;
				lic.push_back(lic1);
		}
		numcell--;
	}
	_mainSvc->GetTaskSvc()->OnBagItemAddOrDelete(roleID,itemID);


	EndOf_Process:

	//组应答数据
	Packet p(&serbuffer);
	s.SetDataBuffer(&serbuffer);
	serbuffer.Reset();

	p.CopyHeader(packet);
	p.Direction = DIRECT_C_S_RESP;
	p.PackHeader();


	s<<RetCode;
	if( 0 == RetCode )
	{//RetCode 为0 才会返回包体剩下内容
		//s<<lic;
	}

	p.UpdatePacketLength();

	//发送应答数据
	if( session.Send(&serbuffer) )
	{
		LOG(LOG_ERROR,__FILE__,__LINE__,"session.Send error ");
	}

	DEBUG_PRINTF( "ack pkg=======, \n" );
	DEBUG_SHOWHEX( serbuffer.GetReadPtr(), serbuffer.GetDataSize(), 0, __FILE__, __LINE__ );
	if( 0 == RetCode )
	{

		_mainSvc->GetBagSvc()->NotifyBag(roleID,lic);
		if(type!=6)
		{
			_mainSvc->GetBagSvc()->NotifyMoney(roleID);
		}

		if(type==7)
		{
			UpdateDBspecialItem(itemID,num);
		}
			UpdateDBItemSellCount(itemID,type,num);
 	}
	return;


}
int PKSvc::MakeSSPkgForPet(const ArchvPosition &posPKOrigin, UInt32 roleID, List<ArchvRolePKInfo> &lrpki,Byte type,Byte dirte)
{
		char szSql[1024];
		Connection con;
		DBOperate dbo;
		int iRet = 0;
		UInt32 PetID=0;
		ArchvRolePKInfo petpkInfo;
		//获取DB连接
		con = _cp->GetConnection();
		dbo.SetHandle(con.GetHandle());
		
		sprintf( szSql, "select	 PetID , PetType,PetKind  ,PetName   ,Level      ,Exp ,MaxExp,   \
							   AddPoint   ,Strength \
							   ,Intelligence   ,Agility        ,MoveSpeed      ,HP             ,MP          \
							   ,MaxHP          ,MaxMP          ,HPRegen        ,MPRegen        ,AttackPowerHigh \
							   ,AttackPowerLow    ,AttackScope       ,AttackSpeed       ,BulletSpeed       ,Defence        \
							   ,MDefence          ,CritRate          ,HitRate           ,DodgeRate             \
							from Pet \
							where RoleID=%d and IsUse=1;", roleID );
	iRet = dbo.QuerySQL(szSql);
	if( 1 == iRet )
	{
//		LOG(LOG_ERROR,__FILE__,__LINE__,"QuerySQL data not found ,szSql[%s] " , szSql);
		return -1;
	}
	if( iRet < 0 )
	{
		LOG(LOG_ERROR,__FILE__,__LINE__,"QuerySQL error[%s],szSql[%s] ", mysql_error(con.GetHandle()), szSql);
		return -1;
 	}
	petpkInfo.controlID=roleID;
	petpkInfo.creatureFlag=4;
	petpkInfo.opposition=type;
	if(posPKOrigin.X-PKSCREEN_XLENGTH/2>0)
	{
		petpkInfo.currPosX=posPKOrigin.X+2;
	}
	else
	{
		petpkInfo.currPosX=posPKOrigin.X-2;
	}
	petpkInfo.currPosY=posPKOrigin.Y;
	while(dbo.HasRowData())
	{
			PetID = dbo.GetIntField(0);
			petpkInfo.roleID=PetID;
		 petpkInfo.creatureType=dbo.GetIntField(1);
		//_petkind=dbo.GetIntField(2) ;力量型什么的
		// Name( dbo.GetStringField(3) );
		petpkInfo.level=dbo.GetIntField(4);
		//Exp( dbo.GetIntField(5) );
		//MaxExp(dbo.GetIntField(6));
		//AddPoint( dbo.GetIntField(7) );
		petpkInfo.Strength=dbo.GetIntField(8);
		petpkInfo.Wisdom=dbo.GetIntField(9);
		petpkInfo.Agile=dbo.GetIntField(10);
		petpkInfo.moveSpeed=dbo.GetIntField(11);
		petpkInfo.hp=dbo.GetIntField(12);
		petpkInfo.mp=dbo.GetIntField(13);
		petpkInfo.maxHP=dbo.GetIntField(14);
		petpkInfo.maxMP=dbo.GetIntField(15);
		// HpRegen( dbo.GetIntField(16) );
		//MpRegen( dbo.GetIntField(17) );
		petpkInfo.attackPowerHigh=dbo.GetIntField(19);
		petpkInfo.attackPowerLow=dbo.GetIntField(20);
		petpkInfo.attackArea=dbo.GetIntField(21);
		petpkInfo.attackBulletSpeed=dbo.GetIntField(22);
		petpkInfo.attackSpeed=dbo.GetIntField(23);
		petpkInfo.defense=dbo.GetIntField(24);
		petpkInfo.mDefense=dbo.GetIntField(25);
		petpkInfo.CritRate=dbo.GetIntField(26);
		petpkInfo.hitRate=dbo.GetIntField(27);
		petpkInfo.dodgeRate=dbo.GetIntField(28);
		
		dbo.NextRow();
	}
	sprintf( szSql, "select	 PetID     ,Strength   ,Intelligence   ,Agility      ,MovSpeed ,MaxHP,MaxMP     \
						   ,HPRegen      ,MPRegen    ,AttackPowerHigh      ,AttackPowerLow   ,AttackSpeed \
						   ,Defence   ,MDefence        ,CritRate      ,HitRate             ,DodgeRae          \
						from PetBonus \
						where PetID = %d ", PetID );
	iRet=dbo.QuerySQL(szSql);
	if( 1 == iRet )
	{
		LOG(LOG_ERROR,__FILE__,__LINE__,"QuerySQL data not found ,szSql[%s] " , szSql);
		return -1;
	}
	if( iRet < 0 )
	{
		LOG(LOG_ERROR,__FILE__,__LINE__,"QuerySQL error[%s],szSql[%s] ", mysql_error(con.GetHandle()), szSql);
		return -1;
 	}
	while(dbo.HasRowData())
	{		
		petpkInfo.Strength =petpkInfo.Strength+dbo.GetIntField(1);
		petpkInfo.Wisdom=petpkInfo.Wisdom+dbo.GetIntField(2);
		petpkInfo.Agile=petpkInfo.Agile+dbo.GetIntField(3);
		petpkInfo.moveSpeed=petpkInfo.moveSpeed+dbo.GetIntField(4);
		petpkInfo.maxHP=petpkInfo.maxHP+dbo.GetIntField(5);
		petpkInfo.maxMP=petpkInfo.maxMP+dbo.GetIntField(6);
	//	HpRegenBonus(dbo.GetIntField(7));
	//	MpRegenBonus(dbo.GetIntField(8));
		petpkInfo.attackPowerHigh=petpkInfo.attackPowerHigh+dbo.GetIntField(9);
		petpkInfo.attackPowerLow=petpkInfo.attackPowerLow+dbo.GetIntField(10);
		petpkInfo.attackSpeed=petpkInfo.attackSpeed+dbo.GetIntField(11);
		petpkInfo.defense=petpkInfo.defense+dbo.GetIntField(12);
		petpkInfo.mDefense=petpkInfo.mDefense+dbo.GetIntField(13);
		petpkInfo.CritRate=petpkInfo.CritRate+dbo.GetIntField(14);
		petpkInfo.hitRate=petpkInfo.hitRate+dbo.GetIntField(15);
		petpkInfo.dodgeRate=petpkInfo.dodgeRate+dbo.GetIntField(16);
		
		dbo.NextRow();
	}
		petpkInfo.direct=dirte;
	 	LOG(LOG_ERROR,__FILE__,__LINE__,"PKRoleID:::: %d contronID :::%d  ---------" , petpkInfo.roleID,petpkInfo.controlID);
	lrpki.push_back(petpkInfo);
	return 0;
}
//@brief 组建 S_S pk请求包:  for 角色
//@lrpki		返回的组建结果
//@return 0 成功  非0 失败,type为1表示攻击者,为2表示被攻击者,区分阵营
int PKSvc::MakeSSPkgForRole( 	const ArchvPosition &posPKOrigin, RolePtr &role, List<ArchvRolePKInfo> &lrpki,Byte type)
{
	ArchvRolePKInfo pkInfo;
	ArchvAvatarDescBrief adb;
	List<ArchvAvatarDescBrief> ladb;
	ArchvPosition rolePosition;
	List<UInt32> lrid;
	ArchvSkill skill;
	char szSql[1024];
	Connection con;
  DBOperate dbo;
	int iRet = 0;
		
		//获取DB连接
		con = _cp->GetConnection();
		dbo.SetHandle(con.GetHandle());

	//赋值
	pkInfo.controlID = role->ID();
	pkInfo.roleID = role->ID();
	pkInfo.level = role->Level();
	if(type==1)
	{
		pkInfo.opposition = 1;
	}
	else
	{
		pkInfo.opposition = 2;
	}
	pkInfo.creatureFlag = 1;
	pkInfo.creatureType = role->ProID();
//	pkInfo.origin = 1;
	//pkInfo.live = 1;
	pkInfo.maxHP = role->MaxHp()+role->MaxHpBonus();
	pkInfo.maxMP =role->MaxMp()+role->MaxMpBonus();
	pkInfo.hp = role->Hp();
	//+(time(NULL)-role->LastHpMpTime)*(role->HpRegen());
	pkInfo.mp = role->Mp();
	//+(time(NULL)-role->LastHpMpTime)*(role->MpRegen());
	pkInfo.moveSpeed = role->MoveSpeed()+role->MovSpeedBonus();
	

	
//pk坐标处理
//	对超出pk地图范围的坐标进行调整
  pkInfo.currPosX = posPKOrigin.X;
	pkInfo.currPosY = posPKOrigin.Y;
LOG(LOG_DEBUG,__FILE__,__LINE__,"----------->>>>roleID [%d], currPosX x[%d],y[%d]  ",
	role->ID(), pkInfo.currPosX, pkInfo.currPosY );
	
	pkInfo.direct = role->Direct();
	pkInfo.attackPowerHigh = role->AttackPowerHigh()+role->AttackPowerHighBonus();
	pkInfo.attackPowerLow = role->AttackPowerLow()+role->AttackPowerLowBonus();
	pkInfo.attackArea = role->AttackScope();
	pkInfo.attackSpeed = role->AttackSpeed()+role->AttackSpeedBonus();
	pkInfo.attackDisplayTime = 2;
	pkInfo.attackBulletSpeed = role->BulletSpeed();
	pkInfo.hitRate = role->HitRate()+role->HitRateBonus();
	pkInfo.dodgeRate = role->DodgeRate()+role->DodgeRateBonus();
	pkInfo.defense = role->Defence()+role->DefenceBonus();
	pkInfo.mDefense = role->MDefence()+role->MDefenceBonus();
	pkInfo.CritRate=role->CritRate()+role->CritRateBonus();
	pkInfo.Agile=role->Agility()+role->AgilityBonus();
	pkInfo.Strength=role->Strength()+role->StrengthBonus();
	pkInfo.Wisdom=role->Intelligence()+role->IntelligenceBonus();
//	LOG(LOG_ERROR,__FILE__,__LINE__,"PKRoleID:::: %d contronID :::%d  ---------" , pkInfo.roleID,pkInfo.controlID);
	//pkInfo.

/*	lrid.push_back(	pkInfo.roleID );
	iRet = _mainSvc->GetAvatarSvc()->GetEquipBrief( lrid, ladb);
	if(iRet)
	{
		LOG(LOG_ERROR,__FILE__,__LINE__,"GetEquipBrief error" );
		return -1;
	}
	*/
//	pkInfo.wpnItemID = ladb.front().wpnItemID;
//	pkInfo.flag = ladb.front().coatID;

	//技能
	pkInfo.las.clear();

		
	sprintf(szSql,"select SkillID,SkillLev from RoleSkill where RoleID=%d and SkillID<300 and SkillLev>0",role->ID());
	iRet=dbo.QuerySQL(szSql);
	if(iRet!=0)
	{
		LOG(LOG_ERROR,__FILE__,__LINE__,"QuerySQL role not have skill[%s],szSql[%s] ", mysql_error(con.GetHandle()), szSql);
	}

	while(dbo.HasRowData())
	{
			skill.skillID=dbo.GetIntField(0);
			skill.skillLevel=dbo.GetIntField(1);
			pkInfo.las.push_back(skill);
		
		dbo.NextRow();
	}
	
		
	
	lrpki.push_back(pkInfo);

//	MakeSSPkgForPet(const ArchvPosition & posPKOrigin,UInt32 roleID,List < ArchvRolePKInfo > & lrpki)
	rolePosition.X=pkInfo.currPosX;
	rolePosition.Y=pkInfo.currPosY;
	MakeSSPkgForPet(posPKOrigin,role->ID(),lrpki,type,pkInfo.direct);
	

	return 0;
}