Example #1
0
////////////////////////////////////////////////////////////////////////////////
// 액션을 실행한다.
////////////////////////////////////////////////////////////////////////////////
void ActionSell::execute (Creature * pCreature1 , Creature * pCreature2) 
	throw(Error)
{
	__BEGIN_TRY

	Assert(pCreature1 != NULL);
	Assert(pCreature2 != NULL);
	Assert(pCreature1->isNPC());
	Assert(pCreature2->isPC());

	NPC* pNPC = dynamic_cast<NPC*>(pCreature1);
	Player* pPlayer = pCreature2->getPlayer();
	Assert(pPlayer != NULL);

	PlayerCreature* pPC = dynamic_cast<PlayerCreature*>(pCreature2);

	GCNPCResponse okpkt;
	pPlayer->sendPacket(&okpkt);

	GCShopVersion pkt;
	pkt.setObjectID(pNPC->getObjectID());
	pkt.setVersion(SHOP_RACK_NORMAL,     pNPC->getShopVersion(SHOP_RACK_NORMAL));
	pkt.setVersion(SHOP_RACK_SPECIAL,    pNPC->getShopVersion(SHOP_RACK_SPECIAL));
	pkt.setVersion(SHOP_RACK_MYSTERIOUS, pNPC->getShopVersion(SHOP_RACK_MYSTERIOUS));

	int taxratio = pNPC->getTaxRatio(pPC);

	if (taxratio != 100 ) pkt.setMarketCondSell(taxratio);
	else pkt.setMarketCondSell(pNPC->getMarketCondSell());

	pPlayer->sendPacket(&pkt);

	__END_CATCH
}
void CGShopRequestListHandler::execute(CGShopRequestList* pPacket , Player* pPlayer)
	 throw(ProtocolException , Error)
{
	__BEGIN_TRY __BEGIN_DEBUG_EX

#ifdef __GAME_SERVER__

	Assert(pPacket != NULL);
	Assert(pPlayer != NULL);

	// 패킷에서 정보를 뽑아낸다.	
	ObjectID_t     NPCID = pPacket->getObjectID();
	ShopRackType_t type  = pPacket->getRackType();

	// 파라미터 및 패킷에서 뽑아낸 정보를 가공
	GamePlayer* pGamePlayer = dynamic_cast<GamePlayer*>(pPlayer);
	PlayerCreature*   pPC         = dynamic_cast<PlayerCreature*>(pGamePlayer->getCreature());
	Zone*       pZone       = pPC->getZone();
	Creature*   pNPCBase    = NULL;
	
	/*
	try
	{
		pNPCBase = pZone->getCreature(NPCID);
	}
	catch (NoSuchElementException & nsee)
	{
		pNPCBase = NULL;
	}
	*/

	// NoSuch제거. by sigi. 2002.5.2
	pNPCBase = pZone->getCreature(NPCID);

	if (pNPCBase == NULL || pNPCBase->isNPC() == false)
	{
		GCNPCResponse gcNPCResponse;
		pPlayer->sendPacket(&gcNPCResponse);
		return;
	}

	NPC* pNPC = dynamic_cast<NPC*>(pNPCBase);

	if (type == SHOP_RACK_SPECIAL)
	{
		// 상품의 리스트를 패킷에다 작성한다.
		GCShopList pkt;
		pkt.setNPCShopType(pNPC->getShopType());
		pkt.setObjectID(NPCID);
		pkt.setShopVersion(pNPC->getShopVersion(type));
		pkt.setShopType(type);

		for (BYTE i=0; i<SHOP_RACK_INDEX_MAX; i++) 
		{
			// 각각의 아이템 정보를 적는다.
			Item* pItem = pNPC->getShopItem(type, i);
			if (pItem != NULL) pkt.setShopItem(i, pItem);
		}

		pkt.setMarketCondBuy(pNPC->getMarketCondBuy());
//		pkt.setMarketCondSell(pNPC->getMarketCondSell());
		pkt.setMarketCondSell(pNPC->getTaxRatio(pPC));

		// 패킷을 보내자.
		pPlayer->sendPacket(&pkt);
	}
	else if (type == SHOP_RACK_MYSTERIOUS)
	{
		// 상품의 리스트를 패킷에다 작성한다.
		GCShopListMysterious pkt;
		pkt.setObjectID(NPCID);
		pkt.setShopVersion(pNPC->getShopVersion(type));
		pkt.setShopType(type);

		for (BYTE i=0; i<SHOP_RACK_INDEX_MAX; i++) 
		{
			// 각각의 아이템 정보를 적는다.
			Item* pItem = pNPC->getShopItem(type, i);
			if (pItem != NULL)
				pkt.setShopItem(i, pItem);
		}

		pkt.setMarketCondBuy(pNPC->getMarketCondBuy());
//		pkt.setMarketCondSell(pNPC->getMarketCondSell());
		pkt.setMarketCondSell(pNPC->getTaxRatio(pPC));

		// 패킷을 보내자.
		pPlayer->sendPacket(&pkt);
	}
	else 
	{
		throw ProtocolException("NORMAL shop item list not allowed!!!");
	}

#endif

	__END_DEBUG_EX __END_CATCH
}