コード例 #1
0
ファイル: ChangePartManager.cpp プロジェクト: lorichen/xgame
void ChangePartManager::changeSuitArmet(SPersonMainPartChangeContext & context)
{
	ulong curBody = getCurrentBody();
	SPersonMainPartChangeContext & curContext = m_CurrentPart[EEntityPart_Suit_Armet];

	if( curBody != EEntityPart_Suit_Armor)//当前显示的不是时装装备的模型,只存储数据
	{
		curContext = context;
		return;
	}

	if( !m_bCanRequestRes)//不能申请资源了
	{
		curContext = context;
		return;
	}

	if(0 == m_pModelNode )//当前显示的节点还没有加载上来,只存储数据
	{
		curContext = context;
		return;
	}

	//首先卸载旧的模型
	const char * pOldBP = gGlobalClient->getEntityClient()->GetSchemeCenter()->getBindPoint(curContext.bindPoint[0] );
	ModelNode * pOld = m_pModelNode->getFirstChildNodeByBone(pOldBP);
	if( pOld )  m_pModelNode->destroyChild( pOld);

	if( context.perform)//穿上装备
	{
		ModelNode * pNode = 0;
		ConfigCreature* pCreatureConfig = ConfigCreatures::Instance()->getCreature(context.resId[0]);
		if( pCreatureConfig )
		{
			pNode = ModelNodeCreater::create(pCreatureConfig);
			if( pNode)
				pNode->setScale(xs::Vector3::UNIT_SCALE);
		}
		else
		{
			const std::string & filename = ConfigCreatureRes::Instance()->getResFromId(context.resId[0]);
			pNode = ModelNodeCreater::create(filename.c_str() );
		}
			
		if( pNode )
		{
			const char * pBP = gGlobalClient->getEntityClient()->GetSchemeCenter()->getBindPoint(context.bindPoint[0]);
			if( !m_pModelNode->addChild(pNode, pBP) )
			{
				pNode->release();
				pNode = 0;
			}
			else
			{
				//设置时装头盔的颜色
				pNode->setGlobalDiffuse(m_vSuitArmetColor);
			}
			
		}
	}
	else
	{
		//已经卸载了
	}

	//保存换装环境
	curContext = context;
	//设置头盔的显示
	showPart(EEntityPart_Suit_Armet, m_bShowPart[EEntityPart_Suit_Armet]);

	return;
}