//---------------------------------------------------
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();
		}
//---------------------------------------------------
void CCharacterVersionAdapter::adaptToVersion9(CCharacter &character) const
{
//	for (int i = 0; i < MAX_INVENTORY_ANIMAL; i++)
	for (int i = INVENTORIES::pet_animal; i < INVENTORIES::max_pet_animal; i++)
	{
//		CGameItem * petInv = *character._Inventory[INVENTORIES::pet_animal + i];
		CInventoryPtr petInv = character._Inventory[INVENTORIES::TInventory(i)];
		if (!petInv)
			continue;
//		if (petInv->getChildren().size() < 256)
		// TODO : still needed ?
		if (petInv->getSlotCount() < 256)
		{
//			petInv->getChildren().resize(256, NULL);
			petInv->setSlotCount(256);
//			petInv->SlotCount = 256;
		}
	}
}
示例#4
0
//-----------------------------------------------------------------------------
void CNamedItems::loadNamedItemsFromFile(const std::string & fileName)
{
	CHashMap<std::string, CGameItemPtr>::iterator it;
	for (it = _NamedItems.begin(); it != _NamedItems.end(); ++it)
	{
		GameItemManager.destroyItem((*it).second);
	}
	_NamedItems.clear();

	string path;
	try
	{
		path = CPath::lookup(fileName);
	}
	catch (Exception &)
	{
		nlwarning("<NAMED_ITEMS> file '%s' was not found", fileName.c_str());
		return;
	}

	static CPersistentDataRecord	pdr;
	pdr.clear();
	pdr.readFromTxtFile(path.c_str());
	CInventoryPtr inv = loadFromPdr(pdr);
	if (inv == NULL)
	{
		nlwarning("<NAMED_ITEMS> error while loading items from the PDR");
		return;
	}

	const uint size = inv->getSlotCount();
	nlinfo("loading '%u' named items", size);
	for (uint i = 0; inv->getFreeSlotCount() != inv->getSlotCount() && i < size; ++i)
	{
		if (inv->getItem(i) == NULL)
			continue;
		CGameItemPtr item = inv->removeItem(i);
		if (item != NULL)
		{
			if (item->getSheetId() == CSheetId::Unknown)
			{
				nlwarning("<NAMED_ITEMS> item '%u' has invalid sheet id", i);
				GameItemManager.destroyItem(item);
				continue;
			}
			if (item->getPhraseId().empty())
			{
				nlwarning("<NAMED_ITEMS> item '%u' has no name", i);
				GameItemManager.destroyItem(item);
				continue;
			}
			if (_NamedItems.find(item->getPhraseId()) != _NamedItems.end())
			{
				nlwarning("<NAMED_ITEMS> item '%u', name '%s' exists more than once", i, item->getPhraseId().c_str());
				GameItemManager.destroyItem(item);
				continue;
			}

			// Yoyo: force this item to work with the new form requirement system.
			// BUT: do it only if _UseNewSystemRequirement==false (if LDs put true, we suppose that the named item has special req value)
			if(item->getUseNewSystemRequirement()==false)
				item->computeRequirementFromForm();

			nldebug("<NAMED_ITEMS> creating named item '%s'",item->getPhraseId().c_str());
			_NamedItems.insert(make_pair(item->getPhraseId(), item));
		}
	}
}
//--------------------------------------------------------------
//					apply()  
//--------------------------------------------------------------
void CSpecialPowerEnchantWeapon::apply()
{
	if (!_Phrase)
		return;
	
	CCharacter* actor = PlayerManager.getChar(_ActorRowId);
	if (!actor)
	{
		nlwarning("<CSpecialPowerEnchantWeapon::apply> Cannot find actor entity or not a player");
		return;
	}
	
	CInventoryPtr inv = actor->getInventory(INVENTORIES::handling);
	nlassert(inv != NULL);
	
	// Test some cases that should be avoided on client (so don't bother adding an error message)
	
	// If we have no equipped item
	if (inv->getSlotCount()<=0)
		return;
	
	// If equipped item is invalid
	CGameItemPtr item = inv->getItem(0);
	if (item == NULL)
		return;
	
	// If item sheet is unknown
	CSheetId itemSheet = item->getSheetId();
	if (itemSheet==CSheetId::Unknown)
		return;
	
	// If item sheet is invalid
	const CStaticItem * form = item->getStaticForm();
	if (!form)
		return;
	
	// If item is not a melee weapon
	ITEMFAMILY::EItemFamily family = form->Family;
	if (family!=ITEMFAMILY::MELEE_WEAPON)
		return;
	
	// Here equipped item is valid. Enchant removal will be done on unequip.
	
	// disable power
	actor->forbidPower(_PowerType, _Phrase->getConsumableFamilyId(), CTickEventHandler::getGameCycle() + _DisablePowerTime + _Duration);
	
	// create effect and apply it on actor
	TGameCycle const endDate = _Duration + CTickEventHandler::getGameCycle();
	float damageBonus = _DpsBonus * 10.f / item->hitRate();
	
	CEnchantWeaponEffect* effect = new CEnchantWeaponEffect(_ActorRowId, _ActorRowId, _EffectFamily, _ParamValue, endDate, _DamageType, SCORES::hit_points, damageBonus, DMGTYPE::UNDEFINED);
	if (effect)
	{
		effect->endsAtCasterDeath(true);
		effect->stackable(true);
		actor->addSabrinaEffect(effect);
	}
	else
		return;
	// send messages
//	TVectorParamCheck params;
	// for actor
	if (actor->getId().getType() == RYZOMID::player)
	{
		SM_STATIC_PARAMS_1(params, STRING_MANAGER::power_type);
		params[0].Enum = _PowerType;
		PHRASE_UTILITIES::sendDynamicSystemMessage(_ActorRowId, "POWER_USE", params);
	}
	
	// for spectators
//	{
//		vector<CEntityId> excluded;
//		excluded.push_back(actor->getId());
//
//		params.resize(2);
//		params[0].Type = STRING_MANAGER::entity;
//		params[0].EId = actor->getId();
//		params[1].Type = STRING_MANAGER::power_type;
//		params[1].Enum = _PowerType;
//		PHRASE_UTILITIES::sendDynamicGroupSystemMessage(_ActorRowId, excluded, "POWER_USE_SPECTATORS", params);
//	}
}