Пример #1
0
EnhanceItemStatus CItemEnhancement::Combine (const CItem &Item, CItemEnhancement Enhancement)

//	Combine
//
//	Combine the current enhancement with the given one

{
    DWORD dwNewMods = Enhancement.m_dwMods;

    //	If we're losing the enhancement, then clear it

    if (dwNewMods == etLoseEnhancement)
    {
        if (IsEnhancement())
        {
            *this = CItemEnhancement();
            return eisEnhancementRemoved;
        }
        else
            return eisNoEffect;
    }

    //	If the item is not currently enhanced, then we take the new enhancement

    else if (m_dwMods == etNone)
    {
        //	For strength/hpBonus, use the following rules:
        //
        //	etStrengthen 0 -> Min(10%, maxHPBonus)
        //	etStrengthen {level} -> Min( {level} * 10, maxHPBonus )

        if (Enhancement.GetType() == etStrengthen
                || Enhancement.GetType() == etHPBonus)
        {
            int iMaxBonus = Item.GetType()->GetMaxHPBonus();
            int iNewBonus = Min((Enhancement.IsStacking() ? 10 : Enhancement.GetHPBonus()), iMaxBonus);
            if (iNewBonus > 0)
            {
                SetModBonus(iNewBonus);
                return eisOK;
            }
            else
                return eisNoEffect;
        }

        //	For all others, take the enhancement

        else
            *this = Enhancement;

        return eisOK;
    }

    //	If already enhanced

    else if (m_dwMods == dwNewMods)
    {
        if (IsDisadvantage())
            return eisNoEffect;
        else
            return eisAlreadyEnhanced;
    }

    //	We currently have a disadvantage

    else if (IsDisadvantage())
    {
        //	We have a disadvantage and the enhancement is another
        //	disadvantage.

        if (Enhancement.IsDisadvantage())
        {
            switch (Enhancement.GetType())
            {
            //	If we're making the disadvantage worse, then
            //	continue; otherwise, no effect.

            case etRegenerate:
            case etResist:
            case etResistEnergy:
            case etResistMatter:
            case etPowerEfficiency:
            {
                if (Enhancement.GetType() == GetType()
                        && Enhancement.GetLevel() > GetLevel())
                {
                    *this = Enhancement;
                    return eisWorse;
                }
                else
                    return eisNoEffect;
            }

            case etHPBonus:
            case etStrengthen:
            {
                if ((GetType() == etHPBonus || GetType() == etStrengthen)
                        && Enhancement.GetHPBonus() < GetHPBonus())
                {
                    *this = Enhancement;
                    return eisWorse;
                }
                else
                    return eisNoEffect;
            }

            case etSpeed:
            case etSpeedOld:
            {
                if ((GetType() == etSpeed || GetType() == etSpeedOld)
                        && Enhancement.GetActivateRateAdj() > GetActivateRateAdj())
                {
                    *this = Enhancement;
                    return eisWorse;
                }
                else
                    return eisNoEffect;
            }

            case etResistByLevel:
            case etResistByDamage:
            case etResistByDamage2:
            {
                if (Enhancement.GetType() == GetType()
                        && Enhancement.GetDamageType() == GetDamageType()
                        && Enhancement.GetLevel() > GetLevel())
                {
                    *this = Enhancement;
                    return eisWorse;
                }
                else
                    return eisNoEffect;
            }

            //	Otherwise, a disadvantage does not affect a disadvantage

            default:
                return eisNoEffect;
            }
        }

        //	We have a disadvantage and we use an enhancement.

        else
        {
            switch (Enhancement.GetType())
            {
            //	Regeneration enhancement always repairs a disadvantage

            case etRegenerate:
            {
                *this = CItemEnhancement();
                return eisRepaired;
            }

            //	If the enhancement is the opposite of the disadvantage
            //	then the disadvantage is repaired.

            case etResist:
            case etResistEnergy:
            case etResistMatter:
            case etPowerEfficiency:
            case etResistByLevel:
            case etResistByDamage:
            case etResistByDamage2:
            case etReflect:
            {
                if (GetType() == Enhancement.GetType())
                {
                    *this = CItemEnhancement();
                    return eisRepaired;
                }
                else
                    return eisNoEffect;
            }

            case etHPBonus:
            case etStrengthen:
            {
                if (GetType() == etHPBonus || GetType() == etStrengthen)
                {
                    *this = CItemEnhancement();
                    return eisRepaired;
                }
                else
                    return eisNoEffect;
            }

            case etSpeed:
            case etSpeedOld:
            {
                if (GetType() == etSpeed || GetType() == etSpeedOld)
                {
                    *this = CItemEnhancement();
                    return eisRepaired;
                }
                else
                    return eisNoEffect;
            }

            //	Otherwise, no effect

            default:
                return eisNoEffect;
            }
        }
    }

    //	We currently have an enhancement

    else
    {
        if (!Enhancement.IsDisadvantage())
        {
            switch (Enhancement.GetType())
            {
            case etHPBonus:
            case etStrengthen:
            {
                if (GetType() != etHPBonus
                        && GetType() != etStrengthen)
                    return eisNoEffect;

                //	If improving...

                int iOldBonus = GetHPBonus();
                int iMaxBonus = Item.GetType()->GetMaxHPBonus();
                int iNewBonus = Min((Enhancement.IsStacking() ? iOldBonus + 10 : Enhancement.GetHPBonus()), iMaxBonus);
                if (iNewBonus > iOldBonus)
                {
                    SetModBonus(iNewBonus);
                    return eisBetter;
                }
                else
                    return eisNoEffect;
            }

            //	If this is the same type of enhancement and it is better,
            //	then take it (otherwise, no effect)

            case etRegenerate:
            case etResist:
            case etResistEnergy:
            case etResistMatter:
            case etPowerEfficiency:
            {
                if (Enhancement.GetType() == GetType()
                        && Enhancement.GetLevel() > GetLevel())
                {
                    *this = Enhancement;
                    return eisBetter;
                }
                else
                    return eisNoEffect;
            }

            case etSpeed:
            case etSpeedOld:
            {
                if (Enhancement.GetType() == GetType()
                        && Enhancement.GetActivateRateAdj() < GetActivateRateAdj())
                {
                    *this = Enhancement;
                    return eisBetter;
                }
                else
                    return eisNoEffect;
            }

            case etResistByLevel:
            case etResistByDamage:
            case etResistByDamage2:
            {
                if (Enhancement.GetType() != GetType())
                    return eisNoEffect;
                else if (Enhancement.GetDamageType() != GetDamageType())
                {
                    *this = Enhancement;
                    return eisEnhancementReplaced;
                }
                else if (Enhancement.GetLevel() > GetLevel())
                {
                    *this = Enhancement;
                    return eisBetter;
                }
                else
                    return eisNoEffect;
            }

            default:
                return eisNoEffect;
            }
        }
        else
        {
            //	A disadvantage always destroys any enhancement

            *this = CItemEnhancement();
            return eisEnhancementRemoved;
        }
    }
}
Пример #2
0
EnhanceItemStatus CItemEnhancement::Combine (CItemEnhancement Enhancement)

