コード例 #1
0
ファイル: player.cpp プロジェクト: Faultless/Dawn
static uint16_t getModifiedAttribute( const Inventory& inventory, const CCharacter* character, uint16_t basicAttributeValue, int16_t(*getItemAttribute)( Item* ), int16_t(*getSpellAttribute)( GeneralBuffSpell* ), uint16_t minValue = std::numeric_limits<uint16_t>::min(), uint16_t maxValue = std::numeric_limits<uint16_t>::max() )
{
	int32_t attributeModifier = 0;
	std::vector<InventoryItem*> equippedItems = inventory.getEquippedItems();
	size_t numItems = equippedItems.size();
	bool readTwoHandedWeapon = false;
	for( size_t curItemNr=0; curItemNr<numItems; ++curItemNr )
	{
		Item* curItem = equippedItems[curItemNr]->getItem();
		assert( curItem != NULL );
		if ( curItem->isTwoHandedWeapon() == false || readTwoHandedWeapon == false )
		{
			attributeModifier += getItemAttribute( curItem );
		}

		// we do this because we only want to read the stats from two-handed weapons once and not two times as it would be since we equip two-handed weapons in both main-hand and off-hand slot.
		if( curItem->isTwoHandedWeapon() )
		{
			readTwoHandedWeapon = true;
		}
	}

	std::vector<std::pair<CSpellActionBase*, uint32_t> > activeSpells;
	activeSpells = character ->getActiveSpells();
	size_t numSpells = activeSpells.size();
	for( size_t curSpellNr=0; curSpellNr<numSpells; ++curSpellNr )
	{
		GeneralBuffSpell *curSpell = dynamic_cast<GeneralBuffSpell*> ( activeSpells[ curSpellNr ].first );
		// since more than Buffspells can be active, we want to check to see that we're getting a buff here...
		if( curSpell != NULL )
		{
			attributeModifier += getSpellAttribute( curSpell );
		}
	}

	if( static_cast<int32_t>( basicAttributeValue ) + attributeModifier < static_cast<int32_t>( minValue ) )
	{
		return minValue;
	}
	else if( static_cast<int32_t>( basicAttributeValue ) + attributeModifier > static_cast<int32_t>( maxValue ) )
	{
		return maxValue;
	}
	else
	{
		return basicAttributeValue + attributeModifier;
	}
}
コード例 #2
0
ファイル: player.cpp プロジェクト: Faultless/Dawn
static uint16_t getModifiedAttribute( ElementType::ElementType elementType, const Inventory &inventory, const CCharacter *character, uint16_t basicAttributeValue, int16_t (*getItemAttribute)( ElementType::ElementType, Item* ), int16_t (*getSpellAttribute)( ElementType::ElementType, GeneralBuffSpell* ), uint16_t minValue = std::numeric_limits<uint16_t>::min(), uint16_t maxValue = std::numeric_limits<uint16_t>::max() )
{
	int32_t attributeModifier = 0;
	std::vector<InventoryItem*> equippedItems = inventory.getEquippedItems();
	size_t numItems = equippedItems.size();
	for( size_t curItemNr=0; curItemNr<numItems; ++curItemNr )
	{
		Item* curItem = equippedItems[ curItemNr ]->getItem();
		assert( curItem != NULL );
		attributeModifier += getItemAttribute( elementType, curItem );
	}

	std::vector<std::pair<CSpellActionBase*, uint32_t> > activeSpells;
	activeSpells = character->getActiveSpells();
	size_t numSpells = activeSpells.size();
	for( size_t curSpellNr=0; curSpellNr<numSpells; ++curSpellNr )
	{
		GeneralBuffSpell* curSpell = dynamic_cast<GeneralBuffSpell*> ( activeSpells[ curSpellNr ].first );

		// since more than Buffspells can be active, we want to check to see that we're getting a buff here...
		if( curSpell != NULL )
		{
			attributeModifier += getSpellAttribute( elementType, curSpell );
		}
	}

	if( static_cast<int32_t>( basicAttributeValue ) + attributeModifier < static_cast<int32_t>( minValue ) )
	{
		return minValue;
	}
	else if ( static_cast<int32_t>( basicAttributeValue ) + attributeModifier > static_cast<int32_t>( maxValue ) )
	{
		return maxValue;
	}
	else
	{
		return basicAttributeValue + attributeModifier;
	}
}