Example #1
0
ORESULT AbilityMachining::CanUseAbility(Obj_Human* pHuman)
{
__ENTER_FUNCTION

	Assert( pHuman );

	AbilityOpera* pAbilityOpera;

	pAbilityOpera = pHuman->GetAbilityOpera();
	Assert( pAbilityOpera );

	switch( pAbilityOpera->m_SubType )
	{
	case NORMAL_TYPE:
		return AbilityCompound::CanUseAbility(pHuman);
	case GEM_COMPOUND:
		{
			ORESULT res;
			res = Ability::CanUseAbility(pHuman);
			if( res != OR_OK )
			{
				return res;
			}

			if( (pAbilityOpera->m_BagPos[0] < 0) || (pAbilityOpera->m_BagPos[0] >= MAX_BAG_SIZE)
			 || (pAbilityOpera->m_BagPos[1] < 0) || (pAbilityOpera->m_BagPos[1] >= MAX_BAG_SIZE)
			 )
			{
				Assert(FALSE);
				return OR_ERROR;
			}

			//const	_ITEM* pGem1 = pHuman->GetItem(pAbilityOpera->m_BagPos[0]);
			//const	_ITEM* pGem2 = pHuman->GetItem(pAbilityOpera->m_BagPos[1]);
			
			Item*	pGem1Item = HumanItemLogic::GetBagItem(pHuman,pAbilityOpera->m_BagPos[0]);
			Item*	pGem2Item = HumanItemLogic::GetBagItem(pHuman,pAbilityOpera->m_BagPos[1]);

			Assert( (pGem1Item != NULL) && (pGem2Item != NULL) );

			if( (pGem1Item->GetItemClass() != ICLASS_GEM) || (pGem2Item->GetItemClass() != ICLASS_GEM) )
			{
				return OR_STUFF_LACK;
			}

			if((pGem1Item->GetItemIndex() != pGem2Item->GetItemIndex())// (pGem1Item->GetItemQual() != pGem2Item->GetItemQual())
			 )
			{
				return OR_STUFF_LACK;
			}

			//if(  >= MAX_GEM_QUALITY ) // pGem1Item->GetItemQual()没法再升了
			//{
			//	return OR_CANNOT_UPGRADE;
			//}

			return OR_OK;
		}
		break;
	case GEM_EMBED:
		{
			ORESULT res;
			res = Ability::CanUseAbility(pHuman);
			if( res != OR_OK )
			{
				return res;
			}

			if( (pAbilityOpera->m_BagPos[0] < 0) || (pAbilityOpera->m_BagPos[0] >= MAX_BAG_SIZE)
			 || (pAbilityOpera->m_BagPos[1] < 0) || (pAbilityOpera->m_BagPos[1] >= MAX_BAG_SIZE)
			 )
			{
				Assert(FALSE);
				return OR_ERROR;
			}

			//const	_ITEM* pGem = pHuman->GetItem(pAbilityOpera->m_BagPos[0]);
			//const	_ITEM* pEquip = pHuman->GetItem(pAbilityOpera->m_BagPos[1]);

			Item*		pGemItem	=	HumanItemLogic::GetBagItem(pHuman,pAbilityOpera->m_BagPos[0]);
			Item*		pEquipItem	=	HumanItemLogic::GetBagItem(pHuman,pAbilityOpera->m_BagPos[1]);
			Assert( (pGemItem != NULL) && (pEquipItem != NULL) );

			if( (pGemItem->GetItemClass() != ICLASS_GEM) || (pEquipItem->GetItemClass() != ICLASS_EQUIP) )
			{
				return OR_STUFF_LACK;
			}

			if( IsGemConflict(pHuman, pAbilityOpera->m_BagPos[0], pAbilityOpera->m_BagPos[1]) == FALSE )
			{
				return OR_GEM_CONFLICT;
			}

			LuaInterface* pLuaInterface;
			pLuaInterface = pHuman->getScene()->GetLuaInterface();

			if( pEquipItem->GetGemSlotMax() <= pEquipItem->GetEquipGemCount()
				|| pLuaInterface->ExeScript_DDD(	ABILITY_LOGIC_SCRIPT, 
													"TooManyGems",
													(INT)pHuman->getScene()->SceneID(),
													(INT)pHuman->GetID(),
													(INT)pAbilityOpera->m_BagPos[1] )
			 )
			{
				return OR_GEM_SLOT_LACK;
			}

			return OR_OK;
		}
		break;
	default:
		Assert(FALSE);
		return OR_ERROR;
	}

	return OR_WARNING;

__LEAVE_FUNCTION

	return OR_ERROR;
}
Example #2
0
UINT CGEquipRefiningHandler::Execute( CGEquipRefining* pPacket, Player* pPlayer )
{
	__ENTER_FUNCTION

	GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
	Assert( pGamePlayer ) ;

	Obj_Human* pHuman = pGamePlayer->GetHuman() ;
	Assert( pHuman ) ;

	Scene* pScene = pHuman->getScene() ;
	if( pScene==NULL )
	{
		Assert(FALSE) ;
		return PACKET_EXE_ERROR ;
	}
	//检查线程执行资源是否正确
	Assert( MyGetCurrentThreadID()==pScene->m_ThreadID );

	//切场景时丢弃换装消息
	//交易状态不可操作
	//摆摊状态不可操作

	// 获取炼化的装备
	BYTE iEquipItemPos = pPacket->GetEquipItemPos();
	Assert(iEquipItemPos >= 0 );
	Assert(iEquipItemPos <= MAX_BAG_SIZE);
	
	GCEquipRefining	msg;
	ItemContainer* pBagContainer = HumanItemLogic::GetBagContainer(pHuman, iEquipItemPos);
	if (pBagContainer == NULL)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRefiningHandler equipment BagIndex is invalid, BagIndex = %d", iEquipItemPos) ;
		msg.SetResult(EQUIPREFINING_NOT_SUCH_ITEM);
		pGamePlayer->SendPacket(&msg);
		return PACKET_EXE_CONTINUE;
	}

	Item* pEquipment = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(iEquipItemPos));
	Assert(NULL != pEquipment);
	//一些验证:星级,等级...
	if( NULL == pEquipment || ICLASS_EQUIP != pEquipment->GetItemClass() || !(pEquipment->IsRuler(IRL_DISCARD) )
		|| pEquipment->IsAdsorbMagic()	|| pEquipment->GetRequireLevel() < EQUIP_REFINING_MIN_LEVEL	//已经附魔或者需求等级小于40
		|| 0 == pEquipment->GetEquipGemCount())	//没有镶嵌宝石
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRefiningHandler equipment type is invalid, BagIndex = %d", iEquipItemPos) ;
		msg.SetResult(EQUIPREFINING_NOT_SUCH_ITEM);
		pGamePlayer->SendPacket(&msg);

		return PACKET_EXE_CONTINUE;
	}
	//获取炼化神器
	BYTE iRefiningItemPos = pPacket->GetRefiningItemPos();
	Assert(iRefiningItemPos >= 0 );
	Assert(iRefiningItemPos <= MAX_BAG_SIZE);

	pBagContainer = HumanItemLogic::GetBagContainer(pHuman, iRefiningItemPos);
	if (pBagContainer == NULL)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRefiningHandler refining BagIndex is invalid, BagIndex = %d", iRefiningItemPos) ;
		msg.SetResult(EQUIPREFINING_NOT_SUCH_ITEM);
		pGamePlayer->SendPacket(&msg);
		return PACKET_EXE_CONTINUE;
	}

	Item* pRefiningItem = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(iRefiningItemPos));
	Assert(NULL != pRefiningItem);
	if(NULL == pRefiningItem || pRefiningItem->GetItemClass() != ICLASS_COMITEM || pRefiningItem->GetItemType() != COMITEM_EQUIP_REFINING)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRefiningHandler refining type is invalid, BagIndex = %d", iRefiningItemPos) ;
		msg.SetResult(EQUIPREFINING_NOT_SUCH_ITEM);
		pGamePlayer->SendPacket(&msg);

		return PACKET_EXE_CONTINUE;
	}
	//逻辑处理 
	COMMITEM_INFO_TB* pGet = g_ItemTable.GetCommItemInfoTB(pRefiningItem->GetItemTableIndex());
	Assert(NULL != pGet);
	if ((pEquipment->GetRequireLevel()-1)/10+1 != pGet->m_nLevel)//验证等级
	{
		msg.SetResult(EQUIPREFINING_NOT_SUCH_ITEM);
		pGamePlayer->SendPacket(&msg);

		return PACKET_EXE_CONTINUE;
	}

	if ( 0 == pEquipment->GetAttrCount())// && pEquipment->GetLevel() 
	{
		msg.SetResult(EQUIPREFINING_NOT_HAVE_ATTR);
		pGamePlayer->SendPacket(&msg);
		return PACKET_EXE_CONTINUE;
	}

	//EQUIP_TB* pGet = g_ItemTable.GetEquipTB(pEquipment->GetItemTableIndex());
	//Assert(NULL != pGet);
	//删除装备和炼化神符道具
	UINT iPrice = pEquipment->GetSellPrice();//保留将要删除的装备属性给后面用
	BYTE iRequireLevel = pEquipment->GetRequireLevel();
	BYTE curEquipPoint = pEquipment->GetEquipPoint();
	BYTE attrCount = 0;

	_ITEM_ATTR tmpItemAttr[MAX_ITEM_ATTR];
	for (BYTE index=0; index<pEquipment->GetAttrCount(); ++index)
	{
		tmpItemAttr[index] = pEquipment->GetEquipAttr(index);
		if (tmpItemAttr[index].m_AttrType > 0)
		{
			attrCount++;
		}
	}
	Assert(attrCount == pEquipment->GetAttrCount());
	//开始删除装备和扣除金钱
	BOOL bRet = FALSE;
	ITEM_LOG_PARAM		ItemLogParam;
	ItemLogParam.OpType	= ITEM_EQUIP_REFINING;

	bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman, pBagContainer->BagIndex2ConIndex(iEquipItemPos));
	if(bRet)
	{
		SaveItemLog(&ItemLogParam);
	}
	else
	{
		msg.SetResult(EQUIPREFINING_ERASE_ITEM_FAIL);
		pGamePlayer->SendPacket(&msg);
		return PACKET_EXE_CONTINUE;
	}
	//删除炼化道具
	bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman, pBagContainer->BagIndex2ConIndex(iRefiningItemPos));
	if(bRet)
	{
		SaveItemLog(&ItemLogParam);
	}
	else
	{
		msg.SetResult(EQUIPREFINING_ERASE_ITEM_FAIL);
		pGamePlayer->SendPacket(&msg);
		return PACKET_EXE_CONTINUE;
	}

	UINT iSoulBeadBagIndex = 0;
	Item*	pSoulBeadItem = NULL;
	//武魂珠
	if (HEQUIP_MAINHAND == curEquipPoint)
	{
		bRet = HumanItemLogic::CreateItemToBag(&ItemLogParam,pHuman,ITEM_WU_SOUL_BEAD, iSoulBeadBagIndex);
		if(bRet)
		{
			SaveItemLog(&ItemLogParam);
		} 
		else 
		{
			msg.SetResult(EQUIPREFINING_ERASE_ITEM_FAIL);
			pGamePlayer->SendPacket(&msg);
			return PACKET_EXE_CONTINUE;
		}
		
		pSoulBeadItem = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(iSoulBeadBagIndex));
		Assert(NULL != pSoulBeadItem);
		Assert(ICLASS_SOUL_BEAD == pSoulBeadItem->GetItemClass());	
		
		pSoulBeadItem->SetSoulBeadPrice(iPrice);//由基本价格计算得出
		pSoulBeadItem->SetSoulBeadNeedLevel(iRequireLevel);
		pSoulBeadItem->SetWuSoulBeadAttr(attrCount, tmpItemAttr);
		
	}//器魂珠
	else if (EQUIP_CAP == pEquipment->GetItemType()//EQUIP_PIFENG == pEquipment->GetEquipPoint() || 
			|| EQUIP_SHOULDER == pEquipment->GetItemType() || EQUIP_HAND == pEquipment->GetItemType()
			|| EQUIP_ARMOR == pEquipment->GetItemType() || EQUIP_BOOT == pEquipment->GetItemType())
	{
		bRet = HumanItemLogic::CreateItemToBag(&ItemLogParam,pHuman,ITEM_WU_SOUL_BEAD, iSoulBeadBagIndex);
		if(bRet)
		{
			SaveItemLog(&ItemLogParam);
		} 
		else 
		{
			msg.SetResult(EQUIPREFINING_ERASE_ITEM_FAIL);
			pGamePlayer->SendPacket(&msg);
			return PACKET_EXE_CONTINUE;
		}
		pSoulBeadItem = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(iSoulBeadBagIndex));
		Assert(NULL != pSoulBeadItem);
		Assert(ICLASS_SOUL_BEAD == pSoulBeadItem->GetItemClass());	
		
		pSoulBeadItem->SetSoulBeadPrice(iPrice);//由基本价格计算得出
		pSoulBeadItem->SetSoulBeadNeedLevel(iRequireLevel);
		pSoulBeadItem->SetQiSoulBeadAttr(attrCount, tmpItemAttr);
	}
	// 通知增加道具到背包
	GCNotifyEquip ItemMsg;
	Assert(pSoulBeadItem);
	ItemMsg.SetBagIndex(iSoulBeadBagIndex);
	pSoulBeadItem->SaveValueTo(ItemMsg.GetItem());
	pGamePlayer->SendPacket(&ItemMsg);
	
	msg.SetResult(EQUIPREFINING_SUCCESS);
	//pGamePlayer->SendPacket(&msg);
	return PACKET_EXE_CONTINUE;

	__LEAVE_FUNCTION

		return	PACKET_EXE_ERROR;
}
Example #3
0
ORESULT AbilityInlay::CanUseAbility(Obj_Human* pHuman)
{
__ENTER_FUNCTION

	Assert( pHuman );

	AbilityOpera* pAbilityOpera;

	pAbilityOpera = pHuman->GetAbilityOpera();
	Assert( pAbilityOpera );

	ORESULT res;
	res = Ability::CanUseAbility(pHuman);
	if( res != OR_OK )
	{
		return res;
	}

	CHAR MaterialBagIndex1 = (CHAR)pAbilityOpera->m_BagPos[2];
	CHAR MaterialBagIndex2 = (CHAR)pAbilityOpera->m_BagPos[3];
	if( (pAbilityOpera->m_BagPos[0] < 0)  || (pAbilityOpera->m_BagPos[0] >= MAX_BAG_SIZE)
	 || (pAbilityOpera->m_BagPos[1] < 0)  || (pAbilityOpera->m_BagPos[1] >= MAX_BAG_SIZE)
	 || (MaterialBagIndex1>= MAX_BAG_SIZE)|| (MaterialBagIndex2>= MAX_BAG_SIZE)
	 )
	{
		Assert(FALSE);
		return OR_ERROR;
	}

	Item* pGemItem = HumanItemLogic::GetBagItem( pHuman, pAbilityOpera->m_BagPos[0] );
	Item* pEquipItem = HumanItemLogic::GetBagItem( pHuman, pAbilityOpera->m_BagPos[1] );
	Item* pMaterialItem1 = NULL;
	Item* pMaterialItem2 = NULL;
	if( MaterialBagIndex1 != -1 )
	{
		pMaterialItem1 = HumanItemLogic::GetBagItem( pHuman, pAbilityOpera->m_BagPos[2] );
		Assert( pMaterialItem1 != NULL );
	}
	if( MaterialBagIndex2 != -1 )
	{
		pMaterialItem2 = HumanItemLogic::GetBagItem( pHuman, pAbilityOpera->m_BagPos[3] );
		Assert( pMaterialItem2 != NULL );
	}
	Assert( (pGemItem != NULL) && (pEquipItem != NULL) );

	if( (pGemItem->IsLock())
	 || (pEquipItem->IsLock())
	 || (pGemItem->IsPWLock())
	 || (pEquipItem->IsPWLock())
	 || (pGemItem->GetItemClass() != ICLASS_GEM)
	 || (pEquipItem->GetItemClass() != ICLASS_EQUIP)
	 )
	{
		return OR_STUFF_LACK;
	}

	//if( pHuman->__GetAbilityLevel(pAbilityOpera->m_AbilityID) < pGemItem->GetItemQual() )
	//{
	//	return OR_NO_LEVEL;
	//}

	if( IsGemConflict(pHuman, pAbilityOpera->m_BagPos[0], pAbilityOpera->m_BagPos[1]) == FALSE )
	{
		return OR_GEM_CONFLICT;
	}

	LuaInterface* pLuaInterface;
	pLuaInterface = pHuman->getScene()->GetLuaInterface();

	if( pEquipItem->GetGemSlotMax() <= pEquipItem->GetEquipGemCount()
	 || pLuaInterface->ExeScript_DDD(	ABILITY_LOGIC_SCRIPT, DEF_GEM_COUNT_CHECK,
										(INT)pHuman->getScene()->SceneID(),
										(INT)pHuman->GetID(),
										(INT)pAbilityOpera->m_BagPos[1] )
	 )
	{
		return OR_GEM_SLOT_LACK;
	}

	if( pLuaInterface->ExeScript_DDDD(	ABILITY_LOGIC_SCRIPT, DEF_IS_GEM_FIT_EQUIP,
										(INT)pHuman->getScene()->SceneID(),
										(INT)pHuman->GetID(),
										pGemItem->GetItemTableIndex(),
										pAbilityOpera->m_BagPos[1] ) == 0
	 )
	{ // 判断宝石和装备是否匹配
		return OR_GEM_NOT_FIT_EQUIP;
	}

	return OR_OK;

__LEAVE_FUNCTION

	return OR_ERROR;
}