//	Combine
//
//	Combine the current enhancement with the given one

	{
	DWORD dwNewMods = Enhancement.m_dwMods;

	//	If we're losing the enhancement, then clear it

	if (dwNewMods == etLoseEnhancement)
		{
		if (IsEnhancement())
			{
			*this = CItemEnhancement();
			return eisEnhancementRemoved;
			}
		else
			return eisNoEffect;
		}

	//	If the item is not currently enhanced, then we take the new enhancement

	else if (m_dwMods == etNone)
		{
		//	For stackable strengthening, start at 1

		if (Enhancement.GetType() == etStrengthen
				&& Enhancement.GetLevel() == 0
				&& Enhancement.GetEnhancementType() == GetEnhancementType())
			m_dwMods = dwNewMods + 1;

		//	For all others, take the enhancement

		else
			*this = Enhancement;

		return eisOK;
		}

	//	If already enhanced

	else if (m_dwMods == dwNewMods)
		{
		if (IsDisadvantage())
			return eisNoEffect;
		else
			return eisAlreadyEnhanced;
		}

	//	We currently have a disadvantage

	else if (IsDisadvantage())
		{
		//	We have a disadvantage and the enhancement is another
		//	disadvantage.

		if (Enhancement.IsDisadvantage())
			{
			switch (Enhancement.GetType())
				{
				//	If we're making the disadvantage worse, then
				//	continue; otherwise, no effect.

				case etStrengthen:
				case etRegenerate:
				case etResist:
				case etResistEnergy:
				case etResistMatter:
				case etPowerEfficiency:
				case etSpeed:
					{
					if (Enhancement.GetType() == GetType()
							&& Enhancement.GetLevel() > GetLevel())
						{
						*this = Enhancement;
						return eisWorse;
						}
					else
						return eisNoEffect;
					}

				case etResistByLevel:
				case etResistByDamage:
				case etResistByDamage2:
					{
					if (Enhancement.GetType() == GetType()
							&& Enhancement.GetDamageType() == GetDamageType()
							&& Enhancement.GetLevel() > GetLevel())
						{
						*this = Enhancement;
						return eisWorse;
						}
					else
						return eisNoEffect;
					}

				//	Otherwise, a disadvantage does not affect a disadvantage

				default:
					return eisNoEffect;
				}
			}

		//	We have a disadvantage and we use an enhancement.

		else
			{
			switch (Enhancement.GetType())
				{
				//	Regeneration enhancement always repairs a disadvantage

				case etRegenerate:
					{
					*this = CItemEnhancement();
					return eisRepaired;
					}

				//	If the enhancement is the opposite of the disadvantage
				//	then the disadvantage is repaired.

				case etStrengthen:
				case etResist:
				case etResistEnergy:
				case etResistMatter:
				case etPowerEfficiency:
				case etResistByLevel:
				case etResistByDamage:
				case etResistByDamage2:
				case etReflect:
				case etSpeed:
					{
					if (GetType() == Enhancement.GetType())
						{
						*this = CItemEnhancement();
						return eisRepaired;
						}
					else
						return eisNoEffect;
					}

				//	Otherwise, no effect

				default:
					return eisNoEffect;
				}
			}
		}

	//	We currently have an enhancement

	else
		{
		if (!Enhancement.IsDisadvantage())
			{
			if (Enhancement.GetType() == GetType())
				{
				switch (Enhancement.GetType())
					{
					case etStrengthen:
						{
						//	If stackable...

						if (Enhancement.GetLevel() == 0)
							{
							if (GetLevel() == 15)
								return eisNoEffect;
							else
								{
								m_dwMods++;
								return eisBetter;
								}
							}

						//	If improving...

						else if (Enhancement.GetLevel() > GetLevel())
							{
							*this = Enhancement;
							return eisBetter;
							}
						else
							return eisNoEffect;
						}

					//	If this is the same type of enhancement and it is better,
					//	then take it (otherwise, no effect)

					case etRegenerate:
					case etResist:
					case etResistEnergy:
					case etResistMatter:
					case etPowerEfficiency:
					case etSpeed:
						{
						if (Enhancement.GetLevel() > GetLevel())
							{
							*this = Enhancement;
							return eisBetter;
							}
						else
							return eisNoEffect;
						}

					case etResistByLevel:
					case etResistByDamage:
					case etResistByDamage2:
						{
						if (Enhancement.GetDamageType() != GetDamageType())
							{
							*this = Enhancement;
							return eisEnhancementReplaced;
							}
						else if (Enhancement.GetLevel() > GetLevel())
							{
							*this = Enhancement;
							return eisBetter;
							}
						else
							return eisNoEffect;
						}

					default:
						return eisNoEffect;
					}
				}

			//	No effect if we're already enhanced

			else
				{
				return eisNoEffect;
				}
			}
		else
			{
			//	A disadvantage always destroys any enhancement

			*this = CItemEnhancement();
			return eisEnhancementRemoved;
			}
		}
	}