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

📄 gcharacterclient.cc

📁 五行MMORPG引擎系统V1.0
💻 CC
字号:
//GCharacter.cc
/*/////////////////////////////////////////////////////////////////

   李亦
	liease@163.com 4040719
	2006-7-18
/*/////////////////////////////////////////////////////////////////
#ifdef TGE_RPGCLIENT

#include "rpg/RPGDataMan.h"
#include "rpg/gobjects/GCharacter.h"
#include "rpg/RPGSetting.h"
#include "rpg/RPGChat.h"


#include "game/shapeBase.h"
#include "game/aiPlayer.h"
#include "gui/containers/GuiCellArrayCtrl.h"

namespace RPG
{


void GCharacter::AddAction(U32 uCmd,U32 dwData)
{
	m_arActionQueues.increment();
	m_arActionQueues.last().dwCmd		= uCmd;
	m_arActionQueues.last().dwData	= dwData;
}

void GCharacter::UpdateToUI(GGoodsArray* pSlot,U32 nIndex)
{
	ERPGGoodsArrayTypes	type;
	STE						pUIName;
	GuiCellArrayControl*	pCellArrayUI;

	if(!pSlot)
		return;

	type		= pSlot->GetArrayType(nIndex);
	pUIName	= RPG::g_pRPGSetting->GetGoodsArTypeUIName(type);
	if(pUIName && pUIName[0] && Sim::findObject(pUIName, pCellArrayUI))
	{
		if(nIndex == -1)
			pCellArrayUI->updateGameIcons();
		else
			pCellArrayUI->updateGameIcon(nIndex - pCellArrayUI->GetBaseIndex());
	}

}

void GCharacter::UpdateToTShape(U32 nUpdates)
{
	U32	n;
	GGoods*	pEquip;

	if(nUpdates & TSU_EQUIPS)
	{
		for(n=0; n<m_arEquipments.size() ; n++)
		{
			pEquip = m_arEquipments[n];
			if(pEquip)
				UpdateEquipToTShape((EGEquipTypes)n,pEquip,FALSE);
		}//for
	}//if(nUpdates & TSU_EQUIPS)


	Player*	pPlayer = dynamic_cast<Player*>(GetGameBase());
	if(pPlayer)
	{
		//if(nUpdates & TSU_MOVE)
		if(nUpdates & TSU_PROPERTY)
		{
			//设置名称
			pPlayer->setShapeName(GetCharName());
			if(this == g_pGPlayer)
			{
				Con::setVariable("$Player::Money", 
						avar("%d%s",m_dataCharacter.nMoney,g_pRPGSetting->GetMoneyUnit()) );
			}
		}//if(nUpdates & TSU_PROPERTY)

		if(nUpdates & TSU_MOVE)
		{
			CalcEquipMoveSpeed();
			pPlayer->setMoveSpeed(m_dataResult.eMoveSpeed + m_dataAffect.eMoveSpeed);
			pPlayer->setMoveRate(m_dataResult.eMoveRate  + m_dataAffect.eMoveRate);
		}

		//位置
		if(nUpdates & TSU_POS)
		{
			pPlayer->setPosition(Point3F(m_dataCharacter.x, m_dataCharacter.y, m_dataCharacter.z),
							Point3F(0,0,m_dataCharacter.rot * M_PI_DIV180));
		}//if(nUpdates & TSU_DISPLACE)


		//
	}//if(pPlayer)

}


void GCharacter::UpdateEquipToTShape(EGEquipTypes slot,GGoods*	pEquip,BOOL bUpdate)
{
	//依据装备槽,变更人物形象...

	///////////////////////////////////////////////
	//下装处理
	if(pEquip == NULL)
	{	
		if(slot == EQUIP_ARMS)
		{
			WearEquipment(slot,NULL);
		}
		else
		{
			RemoveSkinModifier(slot);
		}
		
		if(bUpdate)
			UpdateToTShape(TSU_EFFICACY);

		RPGChat::OutputTipF(TIP_EQUIP_UNLOAD, g_pRPGSetting->GetEquipTypeName(slot) );
		return;
	}//if


	/////////////////////////////////////////////////
	//上装处理
	if(!pEquip->IsType(GGT_EQUIP, slot))
	{
		RPGChat::OutputTipF(TIP_EQUIP_SLOT_ERROR, g_pRPGSetting->GetEquipTypeName(slot) );
		AssertWarn(0,"自动下装");
		return;
	}

	////////////////////////////////////////////////////////////
	//上装处理
	if(slot == EQUIP_ARMS)
	{
		WearEquipment(slot, pEquip);
	}
	else
	{
		StringTableEntry	sTag;
		char	szFile[256];

		sTag = g_pRPGSetting->GetEquipTexTag(slot);
		if(sTag && sTag[0])
		{
			dSprintf(szFile, 256, "models/textures/%s/%s",
						g_pRPGSetting->GetEquipTypeLabel(slot),
						pEquip->GetFileTitle()	);
			AddSkinModifier(slot, sTag, szFile);
		}
	}//else


	if(bUpdate)
		UpdateToTShape(TSU_EFFICACY);

	RPGChat::OutputTipF(TIP_EQUIP_ARMING,
						pEquip->GetGoodsName(),
						g_pRPGSetting->GetEquipTypeName(slot) );

}



bool GCharacter::PlayMotion(StringTableEntry pIconTag)
{
	//发送motion指令
	//Player*	pPlayer = static_cast<Player*>(GetGameBase());
	//if(pPlayer)
	//{
	//	pPlayer->setActionThread(pIconTag, false,true);
	//	RPGChat::OutputTipF(TIP_MOTION_PLAYING,pIconTag);
	//	return true;
	//}
	//return false;
#ifdef TGE_RPGCLIENT
	AddAction(CA_PLAYMOTION, (U32)pIconTag);
#endif
	return true;
}





void GCharacter::AddSkinModifier(U32 slot, StringTableEntry skinName, StringTableEntry printName)
{
	ShapeBase* pShapeBase = dynamic_cast<ShapeBase*>(GetGameBase());
	if(!pShapeBase)
		return;
	pShapeBase->m_skinMan.addSkinModifier(slot,  skinName, printName);
}

void GCharacter::RemoveSkinModifier(U32 slot)
{
	ShapeBase* pShapeBase = dynamic_cast<ShapeBase*>(GetGameBase());
	if(!pShapeBase)
		return;
	pShapeBase->m_skinMan.removeSkinModifier(slot);
}

void GCharacter::ClearSkinModifiers()
{
	ShapeBase* pShapeBase = dynamic_cast<ShapeBase*>(GetGameBase());
	if(!pShapeBase)
		return;
	pShapeBase->m_skinMan.clearSkinModifiers();
}




void GCharacter::WearEquipment(EGEquipTypes slot,GGoods*	pEquip)
{
	ShapeBase* pShapeBase = dynamic_cast<ShapeBase*>(GetGameBase());
	if(!pShapeBase)
		return;

	//下装处理
	if(pEquip == NULL)
	{
		pShapeBase->unmountImage(slot);
		return;
	}

	/////////////////////////////////////////
	//上装处理
	if(!pEquip->IsType(GGT_EQUIP,slot))
	{	
		AssertWarn(0,"上装时装备类型与槽不相应");
		return;
	}



	StringTableEntry sInst = pEquip->GetInstName();
	ShapeBaseImageData* pImage ;

	if(Sim::findObject(sInst, pImage))
	{
      StringHandle team;
		pShapeBase->mountImage(pImage,slot ,true, team);
	}
}





GameBase* GCharacter::CreateGameBase(CSTR sClass)
{
	GameBase*		pObject;
	GameBaseData*	pData;
	ConsoleObject*	pConObj;
	SimGroup*		pGroup;

	pConObj = ConsoleObject::create(sClass);
	if(pConObj == NULL)
		return NULL;

	pObject = static_cast<GameBase*>(pConObj);
	if(pObject)
	{
		if(Sim::findObject(GetInstName(),pData))
		{	
			if(pObject->setDataBlock(pData) && pObject->registerObject() )
			{		
				SetGameBase(pObject);

				if(g_pRPGSetting)
					pGroup = dynamic_cast<SimGroup*>(Sim::findObject( g_pRPGSetting->GetMissionCleanup() ));
				else
					pGroup = NULL;
				if(!pGroup)
					pGroup = Sim::getRootGroup();
				pGroup->addObject(pObject);

				UpdateToTShape();
				return pObject;
			}
		}
	}
	else
	{
		delete pConObj;
	}
	return NULL;
}

bool GCharacter::AttachTSDatablock(GameBaseData* pGBDatablock)
{
	if(pGBDatablock == NULL)
		return false;
	Player* pPlayer = dynamic_cast<Player*>(GetGameBase());
	if(!pPlayer)
	{
		pPlayer = new AIPlayer();
		pPlayer->registerObject();
		SimGroup* pGroup = dynamic_cast<SimGroup*>(Sim::findObject("PCSelectorPlayerGroup"));
		if(!pGroup)
			pGroup = Sim::getRootGroup();
		pGroup->addObject(pPlayer);

		SetGameBase(pPlayer);
	}
	pPlayer->setDataBlock(pGBDatablock);

	return true;
}








/////////////////////////////////////////////////////////////////
ConsoleMethod( GCharacter, addSkinModifier, void, 5, 5, "ObjectView.addSkinModifier(slot,skinTag,skinName)" ) 
{
	char szFileName[1024];
	char szFileName2[1024];
	Con::expandScriptFilename(szFileName,sizeof(szFileName),argv[4]);

   U32 slot;
   dSscanf(argv[2],"%d",&slot);

	object->AddSkinModifier(slot,
									StringTable->insert(argv[3]),
									StringTable->insert(szFileName));

}


ConsoleMethod( GCharacter, removeSkinModifier, void, 3, 3, "ObjectView.removeSkinModifier(slot)" ) 
{
	U32 slot;
   dSscanf(argv[2],"%d",&slot);

	object->RemoveSkinModifier(slot);
}


ConsoleMethod( GCharacter, clearSkinModifiers, void, 2, 2, "ObjectView.clearSkinModifiers()" ) 
{
	object->ClearSkinModifiers();
}

ConsoleMethod( GCharacter, CreateGameBase, const char*, 3, 3, "ObjectView.(className)" ) 
{
	GameBase*	pGBase;
	pGBase = object->CreateGameBase(argv[2]);
	if(!pGBase)
		return "";
	return pGBase->getIdString();
}



};//namespace RPG

#endif//#ifdef TGE_RPGCLIENT

⌨️ 快捷键说明

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