//---------------------------------------------------
void CCharacterVersionAdapter::adaptToVersion14(CCharacter &character) const
{
	// parse all inventories and set items to max Hp when current Hp == 0
	const uint sizeInv = INVENTORIES::NUM_INVENTORY;
	for ( uint i = 0; i < sizeInv ; ++i )
	if (character._Inventory[i] != NULL)
	{
		CInventoryPtr childSrc = character._Inventory[i];
		for ( uint j = 0; j < childSrc->getSlotCount(); j++ )
		{
			CGameItemPtr item = childSrc->getItem(j);
			if (item != NULL)
			{
				if (item->getSheetId() != CSheetId("stack.sitem") )
				{
					if (item->durability() == 0 && item->maxDurability() > 0)
					{
						nlinfo("player %s, patching item %s HP, new value= %u", 
							character.getId().toString().c_str(), item->getSheetId().toString().c_str(), item->maxDurability());
						item->addHp(item->maxDurability());
					}
				}
			}
		}
	}
}
//---------------------------------------------------
void CCharacterVersionAdapter::adaptToVersion17(CCharacter &character) const
{
	// only for pre-order players
	CPlayer * p = PlayerManager.getPlayer( PlayerManager.getPlayerId( character.getId() ) );
	if (p != NULL && p->isPreOrder())
	{
		INVENTORIES::TInventory inventories[] =
		{
			INVENTORIES::bag,
			INVENTORIES::pet_animal1,
			INVENTORIES::pet_animal2,
			INVENTORIES::pet_animal3,
			INVENTORIES::pet_animal4,
			INVENTORIES::player_room
		};

		CSheetId preOrderSheet("pre_order.sitem");
		BOMB_IF(preOrderSheet == CSheetId::Unknown, "cannot find pre_order.sitem!", return);

		// restore pre-order item hp to the max if any
		bool foundPreOrderItem = false;
		for (uint i = 0; i < sizeof(inventories)/sizeof(inventories[0]); ++i)
		{
			CInventoryPtr inv = character.getInventory(inventories[i]);
			if (inv == NULL)
				continue;

			for (uint slot = 0; slot < inv->getSlotCount(); ++slot)
			{
				CGameItemPtr item = inv->getItem(slot);
				if (item == NULL)
					continue;

				if (item->getSheetId() == preOrderSheet)
				{
					foundPreOrderItem = true;
					item->addHp(item->maxDurability());
				}
			}
		}

		// give a new pre-order item to players who lost it
		if (!foundPreOrderItem)
		{
			CGameItemPtr item = character.createItem(10, 1, preOrderSheet);
			BOMB_IF(item == NULL, "cannot create pre_order.sitem!", return);

			if (!character.addItemToInventory(INVENTORIES::bag, item))
				if (!character.addItemToInventory(INVENTORIES::temporary, item))
					item.deleteItem();
		}
Beispiel #3
0
// ****************************************************************************
void CCharacterInvView::updateClientSlot(uint32 slot, const CGameItemPtr item)
{
	// do nothing if client is not ready
	if (!getCharacter()->getEnterFlag())
		return;

	if (item != NULL)
	{
		uint32 price;
		RM_FABER_STAT_TYPE::TRMStatType itemBestStat;

		getCharacter()->queryItemPrice( item, price );
		itemBestStat = item->getCraftParameters() == 0 ? RM_FABER_STAT_TYPE::Unknown : item->getCraftParameters()->getBestItemStat();

		BOTCHATTYPE::TBotChatResaleFlag resaleFlag = (item->durability() == item->maxDurability() ? BOTCHATTYPE::ResaleOk : BOTCHATTYPE::ResaleKOBroken);
		if (item->getLockedByOwner())
		{
			resaleFlag = BOTCHATTYPE::ResaleKOLockedByOwner;
		}

		INVENTORIES::CItemSlot itemSlot( slot );
		itemSlot.setItemProp( INVENTORIES::Sheet, item->getSheetId().asInt() );
		itemSlot.setItemProp( INVENTORIES::Quality, item->quality() );
		itemSlot.setItemProp( INVENTORIES::Quantity, item->getStackSize() );
		itemSlot.setItemProp( INVENTORIES::UserColor, item->color() );
		itemSlot.setItemProp( INVENTORIES::Locked, item->getLockCount() );
		itemSlot.setItemProp( INVENTORIES::Weight, item->weight() / 10 );
		itemSlot.setItemProp( INVENTORIES::NameId, item->sendNameId(getCharacter()) );
		itemSlot.setItemProp( INVENTORIES::Enchant, item->getClientEnchantValue() );
		itemSlot.setItemProp( INVENTORIES::Price, price );
		itemSlot.setItemProp( INVENTORIES::ResaleFlag, resaleFlag );
		itemSlot.setItemProp( INVENTORIES::ItemClass, item->getItemClass() );
		itemSlot.setItemProp( INVENTORIES::ItemBestStat, itemBestStat );
		itemSlot.setItemProp( INVENTORIES::PrerequisitValid, getCharacter()->checkPreRequired( item ) );
		itemSlot.setItemProp( INVENTORIES::Worned, (item->getItemWornState()==ITEM_WORN_STATE::Worned));
		getCharacter()->_InventoryUpdater.setItemProps( getInventory()->getInventoryId(), itemSlot );
	}
	else
	{
		// empty slot
		getCharacter()->_InventoryUpdater.resetItem( getInventory()->getInventoryId(), slot );
	}

	// send slot update to the client
	getCharacter()->_InventoryUpdater.incInfoVersion(getInventory()->getInventoryId(), slot);
}